}
static unsigned int
-FcCacheHash (const FcChar8 *string)
+FcCacheHash (const FcChar8 *string, int len)
{
unsigned int h = 0;
FcChar8 c;
- while ((c = *string++))
+ while (len-- && (c = *string++))
h = (h << 1) ^ c;
- return 0;
+ return h;
}
/*
i.dir_len = 1;
i.base = path;
}
- i.base_hash = FcCacheHash (i.base);
+ i.base_hash = FcCacheHash (i.base, -1);
return i;
}
int len,
FcBool create_missing)
{
- unsigned int hash = FcCacheHash (dir);
+ unsigned int hash = FcCacheHash (dir, len);
FcGlobalCacheDir *d, **prev;
for (prev = &cache->ents[hash % FC_GLOBAL_CACHE_DIR_HASH_SIZE];
free (d);
}
+/*
+ * Check to see if the global cache contains valid data for 'dir'.
+ * If so, scan the global cache for files and directories in 'dir'.
+ * else, return False.
+ */
FcBool
FcGlobalCacheScanDir (FcFontSet *set,
FcStrSet *dirs,
int h;
int dir_len;
FcGlobalCacheSubdir *subdir;
+ FcBool any_in_cache = FcFalse;
if (FcDebug() & FC_DBG_CACHE)
printf ("FcGlobalCacheScanDir %s\n", dir);
return FcFalse;
}
+ /*
+ * See if the timestamp recorded in the global cache
+ * matches the directory time, if not, return False
+ */
if (!FcGlobalCacheCheckTime (&d->info))
{
if (FcDebug () & FC_DBG_CACHE)
return FcFalse;
}
+ /*
+ * Add files from 'dir' to the fontset
+ */
dir_len = strlen ((const char *) dir);
for (h = 0; h < FC_GLOBAL_CACHE_FILE_HASH_SIZE; h++)
for (f = d->ents[h]; f; f = f->next)
{
if (FcDebug() & FC_DBG_CACHEV)
printf ("FcGlobalCacheScanDir add file %s\n", f->info.file);
+ any_in_cache = FcTrue;
if (!FcCacheFontSetAdd (set, dirs, dir, dir_len,
f->info.file, f->name))
{
}
FcGlobalCacheReferenced (cache, &f->info);
}
+ /*
+ * Add directories in 'dir' to 'dirs'
+ */
for (subdir = d->subdirs; subdir; subdir = subdir->next)
{
FcFilePathInfo info = FcFilePathInfoGet (subdir->ent->info.file);
+ any_in_cache = FcTrue;
if (!FcCacheFontSetAdd (set, dirs, dir, dir_len,
info.base, FC_FONT_FILE_DIR))
{
FcGlobalCacheReferenced (cache, &d->info);
- return FcTrue;
+ /*
+ * To recover from a bug in previous versions of fontconfig,
+ * return FcFalse if no entries in the cache were found
+ * for this directory. This will cause any empty directories
+ * to get rescanned every time fontconfig is initialized. This
+ * might get removed at some point when the older cache files are
+ * presumably fixed.
+ */
+ return any_in_cache;
}
/*
{
isDir = FcTrue;
ret = FcStrSetAdd (dirs, file);
- if (cache && ret)
- FcGlobalCacheUpdate (cache, file, 0, FC_FONT_FILE_DIR);
}
/*
* Update the cache
#define FC_MAX_FILE_LEN 4096
+/*
+ * Scan 'dir', adding font files to 'set' and
+ * subdirectories to 'dirs'
+ */
+
FcBool
FcDirScan (FcFontSet *set,
FcStrSet *dirs,
}
free (file);
closedir (d);
+ /*
+ * Now that the directory has been scanned,
+ * add the cache entry
+ */
if (ret && cache)
FcGlobalCacheUpdate (cache, dir, 0, 0);