[Fontconfig] Tutorial or guidance for using fontconfig
Behdad Esfahbod
behdad at behdad.org
Wed Jan 7 15:59:36 PST 2009
Staffan Gimåker wrote:
> On Wednesday 07 January 2009 23:55:45 Behdad Esfahbod wrote:
>> If you still decide to use fontconfig directly, I always reply to messages
>> that are to the point. True, there is no good guide to read. But if you
>> ask smart questions (like, "I have a family name, how do I find the best
>> font file to use?"), you get smart answers. If you ask stupid questions
>> ("how do I use fontconfig?"), you probably don't get any answers.
>
> So, if I have a family name (say, Times), how *do I* find the best font file to
> use (as in, the path to the font)?
Check the man pages for exact parameters and error handling, but something
like this:
FcPattern *pat, *match;
FcResult result;
char *file;
int index;
pat = FcPatternCreate ();
FcPatternAddString (pat, FC_FAMILY, "Times");
FcConfigSubstitute (NULL, pat, FcMatchPattern);
FcDefaultSubstitute (pat);
match = FcFontMatch (NULL, pat, &result);
FcPatternGetString (match, FC_FILE, 0, (FcChar8 **) &file);
FcPatternGetInteger (match, FC_INDEX, 0, &index);
If you use FreeType, at this point you can do:
FT_New_Face (ftlib, file, id, &face);
to get your face. Then you can clean up:
FcPatternDestroy (match);
FcPatternDestroy (pat);
> (We use OpenGL to render (polygonal) text in 3D so, AFAICT, going through
> Pango seems a bit redundant for our usage.)
Going through Pango gets you internationalization. That is, correct rendering
of Arabic, Hebrew, Indic, Thai, etc etc etc. There are a few projects using
Pango with OpenGL. Search the net.
Cheers,
behdad
> Cheers,
> Staffan
More information about the Fontconfig
mailing list