- 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));
+ Grob *g = elts[i];
+
+ if (to_boolean (g->get_property ("cross-staff")))
+ continue;
+
+ bool outside_staff = scm_is_number (g->get_property ("outside-staff-priority"));
+ Real padding = robust_scm2double (g->get_property ("outside-staff-padding"), 0.5);
+
+ // When we encounter the first outside-staff grob, make a copy
+ // of the current heights to use as an estimate for the staff heights.
+ // Note that the outside-staff approximation that we use here doesn't
+ // consider any collisions that might occur between outside-staff grobs,
+ // but only the fact that outside-staff grobs may need to be raised above
+ // the staff.
+ if (outside_staff && begin_line_staff_heights.empty ())
+ {
+ begin_line_staff_heights = begin_line_heights;
+ mid_line_staff_heights = mid_line_heights;
+ }
+
+ // TODO: consider a pure version of get_grob_direction?
+ Direction d = to_dir (g->get_property_data ("direction"));
+ d = (d == CENTER) ? UP : d;
+
+ Interval_t<int> rank_span = g->spanned_rank_interval ();
+ vsize first_break = lower_bound (ranks, (vsize)rank_span[LEFT], less<vsize> ());
+ if (first_break > 0 && ranks[first_break] >= (vsize)rank_span[LEFT])
+ first_break--;
+
+ for (vsize j = first_break; j + 1 < ranks.size () && (int)ranks[j] <= rank_span[RIGHT]; ++j)
+ {
+ int start = ranks[j];
+ int end = ranks[j + 1];
+
+ // Take grobs that are visible with respect to a slightly longer line.
+ // Otherwise, we will never include grobs at breakpoints which aren't
+ // end-of-line-visible.
+ int visibility_end = j + 2 < ranks.size () ? ranks[j + 2] : end;
+
+ if (g->pure_is_visible (start, visibility_end))
+ {
+ Interval dims = g->pure_height (common, start, end);
+ if (!dims.is_empty ())
+ {
+ if (rank_span[LEFT] <= start)
+ {
+ if (outside_staff)
+ begin_line_heights[j].unite (begin_line_staff_heights[j].union_disjoint (dims, padding, d));
+ else
+ begin_line_heights[j].unite (dims);
+ }
+ if (rank_span[RIGHT] > start)
+ {
+ if (outside_staff)
+ mid_line_heights[j].unite (mid_line_staff_heights[j].union_disjoint (dims, padding, d));
+ else
+ mid_line_heights[j].unite (dims);
+ }
+ }
+ }
+ }