X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Falign-interface.cc;h=36aa81f11153d428eb9adafcfd7f2206766b51b4;hb=b97565a9af1c13369ac7e7e9ea80c2638dbc0e51;hp=db71c32b8f2baa8f5adf9d858e5f747efed11552;hpb=deabe8e6c21ae6080e13b269bab24901f74a2254;p=lilypond.git diff --git a/lily/align-interface.cc b/lily/align-interface.cc index db71c32b8f..36aa81f111 100644 --- a/lily/align-interface.cc +++ b/lily/align-interface.cc @@ -3,20 +3,21 @@ source file of the GNU LilyPond music typesetter - (c) 2000--2007 Han-Wen Nienhuys + (c) 2000--2009 Han-Wen Nienhuys */ #include "align-interface.hh" -#include "spanner.hh" -#include "item.hh" #include "axis-group-interface.hh" -#include "pointer-group-interface.hh" -#include "hara-kiri-group-spanner.hh" #include "grob-array.hh" +#include "hara-kiri-group-spanner.hh" #include "international.hh" +#include "item.hh" +#include "paper-column.hh" +#include "pointer-group-interface.hh" +#include "spanner.hh" +#include "skyline-pair.hh" #include "system.hh" #include "warn.hh" -#include "paper-column.hh" /* TODO: for vertical spacing, should also include a rod & spring @@ -83,6 +84,8 @@ Align_interface::stretch_after_break (SCM grob) an empty extent, delete it from the list instead. If the extent is non-empty but there is no skyline available (or pure is true), just create a flat skyline from the bounding box */ +// TODO(jneem): the pure and non-pure parts seem to share very little +// code. Split them into 2 functions, perhaps? static void get_skylines (Grob *me, vector *const elements, @@ -90,37 +93,13 @@ get_skylines (Grob *me, bool pure, int start, int end, vector *const ret) { - /* 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 child_refpoints; - for (vsize i = 0; i < elements->size (); i++) - { - Grob *elt = (*elements)[i]; - Grob *child_common = unsmob_grob ((a == Y_AXIS) - ? elt->get_object ("X-common") - : elt->get_object ("Y-common")); - - if (!child_common) - { - extract_grob_set (elt, "elements", child_elts); - child_common = common_refpoint_of_array (child_elts, elt, other_axis (a)); - } - - child_refpoints.push_back (child_common); - } - - Grob *other_common = common_refpoint_of_array (child_refpoints, me, other_axis (a)); + Grob *other_common = common_refpoint_of_array (*elements, me, other_axis (a)); for (vsize i = elements->size (); i--;) { Grob *g = (*elements)[i]; Skyline_pair skylines; - /* each skyline is calculated relative to (potentially) a different other_axis - coordinate. In order to compare the skylines effectively, we need to shift them - to some absolute reference point */ if (!pure) { Skyline_pair *skys = Skyline_pair::unsmob (g->get_property (a == Y_AXIS @@ -146,7 +125,10 @@ get_skylines (Grob *me, skylines.insert (b, 0, other_axis (a)); } - Real offset = child_refpoints[i]->relative_coordinate (other_common, other_axis (a)); + /* This skyline was calculated relative to the grob g. In order to compare it to + skylines belonging to other grobs, we need to shift it so that it is relative + to the common reference. */ + Real offset = g->relative_coordinate (other_common, other_axis (a)); skylines.shift (offset); } else @@ -157,9 +139,33 @@ get_skylines (Grob *me, { Box b; b[a] = extent; - b[other_axis (a)] = Interval (-infinity_f, infinity_f); + b[other_axis (a)] = Interval (0, infinity_f); skylines.insert (b, 0, other_axis (a)); } + + // This is a hack to get better accuracy on the pure-height of VerticalAlignment. + // It's quite common for a treble clef to be the highest element of one system + // and for a low note (or lyrics) to be the lowest note on another. The two will + // never collide, but the pure-height stuff only works with bounding boxes, so it + // doesn't know that. The result is a significant over-estimation of the pure-height, + // especially on systems with many staves. To correct for this, we build a skyline + // in two parts: the part we did above contains most of the grobs (note-heads, etc.) + // while the bit we're about to do only contains the breakable grobs at the beginning + // of the system. This way, the tall treble clefs are only compared with the treble + // clefs of the other staff and they will be ignored if the staff above is, for example, + // lyrics. + if (Axis_group_interface::has_interface (g) + && !Hara_kiri_group_spanner::request_suicide (g, start, end)) + { + Interval begin_of_line_extent = Axis_group_interface::begin_of_line_pure_height (g, start); + if (!begin_of_line_extent.is_empty ()) + { + Box b; + b[a] = begin_of_line_extent; + b[other_axis (a)] = Interval (-infinity_f, -1); + skylines.insert (b, 0, other_axis (a)); + } + } } if (skylines.is_empty ()) @@ -244,8 +250,10 @@ Align_interface::get_extents_aligned_translates (Grob *me, } } + // So far, we've computed the translates for all the non-empty elements. + // Here, we set the translates for the empty elements: an empty element + // gets the same translation as the last non-empty element before it. vector all_translates; - if (!translates.empty ()) { Real w = translates[0]; @@ -399,18 +407,16 @@ Align_interface::calc_max_stretch (SCM smob) } ADD_INTERFACE (Align_interface, + "Order grobs from top to bottom, left to right, right to left" + " or bottom to top. For vertical alignments of staves, the" + " @code{break-system-details} of the left" + " @rinternals{NonMusicalPaperColumn} may be set to tune" + " vertical spacing. Set @code{alignment-extra-space} to add" + " extra space for staves. Set" + " @code{fixed-alignment-extra-space} to force staves in" + " @code{PianoStaff}s further apart.", - "Order grobs from top to bottom, left to right, right to left or bottom " - "to top. " - "For vertical alignments of staves, the @code{break-system-details} of " - "the left @internalsref{NonMusicalPaperColumn} may be set to tune vertical spacing " - "Set @code{alignment-extra-space} to add extra space for staves. Set " - "@code{fixed-alignment-extra-space} to force staves in PianoStaves further apart." - , - - /* - properties - */ + /* properties */ "align-dir " "axes " "elements "