зеркало из https://github.com/mozilla/pjs.git
Not Part Of The Build. 1) Round font underline/overline/strikeout offsets and sizes to device pixels to try to ensure consistent visual offsets and sizes even when the baseline point is not pixel-aligned. 2) snap the text baseline y coordinate to the nearest pixel, because the decoration lines will be snapped themselves and we need the gaps to remain consistent. 3) fix bug in selection-decoration x coordinate which was forgetting to include the frame x-offset.
This commit is contained in:
Родитель
7e4a98c6aa
Коммит
c4a2486cb0
|
@ -452,6 +452,8 @@ public:
|
|||
void AddInlinePrefWidthForFlow(nsIRenderingContext *aRenderingContext,
|
||||
InlinePrefWidthData *aData);
|
||||
|
||||
gfxFloat GetSnappedBaselineY(gfxContext* aContext, gfxFloat aY);
|
||||
|
||||
// primary frame paint method called from nsDisplayText
|
||||
void PaintText(nsIRenderingContext* aRenderingContext, nsPoint aPt,
|
||||
const nsRect& aDirtyRect);
|
||||
|
@ -3350,19 +3352,19 @@ nsTextFrame::PaintTextDecorations(gfxContext* aCtx, const gfxRect& aDirtyRect,
|
|||
if (decorations & NS_FONT_DECORATION_OVERLINE) {
|
||||
FillClippedRect(aCtx, aTextPaintStyle.PresContext(), overColor, aDirtyRect,
|
||||
gfxRect(aFramePt.x, aFramePt.y,
|
||||
GetRect().width, fontMetrics.underlineSize*pix2app));
|
||||
GetRect().width, NS_round(fontMetrics.underlineSize)*pix2app));
|
||||
}
|
||||
if (decorations & NS_FONT_DECORATION_UNDERLINE) {
|
||||
FillClippedRect(aCtx, aTextPaintStyle.PresContext(), underColor, aDirtyRect,
|
||||
gfxRect(aFramePt.x,
|
||||
aFramePt.y + mAscent - fontMetrics.underlineOffset*pix2app,
|
||||
GetRect().width, fontMetrics.underlineSize*pix2app));
|
||||
GetSnappedBaselineY(aCtx, aFramePt.y) - NS_round(fontMetrics.underlineOffset)*pix2app,
|
||||
GetRect().width, NS_round(fontMetrics.underlineSize)*pix2app));
|
||||
}
|
||||
if (decorations & NS_FONT_DECORATION_LINE_THROUGH) {
|
||||
FillClippedRect(aCtx, aTextPaintStyle.PresContext(), strikeColor, aDirtyRect,
|
||||
gfxRect(aFramePt.x,
|
||||
aFramePt.y + mAscent - fontMetrics.strikeoutOffset*pix2app,
|
||||
GetRect().width, fontMetrics.strikeoutSize*pix2app));
|
||||
GetSnappedBaselineY(aCtx, aFramePt.y) - NS_round(fontMetrics.strikeoutOffset)*pix2app,
|
||||
GetRect().width, NS_round(fontMetrics.strikeoutSize)*pix2app));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3717,7 +3719,7 @@ nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx,
|
|||
gfxFloat advance = hyphenWidth +
|
||||
mTextRun->GetAdvanceWidth(offset, length, &aProvider);
|
||||
if (type == aSelectionType) {
|
||||
gfxFloat x = xOffset - (mTextRun->IsRightToLeft() ? advance : 0);
|
||||
gfxFloat x = aTextBaselinePt.x + xOffset - (mTextRun->IsRightToLeft() ? advance : 0);
|
||||
DrawSelectionDecorations(aCtx, aSelectionType, aTextPaintStyle,
|
||||
gfxPoint(x, aTextBaselinePt.y), advance,
|
||||
aDirtyRect, decorationMetrics);
|
||||
|
@ -3770,6 +3772,17 @@ ComputeTransformedLength(PropertyProvider& aProvider)
|
|||
return iter.GetSkippedOffset() - start;
|
||||
}
|
||||
|
||||
gfxFloat
|
||||
nsTextFrame::GetSnappedBaselineY(gfxContext* aContext, gfxFloat aY)
|
||||
{
|
||||
gfxFloat appUnitsPerDevUnit = mTextRun->GetAppUnitsPerDevUnit();
|
||||
gfxFloat baseline = aY + mAscent;
|
||||
gfxRect putativeRect(0, baseline/appUnitsPerDevUnit, 1, 1);
|
||||
if (!aContext->UserToDevicePixelSnapped(putativeRect))
|
||||
return baseline;
|
||||
return aContext->DeviceToUser(putativeRect.pos).y*appUnitsPerDevUnit;
|
||||
}
|
||||
|
||||
void
|
||||
nsTextFrame::PaintText(nsIRenderingContext* aRenderingContext, nsPoint aPt,
|
||||
const nsRect& aDirtyRect)
|
||||
|
@ -3790,7 +3803,7 @@ nsTextFrame::PaintText(nsIRenderingContext* aRenderingContext, nsPoint aPt,
|
|||
gfxPoint framePt(aPt.x, aPt.y);
|
||||
gfxPoint textBaselinePt(
|
||||
mTextRun->IsRightToLeft() ? gfxFloat(aPt.x + GetSize().width) : framePt.x,
|
||||
aPt.y + mAscent);
|
||||
GetSnappedBaselineY(ctx, aPt.y));
|
||||
|
||||
gfxRect dirtyRect(aDirtyRect.x, aDirtyRect.y,
|
||||
aDirtyRect.width, aDirtyRect.height);
|
||||
|
|
Загрузка…
Ссылка в новой задаче