From f66a2409fca6c7c4dab1f3fb03c2569648a9199b Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 27 Apr 2013 21:13:29 +0200 Subject: [PATCH] Rewrite Stencil::add_at_edge to treat "spacing" stencils differently 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 | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/lily/stencil.cc b/lily/stencil.cc index 6d577482f3..c9105c7e8d 100644 --- a/lily/stencil.cc +++ b/lily/stencil.cc @@ -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); -- 2.39.5