[Fontconfig] Getting FC_FILE Using Fontconfig

Jeremy Moles jeremy at emperorlinux.com
Thu Mar 3 12:09:25 PST 2011

On Wed, 2011-03-02 at 16:29 -0500, Behdad Esfahbod wrote:
> Hi Jeremy,
> On 03/02/11 14:34, Jeremy Moles wrote:
> > 
> > My question is: using the Fontconfig API, is it possible to--in a
> > generic way--find out what font file (or more likely "files", the
> > Fontconfig API will probably want to work with sets of
> > data)--corresponds to a particular Fontconfig string?
> That's what FcFontMatch() does.
> > For example, we love the expressively Pango provides when it allows us
> > to use fonts in the form of:
> > 
> > 	"Arial Bold 20px"
> > 
> > However, a separate API requires the exact font "file" on disk instead,
> > and so we'd like to continue using this expressive Pango/Fontconfig
> > syntax in order to provide the REAL file to the older software.
> Unfortunately Pango currently does not provide the function
> pango_fc_font_description_to_pattern().  It will in some future version.
> You can build a PangoFontDescription, but you need to convert that to a
> Fontconfig pattern yourself (or copy the code from pango).


FcPattern* pat = FcNameParse("arial");
FcFontSet* fs  = FcFontList(0, pat, 0);

for(i = 0; i < fs->nfont; i++) {
	if(FcPatternGetString(fs->fonts[i], FC_FILE, 0, &path)
	== FcResultMatch)


The code above is essentially what I'm using to get the font file paths.
It works for sure on Linux, haven't tested it (yet) in Windows.

Without a pango_fc_font_description_to_pattern() function, I'd like to
go the route (temporarily) of copying this code from Pango. Can you give
me any hints as to whereabouts this process is performed?

You mentioned also a kind of "hackish" way of getting the information
out of Pango (loading the font into the PangoFontMap in the context
isn't a problem), but I wasn't able to piece together the series of
calls in order to achieve this... (we can use whatever version of Pango
is necessary)


> Hope that helps,
> behdad
> > I'll continue browsing through the source for now, but if anyone has any
> > advice to get me started, I'd really appreciate it!
> > 
> > _______________________________________________
> > Fontconfig mailing list
> > Fontconfig at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/fontconfig
> > 

More information about the Fontconfig mailing list