Add FC_DESKTOP_NAME property

To allow users to have desktop-specific matching rule.
This commit is contained in:
Akira TAGOH 2022-11-25 21:15:32 +09:00
parent eb0a199e06
commit 6715a14f13
5 changed files with 82 additions and 25 deletions

View File

@ -128,6 +128,7 @@ typedef int FcBool;
#define FC_POSTSCRIPT_NAME "postscriptname" /* String */ #define FC_POSTSCRIPT_NAME "postscriptname" /* String */
#define FC_FONT_HAS_HINT "fonthashint" /* Bool - true if font has hinting */ #define FC_FONT_HAS_HINT "fonthashint" /* Bool - true if font has hinting */
#define FC_ORDER "order" /* Integer */ #define FC_ORDER "order" /* Integer */
#define FC_DESKTOP_NAME "desktop" /* String */
#define FC_CACHE_SUFFIX ".cache-" FC_CACHE_VERSION #define FC_CACHE_SUFFIX ".cache-" FC_CACHE_VERSION
#define FC_DIR_CACHE_FILE "fonts.cache-" FC_CACHE_VERSION #define FC_DIR_CACHE_FILE "fonts.cache-" FC_CACHE_VERSION
@ -285,7 +286,7 @@ typedef struct _FcObjectSet {
int sobject; int sobject;
const char **objects; const char **objects;
} FcObjectSet; } FcObjectSet;
typedef enum _FcMatchKind { typedef enum _FcMatchKind {
FcMatchPattern, FcMatchFont, FcMatchScan, FcMatchPattern, FcMatchFont, FcMatchScan,
FcMatchKindEnd, FcMatchKindEnd,
@ -400,7 +401,7 @@ FcConfigGetFilename (FcConfig *config,
FcPublic FcChar8 * FcPublic FcChar8 *
FcConfigFilename (const FcChar8 *url); FcConfigFilename (const FcChar8 *url);
FcPublic FcConfig * FcPublic FcConfig *
FcConfigCreate (void); FcConfigCreate (void);
@ -418,7 +419,7 @@ FcConfigGetCurrent (void);
FcPublic FcBool FcPublic FcBool
FcConfigUptoDate (FcConfig *config); FcConfigUptoDate (FcConfig *config);
FcPublic FcBool FcPublic FcBool
FcConfigBuildFonts (FcConfig *config); FcConfigBuildFonts (FcConfig *config);
@ -548,12 +549,12 @@ FcCharSetIsSubset (const FcCharSet *a, const FcCharSet *b);
#define FC_CHARSET_DONE ((FcChar32) -1) #define FC_CHARSET_DONE ((FcChar32) -1)
FcPublic FcChar32 FcPublic FcChar32
FcCharSetFirstPage (const FcCharSet *a, FcCharSetFirstPage (const FcCharSet *a,
FcChar32 map[FC_CHARSET_MAP_SIZE], FcChar32 map[FC_CHARSET_MAP_SIZE],
FcChar32 *next); FcChar32 *next);
FcPublic FcChar32 FcPublic FcChar32
FcCharSetNextPage (const FcCharSet *a, FcCharSetNextPage (const FcCharSet *a,
FcChar32 map[FC_CHARSET_MAP_SIZE], FcChar32 map[FC_CHARSET_MAP_SIZE],
FcChar32 *next); FcChar32 *next);
@ -609,7 +610,7 @@ FcDirCacheLoad (const FcChar8 *dir, FcConfig *config, FcChar8 **cache_file);
FcPublic FcCache * FcPublic FcCache *
FcDirCacheRescan (const FcChar8 *dir, FcConfig *config); FcDirCacheRescan (const FcChar8 *dir, FcConfig *config);
FcPublic FcCache * FcPublic FcCache *
FcDirCacheRead (const FcChar8 *dir, FcBool force, FcConfig *config); FcDirCacheRead (const FcChar8 *dir, FcBool force, FcConfig *config);
@ -772,7 +773,7 @@ FcFontSetMatch (FcConfig *config,
FcPublic FcPattern * FcPublic FcPattern *
FcFontMatch (FcConfig *config, FcFontMatch (FcConfig *config,
FcPattern *p, FcPattern *p,
FcResult *result); FcResult *result);
FcPublic FcPattern * FcPublic FcPattern *
@ -890,10 +891,10 @@ FcPatternHash (const FcPattern *p);
FcPublic FcBool FcPublic FcBool
FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append); FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append);
FcPublic FcBool FcPublic FcBool
FcPatternAddWeak (FcPattern *p, const char *object, FcValue value, FcBool append); FcPatternAddWeak (FcPattern *p, const char *object, FcValue value, FcBool append);
FcPublic FcResult FcPublic FcResult
FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v); FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v);
@ -956,7 +957,7 @@ FcPatternGetRange (const FcPattern *p, const char *object, int id, FcRange **r);
FcPublic FcPattern * FcPublic FcPattern *
FcPatternVaBuild (FcPattern *p, va_list va); FcPatternVaBuild (FcPattern *p, va_list va);
FcPublic FcPattern * FcPublic FcPattern *
FcPatternBuild (FcPattern *p, ...) FC_ATTRIBUTE_SENTINEL(0); FcPatternBuild (FcPattern *p, ...) FC_ATTRIBUTE_SENTINEL(0);
@ -1025,10 +1026,10 @@ FcStrCopy (const FcChar8 *s);
FcPublic FcChar8 * FcPublic FcChar8 *
FcStrCopyFilename (const FcChar8 *s); FcStrCopyFilename (const FcChar8 *s);
FcPublic FcChar8 * FcPublic FcChar8 *
FcStrPlus (const FcChar8 *s1, const FcChar8 *s2); FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
FcPublic void FcPublic void
FcStrFree (FcChar8 *s); FcStrFree (FcChar8 *s);
@ -1145,7 +1146,7 @@ _FCFUNCPROTOEND
* Deprecated functions are placed here to help users fix their code without * Deprecated functions are placed here to help users fix their code without
* digging through documentation * digging through documentation
*/ */
#define FcConfigGetRescanInverval FcConfigGetRescanInverval_REPLACE_BY_FcConfigGetRescanInterval #define FcConfigGetRescanInverval FcConfigGetRescanInverval_REPLACE_BY_FcConfigGetRescanInterval
#define FcConfigSetRescanInverval FcConfigSetRescanInverval_REPLACE_BY_FcConfigSetRescanInterval #define FcConfigSetRescanInverval FcConfigSetRescanInverval_REPLACE_BY_FcConfigSetRescanInterval

View File

@ -211,28 +211,73 @@ retry:
return prgname; return prgname;
} }
static FcChar8 *default_desktop_name;
FcChar8 *
FcGetDesktopName (void)
{
FcChar8 *desktop_name;
retry:
desktop_name = fc_atomic_ptr_get (&default_desktop_name);
if (!desktop_name)
{
char *s = getenv ("XDG_CURRENT_DESKTOP");
if (!s)
desktop_name = FcStrdup ("");
else
desktop_name = FcStrdup (s);
if (!desktop_name)
{
fprintf (stderr, "Fontconfig error: out of memory in %s\n",
__FUNCTION__);
return NULL;
}
if (!fc_atomic_ptr_cmpexch(&default_desktop_name, NULL, desktop_name))
{
free (desktop_name);
goto retry;
}
}
if (desktop_name && !desktop_name[0])
return NULL;
return desktop_name;
}
void void
FcDefaultFini (void) FcDefaultFini (void)
{ {
FcChar8 *lang; FcChar8 *lang;
FcStrSet *langs; FcStrSet *langs;
FcChar8 *prgname; FcChar8 *prgname;
FcChar8 *desktop;
lang = fc_atomic_ptr_get (&default_lang); lang = fc_atomic_ptr_get (&default_lang);
if (lang && fc_atomic_ptr_cmpexch (&default_lang, lang, NULL)) { if (lang && fc_atomic_ptr_cmpexch (&default_lang, lang, NULL))
{
free (lang); free (lang);
} }
langs = fc_atomic_ptr_get (&default_langs); langs = fc_atomic_ptr_get (&default_langs);
if (langs && fc_atomic_ptr_cmpexch (&default_langs, langs, NULL)) { if (langs && fc_atomic_ptr_cmpexch (&default_langs, langs, NULL))
{
FcRefInit (&langs->ref, 1); FcRefInit (&langs->ref, 1);
FcStrSetDestroy (langs); FcStrSetDestroy (langs);
} }
prgname = fc_atomic_ptr_get (&default_prgname); prgname = fc_atomic_ptr_get (&default_prgname);
if (prgname && fc_atomic_ptr_cmpexch (&default_prgname, prgname, NULL)) { if (prgname && fc_atomic_ptr_cmpexch (&default_prgname, prgname, NULL))
{
free (prgname); free (prgname);
} }
desktop = fc_atomic_ptr_get (&default_desktop_name);
if (desktop && fc_atomic_ptr_cmpexch(&default_desktop_name, desktop, NULL))
{
free (desktop);
}
} }
void void
@ -336,6 +381,13 @@ FcDefaultSubstitute (FcPattern *pattern)
FcPatternObjectAddString (pattern, FC_PRGNAME_OBJECT, prgname); FcPatternObjectAddString (pattern, FC_PRGNAME_OBJECT, prgname);
} }
if (FcPatternObjectGet (pattern, FC_DESKTOP_NAME_OBJECT, 0, &v) == FcResultNoMatch)
{
FcChar8 *desktop = FcGetDesktopName ();
if (desktop)
FcPatternObjectAddString (pattern, FC_DESKTOP_NAME_OBJECT, desktop);
}
if (!FcPatternFindObjectIter (pattern, &iter, FC_ORDER_OBJECT)) if (!FcPatternFindObjectIter (pattern, &iter, FC_ORDER_OBJECT))
FcPatternObjectAddInteger (pattern, FC_ORDER_OBJECT, 0); FcPatternObjectAddInteger (pattern, FC_ORDER_OBJECT, 0);
} }

View File

@ -199,7 +199,7 @@ typedef struct _FcValueList {
} FcValueList; } FcValueList;
#define FcValueListNext(vl) FcPointerMember(vl,next,FcValueList) #define FcValueListNext(vl) FcPointerMember(vl,next,FcValueList)
typedef int FcObject; typedef int FcObject;
/* The 1024 is to leave some room for future added internal objects, such /* The 1024 is to leave some room for future added internal objects, such
@ -238,7 +238,7 @@ struct _FcPattern {
FcFontSetFonts(fs)[i], \ FcFontSetFonts(fs)[i], \
FcPattern) : \ FcPattern) : \
fs->fonts[i]) fs->fonts[i])
typedef enum _FcOp { typedef enum _FcOp {
FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpRange, FcOpBool, FcOpCharSet, FcOpLangSet, FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpRange, FcOpBool, FcOpCharSet, FcOpLangSet,
FcOpNil, FcOpNil,
@ -909,6 +909,9 @@ FcGetDefaultLang (void);
FcPrivate FcChar8 * FcPrivate FcChar8 *
FcGetPrgname (void); FcGetPrgname (void);
FcPrivate FcChar8 *
FcGetDesktopName (void);
FcPrivate void FcPrivate void
FcDefaultFini (void); FcDefaultFini (void);

View File

@ -74,4 +74,5 @@ FC_OBJECT (FONT_VARIATIONS, FcTypeString, NULL)
FC_OBJECT (VARIABLE, FcTypeBool, FcCompareBool) FC_OBJECT (VARIABLE, FcTypeBool, FcCompareBool)
FC_OBJECT (FONT_HAS_HINT, FcTypeBool, FcCompareBool) FC_OBJECT (FONT_HAS_HINT, FcTypeBool, FcCompareBool)
FC_OBJECT (ORDER, FcTypeInteger, FcCompareNumber) FC_OBJECT (ORDER, FcTypeInteger, FcCompareNumber)
FC_OBJECT (DESKTOP_NAME, FcTypeString, NULL)
/* ^-------------- Add new objects here. */ /* ^-------------- Add new objects here. */

View File

@ -367,7 +367,7 @@ typedef enum _FcElement {
FcElementDescription, FcElementDescription,
FcElementRemapDir, FcElementRemapDir,
FcElementResetDirs, FcElementResetDirs,
FcElementRescan, FcElementRescan,
FcElementPrefer, FcElementPrefer,
@ -731,7 +731,7 @@ FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type)
if (o) if (o)
FcTypecheckValue (parse, o->type, type); FcTypecheckValue (parse, o->type, type);
} }
else else
FcConfigMessage (parse, FcSevereWarning, FcConfigMessage (parse, FcSevereWarning,
"invalid constant used : %s", "invalid constant used : %s",
expr->u.constant); expr->u.constant);
@ -794,7 +794,7 @@ FcTestCreate (FcConfigParse *parse,
if (test) if (test)
{ {
const FcObjectType *o; const FcObjectType *o;
test->kind = kind; test->kind = kind;
test->qual = qual; test->qual = qual;
test->object = FcObjectFromName ((const char *) field); test->object = FcObjectFromName ((const char *) field);
@ -1533,7 +1533,7 @@ FcStrtod (char *s, char **end)
{ {
char buf[128]; char buf[128];
int slen = strlen (s); int slen = strlen (s);
if (slen + dlen > (int) sizeof (buf)) if (slen + dlen > (int) sizeof (buf))
{ {
if (end) if (end)
@ -3101,7 +3101,7 @@ FcParsePattern (FcConfigParse *parse)
FcConfigMessage (parse, FcSevereError, "out of memory"); FcConfigMessage (parse, FcSevereError, "out of memory");
return; return;
} }
while ((vstack = FcVStackPeek (parse))) while ((vstack = FcVStackPeek (parse)))
{ {
switch ((int) vstack->tag) { switch ((int) vstack->tag) {
@ -3176,7 +3176,7 @@ FcEndElement(void *userData, const XML_Char *name FC_UNUSED)
case FcElementRescan: case FcElementRescan:
FcParseRescan (parse); FcParseRescan (parse);
break; break;
case FcElementPrefer: case FcElementPrefer:
FcParseFamilies (parse, FcVStackPrefer); FcParseFamilies (parse, FcVStackPrefer);
break; break;
@ -3512,7 +3512,7 @@ FcConfigParseAndLoadFromMemoryInternal (FcConfig *config,
XML_SetDoctypeDeclHandler (p, FcStartDoctypeDecl, FcEndDoctypeDecl); XML_SetDoctypeDeclHandler (p, FcStartDoctypeDecl, FcEndDoctypeDecl);
XML_SetElementHandler (p, FcStartElement, FcEndElement); XML_SetElementHandler (p, FcStartElement, FcEndElement);
XML_SetCharacterDataHandler (p, FcCharacterData); XML_SetCharacterDataHandler (p, FcCharacterData);
#endif /* ENABLE_LIBXML2 */ #endif /* ENABLE_LIBXML2 */
#ifndef ENABLE_LIBXML2 #ifndef ENABLE_LIBXML2