lilypond-user
[Top][All Lists]
Advanced

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

Re: Access the first/last line of a markup


From: Aaron Hill
Subject: Re: Access the first/last line of a markup
Date: Mon, 11 Mar 2019 09:20:17 -0700
User-agent: Roundcube Webmail/1.3.8

On 2019-03-11 2:49 am, Urs Liska wrote:
Hi,

returning to my notorious "center-markup-over-measure" issue I was
pointed to yet another issue: vertical alignment when the last line
contains descenders or the first line does not contain ascenders.

Since I am manually placing the markups (given as arguments) using
ly:stencil-combine-at-edge above and below the staff I can't use
staff-padding for padding against the baseline. So what I *think* I
need is retrieving the first and last lines of the markup (which would
be the same if it's a single line markup) and analyze that. However,
that seems difficult. I checked with \displayMusic -\markup ... to see
if I could retrieve stuff from that expression, and although it seems
complicated-but-feasible for most cases it would fail with e.g.
\wordwrap because there's no notion of the resutling lines yet.

I can also access the resulting stencils after using
grob-interpret-markup. However, I have no idea if/how it is possible
to get to the information I need (either a "sub-stencil" for the
first/last line or some information through the stencil-extent).

Do you think there's any automatic solution I can pursue - or will I
be left manually adjusting the padding on a case-by-case basis?

Thanks for any suggestions

A *hack* using transparent glyphs to force alignment:

%%%%
\version "2.19.82"

#(define-markup-command (ascender-descender-placeholder layout props) ()
  (let* ((sten (interpret-markup layout props #{
            \markup \transparent \overlay { d p } #} ))
         (yex (ly:stencil-extent sten Y)))
    (ly:make-stencil (ly:stencil-expr sten) empty-interval yex)))

#(define-markup-command (apply-hack layout props arg) (markup?)
  (interpret-markup layout props #{ \markup \concat {
    \ascender-descender-placeholder $arg } #} ))

bad = -\tweak color #(rgb-color 0.9 0 0) \etc
good = -\tweak color #(rgb-color 0 0.8 0) \etc

{ \time 3/4
  f'4\bad^"d" _"d" f'4\bad^"x" \bad_"x" f'4^"p" \bad_"p"
  f'4\good^\markup \apply-hack "d" _\markup \apply-hack "d"
  f'4\good^\markup \apply-hack "x" \good_\markup \apply-hack "x"
  f'4^\markup \apply-hack "p" \good_\markup \apply-hack "p"
  f'2.^\markup \override #'(line-width . 35) \wordwrap \apply-hack
    { raucous racoon commune consume cocoa-cream macaroons }
  _\markup \override #'(line-width . 35) \wordwrap \apply-hack
    { museum owner unaware wax moose wears mauve mascara }
}
%%%%

This presumes that "d" and "p" are suitable exemplars of ascenders and descenders in the font being used.

If you want to visualize what is happening, replace "\transparent" in the markup command definition with something like "\with-color #blue".


-- Aaron Hill

Attachment: markup-alignment.cropped.png
Description: PNG image


reply via email to

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