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 18:14:31 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.6.0



Am 28.04.2015 um 17:53 schrieb Urs Liska:
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

Wrapping this Scheme function around that:

fontExists =
#(define-scheme-function (parser location font-name)(string?)
   (string=? font-name (ly:font-config-font-exists font-name)))

shows that my idea is right: The C++ function returns the family name of either the given font or the (system-dependent) fallback font. Now all there would be to it is moving the comparison of the latter Scheme function to the C++ function .

Urs




reply via email to

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