Hello Valentin, I looked at the src code as well. I don't see an easy way to by-pass the problem, given that ly:font-config-get-font-file is bound to a C++ code that can't be dynamically overridden. In addition, The procedure explained in
http://lilypond.org/doc/v2.21/Documentation/notation/fonts#single-entry-fonts even if it does work, it appears a bit misleading to me, because it requires to set the font-name attribute with a string which doesn't represent the name of the font, because it can include the style attributes as well. IMHO, replacing: \override #'(font-name . "Bitstream Vera Sans, sans-serif, Oblique Bold") with \override #'(font-formatted-class . "Bitstream Vera Sans, sans-serif, Oblique Bold") Would be more appropriate (maybe there are better strings than "font-formatted-class", but you get the idea). However, I can image that this would be not a trivial change to the current API. In any case, given a string that represents the class of the font (name + other attributes), I can't find a function that can parse this string and consequently finds the associated font-file. In fact #(ly:font-config-get-font-file str) accepts only the name of the font. Then, until we find a way to A) parse the complete string AND B) check if the corresponding font is really found, when I want to set fonts for my score I can only do the following procedure, which is long, unsafe and laborious: 1) I choose a font with some system fonts viewer, then check if it is included in the list obtained with -dshow-available-fonts (this is laborious: it would be better to have a sort of "font viewer" already bound to LilyPond) 2) I Inspect the properties of the chosen font with the above command, so to manually create a string that represents it (i.e: "Bitstream Vera Sans, sans-serif, Oblique Bold") and then set font-name with that string (this is unsafe, because there's not a way to check if the font is installed) 3) Get the file of the font with ly:font-config-get-font-file, and then feed a function like \checkFontFile font-name font-file-name (see the snippet below): this is tedious but necessary too, because if we compile a score on a different OS than the original one, it can raise a warning if the font is not found. And this is error-prone too: for example, for "Liberation Sans, Italic", I got the LiberationSansNarrow-Regular.ttf file, which can be misleading. If we solve at least the above A and B problems, the procedure is much simplified. Please let me know if you have any idea about it, or an alternative. It would be really useful to have a proper way to manage these things. Best, Paolo %%%%%%%%%%%%%% checkFontFile = #(define-scheme-function (parser location fontName fontFile) (string? string?) (let ((warning (not (string-contains (ly:font-config-get-font-file fontName) fontFile)))) (if warning (begin (display "\nwarning: font '") (display fontFile) (display "' not found!\n") ) ) )) %%%%%%%%%%%%%% On Sun, Nov 21, 2021 at 9:32 PM Valentin Petzel <[email protected]> wrote: > Hello Paolo, > > After looking into this it seems like this is intended behaviour for font- > config. Basically this does not perform an exact match, but calculates > some > distance and returns the font with best distance. Maybe it would be > somehow > possible to get that distance and decide upon it? > > Cheers, > Valentin > > Am Sonntag, 21. November 2021, 21:06:15 CET schrieb Paolo Prete: > > Thank you Valentin, a fix for this would be very useful. > > Best, > > Paolo > > > > On Sun, Nov 21, 2021 at 8:52 PM Valentin Petzel <[email protected]> > wrote: > > > Hello Paolo, > > > > > > Theoretically it should be enough to check if > > > #(ly:font-config-get-font-file > > > font-name) is false, but at least on my system this returns just some > > > arbitrary but fixed font file if the font is not found. It should > > > definitely > > > not behave this way, gotta look into this. > > > > > > Cheers, > > > Valentin
