X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Falign-interface.cc;h=216323644f62dba718dc1c9c8b6139df65149265;hb=09bf9a18185476020686ff65b5d70b57051be780;hp=69fb5e921c3a56f4efd3867493d75fb2cf0b8840;hpb=875b287f353888564d12882449447afcaabf097a;p=lilypond.git diff --git a/lily/align-interface.cc b/lily/align-interface.cc index 69fb5e921c..216323644f 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 @@ -30,6 +31,9 @@ SCM Align_interface::calc_positioning_done (SCM smob) { Grob *me = unsmob_grob (smob); + + me->set_property ("positioning-done", SCM_BOOL_T); + SCM axis = scm_car (me->get_property ("axes")); Axis ax = Axis (scm_to_int (axis)); @@ -41,7 +45,7 @@ Align_interface::calc_positioning_done (SCM smob) /* TODO: This belongs to the old two-pass spacing. Delete me. */ -MAKE_SCHEME_CALLBACK(Align_interface, stretch_after_break, 1) +MAKE_SCHEME_CALLBACK (Align_interface, stretch_after_break, 1) SCM Align_interface::stretch_after_break (SCM grob) { @@ -68,7 +72,7 @@ Align_interface::stretch_after_break (SCM grob) Direction stacking_dir = robust_scm2dir (me->get_property ("stacking-dir"), DOWN); - Real delta = extra_space / elems.size() * stacking_dir; + Real delta = extra_space / elems.size () * stacking_dir; for (vsize i = 0; i < elems.size (); i++) elems[i]->translate_axis (i * delta, Y_AXIS); } @@ -87,60 +91,42 @@ 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 *common_refpoint = 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 ("skylines")); + Skyline_pair *skys = Skyline_pair::unsmob (g->get_property (a == Y_AXIS + ? "vertical-skylines" + : "horizontal-skylines")); if (skys) skylines = *skys; - else - programming_error ("no skylines for alignment-child\n"); /* this is perhaps an abuse of minimum-?-extent: maybe we should create another property? But it seems that the only (current) use of minimum-Y-extent is to separate vertically-aligned elements */ - SCM min_extent = g->get_property (a == X_AXIS ? "minimum-X-extent" : "minimum-Y-extent"); + SCM min_extent = g->get_property (a == X_AXIS + ? ly_symbol2scm ("minimum-X-extent") + : ly_symbol2scm ("minimum-Y-extent")); if (is_number_pair (min_extent)) { Box b; - Interval other_extent = g->extent (common_refpoint, other_axis (a)); + Interval other_extent = g->extent (other_common, other_axis (a)); b[a] = ly_scm2interval (min_extent); b[other_axis (a)] = other_extent; if (!other_extent.is_empty ()) skylines.insert (b, 0, other_axis (a)); } - Real offset = child_refpoints[i]->relative_coordinate (common_refpoint, 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 @@ -182,9 +168,7 @@ Align_interface::get_extents_aligned_translates (Grob *me, line_break_details = me_spanner->get_bound (LEFT)->get_property ("line-break-system-details"); if (!me->get_system () && !pure) - me->warning (_ ("vertical alignment called before line-breaking.\n" - "Only do cross-staff spanners with PianoStaff.")); - + me->programming_error ("vertical alignment called before line-breaking"); } Direction stacking_dir = robust_scm2dir (me->get_property ("stacking-dir"), @@ -205,15 +189,24 @@ Align_interface::get_extents_aligned_translates (Grob *me, Real padding = robust_scm2double (me->get_property ("padding"), 0.0); vector translates; + Skyline down_skyline (stacking_dir); for (vsize j = 0; j < elems.size (); j++) { Real dy = 0; if (j == 0) dy = skylines[j][-stacking_dir].max_height (); else - dy = skylines[j-1][stacking_dir].distance (skylines[j][-stacking_dir]); + { + down_skyline.merge (skylines[j-1][stacking_dir]); + dy = down_skyline.distance (skylines[j][-stacking_dir]); + } + + if (isinf (dy)) /* if the skyline is empty, maybe max_height is infinity_f */ + dy = 0.0; - where += stacking_dir * max (0.0, dy + padding + extra_space / elems.size ()); + dy = max (0.0, dy + padding + extra_space / elems.size ()); + down_skyline.raise (-stacking_dir * dy); + where += stacking_dir * dy; translates.push_back (where); } @@ -231,8 +224,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]; @@ -266,12 +261,12 @@ Align_interface::stretch (Grob *me, Real amount, Axis a) Real non_empty_elts = stretchable_children_count (me); Real offset = 0.0; Direction dir = robust_scm2dir (me->get_property ("stacking-dir"), DOWN); - for (vsize i = 0; i < elts.size (); i++) + for (vsize i = 1; i < elts.size (); i++) { - elts[i]->translate_axis (dir * offset, a); if (!elts[i]->extent (me, a).is_empty () && !to_boolean (elts[i]->get_property ("keep-fixed-while-stretching"))) offset += amount / non_empty_elts; + elts[i]->translate_axis (dir * offset, a); } me->flush_extent_cache (Y_AXIS); } @@ -385,35 +380,17 @@ Align_interface::calc_max_stretch (SCM smob) return scm_from_double (ret); } -/* - Find Y-axis parent of G that has a #'forced-distance property. This - has the effect of finding the piano-staff given an object in that - piano staff. - - FIXME: piano staves no longer have forced-distance. The code that - relies on this function (in line-spanner) is broken. -*/ -Grob * -find_fixed_alignment_parent (Grob *g) -{ - (void) g; - programming_error ("deprecated. We don't use forced-distance anymore"); - return 0; -} - 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 "