Commit eb0cf671 authored by Patrick Lam's avatar Patrick Lam
Browse files

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.
parent 2dbe7597
......@@ -191,7 +191,6 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
ret++;
continue;
}
#if 0 // put this back later after fixing DirCacheValid
if (!force && FcDirCacheValid (dir))
{
if (verbose)
......@@ -199,7 +198,6 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
set->nfont, nsubdirs(subdirs));
}
else
#endif
{
if (verbose)
printf ("caching, %d fonts, %d dirs\n",
......@@ -271,7 +269,6 @@ main (int argc, char **argv)
if (systemOnly)
FcConfigEnableHome (FcFalse);
FcCacheForce (FcTrue);
/* need to use FcInitLoadConfig when we use dirs */
FcInit ();
config = FcConfigGetCurrent ();
......
This diff is collapsed.
......@@ -45,16 +45,10 @@ FcFileScanConfig (FcFontSet *set,
FcConfig *config)
{
int id;
#if 0
FcChar8 *name;
FcGlobalCacheFile *cache_file;
FcGlobalCacheDir *cache_dir;
#endif
FcPattern *font;
FcBool ret = FcTrue;
FcBool isDir;
int count = 0;
FcBool need_scan;
if (config && !FcConfigAcceptFilename (config, file))
return FcTrue;
......@@ -64,85 +58,23 @@ FcFileScanConfig (FcFontSet *set,
id = 0;
do
{
need_scan = FcTrue;
font = 0;
#if 0
/*
* Check the cache
* Nothing in the cache, scan the file
*/
if (cache)
if (FcDebug () & FC_DBG_SCAN)
{
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;
}
}
printf ("\tScanning file %s...", file);
fflush (stdout);
}
#endif
/*
* Nothing in the cache, scan the file
*/
if (need_scan)
font = FcFreeTypeQuery (file, id, blanks, &count);
if (FcDebug () & FC_DBG_SCAN)
printf ("done\n");
isDir = FcFalse;
if (!font && FcFileIsDir (file))
{
if (FcDebug () & FC_DBG_SCAN)
{
printf ("\tScanning file %s...", file);
fflush (stdout);
}
font = FcFreeTypeQuery (file, id, blanks, &count);
if (FcDebug () & FC_DBG_SCAN)
printf ("done\n");
isDir = FcFalse;
if (!font && FcFileIsDir (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
isDir = FcTrue;
ret = FcStrSetAdd (dirs, file);
}
/*
* Add the font
......@@ -193,29 +125,19 @@ FcDirScanConfig (FcFontSet *set,
FcChar8 *file;
FcChar8 *base;
FcBool ret = FcTrue;
FcFontSet *tmpSet;
int i;
if (config && !FcConfigAcceptFilename (config, dir))
return FcTrue;
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
*/
if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir, config))
if (cache && FcGlobalCacheReadDir (set, dirs, cache, dir, config))
return FcTrue;
#endif
}
/* freed below */
......@@ -231,7 +153,6 @@ FcDirScanConfig (FcFontSet *set,
printf ("\tScanning dir %s\n", dir);
d = opendir ((char *) dir);
if (!d)
{
free (file);
......@@ -240,12 +161,20 @@ FcDirScanConfig (FcFontSet *set,
return FcTrue;
return FcFalse;
}
tmpSet = FcFontSetCreate();
if (!tmpSet)
{
free (file);
return FcFalse;
}
while (ret && (e = readdir (d)))
{
if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
{
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);
......@@ -254,10 +183,19 @@ FcDirScanConfig (FcFontSet *set,
* Now that the directory has been scanned,
* add the cache entry
*/
#if 0
if (ret && cache)
FcGlobalCacheUpdate (cache, dir, 0, 0);
#endif
FcGlobalCacheUpdate (cache, dir, tmpSet);
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;
}
......@@ -276,15 +214,5 @@ FcDirScan (FcFontSet *set,
FcBool
FcDirSave (FcFontSet *set, const FcChar8 *dir)
{
static int rand_state = 0;
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);
return FcDirCacheWrite (set, dir);
}
......@@ -41,12 +41,6 @@
#include <config.h>
#endif
/* unused */
typedef struct _FcSymbolic {
const char *name;
int value;
} FcSymbolic;
#ifndef FC_CONFIG_PATH
#define FC_CONFIG_PATH "fonts.conf"
#endif
......@@ -323,45 +317,22 @@ typedef struct _FcCaseFold {
* cache which is then rewritten to the users home directory
*/
#define FC_CACHE_MAGIC 0xFC20FC20
#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;
#define FC_CACHE_MAGIC 0xFC02FC02
typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
typedef struct _FcGlobalCacheSubdir {
struct _FcGlobalCacheSubdir *next;
FcGlobalCacheDir *ent;
} FcGlobalCacheSubdir;
struct _FcGlobalCacheDir {
struct _FcGlobalCacheDir *next;
FcGlobalCacheInfo info;
int len;
FcGlobalCacheFile *ents[FC_GLOBAL_CACHE_FILE_HASH_SIZE];
FcGlobalCacheSubdir *subdirs;
FcChar8 *name;
FcCache metadata;
off_t offset;
void *ent;
};
typedef struct _FcGlobalCache {
FcGlobalCacheDir *ents[FC_GLOBAL_CACHE_DIR_HASH_SIZE];
FcGlobalCacheDir *dirs;
FcBool updated;
FcBool broken;
int entries;
int referenced;
int fd;
} FcGlobalCache;
struct _FcAtomic {
......@@ -448,35 +419,11 @@ void
FcGlobalCacheDestroy (FcGlobalCache *cache);
FcBool
FcGlobalCacheCheckTime (const FcChar8*file, FcGlobalCacheInfo *info);
void
FcGlobalCacheReferenced (FcGlobalCache *cache,
FcGlobalCacheInfo *info);
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);
FcGlobalCacheReadDir (FcFontSet *set,
FcStrSet *dirs,
FcGlobalCache *cache,
const FcChar8 *dir,
FcConfig *config);
void
FcGlobalCacheLoad (FcGlobalCache *cache,
......@@ -485,33 +432,17 @@ FcGlobalCacheLoad (FcGlobalCache *cache,
FcBool
FcGlobalCacheUpdate (FcGlobalCache *cache,
const FcChar8 *file,
int id,
const FcChar8 *name);
FcFontSet *set);
FcBool
FcGlobalCacheSave (FcGlobalCache *cache,
const FcChar8 *cache_file);
void
FcCacheForce(FcBool force);
FcBool
FcCacheSerialize (int bank, FcConfig * config);
FcFontSet *
FcCacheRead (FcConfig *config, FcGlobalCache * cache);
FcBool
FcDirCacheRead (FcFontSet * set, const FcChar8 *dir);
FcBool
FcDirCacheWrite (int bank, FcFontSet *set, const FcChar8 *dir);
int
FcCacheBankCount (void);
FcBool
FcCacheHaveBank (int bank);
FcDirCacheWrite (FcFontSet *set, const FcChar8 *dir);
int
FcCacheBankToIndex (int bank);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment