Bug 63922 - FcFreeTypeQueryFace fails on postscripts fonts loaded from memory
authorAkira TAGOH <akira@tagoh.org>
Fri, 10 May 2013 11:26:11 +0000 (20:26 +0900)
committerAkira TAGOH <akira@tagoh.org>
Thu, 16 May 2013 07:49:14 +0000 (16:49 +0900)
Workaround to not failing even when the hash is unable to generate from fonts.
This change also contains to ignore the case if the hash isn't in either both
patterns.

src/fcfreetype.c
src/fcmatch.c
src/fcobjs.h

index 5e8990d..02e85cb 100644 (file)
@@ -1671,10 +1671,10 @@ FcFreeTypeQueryFace (const FT_Face  face,
        alen = (len + 63) & ~63;
        fontdata = malloc (alen);
        if (!fontdata)
-           goto bail1;
+           goto bail3;
        err = FT_Load_Sfnt_Table (face, 0, 0, (FT_Byte *)fontdata, &len);
        if (err != FT_Err_Ok)
-           goto bail1;
+           goto bail3;
        memset (&fontdata[len], 0, alen - len);
        hashstr = FcHashGetSHA256DigestFromMemory (fontdata, len);
     }
@@ -1687,12 +1687,14 @@ FcFreeTypeQueryFace (const FT_Face  face,
     }
     else
     {
-       goto bail1;
+       goto bail3;
     }
-    if (!hashstr)
-       goto bail1;
-    if (!FcPatternAddString (pat, FC_HASH, hashstr))
-       goto bail1;
+    if (hashstr)
+    {
+       if (!FcPatternAddString (pat, FC_HASH, hashstr))
+           goto bail1;
+    }
+bail3:
 
     /*
      * Compute the unicode coverage for the font
index 84c9a9a..10976d6 100644 (file)
@@ -191,15 +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 (FcStrGlobMatch (s1, s2))
-           return 2.0;
-       else
-           return 3.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)                            \
@@ -215,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)
 
index b735401..682fe6a 100644 (file)
@@ -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. */