Commit cd9bca69 authored by Patrick Lam's avatar Patrick Lam
Browse files

Normalize font dirs by using the form, as given in fonts.conf, and recorded

    in FcConfig's fontDirs string set, as canonical.
Actually update config.fontDirs as font directories are scanned.
parent 5576a587
2006-01-09 Patrick Lam <plam@mit.edu>
* fc-cache/fc-cache.c (scanDirs):
* fc-cat/fc-cat.c (FcCacheGlobalFileReadAndPrint, FcCacheFileRead):
* src/fccache.c (FcGlobalCacheReadDir, FcCacheReadDirs,
FcDirCacheRead, FcDirCacheConsume, FcDirCacheWrite):
* src/fccfg.c (FcConfigNormalizeFontDir):
* src/fcdir.c (FcDirScanConfig):
* src/fcint.h:
Normalize font dirs by using the form, as given in fonts.conf, and
recorded in FcConfig's fontDirs string set, as canonical.
Actually update config.fontDirs as font directories are scanned.
2006-01-08 James Su <james.su@gmail.com>
* src/fcmatch.c (FcFontSetMatch):
......
......@@ -183,7 +183,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
FcStrSetDestroy (subdirs);
continue;
}
if (!FcDirScan (set, subdirs, 0, FcConfigGetBlanks (config), dir, force))
if (!FcDirScanConfig (set, subdirs, 0, FcConfigGetBlanks (config), dir, force, config))
{
fprintf (stderr, "\"%s\": error scanning\n", dir);
FcFontSetDestroy (set);
......
......@@ -202,7 +202,7 @@ FcCacheGlobalFileReadAndPrint (FcFontSet * set, FcStrSet *dirs, char *cache_file
printf ("fc-cat: printing global cache contents for dir %s\n",
name_buf);
if (!FcDirCacheConsume (fd, name_buf, set))
if (!FcDirCacheConsume (fd, name_buf, set, 0))
goto bail1;
dir = strdup(name_buf);
......@@ -261,7 +261,7 @@ FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char *cache_file)
if (ls)
*ls = 0;
if (!FcDirCacheConsume (fd, dir, set))
if (!FcDirCacheConsume (fd, dir, set, 0))
goto bail2;
free (dir);
......
......@@ -52,10 +52,7 @@ static void *
FcDirCacheProduce (FcFontSet *set, FcCache * metadata);
static FcBool
FcDirCacheConsume (int fd, const char * dir, FcFontSet *set);
FcBool
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir);
FcDirCacheConsume (int fd, const char * dir, FcFontSet *set, FcConfig *config);
static int
FcCacheNextOffset(off_t w);
......@@ -312,7 +309,7 @@ FcGlobalCacheReadDir (FcFontSet *set, FcStrSet *dirs, FcGlobalCache * cache, con
if (strncmp (d->name, dir, strlen(dir)) == 0)
{
lseek (cache->fd, d->offset, SEEK_SET);
if (!FcDirCacheConsume (cache->fd, dir, set))
if (!FcDirCacheConsume (cache->fd, dir, set, config))
return FcFalse;
if (strcmp (d->name, dir) == 0)
ret = FcTrue;
......@@ -788,7 +785,7 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
free (file);
continue;
}
if (!FcDirCacheValid (dir) || !FcDirCacheRead (set, subdirs, dir))
if (!FcDirCacheValid (dir) || !FcDirCacheRead (set, subdirs, dir, config))
{
if (FcDebug () & FC_DBG_FONTSET)
printf ("cache scan dir %s\n", dir);
......@@ -909,7 +906,7 @@ FcDirCacheOpen (char *cache_file)
/* read serialized state from the cache file */
FcBool
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir)
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config)
{
char *cache_file;
int fd;
......@@ -940,7 +937,7 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir)
while (strlen(FcCacheReadString (fd, subdirName, sizeof (subdirName))) > 0)
FcStrSetAdd (dirs, (FcChar8 *)subdirName);
if (!FcDirCacheConsume (fd, (const char *)dir, set))
if (!FcDirCacheConsume (fd, (const char *)dir, set, config))
goto bail1;
close(fd);
......@@ -955,7 +952,7 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir)
}
static FcBool
FcDirCacheConsume (int fd, const char * dir, FcFontSet *set)
FcDirCacheConsume (int fd, const char * dir, FcFontSet *set, FcConfig *config)
{
FcCache metadata;
void * current_dir_block;
......@@ -980,6 +977,8 @@ FcDirCacheConsume (int fd, const char * dir, FcFontSet *set)
return FcFalse;
FcCacheAddBankDir (metadata.bank, dir);
if (config)
FcConfigAddFontDir (config, (FcChar8 *)dir);
if (!FcFontSetUnserialize (&metadata, set, current_dir_block))
return FcFalse;
......@@ -1052,6 +1051,10 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
char *current_arch_machine_name, * header;
void *current_dir_block = 0;
dir = FcConfigNormalizeFontDir (FcConfigGetCurrent(), dir);
if (!dir)
return FcFalse;
cache_file = (char *)FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
if (!cache_file)
goto bail;
......
......@@ -388,6 +388,29 @@ FcConfigAddFontDir (FcConfig *config,
return FcStrSetAddFilename (config->fontDirs, d);
}
const FcChar8 *
FcConfigNormalizeFontDir (FcConfig *config,
const FcChar8 *d)
{
/* If this is a bottleneck, we can cache the fontDir inodes. */
ino_t di;
int n;
struct stat s;
if (stat ((char *)d, &s) == -1)
return 0;
di = s.st_ino;
for (n = 0; n < config->fontDirs->num; n++)
{
if (stat ((char *)config->fontDirs->strs[n], &s) == -1)
continue;
if (di == s.st_ino)
return config->fontDirs->strs[n];
}
return 0;
}
FcBool
FcConfigAddDir (FcConfig *config,
const FcChar8 *d)
......
......@@ -139,7 +139,7 @@ FcDirScanConfig (FcFontSet *set,
if (cache && FcGlobalCacheReadDir (set, dirs, cache, (char *)dir, config))
return FcTrue;
if (FcDirCacheValid (dir) && FcDirCacheRead (set, dirs, dir))
if (FcDirCacheValid (dir) && FcDirCacheRead (set, dirs, dir, config))
return FcTrue;
}
......@@ -165,6 +165,7 @@ FcDirScanConfig (FcFontSet *set,
return FcFalse;
}
FcConfigAddFontDir (config, dir);
tmpSet = FcFontSetCreate();
if (!tmpSet)
{
......
......@@ -461,7 +461,7 @@ FcBool
FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir);
FcBool
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir);
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
extern int *_fcBankId, *_fcBankIdx;
int
......@@ -494,6 +494,10 @@ FcBool
FcConfigAddConfigFile (FcConfig *config,
const FcChar8 *f);
const FcChar8 *
FcConfigNormalizeFontDir (FcConfig *config,
const FcChar8 *d);
FcBool
FcConfigSetCache (FcConfig *config,
const FcChar8 *c);
......
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