Bug 551313. Workaround synthetic Gill Sans family when DirectWrite is used. r=jkew, a=joedrew
authorJohn Daggett <jdaggett@mozilla.com>
Thu, 27 Jan 2011 12:05:55 +0900
changeset 61357 4ece1ca8430d61a98a0354cf43824f15e64d3959
parent 61356 58d3e2cfdbd0b1b69e36408d41298ead581673b9
child 61358 0d93633ce73922e9efe0a6cb865b443c5494a2d4
push idunknown
push userunknown
push dateunknown
reviewersjkew, joedrew
bugs551313
milestone2.0b11pre
Bug 551313. Workaround synthetic Gill Sans family when DirectWrite is used. r=jkew, a=joedrew
gfx/thebes/gfxDWriteFontList.cpp
gfx/thebes/gfxFT2FontList.cpp
gfx/thebes/gfxFont.h
gfx/thebes/gfxGDIFontList.cpp
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -151,31 +151,30 @@ gfxDWriteFontFamily::FindStyleVariations
         fullID.Append(faceName.Elements());
 
         /**
          * Faces do not have a localized name so we just put the en-us name in
          * here.
          */
         gfxDWriteFontEntry *fe = 
             new gfxDWriteFontEntry(fullID, font);
-        fe->SetFamily(this);
+        AddFontEntry(fe);
 
 #ifdef PR_LOGGING
-    if (LOG_FONTLIST_ENABLED()) {
-        LOG_FONTLIST(("(fontlist) added (%s) to family (%s)"
-             " with style: %s weight: %d stretch: %d",
-             NS_ConvertUTF16toUTF8(fe->Name()).get(),
-             NS_ConvertUTF16toUTF8(Name()).get(),
-             (fe->IsItalic()) ? "italic" : "normal",
-             fe->Weight(), fe->Stretch()));
+        if (LOG_FONTLIST_ENABLED()) {
+            LOG_FONTLIST(("(fontlist) added (%s) to family (%s)"
+                 " with style: %s weight: %d stretch: %d",
+                 NS_ConvertUTF16toUTF8(fe->Name()).get(),
+                 NS_ConvertUTF16toUTF8(Name()).get(),
+                 (fe->IsItalic()) ? "italic" : "normal",
+                 fe->Weight(), fe->Stretch()));
+        }
+#endif
     }
-#endif
 
-        mAvailableFonts.AppendElement(fe);
-    }
     if (!mAvailableFonts.Length()) {
         NS_WARNING("Family with no font faces in it.");
     }
 
     if (mIsBadUnderlineFamily) {
         SetBadUnderlineFonts();
     }
 }
@@ -861,16 +860,69 @@ gfxDWriteFontList::DelayedInitFontList()
 
         // at this point, all family names have been read in
         fam->SetOtherFamilyNamesInitialized();
     }
 
     mOtherFamilyNamesInitialized = PR_TRUE;
     GetFontSubstitutes();
 
+    // bug 551313 - DirectWrite creates a Gill Sans family out of 
+    // poorly named members of the Gill Sans MT family containing
+    // only Ultra Bold weights.  This causes big problems for pages
+    // using Gill Sans which is usually only available on OSX
+
+    nsAutoString nameGillSans(L"Gill Sans");
+    nsAutoString nameGillSansMT(L"Gill Sans MT");
+    BuildKeyNameFromFontName(nameGillSans);
+    BuildKeyNameFromFontName(nameGillSansMT);
+
+    gfxFontFamily *gillSansFamily = mFontFamilies.GetWeak(nameGillSans);
+    gfxFontFamily *gillSansMTFamily = mFontFamilies.GetWeak(nameGillSansMT);
+
+    if (gillSansFamily && gillSansMTFamily) {
+        gillSansFamily->FindStyleVariations();
+        nsTArray<nsRefPtr<gfxFontEntry> >& faces = gillSansFamily->GetFontList();
+        PRUint32 i;
+
+        PRBool allUltraBold = PR_TRUE;
+        for (i = 0; i < faces.Length(); i++) {
+            // does the face have 'Ultra Bold' in the name?
+            if (faces[i]->Name().Find(NS_LITERAL_STRING("Ultra Bold")) == -1) {
+                allUltraBold = PR_FALSE;
+                break;
+            }
+        }
+
+        // if all the Gill Sans faces are Ultra Bold ==> move faces
+        // for Gill Sans into Gill Sans MT family
+        if (allUltraBold) {
+
+            // add faces to Gill Sans MT
+            for (i = 0; i < faces.Length(); i++) {
+                gillSansMTFamily->AddFontEntry(faces[i]);
+
+#ifdef PR_LOGGING
+                if (LOG_FONTLIST_ENABLED()) {
+                    gfxFontEntry *fe = faces[i];
+                    LOG_FONTLIST(("(fontlist) moved (%s) to family (%s)"
+                         " with style: %s weight: %d stretch: %d",
+                         NS_ConvertUTF16toUTF8(fe->Name()).get(),
+                         NS_ConvertUTF16toUTF8(gillSansMTFamily->Name()).get(),
+                         (fe->IsItalic()) ? "italic" : "normal",
+                         fe->Weight(), fe->Stretch()));
+                }
+#endif
+            }
+
+            // remove Gills Sans
+            mFontFamilies.Remove(nameGillSans);
+        }
+    }
+
     StartLoader(kDelayBeforeLoadingFonts, kIntervalBetweenLoadingFonts);
 
     LOGREGISTRY(L"DelayedInitFontList end");
 
 #ifdef PR_LOGGING
     if (LOG_FONTINIT_ENABLED()) {
         QueryPerformanceCounter(&t3);
 
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -136,17 +136,16 @@ gfxFT2FontList::AppendFacesFromFontFile(
                 gfxFontFamily *family = mFontFamilies.GetWeak(name);
                 if (!family) {
                     family = new gfxFontFamily(name);
                     mFontFamilies.Put(name, family);
                     if (mBadUnderlineFamilyNames.Contains(name))
                         family->SetBadUnderlineFamily();
                 }
                 family->AddFontEntry(fe);
-                fe->SetFamily(family);
                 family->SetHasStyles(PR_TRUE);
                 if (family->IsBadUnderlineFamily())
                     fe->mIsBadUnderlineFont = PR_TRUE;
 #ifdef PR_LOGGING
                 if (LOG_ENABLED()) {
                     LOG(("(fontinit) added (%s) to family (%s)"
                          " with style: %s weight: %d stretch: %d",
                          NS_ConvertUTF16toUTF8(fe->Name()).get(), 
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -489,16 +489,17 @@ public:
 
     virtual void LocalizedName(nsAString& aLocalizedName);
     virtual PRBool HasOtherFamilyNames();
     
     nsTArray<nsRefPtr<gfxFontEntry> >& GetFontList() { return mAvailableFonts; }
     
     void AddFontEntry(nsRefPtr<gfxFontEntry> aFontEntry) {
         mAvailableFonts.AppendElement(aFontEntry);
+        aFontEntry->SetFamily(this);
     }
 
     // note that the styles for this family have been added
     void SetHasStyles(PRBool aHasStyles) { mHasStyles = aHasStyles; }
 
     // choose a specific face to match a style using CSS font matching
     // rules (weight matching occurs here).  may return a face that doesn't
     // precisely match (e.g. normal face when no italic face exists).
--- a/gfx/thebes/gfxGDIFontList.cpp
+++ b/gfx/thebes/gfxGDIFontList.cpp
@@ -507,18 +507,17 @@ GDIFontFamily::FamilyAddStylesProc(const
         }
     }
 
     fe = GDIFontEntry::CreateFontEntry(nsDependentString(lpelfe->elfFullName), feType, (logFont.lfItalic == 0xFF),
                                        (PRUint16) (logFont.lfWeight), nsnull);
     if (!fe)
         return 1;
 
-    ff->mAvailableFonts.AppendElement(fe);
-    fe->SetFamily(ff);
+    ff->AddFontEntry(fe);
 
     // mark the charset bit
     fe->mCharset.set(metrics.tmCharSet);
 
     fe->mWindowsFamily = logFont.lfPitchAndFamily & 0xF0;
     fe->mWindowsPitch = logFont.lfPitchAndFamily & 0x0F;
 
     if (nmetrics->ntmFontSig.fsUsb[0] != 0x00000000 &&