Bug 59379 - FC_PRGNAME

Can be used for per-application configuration.
This commit is contained in:
Behdad Esfahbod 2013-01-15 20:41:26 -06:00
parent 3f84695104
commit ec5ca08c80
8 changed files with 99 additions and 4 deletions

View File

@ -141,7 +141,7 @@ AC_TYPE_PID_T
# Checks for library functions.
AC_FUNC_VPRINTF
AC_FUNC_MMAP
AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp mkostemp _mktemp_s strchr strrchr strtol getopt getopt_long sysconf ftruncate chsize rand random lrand48 random_r rand_r regcomp regerror regexec regfree fstatvfs fstatfs lstat])
AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp mkostemp _mktemp_s strchr strrchr strtol getopt getopt_long sysconf ftruncate chsize rand random lrand48 random_r rand_r regcomp regerror readlink regexec regfree fstatvfs fstatfs lstat])
dnl AC_CHECK_FUNCS doesn't check for header files.
dnl posix_fadvise() may be not available in older libc.

View File

@ -190,11 +190,12 @@ convenience for the application's rendering mechanism.
the font
embolden FC_EMBOLDEN Bool Rasterizer should
synthetically embolden the font
fontfeatures FC_FONT_FEATURES String List of the feature tags in
fontfeatures FC_FONT_FEATURES String List of extra feature tags in
OpenType to be enabled
namelang FC_NAMELANG String Language name to be used for the
default value of familylang,
stylelang and fullnamelang
prgname FC_PRGNAME String Name of the running program
</programlisting>
</sect2>
</sect1>

View File

@ -132,6 +132,7 @@ convenience for the applications' rendering mechanism.
capability String List of layout capabilities in the font
embolden Bool Rasterizer should synthetically embolden the font
fontfeatures String List of the feature tags in OpenType to be enabled
prgname String String Name of the running program
</programlisting>
</refsect2>
<refsect2>

View File

@ -114,6 +114,7 @@ typedef int FcBool;
#define FC_LCD_FILTER "lcdfilter" /* Int */
#define FC_FONT_FEATURES "fontfeatures" /* String */
#define FC_NAMELANG "namelang" /* String RFC 3866 langs */
#define FC_PRGNAME "prgname" /* String */
#define FC_CACHE_SUFFIX ".cache-" FC_CACHE_VERSION
#define FC_DIR_CACHE_FILE "fonts.cache-" FC_CACHE_VERSION

View File

@ -1478,6 +1478,7 @@ FcConfigSubstituteWithPat (FcConfig *config,
FcPattern *p_pat,
FcMatchKind kind)
{
FcValue v;
FcSubst *s;
FcSubState *st;
int i;
@ -1513,6 +1514,12 @@ FcConfigSubstituteWithPat (FcConfig *config,
}
FcStrListDone (l);
}
if (FcPatternObjectGet (p, FC_PRGNAME_OBJECT, 0, &v) == FcResultNoMatch)
{
FcChar8 *prgname = FcGetPrgname ();
if (prgname)
FcPatternObjectAddString (p, FC_PRGNAME_OBJECT, prgname);
}
break;
case FcMatchFont:
s = config->substFont;

View File

@ -104,11 +104,81 @@ retry:
return lang;
}
static FcChar8 *default_prgname;
FcChar8 *
FcGetPrgname (void)
{
FcChar8 *prgname;
retry:
prgname = fc_atomic_ptr_get (&default_prgname);
if (!prgname)
{
#ifdef _WIN32
char buf[MAX_PATH+1];
/* TODO This is ASCII-only; fix it. */
if (GetModuleFileNameA (GetModuleHandle (NULL), buf, sizeof (buf) / sizeof (buf[0])) > 0)
{
char *p;
unsigned int len;
p = strrchr (buf, '\\');
if (p)
p++;
else
p = buf;
len = strlen (p);
if (len > 4 && 0 == strcmp (p + len - 4, ".exe"))
{
len -= 4;
buf[len] = '\0';
}
prgname = FcStrdup (p);
}
#else
char buf[8192];
unsigned int len;
len = readlink ("/proc/self/exe", buf, sizeof (buf) - 1);
if (len > 0)
{
char *p;
p = strrchr (buf, '/');
if (p)
p++;
else
p = buf;
prgname = FcStrdup (p);
}
#endif
if (!prgname)
prgname = FcStrdup ("");
if (!fc_atomic_ptr_cmpexch (&default_prgname, NULL, prgname)) {
free (prgname);
goto retry;
}
}
if (prgname && !prgname[0])
return NULL;
return prgname;
}
void
FcDefaultFini (void)
{
FcChar8 *lang;
FcStrSet *langs;
FcChar8 *prgname;
lang = fc_atomic_ptr_get (&default_lang);
if (lang && fc_atomic_ptr_cmpexch (&default_lang, lang, NULL)) {
@ -120,6 +190,11 @@ FcDefaultFini (void)
FcRefInit (&langs->ref, 1);
FcStrSetDestroy (langs);
}
prgname = fc_atomic_ptr_get (&default_prgname);
if (prgname && fc_atomic_ptr_cmpexch (&default_prgname, prgname, NULL)) {
free (prgname);
}
}
void
@ -195,7 +270,7 @@ FcDefaultSubstitute (FcPattern *pattern)
* exact matched "en" has higher score than ll-cc.
*/
v2.type = FcTypeString;
v2.u.s = FcStrdup ("en-us");
v2.u.s = (FcChar8 *) "en-us";
if (FcPatternObjectGet (pattern, FC_FAMILYLANG_OBJECT, 0, &v) == FcResultNoMatch)
{
FcPatternObjectAdd (pattern, FC_FAMILYLANG_OBJECT, namelang, FcTrue);
@ -211,7 +286,13 @@ FcDefaultSubstitute (FcPattern *pattern)
FcPatternObjectAdd (pattern, FC_FULLNAMELANG_OBJECT, namelang, FcTrue);
FcPatternObjectAddWithBinding (pattern, FC_FULLNAMELANG_OBJECT, v2, FcValueBindingWeak, FcTrue);
}
FcFree (v2.u.s);
if (FcPatternObjectGet (pattern, FC_PRGNAME_OBJECT, 0, &v) == FcResultNoMatch)
{
FcChar8 *prgname = FcGetPrgname ();
if (prgname)
FcPatternObjectAddString (pattern, FC_PRGNAME_OBJECT, prgname);
}
}
#define __fcdefault__
#include "fcaliastail.h"

View File

@ -770,6 +770,9 @@ FcInitDebug (void);
FcPrivate FcChar8 *
FcGetDefaultLang (void);
FcPrivate FcChar8 *
FcGetPrgname (void);
FcPrivate void
FcDefaultFini (void);

View File

@ -42,4 +42,5 @@ FC_OBJECT (DECORATIVE, FcTypeBool)
FC_OBJECT (LCD_FILTER, FcTypeInteger)
FC_OBJECT (NAMELANG, FcTypeString)
FC_OBJECT (FONT_FEATURES, FcTypeString)
FC_OBJECT (PRGNAME, FcTypeString)
/* ^-------------- Add new objects here. */