[fontconfig] Fix a web font issue in firefox. (#946859)

Akira TAGOH tagoh at fedoraproject.org
Thu Apr 11 09:32:25 UTC 2013


commit e669d0170be4492cd966114122ad5281ec2276de
Author: Akira TAGOH <tagoh at redhat.com>
Date:   Thu Apr 11 18:32:21 2013 +0900

    Fix a web font issue in firefox. (#946859)

 fontconfig-fix-woff.patch |  157 +++++++++++++++++++++++++++++++++++++++++++++
 fontconfig.spec           |    7 ++-
 2 files changed, 163 insertions(+), 1 deletions(-)
---
diff --git a/fontconfig-fix-woff.patch b/fontconfig-fix-woff.patch
new file mode 100644
index 0000000..a3600c0
--- /dev/null
+++ b/fontconfig-fix-woff.patch
@@ -0,0 +1,157 @@
+diff --git a/src/fcfreetype.c b/src/fcfreetype.c
+index 8a037c0..5e8990d 100644
+--- a/src/fcfreetype.c
++++ b/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,34 @@ FcFreeTypeQueryFace (const FT_Face  face,
+     if (!FcPatternAddBool (pat, FC_DECORATIVE, decorative))
+ 	goto bail1;
+ 
+-    hashstr = FcHashGetSHA256DigestFromFile (file);
++    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 bail1;
++	err = FT_Load_Sfnt_Table (face, 0, 0, (FT_Byte *)fontdata, &len);
++	if (err != FT_Err_Ok)
++	    goto bail1;
++	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 bail1;
++    }
+     if (!hashstr)
+ 	goto bail1;
+     if (!FcPatternAddString (pat, FC_HASH, hashstr))
+ 	goto bail1;
+-    free (hashstr);
+ 
+     /*
+      * Compute the unicode coverage for the font
+@@ -1756,6 +1781,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/src/fchash.c b/src/fchash.c
+index 827b20f..92585a6 100644
+--- a/src/fchash.c
++++ b/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/src/fcint.h b/src/fcint.h
+index c45075e..8919958 100644
+--- a/src/fcint.h
++++ b/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);
diff --git a/fontconfig.spec b/fontconfig.spec
index 51d204d..9af8b58 100644
--- a/fontconfig.spec
+++ b/fontconfig.spec
@@ -3,7 +3,7 @@
 Summary:	Font configuration and customization library
 Name:		fontconfig
 Version:	2.10.92
-Release:	2%{?dist}
+Release:	3%{?dist}
 # src/ftglue.[ch] is in Public Domain
 # src/fccache.c contains Public Domain code
 # fc-case/CaseFolding.txt is in the UCD
@@ -17,6 +17,7 @@ Source1:	25-no-bitmap-fedora.conf
 # https://bugzilla.redhat.com/show_bug.cgi?id=140335
 Patch0:		fontconfig-2.8.0-sleep-less.patch
 Patch1:		%{name}-929372.patch
+Patch2:		%{name}-fix-woff.patch
 
 BuildRequires:	expat-devel
 BuildRequires:	freetype-devel >= %{freetype_version}
@@ -59,6 +60,7 @@ which is useful for developing applications that uses fontconfig.
 %setup -q
 %patch0 -p1 -b .sleep-less
 %patch1 -p1
+%patch2 -p1
 
 %build
 # We don't want to rebuild the docs, but we want to install the included ones.
@@ -135,6 +137,9 @@ fi
 %doc fontconfig-devel.txt fontconfig-devel
 
 %changelog
+* Thu Apr 11 2013 Akira TAGOH <tagoh at redhat.com> - 2.10.92-3
+- Fix a web font issue in firefox. (#946859)
+
 * Mon Apr  1 2013 Akira TAGOH <tagoh at redhat.com> - 2.10.92-2
 - Fix font matching issue. (#929372)
 


More information about the fonts-bugs mailing list