From 5a8444256924f73846e4e5c5d235bb85c7ce18dd Mon Sep 17 00:00:00 2001 From: "masayuki@d-toybox.com" Date: Mon, 3 Sep 2007 08:27:26 -0700 Subject: [PATCH] Bug 394109 Inconsistent text-decoration positioning. r+sr+a=roc --- gfx/thebes/src/gfxRect.cpp | 10 +++++----- layout/base/nsCSSRendering.cpp | 2 +- layout/generic/nsTextFrameThebes.cpp | 21 +++++++++++++-------- layout/xul/base/src/nsTextBoxFrame.cpp | 20 +++++++++++--------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/gfx/thebes/src/gfxRect.cpp b/gfx/thebes/src/gfxRect.cpp index 7282be218e8..b7ece07093f 100644 --- a/gfx/thebes/src/gfxRect.cpp +++ b/gfx/thebes/src/gfxRect.cpp @@ -37,7 +37,7 @@ #include "gfxRect.h" -#include +#include "nsMathUtils.h" gfxRect gfxRect::Intersect(const gfxRect& aRect) const @@ -76,10 +76,10 @@ gfxRect::Union(const gfxRect& aRect) const void gfxRect::Round() { - gfxFloat x0 = floor(X() + 0.5); - gfxFloat y0 = floor(Y() + 0.5); - gfxFloat x1 = floor(XMost() + 0.5); - gfxFloat y1 = floor(YMost() + 0.5); + gfxFloat x0 = NS_round(X()); + gfxFloat y0 = NS_round(Y()); + gfxFloat x1 = NS_round(XMost()); + gfxFloat y1 = NS_round(YMost()); pos.x = x0; pos.y = y0; diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index d36e2f997c6..7aadced2899 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -4437,7 +4437,7 @@ nsCSSRendering::PaintDecorationLine(gfxContext* aGfxContext, // round to device pixels for suppressing the AA. gfxFloat x = NS_round(aPt.x); - gfxFloat y = NS_round(aPt.y + aAscent - offset); + gfxFloat y = NS_round(aPt.y + aAscent) - NS_round(offset); gfxFloat width = NS_round(aLineSize.width); gfxFloat height = NS_round(aLineSize.height); // The y position should be set to the middle of the line. diff --git a/layout/generic/nsTextFrameThebes.cpp b/layout/generic/nsTextFrameThebes.cpp index f1962e4f66a..3a92b911cab 100644 --- a/layout/generic/nsTextFrameThebes.cpp +++ b/layout/generic/nsTextFrameThebes.cpp @@ -466,7 +466,9 @@ public: const nsRect& aDirtyRect); // helper: paint quirks-mode CSS text decorations void PaintTextDecorations(gfxContext* aCtx, const gfxRect& aDirtyRect, - const gfxPoint& aFramePt, nsTextPaintStyle& aTextStyle, + const gfxPoint& aFramePt, + const gfxPoint& aTextBaselinePt, + nsTextPaintStyle& aTextStyle, PropertyProvider& aProvider); // helper: paint text frame when we're impacted by at least one selection. // Return PR_FALSE if the text was not painted and we should continue with @@ -3732,6 +3734,7 @@ FillClippedRect(gfxContext* aCtx, nsPresContext* aPresContext, void nsTextFrame::PaintTextDecorations(gfxContext* aCtx, const gfxRect& aDirtyRect, const gfxPoint& aFramePt, + const gfxPoint& aTextBaselinePt, nsTextPaintStyle& aTextPaintStyle, PropertyProvider& aProvider) { @@ -3798,7 +3801,7 @@ nsTextFrame::PaintTextDecorations(gfxContext* aCtx, const gfxRect& aDirtyRect, PRInt32 app = aTextPaintStyle.PresContext()->AppUnitsPerDevPixel(); // XXX aFramePt is in AppUnits, shouldn't it be nsFloatPoint? - gfxPoint pt(aFramePt.x / app, aFramePt.y / app); + gfxPoint pt(aFramePt.x / app, (aTextBaselinePt.y - mAscent) / app); gfxSize size(GetRect().width / app, 0); gfxFloat ascent = mAscent / app; @@ -4174,15 +4177,15 @@ nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx, aProvider, mTextRun); gfxFloat xOffset, hyphenWidth; PRUint32 offset, length; + PRInt32 app = aTextPaintStyle.PresContext()->AppUnitsPerDevPixel(); + // XXX aTextBaselinePt is in AppUnits, shouldn't it be nsFloatPoint? + gfxPoint pt(0.0, (aTextBaselinePt.y - mAscent) / app); SelectionType type; while (iterator.GetNextSegment(&xOffset, &offset, &length, &hyphenWidth, &type)) { gfxFloat advance = hyphenWidth + mTextRun->GetAdvanceWidth(offset, length, &aProvider); if (type == aSelectionType) { - PRInt32 app = aTextPaintStyle.PresContext()->AppUnitsPerDevPixel(); - // XXX aTextBaselinePt is in AppUnits, shouldn't it be nsFloatPoint? - gfxPoint pt((aTextBaselinePt.x + xOffset) / app, - (aTextBaselinePt.y - mAscent) / app); + pt.x = (aTextBaselinePt.x + xOffset) / app; gfxFloat width = PR_ABS(advance) / app; DrawSelectionDecorations(aCtx, aSelectionType, aTextPaintStyle, pt, width, mAscent / app, decorationMetrics, @@ -4205,7 +4208,8 @@ nsTextFrame::PaintTextWithSelection(gfxContext* aCtx, SelectionType allTypes; PaintTextWithSelectionColors(aCtx, aFramePt, aTextBaselinePt, aDirtyRect, aProvider, aTextPaintStyle, details, &allTypes); - PaintTextDecorations(aCtx, aDirtyRect, aFramePt, aTextPaintStyle, aProvider); + PaintTextDecorations(aCtx, aDirtyRect, aFramePt, aTextBaselinePt, + aTextPaintStyle, aProvider); PRInt32 i; // Iterate through just the selection types that paint decorations and // paint decorations for any that actually occur in this frame. Paint @@ -4297,7 +4301,8 @@ nsTextFrame::PaintText(nsIRenderingContext* aRenderingContext, nsPoint aPt, 0, hyphenTextRun->GetLength(), &dirtyRect, nsnull, nsnull); } } - PaintTextDecorations(ctx, dirtyRect, framePt, textPaintStyle, provider); + PaintTextDecorations(ctx, dirtyRect, framePt, textBaselinePt, + textPaintStyle, provider); } PRInt16 diff --git a/layout/xul/base/src/nsTextBoxFrame.cpp b/layout/xul/base/src/nsTextBoxFrame.cpp index eb35e04e094..a42b648cdbd 100644 --- a/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/layout/xul/base/src/nsTextBoxFrame.cpp @@ -446,16 +446,18 @@ nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext, nscoord offset; nscoord size; - nscoord baseline; - fontMet->GetMaxAscent(baseline); + nscoord ascent; + fontMet->GetMaxAscent(ascent); PRBool isRTL = vis->mDirection == NS_STYLE_DIRECTION_RTL; + nscoord baseline = + presContext->RoundAppUnitsToNearestDevPixels(textRect.y + ascent); nsRefPtr ctx = (gfxContext*) aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT); gfxPoint pt(presContext->AppUnitsToGfxUnits(textRect.x), presContext->AppUnitsToGfxUnits(textRect.y)); gfxFloat width = presContext->AppUnitsToGfxUnits(textRect.width); - gfxFloat baselinePixel = presContext->AppUnitsToGfxUnits(baseline); + gfxFloat ascentPixel = presContext->AppUnitsToGfxUnits(ascent); if (decorations & (NS_FONT_DECORATION_OVERLINE | NS_FONT_DECORATION_UNDERLINE)) { fontMet->GetUnderline(offset, size); gfxFloat offsetPixel = presContext->AppUnitsToGfxUnits(offset); @@ -463,7 +465,7 @@ nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext, if (decorations & NS_FONT_DECORATION_OVERLINE) { nsCSSRendering::PaintDecorationLine(ctx, overColor, pt, gfxSize(width, sizePixel), - baselinePixel, baselinePixel, + ascentPixel, ascentPixel, sizePixel, NS_STYLE_TEXT_DECORATION_OVERLINE, NS_STYLE_BORDER_STYLE_SOLID, @@ -472,7 +474,7 @@ nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext, if (decorations & NS_FONT_DECORATION_UNDERLINE) { nsCSSRendering::PaintDecorationLine(ctx, underColor, pt, gfxSize(width, sizePixel), - baselinePixel, offsetPixel, + ascentPixel, offsetPixel, sizePixel, NS_STYLE_TEXT_DECORATION_UNDERLINE, NS_STYLE_BORDER_STYLE_SOLID, @@ -485,7 +487,7 @@ nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext, gfxFloat sizePixel = presContext->AppUnitsToGfxUnits(size); nsCSSRendering::PaintDecorationLine(ctx, underColor, pt, gfxSize(width, sizePixel), - baselinePixel, offsetPixel, + ascentPixel, offsetPixel, sizePixel, NS_STYLE_TEXT_DECORATION_LINE_THROUGH, NS_STYLE_BORDER_STYLE_SOLID, @@ -515,7 +517,7 @@ nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext, posResolve.logicalIndex = mAccessKeyInfo->mAccesskeyIndex; rv = bidiUtils->RenderText(mCroppedTitle.get(), mCroppedTitle.Length(), direction, presContext, aRenderingContext, - textRect.x, textRect.y + baseline, + textRect.x, baseline, &posResolve, 1); mAccessKeyInfo->mBeforeWidth = posResolve.visualLeftTwips; @@ -524,7 +526,7 @@ nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext, { rv = bidiUtils->RenderText(mCroppedTitle.get(), mCroppedTitle.Length(), direction, presContext, aRenderingContext, - textRect.x, textRect.y + baseline); + textRect.x, baseline); } } } @@ -544,7 +546,7 @@ nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext, mAccessKeyInfo->mBeforeWidth = 0; } - aRenderingContext.DrawString(mCroppedTitle, textRect.x, textRect.y + baseline); + aRenderingContext.DrawString(mCroppedTitle, textRect.x, baseline); } if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {