[Top][All Lists]

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

Re: Determine Length of a markup

From: Aaron Hill
Subject: Re: Determine Length of a markup
Date: Thu, 10 Dec 2020 17:51:21 -0800
User-agent: Roundcube Webmail/1.4.9

On 2020-12-10 3:35 pm, Valentin Petzel wrote:

I’m trying to calculate the width of a InstrumentName markup to automatically set the indent. Some time ago I somewhat managed to do an interpretMarkup by
looking up layout and parser, but I cannot remember, how I did it.

So maybe someone of you guys has a decent way of doing this?

This seems to work:

\version "2.20.0"

measureMarkup =
  (axis text)
  ((number? X) markup?)
  (let* ((layout (ly:parser-lookup '$defaultpaper))
         (props (ly:output-def-lookup layout 'text-font-defaults))
         (sten (interpret-markup layout (list props) text)))
    (* (interval-length (ly:stencil-extent sten axis))
       (ly:output-def-lookup layout 'staff-space))))

foo = \markup \box \pad-x #2 \italic "Lorem ipsum"
\paper { indent = \measureMarkup \foo }
\new Staff \with { instrumentName = \foo }
{ \repeat unfold 16 { b'4 4 2 } \bar "|." }

-- Aaron Hill

reply via email to

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