Re: Check if a font is currently installed
Hello Paolo, If you want to do this for any font you’ll have no other option but to basically do what font-config does, and that is to try to estimate how distant two font names are. I would be very useful if we could get font-config to give us the actual distance. Cheers, Valentin Am Dienstag, 23. November 2021, 00:15:37 CET schrieb Paolo Prete: > Hello Valentin, > > >From what I understand, your procedure relies on the convention that the > > name of the font file has to be very similar to the descriptive name of the > font; unfortunately, this adds unsafety to the procedure I wrote before > (which is already unsafe), even if it shortens that procedure a bit. > I think that the only way to have a reliable check is to parse the > configured name. > An additional C++ helper function, wrapped by Scheme, is highly useful IMHO > (and maybe it should require few lines of additional code), but I wonder as > well if a solution can be found for the last stable versions of LilyPond > too. I have to meditate about it... > > Best, > Paolo > > On Mon, Nov 22, 2021 at 11:31 PM Valentin Petzel wrote: > > Hello Paolo, > > > > This behaviour actually comes from font-config and not from Lilypond. It > > is > > somewhat sensible, since we want to be able to specify a font intuitively > > and > > not by some set identifier. > > > > One hacky way to get what you want if you are checking for very specific > > fonts > > could be this, which would be checking the font file for some string we’d > > expect to find in it. > > > > Cheers, > > Valentin signature.asc Description: This is a digitally signed message part.
Re: Check if a font is currently installed
Hello Valentin, >From what I understand, your procedure relies on the convention that the name of the font file has to be very similar to the descriptive name of the font; unfortunately, this adds unsafety to the procedure I wrote before (which is already unsafe), even if it shortens that procedure a bit. I think that the only way to have a reliable check is to parse the configured name. An additional C++ helper function, wrapped by Scheme, is highly useful IMHO (and maybe it should require few lines of additional code), but I wonder as well if a solution can be found for the last stable versions of LilyPond too. I have to meditate about it... Best, Paolo On Mon, Nov 22, 2021 at 11:31 PM Valentin Petzel wrote: > Hello Paolo, > > This behaviour actually comes from font-config and not from Lilypond. It > is > somewhat sensible, since we want to be able to specify a font intuitively > and > not by some set identifier. > > One hacky way to get what you want if you are checking for very specific > fonts > could be this, which would be checking the font file for some string we’d > expect to find in it. > > Cheers, > Valentin
Re: Check if a font is currently installed
> On 22 Nov 2021, at 23:31, Valentin Petzel wrote: > > Hello Paolo, > > This behaviour actually comes from font-config and not from Lilypond. It is > somewhat sensible, since we want to be able to specify a font intuitively and > not by some set identifier. Somewhat sensible… but someone should teach Fontconfig some manners… aikebah@Rajah Trial % fc-match "Clearface Gothic LT Std" ClearfaceGothicLTStd-Roman.otf: "Clearface Gothic LT Std" "55 Roman" aikebah@Rajah Trial % fc-match "Clearface Gothic LT" Verdana.ttf: "Verdana" "Regular" I would consider "Clearface Gothic LT Std” a MUCH better match than Verdana, but fontconfig disagrees So I can also perfectly see the sense in Paolo’s quest for checking if the selected font appears to be what he attempted to configure. > > One hacky way to get what you want if you are checking for very specific > fonts > could be this, which would be checking the font file for some string we’d > expect to find in it. > > Cheers, > Valentin
Re: Check if a font is currently installed
Hello Paolo, This behaviour actually comes from font-config and not from Lilypond. It is somewhat sensible, since we want to be able to specify a font intuitively and not by some set identifier. One hacky way to get what you want if you are checking for very specific fonts could be this, which would be checking the font file for some string we’d expect to find in it. Cheers, Valentin#(define path1 (ly:font-config-get-font-file "TeX Gyre Schola")) #(define path2 (ly:font-config-get-font-file "nonsense")) #(define (read-line port) (define (iterator prev) (let ((char (read-char port))) (if (or (eof-object? char) (equal? char #\nl)) (if (and (eof-object? char) (null? prev)) 'eof prev) (iterator (cons char prev) (let ((rev-list (iterator '( (if (equal? rev-list 'eof) 'eof (list->string (reverse rev-list) #(define (file-contains? path expr) (define (iterator port) (let ((line (read-line port))) (if (equal? line 'eof) #f (if (string-contains line expr) #t (iterator port) (iterator (open-input-file path))) #(display (file-contains? path1 "TeXGyreSchola")) #(display (file-contains? path2 "nonsense")) signature.asc Description: This is a digitally signed message part.
Re: Check if a font is currently installed
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 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 > 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
Re: Check if a font is currently installed
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 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 signature.asc Description: This is a digitally signed message part.
Re: Check if a font is currently installed
Thank you Valentin, a fix for this would be very useful. Best, Paolo On Sun, Nov 21, 2021 at 8:52 PM Valentin Petzel 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 > >
Re: Check if a font is currently installed
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 Am Sonntag, 21. November 2021, 19:12:33 CET schrieb Paolo Prete: > Sorry, it doesn't help. > It just shows a long list of the available fonts. > Not what I was searching for... > Best, > P > > On Sun, Nov 21, 2021 at 6:37 PM David Wright > > wrote: > > On Sun 21 Nov 2021 at 17:29:37 (+0100), Paolo Prete wrote: > > > it would be useful to have a functions that checks if a font with a > > > specific font-name is currently installed, so to have the produced score > > > without visual errors that are not always easy to detect. > > > > Would the list produced by this snippet help? I can't help you > > parse the output as I'm not a scheme programmer. > > > > > I searched a bit in the list of the scheme helper functions, and could > > > > find > > > > > only: > > > > > > ly:font-config-get-font-file font-name > > > > > > However, in case the file is not found, it defaults to some font that (I > > > suppose) is OS dependent, then I don't know how to check if the > > > searched > > > font is really installed. Any idea about this? > > > > Cheers, > > David. signature.asc Description: This is a digitally signed message part.
Re: Check if a font is currently installed
What I mean is that a font-name attribute can be in the form: "Bitstream Vera Sans, sans-serif, Oblique Bold" If you want to check that the font-name is accepted, you have to inspect the output of the list and then see if it can be a valid combination of font + style attributes (see: http://lilypond.org/doc/v2.21/Documentation/notation/fonts#single-entry-fonts ) This is not what I was searching for. I would like to automatize this check, so to prevent LilyPond to compile the score (or raise a warning) if the font is not found, with a function like: \checkFont "Bitstream Vera Sans, sans-serif, Oblique Bold" (ly:font-config-get-font-file font-name) appears the only scheme function candidate for this, but unfortunately it defaults to some system font when the wanted font-name does not correspond to any file. Best, P On Sun, Nov 21, 2021 at 7:38 PM David Wright wrote: > On Sun 21 Nov 2021 at 19:12:33 (+0100), Paolo Prete wrote: > > On Sun, Nov 21, 2021 at 6:37 PM David Wright wrote: > > > On Sun 21 Nov 2021 at 17:29:37 (+0100), Paolo Prete wrote: > > > > > > > > it would be useful to have a functions that checks if a font with a > > > > specific font-name is currently installed, so to have the produced > score > > > > without visual errors that are not always easy to detect. > > > > > > Would the list produced by this snippet help? I can't help you > > > parse the output as I'm not a scheme programmer. > > > > > > > I searched a bit in the list of the scheme helper functions, and > could > > > find only: > > > > > > > > ly:font-config-get-font-file font-name > > > > > > > > However, in case the file is not found, it defaults to some font > that (I > > > > suppose) is OS dependent, then I don't know how to check if the > searched > > > > font is really installed. Any idea about this? > > > > > Sorry, it doesn't help. > > It just shows a long list of the available fonts. > > Not what I was searching for... > > Does that mean that your 'specific font-name' would not appear in > that long list of available fonts, or that if it appeared, that still > wouldn't be a sufficient indication that what you wanted from that > font was actually available, ie some attribute might not be present. > > Cheers, > David. >
Re: Check if a font is currently installed
On Sun 21 Nov 2021 at 19:12:33 (+0100), Paolo Prete wrote: > On Sun, Nov 21, 2021 at 6:37 PM David Wright wrote: > > On Sun 21 Nov 2021 at 17:29:37 (+0100), Paolo Prete wrote: > > > > > > it would be useful to have a functions that checks if a font with a > > > specific font-name is currently installed, so to have the produced score > > > without visual errors that are not always easy to detect. > > > > Would the list produced by this snippet help? I can't help you > > parse the output as I'm not a scheme programmer. > > > > > I searched a bit in the list of the scheme helper functions, and could > > find only: > > > > > > ly:font-config-get-font-file font-name > > > > > > However, in case the file is not found, it defaults to some font that (I > > > suppose) is OS dependent, then I don't know how to check if the searched > > > font is really installed. Any idea about this? > > > Sorry, it doesn't help. > It just shows a long list of the available fonts. > Not what I was searching for... Does that mean that your 'specific font-name' would not appear in that long list of available fonts, or that if it appeared, that still wouldn't be a sufficient indication that what you wanted from that font was actually available, ie some attribute might not be present. Cheers, David.
Re: Check if a font is currently installed
Sorry, it doesn't help. It just shows a long list of the available fonts. Not what I was searching for... Best, P On Sun, Nov 21, 2021 at 6:37 PM David Wright wrote: > On Sun 21 Nov 2021 at 17:29:37 (+0100), Paolo Prete wrote: > > > > it would be useful to have a functions that checks if a font with a > > specific font-name is currently installed, so to have the produced score > > without visual errors that are not always easy to detect. > > Would the list produced by this snippet help? I can't help you > parse the output as I'm not a scheme programmer. > > > I searched a bit in the list of the scheme helper functions, and could > find > > only: > > > > ly:font-config-get-font-file font-name > > > > However, in case the file is not found, it defaults to some font that (I > > suppose) is OS dependent, then I don't know how to check if the searched > > font is really installed. Any idea about this? > > Cheers, > David. >
Re: Check if a font is currently installed
On Sun 21 Nov 2021 at 17:29:37 (+0100), Paolo Prete wrote: > > it would be useful to have a functions that checks if a font with a > specific font-name is currently installed, so to have the produced score > without visual errors that are not always easy to detect. Would the list produced by this snippet help? I can't help you parse the output as I'm not a scheme programmer. > I searched a bit in the list of the scheme helper functions, and could find > only: > > ly:font-config-get-font-file font-name > > However, in case the file is not found, it defaults to some font that (I > suppose) is OS dependent, then I don't know how to check if the searched > font is really installed. Any idea about this? Cheers, David. #(ly:font-config-display-fonts)