lilypond-user
[Top][All Lists]
Advanced

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

Re: How to determine if a font is a fallback font?


From: Urs Liska
Subject: Re: How to determine if a font is a fallback font?
Date: Tue, 28 Apr 2015 15:53:22 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.6.0



Am 28.04.2015 um 12:18 schrieb Werner LEMBERG:
On my openSuSE GNU/Linux box, I get different results.

Given font name: Emmentaler-13
Determined font file: /usr/share/fonts/TTF/mplus-1c-medium.ttf
Actual font in that file: mplus-1c-medium
Given font is present: #f
  Given font name: Emmentaler-13
  Determined font file: /usr/local/share/lilypond/2.19.16/fonts/otf/emmentaler-13.otf
  Actual font in that file: Emmentaler-13
  Given font is present: #t/usr/local/share/lilypond/2.19.16/fonts/otf/emmentaler-13.otf
  Emmentaler-13

Given font name: Alegreya
Determined font file: /usr/share/fonts/TTF/mplus-1c-medium.ttf
Actual font in that file: mplus-1c-medium
Given font is present: #f
  Given font name: Alegreya
  Determined font file: /usr/share/fonts/truetype/Alegreya-Regular.ttf
  Actual font in that file: Alegreya-Regular
  Given font is present: #f/usr/share/fonts/truetype/Alegreya-Regular.ttf
  Alegreya-Regular

Note that `ly:ttf-ps-name' returns the font's *PostScript* name.  This
is *not* what fontconfig normally operates on (but see below).

Given font name: DejaVu Sans
Determined font file: /usr/share/fonts/TTF/mplus-1c-medium.ttf
Actual font in that file: mplus-1c-medium
Given font is present: #f/usr/share/fonts/TTF/mplus-1c-medium.ttf
mplus-1c-medium
  Given font name: DejaVu Sans
  Determined font file: /usr/share/fonts/truetype/DejaVuSans.ttf
  Actual font in that file: DejaVuSans
  Given font is present: #f/usr/share/fonts/truetype/DejaVuSans.ttf
  DejaVuSans

Same as above: `DejaVuSans' != `DejaVu Sans'.

Since FontConfig version 2.11 (released October 2013), however, it is
possible to search for PostScript names also.  Example:

  $ fc-match "Alegreya"
  Alegreya-Regular.ttf: "Alegreya" "Regular"

  $ fc-match "AlegreyaRegular"
  arial.ttf: "Arial" "Normal"

  $ fc-match ":postscriptname=AlegreyaRegular"
  Alegreya-Regular.ttf: "Alegreya" "Regular"

Maybe lilypond's `display_fontset' function (in font-config-scheme.cc)
can be extended to display PS names also.  And perhaps it makes sense
to extend lilypond's font loading function to accept a font's PS name
– or to provide a Scheme function wrapper for FontConfig to access a
given font's PS name.

As it stands I can't use this comparison either to determine if a given font is present on the user's system.
I think in any case it would be good to have a pair of functions that can reliably perform the step name->file->name and return the original input as its result. Currently the input is a "font name" and the output is a "PostScript name" (just to repeat that.)

From starting to look at the font- C++ files and searching the net for approaches I can think of the following possibilities:

1)
Add a companion to ly:ttf-ps-name that returns the file name. Unfortunately there seems to be no equivalent to FT_Get_Postscript_Name, and from what I've seen one would have to somehow retrieve the information from FT_Get_Sfnt_Name (which clearly is over my head).

2)
Modify ly:font-config-get-font-file so its return value is predictable if the font is not found.
I don't fully understand what happens in that function (also because available documentation on the Freetype commands seems even harder to grasp than LilyPond's internals ...), but wouldn't it be possible to modify this so that it doesn't perform that seemingly random font

If that's possible I would suggest this second approach and would like to get opinions on possible side-effects that I don't see yet.
I think that in most of the cases it is very undesirable to use an arbitrary font instead of the requested font. So what I'm proposing is to change this function so that it returns #f or an empty string if the requested font doesn't exist.
A modification in font.scm will then take care of handling that case properly by printing a warning and providing a proper (i.e. predictable) fallback font. In \setMusicFont (these functions are new in what I'm preparing) it would fallback to Emmentaler, in \setTextFont to the appropriate default text font.

What do you think?

Urs


    Werner


reply via email to

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