]> git.donarmstrong.com Git - lilypond.git/commitdiff
Don't report a programming error when aligned grob has empty extent.
authorJanek Warchoł <lemniskata.bernoullego@gmail.com>
Sun, 24 Mar 2013 10:43:52 +0000 (11:43 +0100)
committerJanek Warchoł <lemniskata.bernoullego@gmail.com>
Tue, 26 Mar 2013 21:47:09 +0000 (22:47 +0100)
(Issue 3259)

If a grob's extent is empty (undefined), alignment procedures from
Self_alignment_interface don't have any information about grob's
dimensions, so they cannot calculate the offset required to achieve
specified alignment of such grob.

However, this isn't actually a problem: if a grob's extent is empty,
this usually means that the grob itself is empty, and in that case
there is nothing to align at all.  Therefore, no programming error
should be reported.

For example, a user may remove some grob from output by overriding
its stencil to #f.  This will result in an empty extent, and Lily
shouldn't complain about being unable to align such grob, because
there is nothing to align.

Nevertheless, if the extent is empty but the stencil itself isn't
empty, the situation looks suspicious, so we issue a warning.

lily/self-alignment-interface.cc

index 59adfc3e6ca04d878349f6e3425843c703694c45..1b4e421b70070afd612c345a43b4c116e5e70387 100644 (file)
@@ -59,8 +59,12 @@ Self_alignment_interface::aligned_on_self (Grob *me, Axis a, bool pure, int star
   if (scm_is_number (align))
     {
       Interval ext (me->maybe_pure_extent (me, a, pure, start, end));
+      // Empty extent doesn't mean an error - we simply don't align such grobs.
+      // However, empty extent and non-empty stencil would be suspicious.
       if (!ext.is_empty ())
         return scm_from_double (- ext.linear_combination (scm_to_double (align)));
+      else if (me->get_stencil ())
+        warning (me->name () + " has empty extent and non-empty stencil.");
     }
   return scm_from_double (0.0);
 }
@@ -147,13 +151,19 @@ Self_alignment_interface::aligned_on_parent (Grob *me, Axis a)
   Real align = scm_to_double (align_prop);
 
   Interval ext (me->extent (me, a));
-  if (ext.is_empty ())
-    programming_error ("cannot align on self: empty element");
-  else
+
+  // Empty extent doesn't mean an error - we simply don't align such grobs.
+  // However, empty extent and non-empty stencil would be suspicious.
+  if (!ext.is_empty ())
     x -= ext.linear_combination (align);
+  else if (me->get_stencil ())
+    warning (me->name () + " has empty extent and non-empty stencil.");
 
+  // See comment above.
   if (!he.is_empty ())
     x += he.linear_combination (align);
+  else if (him->get_stencil ())
+    warning (him->name () + " has empty extent and non-empty stencil.");
 
   return scm_from_double (x);
 }