X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Faxis-group-interface.cc;h=b62465322eb8044081bd5801b560c3b60ef21ea5;hb=d8c103f73dec7a61da04f3be0ffa6a790660fb52;hp=9fbfdf3193f29fb1c3329b880ddb55296cc4eabc;hpb=587186e70d21624cff1d1a7956ef7f37cb11dd3e;p=lilypond.git diff --git a/lily/axis-group-interface.cc b/lily/axis-group-interface.cc index 9fbfdf3193..b62465322e 100644 --- a/lily/axis-group-interface.cc +++ b/lily/axis-group-interface.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 2000--2006 Han-Wen Nienhuys + (c) 2000--2007 Han-Wen Nienhuys */ #include "axis-group-interface.hh" @@ -14,9 +14,11 @@ #include "grob-array.hh" #include "hara-kiri-group-spanner.hh" #include "international.hh" +#include "lookup.hh" #include "paper-column.hh" #include "paper-score.hh" #include "separation-item.hh" +#include "stencil.hh" #include "system.hh" #include "warn.hh" @@ -61,13 +63,24 @@ Axis_group_interface::relative_group_extent (vector const &elts, for (vsize i = 0; i < elts.size (); i++) { Grob *se = elts[i]; - Interval dims = se->extent (common, a); - if (!dims.is_empty ()) - r.unite (dims); + if (!to_boolean (se->get_property ("cross-staff"))) + { + Interval dims = se->extent (common, a); + if (!dims.is_empty ()) + r.unite (dims); + } } return r; } + +/* + FIXME: pure extent handling has a lot of ad-hoc caching. + This should be done with grob property callbacks. + + --hwn +*/ + Interval Axis_group_interface::cached_pure_height (Grob *me, vector const &elts, @@ -101,7 +114,7 @@ Axis_group_interface::cached_pure_height (Grob *me, if (!scm_is_vector (extents)) { extents = scm_c_make_vector (breaks.size () - 1, SCM_EOL); - for (vsize i = 0; i < breaks.size () - 1; i++) + for (vsize i = 0; i + 1 < breaks.size (); i++) { int st = Paper_column::get_rank (cols[breaks[i]]); int ed = Paper_column::get_rank (cols[breaks[i+1]]); @@ -141,7 +154,7 @@ Axis_group_interface::relative_pure_height (Grob *me, for (vsize i = 0; i < elts.size (); i++) { - Interval_t rank_span = elts[i]->spanned_rank_iv (); + Interval_t rank_span = elts[i]->spanned_rank_interval (); Item *it = dynamic_cast (elts[i]); if (rank_span[LEFT] <= end && rank_span[RIGHT] >= start && (!it || it->pure_is_visible (start, end))) { @@ -177,6 +190,17 @@ Axis_group_interface::pure_height (SCM smob, SCM start_scm, SCM end_scm) int end = robust_scm2int (end_scm, INT_MAX); Grob *me = unsmob_grob (smob); + /* Maybe we are in the second pass of a two-pass spacing run. In that + case, the Y-extent of a system is already given to us */ + System *system = dynamic_cast (me); + if (system) + { + SCM line_break_details = system->column (start)->get_property ("line-break-system-details"); + SCM system_y_extent = scm_assq (ly_symbol2scm ("system-Y-extent"), line_break_details); + if (scm_is_pair (system_y_extent)) + return scm_cdr (system_y_extent); + } + return pure_group_height (me, start, end); } @@ -186,7 +210,16 @@ Axis_group_interface::calc_skylines (SCM smob) { Grob *me = unsmob_grob (smob); extract_grob_set (me, "elements", elts); - return skyline_spacing (me, elts).smobbed_copy (); + Skyline_pair skylines = skyline_spacing (me, elts); + + /* add a minimum-Y-extent-sized box to the skyline */ + SCM min_y_extent = me->get_property ("minimum-Y-extent"); + if (is_number_pair (min_y_extent)) + { + Box b (me->extent (me, X_AXIS), ly_scm2interval (min_y_extent)); + skylines.insert (b, 0, X_AXIS); + } + return skylines.smobbed_copy (); } /* whereas calc_skylines calculates skylines for axis-groups with a lot of @@ -208,7 +241,7 @@ Axis_group_interface::combine_skylines (SCM smob) Skyline_pair ret; for (vsize i = 0; i < elements.size (); i++) { - SCM skyline_scm = elements[i]->get_property ("skylines"); + SCM skyline_scm = elements[i]->get_property ("vertical-skylines"); if (Skyline_pair::unsmob (skyline_scm)) { Real offset = elements[i]->relative_coordinate (y_common, Y_AXIS); @@ -224,7 +257,8 @@ SCM Axis_group_interface::generic_group_extent (Grob *me, Axis a) { /* trigger the callback to do skyline-spacing on the children */ - (void) me->get_property ("skylines"); + if (a == Y_AXIS) + (void) me->get_property ("vertical-skylines"); extract_grob_set (me, "elements", elts); Grob *common = common_refpoint_of_array (elts, me, a); @@ -275,14 +309,26 @@ Axis_group_interface::calc_pure_elts_and_common (Grob *me) return common; } -MAKE_SCHEME_CALLBACK(Axis_group_interface,calc_y_common, 1); +MAKE_SCHEME_CALLBACK (Axis_group_interface, calc_x_common, 1); +SCM +Axis_group_interface::calc_x_common (SCM grob) +{ + Grob *me = unsmob_grob (grob); + + extract_grob_set (me, "elements", elts); + Grob *common = common_refpoint_of_array (elts, me, X_AXIS); + return common->self_scm (); +} + +MAKE_SCHEME_CALLBACK (Axis_group_interface, calc_y_common, 1); SCM Axis_group_interface::calc_y_common (SCM grob) { Grob *me = unsmob_grob (grob); extract_grob_set (me, "elements", elts); - return common_refpoint_of_array (elts, me, Y_AXIS)->self_scm (); + Grob *common = common_refpoint_of_array (elts, me, Y_AXIS); + return common->self_scm (); } SCM @@ -324,6 +370,12 @@ staff_priority_less (Grob * const &g1, Grob * const &g2) else if (priority_1 > priority_2) return false; + /* if neither grob has an outside-staff priority, the ordering will have no + effect -- we just need to choose a consistent ordering. We do this to + avoid the side-effect of calculating extents. */ + if (isinf (priority_1)) + return g1 < g2; + /* if there is no preference in staff priority, choose the left-most one */ Grob *common = g1->common_refpoint (g2, X_AXIS); Real start_1 = g1->extent (common, X_AXIS)[LEFT]; @@ -332,17 +384,27 @@ staff_priority_less (Grob * const &g1, Grob * const &g2) } static void -add_boxes (Grob *me, Grob *x_common, Grob *y_common, vector *const boxes) +add_boxes (Grob *me, Grob *x_common, Grob *y_common, vector *const boxes, Skyline_pair *skylines) { - /* if we are a parent, consider the children's boxes instead of mine */ - if (Grob_array *elements = unsmob_grob_array (me->get_object ("elements"))) + /* if a child has skylines, use them instead of the extent box */ + if (Skyline_pair *pair = Skyline_pair::unsmob (me->get_property ("vertical-skylines"))) + { + Skyline_pair s = *pair; + s.shift (me->relative_coordinate (x_common, X_AXIS)); + s.raise (me->relative_coordinate (y_common, Y_AXIS)); + skylines->merge (s); + } + else if (Grob_array *elements = unsmob_grob_array (me->get_object ("elements"))) { for (vsize i = 0; i < elements->size (); i++) - add_boxes (elements->grob (i), x_common, y_common, boxes); + add_boxes (elements->grob (i), x_common, y_common, boxes, skylines); + } + else if (!scm_is_number (me->get_property ("outside-staff-priority")) + && !to_boolean (me->get_property ("cross-staff"))) + { + boxes->push_back (Box (me->extent (x_common, X_AXIS), + me->extent (y_common, Y_AXIS))); } - else if (!scm_is_number (me->get_property ("outside-staff-priority"))) - boxes->push_back (Box (me->extent (x_common, X_AXIS), - me->extent (y_common, Y_AXIS))); } /* We want to avoid situations like this: @@ -396,9 +458,7 @@ add_grobs_of_one_priority (Skyline_pair *const skylines, if (b[X_AXIS][LEFT] - 2*horizon_padding < last_affected_position[dir]) continue; - if (b[X_AXIS].is_empty () || b[Y_AXIS].is_empty ()) - warning (_f ("outside-staff object %s has an empty extent", elements[i]->name ().c_str ())); - else + if (!b[X_AXIS].is_empty () && !b[Y_AXIS].is_empty ()) { boxes.clear (); boxes.push_back (b); @@ -436,25 +496,62 @@ Axis_group_interface::skyline_spacing (Grob *me, vector elements) vsize i = 0; vector boxes; + Skyline_pair skylines; for (i = 0; i < elements.size () && !scm_is_number (elements[i]->get_property ("outside-staff-priority")); i++) - add_boxes (elements[i], x_common, y_common, &boxes); + add_boxes (elements[i], x_common, y_common, &boxes, &skylines); - Skyline_pair skylines (boxes, 0, X_AXIS); + SCM padding_scm = me->get_property ("skyline-horizontal-padding"); + Real padding = robust_scm2double (padding_scm, 0.1); + skylines.merge (Skyline_pair (boxes, padding, X_AXIS)); for (; i < elements.size (); i++) { SCM priority = elements[i]->get_property ("outside-staff-priority"); vector current_elts; current_elts.push_back (elements[i]); - while (i < elements.size () - 1 + while (i + 1 < elements.size () && scm_eq_p (elements[i+1]->get_property ("outside-staff-priority"), priority)) current_elts.push_back (elements[++i]); add_grobs_of_one_priority (&skylines, current_elts, x_common, y_common); } + skylines.shift (-me->relative_coordinate (x_common, X_AXIS)); return skylines; } +MAKE_SCHEME_CALLBACK (Axis_group_interface, calc_max_stretch, 1) +SCM +Axis_group_interface::calc_max_stretch (SCM smob) +{ + Grob *me = unsmob_grob (smob); + Real ret = 0; + extract_grob_set (me, "elements", elts); + + for (vsize i = 0; i < elts.size (); i++) + if (Axis_group_interface::has_interface (elts[i])) + ret += robust_scm2double (elts[i]->get_property ("max-stretch"), 0.0); + + return scm_from_double (ret); +} + +extern bool debug_skylines; +MAKE_SCHEME_CALLBACK (Axis_group_interface, print, 1) +SCM +Axis_group_interface::print (SCM smob) +{ + if (!debug_skylines) + return SCM_BOOL_F; + + Grob *me = unsmob_grob (smob); + Stencil ret; + if (Skyline_pair *s = Skyline_pair::unsmob (me->get_property ("vertical-skylines"))) + { + ret.add_stencil (Lookup::points_to_line_stencil (0.1, (*s)[UP].to_points (X_AXIS)).in_color (255, 0, 255)); + ret.add_stencil (Lookup::points_to_line_stencil (0.1, (*s)[DOWN].to_points (X_AXIS)).in_color (0, 255, 255)); + } + return ret.smobbed_copy (); +} + ADD_INTERFACE (Axis_group_interface, "An object that groups other layout objects.", @@ -464,8 +561,10 @@ ADD_INTERFACE (Axis_group_interface, "Y-common " "axes " "elements " + "keep-fixed-while-stretching " + "max-stretch " "pure-Y-common " "pure-relevant-elements " - "skylines " + "vertical-skylines " "cached-pure-extents " );