+
+/*
+ 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, int start, int end)
+{
+ Paper_score *ps = get_root_system (me)->paper_score ();
+ vector<vsize> breaks = ps->get_break_indices ();
+ vector<Grob*> cols = ps->get_columns ();
+
+ SCM extents = me->get_property ("adjacent-pure-heights");
+
+ if (!scm_is_vector (extents))
+ return Interval (0, 0);
+
+ Interval ext;
+ for (vsize i = 0; i + 1 < breaks.size (); i++)
+ {
+ int r = Paper_column::get_rank (cols[breaks[i]]);
+ if (r > end)
+ break;
+
+ if (r >= start)
+ ext.unite (ly_scm2interval (scm_c_vector_ref (extents, i)));
+ }
+
+ return ext;
+}
+
+MAKE_SCHEME_CALLBACK (Axis_group_interface, adjacent_pure_heights, 1)
+SCM
+Axis_group_interface::adjacent_pure_heights (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+
+ Grob *common = calc_pure_elts_and_common (me);
+ extract_grob_set (me, "pure-relevant-items", items);
+ extract_grob_set (me, "pure-relevant-spanners", spanners);
+
+ Paper_score *ps = get_root_system (me)->paper_score ();
+ vector<vsize> breaks = ps->get_break_indices ();
+ vector<Grob*> cols = ps->get_columns ();
+
+ SCM ret = scm_c_make_vector (breaks.size () - 1, SCM_EOL);
+ vsize it_index = 0;
+ for (vsize i = 0; i + 1 < breaks.size (); i++)
+ {
+ int start = Paper_column::get_rank (cols[breaks[i]]);
+ int end = Paper_column::get_rank (cols[breaks[i+1]]);
+ Interval iv;
+
+ for (vsize j = it_index; j < items.size (); j++)
+ {
+ Item *it = dynamic_cast<Item*> (items[j]);
+ int rank = it->get_column ()->get_rank ();
+
+ if (rank <= end && it->pure_is_visible (start, end)
+ && !to_boolean (it->get_property ("cross-staff")))
+ {
+ Interval dims = items[j]->pure_height (common, start, end);
+ if (!dims.is_empty ())
+ iv.unite (dims);
+ }
+
+ if (rank < end)
+ it_index++;
+ else if (rank > end)
+ break;
+ }
+
+ for (vsize j = 0; j < spanners.size (); j++)
+ {
+ Interval_t<int> rank_span = spanners[j]->spanned_rank_interval ();
+ if (rank_span[LEFT] <= end && rank_span[RIGHT] >= start
+ && !to_boolean (spanners[j]->get_property ("cross-staff")))
+ {
+ Interval dims = spanners[j]->pure_height (common, start, end);
+ if (!dims.is_empty ())
+ iv.unite (dims);
+ }
+ }
+
+ scm_vector_set_x (ret, scm_from_int (i), ly_interval2scm (iv));
+ }
+ return ret;
+}
+
+Interval
+Axis_group_interface::relative_pure_height (Grob *me, int start, int end)
+{
+ /* It saves a _lot_ of time if we assume a VerticalAxisGroup is additive
+ (ie. height (i, k) = max (height (i, j) height (j, k)) for all i <= j <= k).
+ Unfortunately, it isn't always true, particularly if there is a
+ VerticalAlignment somewhere in the descendants.
+
+ Apart from PianoStaff, which has a fixed VerticalAlignment so it doesn't
+ count, the only VerticalAlignment comes from Score. This makes it
+ reasonably safe to assume that if our parent is a VerticalAlignment,
+ we can assume additivity and cache things nicely. */
+ Grob *p = me->get_parent (Y_AXIS);
+ if (p && Align_interface::has_interface (p))
+ return Axis_group_interface::cached_pure_height (me, start, end);
+
+ Grob *common = calc_pure_elts_and_common (me);
+ extract_grob_set (me, "pure-relevant-items", items);
+ extract_grob_set (me, "pure-relevant-spanners", spanners);
+
+ Interval r;
+
+ for (vsize i = 0; i < items.size (); i++)
+ {
+ Item *it = dynamic_cast<Item*> (items[i]);
+ int rank = it->get_column ()->get_rank ();
+
+ if (rank > end)
+ break;
+ else if (rank >= start && it->pure_is_visible (start, end)
+ && !to_boolean (it->get_property ("cross-staff")))
+ {
+ Interval dims = it->pure_height (common, start, end);
+ if (!dims.is_empty ())
+ r.unite (dims);
+ }
+ }
+
+ for (vsize i = 0; i < spanners.size (); i++)
+ {
+ Interval_t<int> rank_span = spanners[i]->spanned_rank_interval ();
+ if (rank_span[LEFT] <= end && rank_span[RIGHT] >= start
+ && !to_boolean (spanners[i]->get_property ("cross-staff")))
+ {
+ Interval dims = spanners[i]->pure_height (common, start, end);
+ if (!dims.is_empty ())
+ r.unite (dims);
+ }
+ }
+ return r;
+}
+
+MAKE_SCHEME_CALLBACK (Axis_group_interface, width, 1);
+SCM
+Axis_group_interface::width (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+ return generic_group_extent (me, X_AXIS);
+}
+
+MAKE_SCHEME_CALLBACK (Axis_group_interface, height, 1);
+SCM
+Axis_group_interface::height (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+ return generic_group_extent (me, Y_AXIS);
+}
+
+MAKE_SCHEME_CALLBACK (Axis_group_interface, pure_height, 3);
+SCM
+Axis_group_interface::pure_height (SCM smob, SCM start_scm, SCM end_scm)
+{
+ int start = robust_scm2int (start_scm, 0);
+ 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<System*> (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 ly_interval2scm (pure_group_height (me, start, end));
+}
+
+MAKE_SCHEME_CALLBACK (Axis_group_interface, calc_skylines, 1);
+SCM
+Axis_group_interface::calc_skylines (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+ extract_grob_set (me, "elements", elts);
+ Skyline_pair skylines = skyline_spacing (me, elts);
+
+ return skylines.smobbed_copy ();
+}
+
+/* whereas calc_skylines calculates skylines for axis-groups with a lot of
+ visible children, combine_skylines is designed for axis-groups whose only
+ children are other axis-groups (ie. VerticalAlignment). Rather than
+ calculating all the skylines from scratch, we just merge the skylines
+ of the children.
+*/
+MAKE_SCHEME_CALLBACK (Axis_group_interface, combine_skylines, 1);
+SCM
+Axis_group_interface::combine_skylines (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+ extract_grob_set (me, "elements", elements);
+ Grob *y_common = common_refpoint_of_array (elements, me, Y_AXIS);
+ Grob *x_common = common_refpoint_of_array (elements, me, X_AXIS);
+
+ if (y_common != me)
+ programming_error ("combining skylines that don't belong to me");
+
+ Skyline_pair ret;
+ for (vsize i = 0; i < elements.size (); i++)
+ {
+ 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);
+ Skyline_pair other = *Skyline_pair::unsmob (skyline_scm);
+ other.raise (offset);
+ other.shift (elements[i]->relative_coordinate (x_common, X_AXIS));
+ ret.merge (other);
+ }
+ }
+ return ret.smobbed_copy ();
+}
+