summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--fc-cache/fc-cache.c2
-rw-r--r--fc-cat/fc-cat.c4
-rw-r--r--src/fccache.c21
-rw-r--r--src/fccfg.c23
-rw-r--r--src/fcdir.c3
-rw-r--r--src/fcint.h6
7 files changed, 59 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a11603b..5b15e60b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+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):
diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c
index 7acaafe4..6aa53a5a 100644
--- a/fc-cache/fc-cache.c
+++ b/fc-cache/fc-cache.c
@@ -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);
diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c
index 14e5c164..419d29ff 100644
--- a/fc-cat/fc-cat.c
+++ b/fc-cat/fc-cat.c
@@ -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);
diff --git a/src/fccache.c b/src/fccache.c
index 99d70417..e68259f1 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -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;
diff --git a/src/fccfg.c b/src/fccfg.c
index eefbca98..8b449481 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -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)
diff --git a/src/fcdir.c b/src/fcdir.c
index 5452b60c..cf4a25be 100644
--- a/src/fcdir.c
+++ b/src/fcdir.c
@@ -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)
{
diff --git a/src/fcint.h b/src/fcint.h
index 435af824..8043e864 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -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);