On Tue, 17 Feb 2015 20:37:04 +0200, John Found wrote:

> Recently I am working on text rendering with FreeType.
> 
> The FreeType function FT_New_Face uses the filename of the font, but
> I want more flexible approach with font substitution and suggesting
> fonts by some pattern, for example "serif", "monospaced", "bold", etc.

There is a sequence of Fontconfig calls I use as standard. For
a C version, see the load_sub_face routine here
<https://github.com/ldo/dvdauthor/blob/master/src/subfont.c>. The steps
are:

    * call FcNameParse to parse the user-provided string into an
      FcPattern
    * Do an FcConfigSubstitute on the pattern to apply a user-default
      configuration
    * Also call FcDefaultSubstitute on the pattern to apply a
      hard-coded default configuration
    * Call FcFontMatch to actually find a matching font
    * Then FcPatternGetString(... FC_FILE ...) on the match to get the
      pathname of the font file.

For a Python equivalent, see the Face.find_face method here
<https://github.com/ldo/python_freetype/blob/master/freetype.py>.

Fontconfig pattern strings can take such useful forms as
“palatino:style=italic:weight=1000"”, “sans-serif:slant=500” etc.

_______________________________________________
Freetype mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/freetype

Reply via email to