in FcConfig's fontDirs string set, as canonical.
Actually update config.fontDirs as font directories are scanned.
+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):
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);
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);
if (ls)
*ls = 0;
- if (!FcDirCacheConsume (fd, dir, set))
+ if (!FcDirCacheConsume (fd, dir, set, 0))
goto bail2;
free (dir);
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);
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;
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);
/* 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;
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);
}
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;
return FcFalse;
FcCacheAddBankDir (metadata.bank, dir);
+ if (config)
+ FcConfigAddFontDir (config, (FcChar8 *)dir);
if (!FcFontSetUnserialize (&metadata, set, current_dir_block))
return FcFalse;
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;
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)
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;
}
return FcFalse;
}
+ FcConfigAddFontDir (config, dir);
tmpSet = FcFontSetCreate();
if (!tmpSet)
{
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
FcConfigAddConfigFile (FcConfig *config,
const FcChar8 *f);
+const FcChar8 *
+FcConfigNormalizeFontDir (FcConfig *config,
+ const FcChar8 *d);
+
FcBool
FcConfigSetCache (FcConfig *config,
const FcChar8 *c);