Add filename-based accept/reject to ammend available fonts.

change FT_ENCODING_ADOBE_CUSTOM to ft_encoding_adobe_custom for older
    FreeType releases.
This commit is contained in:
Keith Packard 2003-05-07 16:13:24 +00:00
parent f98ecf6339
commit d47c9d6efe
6 changed files with 232 additions and 30 deletions

View File

@ -251,7 +251,8 @@ FcCacheFontSetAdd (FcFontSet *set,
const FcChar8 *dir, const FcChar8 *dir,
int dir_len, int dir_len,
const FcChar8 *file, const FcChar8 *file,
const FcChar8 *name) const FcChar8 *name,
FcConfig *config)
{ {
FcChar8 path_buf[8192], *path; FcChar8 path_buf[8192], *path;
int len; int len;
@ -276,7 +277,9 @@ FcCacheFontSetAdd (FcFontSet *set,
path[dir_len++] = '/'; path[dir_len++] = '/';
#endif #endif
strcpy ((char *) path + dir_len, (const char *) file); 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) if (FcDebug () & FC_DBG_CACHEV)
printf (" dir cache dir \"%s\"\n", path); printf (" dir cache dir \"%s\"\n", path);
@ -539,7 +542,8 @@ FcBool
FcGlobalCacheScanDir (FcFontSet *set, FcGlobalCacheScanDir (FcFontSet *set,
FcStrSet *dirs, FcStrSet *dirs,
FcGlobalCache *cache, FcGlobalCache *cache,
const FcChar8 *dir) const FcChar8 *dir,
FcConfig *config)
{ {
FcGlobalCacheDir *d = FcGlobalCacheDirGet (cache, dir, FcGlobalCacheDir *d = FcGlobalCacheDirGet (cache, dir,
strlen ((const char *) dir), strlen ((const char *) dir),
@ -582,7 +586,7 @@ FcGlobalCacheScanDir (FcFontSet *set,
printf ("FcGlobalCacheScanDir add file %s\n", f->info.file); printf ("FcGlobalCacheScanDir add file %s\n", f->info.file);
any_in_cache = FcTrue; any_in_cache = FcTrue;
if (!FcCacheFontSetAdd (set, dirs, dir, dir_len, if (!FcCacheFontSetAdd (set, dirs, dir, dir_len,
f->info.file, f->name)) f->info.file, f->name, config))
{ {
cache->broken = FcTrue; cache->broken = FcTrue;
return FcFalse; return FcFalse;
@ -598,7 +602,7 @@ FcGlobalCacheScanDir (FcFontSet *set,
any_in_cache = FcTrue; any_in_cache = FcTrue;
if (!FcCacheFontSetAdd (set, dirs, dir, dir_len, if (!FcCacheFontSetAdd (set, dirs, dir, dir_len,
info.base, FC_FONT_FILE_DIR)) info.base, FC_FONT_FILE_DIR, config))
{ {
cache->broken = FcTrue; cache->broken = FcTrue;
return FcFalse; return FcFalse;
@ -971,7 +975,7 @@ FcDirCacheValid (const FcChar8 *dir)
} }
FcBool 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); FcChar8 *cache_file = FcStrPlus (dir, (FcChar8 *) "/" FC_DIR_CACHE_FILE);
FILE *f; FILE *f;
@ -1016,7 +1020,7 @@ FcDirCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
(name = FcCacheReadString (f, name_buf, sizeof (name_buf)))) (name = FcCacheReadString (f, name_buf, sizeof (name_buf))))
{ {
if (!FcCacheFontSetAdd (set, dirs, cache_file, dir_len, if (!FcCacheFontSetAdd (set, dirs, cache_file, dir_len,
file, name)) file, name, config))
goto bail3; goto bail3;
if (file != file_buf) if (file != file_buf)
free (file); free (file);

View File

@ -55,10 +55,18 @@ FcConfigCreate (void)
if (!config->fontDirs) if (!config->fontDirs)
goto bail3; goto bail3;
config->acceptGlobs = FcStrSetCreate ();
if (!config->acceptGlobs)
goto bail4;
config->rejectGlobs = FcStrSetCreate ();
if (!config->rejectGlobs)
goto bail5;
config->cache = 0; config->cache = 0;
if (FcConfigHome()) if (FcConfigHome())
if (!FcConfigSetCache (config, (FcChar8 *) ("~/" FC_USER_CACHE_FILE))) if (!FcConfigSetCache (config, (FcChar8 *) ("~/" FC_USER_CACHE_FILE)))
goto bail4; goto bail6;
config->blanks = 0; config->blanks = 0;
@ -73,6 +81,10 @@ FcConfigCreate (void)
return config; return config;
bail6:
FcStrSetDestroy (config->rejectGlobs);
bail5:
FcStrSetDestroy (config->acceptGlobs);
bail4: bail4:
FcStrSetDestroy (config->fontDirs); FcStrSetDestroy (config->fontDirs);
bail3: bail3:
@ -159,6 +171,8 @@ FcConfigDestroy (FcConfig *config)
FcStrSetDestroy (config->configDirs); FcStrSetDestroy (config->configDirs);
FcStrSetDestroy (config->fontDirs); FcStrSetDestroy (config->fontDirs);
FcStrSetDestroy (config->configFiles); FcStrSetDestroy (config->configFiles);
FcStrSetDestroy (config->acceptGlobs);
FcStrSetDestroy (config->rejectGlobs);
FcStrFree (config->cache); FcStrFree (config->cache);
@ -203,7 +217,8 @@ FcConfigBuildFonts (FcConfig *config)
{ {
if (FcDebug () & FC_DBG_FONTSET) if (FcDebug () & FC_DBG_FONTSET)
printf ("scan dir %s\n", dir); 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); FcStrListDone (list);
@ -1620,7 +1635,7 @@ FcConfigAppFontAddFile (FcConfig *config,
FcConfigSetFonts (config, set, FcSetApplication); 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); FcStrSetDestroy (subdirs);
return FcFalse; return FcFalse;
@ -1667,7 +1682,7 @@ FcConfigAppFontAddDir (FcConfig *config,
FcConfigSetFonts (config, set, FcSetApplication); 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); FcStrSetDestroy (subdirs);
return FcFalse; return FcFalse;
@ -1688,3 +1703,76 @@ FcConfigAppFontClear (FcConfig *config)
{ {
FcConfigSetFonts (config, 0, FcSetApplication); 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;
}

View File

@ -36,12 +36,13 @@ FcFileIsDir (const FcChar8 *file)
} }
FcBool FcBool
FcFileScan (FcFontSet *set, FcFileScanConfig (FcFontSet *set,
FcStrSet *dirs, FcStrSet *dirs,
FcGlobalCache *cache, FcGlobalCache *cache,
FcBlanks *blanks, FcBlanks *blanks,
const FcChar8 *file, const FcChar8 *file,
FcBool force) FcBool force,
FcConfig *config)
{ {
int id; int id;
FcChar8 *name; FcChar8 *name;
@ -53,6 +54,9 @@ FcFileScan (FcFontSet *set,
FcGlobalCacheDir *cache_dir; FcGlobalCacheDir *cache_dir;
FcBool need_scan; FcBool need_scan;
if (config && !FcConfigAcceptFilename (config, file))
return FcTrue;
if (force) if (force)
cache = 0; cache = 0;
id = 0; id = 0;
@ -151,6 +155,17 @@ FcFileScan (FcFontSet *set,
return ret; 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 #define FC_MAX_FILE_LEN 4096
/* /*
@ -159,12 +174,13 @@ FcFileScan (FcFontSet *set,
*/ */
FcBool FcBool
FcDirScan (FcFontSet *set, FcDirScanConfig (FcFontSet *set,
FcStrSet *dirs, FcStrSet *dirs,
FcGlobalCache *cache, FcGlobalCache *cache,
FcBlanks *blanks, FcBlanks *blanks,
const FcChar8 *dir, const FcChar8 *dir,
FcBool force) FcBool force,
FcConfig *config)
{ {
DIR *d; DIR *d;
struct dirent *e; struct dirent *e;
@ -172,12 +188,15 @@ FcDirScan (FcFontSet *set,
FcChar8 *base; FcChar8 *base;
FcBool ret = FcTrue; FcBool ret = FcTrue;
if (config && !FcConfigAcceptFilename (config, dir))
return FcTrue;
if (!force) if (!force)
{ {
/* /*
* Check fonts.cache-<version> file * Check fonts.cache-<version> file
*/ */
if (FcDirCacheReadDir (set, dirs, dir)) if (FcDirCacheReadDir (set, dirs, dir, config))
{ {
if (cache) if (cache)
FcGlobalCacheReferenceSubdir (cache, dir); FcGlobalCacheReferenceSubdir (cache, dir);
@ -187,7 +206,7 @@ FcDirScan (FcFontSet *set,
/* /*
* Check ~/.fonts.cache-<version> file * Check ~/.fonts.cache-<version> file
*/ */
if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir)) if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir, config))
return FcTrue; return FcTrue;
} }
@ -218,7 +237,7 @@ FcDirScan (FcFontSet *set,
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 = FcFileScan (set, dirs, cache, blanks, file, force); ret = FcFileScanConfig (set, dirs, cache, blanks, file, force, config);
} }
} }
free (file); free (file);
@ -233,6 +252,17 @@ FcDirScan (FcFontSet *set,
return ret; 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 FcBool
FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir) FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
{ {

View File

@ -1575,7 +1575,7 @@ FcFreeTypeUseNames (FT_Face face)
if (!FT_Has_PS_Glyph_Names (face)) if (!FT_Has_PS_Glyph_Names (face))
return FcFalse; return FcFalse;
for (map = 0; map < face->num_charmaps; map++) 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 FcTrue;
return FcFalse; return FcFalse;
} }

View File

@ -323,6 +323,11 @@ struct _FcConfig {
FcSubst *substPattern; /* substitutions for patterns */ FcSubst *substPattern; /* substitutions for patterns */
FcSubst *substFont; /* substitutions for fonts */ FcSubst *substFont; /* substitutions for fonts */
int maxObjects; /* maximum number of tests in all substs */ 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 * The set of fonts loaded from the listed directories; the
* order within the set does not determine the font selection, * order within the set does not determine the font selection,
@ -375,7 +380,8 @@ FcBool
FcGlobalCacheScanDir (FcFontSet *set, FcGlobalCacheScanDir (FcFontSet *set,
FcStrSet *dirs, FcStrSet *dirs,
FcGlobalCache *cache, FcGlobalCache *cache,
const FcChar8 *dir); const FcChar8 *dir,
FcConfig *config);
FcGlobalCacheFile * FcGlobalCacheFile *
FcGlobalCacheFileGet (FcGlobalCache *cache, FcGlobalCacheFileGet (FcGlobalCache *cache,
@ -399,7 +405,10 @@ FcGlobalCacheSave (FcGlobalCache *cache,
const FcChar8 *cache_file); const FcChar8 *cache_file);
FcBool FcBool
FcDirCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir); FcDirCacheReadDir (FcFontSet *set,
FcStrSet *dirs,
const FcChar8 *dir,
FcConfig *config);
FcBool FcBool
FcDirCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir); FcDirCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
@ -446,6 +455,15 @@ FcConfigCompareValue (const FcValue m,
FcOp op, FcOp op,
const FcValue v); const FcValue v);
FcBool
FcConfigGlobAdd (FcConfig *config,
const FcChar8 *glob,
FcBool accept);
FcBool
FcConfigAcceptFilename (FcConfig *config,
const FcChar8 *filename);
/* fccharset.c */ /* fccharset.c */
FcCharSet * FcCharSet *
FcCharSetFreeze (FcCharSet *cs); FcCharSetFreeze (FcCharSet *cs);
@ -486,6 +504,24 @@ FcDebug (void);
/* fcdir.c */ /* 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 */ /* fcfont.c */
int int
FcFontDebug (void); FcFontDebug (void);

View File

@ -317,6 +317,11 @@ typedef enum _FcElement {
FcElementDefault, FcElementDefault,
FcElementFamily, FcElementFamily,
FcElementSelectfont,
FcElementAcceptfont,
FcElementRejectfont,
FcElementGlob,
FcElementTest, FcElementTest,
FcElementEdit, FcElementEdit,
FcElementInt, FcElementInt,
@ -373,6 +378,11 @@ FcElementMap (const XML_Char *name)
{ "default", FcElementDefault }, { "default", FcElementDefault },
{ "family", FcElementFamily }, { "family", FcElementFamily },
{ "selectfont", FcElementSelectfont },
{ "acceptfont", FcElementAcceptfont },
{ "rejectfont", FcElementRejectfont },
{ "glob", FcElementGlob },
{ "test", FcElementTest }, { "test", FcElementTest },
{ "edit", FcElementEdit }, { "edit", FcElementEdit },
{ "int", FcElementInt }, { "int", FcElementInt },
@ -428,6 +438,7 @@ typedef enum _FcVStackTag {
FcVStackFamily, FcVStackFamily,
FcVStackField, FcVStackField,
FcVStackConstant, FcVStackConstant,
FcVStackGlob,
FcVStackPrefer, FcVStackPrefer,
FcVStackAccept, FcVStackAccept,
@ -544,6 +555,7 @@ FcVStackDestroy (FcVStack *vstack)
case FcVStackFamily: case FcVStackFamily:
case FcVStackField: case FcVStackField:
case FcVStackConstant: case FcVStackConstant:
case FcVStackGlob:
FcStrFree (vstack->u.string); FcStrFree (vstack->u.string);
break; break;
case FcVStackInteger: case FcVStackInteger:
@ -1639,6 +1651,30 @@ FcParseMatch (FcConfigParse *parse)
FcConfigMessage (parse, FcSevereError, "out of memory"); 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 static void
FcEndElement(void *userData, const XML_Char *name) FcEndElement(void *userData, const XML_Char *name)
{ {
@ -1761,7 +1797,15 @@ FcEndElement(void *userData, const XML_Char *name)
case FcElementCharset: case FcElementCharset:
/* FcParseCharset (parse); */ /* FcParseCharset (parse); */
break; break;
case FcElementSelectfont:
break;
case FcElementAcceptfont:
case FcElementRejectfont:
FcParseAcceptRejectFont (parse, parse->pstack->element);
break;
case FcElementGlob:
FcParseString (parse, FcVStackGlob);
break;
case FcElementName: case FcElementName:
FcParseString (parse, FcVStackField); FcParseString (parse, FcVStackField);
break; break;