src/fcint.c
The global cache now uses the same mmap-based cache infrastructure as the per-directory caches. Furthermore, the global cache is automatically updated (if possible) whenever fontconfig is used. Rip out remnants of the old cache infrastructure.
This commit is contained in:
parent
2dbe759762
commit
eb0cf67144
|
@ -191,7 +191,6 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
|
||||||
ret++;
|
ret++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#if 0 // put this back later after fixing DirCacheValid
|
|
||||||
if (!force && FcDirCacheValid (dir))
|
if (!force && FcDirCacheValid (dir))
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
|
@ -199,7 +198,6 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
|
||||||
set->nfont, nsubdirs(subdirs));
|
set->nfont, nsubdirs(subdirs));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf ("caching, %d fonts, %d dirs\n",
|
printf ("caching, %d fonts, %d dirs\n",
|
||||||
|
@ -271,7 +269,6 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
if (systemOnly)
|
if (systemOnly)
|
||||||
FcConfigEnableHome (FcFalse);
|
FcConfigEnableHome (FcFalse);
|
||||||
FcCacheForce (FcTrue);
|
|
||||||
/* need to use FcInitLoadConfig when we use dirs */
|
/* need to use FcInitLoadConfig when we use dirs */
|
||||||
FcInit ();
|
FcInit ();
|
||||||
config = FcConfigGetCurrent ();
|
config = FcConfigGetCurrent ();
|
||||||
|
|
1192
src/fccache.c
1192
src/fccache.c
File diff suppressed because it is too large
Load Diff
146
src/fcdir.c
146
src/fcdir.c
|
@ -45,16 +45,10 @@ FcFileScanConfig (FcFontSet *set,
|
||||||
FcConfig *config)
|
FcConfig *config)
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
#if 0
|
|
||||||
FcChar8 *name;
|
|
||||||
FcGlobalCacheFile *cache_file;
|
|
||||||
FcGlobalCacheDir *cache_dir;
|
|
||||||
#endif
|
|
||||||
FcPattern *font;
|
FcPattern *font;
|
||||||
FcBool ret = FcTrue;
|
FcBool ret = FcTrue;
|
||||||
FcBool isDir;
|
FcBool isDir;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
FcBool need_scan;
|
|
||||||
|
|
||||||
if (config && !FcConfigAcceptFilename (config, file))
|
if (config && !FcConfigAcceptFilename (config, file))
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
|
@ -64,85 +58,23 @@ FcFileScanConfig (FcFontSet *set,
|
||||||
id = 0;
|
id = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
need_scan = FcTrue;
|
|
||||||
font = 0;
|
font = 0;
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Check the cache
|
|
||||||
*/
|
|
||||||
if (cache)
|
|
||||||
{
|
|
||||||
if ((cache_file = FcGlobalCacheFileGet (cache, file, id, &count)))
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Found a cache entry for the file
|
|
||||||
*/
|
|
||||||
if (FcGlobalCacheCheckTime (file, &cache_file->info))
|
|
||||||
{
|
|
||||||
name = cache_file->name;
|
|
||||||
need_scan = FcFalse;
|
|
||||||
FcGlobalCacheReferenced (cache, &cache_file->info);
|
|
||||||
/* "." means the file doesn't contain a font */
|
|
||||||
if (FcStrCmp (name, FC_FONT_FILE_INVALID) != 0)
|
|
||||||
{
|
|
||||||
font = FcNameParse (name);
|
|
||||||
if (font)
|
|
||||||
if (!FcPatternAddString (font, FC_FILE, file))
|
|
||||||
ret = FcFalse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((cache_dir = FcGlobalCacheDirGet (cache, file,
|
|
||||||
strlen ((const char *) file),
|
|
||||||
FcFalse)))
|
|
||||||
{
|
|
||||||
if (FcGlobalCacheCheckTime (cache_dir->info.file,
|
|
||||||
&cache_dir->info))
|
|
||||||
{
|
|
||||||
font = 0;
|
|
||||||
need_scan = FcFalse;
|
|
||||||
FcGlobalCacheReferenced (cache, &cache_dir->info);
|
|
||||||
if (!FcStrSetAdd (dirs, file))
|
|
||||||
ret = FcFalse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/*
|
/*
|
||||||
* Nothing in the cache, scan the file
|
* Nothing in the cache, scan the file
|
||||||
*/
|
*/
|
||||||
if (need_scan)
|
if (FcDebug () & FC_DBG_SCAN)
|
||||||
{
|
{
|
||||||
if (FcDebug () & FC_DBG_SCAN)
|
printf ("\tScanning file %s...", file);
|
||||||
{
|
fflush (stdout);
|
||||||
printf ("\tScanning file %s...", file);
|
}
|
||||||
fflush (stdout);
|
font = FcFreeTypeQuery (file, id, blanks, &count);
|
||||||
}
|
if (FcDebug () & FC_DBG_SCAN)
|
||||||
font = FcFreeTypeQuery (file, id, blanks, &count);
|
printf ("done\n");
|
||||||
if (FcDebug () & FC_DBG_SCAN)
|
isDir = FcFalse;
|
||||||
printf ("done\n");
|
if (!font && FcFileIsDir (file))
|
||||||
isDir = FcFalse;
|
{
|
||||||
if (!font && FcFileIsDir (file))
|
isDir = FcTrue;
|
||||||
{
|
ret = FcStrSetAdd (dirs, file);
|
||||||
isDir = FcTrue;
|
|
||||||
ret = FcStrSetAdd (dirs, file);
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Update the cache
|
|
||||||
*/
|
|
||||||
if (cache && font)
|
|
||||||
{
|
|
||||||
FcChar8 *unparse;
|
|
||||||
|
|
||||||
unparse = FcNameUnparse (font);
|
|
||||||
if (unparse)
|
|
||||||
{
|
|
||||||
(void) FcGlobalCacheUpdate (cache, file, id, unparse);
|
|
||||||
FcStrFree (unparse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Add the font
|
* Add the font
|
||||||
|
@ -193,29 +125,19 @@ FcDirScanConfig (FcFontSet *set,
|
||||||
FcChar8 *file;
|
FcChar8 *file;
|
||||||
FcChar8 *base;
|
FcChar8 *base;
|
||||||
FcBool ret = FcTrue;
|
FcBool ret = FcTrue;
|
||||||
|
FcFontSet *tmpSet;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (config && !FcConfigAcceptFilename (config, dir))
|
if (config && !FcConfigAcceptFilename (config, dir))
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
|
|
||||||
if (!force)
|
if (!force)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Check fonts.cache-<version> file
|
|
||||||
*/
|
|
||||||
if (FcDirCacheReadDir (set, dirs, dir, config))
|
|
||||||
{
|
|
||||||
if (cache)
|
|
||||||
FcGlobalCacheReferenceSubdir (cache, dir);
|
|
||||||
return FcTrue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check ~/.fonts.cache-<version> file
|
* Check ~/.fonts.cache-<version> file
|
||||||
*/
|
*/
|
||||||
if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir, config))
|
if (cache && FcGlobalCacheReadDir (set, dirs, cache, dir, config))
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* freed below */
|
/* freed below */
|
||||||
|
@ -231,7 +153,6 @@ FcDirScanConfig (FcFontSet *set,
|
||||||
printf ("\tScanning dir %s\n", dir);
|
printf ("\tScanning dir %s\n", dir);
|
||||||
|
|
||||||
d = opendir ((char *) dir);
|
d = opendir ((char *) dir);
|
||||||
|
|
||||||
if (!d)
|
if (!d)
|
||||||
{
|
{
|
||||||
free (file);
|
free (file);
|
||||||
|
@ -240,12 +161,20 @@ FcDirScanConfig (FcFontSet *set,
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmpSet = FcFontSetCreate();
|
||||||
|
if (!tmpSet)
|
||||||
|
{
|
||||||
|
free (file);
|
||||||
|
return FcFalse;
|
||||||
|
}
|
||||||
|
|
||||||
while (ret && (e = readdir (d)))
|
while (ret && (e = readdir (d)))
|
||||||
{
|
{
|
||||||
if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
|
if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
|
||||||
{
|
{
|
||||||
strcpy ((char *) base, (char *) e->d_name);
|
strcpy ((char *) base, (char *) e->d_name);
|
||||||
ret = FcFileScanConfig (set, dirs, cache, blanks, file, force, config);
|
ret = FcFileScanConfig (tmpSet, dirs, cache, blanks, file, force, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free (file);
|
free (file);
|
||||||
|
@ -254,10 +183,19 @@ FcDirScanConfig (FcFontSet *set,
|
||||||
* Now that the directory has been scanned,
|
* Now that the directory has been scanned,
|
||||||
* add the cache entry
|
* add the cache entry
|
||||||
*/
|
*/
|
||||||
#if 0
|
|
||||||
if (ret && cache)
|
if (ret && cache)
|
||||||
FcGlobalCacheUpdate (cache, dir, 0, 0);
|
FcGlobalCacheUpdate (cache, dir, tmpSet);
|
||||||
#endif
|
|
||||||
|
for (i = 0; i < tmpSet->nfont; i++)
|
||||||
|
FcFontSetAdd (set, tmpSet->fonts[i]);
|
||||||
|
|
||||||
|
if (tmpSet->fonts)
|
||||||
|
{
|
||||||
|
FcMemFree (FC_MEM_FONTPTR, tmpSet->sfont * sizeof (FcPattern *));
|
||||||
|
free (tmpSet->fonts);
|
||||||
|
}
|
||||||
|
FcMemFree (FC_MEM_FONTSET, sizeof (FcFontSet));
|
||||||
|
free (tmpSet);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -276,15 +214,5 @@ FcDirScan (FcFontSet *set,
|
||||||
FcBool
|
FcBool
|
||||||
FcDirSave (FcFontSet *set, const FcChar8 *dir)
|
FcDirSave (FcFontSet *set, const FcChar8 *dir)
|
||||||
{
|
{
|
||||||
static int rand_state = 0;
|
return FcDirCacheWrite (set, dir);
|
||||||
int bank;
|
|
||||||
|
|
||||||
if (!rand_state)
|
|
||||||
rand_state = time(0L);
|
|
||||||
bank = rand_r(&rand_state);
|
|
||||||
|
|
||||||
while (FcCacheHaveBank(bank))
|
|
||||||
bank = rand_r(&rand_state);
|
|
||||||
|
|
||||||
return FcDirCacheWrite (bank, set, dir);
|
|
||||||
}
|
}
|
||||||
|
|
97
src/fcint.h
97
src/fcint.h
|
@ -41,12 +41,6 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* unused */
|
|
||||||
typedef struct _FcSymbolic {
|
|
||||||
const char *name;
|
|
||||||
int value;
|
|
||||||
} FcSymbolic;
|
|
||||||
|
|
||||||
#ifndef FC_CONFIG_PATH
|
#ifndef FC_CONFIG_PATH
|
||||||
#define FC_CONFIG_PATH "fonts.conf"
|
#define FC_CONFIG_PATH "fonts.conf"
|
||||||
#endif
|
#endif
|
||||||
|
@ -323,45 +317,22 @@ typedef struct _FcCaseFold {
|
||||||
* cache which is then rewritten to the users home directory
|
* cache which is then rewritten to the users home directory
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FC_CACHE_MAGIC 0xFC20FC20
|
#define FC_CACHE_MAGIC 0xFC02FC02
|
||||||
#define FC_GLOBAL_CACHE_DIR_HASH_SIZE 37
|
|
||||||
#define FC_GLOBAL_CACHE_FILE_HASH_SIZE 67
|
|
||||||
|
|
||||||
typedef struct _FcGlobalCacheInfo {
|
|
||||||
unsigned int hash;
|
|
||||||
FcChar8 *file;
|
|
||||||
time_t time;
|
|
||||||
FcBool referenced;
|
|
||||||
} FcGlobalCacheInfo;
|
|
||||||
|
|
||||||
typedef struct _FcGlobalCacheFile {
|
|
||||||
struct _FcGlobalCacheFile *next;
|
|
||||||
FcGlobalCacheInfo info;
|
|
||||||
int id;
|
|
||||||
FcChar8 *name;
|
|
||||||
} FcGlobalCacheFile;
|
|
||||||
|
|
||||||
typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
|
typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
|
||||||
|
|
||||||
typedef struct _FcGlobalCacheSubdir {
|
|
||||||
struct _FcGlobalCacheSubdir *next;
|
|
||||||
FcGlobalCacheDir *ent;
|
|
||||||
} FcGlobalCacheSubdir;
|
|
||||||
|
|
||||||
struct _FcGlobalCacheDir {
|
struct _FcGlobalCacheDir {
|
||||||
struct _FcGlobalCacheDir *next;
|
struct _FcGlobalCacheDir *next;
|
||||||
FcGlobalCacheInfo info;
|
FcChar8 *name;
|
||||||
int len;
|
FcCache metadata;
|
||||||
FcGlobalCacheFile *ents[FC_GLOBAL_CACHE_FILE_HASH_SIZE];
|
off_t offset;
|
||||||
FcGlobalCacheSubdir *subdirs;
|
void *ent;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _FcGlobalCache {
|
typedef struct _FcGlobalCache {
|
||||||
FcGlobalCacheDir *ents[FC_GLOBAL_CACHE_DIR_HASH_SIZE];
|
FcGlobalCacheDir *dirs;
|
||||||
FcBool updated;
|
FcBool updated;
|
||||||
FcBool broken;
|
int fd;
|
||||||
int entries;
|
|
||||||
int referenced;
|
|
||||||
} FcGlobalCache;
|
} FcGlobalCache;
|
||||||
|
|
||||||
struct _FcAtomic {
|
struct _FcAtomic {
|
||||||
|
@ -448,35 +419,11 @@ void
|
||||||
FcGlobalCacheDestroy (FcGlobalCache *cache);
|
FcGlobalCacheDestroy (FcGlobalCache *cache);
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
FcGlobalCacheCheckTime (const FcChar8*file, FcGlobalCacheInfo *info);
|
FcGlobalCacheReadDir (FcFontSet *set,
|
||||||
|
FcStrSet *dirs,
|
||||||
void
|
FcGlobalCache *cache,
|
||||||
FcGlobalCacheReferenced (FcGlobalCache *cache,
|
const FcChar8 *dir,
|
||||||
FcGlobalCacheInfo *info);
|
FcConfig *config);
|
||||||
|
|
||||||
void
|
|
||||||
FcGlobalCacheReferenceSubdir (FcGlobalCache *cache,
|
|
||||||
const FcChar8 *dir);
|
|
||||||
|
|
||||||
FcGlobalCacheDir *
|
|
||||||
FcGlobalCacheDirGet (FcGlobalCache *cache,
|
|
||||||
const FcChar8 *dir,
|
|
||||||
int len,
|
|
||||||
FcBool create_missing);
|
|
||||||
|
|
||||||
FcBool
|
|
||||||
FcGlobalCacheScanDir (FcFontSet *set,
|
|
||||||
FcStrSet *dirs,
|
|
||||||
FcGlobalCache *cache,
|
|
||||||
const FcChar8 *dir,
|
|
||||||
FcConfig *config);
|
|
||||||
|
|
||||||
FcGlobalCacheFile *
|
|
||||||
FcGlobalCacheFileGet (FcGlobalCache *cache,
|
|
||||||
const FcChar8 *file,
|
|
||||||
int id,
|
|
||||||
int *count);
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FcGlobalCacheLoad (FcGlobalCache *cache,
|
FcGlobalCacheLoad (FcGlobalCache *cache,
|
||||||
|
@ -485,33 +432,17 @@ FcGlobalCacheLoad (FcGlobalCache *cache,
|
||||||
FcBool
|
FcBool
|
||||||
FcGlobalCacheUpdate (FcGlobalCache *cache,
|
FcGlobalCacheUpdate (FcGlobalCache *cache,
|
||||||
const FcChar8 *file,
|
const FcChar8 *file,
|
||||||
int id,
|
FcFontSet *set);
|
||||||
const FcChar8 *name);
|
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
FcGlobalCacheSave (FcGlobalCache *cache,
|
FcGlobalCacheSave (FcGlobalCache *cache,
|
||||||
const FcChar8 *cache_file);
|
const FcChar8 *cache_file);
|
||||||
|
|
||||||
void
|
|
||||||
FcCacheForce(FcBool force);
|
|
||||||
|
|
||||||
FcBool
|
|
||||||
FcCacheSerialize (int bank, FcConfig * config);
|
|
||||||
|
|
||||||
FcFontSet *
|
FcFontSet *
|
||||||
FcCacheRead (FcConfig *config, FcGlobalCache * cache);
|
FcCacheRead (FcConfig *config, FcGlobalCache * cache);
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
FcDirCacheRead (FcFontSet * set, const FcChar8 *dir);
|
FcDirCacheWrite (FcFontSet *set, const FcChar8 *dir);
|
||||||
|
|
||||||
FcBool
|
|
||||||
FcDirCacheWrite (int bank, FcFontSet *set, const FcChar8 *dir);
|
|
||||||
|
|
||||||
int
|
|
||||||
FcCacheBankCount (void);
|
|
||||||
|
|
||||||
FcBool
|
|
||||||
FcCacheHaveBank (int bank);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
FcCacheBankToIndex (int bank);
|
FcCacheBankToIndex (int bank);
|
||||||
|
|
Loading…
Reference in New Issue