]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/hara-kiri-group-spanner.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / hara-kiri-group-spanner.cc
index d82fa3bc2311620dfd9bc1f741a91f75111c9792..981639c237d81db41dc4f37ca5354a38a8f2bba9 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
-  Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
+  Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
+#include "hara-kiri-group-spanner.hh"
+
+#include "paper-column.hh"
+#include "pointer-group-interface.hh"
 #include "axis-group-interface.hh"
 #include "spanner.hh"
-#include "hara-kiri-group-spanner.hh"
 #include "warn.hh"
 #include "item.hh"
 
-
-MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner,y_extent,2);
+MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, y_extent, 1);
 SCM
-Hara_kiri_group_spanner::y_extent (SCM element_smob, SCM scm_axis)
+Hara_kiri_group_spanner::y_extent (SCM smob)
 {
-  Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) scm_to_int (scm_axis);
-
-  assert (a == Y_AXIS);
+  Grob *me = unsmob_grob (smob);
   consider_suicide (me);
-  return  Axis_group_interface::group_extent_callback (me->self_scm (), scm_axis);
+  return Axis_group_interface::generic_group_extent (me, Y_AXIS);
 }
 
-
 void
-Hara_kiri_group_spanner::consider_suicide (Grob*me)
+Hara_kiri_group_spanner::consider_suicide (Grob *me)
 {
-  Spanner*sp = dynamic_cast<Spanner*> (me);
-  SCM worth = me->get_property ("items-worth-living");
-  if (ly_c_pair_p (worth))
+  Spanner *sp = dynamic_cast<Spanner *> (me);
+  if (!to_boolean (me->get_property ("remove-empty")))
     return ;
 
-  if (!to_boolean (me->get_property ("remove-first"))
-      && broken_spanner_index (sp) == 0)
-    {
-      return ;
-    }
-  
-  Link_array<Grob> childs = Axis_group_interface::get_children (me);
-  for (int i = 0; i < childs.size (); i++)
-    childs[i]->suicide ();
+  extract_grob_set (me, "items-worth-living", worth);
+  if (worth.size ())
+    return;
+
+  bool remove_first = to_boolean (me->get_property ("remove-first"));
+  if (!remove_first
+       && ((sp->original () && broken_spanner_index (sp) == 0)
+          || Paper_column::get_rank (sp->get_bound (LEFT)->get_column ())
+          == 0)) 
+    return;
 
+  vector<Grob*> childs;
+  Axis_group_interface::get_children (me, &childs);
+  for (vsize i = 0; i < childs.size (); i++)
+    childs[i]->suicide ();
 
   /*
     very appropriate name here :-)
-   */
+  */
   me->suicide ();
 }
 
-
-
 /*
   We can't rely on offsets and dimensions of elements in a hara-kiri
   group. Use a callback to make sure that hara-kiri has been done
   before asking for offsets.  */
-MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner,force_hara_kiri_callback,2);
+MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, after_line_breaking, 1);
 SCM
-Hara_kiri_group_spanner::force_hara_kiri_callback (SCM element_smob, SCM axis)
+Hara_kiri_group_spanner::after_line_breaking (SCM smob)
 {
-  Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) scm_to_int (axis);
-  assert (a == Y_AXIS);
+  Grob *me = unsmob_grob (smob);
   consider_suicide (me);
-  return scm_make_real (0.0);
+  return SCM_UNSPECIFIED;
 }
 
-
-MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner,force_hara_kiri_in_parent_callback,2);
+MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, force_hara_kiri_callback, 1);
 SCM
-Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM element_smob, SCM axis)
+Hara_kiri_group_spanner::force_hara_kiri_callback (SCM smob)
 {
-  Grob *daughter = unsmob_grob (element_smob);
-  Axis a = (Axis) scm_to_int (axis);
-  assert (a == Y_AXIS);
-  force_hara_kiri_callback (daughter->get_parent (a)->self_scm (), axis);
-  return scm_make_real (0.0);
+  Grob *me = unsmob_grob (smob);
+  consider_suicide (me);
+  return scm_from_double (0.0);
 }
 
-void
-Hara_kiri_group_spanner::add_element (Grob * me, Grob *e)
+MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, force_hara_kiri_in_y_parent_callback, 1);
+SCM
+Hara_kiri_group_spanner::force_hara_kiri_in_y_parent_callback (SCM smob)
 {
-  //  e->add_offset_callback (force_hara_kiri_in_parent_callback, Y_AXIS);
-  Axis_group_interface::add_element (me, e);
+  Grob *daughter = unsmob_grob (smob);
+  force_hara_kiri_callback (daughter->get_parent (Y_AXIS)->self_scm ());
+  return scm_from_double (0.0);
 }
 
-
-
-
-
-void 
-Hara_kiri_group_spanner::add_interesting_item (Grob* me,Grob* n)
+void
+Hara_kiri_group_spanner::add_interesting_item (Grob *me, Grob *n)
 {
-  me->add_dependency (n);
-  Pointer_group_interface::add_grob (me, ly_symbol2scm ("items-worth-living"),n);
+  Pointer_group_interface::add_unordered_grob (me, ly_symbol2scm ("items-worth-living"), n);
 }
 
-
-ADD_INTERFACE (Hara_kiri_group_spanner,"hara-kiri-group-interface",
+ADD_INTERFACE (Hara_kiri_group_spanner, "hara-kiri-group-interface",
               "A group spanner that  keeps track of interesting items.  If it "
               "doesn't contain any after linebreaking, then it "
-              "will remove itself and all its children."
-              ,
-              "items-worth-living remove-first");
+              "will remove itself and all its children.",
+
+
+              /* properties */
+              "items-worth-living "
+              "remove-empty "
+              "remove-first "
+              );
+