Bug 426616 Acid2 chin is 1px too tall in FF3b5 r=pavlov, sr=roc, a1.9=beltzner

This commit is contained in:
masayuki@d-toybox.com 2008-04-12 01:54:18 -07:00
parent 77a050c2f0
commit 0767329450
2 changed files with 35 additions and 3 deletions

View File

@ -1468,8 +1468,9 @@ public:
// If this group has such "bad" font, each platform's gfxFontGroup initialized mUnderlineOffset. // If this group has such "bad" font, each platform's gfxFontGroup initialized mUnderlineOffset.
// The value should be lower value of first font's metrics and the bad font's metrics. // The value should be lower value of first font's metrics and the bad font's metrics.
// Otherwise, this returns from first font's metrics. // Otherwise, this returns from first font's metrics.
enum { UNDERLINE_OFFSET_NOT_SET = PR_INT16_MAX };
gfxFloat GetUnderlineOffset() { gfxFloat GetUnderlineOffset() {
if (mStyle.size != 0 && mUnderlineOffset == 0) if (mUnderlineOffset == UNDERLINE_OFFSET_NOT_SET)
mUnderlineOffset = GetFontAt(0)->GetMetrics().underlineOffset; mUnderlineOffset = GetFontAt(0)->GetMetrics().underlineOffset;
return mUnderlineOffset; return mUnderlineOffset;
} }

View File

@ -577,11 +577,22 @@ gfxFont::SanitizeMetrics(gfxFont::Metrics *aMetrics, PRBool aIsBadUnderlineFont)
aMetrics->underlineOffset = PR_MIN(aMetrics->underlineOffset, -1.0); aMetrics->underlineOffset = PR_MIN(aMetrics->underlineOffset, -1.0);
if (aMetrics->maxAscent < 1.0) {
// We cannot draw strikeout line and overline in the ascent...
aMetrics->underlineSize = 0;
aMetrics->underlineOffset = 0;
aMetrics->strikeoutSize = 0;
aMetrics->strikeoutOffset = 0;
return;
}
/** /**
* Some CJK fonts have bad underline offset. Therefore, if this is such font, * Some CJK fonts have bad underline offset. Therefore, if this is such font,
* we need to lower the underline offset to bottom of *em* descent. * we need to lower the underline offset to bottom of *em* descent.
* However, if this is system font, we should not do this for the rendering compatibility with * However, if this is system font, we should not do this for the rendering compatibility with
* another application's UI on the platform. * another application's UI on the platform.
* XXX Should not use this hack if the font size is too small?
* Such text cannot be read, this might be used for tight CSS rendering? (E.g., Acid2)
*/ */
if (!mStyle.systemFont && aIsBadUnderlineFont) { if (!mStyle.systemFont && aIsBadUnderlineFont) {
// First, we need 2 pixels between baseline and underline at least. Because many CJK characters // First, we need 2 pixels between baseline and underline at least. Because many CJK characters
@ -599,8 +610,28 @@ gfxFont::SanitizeMetrics(gfxFont::Metrics *aMetrics, PRBool aIsBadUnderlineFont)
// If underline positioned is too far from the text, descent position is preferred so that underline // If underline positioned is too far from the text, descent position is preferred so that underline
// will stay within the boundary. // will stay within the boundary.
else if (aMetrics->underlineSize - aMetrics->underlineOffset > aMetrics->maxDescent) { else if (aMetrics->underlineSize - aMetrics->underlineOffset > aMetrics->maxDescent) {
if (aMetrics->underlineSize > aMetrics->maxDescent)
aMetrics->underlineSize = PR_MAX(aMetrics->maxDescent, 1.0);
// The max underlineOffset is 1px (the min underlineSize is 1px, and min maxDescent is 0px.)
aMetrics->underlineOffset = aMetrics->underlineSize - aMetrics->maxDescent; aMetrics->underlineOffset = aMetrics->underlineSize - aMetrics->maxDescent;
aMetrics->underlineOffset = PR_MIN(aMetrics->underlineOffset, -1.0); }
// If strikeout line is overflowed from the ascent, the line should be resized and moved for
// that being in the ascent space.
// Note that the strikeoutOffset is *middle* of the strikeout line position.
gfxFloat halfOfStrikeoutSize = NS_floor(aMetrics->strikeoutSize / 2.0 + 0.5);
if (halfOfStrikeoutSize + aMetrics->strikeoutOffset > aMetrics->maxAscent) {
if (aMetrics->strikeoutSize > aMetrics->maxAscent) {
aMetrics->strikeoutSize = PR_MAX(aMetrics->maxAscent, 1.0);
halfOfStrikeoutSize = NS_floor(aMetrics->strikeoutSize / 2.0 + 0.5);
}
gfxFloat ascent = NS_floor(aMetrics->maxAscent + 0.5);
aMetrics->strikeoutOffset = PR_MAX(halfOfStrikeoutSize, ascent / 2.0);
}
// If overline is larger than the ascent, the line should be resized.
if (aMetrics->underlineSize > aMetrics->maxAscent) {
aMetrics->underlineSize = aMetrics->maxAscent;
} }
} }
@ -718,7 +749,7 @@ gfxGlyphExtents::SetTightGlyphExtents(PRUint32 aGlyphID, const gfxRect& aExtents
} }
gfxFontGroup::gfxFontGroup(const nsAString& aFamilies, const gfxFontStyle *aStyle) gfxFontGroup::gfxFontGroup(const nsAString& aFamilies, const gfxFontStyle *aStyle)
: mFamilies(aFamilies), mStyle(*aStyle), mUnderlineOffset(0) : mFamilies(aFamilies), mStyle(*aStyle), mUnderlineOffset(UNDERLINE_OFFSET_NOT_SET)
{ {
} }