*/
#include "fcint.h"
+#include <dirent.h>
+#include <sys/types.h>
#if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
#define STRICT
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;
return config;
+bail9:
+ FcStrFree (config->cache);
bail8:
FcFontSetDestroy (config->rejectPatterns);
bail7:
return 0;
}
-typedef struct _FcFileTime {
- time_t time;
- FcBool set;
-} FcFileTime;
-
static FcFileTime
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)
{
FcStrSetDestroy (config->configDirs);
FcStrSetDestroy (config->fontDirs);
+ FcStrSetDestroy (config->cacheDirs);
FcStrSetDestroy (config->configFiles);
FcStrSetDestroy (config->acceptGlobs);
FcStrSetDestroy (config->rejectGlobs);
FcBool
FcConfigBuildFonts (FcConfig *config)
{
- FcFontSet *fonts;
+ FcFontSet *fonts, *cached_fonts;
FcGlobalCache *cache;
FcStrList *list;
+ FcStrSet *oldDirs;
FcChar8 *dir;
fonts = FcFontSetCreate ();
if (!cache)
goto bail1;
- if (config->cache)
- FcGlobalCacheLoad (cache, config->cache);
+ oldDirs = FcStrSetCreate ();
+ if (!oldDirs)
+ goto bail2;
- list = FcConfigGetFontDirs (config);
- if (!list)
- goto bail1;
+ if (config->cache)
+ FcGlobalCacheLoad (cache, oldDirs, config->cache, config);
- while ((dir = FcStrListNext (list)))
+ cached_fonts = FcCacheRead(config, cache);
+ if (!cached_fonts)
{
- if (FcDebug () & FC_DBG_FONTSET)
- printf ("scan dir %s\n", dir);
- FcDirScanConfig (fonts, config->fontDirs, cache,
- config->blanks, dir, FcFalse, config);
+ list = FcConfigGetFontDirs (config);
+ if (!list)
+ goto bail3;
+
+ while ((dir = FcStrListNext (list)))
+ {
+ if (FcDebug () & FC_DBG_FONTSET)
+ printf ("build scan dir %s\n", dir);
+ FcDirScanConfig (fonts, config->fontDirs, cache,
+ config->blanks, dir, FcFalse, config);
+ }
+
+ FcStrListDone (list);
+ }
+ else
+ {
+ int i;
+
+ for (i = 0; i < oldDirs->num; i++)
+ {
+ if (FcDebug () & FC_DBG_FONTSET)
+ printf ("scan dir %s\n", oldDirs->strs[i]);
+ FcDirScanConfig (fonts, config->fontDirs, cache,
+ config->blanks, oldDirs->strs[i],
+ FcFalse, config);
+ }
+
+ for (i = 0; i < cached_fonts->nfont; 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 */
+ }
+ cached_fonts->nfont = 0;
+ FcFontSetDestroy (cached_fonts);
}
-
- FcStrListDone (list);
if (FcDebug () & FC_DBG_FONTSET)
FcFontSetPrint (fonts);
if (config->cache)
- FcGlobalCacheSave (cache, config->cache);
+ FcGlobalCacheSave (cache, config->cache, config);
FcGlobalCacheDestroy (cache);
+ FcStrSetDestroy (oldDirs);
FcConfigSetFonts (config, fonts, FcSetSystem);
return FcTrue;
+bail3:
+ FcStrSetDestroy (oldDirs);
+bail2:
+ FcGlobalCacheDestroy (cache);
bail1:
FcFontSetDestroy (fonts);
bail0:
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)
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;
}
}
else if (v.type == FcTypeVoid && u.type == FcTypeMatrix)
{
- v.u.mi = FcIdentityMatrix;
+ v.u.m = &FcIdentityMatrix;
v.type = FcTypeMatrix;
}
else if (v.type == FcTypeString && u.type == FcTypeLangSet)
{
- v.u.li = FcLangSetPtrCreateDynamic(FcLangSetPromote
- (FcObjectPtrU(v.u.si)));
+ v.u.l = FcLangSetPromote (v.u.s);
v.type = FcTypeLangSet;
}
return v;
}
FcBool
-FcConfigCompareValue (const FcValue left_o,
+FcConfigCompareValue (const FcValue *left_o,
FcOp op,
- const FcValue right_o)
+ const FcValue *right_o)
{
- FcValue left = left_o;
- FcValue right = right_o;
+ FcValue left = FcValueCanonicalize(left_o);
+ FcValue right = FcValueCanonicalize(right_o);
FcBool ret = FcFalse;
left = FcConfigPromote (left, right);
switch (op) {
case FcOpEqual:
case FcOpListing:
- ret = FcStrCmpIgnoreCase (FcObjectPtrU(left.u.si),
- FcObjectPtrU(right.u.si)) == 0;
+ ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) == 0;
break;
case FcOpContains:
- ret = FcStrStrIgnoreCase (FcObjectPtrU(left.u.si),
- FcObjectPtrU(right.u.si)) != 0;
+ ret = FcStrStrIgnoreCase (left.u.s, right.u.s) != 0;
break;
case FcOpNotEqual:
- ret = FcStrCmpIgnoreCase (FcObjectPtrU(left.u.si),
- FcObjectPtrU(right.u.si)) != 0;
+ ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) != 0;
break;
case FcOpNotContains:
- ret = FcStrCmpIgnoreCase (FcObjectPtrU(left.u.si),
- FcObjectPtrU(right.u.si)) == 0;
+ ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) == 0;
break;
default:
break;
case FcOpEqual:
case FcOpContains:
case FcOpListing:
- ret = FcMatrixEqual (FcMatrixPtrU(left.u.mi), FcMatrixPtrU(right.u.mi));
+ ret = FcMatrixEqual (left.u.m, right.u.m);
break;
case FcOpNotEqual:
case FcOpNotContains:
- ret = !FcMatrixEqual (FcMatrixPtrU(left.u.mi), FcMatrixPtrU(right.u.mi));
+ ret = !FcMatrixEqual (left.u.m, right.u.m);
break;
default:
break;
case FcOpContains:
case FcOpListing:
/* left contains right if right is a subset of left */
- ret = FcCharSetIsSubset (FcCharSetPtrU(right.u.ci), FcCharSetPtrU(left.u.ci));
+ ret = FcCharSetIsSubset (right.u.c, left.u.c);
break;
case FcOpNotContains:
/* left contains right if right is a subset of left */
- ret = !FcCharSetIsSubset (FcCharSetPtrU(right.u.ci), FcCharSetPtrU(left.u.ci));
+ ret = !FcCharSetIsSubset (right.u.c, left.u.c);
break;
case FcOpEqual:
- ret = FcCharSetEqual (FcCharSetPtrU(left.u.ci), FcCharSetPtrU(right.u.ci));
+ ret = FcCharSetEqual (left.u.c, right.u.c);
break;
case FcOpNotEqual:
- ret = !FcCharSetEqual (FcCharSetPtrU(left.u.ci), FcCharSetPtrU(right.u.ci));
+ ret = !FcCharSetEqual (left.u.c, right.u.c);
break;
default:
break;
switch (op) {
case FcOpContains:
case FcOpListing:
- ret = FcLangSetContains (FcLangSetPtrU(left.u.li), FcLangSetPtrU(right.u.li));
+ ret = FcLangSetContains (left.u.l, right.u.l);
break;
case FcOpNotContains:
- ret = !FcLangSetContains (FcLangSetPtrU(left.u.li), FcLangSetPtrU(right.u.li));
+ ret = !FcLangSetContains (left.u.l, right.u.l);
break;
case FcOpEqual:
- ret = FcLangSetEqual (FcLangSetPtrU(left.u.li), FcLangSetPtrU(right.u.li));
+ ret = FcLangSetEqual (left.u.l, right.u.l);
break;
case FcOpNotEqual:
- ret = !FcLangSetEqual (FcLangSetPtrU(left.u.li), FcLangSetPtrU(right.u.li));
+ ret = !FcLangSetEqual (left.u.l, right.u.l);
break;
default:
break;
FcValue v, vl, vr;
FcResult r;
FcMatrix *m;
+ FcChar8 *str;
switch (e->op) {
case FcOpInteger:
break;
case FcOpString:
v.type = FcTypeString;
- v.u.si = FcObjectStaticName(e->u.sval);
- v = FcValueSave (v);
+ v.u.s = FcStrStaticName(e->u.sval);
break;
case FcOpMatrix:
v.type = FcTypeMatrix;
- v.u.mi = FcMatrixPtrCreateDynamic(e->u.mval);
+ v.u.m = e->u.mval;
v = FcValueSave (v);
break;
case FcOpCharSet:
v.type = FcTypeCharSet;
- v.u.ci = FcCharSetPtrCreateDynamic(e->u.cval);
+ v.u.c = e->u.cval;
v = FcValueSave (v);
break;
case FcOpBool:
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))
vl = FcConfigEvaluate (p, e->u.tree.left);
vr = FcConfigEvaluate (p, e->u.tree.right);
v.type = FcTypeBool;
- v.u.b = FcConfigCompareValue (vl, e->op, vr);
+ v.u.b = FcConfigCompareValue (&vl, e->op, &vr);
FcValueDestroy (vl);
FcValueDestroy (vr);
break;
switch (e->op) {
case FcOpPlus:
v.type = FcTypeString;
- v.u.si = FcObjectStaticName
- (FcStrPlus (FcObjectPtrU(vl.u.si),
- FcObjectPtrU(vr.u.si)));
+ str = FcStrPlus (vl.u.s, vr.u.s);
+ v.u.s = FcStrStaticName (str);
+ FcStrFree (str);
- if (!FcObjectPtrU(v.u.si))
+ if (!v.u.s)
v.type = FcTypeVoid;
break;
default:
if (m)
{
FcMemAlloc (FC_MEM_MATRIX, sizeof (FcMatrix));
- FcMatrixMultiply (m, FcMatrixPtrU(vl.u.mi),
- FcMatrixPtrU(vr.u.mi));
- v.u.mi = FcMatrixPtrCreateDynamic(m);
+ FcMatrixMultiply (m, vl.u.m, vr.u.m);
+ v.u.m = m;
}
else
{
for (v = values; v; v = FcValueListPtrU(v->next))
{
/* Compare the pattern value to the match expression value */
- if (FcConfigCompareValue (v->value, t->op, value))
+ if (FcConfigCompareValue (&v->value, t->op, &value))
{
if (!ret)
ret = v;
FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
{
FcValueList *l;
- FcValueListPtr lp;
if (!e)
return 0;
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.storage == FcStorageDynamic)
- {
- FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
- free (l);
- }
- lp = next;
+ FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
+ free (l);
+ l = next;
}
+
return l;
}
/*
* 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
FcConfigPatternAdd (p, e->field, l, FcTrue);
break;
default:
+ FcValueListDestroy (FcValueListPtrCreateDynamic(l));
break;
}
}
home = getenv ("USERPROFILE");
#endif
- return home;
+ return (FcChar8 *) home;
}
return 0;
}
}
FcStrListDone (sublist);
}
+ FcStrSetDestroy (subdirs);
return FcTrue;
}
}
FcStrListDone (sublist);
}
+ FcStrSetDestroy (subdirs);
return FcTrue;
}
int i;
for (i = 0; i < globs->num; i++)
- if (FcConfigGlobMatch (FcStrSetGet(globs, i), string))
+ if (FcConfigGlobMatch (globs->strs[i], string))
return FcTrue;
return FcFalse;
}