X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Falign-interface.cc;h=bedae50c809cd878484159ff43ead5d915335636;hb=30eb1ded55e8d8b17495b96a3741750fe34d3599;hp=ba4322d8bb0b906fb89aed10562cf6b9adfb6a64;hpb=87bcea3a1d67afec13b49c2facd9fb28cc37277b;p=lilypond.git diff --git a/lily/align-interface.cc b/lily/align-interface.cc index ba4322d8bb..bedae50c80 100644 --- a/lily/align-interface.cc +++ b/lily/align-interface.cc @@ -7,7 +7,6 @@ */ #include "align-interface.hh" - #include "spanner.hh" #include "item.hh" #include "axis-group-interface.hh" @@ -15,6 +14,13 @@ #include "hara-kiri-group-spanner.hh" #include "grob-array.hh" +/* + TODO: for vertical spacing, should also include a rod & spring + scheme of sorts into this: the alignment should default to a certain + distance between element refpoints, unless bbox force a bigger + distance. + */ + MAKE_SCHEME_CALLBACK (Align_interface, alignment_callback, 2); SCM Align_interface::alignment_callback (SCM element_smob, SCM axis) @@ -23,10 +29,8 @@ Align_interface::alignment_callback (SCM element_smob, SCM axis) Axis ax = (Axis)scm_to_int (axis); Grob *par = me->get_parent (ax); if (par && !to_boolean (par->get_property ("positioning-done"))) - { - Align_interface::align_elements_to_extents (par, ax); - } - return scm_make_real (0.0); + Align_interface::align_elements_to_extents (par, ax); + return scm_from_double (0.0); } MAKE_SCHEME_CALLBACK (Align_interface, fixed_distance_alignment_callback, 2); @@ -37,10 +41,45 @@ Align_interface::fixed_distance_alignment_callback (SCM element_smob, SCM axis) Axis ax = (Axis)scm_to_int (axis); Grob *par = me->get_parent (ax); if (par && !to_boolean (par->get_property ("positioning-done"))) + Align_interface::align_to_fixed_distance (par, ax); + return scm_from_double (0.0); +} + +/* + merge with align-to-extents? +*/ +MAKE_SCHEME_CALLBACK(Align_interface, stretch_after_break, 1) +SCM +Align_interface::stretch_after_break (SCM grob) +{ + Grob *me = unsmob_grob (grob); + + Spanner *me_spanner = dynamic_cast (me); + extract_grob_set (me, "elements", elems); + if (me_spanner && elems.size ()) { - Align_interface::align_to_fixed_distance (par, ax); + Grob *common = common_refpoint_of_array (elems, me, Y_AXIS); + + /* force position callbacks */ + for (int i = 0; i < elems.size (); i++) + elems[i]->relative_coordinate (common, Y_AXIS); + + SCM details = me_spanner->get_bound (LEFT)->get_property ("line-break-system-details"); + SCM extra_space_handle = scm_assoc (ly_symbol2scm ("fixed-alignment-extra-space"), details); + + Real extra_space = robust_scm2double (scm_is_pair (extra_space_handle) + ? scm_cdr (extra_space_handle) + : SCM_EOL, + 0.0); + + Direction stacking_dir = robust_scm2dir (me->get_property ("stacking-dir"), + DOWN); + Real delta = extra_space / elems.size() * stacking_dir; + for (int i = 0; i < elems.size (); i++) + elems[i]->translate_axis (i * delta, Y_AXIS); } - return scm_make_real (0.0); + + return SCM_UNSPECIFIED; } /* @@ -51,18 +90,15 @@ Align_interface::align_to_fixed_distance (Grob *me, Axis a) { me->set_property ("positioning-done", SCM_BOOL_T); - SCM d = me->get_property ("stacking-dir"); - - Direction stacking_dir = scm_is_number (d) ? to_dir (d) : CENTER; - if (!stacking_dir) - stacking_dir = DOWN; + Direction stacking_dir = robust_scm2dir (me->get_property ("stacking-dir"), + DOWN); Real dy = robust_scm2double (me->get_property ("forced-distance"), 0.0); extract_grob_set (me, "elements", elem_source); - Link_array elems (elem_source); // writable.. - + Link_array elems (elem_source); // writable.. + Real where_f = 0; Interval v; @@ -77,8 +113,6 @@ Align_interface::align_to_fixed_distance (Grob *me, Axis a) force_hara_kiri_callback () (extent and offset callback) is such that we might get into a loop if we call extent () or offset () the elements. - - */ if (a == Y_AXIS && Hara_kiri_group_spanner::has_interface (elems[j])) @@ -99,9 +133,7 @@ Align_interface::align_to_fixed_distance (Grob *me, Axis a) TODO: support self-alignment-{Y, X} */ for (int i = 0; i < translates.size (); i++) - { - elems[i]->translate_axis (translates[i] - v.center (), a); - } + elems[i]->translate_axis (translates[i] - v.center (), a); } /* @@ -122,21 +154,33 @@ Align_interface::align_to_fixed_distance (Grob *me, Axis a) void Align_interface::align_elements_to_extents (Grob *me, Axis a) { + Real extra_space = 0.0; Spanner *me_spanner = dynamic_cast (me); if (a == Y_AXIS - && me_spanner - && me_spanner->get_bound (LEFT)->break_status_dir () == CENTER) + && me_spanner) { - me_spanner->warning (_("vertical alignment called before line-breaking. Only do cross-staff spanners with PianoStaff.")); +#if 0 + /* + TODO: messes up for figured bass alignments. + */ + if (me_spanner->get_bound (LEFT)->break_status_dir () == CENTER) + me->warning (_ ("vertical alignment called before line-breaking. " + "Only do cross-staff spanners with PianoStaff.")); +#endif + + SCM details = me_spanner->get_bound (LEFT)->get_property ("line-break-system-details"); + SCM extra_space_handle = scm_assoc (ly_symbol2scm ("alignment-extra-space"), details); + + extra_space = robust_scm2double (scm_is_pair (extra_space_handle) + ? scm_cdr (extra_space_handle) + : SCM_EOL, + extra_space); } me->set_property ("positioning-done", SCM_BOOL_T); - - SCM d = me->get_property ("stacking-dir"); - - Direction stacking_dir = scm_is_number (d) ? to_dir (d) : CENTER; - if (!stacking_dir) - stacking_dir = DOWN; + + Direction stacking_dir = robust_scm2dir (me->get_property ("stacking-dir"), + DOWN); Interval threshold = robust_scm2interval (me->get_property ("threshold"), Interval (0, Interval::infinity ())); @@ -164,19 +208,13 @@ Align_interface::align_elements_to_extents (Grob *me, Axis a) prevent ugly cyclic dependencies that arise when you combine self-alignment on a child with alignment of children. */ - static SCM prop_syms[2]; - - if (!prop_syms[0]) - { - prop_syms[X_AXIS] = ly_symbol2scm ("self-alignment-X"); - prop_syms[Y_AXIS] = ly_symbol2scm ("self-alignment-Y"); - } - - SCM align (me->internal_get_property (prop_syms[a])); + SCM align ((a == X_AXIS) + ? me->get_property ("self-alignment-X") + : me->get_property ("self-alignment-Y")); Array translates; Interval total; - Real where_f = 0; + Real where = 0; for (int j = 0; j < elems.size (); j++) { @@ -189,17 +227,15 @@ Align_interface::align_elements_to_extents (Grob *me, Axis a) */ dy *= stacking_dir; if (j) - { - dy = min (max (dy, threshold[SMALLER]), - threshold[BIGGER]); - } + dy = min (max (dy, threshold[SMALLER]), threshold[BIGGER]); - where_f += stacking_dir * dy; - total.unite (dims[j] + where_f); - translates.push (where_f); + where += stacking_dir * (dy + extra_space / elems.size ()); + total.unite (dims[j] + where); + translates.push (where); } Real center_offset = 0.0; + /* also move the grobs that were empty, to maintain spatial order. */ @@ -212,9 +248,7 @@ Align_interface::align_elements_to_extents (Grob *me, Axis a) while (j < all_grobs.size ()) { if (i < elems.size () && all_grobs[j] == elems[i]) - { - w = translates[i++]; - } + w = translates[i++]; all_translates.push (w); j++; } @@ -257,7 +291,6 @@ Align_interface::set_axis (Grob *me, Axis a) } ga->set_ordered (true); - } /* @@ -279,10 +312,25 @@ find_fixed_alignment_parent (Grob *g) return 0; } -ADD_INTERFACE (Align_interface, "align-interface", - "Order grobs from top to bottom, left to right, right to left or bottom" - "to top.", - "forced-distance stacking-dir align-dir threshold positioning-done " +ADD_INTERFACE (Align_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 @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 + */ + "forced-distance " + "stacking-dir " + "align-dir " + "threshold " + "positioning-done " "elements axes"); struct Foobar