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.
Werner
I think I have found something.
After some experimenting with a copy of font-config-get-font-file and
trying different approaches I could guess from the documentations
available I found that replacing an item in the FcPatternGetString call
this function returns the font name and not the Postscript name or the
font file.
The following preliminary function (if added to font-config-scheme.cc)
returns either the Font Name (if the font exists) or "Emmentaler-11" (on
my system) if it doesn't exist. I assume it would return other names on
other systems:
LY_DEFINE (ly_font_config_font_exists, "ly:font-config-font-exists", 1,
0, 0,
(SCM name),
"Determing if font @var{name} exists.")
{
LY_ASSERT_TYPE (scm_is_string, name, 1);
FcPattern *pat = FcPatternCreate ();
FcValue val;
val.type = FcTypeString;
val.u.s = (const FcChar8 *)ly_scm2string (name).c_str (); //
FC_SLANT_ITALIC;
FcPatternAdd (pat, FC_FAMILY, val, FcFalse);
FcResult result;
SCM scm_result = SCM_BOOL_F;
FcConfigSubstitute (NULL, pat, FcMatchFont);
FcDefaultSubstitute (pat);
pat = FcFontMatch (NULL, pat, &result);
FcChar8 *str = 0;
if (FcPatternGetString (pat, FC_FAMILY, 0, &str) == FcResultMatch)
scm_result = scm_from_utf8_string ((char const *)str);
FcPatternDestroy (pat);
return scm_result;
}
Now I get stuck with C++ basics, namely types, references and pointers,
but it should be possible to achieve something with the following approach:
In the line
scm_result = scm_from_utf ...
"str" holds the result from this match.
If this matches the originally passed "name" argument the return value
should be set to SCM_BOOL_T.
This should be dead easy, but I don't know to perform this comparison.
If someone gives me a helping hand here we would get a function
ly:font-config-font-exists that returns #t or #f depending on the
existence of the font.
Please ...
Best
Urs
set the return value to SCM_BOOL_T if
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user