lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to really center a text above a note?


From: Neil Puttock
Subject: Re: How to really center a text above a note?
Date: Mon, 29 Jun 2009 18:10:09 +0100

2009/6/29 Trevor Bača <address@hidden>:

> ... is it possible that TextScripts *used to* have NoteHeads as grob-parents
> (at least in 2.9.16) and have since changed to have PaperColumns as grob
> parents, thus rendering the settings from 2.9.16 no longer functional?

Michael's correct.  The Text_engraver used to acknowledge rhythmic
heads (i.e., noteheads & rests) and set them as X or Y parent
depending on the side-support axis, but this code was removed in
2.11.15.

> Or is something else now going that would prevent calls to
> Self_alignment_interface::aligned_on_x_parent and centered_on_x_parent from
> working as they did previously?

The centring still works; it just that the text is anchored to the paper column.

What appears to be strange positioning makes more sense if you display
the paper columns (see attached image): in the centred case, the text
is centred on the origin of the paper column (where the blue arrow is
pointing).

With apologies to Michael, here's a simpler method for centring text
using a grob callback, which effectively does the same as your old
code by retrieving the notehead (or rest) from the PaperColumn then
mimicking the centered_on_x_parent callback:

textScriptCenterOnParent = \override TextScript #'X-offset =
#(lambda (grob)
   (let* (
          ;; get parent in X axis (a PaperColumn)
          (paper-col (ly:grob-parent grob X))
          ;; extract array of grobs attached to this column
          (elts (ly:grob-object paper-col 'elements))
          ;; could be an unsafe assumption, but the first
          ;; element should be a NoteHead or Rest
          (rhythmic-head (ly:grob-array-ref elts 0)))

     (+
      ;; read self-alignment-X
      (ly:self-alignment-interface::x-aligned-on-self grob)
      ;; equivalent to ly:self-alignment-interface::centered-on-x-parent,
      ;; but using the extracted notehead/rest instead of the paper column
      (interval-center
       (ly:grob-robust-relative-extent rhythmic-head rhythmic-head X)))))

Regards,
Neil

Attachment: aligned-to-papercolumn.png
Description: PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]