From 1656075e24330067ff1dfa4d8253e5f3e5783014 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Janek=20Warcho=C5=82?= Date: Sun, 24 Mar 2013 11:43:52 +0100 Subject: [PATCH] Don't report a programming error when aligned grob has empty extent. (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 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lily/self-alignment-interface.cc b/lily/self-alignment-interface.cc index 59adfc3e6c..1b4e421b70 100644 --- a/lily/self-alignment-interface.cc +++ b/lily/self-alignment-interface.cc @@ -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); } -- 2.39.2