From e4f6d7a1d496056a1805e3e5d59606d02c5a862b Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 3 Oct 2005 11:15:56 +0000 Subject: [PATCH] * lily/align-interface.cc (stretch_after_break): new function. Read fixed-alignment-extra-space property. (align_elements_to_extents): read alignment-extra-space property. * lily/lily-guile.cc (robust_scm2dir): new function. --- lily/align-interface.cc | 93 +++++++++++++++++++++++++-------- lily/include/align-interface.hh | 1 + lily/include/lily-guile.hh | 1 + lily/lily-guile.cc | 8 +++ 4 files changed, 82 insertions(+), 21 deletions(-) diff --git a/lily/align-interface.cc b/lily/align-interface.cc index 1b661e8f9e..ce3e9b8731 100644 --- a/lily/align-interface.cc +++ b/lily/align-interface.cc @@ -39,6 +39,44 @@ Align_interface::fixed_distance_alignment_callback (SCM element_smob, SCM axis) 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 ()) + { + 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(); + for (int i = 0; i < elems.size (); i++) + elems[i]->translate_axis (i * delta, Y_AXIS); + } + + return SCM_UNSPECIFIED; +} + /* merge with align-to-extents? */ @@ -73,8 +111,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])) @@ -116,14 +152,26 @@ 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->warning (_ ("vertical alignment called before line-breaking. Only do cross-staff spanners with PianoStaff.")); + && me_spanner) + { + 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.")); - me->set_property ("positioning-done", SCM_BOOL_T); + 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; @@ -156,19 +204,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++) { @@ -183,12 +225,13 @@ Align_interface::align_elements_to_extents (Grob *me, Axis a) if (j) 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. */ @@ -266,9 +309,17 @@ find_fixed_alignment_parent (Grob *g) } ADD_INTERFACE (Align_interface, "align-interface", - "Order grobs from top to bottom, left to right, right to left or bottom" + "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 " + + /* + properties + */ + "forced-distance " + "stacking-dir " + "align-dir " + "threshold " + "positioning-done " "elements axes"); struct Foobar diff --git a/lily/include/align-interface.hh b/lily/include/align-interface.hh index 8ac3503a4b..ec8099d252 100644 --- a/lily/include/align-interface.hh +++ b/lily/include/align-interface.hh @@ -16,6 +16,7 @@ struct Align_interface { DECLARE_SCHEME_CALLBACK (alignment_callback, (SCM element, SCM axis)); DECLARE_SCHEME_CALLBACK (fixed_distance_alignment_callback, (SCM element, SCM axis)); + DECLARE_SCHEME_CALLBACK (stretch_after_break, (SCM element)); static void align_to_fixed_distance (Grob *, Axis a); static void align_elements_to_extents (Grob *, Axis a); static void set_axis (Grob *, Axis); diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 672a0df804..ad01de3694 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -51,6 +51,7 @@ char *ly_scm2newstr (SCM str, size_t *lenp); Real robust_scm2double (SCM, double); int robust_scm2int (SCM, int); +Direction robust_scm2dir (SCM, Direction); Drul_array robust_scm2drul (SCM, Drul_array); Interval robust_scm2interval (SCM, Drul_array); Offset robust_scm2offset (SCM, Offset); diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 17409239b1..681d1762c0 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -613,6 +613,14 @@ robust_scm2double (SCM k, double x) return x; } +Direction +robust_scm2dir (SCM d, Direction def) +{ + if (is_direction (d)) + def = to_dir (d); + return def; +} + Interval robust_scm2interval (SCM k, Drul_array v) { -- 2.39.2