summaryrefslogtreecommitdiff
path: root/src/fccfg.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@neko.keithp.com>2006-09-01 01:15:14 -0700
committerKeith Packard <keithp@neko.keithp.com>2006-09-01 01:15:14 -0700
commitbc5e487f2a1ad9946aa5c6e19cd75794fc38d530 (patch)
treeaecca6b73781e0dd0476da86f82ffbca5165d364 /src/fccfg.c
parentaec8c90b450c115718fd87bc270e35ee6b605967 (diff)
Pass directory information around in FcCache structure. Freeze charsets.
Instead of passing directory information around in separate variables, collect it all in an FcCache structure. Numerous internal and tool interfaces changed as a result of this. Charsets are now pre-frozen before being serialized. This causes them to share across multiple fonts in the same cache.
Diffstat (limited to 'src/fccfg.c')
-rw-r--r--src/fccfg.c169
1 files changed, 95 insertions, 74 deletions
diff --git a/src/fccfg.c b/src/fccfg.c
index bcc3bd28..cec0e4a7 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -222,7 +222,7 @@ FcConfigDestroy (FcConfig *config)
for (cl = config->caches; cl; cl = cl_next)
{
cl_next = cl->next;
- FcDirCacheUnmap (cl->cache);
+ FcDirCacheUnload (cl->cache);
free (cl);
}
@@ -231,86 +231,120 @@ FcConfigDestroy (FcConfig *config)
}
/*
- * 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;
+ FcCacheList *cl = malloc (sizeof (FcCacheList));
+ FcFontSet *fs;
+ intptr_t *dirs;
+ int i;
- fonts = FcFontSetCreate ();
- if (!fonts)
- goto bail0;
-
- oldDirs = FcStrSetCreate ();
- if (!oldDirs)
- goto bail2;
+ /*
+ * Add to cache list
+ */
+ if (!cl)
+ return FcFalse;
+ cl->cache = cache;
+ cl->next = config->caches;
+ config->caches = cl;
- cached_fonts = FcCacheRead(config);
- if (!cached_fonts)
+ /*
+ * Add fonts
+ */
+ fs = FcCacheSet (cache);
+ if (fs)
{
- list = FcConfigGetFontDirs (config);
- if (!list)
- goto bail3;
-
- 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;
+
+ FcFontSetAdd (config->fonts[FcSetSystem], font);
}
-
- FcStrListDone (list);
}
- 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);
+ }
+
+ 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;
}
@@ -457,19 +491,6 @@ FcConfigSetFonts (FcConfig *config,
config->fonts[set] = fonts;
}
-FcBool
-FcConfigAddCache (FcConfig *config, FcCache *cache)
-{
- FcCacheList *cl = malloc (sizeof (FcCacheList));
-
- if (!cl)
- return FcFalse;
- cl->cache = cache;
- cl->next = config->caches;
- config->caches = cl;
- return FcTrue;
-}
-
FcBlanks *
FcConfigGetBlanks (FcConfig *config)
{
@@ -1750,7 +1771,7 @@ FcConfigAppFontAddFile (FcConfig *config,
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;