[Fontconfig] Lifetime of strings from FcPatternGetString

Sairus Patel sppatel at adobe.com
Tue Jul 8 15:37:40 PDT 2008


Hello all,

It’s not clear from the FC documentation how long we can expect a string returned from a pattern by FcPatternGetString to remain valid.

The doc does say that FcPatternGetString provides a pointer to the actual string within the pattern, but as in the code snippet below, the pattern is destroyed but I've observed that the returned filename value seems to remain usable.
 
Am I purely lucky that the memory is still valid, or are these strings “atoms” i.e. strings that remain valid for the entire lifetime of FontConfig? Is this documented anywhere?

Thanks,
Sairus



const char* FindFileName(const char* family, bool isBold, bool isItalic)
{
                const char* filename = NULL;
	[...]
                FcPattern* pattern = FcPatternBuild(NULL,
                                                                                                                FC_SCALABLE, FcTypeBool, true,
                                                                                                                FC_FAMILY, FcTypeString, family,
                                                                                                                FC_WEIGHT, FcTypeInteger, weight,
                                                                                                                FC_SLANT, FcTypeInteger, slant,
                                                                                                                NULL);
                if(pattern) {
                                FcConfigSubstitute(0, pattern, FcMatchPattern);
                                FcDefaultSubstitute(pattern);
                                FcResult result;
                                FcPattern* match = FcFontMatch(0, pattern, &result);
                                if(match) {
                                                FcChar8* str = 0;
                                                if(FcPatternGetString(match, FC_FILE, 0, &str) == FcResultMatch) {
                                                                filename = (const char*)str;
                                                }
                                }
                                FcPatternDestroy(pattern);
                }
                return filename;
}


More information about the Fontconfig mailing list