X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=src%2Ffccfg.c;h=3c3681a100620e9c803e811aae0f55195121e340;hb=db50cbdaf592349c204ab0af0e7061ea72237044;hp=5d6339f65af9102b828000ece797127dffa5bb2d;hpb=13cdf607533ad592b896b738c5642f3685fd8053;p=fontconfig.git diff --git a/src/fccfg.c b/src/fccfg.c index 5d6339f..3c3681a 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -23,6 +23,8 @@ */ #include "fcint.h" +#include +#include #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT)) #define STRICT @@ -98,13 +100,17 @@ FcConfigCreate (void) if (!FcConfigSetCache (config, cache_dir)) { FcStrFree (cache_dir); - goto bail6; + goto bail8; } FcStrFree (cache_dir); } } #endif + config->cacheDirs = FcStrSetCreate (); + if (!config->cacheDirs) + goto bail9; + config->blanks = 0; config->substPattern = 0; @@ -118,6 +124,8 @@ FcConfigCreate (void) return config; +bail9: + FcStrFree (config->cache); bail8: FcFontSetDestroy (config->rejectPatterns); bail7: @@ -139,11 +147,6 @@ bail0: return 0; } -typedef struct _FcFileTime { - time_t time; - FcBool set; -} FcFileTime; - static FcFileTime FcConfigNewestFile (FcStrSet *files) { @@ -166,6 +169,19 @@ FcConfigNewestFile (FcStrSet *files) return newest; } +FcFileTime +FcConfigModifiedTime (FcConfig *config) +{ + if (!config) + { + FcFileTime v = { 0, FcFalse }; + config = FcConfigGetCurrent (); + if (!config) + return v; + } + return FcConfigNewestFile (config->configFiles); +} + FcBool FcConfigUptoDate (FcConfig *config) { @@ -216,6 +232,7 @@ FcConfigDestroy (FcConfig *config) FcStrSetDestroy (config->configDirs); FcStrSetDestroy (config->fontDirs); + FcStrSetDestroy (config->cacheDirs); FcStrSetDestroy (config->configFiles); FcStrSetDestroy (config->acceptGlobs); FcStrSetDestroy (config->rejectGlobs); @@ -266,14 +283,14 @@ FcConfigBuildFonts (FcConfig *config) goto bail2; if (config->cache) - FcGlobalCacheLoad (cache, oldDirs, config->cache); + FcGlobalCacheLoad (cache, oldDirs, config->cache, config); cached_fonts = FcCacheRead(config, cache); if (!cached_fonts) { list = FcConfigGetFontDirs (config); if (!list) - goto bail2; + goto bail3; while ((dir = FcStrListNext (list))) { @@ -300,7 +317,11 @@ FcConfigBuildFonts (FcConfig *config) for (i = 0; i < cached_fonts->nfont; i++) { - if (FcConfigAcceptFont (config, cached_fonts->fonts[i])) + FcChar8 *cfn; + FcPatternGetString (cached_fonts->fonts[i], FC_FILE, 0, &cfn); + + if (FcConfigAcceptFont (config, cached_fonts->fonts[i]) && + (cfn && FcConfigAcceptFilename (config, cfn))) FcFontSetAdd (fonts, cached_fonts->fonts[i]); cached_fonts->fonts[i] = 0; /* prevent free in FcFontSetDestroy */ @@ -313,15 +334,17 @@ FcConfigBuildFonts (FcConfig *config) FcFontSetPrint (fonts); if (config->cache) - FcGlobalCacheSave (cache, config->cache); + FcGlobalCacheSave (cache, config->cache, config); FcGlobalCacheDestroy (cache); FcStrSetDestroy (oldDirs); FcConfigSetFonts (config, fonts, FcSetSystem); return FcTrue; -bail2: +bail3: FcStrSetDestroy (oldDirs); +bail2: + FcGlobalCacheDestroy (cache); bail1: FcFontSetDestroy (fonts); bail0: @@ -396,6 +419,25 @@ FcConfigGetFontDirs (FcConfig *config) return FcStrListCreate (config->fontDirs); } +FcBool +FcConfigAddCacheDir (FcConfig *config, + const FcChar8 *d) +{ + return FcStrSetAddFilename (config->cacheDirs, d); +} + +FcStrList * +FcConfigGetCacheDirs (FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + return FcStrListCreate (config->cacheDirs); +} + FcBool FcConfigAddConfigFile (FcConfig *config, const FcChar8 *f) @@ -490,17 +532,21 @@ FcBool FcConfigAddBlank (FcConfig *config, FcChar32 blank) { - FcBlanks *b; + FcBlanks *b, *freeme = 0; b = config->blanks; if (!b) { - b = FcBlanksCreate (); + freeme = b = FcBlanksCreate (); if (!b) return FcFalse; } if (!FcBlanksAdd (b, blank)) + { + if (freeme) + FcBlanksDestroy (freeme); return FcFalse; + } config->blanks = b; return FcTrue; } @@ -778,6 +824,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) FcValue v, vl, vr; FcResult r; FcMatrix *m; + FcChar8 *str; switch (e->op) { case FcOpInteger: @@ -791,7 +838,6 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) case FcOpString: v.type = FcTypeString; v.u.s = FcStrStaticName(e->u.sval); - v = FcValueSave (v); break; case FcOpMatrix: v.type = FcTypeMatrix; @@ -811,6 +857,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) r = FcPatternGet (p, e->u.field, 0, &v); if (r != FcResultMatch) v.type = FcTypeVoid; + v = FcValueSave (v); break; case FcOpConst: if (FcNameConstant (e->u.constant, &v.u.i)) @@ -908,7 +955,9 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) switch (e->op) { case FcOpPlus: v.type = FcTypeString; - v.u.s = FcStrStaticName (FcStrPlus (vl.u.s, vr.u.s)); + str = FcStrPlus (vl.u.s, vr.u.s); + v.u.s = FcStrStaticName (str); + FcStrFree (str); if (!v.u.s) v.type = FcTypeVoid; @@ -1083,7 +1132,6 @@ static FcValueList * FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding) { FcValueList *l; - FcValueListPtr lp; if (!e) return 0; @@ -1102,18 +1150,15 @@ FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding) l->next = FcValueListPtrCreateDynamic(0); } l->binding = binding; - lp = FcValueListPtrCreateDynamic(l); - while (FcValueListPtrU(lp) && FcValueListPtrU(lp)->value.type == FcTypeVoid) + if (l->value.type == FcTypeVoid) { - FcValueListPtr next = FcValueListPtrU(lp)->next; + FcValueList *next = FcValueListPtrU(l->next); - if (lp.bank == FC_BANK_DYNAMIC) - { - FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList)); - free (l); - } - lp = next; + FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList)); + free (l); + l = next; } + return l; } @@ -1393,7 +1438,8 @@ FcConfigSubstituteWithPat (FcConfig *config, /* * Delete the marked value */ - FcConfigDel (&st[i].elt->values, thisValue); + if (thisValue) + FcConfigDel (&st[i].elt->values, thisValue); /* * Adjust any pointers into the value list to ensure * future edits occur at the same place @@ -1448,6 +1494,7 @@ FcConfigSubstituteWithPat (FcConfig *config, FcConfigPatternAdd (p, e->field, l, FcTrue); break; default: + FcValueListDestroy (FcValueListPtrCreateDynamic(l)); break; } } @@ -1765,6 +1812,7 @@ FcConfigAppFontAddFile (FcConfig *config, } FcStrListDone (sublist); } + FcStrSetDestroy (subdirs); return FcTrue; } @@ -1812,6 +1860,7 @@ FcConfigAppFontAddDir (FcConfig *config, } FcStrListDone (sublist); } + FcStrSetDestroy (subdirs); return FcTrue; }