- Flags are always aligned with staff lines, so we need to check the end point
- of the stem: For stems ending on staff lines, use different flags than for
- notes between staff lines. The idea is that flags are always vertically
- aligned with the staff lines, regardless of whether the note head is on a
- staff line or between two staff lines. In other words, the inner end of
- a flag always touches a staff line."
-
- (let* ((adjust #t)
- (stem-end (inexact->exact (round (ly:grob-property stem-grob 'stem-end-position))))
+Flags are always aligned with staff lines, so we need to check the end point
+of the stem: For stems ending on staff lines, use different flags than for
+notes between staff lines. The idea is that flags are always vertically
+aligned with the staff lines, regardless of whether the note head is on a
+staff line or between two staff lines. In other words, the inner end of
+a flag always touches a staff line."
+
+ (let* ((stem-grob (ly:grob-parent grob X))
+ (adjust #t)
+ (d (ly:grob-property stem-grob 'direction))
+ (ss (ly:staff-symbol-staff-space stem-grob))
+ (stem-end (inexact->exact (round (* (index-cell
+ (ly:grob-extent stem-grob
+ stem-grob
+ Y)
+ d)
+ (/ 2 ss)))))