const FcChar8 *dir,
int dir_len,
const FcChar8 *file,
- const FcChar8 *name)
+ const FcChar8 *name,
+ FcConfig *config)
{
FcChar8 path_buf[8192], *path;
int len;
path[dir_len++] = '/';
#endif
strcpy ((char *) path + dir_len, (const char *) file);
- if (!FcStrCmp (name, FC_FONT_FILE_DIR))
+ if (config && !FcConfigAcceptFilename (config, path))
+ ret = FcTrue;
+ else if (!FcStrCmp (name, FC_FONT_FILE_DIR))
{
if (FcDebug () & FC_DBG_CACHEV)
printf (" dir cache dir \"%s\"\n", path);
FcGlobalCacheScanDir (FcFontSet *set,
FcStrSet *dirs,
FcGlobalCache *cache,
- const FcChar8 *dir)
+ const FcChar8 *dir,
+ FcConfig *config)
{
FcGlobalCacheDir *d = FcGlobalCacheDirGet (cache, dir,
strlen ((const char *) dir),
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))
+ f->info.file, f->name, config))
{
cache->broken = FcTrue;
return FcFalse;
any_in_cache = FcTrue;
if (!FcCacheFontSetAdd (set, dirs, dir, dir_len,
- info.base, FC_FONT_FILE_DIR))
+ info.base, FC_FONT_FILE_DIR, config))
{
cache->broken = FcTrue;
return FcFalse;
}
FcBool
-FcDirCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
+FcDirCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir, FcConfig *config)
{
FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
FILE *f;
(name = FcCacheReadString (f, name_buf, sizeof (name_buf))))
{
if (!FcCacheFontSetAdd (set, dirs, cache_file, dir_len,
- file, name))
+ file, name, config))
goto bail3;
if (file != file_buf)
free (file);
if (!config->fontDirs)
goto bail3;
+ config->acceptGlobs = FcStrSetCreate ();
+ if (!config->acceptGlobs)
+ goto bail4;
+
+ config->rejectGlobs = FcStrSetCreate ();
+ if (!config->rejectGlobs)
+ goto bail5;
+
config->cache = 0;
if (FcConfigHome())
if (!FcConfigSetCache (config, (FcChar8 *) ("~/" FC_USER_CACHE_FILE)))
- goto bail4;
+ goto bail6;
config->blanks = 0;
return config;
+bail6:
+ FcStrSetDestroy (config->rejectGlobs);
+bail5:
+ FcStrSetDestroy (config->acceptGlobs);
bail4:
FcStrSetDestroy (config->fontDirs);
bail3:
FcStrSetDestroy (config->configDirs);
FcStrSetDestroy (config->fontDirs);
FcStrSetDestroy (config->configFiles);
+ FcStrSetDestroy (config->acceptGlobs);
+ FcStrSetDestroy (config->rejectGlobs);
FcStrFree (config->cache);
{
if (FcDebug () & FC_DBG_FONTSET)
printf ("scan dir %s\n", dir);
- FcDirScan (fonts, config->fontDirs, cache, config->blanks, dir, FcFalse);
+ FcDirScanConfig (fonts, config->fontDirs, cache,
+ config->blanks, dir, FcFalse, config);
}
FcStrListDone (list);
FcConfigSetFonts (config, set, FcSetApplication);
}
- if (!FcFileScan (set, subdirs, 0, config->blanks, file, FcFalse))
+ if (!FcFileScanConfig (set, subdirs, 0, config->blanks, file, FcFalse, config))
{
FcStrSetDestroy (subdirs);
return FcFalse;
FcConfigSetFonts (config, set, FcSetApplication);
}
- if (!FcDirScan (set, subdirs, 0, config->blanks, dir, FcFalse))
+ if (!FcDirScanConfig (set, subdirs, 0, config->blanks, dir, FcFalse, config))
{
FcStrSetDestroy (subdirs);
return FcFalse;
{
FcConfigSetFonts (config, 0, FcSetApplication);
}
+
+/*
+ * Manage filename-based font source selectors
+ */
+
+FcBool
+FcConfigGlobAdd (FcConfig *config,
+ const FcChar8 *glob,
+ FcBool accept)
+{
+ FcStrSet *set = accept ? config->acceptGlobs : config->rejectGlobs;
+
+ return FcStrSetAdd (set, glob);
+}
+
+static FcBool
+FcConfigGlobMatch (const FcChar8 *glob,
+ const FcChar8 *string)
+{
+ FcChar8 c;
+
+ while ((c = *glob++))
+ {
+ switch (c) {
+ case '*':
+ /* short circuit common case */
+ if (!*glob)
+ return FcTrue;
+ /* short circuit another common case */
+ if (strchr ((char *) glob, '*') == 0)
+ string += strlen ((char *) string) - strlen ((char *) glob);
+ while (*string)
+ {
+ if (FcConfigGlobMatch (glob, string))
+ return FcTrue;
+ string++;
+ }
+ return FcFalse;
+ case '?':
+ if (*string++ == '\0')
+ return FcFalse;
+ break;
+ default:
+ if (*string++ != c)
+ return FcFalse;
+ break;
+ }
+ }
+ return *string == '\0';
+}
+
+static FcBool
+FcConfigGlobsMatch (const FcStrSet *globs,
+ const FcChar8 *string)
+{
+ int i;
+
+ for (i = 0; i < globs->num; i++)
+ if (FcConfigGlobMatch (globs->strs[i], string))
+ return FcTrue;
+ return FcFalse;
+}
+
+FcBool
+FcConfigAcceptFilename (FcConfig *config,
+ const FcChar8 *filename)
+{
+ if (FcConfigGlobsMatch (config->acceptGlobs, filename))
+ return FcTrue;
+ if (FcConfigGlobsMatch (config->rejectGlobs, filename))
+ return FcFalse;
+ return FcTrue;
+}
}
FcBool
-FcFileScan (FcFontSet *set,
- FcStrSet *dirs,
- FcGlobalCache *cache,
- FcBlanks *blanks,
- const FcChar8 *file,
- FcBool force)
+FcFileScanConfig (FcFontSet *set,
+ FcStrSet *dirs,
+ FcGlobalCache *cache,
+ FcBlanks *blanks,
+ const FcChar8 *file,
+ FcBool force,
+ FcConfig *config)
{
int id;
FcChar8 *name;
FcGlobalCacheDir *cache_dir;
FcBool need_scan;
+ if (config && !FcConfigAcceptFilename (config, file))
+ return FcTrue;
+
if (force)
cache = 0;
id = 0;
return ret;
}
+FcBool
+FcFileScan (FcFontSet *set,
+ FcStrSet *dirs,
+ FcGlobalCache *cache,
+ FcBlanks *blanks,
+ const FcChar8 *file,
+ FcBool force)
+{
+ return FcFileScanConfig (set, dirs, cache, blanks, file, force, 0);
+}
+
#define FC_MAX_FILE_LEN 4096
/*
*/
FcBool
-FcDirScan (FcFontSet *set,
- FcStrSet *dirs,
- FcGlobalCache *cache,
- FcBlanks *blanks,
- const FcChar8 *dir,
- FcBool force)
+FcDirScanConfig (FcFontSet *set,
+ FcStrSet *dirs,
+ FcGlobalCache *cache,
+ FcBlanks *blanks,
+ const FcChar8 *dir,
+ FcBool force,
+ FcConfig *config)
{
DIR *d;
struct dirent *e;
FcChar8 *base;
FcBool ret = FcTrue;
+ if (config && !FcConfigAcceptFilename (config, dir))
+ return FcTrue;
+
if (!force)
{
/*
* Check fonts.cache-<version> file
*/
- if (FcDirCacheReadDir (set, dirs, dir))
+ if (FcDirCacheReadDir (set, dirs, dir, config))
{
if (cache)
FcGlobalCacheReferenceSubdir (cache, dir);
/*
* Check ~/.fonts.cache-<version> file
*/
- if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir))
+ if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir, config))
return FcTrue;
}
if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
{
strcpy ((char *) base, (char *) e->d_name);
- ret = FcFileScan (set, dirs, cache, blanks, file, force);
+ ret = FcFileScanConfig (set, dirs, cache, blanks, file, force, config);
}
}
free (file);
return ret;
}
+FcBool
+FcDirScan (FcFontSet *set,
+ FcStrSet *dirs,
+ FcGlobalCache *cache,
+ FcBlanks *blanks,
+ const FcChar8 *dir,
+ FcBool force)
+{
+ return FcDirScanConfig (set, dirs, cache, blanks, dir, force, 0);
+}
+
FcBool
FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
{
if (!FT_Has_PS_Glyph_Names (face))
return FcFalse;
for (map = 0; map < face->num_charmaps; map++)
- if (face->charmaps[map]->encoding == FT_ENCODING_ADOBE_CUSTOM)
+ if (face->charmaps[map]->encoding == ft_encoding_adobe_custom)
return FcTrue;
return FcFalse;
}
FcSubst *substPattern; /* substitutions for patterns */
FcSubst *substFont; /* substitutions for fonts */
int maxObjects; /* maximum number of tests in all substs */
+ /*
+ * List of patterns used to control font file selection
+ */
+ FcStrSet *acceptGlobs;
+ FcStrSet *rejectGlobs;
/*
* The set of fonts loaded from the listed directories; the
* order within the set does not determine the font selection,
FcGlobalCacheScanDir (FcFontSet *set,
FcStrSet *dirs,
FcGlobalCache *cache,
- const FcChar8 *dir);
+ const FcChar8 *dir,
+ FcConfig *config);
FcGlobalCacheFile *
FcGlobalCacheFileGet (FcGlobalCache *cache,
const FcChar8 *cache_file);
FcBool
-FcDirCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
+FcDirCacheReadDir (FcFontSet *set,
+ FcStrSet *dirs,
+ const FcChar8 *dir,
+ FcConfig *config);
FcBool
FcDirCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
FcOp op,
const FcValue v);
+FcBool
+FcConfigGlobAdd (FcConfig *config,
+ const FcChar8 *glob,
+ FcBool accept);
+
+FcBool
+FcConfigAcceptFilename (FcConfig *config,
+ const FcChar8 *filename);
+
/* fccharset.c */
FcCharSet *
FcCharSetFreeze (FcCharSet *cs);
/* fcdir.c */
+FcBool
+FcFileScanConfig (FcFontSet *set,
+ FcStrSet *dirs,
+ FcFileCache *cache,
+ FcBlanks *blanks,
+ const FcChar8 *file,
+ FcBool force,
+ FcConfig *config);
+
+FcBool
+FcDirScanConfig (FcFontSet *set,
+ FcStrSet *dirs,
+ FcFileCache *cache,
+ FcBlanks *blanks,
+ const FcChar8 *dir,
+ FcBool force,
+ FcConfig *config);
+
/* fcfont.c */
int
FcFontDebug (void);
FcElementDefault,
FcElementFamily,
+ FcElementSelectfont,
+ FcElementAcceptfont,
+ FcElementRejectfont,
+ FcElementGlob,
+
FcElementTest,
FcElementEdit,
FcElementInt,
{ "default", FcElementDefault },
{ "family", FcElementFamily },
+ { "selectfont", FcElementSelectfont },
+ { "acceptfont", FcElementAcceptfont },
+ { "rejectfont", FcElementRejectfont },
+ { "glob", FcElementGlob },
+
{ "test", FcElementTest },
{ "edit", FcElementEdit },
{ "int", FcElementInt },
FcVStackFamily,
FcVStackField,
FcVStackConstant,
+ FcVStackGlob,
FcVStackPrefer,
FcVStackAccept,
case FcVStackFamily:
case FcVStackField:
case FcVStackConstant:
+ case FcVStackGlob:
FcStrFree (vstack->u.string);
break;
case FcVStackInteger:
FcConfigMessage (parse, FcSevereError, "out of memory");
}
+static void
+FcParseAcceptRejectFont (FcConfigParse *parse, FcElement element)
+{
+ FcVStack *vstack;
+
+ while ((vstack = FcVStackPop (parse)))
+ {
+ switch (vstack->tag) {
+ case FcVStackGlob:
+ if (!FcConfigGlobAdd (parse->config,
+ vstack->u.string,
+ element == FcElementAcceptfont))
+ {
+ FcConfigMessage (parse, FcSevereError, "out of memory");
+ }
+ break;
+ default:
+ FcConfigMessage (parse, FcSevereWarning, "bad font selector");
+ break;
+ }
+ FcVStackDestroy (vstack);
+ }
+}
+
static void
FcEndElement(void *userData, const XML_Char *name)
{
case FcElementCharset:
/* FcParseCharset (parse); */
break;
-
+ case FcElementSelectfont:
+ break;
+ case FcElementAcceptfont:
+ case FcElementRejectfont:
+ FcParseAcceptRejectFont (parse, parse->pstack->element);
+ break;
+ case FcElementGlob:
+ FcParseString (parse, FcVStackGlob);
+ break;
case FcElementName:
FcParseString (parse, FcVStackField);
break;