Bug 386065 - "legend {font-size:0;} still shows the text (yahoo.com mainpage)" [p=chris@pearce.org.nz (Chris Pearce) r+sr=roc a=blocking1.9+]
authorreed@reedloden.com
Thu, 11 Oct 2007 21:22:25 -0700
changeset 6859 f8e2f8415c270e16274f4f205a1e6f3b9c21c941
parent 6858 a9c09320594db477b40c6347d88db75ab95c09a3
child 6860 ca2a33af72a1384c8c3b9c6862289ce185d2ddbb
push idunknown
push userunknown
push dateunknown
reviewersblocking1.9
bugs386065
milestone1.9a9pre
Bug 386065 - "legend {font-size:0;} still shows the text (yahoo.com mainpage)" [p=chris@pearce.org.nz (Chris Pearce) r+sr=roc a=blocking1.9+]
gfx/src/thebes/nsThebesFontMetrics.cpp
gfx/thebes/src/gfxTextRunWordCache.cpp
--- a/gfx/src/thebes/nsThebesFontMetrics.cpp
+++ b/gfx/src/thebes/nsThebesFontMetrics.cpp
@@ -67,20 +67,17 @@ nsThebesFontMetrics::Init(const nsFont& 
 {
     mFont = aFont;
     mLangGroup = aLangGroup;
     mDeviceContext = (nsThebesDeviceContext*)aContext;
     mP2A = mDeviceContext->AppUnitsPerDevPixel();
     mIsRightToLeft = PR_FALSE;
     mTextRunRTL = PR_FALSE;
 
-    // work around layout giving us 0 sized fonts...
     gfxFloat size = gfxFloat(aFont.size) / mP2A;
-    if (size == 0.0)
-        size = 1.0;
 
     nsCString langGroup;
     if (aLangGroup) {
         const char* lg;
         mLangGroup->GetUTF8String(&lg);
         langGroup.Assign(lg);
     }
 
--- a/gfx/thebes/src/gfxTextRunWordCache.cpp
+++ b/gfx/thebes/src/gfxTextRunWordCache.cpp
@@ -357,22 +357,44 @@ TextRunWordCache::FinishTextRun(gfxTextR
                 if (IsBoundarySpace(aTextRun->GetChar(charIndex))) {
                     aTextRun->SetSpaceGlyph(font, aContext, charIndex);
                 }
             }
         }
     }
 }
 
+static gfxTextRun *
+MakeBlankTextRun(const void* aText, PRUint32 aLength,
+                         gfxFontGroup *aFontGroup,
+                         const gfxFontGroup::Parameters *aParams,
+                         PRUint32 aFlags)
+{
+    nsAutoPtr<gfxTextRun> textRun;
+    textRun = new gfxTextRun(aParams, aText, aLength, aFontGroup, aFlags);
+    if (!textRun || !textRun->GetCharacterGlyphs())
+        return nsnull;
+    gfxFont *font = aFontGroup->GetFontAt(0);
+    textRun->AddGlyphRun(font, 0);
+    return textRun.forget();
+}
+
 gfxTextRun *
 TextRunWordCache::MakeTextRun(const PRUnichar *aText, PRUint32 aLength,
                               gfxFontGroup *aFontGroup,
                               const gfxFontGroup::Parameters *aParams,
                               PRUint32 aFlags)
 {
+    if (aFontGroup->GetStyle()->size == 0) {
+        // Short-circuit for size-0 fonts, as Windows and ATSUI can't handle
+        // them, and always create at least size 1 fonts, i.e. they still
+        // render something for size 0 fonts.
+        return MakeBlankTextRun(aText, aLength, aFontGroup, aParams, aFlags);
+    }
+
     nsAutoPtr<gfxTextRun> textRun;
     textRun = new gfxTextRun(aParams, aText, aLength, aFontGroup, aFlags);
     if (!textRun || !textRun->GetCharacterGlyphs())
         return nsnull;
 #ifdef DEBUG
     textRun->mCachedWords = 0;
 #endif
 
@@ -438,16 +460,23 @@ TextRunWordCache::MakeTextRun(const PRUn
 }
 
 gfxTextRun *
 TextRunWordCache::MakeTextRun(const PRUint8 *aText, PRUint32 aLength,
                               gfxFontGroup *aFontGroup,
                               const gfxFontGroup::Parameters *aParams,
                               PRUint32 aFlags)
 {
+    if (aFontGroup->GetStyle()->size == 0) {
+        // Short-circuit for size-0 fonts, as Windows and ATSUI can't handle
+        // them, and always create at least size 1 fonts, i.e. they still
+        // render something for size 0 fonts.
+        return MakeBlankTextRun(aText, aLength, aFontGroup, aParams, aFlags);
+    }
+
     aFlags |= gfxTextRunFactory::TEXT_IS_8BIT;
     nsAutoPtr<gfxTextRun> textRun;
     textRun = new gfxTextRun(aParams, aText, aLength, aFontGroup, aFlags);
     if (!textRun || !textRun->GetCharacterGlyphs())
         return nsnull;
 #ifdef DEBUG
     textRun->mCachedWords = 0;
 #endif