]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/break-align-interface.cc
* The grand 2005-2006 replace.
[lilypond.git] / lily / break-align-interface.cc
index 1b3daecdb32ec39cc35aa5bcb34ec51a08aaa9db..b5a2aa737723aa91f46c0bd6e9857ea856ef499a 100644 (file)
@@ -3,14 +3,13 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
-#include <math.h>
 
 #include "break-align-interface.hh"
-#include "libc-extension.hh"   // isinf
 
+#include "pointer-group-interface.hh"
 #include "self-alignment-interface.hh"
 #include "side-position-interface.hh"
 #include "axis-group-interface.hh"
 #include "paper-column.hh"
 #include "align-interface.hh"
 
-MAKE_SCHEME_CALLBACK (Break_align_interface, alignment_callback, 2);
-SCM
-Break_align_interface::alignment_callback (SCM element_smob, SCM axis)
-{
-  Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) scm_to_int (axis);
-
-  assert (a == X_AXIS);
-  Grob *par = me->get_parent (a);
-  if (par && !to_boolean (par->get_property ("positioning-done")))
-    {
-      par->set_property ("positioning-done", SCM_BOOL_T);
-      Break_align_interface::do_alignment (par);
-    }
-
-  return scm_make_real (0);
-}
 
-MAKE_SCHEME_CALLBACK (Break_align_interface, self_align_callback, 2);
+MAKE_SCHEME_CALLBACK (Break_align_interface, self_align_callback, 1);
 SCM
-Break_align_interface::self_align_callback (SCM element_smob, SCM axis)
+Break_align_interface::self_align_callback (SCM smob)
 {
-  Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) scm_to_int (axis);
-  assert (a == X_AXIS);
+  Grob *me = unsmob_grob (smob);
 
   Item *item = dynamic_cast<Item *> (me);
   Direction bsd = item->break_status_dir ();
   if (bsd == LEFT)
-    {
-      me->set_property ("self-alignment-X", scm_int2num (RIGHT));
-    }
+    me->set_property ("self-alignment-X", scm_from_int (RIGHT));
 
   /*
     Force break alignment itself to be done first, in the case
   */
-  return Self_alignment_interface::aligned_on_self (element_smob, axis);
+  return Self_alignment_interface::aligned_on_self (me, X_AXIS);
 }
 
 /*
@@ -70,13 +48,16 @@ Link_array<Grob>
 Break_align_interface::ordered_elements (Grob *grob)
 {
   Item *me = dynamic_cast<Item *> (grob);
-  SCM elts = me->get_property ("elements");
+  extract_grob_set (me, "elements", elts);
+
   SCM order_vec = me->get_property ("break-align-orders");
   if (!scm_is_vector (order_vec)
       || scm_c_vector_length (order_vec) < 3)
-    return extract_grob_array (me, ly_symbol2scm ("elements"));
+    return elts;
+
+  Link_array<Grob> writable_elts (elts);
   SCM order = scm_vector_ref (order_vec,
-                             scm_int2num (me->break_status_dir () + 1));
+                             scm_from_int (me->break_status_dir () + 1));
 
   /*
     Copy in order specified in BREAK-ALIGN-ORDER.
@@ -86,28 +67,31 @@ Break_align_interface::ordered_elements (Grob *grob)
     {
       SCM sym = scm_car (order);
 
-      for (SCM s = elts; scm_is_pair (s); s = scm_cdr (s))
+      for (int i = writable_elts.size (); i--;)
        {
-         Grob *g = unsmob_grob (scm_car (s));
+         Grob *g = writable_elts[i];
          if (g && sym == g->get_property ("break-align-symbol"))
            {
              new_elts.push (g);
-             elts = scm_delq (g->self_scm (), elts);
+             writable_elts.del (i);
            }
        }
     }
+
   return new_elts;
 }
 
 void
 Break_align_interface::add_element (Grob *me, Grob *toadd)
 {
-  Axis_group_interface::add_element (me, toadd);
+  Align_interface::add_element (me, toadd);
 }
 
-void
-Break_align_interface::do_alignment (Grob *grob)
+MAKE_SCHEME_CALLBACK(Break_align_interface, calc_positioning_done, 1)
+SCM
+Break_align_interface::calc_positioning_done (SCM smob)
 {
+  Grob *grob = unsmob_grob (smob);  
   Item *me = dynamic_cast<Item *> (grob);
 
   Link_array<Grob> elems = ordered_elements (me);
@@ -151,10 +135,11 @@ Break_align_interface::do_alignment (Grob *grob)
       /*
        Find the first grob with a space-alist entry.
       */
-      for (SCM s = l->get_property ("elements");
-          scm_is_pair (s); s = scm_cdr (s))
+      extract_grob_set (l, "elements", elts);
+
+      for (int i = elts.size (); i--;)
        {
-         Grob *elt = unsmob_grob (scm_car (s));
+         Grob *elt = elts[i];
 
          if (edge_idx < 0
              && elt->get_property ("break-align-symbol")
@@ -176,12 +161,15 @@ Break_align_interface::do_alignment (Grob *grob)
        table, but that gets icky when that grob is suicided for some
        reason.
       */
-      for (SCM s = r ? r->get_property ("elements") : SCM_EOL;
-          !scm_is_symbol (rsym) && scm_is_pair (s); s = scm_cdr (s))
+      if (r)
        {
-         Grob *elt = unsmob_grob (scm_car (s));
-
-         rsym = elt->get_property ("break-align-symbol");
+         extract_grob_set (r, "elements", elts);
+         for (int i = elts.size ();
+              !scm_is_symbol (rsym) && i--;)
+           {
+             Grob *elt = elts[i];
+             rsym = elt->get_property ("break-align-symbol");
+           }
        }
 
       if (rsym == ly_symbol2scm ("left-edge"))
@@ -225,12 +213,10 @@ Break_align_interface::do_alignment (Grob *grob)
              - extents[next_idx][LEFT];
          /* should probably junk minimum-space */
          else if (type == ly_symbol2scm ("minimum-space"))
-           offsets[next_idx] = extents[idx][RIGHT] >? distance;
+           offsets[next_idx] = max (extents[idx][RIGHT], distance);
        }
       else
-       {
-         extra_right_space = distance;
-       }
+       extra_right_space = distance;
 
       idx = next_idx;
     }
@@ -247,10 +233,11 @@ Break_align_interface::do_alignment (Grob *grob)
       total_extent.unite (extents[i] + here);
     }
 
+  if (total_extent.is_empty ())
+    return SCM_BOOL_T;
+
   if (me->break_status_dir () == LEFT)
-    {
-      alignment_off = -total_extent[RIGHT] - extra_right_space;
-    }
+    alignment_off = -total_extent[RIGHT] - extra_right_space;
   else if (edge_idx < 0)
     alignment_off = -total_extent[LEFT];
 
@@ -260,6 +247,8 @@ Break_align_interface::do_alignment (Grob *grob)
       here += offsets[i];
       elems[i]->translate_axis (here, X_AXIS);
     }
+
+  return SCM_BOOL_T;
 }
 
 ADD_INTERFACE (Break_aligned_interface, "break-aligned-interface",
@@ -285,9 +274,16 @@ ADD_INTERFACE (Break_aligned_interface, "break-aligned-interface",
               "\n"
               "Rules for this spacing are much more complicated than this. \n"
               "See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147\n",
-              "break-align-symbol space-alist");
+
+              /* properties */ 
+              "break-align-symbol "
+              "space-alist "
+              );
 
 ADD_INTERFACE (Break_align_interface, "break-alignment-interface",
               "The object that performs break aligment. See @ref{break-aligned-interface}.",
-              "positioning-done break-align-orders");
+
+              /* properties */
+              "positioning-done "
+              "break-align-orders");