* PERFORMANCE OF THIS SOFTWARE.
*/
+#include <dirent.h>
+#include <sys/types.h>
#include "fcint.h"
#if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
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)
{
FcBool
FcConfigBuildFonts (FcConfig *config)
{
- FcFontSet *fonts;
+ FcFontSet *fonts, *cached_fonts;
FcGlobalCache *cache;
FcStrList *list;
+ FcStrSet *oldDirs;
FcChar8 *dir;
-#if 0
- if (config->cache)
- FcGlobalCacheLoad (cache, config->cache);
-#endif
- if (config->fonts[FcSetSystem])
- return FcTrue;
-
fonts = FcFontSetCreate ();
if (!fonts)
goto bail0;
-
-#if 0
+
cache = FcGlobalCacheCreate ();
if (!cache)
goto bail1;
-#endif
- list = FcConfigGetFontDirs (config);
- if (!list)
- goto bail1;
+ oldDirs = FcStrSetCreate ();
+ if (!oldDirs)
+ goto bail2;
- while ((dir = FcStrListNext (list)))
+ if (config->cache)
+ FcGlobalCacheLoad (cache, oldDirs, config->cache, config);
+
+ cached_fonts = FcCacheRead(config, cache);
+ if (!cached_fonts)
+ {
+ list = FcConfigGetFontDirs (config);
+ if (!list)
+ goto bail2;
+
+ 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
{
- if (FcDebug () & FC_DBG_FONTSET)
- printf ("scan dir %s\n", dir);
- FcDirScanConfig (fonts, config->fontDirs, cache,
- config->blanks, dir, FcFalse, config);
+ 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 0
if (config->cache)
- FcGlobalCacheSave (cache, config->cache);
+ FcGlobalCacheSave (cache, config->cache, config);
FcGlobalCacheDestroy (cache);
-#endif
+ FcStrSetDestroy (oldDirs);
FcConfigSetFonts (config, fonts, FcSetSystem);
return FcTrue;
+bail2:
+ FcStrSetDestroy (oldDirs);
bail1:
FcFontSetDestroy (fonts);
bail0:
return FcStrListCreate (config->configDirs);
}
+static FcChar8 *
+FcConfigInodeMatchFontDir (FcConfig *config, const FcChar8 *d)
+{
+ int n;
+ ino_t di;
+ dev_t dd;
+ struct stat s;
+
+ /* first we do string matches rather than file accesses */
+ /* FcStrSetMember doesn't tell us the index so that we can return
+ * the config-owned copy. */
+ for (n = 0; n < config->fontDirs->num; n++)
+ {
+ if (!FcStrCmp (config->fontDirs->strs[n], d))
+ return config->fontDirs->strs[n];
+ }
+
+ /* If this is a bottleneck, we can cache the fontDir inodes. */
+ if (stat ((char *)d, &s) == -1)
+ return 0;
+ di = s.st_ino; dd = s.st_dev;
+
+ for (n = 0; n < config->fontDirs->num; n++)
+ {
+ if (stat ((char *)config->fontDirs->strs[n], &s) == -1)
+ continue;
+ if (di == s.st_ino && dd == s.st_dev)
+ return config->fontDirs->strs[n];
+ }
+ return 0;
+}
+
FcBool
FcConfigAddFontDir (FcConfig *config,
const FcChar8 *d)
{
+ /* Avoid adding d if it's an alias of something else, too. */
+ if (FcConfigInodeMatchFontDir(config, d))
+ return FcTrue;
return FcStrSetAddFilename (config->fontDirs, d);
}
+static FcBool
+FcConfigAddFontDirSubdirs (FcConfig *config,
+ const FcChar8 *d)
+{
+ DIR *dir;
+ struct dirent *e;
+ FcChar8 *subdir;
+ FcBool added = FcFalse;
+
+ if (!(dir = opendir ((char *) d)))
+ return FcFalse;
+ if (!(subdir = (FcChar8 *) malloc (strlen ((char *) d) + FC_MAX_FILE_LEN + 2)))
+ {
+ fprintf (stderr, "out of memory");
+ return FcFalse;
+ }
+ while ((e = readdir (dir)))
+ {
+ if (strcmp (e->d_name, ".") && strcmp (e->d_name, "..") &&
+ strlen (e->d_name) < FC_MAX_FILE_LEN)
+ {
+ strcpy ((char *)subdir, (char *)d);
+ strcat ((char *)subdir, "/");
+ strcat ((char *)subdir, e->d_name);
+ if (FcFileIsDir (subdir))
+ {
+ if (FcConfigInodeMatchFontDir(config, subdir))
+ continue; /* already added */
+ FcStrSetAddFilename (config->fontDirs, subdir);
+ FcConfigAddFontDirSubdirs (config, subdir);
+ added = FcTrue;
+ }
+ }
+ }
+ free (subdir);
+ closedir (dir);
+ return added;
+}
+
+const FcChar8 *
+FcConfigNormalizeFontDir (FcConfig *config,
+ const FcChar8 *d)
+{
+ FcChar8 *d0;
+ int n, n0;
+ FcBool added = FcFalse;
+
+ d0 = FcConfigInodeMatchFontDir(config, d);
+ if (d0)
+ return d0;
+
+ /* Ok, we didn't find it in fontDirs; let's add subdirs.... */
+ for (n = 0, n0 = config->fontDirs->num; n < n0; n++)
+ {
+ if (FcConfigAddFontDirSubdirs (config, config->fontDirs->strs[n]))
+ added = FcTrue;
+ }
+
+ /* ... and try again. */
+ if (added)
+ return FcConfigInodeMatchFontDir(config, d);
+
+ return 0;
+}
+
FcBool
FcConfigAddDir (FcConfig *config,
const FcChar8 *d)
}
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;
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)));
+ v.u.s = FcStrStaticName (FcStrPlus (vl.u.s, vr.u.s));
- 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;
}
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;
}