*/
#include "fcint.h"
-#include "fcftint.h"
-#include <ft2build.h>
-#include FT_FREETYPE_H
#include <dirent.h>
FcBool
static FcBool
FcFileScanFontConfig (FcFontSet *set,
- FcBlanks *blanks,
const FcChar8 *file,
FcConfig *config)
{
- FT_Library ftLibrary;
- FT_Face face;
- FcPattern *font;
+ int i;
FcBool ret = FcTrue;
- int num_faces = 0;
- int num_instances = 0;
- int face_num = 0;
- int instance_num = 0;
- int id;
+ int old_nfont = set->nfont;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
- if (FT_Init_FreeType (&ftLibrary))
+ if (FcDebug () & FC_DBG_SCAN)
+ {
+ printf ("\tScanning file %s...", file);
+ fflush (stdout);
+ }
+
+ if (!FcFreeTypeQueryAll (file, -1, NULL, NULL, set))
return FcFalse;
- do
- {
- font = 0;
- /*
- * Nothing in the cache, scan the file
- */
- if (FcDebug () & FC_DBG_SCAN)
- {
- printf ("\tScanning file %s...", file);
- fflush (stdout);
- }
+ if (FcDebug () & FC_DBG_SCAN)
+ printf ("done\n");
- id = ((instance_num << 16) + face_num);
- if (FT_New_Face (ftLibrary, (char *) file, id, &face))
- return FcFalse;
- num_faces = face->num_faces;
- num_instances = face->style_flags >> 16;
- font = FcFreeTypeQueryFace (face, file, id, blanks);
- FT_Done_Face (face);
+ for (i = old_nfont; i < set->nfont; i++)
+ {
+ FcPattern *font = set->fonts[i];
- if (FcDebug () & FC_DBG_SCAN)
- printf ("done\n");
/*
* Get rid of sysroot here so that targeting scan rule may contains FC_FILE pattern
* and they should usually expect without sysroot.
*/
- if (font && sysroot)
+ if (sysroot)
{
size_t len = strlen ((const char *)sysroot);
FcChar8 *f = NULL;
/*
* Edit pattern with user-defined rules
*/
- if (font && config && !FcConfigSubstitute (config, font, FcMatchScan))
- {
- FcPatternDestroy (font);
- font = NULL;
+ if (config && !FcConfigSubstitute (config, font, FcMatchScan))
ret = FcFalse;
- }
- /*
- * Add the font
- */
- if (font)
+ if (FcDebug() & FC_DBG_SCANV)
{
- if (FcDebug() & FC_DBG_SCANV)
- {
- printf ("Final font pattern:\n");
- FcPatternPrint (font);
- }
- if (!FcFontSetAdd (set, font))
- {
- FcPatternDestroy (font);
- font = NULL;
- ret = FcFalse;
- }
- }
- else
- ret = FcFalse;
-
- if (instance_num < num_instances)
- instance_num++;
- else
- {
- face_num++;
- instance_num = 0;
+ printf ("Final font pattern:\n");
+ FcPatternPrint (font);
}
- } while (font && ret && face_num < num_faces);
-
- FT_Done_FreeType (ftLibrary);
+ }
return ret;
}
FcBool
FcFileScanConfig (FcFontSet *set,
FcStrSet *dirs,
- FcBlanks *blanks,
const FcChar8 *file,
FcConfig *config)
{
else
{
if (set)
- return FcFileScanFontConfig (set, blanks, file, config);
+ return FcFileScanFontConfig (set, file, config);
else
return FcTrue;
}
FcFileScan (FcFontSet *set,
FcStrSet *dirs,
FcFileCache *cache FC_UNUSED,
- FcBlanks *blanks,
+ FcBlanks *blanks FC_UNUSED,
const FcChar8 *file,
FcBool force FC_UNUSED)
{
- return FcFileScanConfig (set, dirs, blanks, file, FcConfigGetCurrent ());
+ return FcFileScanConfig (set, dirs, file, FcConfigGetCurrent ());
}
/*
FcBool
FcDirScanConfig (FcFontSet *set,
FcStrSet *dirs,
- FcBlanks *blanks,
const FcChar8 *dir,
FcBool force, /* XXX unused */
FcConfig *config)
if (!set && !dirs)
return FcTrue;
- if (!blanks)
- blanks = FcConfigGetBlanks (config);
-
/* freed below */
file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1);
if (!file) {
* Scan file files to build font patterns
*/
for (i = 0; i < files->num; i++)
- FcFileScanConfig (set, dirs, blanks, files->strs[i], config);
+ FcFileScanConfig (set, dirs, files->strs[i], config);
bail2:
FcStrSetDestroy (files);
FcBool
FcDirScan (FcFontSet *set,
FcStrSet *dirs,
- FcFileCache *cache, /* XXX unused */
- FcBlanks *blanks,
+ FcFileCache *cache FC_UNUSED,
+ FcBlanks *blanks FC_UNUSED,
const FcChar8 *dir,
- FcBool force /* XXX unused */)
+ FcBool force FC_UNUSED)
{
if (cache || !force)
return FcFalse;
- return FcDirScanConfig (set, dirs, blanks, dir, force, FcConfigGetCurrent ());
+ return FcDirScanConfig (set, dirs, dir, force, FcConfigGetCurrent ());
}
/*
struct stat dir_stat;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
FcChar8 *d;
+#ifndef _WIN32
int fd = -1;
+#endif
if (sysroot)
d = FcStrBuildFilename (sysroot, dir, NULL);
if (!dirs)
goto bail1;
+#ifndef _WIN32
fd = FcDirCacheLock (dir, config);
+#endif
/*
* Scan the dir
*/
- if (!FcDirScanConfig (set, dirs, NULL, d, FcTrue, config))
+ if (!FcDirScanConfig (set, dirs, d, FcTrue, config))
goto bail2;
/*
FcDirCacheWrite (cache, config);
bail2:
+#ifndef _WIN32
FcDirCacheUnlock (fd);
+#endif
FcStrSetDestroy (dirs);
bail1:
FcFontSetDestroy (set);
FcStrSet *dirs;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
FcChar8 *d = NULL;
+#ifndef _WIN32
int fd = -1;
+#endif
cache = FcDirCacheLoad (dir, config, NULL);
if (!cache)
if (!dirs)
goto bail;
+#ifndef _WIN32
fd = FcDirCacheLock (dir, config);
+#endif
/*
* Scan the dir
*/
- if (!FcDirScanConfig (NULL, dirs, NULL, d, FcTrue, config))
+ if (!FcDirScanConfig (NULL, dirs, d, FcTrue, config))
goto bail1;
/*
* Rebuild the cache object
FcDirCacheWrite (new, config);
bail1:
+#ifndef _WIN32
FcDirCacheUnlock (fd);
+#endif
FcStrSetDestroy (dirs);
bail:
if (d)
{
FcCache *cache = NULL;
+ FcDirCacheCreateUUID ((FcChar8 *) dir, FcFalse, config);
/* Try to use existing cache file */
if (!force)
cache = FcDirCacheLoad (dir, config, NULL);
/* Not using existing cache file, construct new cache */
if (!cache)
cache = FcDirCacheScan (dir, config);
+ if (cache)
+ {
+ FcFontSet *fs = FcCacheSet (cache);
+
+ if (cache->dirs_count == 0 && (!fs || fs->nfont == 0))
+ FcDirCacheDeleteUUID (dir, config);
+ }
return cache;
}