[Fontconfig] fontconfig: Branch 'master'
Behdad Esfahbod
behdad at kemper.freedesktop.org
Tue Jan 15 18:46:51 PST 2013
configure.ac | 2 -
doc/fontconfig-devel.sgml | 3 +
doc/fontconfig-user.sgml | 1
fontconfig/fontconfig.h | 1
src/fccfg.c | 7 +++
src/fcdefault.c | 85 ++++++++++++++++++++++++++++++++++++++++++++--
src/fcint.h | 3 +
src/fcobjs.h | 1
8 files changed, 99 insertions(+), 4 deletions(-)
New commits:
commit ec5ca08c807585a9230f83c95f7cca6b7065b142
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue Jan 15 20:41:26 2013 -0600
Bug 59379 - FC_PRGNAME
Can be used for per-application configuration.
diff --git a/configure.ac b/configure.ac
index 06ac8a2..a520ae7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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.
diff --git a/doc/fontconfig-devel.sgml b/doc/fontconfig-devel.sgml
index b35ef9a..05c5c09 100644
--- a/doc/fontconfig-devel.sgml
+++ b/doc/fontconfig-devel.sgml
@@ -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>
diff --git a/doc/fontconfig-user.sgml b/doc/fontconfig-user.sgml
index 068b1fc..90e246b 100644
--- a/doc/fontconfig-user.sgml
+++ b/doc/fontconfig-user.sgml
@@ -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>
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index 3676fc1..dc2532f 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -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
diff --git a/src/fccfg.c b/src/fccfg.c
index 877a4f5..3e9fdab 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -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;
diff --git a/src/fcdefault.c b/src/fcdefault.c
index 6937994..aa47840 100644
--- a/src/fcdefault.c
+++ b/src/fcdefault.c
@@ -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"
diff --git a/src/fcint.h b/src/fcint.h
index 5129267..3cf526f 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -770,6 +770,9 @@ FcInitDebug (void);
FcPrivate FcChar8 *
FcGetDefaultLang (void);
+FcPrivate FcChar8 *
+FcGetPrgname (void);
+
FcPrivate void
FcDefaultFini (void);
diff --git a/src/fcobjs.h b/src/fcobjs.h
index cbe0190..ad803eb 100644
--- a/src/fcobjs.h
+++ b/src/fcobjs.h
@@ -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. */
More information about the Fontconfig
mailing list