- if (to_boolean (me->get_property ("quantize-position")))
- {
- Grob *common = me->common_refpoint (staff, Y_AXIS);
- Real my_off = me->relative_coordinate (common, Y_AXIS);
- Real staff_off = staff->relative_coordinate (common, Y_AXIS);
- Real ss = Staff_symbol::staff_space (staff);
- Real position = 2 * (my_off + o - staff_off) / ss;
- Real rounded = directed_round (position, dir);
- Grob *head = me->get_parent (X_AXIS);
-
- if (rounded <= 2 * Staff_symbol_referencer::staff_radius (me)
- || (Note_head::has_interface (head)
- && sign (Staff_symbol_referencer::get_position (head)) == - dir))
- {
- o += dir *(rounded - position) * 0.5 * ss;
- if (Staff_symbol_referencer::on_staffline (me, int (rounded)))
- o += dir * 0.5 * ss;
- }
- }
- else if (scm_is_number (me->get_property ("staff-padding")))
- {
- Real padding
- = Staff_symbol_referencer::staff_space (me)
- * scm_to_double (me->get_property ("staff-padding"));
-
- Grob *common = me->common_refpoint (staff, Y_AXIS);
-
- Interval staff_size = staff->extent (common, Y_AXIS);
- Real diff = dir*staff_size[dir] + padding - dir * (o + iv[-dir]);
- o += dir * max (diff, 0.0);
- }
+ if (quantize_position)
+ {
+ Grob *common = me->common_refpoint (staff, Y_AXIS);
+ Real my_off = me->get_parent (Y_AXIS)->maybe_pure_coordinate (common, Y_AXIS, pure, start, end);
+ Real staff_off = staff->maybe_pure_coordinate (common, Y_AXIS, pure, start, end);
+ Real ss = Staff_symbol::staff_space (staff);
+ Real position = 2 * (my_off + total_off - staff_off) / ss;
+ Real rounded = directed_round (position, dir);
+ Grob *head = me->get_parent (X_AXIS);
+
+ Interval staff_span = Staff_symbol::line_span (staff);
+ staff_span.widen (1);
+ if (staff_span.contains (position)
+ /* If we are between notehead and staff, quantize for ledger lines. */
+ || (has_interface<Note_head> (head)
+ && dir * position < 0))
+ {
+ total_off += (rounded - position) * 0.5 * ss;
+ if (Staff_symbol_referencer::on_line (me, int (rounded)))
+ total_off += dir * 0.5 * ss;
+ }
+ }
+ else if (scm_is_number (me->get_maybe_pure_property ("staff-padding", pure, start, end)) && dir)
+ {
+ Real staff_padding
+ = Staff_symbol_referencer::staff_space (me)
+ * scm_to_double (me->get_maybe_pure_property ("staff-padding", pure, start, end));
+
+ Grob *parent = me->get_parent (Y_AXIS);
+ Grob *common = me->common_refpoint (staff, Y_AXIS);
+ Real parent_position = parent->maybe_pure_coordinate (common, Y_AXIS, pure, start, end);
+ Real staff_position = staff->maybe_pure_coordinate (common, Y_AXIS, pure, start, end);
+ Interval staff_extent = staff->maybe_pure_extent (staff, a, pure, start, end);
+ Real diff = (dir * staff_extent[dir] + staff_padding
+ - dir * total_off
+ + dir * (staff_position - parent_position));
+ total_off += dir * max (diff, 0.0);
+ }