]> git.donarmstrong.com Git - lilypond.git/commitdiff
Rewrite Stencil::add_at_edge to treat "spacing" stencils differently
authorDavid Kastrup <dak@gnu.org>
Sat, 27 Apr 2013 19:13:29 +0000 (21:13 +0200)
committerDavid Kastrup <dak@gnu.org>
Sun, 26 May 2013 00:33:02 +0000 (02:33 +0200)
A spacing stencil is one that is non-empty in its own axis, but empty
in the orthogonal axis.  Since they don't actually have a bounding box
to convey, they don't need padding, and they don't suffer from the
equality of the lower left bounding box corner with the reference
point.

lily/stencil.cc

index 6d577482f337723781f0201ccbc893d739065ef8..c9105c7e8dcc5a85807dfe85617d82d5c621b378 100644 (file)
@@ -259,22 +259,46 @@ Stencil::align_to (Axis a, Real x)
 }
 
 /*  See scheme Function.  */
+
+// Any stencil that is empty in the orthogonal axis is spacing.
+// Spacing is not subjected to the max (0) rule and can thus be
+// negative.
+
 void
 Stencil::add_at_edge (Axis a, Direction d, Stencil const &s, Real padding)
 {
-  Interval my_extent = dim_[a];
-  Interval i (s.extent (a));
-  Real his_extent;
-  if (i.is_empty ())
+  // Material that is empty in the axis of reference has only limited
+  // usefulness for combining.  We still retain as much information as
+  // available since there may be uses like setting page links or
+  // background color or watermarks.
+
+  if (is_empty (a))
     {
-      programming_error ("Stencil::add_at_edge: adding empty stencil.");
-      his_extent = 0.0;
+      add_stencil (s);
+      return;
     }
-  else
-    his_extent = i[-d];
 
-  Real offset = (my_extent.is_empty () ? 0.0 : my_extent[d] - his_extent)
-                + d * padding;
+  Interval first_extent = extent (a);
+
+  if (s.is_empty (a))
+    {
+      Stencil toadd (s);
+      toadd.translate_axis (first_extent[d], a);
+      add_stencil (toadd);
+      return;
+    }
+
+  Interval next_extent = s.extent (a);
+
+  bool first_is_spacing = is_empty (other_axis (a));
+  bool next_is_spacing = s.is_empty (other_axis (a));
+
+  Real offset = first_extent[d] - next_extent[-d];
+
+  if (!(first_is_spacing || next_is_spacing))
+    {
+      offset += d * padding;
+    }
 
   Stencil toadd (s);
   toadd.translate_axis (offset, a);