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+]
--- 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