]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/break-align-interface.cc
2003 -> 2004
[lilypond.git] / lily / break-align-interface.cc
index c29c74b2407c6b12dfba9ecb06ddc03699f45d8e..de8ba98a118c4f7554baa96e2d4d1e1707af33eb 100644 (file)
@@ -3,13 +3,14 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 
 #include <math.h>
 #include <libc-extension.hh>   // isinf
 
+#include "self-alignment-interface.hh"
 #include "side-position-interface.hh"
 #include "axis-group-interface.hh"
 #include "warn.hh"
@@ -31,9 +32,9 @@ Break_align_interface::alignment_callback (SCM element_smob, SCM axis)
 
   assert (a == X_AXIS);
   Grob *par = me->get_parent (a);
-  if (par && !to_boolean (par->get_grob_property ("break-alignment-done")))
+  if (par && !to_boolean (par->get_grob_property ("positioning-done")))
     {
-      par->set_grob_property ("break-alignment-done", SCM_BOOL_T);
+      par->set_grob_property ("positioning-done", SCM_BOOL_T);
       Break_align_interface::do_alignment (par);
     }
     
@@ -71,21 +72,22 @@ void
 Break_align_interface::do_alignment (Grob *me)
 {
   Item * item = dynamic_cast<Item*> (me);
-
   Link_array<Grob> elems
     = Pointer_group_interface__extract_grobs (me, (Grob*)0,
                                                 "elements");
   Array<Interval> extents;
-  
+
+  int last_nonempty = -1; 
   for (int i=0; i < elems.size (); i++) 
     {
       Interval y = elems[i]->extent (elems[i], X_AXIS);
       extents.push (y);
+      if (!y.is_empty ())
+       last_nonempty = i; 
     }
 
-
   int idx  = 0;
-  while (idx < extents.size  () && extents[idx].empty_b ())
+  while (idx < extents.size  () && extents[idx].is_empty ())
     idx++;
   
   Array<Real> offsets;
@@ -94,28 +96,35 @@ Break_align_interface::do_alignment (Grob *me)
     offsets[i] = 0.0;
 
 
+  Real extra_right_space = 0.0;
   int edge_idx = -1;
   while (idx < elems.size())
     {
       int next_idx = idx+1;
-      while ( next_idx < elems.size() && extents[next_idx].empty_b())
+      while (next_idx < elems.size() &&
+            extents[next_idx].is_empty () )
        next_idx++;
-
-      if (next_idx == elems.size())
-       break;
       
       Grob *l = elems[idx];
-      Grob *r = elems[next_idx];
+      Grob *r = 0;
+
+      if (next_idx < elems.size())
+       r = elems[next_idx];
 
       SCM alist = SCM_EOL;
 
+
+      /*
+       Find the first grob with a space-alist entry.
+       */
       for (SCM s= l->get_grob_property ("elements");
           gh_pair_p (s) ; s = gh_cdr (s))
          {
            Grob *elt = unsmob_grob (gh_car (s));
 
            if (edge_idx < 0
-               && elt->get_grob_property ("break-align-symbol") == ly_symbol2scm( "left-edge"))
+               && elt->get_grob_property ("break-align-symbol")
+               == ly_symbol2scm( "left-edge"))
              edge_idx = idx;
            
            SCM l =elt->get_grob_property ("space-alist");
@@ -126,25 +135,21 @@ Break_align_interface::do_alignment (Grob *me)
              }
          }
 
-      SCM rsym = SCM_EOL;
+      SCM rsym = r ? SCM_EOL : ly_symbol2scm ("right-edge");
 
       /*
        We used to use #'cause to find out the symbol and the spacing
        table, but that gets icky when that grob is suicided for some
        reason.
       */
-      for (SCM s = r->get_grob_property ("elements");
-          gh_pair_p (s); s = gh_cdr (s))
+      for (SCM s = r ? r->get_grob_property ("elements") : SCM_EOL;
+          !gh_symbol_p (rsym) && gh_pair_p (s); s = gh_cdr (s))
        {
          Grob * elt =unsmob_grob(gh_car (s));
 
-         SCM sym = elt->get_grob_property ("break-align-symbol");
-         if (gh_symbol_p (sym))
-           {
-             rsym = sym;
-             break;
-           }
+         rsym = elt->get_grob_property ("break-align-symbol");
        }
+       
       if (rsym  == ly_symbol2scm("left-edge"))
        edge_idx = next_idx;
 
@@ -179,15 +184,23 @@ Break_align_interface::do_alignment (Grob *me)
          type = gh_car (entry) ;
        }
 
-      if (type == ly_symbol2scm ("extra-space"))
-       offsets[next_idx] = extents[idx][RIGHT] + distance;
-      else if (type == ly_symbol2scm("minimum-space"))
-       offsets[next_idx] = extents[idx][RIGHT] >? distance;
-
+      if (r)
+       {
+         if (type == ly_symbol2scm ("extra-space"))
+           offsets[next_idx] = extents[idx][RIGHT] + distance
+             - extents[next_idx][LEFT];
+         /* should probably junk minimum-space */
+         else if (type == ly_symbol2scm("minimum-space"))
+           offsets[next_idx] = extents[idx][RIGHT] >? distance;
+       }
+      else
+       {
+         extra_right_space = distance;   
+       }
+      
       idx = next_idx;
     }
 
-
   Real here = 0.0;
   Interval total_extent;
 
@@ -202,7 +215,9 @@ Break_align_interface::do_alignment (Grob *me)
 
 
   if (item->break_status_dir () == LEFT)
-    alignment_off = -total_extent[RIGHT];
+    {
+      alignment_off = - total_extent[RIGHT] - extra_right_space;
+    }
   else if (edge_idx < 0)
     alignment_off = -total_extent[LEFT];
 
@@ -216,28 +231,33 @@ Break_align_interface::do_alignment (Grob *me)
 
 
 ADD_INTERFACE (Break_aligned_interface, "break-aligned-interface",
-  "Items that are aligned in prefatory matter.
-
-The spacing of these items is controlled by the space-alist
-property. It contains a list break-align-symbols with a specification
-of the associated space. The space definition is either (extra-space
-. @var{number}), which adds space after the symbol, (minimum-space
-. @var{ms}), which pads the space until it it is @var{ms}.
-
-
-Special keys for the alist are 'first-note and 'next-note, signifyign
-the first note on a line, and the next note halfway a line.
-
-Rules for this spacing are much more complicated than this. 
-See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147
-
-
-",
-  "break-align-symbol break-alignment-done space-alist");
+              "Items that are aligned in prefatory matter.\n"
+              "\n"
+              "The spacing of these items is controlled by the space-alist\n"
+              "property. It contains a list break-align-symbols with a specification\n"
+              "of the associated space. The space specification can be "
+              "@table @code\n"
+              "@item (minimum-space . @var{spc}))\n"
+              "  Pad space until the distance is @var{spc}\n"
+              "@item (fixed-space . @var{spc})\n"
+              "  Set a fixed space\n" 
+              "@item (semi-fixed-space . @var{spc})\n"
+              "  Set a space. Half of it is fixed and half is stretchable. \n"
+              "(does not work at start of line. fixme)\n"
+              "@item (extra-space . @var{spc})\n"
+              "  Add @var{spc} amount of space.\n"
+              "@end table\n"
+              "\n"
+              "Special keys for the alist are 'first-note and 'next-note, signifying\n"
+              "the first note on a line, and the next note halfway a line.\n"
+              "\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");
 
 ADD_INTERFACE (Break_align_interface, "break-alignment-interface",
   "See @ref{break-aligned-interface}.",
-  "break-alignment-done");
+  "positioning-done");