CVSROOT:        /cvsroot/lilypond
Module name:    lilypond
Branch:         
Changes by:     Han-Wen Nienhuys <[EMAIL PROTECTED]>    05/10/03 11:15:56

Modified files:
        lily           : align-interface.cc lily-guile.cc 
        lily/include   : align-interface.hh lily-guile.hh 

Log message:
        * lily/align-interface.cc (stretch_after_break): new
        function. Read fixed-alignment-extra-space property.
        (align_elements_to_extents): read alignment-extra-space property.
        
        * lily/lily-guile.cc (robust_scm2dir): new function.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/align-interface.cc.diff?tr1=1.82&tr2=1.83&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/lily-guile.cc.diff?tr1=1.224&tr2=1.225&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/include/align-interface.hh.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/include/lily-guile.hh.diff?tr1=1.165&tr2=1.166&r1=text&r2=text

Patches:
Index: lilypond/lily/align-interface.cc
diff -u lilypond/lily/align-interface.cc:1.82 
lilypond/lily/align-interface.cc:1.83
--- lilypond/lily/align-interface.cc:1.82       Mon Sep 12 12:46:48 2005
+++ lilypond/lily/align-interface.cc    Mon Oct  3 11:15:55 2005
@@ -42,6 +42,44 @@
 /*
   merge with align-to-extents?
 */
+MAKE_SCHEME_CALLBACK(Align_interface, stretch_after_break, 1)
+SCM
+Align_interface::stretch_after_break (SCM grob)
+{
+  Grob *me = unsmob_grob (grob);
+
+  Spanner *me_spanner = dynamic_cast<Spanner *> (me);
+  extract_grob_set (me, "elements", elems);
+  if (me_spanner && elems.size ())
+    {
+      Grob *common = common_refpoint_of_array (elems, me, Y_AXIS);
+
+      /* force position callbacks */
+      for (int i = 0; i < elems.size (); i++)
+       elems[i]->relative_coordinate (common, Y_AXIS);
+
+      SCM details =  me_spanner->get_bound (LEFT)->get_property 
("line-break-system-details");
+      SCM extra_space_handle = scm_assoc (ly_symbol2scm 
("fixed-alignment-extra-space"), details);
+      
+      Real extra_space = robust_scm2double (scm_is_pair (extra_space_handle)
+                                           ? scm_cdr (extra_space_handle)
+                                           : SCM_EOL,
+                                           0.0);
+
+      Direction stacking_dir = robust_scm2dir (me->get_property 
("stacking-dir"),
+                                              DOWN);
+  
+      Real delta  = extra_space / elems.size();
+      for (int i = 0; i < elems.size (); i++)
+       elems[i]->translate_axis (i * delta, Y_AXIS);
+    }
+  
+  return SCM_UNSPECIFIED;
+}
+
+/*
+  merge with align-to-extents?
+*/
 void
 Align_interface::align_to_fixed_distance (Grob *me, Axis a)
 {
@@ -73,8 +111,6 @@
        force_hara_kiri_callback () (extent and offset callback) is
        such that we might get into a loop if we call extent () or
        offset () the elements.
-
-
       */
       if (a == Y_AXIS
          && Hara_kiri_group_spanner::has_interface (elems[j]))
@@ -116,14 +152,26 @@
 void
 Align_interface::align_elements_to_extents (Grob *me, Axis a)
 {
+  Real extra_space = 0.0;
   Spanner *me_spanner = dynamic_cast<Spanner *> (me);
   if (a == Y_AXIS
-      && me_spanner
-      && me_spanner->get_bound (LEFT)->break_status_dir () == CENTER)
-    me_spanner->warning (_ ("vertical alignment called before line-breaking. 
Only do cross-staff spanners with PianoStaff."));
-
+      && me_spanner)
+    {
+      if (me_spanner->get_bound (LEFT)->break_status_dir () == CENTER)
+       me->warning (_ ("vertical alignment called before line-breaking. "
+                       "Only do cross-staff spanners with PianoStaff."));
+
+      SCM details =  me_spanner->get_bound (LEFT)->get_property 
("line-break-system-details");
+      SCM extra_space_handle = scm_assoc (ly_symbol2scm 
("alignment-extra-space"), details);
+
+      extra_space = robust_scm2double (scm_is_pair (extra_space_handle)
+                                      ? scm_cdr (extra_space_handle)
+                                      : SCM_EOL,
+                                      extra_space);
+    }
+  
   me->set_property ("positioning-done", SCM_BOOL_T);
-
+  
   SCM d = me->get_property ("stacking-dir");
 
   Direction stacking_dir = scm_is_number (d) ? to_dir (d) : CENTER;
@@ -156,19 +204,13 @@
     prevent ugly cyclic dependencies that arise when you combine
     self-alignment on a child with alignment of children.
   */
-  static SCM prop_syms[2];
-
-  if (!prop_syms[0])
-    {
-      prop_syms[X_AXIS] = ly_symbol2scm ("self-alignment-X");
-      prop_syms[Y_AXIS] = ly_symbol2scm ("self-alignment-Y");
-    }
-
-  SCM align (me->internal_get_property (prop_syms[a]));
+  SCM align ((a == X_AXIS)
+            ? me->get_property ("self-alignment-X")
+            : me->get_property ("self-alignment-Y"));
 
   Array<Real> translates;
   Interval total;
-  Real where_f = 0;
+  Real where = 0;
 
   for (int j = 0; j < elems.size (); j++)
     {
@@ -183,12 +225,13 @@
       if (j)
        dy = min (max (dy, threshold[SMALLER]), threshold[BIGGER]);
 
-      where_f += stacking_dir * dy;
-      total.unite (dims[j] + where_f);
-      translates.push (where_f);
+      where += stacking_dir * (dy + extra_space / elems.size ());
+      total.unite (dims[j] + where);
+      translates.push (where);
     }
 
   Real center_offset = 0.0;
+  
   /*
     also move the grobs that were empty, to maintain spatial order.
   */
@@ -266,9 +309,17 @@
 }
 
 ADD_INTERFACE (Align_interface, "align-interface",
-              "Order grobs from top to bottom, left to right, right to left or 
bottom"
+              "Order grobs from top to bottom, left to right, right to left or 
bottom "
               "to top.",
-              "forced-distance stacking-dir align-dir threshold 
positioning-done "
+              
+              /*
+                properties
+               */
+              "forced-distance "
+              "stacking-dir "
+              "align-dir "
+              "threshold "
+              "positioning-done "
               "elements axes");
 
 struct Foobar
Index: lilypond/lily/include/align-interface.hh
diff -u lilypond/lily/include/align-interface.hh:1.23 
lilypond/lily/include/align-interface.hh:1.24
--- lilypond/lily/include/align-interface.hh:1.23       Thu Mar 10 14:36:12 2005
+++ lilypond/lily/include/align-interface.hh    Mon Oct  3 11:15:56 2005
@@ -16,6 +16,7 @@
 {
   DECLARE_SCHEME_CALLBACK (alignment_callback, (SCM element, SCM axis));
   DECLARE_SCHEME_CALLBACK (fixed_distance_alignment_callback, (SCM element, 
SCM axis));
+  DECLARE_SCHEME_CALLBACK (stretch_after_break, (SCM element));
   static void align_to_fixed_distance (Grob *, Axis a);
   static void align_elements_to_extents (Grob *, Axis a);
   static void set_axis (Grob *, Axis);
Index: lilypond/lily/include/lily-guile.hh
diff -u lilypond/lily/include/lily-guile.hh:1.165 
lilypond/lily/include/lily-guile.hh:1.166
--- lilypond/lily/include/lily-guile.hh:1.165   Mon Aug 22 15:50:37 2005
+++ lilypond/lily/include/lily-guile.hh Mon Oct  3 11:15:56 2005
@@ -51,6 +51,7 @@
 
 Real robust_scm2double (SCM, double);
 int robust_scm2int (SCM, int);
+Direction robust_scm2dir (SCM, Direction);
 Drul_array<Real> robust_scm2drul (SCM, Drul_array<Real>);
 Interval robust_scm2interval (SCM, Drul_array<Real>);
 Offset robust_scm2offset (SCM, Offset);
Index: lilypond/lily/lily-guile.cc
diff -u lilypond/lily/lily-guile.cc:1.224 lilypond/lily/lily-guile.cc:1.225
--- lilypond/lily/lily-guile.cc:1.224   Mon Sep 12 23:33:24 2005
+++ lilypond/lily/lily-guile.cc Mon Oct  3 11:15:55 2005
@@ -613,6 +613,14 @@
   return x;
 }
 
+Direction
+robust_scm2dir (SCM d, Direction def)
+{
+  if (is_direction (d))
+    def = to_dir (d);
+  return def;
+}
+
 Interval
 robust_scm2interval (SCM k, Drul_array<Real> v)
 {


_______________________________________________
Lilypond-cvs mailing list
Lilypond-cvs@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-cvs

Reply via email to