bug 737315 - use the proxy's name for the FT2 entry when instantiating a downloaded font. r=jdaggett
authorJonathan Kew <jkew@mozilla.com>
Thu, 24 May 2012 09:15:54 +0100
changeset 94791 8d1b746c137b6bca479a0a638574a602a71a3b21
parent 94790 f0c9c6e916db8f0a1f8a2d071f0abf597d57c7f4
child 94792 1865549541b72aec5d9a55d601da7588c97bae3e
push id9807
push userjkew@mozilla.com
push dateThu, 24 May 2012 08:17:30 +0000
treeherdermozilla-inbound@1865549541b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs737315
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 737315 - use the proxy's name for the FT2 entry when instantiating a downloaded font. r=jdaggett
gfx/thebes/gfxFT2FontList.cpp
gfx/thebes/gfxFT2FontList.h
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -172,17 +172,21 @@ FT2FontEntry::CreateFontEntry(const gfxP
         NS_Free((void*)aFontData);
         return nsnull;
     }
     if (FT_Err_Ok != FT_Select_Charmap(face, FT_ENCODING_UNICODE)) {
         FT_Done_Face(face);
         NS_Free((void*)aFontData);
         return nsnull;
     }
-    FT2FontEntry* fe = FT2FontEntry::CreateFontEntry(face, nsnull, 0, aFontData);
+    // Create our FT2FontEntry, which inherits the name of the proxy
+    // as it's not guaranteed that the face has valid names (bug 737315)
+    FT2FontEntry* fe =
+        FT2FontEntry::CreateFontEntry(face, nsnull, 0, aProxyEntry.Name(),
+                                      aFontData);
     if (fe) {
         fe->mItalic = aProxyEntry.mItalic;
         fe->mWeight = aProxyEntry.mWeight;
         fe->mStretch = aProxyEntry.mStretch;
     }
     return fe;
 }
 
@@ -225,32 +229,22 @@ FT2FontEntry::CreateFontEntry(const Font
     fe->mItalic = aFLE.italic();
     return fe;
 }
 
 /* static */
 FT2FontEntry*
 FT2FontEntry::CreateFontEntry(FT_Face aFace,
                               const char* aFilename, PRUint8 aIndex,
+                              const nsAString& aName,
                               const PRUint8 *aFontData)
 {
     static cairo_user_data_key_t key;
 
-    if (!aFace->family_name) {
-        FT_Done_Face(aFace);
-        return nsnull;
-    }
-    // Construct font name from family name and style name, regular fonts
-    // do not have the modifier by convention.
-    NS_ConvertUTF8toUTF16 fontName(aFace->family_name);
-    if (aFace->style_name && strcmp("Regular", aFace->style_name)) {
-        fontName.AppendLiteral(" ");
-        AppendUTF8toUTF16(aFace->style_name, fontName);
-    }
-    FT2FontEntry *fe = new FT2FontEntry(fontName);
+    FT2FontEntry *fe = new FT2FontEntry(aName);
     fe->mItalic = aFace->style_flags & FT_STYLE_FLAG_ITALIC;
     fe->mFTFace = aFace;
     int flags = gfxPlatform::GetPlatform()->FontHintingEnabled() ?
                 FT_LOAD_DEFAULT :
                 (FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_HINTING);
     fe->mFontFace = cairo_ft_font_face_create_for_ft_face(aFace, flags);
     fe->mFilename = aFilename;
     fe->mFTFontIndex = aIndex;
@@ -278,16 +272,33 @@ FT2FontEntry::CreateFontEntry(FT_Face aF
     else
         fe->mWeight = 400;
 
     NS_ASSERTION(fe->mWeight >= 100 && fe->mWeight <= 900, "Invalid final weight in font!");
 
     return fe;
 }
 
+// construct font entry name for an installed font from names in the FT_Face,
+// and then create our FT2FontEntry
+static FT2FontEntry*
+CreateNamedFontEntry(FT_Face aFace, const char* aFilename, PRUint8 aIndex)
+{
+    if (!aFace->family_name) {
+        return nsnull;
+    }
+    nsAutoString fontName;
+    AppendUTF8toUTF16(aFace->family_name, fontName);
+    if (aFace->style_name && strcmp("Regular", aFace->style_name)) {
+        fontName.AppendLiteral(" ");
+        AppendUTF8toUTF16(aFace->style_name, fontName);
+    }
+    return FT2FontEntry::CreateFontEntry(aFace, aFilename, aIndex, fontName);
+}
+
 FT2FontEntry*
 gfxFT2Font::GetFontEntry()
 {
     return static_cast<FT2FontEntry*> (mFontEntry.get());
 }
 
 cairo_font_face_t *
 FT2FontEntry::CairoFontFace()
@@ -746,17 +757,17 @@ gfxFT2FontList::AppendFacesFromFontFile(
             if (FT_Err_Ok != FT_New_Face(ftLibrary, aFileName.get(), i, &face)) {
                 continue;
             }
             if (FT_Err_Ok != FT_Select_Charmap(face, FT_ENCODING_UNICODE)) {
                 FT_Done_Face(face);
                 continue;
             }
             FT2FontEntry* fe =
-                FT2FontEntry::CreateFontEntry(face, aFileName.get(), i);
+                CreateNamedFontEntry(face, aFileName.get(), i);
             if (fe) {
                 NS_ConvertUTF8toUTF16 name(face->family_name);
                 BuildKeyNameFromFontName(name);       
                 gfxFontFamily *family = mFontFamilies.GetWeak(name);
                 if (!family) {
                     family = new FT2FontFamily(name);
                     mFontFamilies.Put(name, family);
                     if (mBadUnderlineFamilyNames.Contains(name)) {
--- a/gfx/thebes/gfxFT2FontList.h
+++ b/gfx/thebes/gfxFT2FontList.h
@@ -45,23 +45,24 @@ public:
                     const PRUint8 *aFontData, PRUint32 aLength);
 
     // create a font entry representing an installed font, identified by
     // a FontListEntry; the freetype and cairo faces will not be instantiated
     // until actually needed
     static FT2FontEntry*
     CreateFontEntry(const FontListEntry& aFLE);
 
-    // create a font entry for a given freetype face; if it is an installed font,
+    // Create a font entry for a given freetype face; if it is an installed font,
     // also record the filename and index
+    // aFontData (if non-NULL) is NS_Malloc'ed data that aFace depends on,
+    // to be freed after the face is destroyed
     static FT2FontEntry* 
     CreateFontEntry(FT_Face aFace, const char *aFilename, PRUint8 aIndex,
+                    const nsAString& aName,
                     const PRUint8 *aFontData = nsnull);
-        // aFontData is NS_Malloc'ed data that aFace depends on, to be freed
-        // after the face is destroyed; null if there is no such buffer
 
     virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle,
                                         bool aNeedsBold);
 
     cairo_font_face_t *CairoFontFace();
     cairo_scaled_font_t *CreateScaledFont(const gfxFontStyle *aStyle);
 
     nsresult ReadCMAP();