Commit c4324f54 authored by Keith Packard's avatar Keith Packard Committed by Akira TAGOH

Replace UUID file mechanism with per-directory 'map' attribute [v2]

The UUID files would be placed in each font directory to provide the
unique cache name, independent of path, for that directory. The UUID
files are undesireable for a couple of reasons:

 1) They must be placed in the font directories to be useful. This
    requires modifying the font directories themselves, introducing
    potential visible timestamp changes when running multiple
    applications, and makes the cache processing inconsistent between
    applications with permission to write to the font directories and
    applications without such permission.

 2) The UUID contents were generated randomly, which makes the font
    cache not reproducible across multiple runs.

One proposed fix for 2) is to make the UUID dependent on the font
directory path, but once we do that, we can simply use the font
directory path itself as the key as the original MD5-based font cache
naming mechanism did.

The goal of the UUID file mechanism was to fix startup time of
flatpaks; as the font path names inside the flatpak did not match the
font path names in the base system, the font cache would need to be
reconstructed the first time the flatpak was launched.

The new mechanism for doing this is to allow each '<dir>' element in
the configuration include a 'map' attribute. When looking for a cache
file for a particular directory, if the directory name starts with the
contents of the <dir> element, that portion of the name will be
replaced with the value of the 'map' attribute.

Outside of the flatpak, nothing need change -- fontconfig will build
cache files using real directory names.

Inside the flatpak, the custom fonts.conf file will now include
mappings such as this:

	<dir map="/usr/share/fonts">/run/host/fonts</dir>

When scanning the directory /run/host/fonts/ttf, fontconfig will
use the name /usr/share/fonts/ttf as the source for building the cache
file name.

The existing FC_FILE replacement code used for the UUID-based
implementation continues to correctly adapt font path names seen by
applications.

v2:
	Leave FcDirCacheCreateUUID stub around to avoid removing
	public API function.

	Document 'map' attribute of <dir> element in
	fontconfig-user.sgml
Suggested-by: Akira TAGOH's avatarAkira TAGOH <akira@tagoh.org>
Signed-off-by: Keith Packard's avatarKeith Packard <keithp@keithp.com>
parent 4cde12bf
...@@ -332,39 +332,6 @@ AM_CONDITIONAL(FREETYPE_PCF_LONG_FAMILY_NAMES, test "x$have_pcf_long_family_name ...@@ -332,39 +332,6 @@ AM_CONDITIONAL(FREETYPE_PCF_LONG_FAMILY_NAMES, test "x$have_pcf_long_family_name
LIBS="$fontconfig_save_libs" LIBS="$fontconfig_save_libs"
CFLAGS="$fontconfig_save_cflags" CFLAGS="$fontconfig_save_cflags"
#
# Check for uuid
#
if test "$os_win32" != "yes"; then
use_pkgconfig_for_uuid=yes
if test -n "${UUID_LIBS}"; then
save_UUID_LIBS=$UUID_LIBS
fi
PKG_CHECK_MODULES([UUID], [uuid],
[use_pkgconfig_for_uuid=yes],
[use_pkgconfig_for_uuid=no])
if test "x$use_pkgconfig_for_uuid" = "xno"; then
AC_MSG_CHECKING([where uuid functions comes from])
AC_TRY_LINK([#include <uuid/uuid.h>],
[uuid_t a; uuid_generate(a);],
[AC_MSG_RESULT([builtin])
UUID_CFLAGS=""
UUID_LIBS=""
],[AC_MSG_ERROR([
*** uuid is required. install util-linux.
])])
else
if test -z "${save_UUID_LIBS+x}" && test "x${UUID_LIBS}" != "x"; then
PKGCONFIG_REQUIRES_PRIVATELY="$PKGCONFIG_REQUIRES_PRIVATELY uuid"
fi
fi
else
UUID_CFLAGS=""
UUID_LIBS=""
fi
AC_SUBST(UUID_CFLAGS)
AC_SUBST(UUID_LIBS)
# #
# Check expat configuration # Check expat configuration
# #
......
...@@ -88,20 +88,6 @@ to <parameter>config</parameter>. ...@@ -88,20 +88,6 @@ to <parameter>config</parameter>.
@SINCE@ 2.9.91 @SINCE@ 2.9.91
@@ @@
@RET@ FcBool
@FUNC@ FcDirCacheCreateUUID
@TYPE1@ FcChar8 * @ARG1@ dir
@TYPE2@ FcBool @ARG2@ force
@TYPE3@ FcConfig * @ARG3@ config
@PURPOSE@ Create .uuid file at a directory
@DESC@
This is to create .uuid file containing an UUID at a font directory of
<parameter>dir</parameter>.
The UUID will be used to identify the font directory and is used to determine
the cache filename if available.
@SINCE@ 2.12.92
@@
@RET@ FcBool @RET@ FcBool
@FUNC@ FcDirCacheDeleteUUID @FUNC@ FcDirCacheDeleteUUID
@TYPE1@ const FcChar8 * @ARG1@ dir @TYPE1@ const FcChar8 * @ARG1@ dir
......
...@@ -310,9 +310,15 @@ following structure: ...@@ -310,9 +310,15 @@ following structure:
This is the top level element for a font configuration and can contain This is the top level element for a font configuration and can contain
<literal>&lt;dir&gt;</literal>, <literal>&lt;cachedir&gt;</literal>, <literal>&lt;include&gt;</literal>, <literal>&lt;match&gt;</literal> and <literal>&lt;alias&gt;</literal> elements in any order. <literal>&lt;dir&gt;</literal>, <literal>&lt;cachedir&gt;</literal>, <literal>&lt;include&gt;</literal>, <literal>&lt;match&gt;</literal> and <literal>&lt;alias&gt;</literal> elements in any order.
</para></refsect2> </para></refsect2>
<refsect2><title><literal>&lt;dir prefix="default"&gt;</literal></title><para> <refsect2><title><literal>&lt;dir prefix="default" map=""&gt;</literal></title><para>
This element contains a directory name which will be scanned for font files This element contains a directory name which will be scanned for font files
to include in the set of available fonts. If 'prefix' is set to "default" or "cwd", the current working directory will be added as the path prefix prior to the value. If 'prefix' is set to "xdg", the value in the XDG_DATA_HOME environment variable will be added as the path prefix. please see XDG Base Directory Specification for more details. If 'prefix' is set to "relative", the path of current file will be added prior to the value. to include in the set of available fonts. If 'prefix' is set to "default" or "cwd", the current working directory will be added as the path prefix prior to the value. If 'prefix' is set to "xdg", the value in the XDG_DATA_HOME environment variable will be added as the path prefix. please see XDG Base Directory Specification for more details. If 'prefix' is set to "relative", the path of current file will be added prior to the value.
</para><para>
If a 'map' attribute is specified, its value will replace the
directory path when matching cached information for fonts contained in
this directory. This is useful if the directory name is an alias
(via a bind mount or symlink) to another directory in the system for
which cached font information is likely to exist.
</para></refsect2> </para></refsect2>
<refsect2><title><literal>&lt;cachedir prefix="default"&gt;</literal></title><para> <refsect2><title><literal>&lt;cachedir prefix="default"&gt;</literal></title><para>
This element contains a directory name that is supposed to be stored or read This element contains a directory name that is supposed to be stored or read
......
...@@ -203,7 +203,6 @@ scanDirs (FcStrList *list, FcConfig *config, FcBool force, FcBool really_force, ...@@ -203,7 +203,6 @@ scanDirs (FcStrList *list, FcConfig *config, FcBool force, FcBool really_force,
if (really_force) if (really_force)
{ {
FcDirCacheUnlink (dir, config); FcDirCacheUnlink (dir, config);
FcDirCacheCreateUUID ((FcChar8 *) dir, FcTrue, config);
} }
cache = NULL; cache = NULL;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
--> -->
<!ELEMENT dir (#PCDATA)> <!ELEMENT dir (#PCDATA)>
<!ATTLIST dir <!ATTLIST dir
map CDATA #IMPLIED
prefix (default|xdg|relative|cwd) "default" prefix (default|xdg|relative|cwd) "default"
xml:space (default|preserve) 'preserve'> xml:space (default|preserve) 'preserve'>
......
...@@ -77,7 +77,6 @@ AM_CPPFLAGS = \ ...@@ -77,7 +77,6 @@ AM_CPPFLAGS = \
$(ICONV_CFLAGS) \ $(ICONV_CFLAGS) \
$(LIBXML2_CFLAGS) \ $(LIBXML2_CFLAGS) \
$(EXPAT_CFLAGS) \ $(EXPAT_CFLAGS) \
$(UUID_CFLAGS) \
$(WARN_CFLAGS) \ $(WARN_CFLAGS) \
-DFC_CACHEDIR='"$(FC_CACHEDIR)"' \ -DFC_CACHEDIR='"$(FC_CACHEDIR)"' \
-DFONTCONFIG_PATH='"$(BASECONFIGDIR)"' \ -DFONTCONFIG_PATH='"$(BASECONFIGDIR)"' \
...@@ -167,7 +166,7 @@ lib_LTLIBRARIES = libfontconfig.la ...@@ -167,7 +166,7 @@ lib_LTLIBRARIES = libfontconfig.la
libfontconfig_la_LDFLAGS = \ libfontconfig_la_LDFLAGS = \
-version-info @LIBT_VERSION_INFO@ -no-undefined $(export_symbols) -version-info @LIBT_VERSION_INFO@ -no-undefined $(export_symbols)
libfontconfig_la_LIBADD = $(ICONV_LIBS) $(FREETYPE_LIBS) $(LIBXML2_LIBS) $(EXPAT_LIBS) $(UUID_LIBS) $(LTLIBINTL) libfontconfig_la_LIBADD = $(ICONV_LIBS) $(FREETYPE_LIBS) $(LIBXML2_LIBS) $(EXPAT_LIBS) $(LTLIBINTL)
libfontconfig_la_DEPENDENCIES = $(fontconfig_def_dependency) libfontconfig_la_DEPENDENCIES = $(fontconfig_def_dependency)
......
...@@ -51,103 +51,7 @@ FcDirCacheCreateUUID (FcChar8 *dir, ...@@ -51,103 +51,7 @@ FcDirCacheCreateUUID (FcChar8 *dir,
FcBool force, FcBool force,
FcConfig *config) FcConfig *config)
{ {
FcBool ret = FcTrue; return FcTrue;
#ifndef _WIN32
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
FcChar8 *target;
FcChar8 *uuidname;
if (sysroot)
target = FcStrBuildFilename (sysroot, dir, NULL);
else
target = FcStrdup (dir);
uuidname = FcStrBuildFilename (target, ".uuid", NULL);
if (!uuidname)
{
FcStrFree (target);
return FcFalse;
}
if (force || access ((const char *) uuidname, F_OK) < 0)
{
FcAtomic *atomic;
int fd;
uuid_t uuid;
char out[37];
FcBool (* hash_add) (FcHashTable *, void*, void*);
struct stat statb;
struct timeval times[2];
if (FcStat (target, &statb) != 0)
{
ret = FcFalse;
goto bail1;
}
atomic = FcAtomicCreate (uuidname);
if (!atomic)
{
ret = FcFalse;
goto bail1;
}
if (!FcAtomicLock (atomic))
{
ret = FcFalse;
goto bail2;
}
fd = FcOpen ((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT, 0644);
if (fd == -1)
{
ret = FcFalse;
goto bail3;
}
uuid_generate_random (uuid);
if (force)
hash_add = FcHashTableReplace;
else
hash_add = FcHashTableAdd;
if (!hash_add (config->uuid_table, target, uuid))
{
ret = FcFalse;
FcAtomicDeleteNew (atomic);
close (fd);
goto bail3;
}
uuid_unparse (uuid, out);
if (FcDebug () & FC_DBG_CACHE)
printf ("FcDirCacheCreateUUID %s: %s\n", uuidname, out);
write (fd, out, strlen (out));
close (fd);
FcAtomicReplaceOrig (atomic);
bail3:
FcAtomicUnlock (atomic);
bail2:
FcAtomicDestroy (atomic);
if (ret)
{
/* revert mtime of the directory */
times[0].tv_sec = statb.st_atime;
times[1].tv_sec = statb.st_mtime;
#ifdef HAVE_STRUCT_STAT_ST_MTIM
times[0].tv_usec = statb.st_atim.tv_nsec / 1000;
times[1].tv_usec = statb.st_mtim.tv_nsec / 1000;
#else
times[0].tv_usec = 0;
times[1].tv_usec = 0;
#endif
if (utimes ((const char *) target, times) != 0)
{
fprintf (stderr, "Unable to revert mtime: %s\n", target);
}
}
}
bail1:
FcStrFree (uuidname);
FcStrFree (target);
#endif
return ret;
} }
FcBool FcBool
...@@ -187,7 +91,6 @@ FcDirCacheDeleteUUID (const FcChar8 *dir, ...@@ -187,7 +91,6 @@ FcDirCacheDeleteUUID (const FcChar8 *dir,
{ {
fprintf (stderr, "Unable to revert mtime: %s\n", d); fprintf (stderr, "Unable to revert mtime: %s\n", d);
} }
FcHashTableRemove (config->uuid_table, target);
} }
FcStrFree (target); FcStrFree (target);
bail: bail:
...@@ -197,59 +100,6 @@ bail: ...@@ -197,59 +100,6 @@ bail:
return ret; return ret;
} }
#ifndef _WIN32
static void
FcDirCacheReadUUID (FcChar8 *dir,
FcConfig *config)
{
void *u;
uuid_t uuid;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
FcChar8 *target;
if (sysroot)
target = FcStrBuildFilename (sysroot, dir, NULL);
else
target = FcStrdup (dir);
if (!FcHashTableFind (config->uuid_table, target, &u))
{
FcChar8 *uuidname = FcStrBuildFilename (target, ".uuid", NULL);
int fd;
if ((fd = FcOpen ((char *) uuidname, O_RDONLY)) >= 0)
{
char suuid[37];
ssize_t len;
memset (suuid, 0, sizeof (suuid));
len = read (fd, suuid, 36);
if (len != -1)
{
suuid[len] = 0;
memset (uuid, 0, sizeof (uuid));
if (uuid_parse (suuid, uuid) == 0)
{
if (FcDebug () & FC_DBG_CACHE)
printf ("FcDirCacheReadUUID %s -> %s\n", uuidname, suuid);
FcHashTableAdd (config->uuid_table, target, uuid);
}
}
close (fd);
}
else
{
if (FcDebug () & FC_DBG_CACHE)
printf ("FcDirCacheReadUUID Unable to read %s\n", uuidname);
}
FcStrFree (uuidname);
}
else
FcHashUuidFree (u);
FcStrFree (target);
}
#endif
struct MD5Context { struct MD5Context {
FcChar32 buf[4]; FcChar32 buf[4];
FcChar32 bits[2]; FcChar32 bits[2];
...@@ -300,18 +150,26 @@ static const char bin2hex[] = { '0', '1', '2', '3', ...@@ -300,18 +150,26 @@ static const char bin2hex[] = { '0', '1', '2', '3',
'c', 'd', 'e', 'f' }; 'c', 'd', 'e', 'f' };
static FcChar8 * static FcChar8 *
FcDirCacheBasenameMD5 (const FcChar8 *dir, FcChar8 cache_base[CACHEBASE_LEN]) FcDirCacheBasenameMD5 (FcConfig *config, const FcChar8 *dir, FcChar8 cache_base[CACHEBASE_LEN])
{ {
FcChar8 *new_dir;
unsigned char hash[16]; unsigned char hash[16];
FcChar8 *hex_hash; FcChar8 *hex_hash;
int cnt; int cnt;
struct MD5Context ctx; struct MD5Context ctx;
new_dir = FcConfigMapFontPath(config, dir);
if (new_dir)
dir = new_dir;
MD5Init (&ctx); MD5Init (&ctx);
MD5Update (&ctx, (const unsigned char *)dir, strlen ((const char *) dir)); MD5Update (&ctx, (const unsigned char *)dir, strlen ((const char *) dir));
MD5Final (hash, &ctx); MD5Final (hash, &ctx);
if (new_dir)
FcStrFree(new_dir);
cache_base[0] = '/'; cache_base[0] = '/';
hex_hash = cache_base + 1; hex_hash = cache_base + 1;
for (cnt = 0; cnt < 16; ++cnt) for (cnt = 0; cnt < 16; ++cnt)
...@@ -325,31 +183,6 @@ FcDirCacheBasenameMD5 (const FcChar8 *dir, FcChar8 cache_base[CACHEBASE_LEN]) ...@@ -325,31 +183,6 @@ FcDirCacheBasenameMD5 (const FcChar8 *dir, FcChar8 cache_base[CACHEBASE_LEN])
return cache_base; return cache_base;
} }
#ifndef _WIN32
static FcChar8 *
FcDirCacheBasenameUUID (const FcChar8 *dir, FcChar8 cache_base[CACHEBASE_LEN], FcConfig *config)
{
void *u;
FcChar8 *target;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
if (sysroot)
target = FcStrBuildFilename (sysroot, dir, NULL);
else
target = FcStrdup (dir);
if (FcHashTableFind (config->uuid_table, target, &u))
{
uuid_unparse (u, (char *) cache_base);
strcat ((char *) cache_base, "-" FC_ARCHITECTURE FC_CACHE_SUFFIX);
FcHashUuidFree (u);
FcStrFree (target);
return cache_base;
}
FcStrFree (target);
return NULL;
}
#endif
FcBool FcBool
FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config) FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
{ {
...@@ -359,10 +192,7 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config) ...@@ -359,10 +192,7 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
FcChar8 *cache_dir; FcChar8 *cache_dir;
const FcChar8 *sysroot = FcConfigGetSysRoot (config); const FcChar8 *sysroot = FcConfigGetSysRoot (config);
#ifndef _WIN32 FcDirCacheBasenameMD5 (config, dir, cache_base);
if (!FcDirCacheBasenameUUID (dir, cache_base, config))
#endif
FcDirCacheBasenameMD5 (dir, cache_base);
list = FcStrListCreate (config->cacheDirs); list = FcStrListCreate (config->cacheDirs);
if (!list) if (!list)
...@@ -439,10 +269,7 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir, ...@@ -439,10 +269,7 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
} }
FcStrFree (d); FcStrFree (d);
#ifndef _WIN32 FcDirCacheBasenameMD5 (config, dir, cache_base);
if (!FcDirCacheBasenameUUID (dir, cache_base, config))
#endif
FcDirCacheBasenameMD5 (dir, cache_base);
list = FcStrListCreate (config->cacheDirs); list = FcStrListCreate (config->cacheDirs);
if (!list) if (!list)
...@@ -1070,9 +897,6 @@ FcDirCacheLoad (const FcChar8 *dir, FcConfig *config, FcChar8 **cache_file) ...@@ -1070,9 +897,6 @@ FcDirCacheLoad (const FcChar8 *dir, FcConfig *config, FcChar8 **cache_file)
{ {
FcCache *cache = NULL; FcCache *cache = NULL;
#ifndef _WIN32
FcDirCacheReadUUID ((FcChar8 *) dir, config);
#endif
if (!FcDirCacheProcess (config, dir, if (!FcDirCacheProcess (config, dir,
FcDirCacheMapHelper, FcDirCacheMapHelper,
&cache, cache_file)) &cache, cache_file))
...@@ -1377,10 +1201,7 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config) ...@@ -1377,10 +1201,7 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
if (!cache_dir) if (!cache_dir)
return FcFalse; return FcFalse;
#ifndef _WIN32 FcDirCacheBasenameMD5 (config, dir, cache_base);
if (!FcDirCacheBasenameUUID (dir, cache_base, config))
#endif
FcDirCacheBasenameMD5 (dir, cache_base);
cache_hashed = FcStrBuildFilename (cache_dir, cache_base, NULL); cache_hashed = FcStrBuildFilename (cache_dir, cache_base, NULL);
FcStrFree (cache_dir); FcStrFree (cache_dir);
if (!cache_hashed) if (!cache_hashed)
...@@ -1577,10 +1398,7 @@ FcDirCacheLock (const FcChar8 *dir, ...@@ -1577,10 +1398,7 @@ FcDirCacheLock (const FcChar8 *dir,
const FcChar8 *sysroot = FcConfigGetSysRoot (config); const FcChar8 *sysroot = FcConfigGetSysRoot (config);
int fd = -1; int fd = -1;
#ifndef _WIN32 FcDirCacheBasenameMD5 (config, dir, cache_base);
if (!FcDirCacheBasenameUUID (dir, cache_base, config))
#endif
FcDirCacheBasenameMD5 (dir, cache_base);
list = FcStrListCreate (config->cacheDirs); list = FcStrListCreate (config->cacheDirs);
if (!list) if (!list)
return -1; return -1;
......
...@@ -52,18 +52,6 @@ retry: ...@@ -52,18 +52,6 @@ retry:
return config; return config;
} }
static FcChar32
FcHashAsStrIgnoreCase (const void *data)
{
return FcStrHashIgnoreCase (data);
}
static int
FcCompareAsStr (const void *v1, const void *v2)
{
return FcStrCmp (v1, v2);
}
static void static void
FcDestroyAsRule (void *data) FcDestroyAsRule (void *data)
{ {
...@@ -76,12 +64,6 @@ FcDestroyAsRuleSet (void *data) ...@@ -76,12 +64,6 @@ FcDestroyAsRuleSet (void *data)
FcRuleSetDestroy (data); FcRuleSetDestroy (data);
} }
static void
FcDestroyAsStr (void *data)
{
FcStrFree (data);
}
FcBool FcBool
FcConfigInit (void) FcConfigInit (void)
{ {
...@@ -127,6 +109,10 @@ FcConfigCreate (void) ...@@ -127,6 +109,10 @@ FcConfigCreate (void)
if (!config->configDirs) if (!config->configDirs)
goto bail1; goto bail1;
config->configMapDirs = FcStrSetCreate();
if (!config->configMapDirs)
goto bail1_5;
config->configFiles = FcStrSetCreate (); config->configFiles = FcStrSetCreate ();
if (!config->configFiles) if (!config->configFiles)
goto bail2; goto bail2;
...@@ -182,13 +168,6 @@ FcConfigCreate (void) ...@@ -182,13 +168,6 @@ FcConfigCreate (void)
if (!config->availConfigFiles) if (!config->availConfigFiles)
goto bail10; goto bail10;
config->uuid_table = FcHashTableCreate (FcHashAsStrIgnoreCase,
FcCompareAsStr,
FcHashStrCopy,
FcHashUuidCopy,
FcDestroyAsStr,
FcHashUuidFree);
FcRefInit (&config->ref, 1); FcRefInit (&config->ref, 1);
return config; return config;
...@@ -213,6 +192,8 @@ bail4: ...@@ -213,6 +192,8 @@ bail4:
bail3: bail3:
FcStrSetDestroy (config->configFiles); FcStrSetDestroy (config->configFiles);
bail2: bail2:
FcStrSetDestroy (config->configMapDirs);
bail1_5:
FcStrSetDestroy (config->configDirs); FcStrSetDestroy (config->configDirs);
bail1: bail1:
free (config); free (config);
...@@ -324,6 +305,7 @@ FcConfigDestroy (FcConfig *config) ...@@ -324,6 +305,7 @@ FcConfigDestroy (FcConfig *config)
(void) fc_atomic_ptr_cmpexch (&_fcConfig, config, NULL); (void) fc_atomic_ptr_cmpexch (&_fcConfig, config, NULL);
FcStrSetDestroy (config->configDirs); FcStrSetDestroy (config->configDirs);
FcStrSetDestroy (config->configMapDirs);
FcStrSetDestroy (config->fontDirs); FcStrSetDestroy (config->fontDirs);
FcStrSetDestroy (config->cacheDirs); FcStrSetDestroy (config->cacheDirs);
FcStrSetDestroy (config->configFiles); FcStrSetDestroy (config->configFiles);
...@@ -350,8 +332,6 @@ FcConfigDestroy (FcConfig *config) ...@@ -350,8 +332,6 @@ FcConfigDestroy (FcConfig *config)
if (config->sysRoot) if (config->sysRoot)
FcStrFree (config->sysRoot); FcStrFree (config->sysRoot);
FcHashTableDestroy (config->uuid_table);
free (config); free (config);
} }
...@@ -559,9 +539,10 @@ FcConfigGetConfigDirs (FcConfig *config) ...@@ -559,9 +539,10 @@ FcConfigGetConfigDirs (FcConfig *config)
FcBool FcBool
FcConfigAddFontDir (FcConfig *config, FcConfigAddFontDir (FcConfig *config,
const FcChar8 *d) const FcChar8 *d,
const FcChar8 *m)
{ {
return FcStrSetAddFilename (config->fontDirs, d); return FcStrSetAddFilenamePair (config->fontDirs, d, m);
} }
FcStrList * FcStrList *
...@@ -576,6 +557,47 @@ FcConfigGetFontDirs (FcConfig *config) ...@@ -576,6 +557,47 @@ FcConfigGetFontDirs (FcConfig *config)
return FcStrListCreate (config->fontDirs); return FcStrListCreate (config->fontDirs);
} }
static FcBool
FcConfigPathStartsWith(const FcChar8 *path,
const FcChar8 *start)
{
int len = strlen((char *) start);
if (strncmp((char *) path, (char *) start, len) != 0)
return FcFalse;
switch (path[len]) {
case '\0':
case FC_DIR_SEPARATOR:
return FcTrue;
default:
return FcFalse;
}
}
FcChar8 *
FcConfigMapFontPath(FcConfig *config,
const FcChar8 *path)
{
FcStrList *list;
FcChar8 *dir;
FcChar8 *map;
list = FcConfigGetFontDirs(config);
if (!list)
return 0;
while ((dir = FcStrListNext(list)))
if (FcConfigPathStartsWith(path, dir))
break;
FcStrListDone(list);
if (!dir)
return 0;
map = FcStrPairSecond(dir);
if (!map)
return 0;
return FcStrBuildFilename(map, path + strlen((char *) dir), NULL);
}
FcBool FcBool
FcConfigAddCacheDir (FcConfig *config, FcConfigAddCacheDir (FcConfig *config,
const FcChar8 *d) const FcChar8 *d)
......
...@@ -413,7 +413,6 @@ FcDirCacheRead (const FcChar8 *dir, FcBool force, FcConfig *config) ...@@ -413,7 +413,6 @@ FcDirCacheRead (const FcChar8 *dir, FcBool force, FcConfig *config)
{ {
FcCache *cache = NULL; FcCache *cache = NULL;
FcDirCacheCreateUUID ((FcChar8 *) dir, FcFalse, config);
/* Try to use existing cache file */ /* Try to use existing cache file */
if (!force) if (!force)
cache = FcDirCacheLoad (dir, config, NULL); cache = FcDirCacheLoad (dir, config, NULL);
......
...@@ -52,23 +52,6 @@ FcHashStrCopy (const void *src, ...@@ -52,23 +52,6 @@ FcHashStrCopy (const void *src,
return *dest != NULL; return *dest != NULL;
} }
FcBool
FcHashUuidCopy (const void *src,
void **dest)
{
#ifndef _WIN32
*dest = malloc (sizeof (uuid_t));
uuid_copy (*dest, src);
#endif
return FcTrue;
}
void
FcHashUuidFree (void *data)
{
free (data);
}
FcHashTable * FcHashTable *
FcHashTableCreate (FcHashFunc hash_func, FcHashTableCreate (FcHashFunc hash_func,
FcCompareFunc compare_func, FcCompareFunc compare_func,
......
...@@ -509,6 +509,7 @@ struct _FcConfig { ...@@ -509,6 +509,7 @@ struct _FcConfig {
* and those directives may occur in any order * and those directives may occur in any order
*/ */
FcStrSet *configDirs; /* directories to scan for fonts */ FcStrSet *configDirs; /* directories to scan for fonts */
FcStrSet *configMapDirs; /* mapped names to generate cache entries */
/* /*
* List of directories containing fonts, * List of directories containing fonts,
* built by recursively scanning the set * built by recursively scanning the set
...@@ -565,7 +566,6 @@ struct _FcConfig { ...@@ -565,7 +566,6 @@ struct _FcConfig {
FcChar8 *sysRoot; /* override the system root directory */ FcChar8 *sysRoot; /* override the system root directory */
FcStrSet *availConfigFiles; /* config files available */ FcStrSet *availConfigFiles; /* config files available */
FcPtrList *rulesetList; /* List of rulesets being installed */ FcPtrList *rulesetList; /* List of rulesets being installed */
FcHashTable *uuid_table; /* UUID table for cachedirs */
}; };
typedef struct _FcFileTime { typedef struct _FcFileTime {
...@@ -659,7 +659,12 @@ FcConfigAddConfigDir (FcConfig *config, ...@@ -659,7 +659,12 @@ FcConfigAddConfigDir (FcConfig *config,
FcPrivate FcBool FcPrivate FcBool
FcConfigAddFontDir (FcConfig *config, FcConfigAddFontDir (FcConfig *config,
const FcChar8 *d); const FcChar8 *d,
const FcChar8 *m);
FcPrivate FcChar8 *
FcConfigMapFontPath(FcConfig *config,
const FcChar8 *path);
FcPrivate FcBool FcPrivate FcBool
FcConfigAddCacheDir (FcConfig *config, FcConfigAddCacheDir (FcConfig *config,
...@@ -1236,6 +1241,15 @@ FcStrSetAddLangs (FcStrSet *strs, const char *languages); ...@@ -1236,6 +1241,15 @@ FcStrSetAddLangs (FcStrSet *strs, const char *languages);