Commit 7410e40b authored by Patrick Lam's avatar Patrick Lam

2006-08-04 Keith Packard (keithp@keithp.com) reviewed by: plam

Make cache directories configurable. Simplify and correct some code which
    deals with per-directory caches.
parent 62a4a845
2006-08-04 Keith Packard (keithp@keithp.com)
reviewed by: plam
* configure.in:
* fonts.conf.in:
* fonts.dtd:
* fc-cache/fc-cache.c (scanDirs):
* fontconfig/fontconfig.h:
* src/Makefile.am:
* src/fcint.h:
* src/fccache.c (FcDirCacheValid, FcDirHasCurrentArch,
FcDirCacheUnlink, FcDirCacheBasename,
FcCacheReadDirs, FcDirCacheOpen, FcDirCacheRead,
FcMakeDirectory, FcDirCacheWrite):
* src/fccfg.c (FcConfigCreate, FcConfigDestroy, FcConfigAddCacheDir,
FcConfigGetCacheDirs):
* src/fcdir.c (FcDirScanConfig, FcDirSave):
* src/fcinit.c (FcInitFallbackConfig):
* src/fcxml.c (fcElementMap, FcEndElement):
* test/fonts.conf.in, test/run-test.sh:
Make cache directories configurable. Simplify and correct
some code which deals with per-directory caches.
2006-07-19 Jon Burgess (jburgess@uklinux.net)
reviewed by: plam
......
......@@ -431,6 +431,22 @@ esac
AC_SUBST(FC_FONTPATH)
#
# Set default cache directory path
#
AC_ARG_WITH(cache-dir, [ --with-cache-dir=DIR Use DIR to store cache files (default /var/cache/fontconfig)], fc_cachedir="$withval", fc_cachedir=yes)
case $fc_cachedir in
no|yes)
fc_cachedir=`eval echo "${localstatedir}/cache/"${PACKAGE}`
;;
*)
;;
esac
AC_SUBST(fc_cachedir)
FC_CACHEDIR=${fc_cachedir}
AC_SUBST(FC_CACHEDIR)
FC_FONTDATE=`LC_ALL=C date`
AC_SUBST(FC_FONTDATE)
......@@ -516,12 +532,6 @@ fi
AC_SUBST(DOCDIR)
#
# Make /var/cache/fontconfig directory available to source code
#
pkgcachedir='${localstatedir}/cache/'${PACKAGE}
AC_SUBST(pkgcachedir)
AC_OUTPUT([
Makefile
......
......@@ -230,7 +230,8 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
ret++;
continue;
}
if (!force && FcDirCacheValid (dir) && FcDirCacheHasCurrentArch (dir))
if (!force && FcDirCacheValid (dir, config) &&
FcDirCacheHasCurrentArch (dir, config))
{
if (verbose)
printf ("skipping, %d fonts, %d dirs\n",
......@@ -244,14 +245,12 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
/* This is the only reason we can't combine
* Valid w/HasCurrentArch... */
if (!FcDirCacheValid (dir))
if (!FcDirCacheValid (dir, config))
if (!FcDirCacheUnlink (dir, config))
ret++;
if (!FcDirSave (set, subdirs, dir))
{
if (!ret)
fprintf (stderr, "Caches are currently saved to \"%s\"\n", PKGCACHEDIR);
fprintf (stderr, "Can't save cache for \"%s\"\n", dir);
ret++;
}
......
......@@ -276,10 +276,10 @@ typedef struct _FcStrSet FcStrSet;
_FCFUNCPROTOBEGIN
FcBool
FcDirCacheValid (const FcChar8 *cache_file);
FcDirCacheValid (const FcChar8 *cache_file, FcConfig *config);
FcBool
FcDirCacheHasCurrentArch (const FcChar8 *dir);
FcDirCacheHasCurrentArch (const FcChar8 *dir, FcConfig *config);
FcBool
FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config);
......
......@@ -27,6 +27,11 @@
@FC_FONTPATH@
<dir>~/.fonts</dir>
<!-- Font cache directory list -->
<cachedir>@FC_CACHEDIR@</cachedir>
<cachedir>~/.fonts/fontconfig</cachedir>
<!--
Accept deprecated 'mono' alias, replacing it with 'monospace'
-->
......
......@@ -22,6 +22,18 @@
<!ELEMENT cache (#PCDATA)>
<!ATTLIST cache xml:space (default|preserve) 'preserve'>
<!--
Add a directory that is searched for font cache files.
These hold per-directory cache data and are searched in
order for each directory. When writing cache files, the first
directory which allows the cache file to be created is used.
A leading '~' in a directory name is replaced with the users
home directory path.
-->
<!ELEMENT cachedir (#PCDATA)>
<!ATTLIST cachedir xml:space (default|preserve) 'preserve'>
<!--
Reference another configuration file; note that this
is another complete font configuration file and not
......
......@@ -63,8 +63,6 @@ uninstall-ms-import-lib:
endif
AM_CPPFLAGS = -DPKGCACHEDIR='"${pkgcachedir}"'
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/src \
......@@ -72,6 +70,7 @@ INCLUDES = \
$(LIBXML2_CFLAGS) \
$(EXPAT_CFLAGS) \
$(WARN_CFLAGS) \
-DFC_CACHEDIR='"$(FC_CACHEDIR)"' \
-DFONTCONFIG_PATH='"$(CONFDIR)"'
EXTRA_DIST = fontconfig.def.in
......
This diff is collapsed.
......@@ -100,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;
......@@ -120,6 +124,8 @@ FcConfigCreate (void)
return config;
bail9:
FcStrFree (config->cache);
bail8:
FcFontSetDestroy (config->rejectPatterns);
bail7:
......@@ -226,6 +232,7 @@ FcConfigDestroy (FcConfig *config)
FcStrSetDestroy (config->configDirs);
FcStrSetDestroy (config->fontDirs);
FcStrSetDestroy (config->cacheDirs);
FcStrSetDestroy (config->configFiles);
FcStrSetDestroy (config->acceptGlobs);
FcStrSetDestroy (config->rejectGlobs);
......@@ -512,6 +519,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)
......
......@@ -151,8 +151,8 @@ FcDirScanConfig (FcFontSet *set,
if (cache && FcGlobalCacheReadDir (set, dirs, cache, (char *)dir, config))
return FcTrue;
if (FcDirCacheValid (dir) &&
FcDirCacheHasCurrentArch (dir) &&
if (FcDirCacheValid (dir, config) &&
FcDirCacheHasCurrentArch (dir, config) &&
FcDirCacheRead (set, dirs, dir, config))
return FcTrue;
}
......@@ -277,5 +277,5 @@ FcDirScan (FcFontSet *set,
FcBool
FcDirSave (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir)
{
return FcDirCacheWrite (set, dirs, dir);
return FcDirCacheWrite (set, dirs, dir, FcConfigGetCurrent ());
}
......@@ -35,6 +35,8 @@ FcInitFallbackConfig (void)
goto bail0;
if (!FcConfigAddDir (config, (FcChar8 *) FC_DEFAULT_FONTS))
goto bail1;
if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR))
goto bail1;
return config;
bail1:
......
......@@ -388,6 +388,10 @@ struct _FcConfig {
* of configured directories
*/
FcStrSet *fontDirs;
/*
* List of directories containing cache files.
*/
FcStrSet *cacheDirs;
/*
* Names of all of the configuration files used
* to create this configuration
......@@ -476,7 +480,7 @@ FcFontSet *
FcCacheRead (FcConfig *config, FcGlobalCache * cache);
FcBool
FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir);
FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
FcBool
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
......@@ -508,6 +512,13 @@ FcBool
FcConfigAddDir (FcConfig *config,
const FcChar8 *d);
FcBool
FcConfigAddCacheDir (FcConfig *config,
const FcChar8 *d);
FcStrList *
FcConfigGetCacheDirs (FcConfig *config);
FcBool
FcConfigAddConfigFile (FcConfig *config,
const FcChar8 *f);
......
......@@ -285,6 +285,7 @@ typedef enum _FcElement {
FcElementNone,
FcElementFontconfig,
FcElementDir,
FcElementCacheDir,
FcElementCache,
FcElementInclude,
FcElementConfig,
......@@ -345,6 +346,7 @@ static const struct {
} fcElementMap[] = {
{ "fontconfig", FcElementFontconfig },
{ "dir", FcElementDir },
{ "cachedir", FcElementCacheDir },
{ "cache", FcElementCache },
{ "include", FcElementInclude },
{ "config", FcElementConfig },
......@@ -2053,6 +2055,21 @@ FcEndElement(void *userData, const XML_Char *name)
}
FcStrFree (data);
break;
case FcElementCacheDir:
data = FcStrBufDone (&parse->pstack->str);
if (!data)
{
FcConfigMessage (parse, FcSevereError, "out of memory");
break;
}
if (!FcStrUsesHome (data) || FcConfigHome ())
{
if (!FcConfigAddCacheDir (parse->config, data))
FcConfigMessage (parse, FcSevereError, "out of memory; cannot add cache directory %s", data);
}
FcStrFree (data);
break;
case FcElementCache:
data = FcStrBufDone (&parse->pstack->str);
if (!data)
......
<fontconfig>
<dir>@FONTDIR@</dir>
<cache>@CACHEFILE@</cache>
<cachedir>@CACHEDIR@</cachedir>
</fontconfig>
......@@ -3,6 +3,7 @@ TESTDIR=${srcdir-`pwd`}
FONTDIR=`pwd`/fonts
CACHEFILE=`pwd`/fonts.cache
CACHEDIR=`pwd`/cache.dir
ECHO=true
......@@ -39,7 +40,8 @@ dotest () {
}
sed "s!@FONTDIR@!$FONTDIR!
s!@CACHEFILE@!$CACHEFILE!" < $TESTDIR/fonts.conf.in > fonts.conf
s!@CACHEFILE@!$CACHEFILE!
s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts.conf
FONTCONFIG_FILE=`pwd`/fonts.conf
export FONTCONFIG_FILE
......@@ -89,4 +91,4 @@ mkdir $FONTDIR/a
cp $FONT2 $FONTDIR/a
check
rm -rf $FONTDIR $CACHEFILE $FONTCONFIG_FILE out
rm -rf $FONTDIR $CACHEFILE $CACHEDIR $FONTCONFIG_FILE out
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment