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

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

@ -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. */