aboutsummaryrefslogtreecommitdiff
path: root/fontconfig/src
diff options
context:
space:
mode:
Diffstat (limited to 'fontconfig/src')
-rw-r--r--fontconfig/src/fcatomic.h14
-rw-r--r--fontconfig/src/fccfg.c46
-rw-r--r--fontconfig/src/fcfreetype.c45
-rw-r--r--fontconfig/src/fchash.c57
-rw-r--r--fontconfig/src/fcint.h9
-rw-r--r--fontconfig/src/fcmatch.c32
-rw-r--r--fontconfig/src/fcname.c6
-rw-r--r--fontconfig/src/fcobjs.h2
-rw-r--r--fontconfig/src/fcstr.c44
9 files changed, 189 insertions, 66 deletions
diff --git a/fontconfig/src/fcatomic.h b/fontconfig/src/fcatomic.h
index a76431139..362e52164 100644
--- a/fontconfig/src/fcatomic.h
+++ b/fontconfig/src/fcatomic.h
@@ -70,13 +70,25 @@ typedef LONG fc_atomic_int_t;
#elif !defined(FC_NO_MT) && defined(__APPLE__)
#include <libkern/OSAtomic.h>
+#ifdef __MAC_OS_X_MIN_REQUIRED
+#include <AvailabilityMacros.h>
+#elif defined(__IPHONE_OS_MIN_REQUIRED)
+#include <Availability.h>
+#endif
typedef int fc_atomic_int_t;
#define fc_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V))
#define fc_atomic_ptr_get(P) (OSMemoryBarrier (), (void *) *(P))
+#if (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 || __IPHONE_VERSION_MIN_REQUIRED >= 20100)
#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P))
-
+#else
+#if __ppc64__ || __x86_64__
+#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap64Barrier ((int64_t) (O), (int64_t) (N), (int64_t*) (P))
+#else
+#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap32Barrier ((int32_t) (O), (int32_t) (N), (int32_t*) (P))
+#endif
+#endif
#elif !defined(FC_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES)
diff --git a/fontconfig/src/fccfg.c b/fontconfig/src/fccfg.c
index 7da50b50f..fcdf73efe 100644
--- a/fontconfig/src/fccfg.c
+++ b/fontconfig/src/fccfg.c
@@ -2211,57 +2211,13 @@ FcConfigGlobAdd (FcConfig *config,
}
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)
- {
- size_t l1, l2;
-
- l1 = strlen ((char *) string);
- l2 = strlen ((char *) glob);
- if (l1 < l2)
- return FcFalse;
- string += (l1 - l2);
- }
- 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))
+ if (FcStrGlobMatch (globs->strs[i], string))
return FcTrue;
return FcFalse;
}
diff --git a/fontconfig/src/fcfreetype.c b/fontconfig/src/fcfreetype.c
index c7859848c..55f2626a5 100644
--- a/fontconfig/src/fcfreetype.c
+++ b/fontconfig/src/fcfreetype.c
@@ -1104,7 +1104,10 @@ FcFreeTypeQueryFace (const FT_Face face,
char psname[256];
const char *tmp;
- FcChar8 *hashstr;
+ FcChar8 *hashstr = NULL;
+ char *fontdata = NULL;
+ FT_Error err;
+ FT_ULong len = 0, alen;
pat = FcPatternCreate ();
if (!pat)
@@ -1662,12 +1665,36 @@ FcFreeTypeQueryFace (const FT_Face face,
if (!FcPatternAddBool (pat, FC_DECORATIVE, decorative))
goto bail1;
- hashstr = FcHashGetSHA256DigestFromFile (file);
- if (!hashstr)
- goto bail1;
- if (!FcPatternAddString (pat, FC_HASH, hashstr))
- goto bail1;
- free (hashstr);
+ err = FT_Load_Sfnt_Table (face, 0, 0, NULL, &len);
+ if (err == FT_Err_Ok)
+ {
+ alen = (len + 63) & ~63;
+ fontdata = malloc (alen);
+ if (!fontdata)
+ goto bail3;
+ err = FT_Load_Sfnt_Table (face, 0, 0, (FT_Byte *)fontdata, &len);
+ if (err != FT_Err_Ok)
+ goto bail3;
+ memset (&fontdata[len], 0, alen - len);
+ hashstr = FcHashGetSHA256DigestFromMemory (fontdata, len);
+ }
+ else if (err == FT_Err_Invalid_Face_Handle)
+ {
+ /* font may not support SFNT. falling back to
+ * read the font data from file directly
+ */
+ hashstr = FcHashGetSHA256DigestFromFile (file);
+ }
+ else
+ {
+ goto bail3;
+ }
+ if (hashstr)
+ {
+ if (!FcPatternAddString (pat, FC_HASH, hashstr))
+ goto bail1;
+ }
+bail3:
/*
* Compute the unicode coverage for the font
@@ -1756,6 +1783,10 @@ FcFreeTypeQueryFace (const FT_Face face,
bail2:
FcCharSetDestroy (cs);
bail1:
+ if (hashstr)
+ free (hashstr);
+ if (fontdata)
+ free (fontdata);
FcPatternDestroy (pat);
bail0:
return NULL;
diff --git a/fontconfig/src/fchash.c b/fontconfig/src/fchash.c
index 827b20f9f..92585a632 100644
--- a/fontconfig/src/fchash.c
+++ b/fontconfig/src/fchash.c
@@ -220,7 +220,7 @@ FcHashGetSHA256DigestFromFile (const FcChar8 *filename)
ret = FcHashInitSHA256Digest ();
if (!ret)
- return NULL;
+ goto bail0;
while (!feof (fp))
{
@@ -261,5 +261,60 @@ FcHashGetSHA256DigestFromFile (const FcChar8 *filename)
bail0:
fclose (fp);
+
return NULL;
}
+
+FcChar8 *
+FcHashGetSHA256DigestFromMemory (const char *fontdata,
+ size_t length)
+{
+ char ibuf[64];
+ FcChar32 *ret;
+ size_t i = 0;
+
+ ret = FcHashInitSHA256Digest ();
+ if (!ret)
+ return NULL;
+
+ while (i <= length)
+ {
+ if ((length - i) < 64)
+ {
+ long v;
+ size_t n;
+
+ /* add a padding */
+ n = length - i;
+ if (n > 0)
+ memcpy (ibuf, &fontdata[i], n);
+ memset (&ibuf[n], 0, 64 - n);
+ ibuf[n] = 0x80;
+ if ((64 - n) < 9)
+ {
+ /* process a block once */
+ FcHashComputeSHA256Digest (ret, ibuf);
+ memset (ibuf, 0, 64);
+ }
+ /* set input size at the end */
+ v = length * 8;
+ ibuf[63 - 0] = v & 0xff;
+ ibuf[63 - 1] = (v >> 8) & 0xff;
+ ibuf[63 - 2] = (v >> 16) & 0xff;
+ ibuf[63 - 3] = (v >> 24) & 0xff;
+ ibuf[63 - 4] = (v >> 32) & 0xff;
+ ibuf[63 - 5] = (v >> 40) & 0xff;
+ ibuf[63 - 6] = (v >> 48) & 0xff;
+ ibuf[63 - 7] = (v >> 56) & 0xff;
+ FcHashComputeSHA256Digest (ret, ibuf);
+ break;
+ }
+ else
+ {
+ FcHashComputeSHA256Digest (ret, &fontdata[i]);
+ }
+ i += 64;
+ }
+
+ return FcHashSHA256ToString (ret);
+}
diff --git a/fontconfig/src/fcint.h b/fontconfig/src/fcint.h
index c45075ecc..65bf3330b 100644
--- a/fontconfig/src/fcint.h
+++ b/fontconfig/src/fcint.h
@@ -818,9 +818,14 @@ FcFontSetSerialize (FcSerialize *serialize, const FcFontSet * s);
FcPrivate FcChar8 *
FcHashGetSHA256Digest (const FcChar8 *input_strings,
size_t len);
+
FcPrivate FcChar8 *
FcHashGetSHA256DigestFromFile (const FcChar8 *filename);
+FcPrivate FcChar8 *
+FcHashGetSHA256DigestFromMemory (const char *fontdata,
+ size_t length);
+
/* fcinit.c */
FcPrivate FcConfig *
FcInitLoadOwnConfig (FcConfig *config);
@@ -1085,6 +1090,10 @@ FcPrivate int
FcStrMatchIgnoreCaseAndDelims (const FcChar8 *s1, const FcChar8 *s2, const FcChar8 *delims);
FcPrivate FcBool
+FcStrGlobMatch (const FcChar8 *glob,
+ const FcChar8 *string);
+
+FcPrivate FcBool
FcStrUsesHome (const FcChar8 *s);
FcPrivate FcChar8 *
diff --git a/fontconfig/src/fcmatch.c b/fontconfig/src/fcmatch.c
index 2d7b79840..10976d6e8 100644
--- a/fontconfig/src/fcmatch.c
+++ b/fontconfig/src/fcmatch.c
@@ -191,17 +191,26 @@ FcCompareSize (FcValue *value1, FcValue *value2)
static double
FcCompareFilename (FcValue *v1, FcValue *v2)
{
- const FcChar8 *s1 = FcValueString (v1), *s2 = FcValueString (v2);
- if (FcStrCmp (s1, s2) == 0)
- return 0.0;
- else if (FcStrCmpIgnoreCase (s1, s2) == 0)
- return 1.0;
- else if (FcStrRegexCmp (s2, s1))
- return 2.0;
- else if (FcStrRegexCmpIgnoreCase (s2, s1))
- return 3.0;
- else
- return 4.0;
+ const FcChar8 *s1 = FcValueString (v1), *s2 = FcValueString (v2);
+ if (FcStrCmp (s1, s2) == 0)
+ return 0.0;
+ else if (FcStrCmpIgnoreCase (s1, s2) == 0)
+ return 1.0;
+ else if (FcStrGlobMatch (s1, s2))
+ return 2.0;
+ else
+ return 3.0;
+}
+
+static double
+FcCompareHash (FcValue *v1, FcValue *v2)
+{
+ const FcChar8 *s1 = FcValueString (v1), *s2 = FcValueString (v2);
+
+ /* Do not match an empty string */
+ if (!s1 || !s2 || !s1[0] || !s2[0])
+ return 1.0;
+ return FcCompareString (v1, v2);
}
#define PRI_NULL(n) \
@@ -217,6 +226,7 @@ FcCompareFilename (FcValue *v1, FcValue *v2)
#define PRI_FcCompareCharSet(n) PRI1(n)
#define PRI_FcCompareLang(n) PRI1(n)
#define PRI_FcComparePostScript(n) PRI1(n)
+#define PRI_FcCompareHash(n) PRI1(n)
#define FC_OBJECT(NAME, Type, Cmp) PRI_##Cmp(NAME)
diff --git a/fontconfig/src/fcname.c b/fontconfig/src/fcname.c
index 6dd4d4948..a52534548 100644
--- a/fontconfig/src/fcname.c
+++ b/fontconfig/src/fcname.c
@@ -318,6 +318,12 @@ FcNameFindNext (const FcChar8 *cur, const char *delim, FcChar8 *save, FcChar8 *l
while ((c = *cur))
{
+ if (!isspace (c))
+ break;
+ ++cur;
+ }
+ while ((c = *cur))
+ {
if (c == '\\')
{
++cur;
diff --git a/fontconfig/src/fcobjs.h b/fontconfig/src/fcobjs.h
index b7354012d..682fe6ad3 100644
--- a/fontconfig/src/fcobjs.h
+++ b/fontconfig/src/fcobjs.h
@@ -43,6 +43,6 @@ FC_OBJECT (LCD_FILTER, FcTypeInteger, NULL)
FC_OBJECT (NAMELANG, FcTypeString, NULL)
FC_OBJECT (FONT_FEATURES, FcTypeString, NULL)
FC_OBJECT (PRGNAME, FcTypeString, NULL)
-FC_OBJECT (HASH, FcTypeString, FcCompareString)
+FC_OBJECT (HASH, FcTypeString, FcCompareHash)
FC_OBJECT (POSTSCRIPT_NAME, FcTypeString, FcComparePostScript)
/* ^-------------- Add new objects here. */
diff --git a/fontconfig/src/fcstr.c b/fontconfig/src/fcstr.c
index 339a3465d..3a32031a2 100644
--- a/fontconfig/src/fcstr.c
+++ b/fontconfig/src/fcstr.c
@@ -459,6 +459,50 @@ FcStrMatchIgnoreCaseAndDelims (const FcChar8 *s1, const FcChar8 *s2, const FcCha
return w1.src - s1 - 1;
}
+FcBool
+FcStrGlobMatch (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)
+ {
+ size_t l1, l2;
+
+ l1 = strlen ((char *) string);
+ l2 = strlen ((char *) glob);
+ if (l1 < l2)
+ return FcFalse;
+ string += (l1 - l2);
+ }
+ while (*string)
+ {
+ if (FcStrGlobMatch (glob, string))
+ return FcTrue;
+ string++;
+ }
+ return FcFalse;
+ case '?':
+ if (*string++ == '\0')
+ return FcFalse;
+ break;
+ default:
+ if (*string++ != c)
+ return FcFalse;
+ break;
+ }
+ }
+ return *string == '\0';
+}
+
const FcChar8 *
FcStrStrIgnoreCase (const FcChar8 *s1, const FcChar8 *s2)
{