Usage of ly:stencil-fonts ??

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Usage of ly:stencil-fonts ??

Thomas Morley-2
Hi,

in the IR one can find:
"
Function: ly:stencil-fonts s
Analyze s, and return a list of fonts used in s.
"

Though, how to get some output from it?

At least the code below returns nothing relevant.
(I used old syntax to check with all lily-version available, i.e.
since 2.12.3 up to 2.21.0)

#(use-modules (ice-9 pretty-print))

{
  \override NoteHead #'after-line-breaking =
  #(lambda (grob)
    ;(pretty-print (ly:stencil-expr (ly:grob-property grob 'stencil)))
    (write (ly:stencil-fonts (ly:grob-property grob 'stencil))))

  c'1

  \override TextScript #'after-line-breaking =
  #(lambda (grob)
    ;(pretty-print (ly:stencil-expr (ly:grob-property grob 'stencil)))
    (write (ly:stencil-fonts (ly:grob-property grob 'stencil))))
  s-\markup \number "1"
}

Something wrong with my code? Or stopped it working long time ago? Did
it ever work?
(I found not a single usage)

Afaict, ly:stencil-fonts was last changed with

 commit 7a6c3f44dad456a55a4d67c8647332d16022e7d1
 Author: Han-Wen Nienhuys <[hidden email]>
 Date:   Fri Jan 7 12:40:11 2005 +0000

     *** empty log message ***

Any hints?

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Usage of ly:stencil-fonts ??

Torsten Hämmerle
Hi Harm,

As it looks like, this function has not been working for some time, I've
tested it back to 2.14.2

What does it do?

In lily/stencil-interpret.cc, the function find_expression_fonts gets a
scheme variable called expr with the following contents:


*(A) in your NoteHead example:*

(named-glyph #<Font_metric ("emmentaler-20" . 0.569055118110236)>
noteheads.s0)

-> Font_metric contains "Emmentaler-20"


*(B) I've changed the TextScript example to \markup \italic "italic"*

Now, the expressiong gets a bit convoluted, but there's still a
<Font_metric> information contained (but with font-name #f and dummy size
1.0), but there still are font names in the glyph-string (this time it is
"TeXGyreSchola-Italic")

(translate-stencil (0.0 . 0.0) (glyph-string #<Font_metric (#f . 1.0)>
TeXGyreSchola-Italic 3.865234375 #f (quote ((0.717009448818898
(-0.0341433070866142 . 1.4340188976378) 0.0 0.0 i) (0.785296062992126
(-0.0341433070866142 . 1.36573228346457) 0.0 0.0 t) (1.26330236220472
(-0.0341433070866142 . 1.02429921259843) 0.0 0.0 a) (0.717009448818898
(-0.0341433070866142 . 1.60473543307087) 0.0 0.0 l) (0.717009448818898
(-0.0341433070866142 . 1.4340188976378) 0.0 0.0 i) (0.990155905511811
(-0.0341433070866142 . 1.05844251968504) 0.0 0.0 c)))))


It calls function *interpret_stencil_expression* and (in our two cases),
"named-glyph" and "glyph-string" should use function *find_font_function*

But this function just takes care of "text" and "char".

Unfortunately, we have "named-glyph" and "glyph-string" instead (I think
font handling has considerably changed in the meantime), so that the
function returns nothing.


*Experimental correction*

When implementing "named-glyph" (giving back cadr) and "glyph-string"
(giving back caddr), we actually get

(#<Font_metric ("emmentaler-20" . 0.569055118110236)>) for the NoteHead and
("TeXGyreSchola-Italic") for the TextScript in a first simple attempt.

With just your \number "1" example, TextScript will report ("Emmentaler-20")

So, basically, the information is there and it could be done.
But this looks like a tracker issue, because, as you found out, the function
currently just does nothing where it should give back a result.

All the best,
Torsten






--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Usage of ly:stencil-fonts ??

Thomas Morley-2
Hi Torsten,
Am So., 21. Okt. 2018 um 17:17 Uhr schrieb Torsten Hämmerle
<[hidden email]>:
>
> Hi Harm,
>
> As it looks like, this function has not been working for some time, I've
> tested it back to 2.14.2

I even checked with 2.12.3 (without useful result)

> What does it do?
>
> In lily/stencil-interpret.cc, the function find_expression_fonts gets a
> scheme variable called expr with the following contents:
>
>
> *(A) in your NoteHead example:*
>
> (named-glyph #<Font_metric ("emmentaler-20" . 0.569055118110236)>
> noteheads.s0)
>
> -> Font_metric contains "Emmentaler-20"
>
>
> *(B) I've changed the TextScript example to \markup \italic "italic"*
>
> Now, the expressiong gets a bit convoluted, but there's still a
> <Font_metric> information contained (but with font-name #f and dummy size
> 1.0), but there still are font names in the glyph-string (this time it is
> "TeXGyreSchola-Italic")
>
> (translate-stencil (0.0 . 0.0) (glyph-string #<Font_metric (#f . 1.0)>
> TeXGyreSchola-Italic 3.865234375 #f (quote ((0.717009448818898
> (-0.0341433070866142 . 1.4340188976378) 0.0 0.0 i) (0.785296062992126
> (-0.0341433070866142 . 1.36573228346457) 0.0 0.0 t) (1.26330236220472
> (-0.0341433070866142 . 1.02429921259843) 0.0 0.0 a) (0.717009448818898
> (-0.0341433070866142 . 1.60473543307087) 0.0 0.0 l) (0.717009448818898
> (-0.0341433070866142 . 1.4340188976378) 0.0 0.0 i) (0.990155905511811
> (-0.0341433070866142 . 1.05844251968504) 0.0 0.0 c)))))
>

Yep, (A) and (B) is the the stencil-expression.
It's what you get, after uncommenting the lines starting with
(pretty-print (ly:stencil-expr ...
in my example-code.

>
> It calls function *interpret_stencil_expression* and (in our two cases),
> "named-glyph" and "glyph-string" should use function *find_font_function*
>
> But this function just takes care of "text" and "char".
>
> Unfortunately, we have "named-glyph" and "glyph-string" instead (I think
> font handling has considerably changed in the meantime), so that the
> function returns nothing.
>
>
> *Experimental correction*
>
> When implementing "named-glyph" (giving back cadr) and "glyph-string"
> (giving back caddr), we actually get
>
> (#<Font_metric ("emmentaler-20" . 0.569055118110236)>) for the NoteHead and
> ("TeXGyreSchola-Italic") for the TextScript in a first simple attempt.
>
> With just your \number "1" example, TextScript will report ("Emmentaler-20")
>
> So, basically, the information is there and it could be done.
> But this looks like a tracker issue, because, as you found out, the function
> currently just does nothing where it should give back a result.

Agreed, I'll put up a tracker issue.

Some background:

I'm pretty sure I can get the used fonts from (ly:stencil-expr
some-stencil), though this is tedious (I did similar before) and I
hoped ly:stencil-fonts could do the work for me ;)

My goal would be to understand how exatly in/decreased fonts affect
the final stencil and how to get this info out of a given stencil
compared to a default font size.

As an intermediate step, look at the stencil-expression from:

\markup "g"

You'll get:

(translate-stencil
  (0.0 . 0.0)
  (glyph-string
    #<Font_metric (#f . 1.0)>
    "TeXGyreSchola-Regular"
    3.865234375
    #f
    '((1.1950157480315
       (-0.443862992125984 . 1.09258582677165)
       0.0
       0.0
       "g"))))

I like to understand the numerical values.
The pair (-0.443862992125984 . 1.09258582677165) seems to be the
extent in Y-axis.

But what about 3.865234375 and 1.1950157480315?

Any hints?

Thanks.
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Usage of ly:stencil-fonts ??

Torsten Hämmerle
Thomas Morley-2 wrote
> I like to understand the numerical values.
> The pair (-0.443862992125984 . 1.09258582677165) seems to be the
> extent in Y-axis.
>
> But what about 3.865234375 and 1.1950157480315?

Hi Harm,

*The 3.865234375 is the font size (in millimetres!)*
Converting this into pt (1 inch = 72.27 pt = 25.4 mm), you'll end up with
the standard 11pt fontsize.
These font sizes are always (!) absolute and never depend on
global-staff-size etc.

*The 1.1950157480315 is the running width of the character*

HTH,
Torsten



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Usage of ly:stencil-fonts ??

Thomas Morley-2
Hi Torsten,

I've created
https://sourceforge.net/p/testlilyissues/issues/5430/
Am So., 21. Okt. 2018 um 21:33 Uhr schrieb Torsten Hämmerle
<[hidden email]>:

>
> Thomas Morley-2 wrote
> > I like to understand the numerical values.
> > The pair (-0.443862992125984 . 1.09258582677165) seems to be the
> > extent in Y-axis.
> >
> > But what about 3.865234375 and 1.1950157480315?
>
> Hi Harm,
>
> *The 3.865234375 is the font size (in millimetres!)*
> Converting this into pt (1 inch = 72.27 pt = 25.4 mm), you'll end up with
> the standard 11pt fontsize.
> These font sizes are always (!) absolute and never depend on
> global-staff-size etc.
>
> *The 1.1950157480315 is the running width of the character*

Though, I still don't get it.
Tbh, I'm more the opposite of a font-nerd, but I've tried  the code below:

#(define-markup-command (check layout props arg)(markup?)
  (let ((o-s (ly:output-def-lookup layout 'output-scale))
        (ancestor-o-s (ly:output-def-lookup $defaultlayout 'output-scale))
        (pt (ly:output-def-lookup layout 'pt))
        (ancestor-pt (ly:output-def-lookup $defaultlayout 'pt))
        ;(t-f-d (ly:output-def-lookup layout 'text-font-defaults))
        (t-f-s (ly:output-def-lookup layout 'text-font-size))
        (ancestor-t-f-s (ly:output-def-lookup $defaultlayout 'text-font-size))
        (stil (interpret-markup layout props arg))
  )
    (format #t "\noutput-scale: ~a" o-s)
    (format #t "\nancestor-output-scale: ~a" ancestor-o-s)
    (newline)
    (format #t "\npt: ~a" pt)
    (format #t "\nancestor-pt: ~a" ancestor-pt)
    (newline)
    (format #t "\ntext-font-size: ~a" t-f-s)
    (format #t "\nancestor-text-font-size: ~a" ancestor-t-f-s)
    (newline)
    (format #t "\nfont-design-size from current layout (same as
ancestor-pt): ~a"
      (ly:font-design-size (ly:paper-get-font layout props)))
    (newline)
    ;; this list selection has no security net, too lazy ...
    (format #t "\nfont and size (in mm) from stencil-expr: ~y"
      (take (drop (cdaddr (ly:stencil-expr stil)) 1) 2))

    (display (ly:output-def-lookup layout 'font-size))
    (display "\n#########################################\n")


    stil
    ))

\markup \check "g"
\markup \check \fontsize #2 "Ŏ"

It returns all sort of values, but I found no arithmetic how I can get
to the numerical number for the mm-font-size from the
stencil-expression.

Do you have some further hints?


Thanks,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Usage of ly:stencil-fonts ??

Torsten Hämmerle
Hi Harm,

All these numbers are quite confusing at first glance. And at second and
third glance, too.
But they are nothing but conversion factors to switch units.
And, unfortunately, LilyPond basically uses three concurrent units in
parallel:

- LilyPond units in staff-spaces
- Pango units in mm
- Typographic units in pt


This said, I'll try to derive all the values you have found using the
example of a standard 20-pt-staff with the corresponding standard text font
size of 11pt.
I will use a ridiculous number of decimal places to make it easier to
compare the results to your scheme output.

As LilyPond is a European program, there are no inches to be seen and we'll
only use mm (millimetres).
Both mm and pt are always absolute units (as printed on the final sheet),
whereas a staff-space (let's call it 1sp) is always relative (depending on
the current staff-size).



pt value: conversion between pt and sp

The 'pt values are the conversion factor from pt to staff-spaces:
A 5-line 20-pt staff is 4sp high ==> 20pt = 4sp, in other words:

1pt = 0.2sp (resp: 'pt = 0.2)

See? Multiply any value in pt by 'pt and you'll get staff-spaces.

With a 10-pt staff, we get 'pt = 0.4 so that you have to multiply any
pt-value by 0.4 to get the corresponding value in staff-spaces. The factor
has to be twice as big because a 10pt staff is half the size of a 20pt
staff.

 
ancestor-pt value: conversion between pt and mm

In markup (i.e. font environment), Pango fonts (metrics and size in mm!)
come into play.

This factor does not change when varying global-staff-size or anything,
because both pt and mm are absolute units and the conversion factor always
stays the same. Knowing how many mm or pt are in an inch, it's easy to
derive the factor:
1in = 25.4mm
1in = 72.27pt

1pt = 0.3514598035145980351459803514598 mm
This is your ancestor-pt value. :)

Our standard 11pt-font therefore will be 3.8660578386605783... mm in size
*Caveat:* the Pango font size from stencil-expr is not quite that, because
there is some rounding applied to avoid buffering too many fonts with with
microscopic size differences.


text-font-size: Just the actual font size in pt

The text-font-size displayed for a 20pt staff is 11pt (as suspected).
When setting global-staff-size to 10pt, text-font-size will consequently
only be half as big: 5.5pt.


font and size form stencil-expr

This is, as usual, the font size in (absolute) mm, but slightly quantized to
avoid the buffering of too many differently-sized fonts with only
microscopic font size differences.

3.865234375 is about what we'd expect for a standard 11pt font, applying
\fontsize #2 will change this by a factor of 2^(2/6) = 1.2599210498 so that
we get a
4.870927651... as reported (slight quanting/rounding effects).


output-scale: converting staff-spaces into mm

Finally, the output-scale factor is needed to transform LilyPond metrics (or
\translate #'(a . b) operations) from staff spaces to Pango mm.


In a 20pt standard stave, four staff-spaces will make up the 20pt, i.e. 1sp
= 5pt.
Using the pt-to-mm conversion factor (we want mm for Pango!), one
staff-space is
1sp = 5pt = 1.7572990175... mm (that's your output-scale).

If we change the staff-size to 16pt, we get
1pt = 4pt = 1,4058392... as output-scale.


That's about all, I think…

HTH,
Torsten



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Usage of ly:stencil-fonts ??

Thomas Morley-2
Am Mo., 22. Okt. 2018 um 21:59 Uhr schrieb Torsten Hämmerle
<[hidden email]>:

>
> Hi Harm,
>
> All these numbers are quite confusing at first glance. And at second and
> third glance, too.
> But they are nothing but conversion factors to switch units.
> And, unfortunately, LilyPond basically uses three concurrent units in
> parallel:
>
> - LilyPond units in staff-spaces
> - Pango units in mm
> - Typographic units in pt
>
>
> This said, I'll try to derive all the values you have found using the
> example of a standard 20-pt-staff with the corresponding standard text font
> size of 11pt.
> I will use a ridiculous number of decimal places to make it easier to
> compare the results to your scheme output.
>
> As LilyPond is a European program, there are no inches to be seen and we'll
> only use mm (millimetres).
> Both mm and pt are always absolute units (as printed on the final sheet),
> whereas a staff-space (let's call it 1sp) is always relative (depending on
> the current staff-size).
>
>
>
> pt value: conversion between pt and sp
>
> The 'pt values are the conversion factor from pt to staff-spaces:
> A 5-line 20-pt staff is 4sp high ==> 20pt = 4sp, in other words:
>
> 1pt = 0.2sp (resp: 'pt = 0.2)
>
> See? Multiply any value in pt by 'pt and you'll get staff-spaces.
>
> With a 10-pt staff, we get 'pt = 0.4 so that you have to multiply any
> pt-value by 0.4 to get the corresponding value in staff-spaces. The factor
> has to be twice as big because a 10pt staff is half the size of a 20pt
> staff.
>
>
> ancestor-pt value: conversion between pt and mm
>
> In markup (i.e. font environment), Pango fonts (metrics and size in mm!)
> come into play.
>
> This factor does not change when varying global-staff-size or anything,
> because both pt and mm are absolute units and the conversion factor always
> stays the same. Knowing how many mm or pt are in an inch, it's easy to
> derive the factor:
> 1in = 25.4mm
> 1in = 72.27pt
>
> 1pt = 0.3514598035145980351459803514598 mm
> This is your ancestor-pt value. :)
>
> Our standard 11pt-font therefore will be 3.8660578386605783... mm in size
> *Caveat:* the Pango font size from stencil-expr is not quite that, because
> there is some rounding applied to avoid buffering too many fonts with with
> microscopic size differences.
>
>
> text-font-size: Just the actual font size in pt
>
> The text-font-size displayed for a 20pt staff is 11pt (as suspected).
> When setting global-staff-size to 10pt, text-font-size will consequently
> only be half as big: 5.5pt.
>
>
> font and size form stencil-expr
>
> This is, as usual, the font size in (absolute) mm, but slightly quantized to
> avoid the buffering of too many differently-sized fonts with only
> microscopic font size differences.
>
> 3.865234375 is about what we'd expect for a standard 11pt font, applying
> \fontsize #2 will change this by a factor of 2^(2/6) = 1.2599210498 so that
> we get a
> 4.870927651... as reported (slight quanting/rounding effects).
>
>
> output-scale: converting staff-spaces into mm
>
> Finally, the output-scale factor is needed to transform LilyPond metrics (or
> \translate #'(a . b) operations) from staff spaces to Pango mm.
>
>
> In a 20pt standard stave, four staff-spaces will make up the 20pt, i.e. 1sp
> = 5pt.
> Using the pt-to-mm conversion factor (we want mm for Pango!), one
> staff-space is
> 1sp = 5pt = 1.7572990175... mm (that's your output-scale).
>
> If we change the staff-size to 16pt, we get
> 1pt = 4pt = 1,4058392... as output-scale.
>
>
> That's about all, I think…
>
> HTH,
> Torsten

Hi Torsten,

thanks for all the info, I'll need to study it thoroughly.

Btw, I meanwhile got LilyPond 2.8.8 working in an old LilyDev.
With this ancient version ly:stencil-fonts always returns '() as well.

Thanks,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user