> Hi Lilypond users,

Hi Michael,

> in below example, I have replaced the text fonts.
> Now other fonts typically have a different size than the default Emmenthaler
> font. In below example, to match the default fonts size, I'd like to scale 
the
> serif and sans font by a factor of, say, x1.23. Only those two types. Not 
any
> global scaling like "set-global-staff-size" which would scale everything else 
as
> well...
> 
> Any idea how this could be achieved?

I would implement proper font matching. The issue here is that the size of the 
font is not well defined: The typical size we mean when we say 12pt is the 
height of the whole body used in moveable type — this makes sense in 
typography, as types with different body heights will not work out so well. But 
this means this is the total height available to the font. This has to 
incorporate also the space for descenders, ascenders and diacritics.

But these proportions are kind of different on each type, which is why certain 
combinations of types won’t work.

Now, in times of digital typography this makes less sense. Here the intuitive 
size is either the versal or lining height (that is the typical height of 
capital letters) or the medieval or x-height (the typical height of minuscles 
(though note that this is more of a design element rather than a strict 
height).

Matching font heights as it is done by fontspec is done by matching one of 
these two heights. In well paired fonts the choice of which to use does not 
really matter. But generally fonts created for typewriters and computer screens 
will have a bigger x-height (which we can actually see when comparing the 
default serif and sans fonts used by Lilypond, which have nothing in common, 
but also when comparing e.g. Linux Libertine and Linux Biolinum (as in your 
example), which are designed to be compatible).

Usually matching x-height is the preferred way to create the most even text. 
But if you have text that focusses on capital letters of course matching by 
lining height will be

The attached code uses a string-transformer to scale all text to match 
Lilypond’s default fonts either by lining height or x-height.

Cheers,
Tina
#(define (match-fonts layout props input-string)
   (let* ((match-mode (chain-assoc-get 'match-fonts-by props #f))
          (test-char (and match-mode (if (equal? match-mode 'lining) "H" "x")))
          (test-char-stc
           (and test-char
                (interpret-markup
                 layout
                 (cons
                  '(
                     (match-fonts-by . #f)
                     (font-size . 0)
                     (font-shape . upright)
                     (font-series . normal)
                     (font-encoding . latin1)
                     (font-variant . normal)
                   )
                  props)
                 test-char)))
          (test-char-height (and test-char-stc (cdr (ly:stencil-extent test-char-stc Y))))
          (ref (and match-mode (if (equal? match-mode 'lining) 1.5884640132874015 1.0252328186515747)))
          (scale (and match-mode (/ ref test-char-height))))
     (if scale
         (make-scale-markup (cons scale scale) input-string)
         input-string)))

\paper {
  property-defaults.string-transformers = #`(,ly:perform-text-replacements ,match-fonts)
  property-defaults.match-fonts-by = #'x
}

#(define-markup-command (select-font layout props family name mup) (symbol? string? markup?)
   #:properties ((fonts))
   (interpret-markup
    layout
    (cons `((fonts . ,(acons family name fonts))) props)
    mup))



\markup \override #'(match-fonts-by . #f) {
  Hx
  \select-font #'serif "Libertinus Serif" Hx
  \select-font #'sans "Libertinus Sans" Hx
  \sans Hx
  \typewriter Hx
}

\markup\vspace #0.5

\markup \override #'(match-fonts-by . lining) {
  Hx
  \select-font #'serif "Libertinus Serif" Hx
  \select-font #'sans "Libertinus Sans" Hx
  \sans Hx
  \typewriter Hx
}

\markup\vspace #0.5

\markup \override #'(match-fonts-by . x) {
  Hx
  \select-font #'serif "Libertinus Serif" Hx
  \select-font #'sans "Libertinus Sans" Hx
  \sans Hx
  \typewriter Hx
}


\markup\vspace #2


\markup \override #'(match-fonts-by . #f) {
  Lilypond \italic Serif
  \select-font #'serif "Libertinus Serif" { Libertinus \italic Serif }
  \select-font #'sans "Libertinus Sans" \sans { Libertinus \italic Sans }
  \sans { Lilypond \italic Sans }
  \typewriter { Lilypond \italic Typewriter }
}

\markup\vspace #0.5

\markup \override #'(match-fonts-by . lining) {
  Lilypond \italic Serif
  \select-font #'serif "Libertinus Serif" { Libertinus \italic Serif }
  \select-font #'sans "Libertinus Sans" \sans { Libertinus \italic Sans }
  \sans { Lilypond \italic Sans }
  \typewriter { Lilypond \italic Typewriter }
}

\markup\vspace #0.5

\markup \override #'(match-fonts-by . x) {
  Lilypond \italic Serif
  \select-font #'serif "Libertinus Serif" { Libertinus \italic Serif }
  \select-font #'sans "Libertinus Sans" \sans { Libertinus \italic Sans }
  \sans { Lilypond \italic Sans }
  \typewriter { Lilypond \italic Typewriter }
}


\markup\vspace #2


\markup \override #'(match-fonts-by . #f) {
  LILYPOND \italic SERIF
  \select-font #'serif "Libertinus Serif" { LIBERTINUS \italic SERIF }
  \select-font #'sans "Libertinus Sans" \sans { LIBERTINUS \italic SANS }
  \sans { LILYPOND \italic SANS }
  \typewriter { LILYPOND \italic TYPEWRITER }
}

\markup\vspace #0.5

\markup \override #'(match-fonts-by . lining) {
  LILYPOND \italic SERIF
  \select-font #'serif "Libertinus Serif" { LIBERTINUS \italic SERIF }
  \select-font #'sans "Libertinus Sans" \sans { LIBERTINUS \italic SANS }
  \sans { LILYPOND \italic SANS }
  \typewriter { LILYPOND \italic TYPEWRITER }
}

\markup\vspace #0.5

\markup \override #'(match-fonts-by . x) {
  LILYPOND \italic SERIF
  \select-font #'serif "Libertinus Serif" { LIBERTINUS \italic SERIF }
  \select-font #'sans "Libertinus Sans" \sans { LIBERTINUS \italic SANS }
  \sans { LILYPOND \italic SANS }
  \typewriter { LILYPOND \italic TYPEWRITER }
}

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to