]> git.wh0rd.org - fontconfig.git/commitdiff
Normalize font dirs by using the form, as given in fonts.conf, and recorded
authorPatrick Lam <plam@MIT.EDU>
Mon, 9 Jan 2006 13:58:04 +0000 (13:58 +0000)
committerPatrick Lam <plam@MIT.EDU>
Mon, 9 Jan 2006 13:58:04 +0000 (13:58 +0000)
    in FcConfig's fontDirs string set, as canonical.
Actually update config.fontDirs as font directories are scanned.

ChangeLog
fc-cache/fc-cache.c
fc-cat/fc-cat.c
src/fccache.c
src/fccfg.c
src/fcdir.c
src/fcint.h

index 9a11603be8c190b213817c8ca123d3674e3195ea..5b15e60b762cd566ca39776f73005c4895f7b121 100644 (file)
--- 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):
 
index 7acaafe4a9acdc727836300c573c153d4e6ee8b7..6aa53a5a76bc5c2445909f572509f6ca157fffb3 100644 (file)
@@ -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);
index 14e5c164f8eb0ec86ce8fd74c48925ef63fc2981..419d29ffeabaa6b83cd2060fda1a51d49b6a45c6 100644 (file)
@@ -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);
 
index 99d70417e4c8f3612d36268e2d94ba3bd12c47e6..e68259f1f0d9b1aa60f24faec75b5cfb0ee486c6 100644 (file)
@@ -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;
index eefbca982e356e02d085b6e5bb87742241b2cad8..8b4494819e430626c18edfc846afb2f21d64be7b 100644 (file)
@@ -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)
index 5452b60ca6f91daf2c6da51610faac751e7fbb29..cf4a25be363ae305e2e378365e17c259b49ea0d5 100644 (file)
@@ -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)
     {  
index 435af824145ef1129aef4460e0f8310299afd41b..8043e86490bebfe7e6f77b8b2e0840c3c4e4e87a 100644 (file)
@@ -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);