if (!config->rejectPatterns)
goto bail7;
- config->cache = 0;
- if (FcConfigHome())
- if (!FcConfigSetCache (config, (FcChar8 *) ("~/" FC_USER_CACHE_FILE)))
- goto bail8;
-
-#ifdef _WIN32
- if (config->cache == 0)
- {
- /* If no home, use the temp folder. */
- FcChar8 dummy[1];
- int templen = GetTempPath (1, dummy);
- FcChar8 *temp = malloc (templen + 1);
-
- if (temp)
- {
- FcChar8 *cache_dir;
-
- GetTempPath (templen + 1, temp);
- cache_dir = FcStrPlus (temp, FC_USER_CACHE_FILE);
- free (temp);
- if (!FcConfigSetCache (config, cache_dir))
- {
- FcStrFree (cache_dir);
- goto bail8;
- }
- FcStrFree (cache_dir);
- }
- }
-#endif
-
config->cacheDirs = FcStrSetCreate ();
if (!config->cacheDirs)
- goto bail9;
+ goto bail8;
config->blanks = 0;
config->substPattern = 0;
config->substFont = 0;
+ config->substScan = 0;
config->maxObjects = 0;
for (set = FcSetSystem; set <= FcSetApplication; set++)
config->fonts[set] = 0;
return config;
-bail9:
- FcStrFree (config->cache);
bail8:
FcFontSetDestroy (config->rejectPatterns);
bail7:
if (config->blanks)
FcBlanksDestroy (config->blanks);
- if (config->cache)
- FcStrFree (config->cache);
-
FcSubstDestroy (config->substPattern);
FcSubstDestroy (config->substFont);
+ FcSubstDestroy (config->substScan);
for (set = FcSetSystem; set <= FcSetApplication; set++)
if (config->fonts[set])
FcFontSetDestroy (config->fonts[set]);
}
/*
- * Scan the current list of directories in the configuration
- * and build the set of available fonts. Update the
- * per-user cache file to reflect the new configuration
+ * Add cache to configuration, adding fonts and directories
*/
FcBool
-FcConfigBuildFonts (FcConfig *config)
+FcConfigAddCache (FcConfig *config, FcCache *cache)
{
- FcFontSet *fonts, *cached_fonts;
- FcStrList *list;
- FcStrSet *oldDirs;
- FcChar8 *dir;
-
- fonts = FcFontSetCreate ();
- if (!fonts)
- goto bail0;
-
- oldDirs = FcStrSetCreate ();
- if (!oldDirs)
- goto bail2;
-
- cached_fonts = FcCacheRead(config);
- if (!cached_fonts)
+ FcFontSet *fs;
+ intptr_t *dirs;
+ int i;
+
+ /*
+ * Add fonts
+ */
+ fs = FcCacheSet (cache);
+ if (fs)
{
- list = FcConfigGetFontDirs (config);
- if (!list)
- goto bail3;
+ int nref = 0;
- while ((dir = FcStrListNext (list)))
+ for (i = 0; i < fs->nfont; i++)
{
- if (FcDebug () & FC_DBG_FONTSET)
- printf ("build scan dir %s\n", dir);
- FcDirScanConfig (fonts, config->fontDirs,
- config->blanks, dir, FcFalse, config);
+ FcPattern *font = FcFontSetFont (fs, i);
+ FcChar8 *font_file;
+
+ /*
+ * Check to see if font is banned by filename
+ */
+ if (FcPatternObjectGetString (font, FC_FILE_OBJECT,
+ 0, &font_file) == FcResultMatch &&
+ !FcConfigAcceptFilename (config, font_file))
+ {
+ continue;
+ }
+
+ /*
+ * Check to see if font is banned by pattern
+ */
+ if (!FcConfigAcceptFont (config, font))
+ continue;
+
+ nref++;
+ FcFontSetAdd (config->fonts[FcSetSystem], font);
}
-
- FcStrListDone (list);
+ FcDirCacheReference (cache, nref);
}
- else
+
+ /*
+ * Add directories
+ */
+ dirs = FcCacheDirs (cache);
+ if (dirs)
{
- 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,
- config->blanks, oldDirs->strs[i],
- FcFalse, config);
+ for (i = 0; i < cache->dirs_count; i++)
+ {
+ FcChar8 *dir = FcOffsetToPtr (dirs, dirs[i], FcChar8);
+ if (FcConfigAcceptFilename (config, dir))
+ FcConfigAddFontDir (config, dir);
}
+ }
+ return FcTrue;
+}
- for (i = 0; i < cached_fonts->nfont; i++)
- {
- FcChar8 *cfn;
- FcPattern *font = cached_fonts->fonts[i];
- FcPatternObjectGetString (font, FC_FILE_OBJECT, 0, &cfn);
+/*
+ * Scan the current list of directories in the configuration
+ * and build the set of available fonts.
+ */
- if (FcConfigAcceptFont (config, font) &&
- (cfn && FcConfigAcceptFilename (config, cfn)))
- FcFontSetAdd (fonts, font);
+FcBool
+FcConfigBuildFonts (FcConfig *config)
+{
+ FcFontSet *fonts;
+ FcStrList *dirlist;
+ FcChar8 *dir;
+ FcCache *cache;
- cached_fonts->fonts[i] = 0; /* prevent free in FcFontSetDestroy */
- }
- cached_fonts->nfont = 0;
- FcFontSetDestroy (cached_fonts);
+ if (!config)
+ {
+ config = FcConfigGetCurrent ();
+ if (!config)
+ return FcFalse;
+ }
+
+ fonts = FcFontSetCreate ();
+ if (!fonts)
+ goto bail;
+
+ FcConfigSetFonts (config, fonts, FcSetSystem);
+
+ dirlist = FcStrListCreate (config->fontDirs);
+ if (!dirlist)
+ goto bail;
+
+ while ((dir = FcStrListNext (dirlist)))
+ {
+ if (FcDebug () & FC_DBG_FONTSET)
+ printf ("adding fonts from%s\n", dir);
+ cache = FcDirCacheRead (dir, FcFalse, config);
+ if (!cache)
+ continue;
+ FcConfigAddCache (config, cache);
+ FcDirCacheUnload (cache);
}
+ FcStrListDone (dirlist);
+
if (FcDebug () & FC_DBG_FONTSET)
FcFontSetPrint (fonts);
- FcStrSetDestroy (oldDirs);
-
- FcConfigSetFonts (config, fonts, FcSetSystem);
-
return FcTrue;
-bail3:
- FcStrSetDestroy (oldDirs);
-bail2:
- FcFontSetDestroy (fonts);
-bail0:
+bail:
return FcFalse;
}
return FcStrListCreate (config->configFiles);
}
-FcBool
-FcConfigSetCache (FcConfig *config,
- const FcChar8 *c)
-{
- FcChar8 *new = FcStrCopyFilename (c);
-
- if (!new)
- return FcFalse;
- if (config->cache)
- FcStrFree (config->cache);
- config->cache = new;
- return FcTrue;
-}
-
FcChar8 *
FcConfigGetCache (FcConfig *config)
{
- if (!config)
- {
- config = FcConfigGetCurrent ();
- if (!config)
- return 0;
- }
- return config->cache;
+ return NULL;
}
FcFontSet *
config->fonts[set] = fonts;
}
-
-
FcBlanks *
FcConfigGetBlanks (FcConfig *config)
{
FcTest *t;
int num;
+ switch (kind) {
+ case FcMatchPattern:
+ prev = &config->substPattern;
+ break;
+ case FcMatchFont:
+ prev = &config->substFont;
+ break;
+ case FcMatchScan:
+ prev = &config->substScan;
+ break;
+ default:
+ return FcFalse;
+ }
subst = (FcSubst *) malloc (sizeof (FcSubst));
if (!subst)
return FcFalse;
FcMemAlloc (FC_MEM_SUBST, sizeof (FcSubst));
- if (kind == FcMatchPattern)
- prev = &config->substPattern;
- else
- prev = &config->substFont;
for (; *prev; prev = &(*prev)->next);
*prev = subst;
subst->next = 0;
return FcFalse;
}
+ switch (kind) {
+ case FcMatchPattern:
+ s = config->substPattern;
+ break;
+ case FcMatchFont:
+ s = config->substFont;
+ break;
+ case FcMatchScan:
+ s = config->substScan;
+ break;
+ default:
+ return FcFalse;
+ }
+
st = (FcSubState *) malloc (config->maxObjects * sizeof (FcSubState));
if (!st && config->maxObjects)
return FcFalse;
printf ("FcConfigSubstitute ");
FcPatternPrint (p);
}
- if (kind == FcMatchPattern)
- s = config->substPattern;
- else
- s = config->substFont;
for (; s; s = s->next)
{
/*
FcConfigSetFonts (config, set, FcSetApplication);
}
- if (!FcFileScanConfig (set, subdirs, config->blanks, file, FcFalse, config))
+ if (!FcFileScanConfig (set, subdirs, config->blanks, file, config))
{
FcStrSetDestroy (subdirs);
return FcFalse;
return FcFalse;
return FcTrue;
}
+#define __fccfg__
+#include "fcaliastail.h"
+#undef __fccfg__