From 42c5103a716d4d94ccb1c71378d1d7cb197844a4 Mon Sep 17 00:00:00 2001
From: Joe Neeman <joeneeman@gmail.com>
Date: Thu, 21 Dec 2006 14:03:54 +0200
Subject: [PATCH] Fix refpoints in align-interface. Fine-tune
 padding/minimum-Y-extent of staves

---
 lily/align-interface.cc | 23 ++++++++++++++++++-----
 ly/engraver-init.ly     |  8 ++++----
 scm/define-grobs.scm    |  3 ++-
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/lily/align-interface.cc b/lily/align-interface.cc
index e4505675df..690f2a4921 100644
--- a/lily/align-interface.cc
+++ b/lily/align-interface.cc
@@ -138,13 +138,25 @@ get_skylines (Grob *me,
 	      bool pure, int start, int end,
 	      vector<Skyline_pair> *const ret)
 {
-  Grob *other_axis_common = common_refpoint_of_array (*elements, me, other_axis (a));
+  /* each child's skyline was calculated according to the common refpoint of its
+     elements. Here we need all the skylines to be positioned with respect to
+     a single refpoint, so we need the common refpoint of the common refpoints
+     of the elements of the children */
+  vector<Grob*> child_refpoints;
+  for (vsize i = 0; i < elements->size (); i++)
+    {
+      extract_grob_set ((*elements)[i], "elements", child_elts);
+      Grob *child_common = common_refpoint_of_array (child_elts, (*elements)[i], other_axis (a));
+      child_refpoints.push_back (child_common);
+    }
+  Grob *common_refpoint = common_refpoint_of_array (child_refpoints, me, other_axis (a));
+  
   for (vsize i = elements->size (); i--;)
     {
       Grob *g = (*elements)[i];
       Interval extent = g->maybe_pure_extent (g, a, pure, start, end);
       Interval other_extent = pure ? Interval (-infinity_f, infinity_f)
-	: g->extent (other_axis_common, other_axis (a));
+	: g->extent (common_refpoint, other_axis (a));
       Box b = (a == X_AXIS) ? Box (extent, other_extent) : Box (other_extent, extent);
       
       if (extent.is_empty ())
@@ -179,8 +191,9 @@ get_skylines (Grob *me,
 	      b[a] = ly_scm2interval (min_extent);
 	      skylines.insert (b, 0, other_axis (a));
 	    }
-	  Real offset = g->relative_coordinate (other_axis_common, other_axis (a));
-	  skylines.shift (-offset);
+
+	  Real offset = child_refpoints[i]->relative_coordinate (common_refpoint, other_axis (a));
+	  skylines.shift (offset);
 	}
 
 
@@ -234,7 +247,7 @@ Align_interface::get_extents_aligned_translates (Grob *me,
       else
 	dy = skylines[j-1][stacking_dir].distance (skylines[j][-stacking_dir]);
 
-      where += stacking_dir * (dy + padding + extra_space / elems.size ());
+      where += stacking_dir * max (0.0, dy + padding + extra_space / elems.size ());
       translates.push_back (where);
     }
 
diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly
index 6907308aab..f69cc77fbc 100644
--- a/ly/engraver-init.ly
+++ b/ly/engraver-init.ly
@@ -57,7 +57,7 @@
   \consists "Figured_bass_position_engraver"
   \consists "Script_row_engraver"
 
-  \override VerticalAxisGroup #'minimum-Y-extent = #'(-4 . 4)
+  \override VerticalAxisGroup #'minimum-Y-extent = #'(-3.5 . 3.5)
   localKeySignature = #'()
   createSpacing = ##t
   ignoreFiguredBassRest = ##t 
@@ -358,7 +358,7 @@ staffs, with a bracket in front and spanning bar lines. "
 
 \context{
   \type "Engraver_group"
-  \override VerticalAxisGroup #'minimum-Y-extent = #'(-1.2 . 2.4)
+  \override VerticalAxisGroup #'minimum-Y-extent = #'(-0.75 . 2.0)
 
   \description " Corresponds to a voice with lyrics.  Handles the
 printing of a single line of lyrics.  "
@@ -416,7 +416,7 @@ printing of a single line of lyrics.  "
   \consists "Hara_kiri_engraver"
 %  \consists "Note_spacing_engraver"
   voltaOnThisStaff = ##f
-  \override VerticalAxisGroup #'minimum-Y-extent = #'(0 . 2.5)
+  \override VerticalAxisGroup #'minimum-Y-extent = #'(0 . 2)
   \override SeparatingGroupSpanner #'padding = #0.8
   \override VerticalAxisGroup #'remove-first = ##t
   \override VerticalAxisGroup #'remove-empty = ##t
@@ -635,7 +635,7 @@ AncientRemoveEmptyStaffContext = \context {
 
   \override VerticalAxisGroup #'remove-empty = ##t
   \override VerticalAxisGroup #'remove-first = ##t
-  \override VerticalAxisGroup #'minimum-Y-extent = #'(-0.5 . 2.5)
+  \override VerticalAxisGroup #'minimum-Y-extent = #'(0 . 2)
 }
 
 \context {
diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm
index a794f75470..f6f778b150 100644
--- a/scm/define-grobs.scm
+++ b/scm/define-grobs.scm
@@ -239,6 +239,7 @@
 	(positioning-done . ,ly:align-interface::calc-positioning-done)
 	(Y-extent . ,ly:axis-group-interface::height)
 	(stacking-dir . -1)
+	(padding . 0.2)
 	(meta . ((class . Spanner)
 		 (interfaces . (align-interface
 				bass-figure-alignment-interface
@@ -1977,7 +1978,7 @@
 	(Y-extent . ,ly:axis-group-interface::height)
 	(X-extent . ,ly:axis-group-interface::width)
 	(stacking-dir . -1)
-	(padding . 0.1)
+	(padding . 0.5)
 	(skylines . ,ly:axis-group-interface::combine-skylines)
 	(meta . ((class . Spanner)
 		 (interfaces . (align-interface
-- 
2.39.5