<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Dear list users,<br>
    <br>
    this is my first post to this list, and also I'm completely new to
    using fontconfig from a programming language. But I have tried to
    get my head around the function references, and in the project I'm
    working at there are other people who are experienced with font
    issues and who couldn't help me either. So I dare to ask here
    directly.<br>
    I apologize in advance for the (not unlikely) case that I'm simply
    not seeing the obvious.<br>
    <br>
    I am working on a patch for GNU LilyPond (<a class="moz-txt-link-freetext" href="http://lilypond.org">http://lilypond.org</a>) that
    will make the use of (music and text) fonts significantly easier and
    more powerful. However, to achieve what I want I need to reliably
    determine if a font (that is given by its font name) is visible to
    fontconfig on the user's system. And all of my approaches so far
    have limitations that are inacceptable (and seem unnecessary). I'll
    concentrate on one approach that seems the most promising in my
    eyes.<br>
    <br>
    LilyPond provides a function (ly:font-config-get-font-file
    <name>) in its C++ part which returns the full path and file
    name to the font, and the path to a substitution font if the
    requested font is not found.<br>
    However, the substitution font is different on the users' systems,
    so my initial approach (checking if the returned font is the one *I*
    was getting as substitution) wasn't successful. However, I can see a
    way to handle that  by modifying the function's implementation.<br>
    <br>
    The existing function is defined as follows:<br>
    <a class="moz-txt-link-freetext" href="http://git.savannah.gnu.org/cgit/lilypond.git/tree/lily/font-config-scheme.cc">http://git.savannah.gnu.org/cgit/lilypond.git/tree/lily/font-config-scheme.cc</a>,
    line 101ff.<br>
    <br>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <pre style="padding: 0px; margin: 0px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><code>LY_DEFINE (ly_font_config_get_font_file, "ly:font-config-get-font-file", 1, 0, 0,
           (SCM name),
           "Get the file for font @var{name}.")
{
  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_FILE, 0, &str) == FcResultMatch)
    scm_result = scm_from_utf8_string ((char const *)str);

  FcPatternDestroy (pat);

  return scm_result;
}

</code></pre>
    <br class="Apple-interchange-newline">
    I hope the LilyPond/Guile specific stuff doesn't step in the way of
    looking at the code.<br>
    Despite looking at the documentation of the different Fc...
    functions and some example code, e.g. on StackOverflow I don't
    really see how to properly modify that function. My goal would be to
    set it so *no* replacement font is returned when the requested font
    isn't found. Basically str should only hold the path and the `if`
    expression should only evaluate to true when the font is found.<br>
    The function as a whole would then either return the string or
    'false' (which is no problem with the Guile/Scheme wrappers).<br>
    <br>
    Can you advise me how to achieve that? AFAICS it should be a simple
    matter of setting the configuration properly. Or is the return of a
    default font built-in at a deeper level? (I mean running fc-match in
    the terminal also returns a default for non-present fonts.)<br>
    In that case I'd try another approach that *seemed* promising but
    also had some issues: returning the family name and comparing that
    to the originally given family name.<br>
    <br>
    Thanks in advance<br>
    Urs<br>
  </body>
</html>