From e0562335f66ac4878f36087c37539e71771d393d Mon Sep 17 00:00:00 2001 From: "masayuki%d-toybox.com" Date: Sat, 12 Jan 2008 17:30:28 +0000 Subject: [PATCH] Bug 410748 Control borders are not drawn correctly r+sr+a=roc --- gfx/thebes/public/gfxPoint.h | 9 +++++++-- gfx/thebes/public/gfxRect.h | 11 ++++++++--- gfx/thebes/src/gfxRect.cpp | 9 +++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gfx/thebes/public/gfxPoint.h b/gfx/thebes/public/gfxPoint.h index 4837235df58..68ea3062f92 100644 --- a/gfx/thebes/public/gfxPoint.h +++ b/gfx/thebes/public/gfxPoint.h @@ -141,9 +141,14 @@ struct THEBES_API gfxPoint { gfxPoint operator/(const gfxFloat v) const { return gfxPoint(x / v, y / v); } + // Round() is *not* rounding to nearest integer if the values are negative. + // They are always rounding as floor(n + 0.5). + // See https://bugzilla.mozilla.org/show_bug.cgi?id=410748#c14 + // And if you need similar method which is using NS_round(), you should + // create new |RoundAwayFromZero()| method. gfxPoint& Round() { - x = NS_round(x); - y = NS_round(y); + x = NS_floor(x + 0.5); + y = NS_floor(y + 0.5); return *this; } }; diff --git a/gfx/thebes/public/gfxRect.h b/gfx/thebes/public/gfxRect.h index a283bb5c017..1971bf7238f 100644 --- a/gfx/thebes/public/gfxRect.h +++ b/gfx/thebes/public/gfxRect.h @@ -115,10 +115,15 @@ struct THEBES_API gfxRect { Outset(sides[0], sides[1], sides[2], sides[3]); } - // Round the rectangle to integer coordinates; rounds to the neearest - // pixel centers. Suitable for most places where integral device coordinates + // Round the rectangle to integer coordinates. + // Suitable for most places where integral device coordinates // are needed, but note that any translation should be applied first to - // avoid pixel rounding errors + // avoid pixel rounding errors. + // Note that this is *not* rounding to nearest integer if the values are negative. + // They are always rounding as floor(n + 0.5). + // See https://bugzilla.mozilla.org/show_bug.cgi?id=410748#c14 + // If you need similar method which is using NS_round(), you should create + // new |RoundAwayFromZero()| method. void Round(); // grabbing specific points diff --git a/gfx/thebes/src/gfxRect.cpp b/gfx/thebes/src/gfxRect.cpp index b7ece07093f..88da6a31200 100644 --- a/gfx/thebes/src/gfxRect.cpp +++ b/gfx/thebes/src/gfxRect.cpp @@ -76,10 +76,11 @@ gfxRect::Union(const gfxRect& aRect) const void gfxRect::Round() { - gfxFloat x0 = NS_round(X()); - gfxFloat y0 = NS_round(Y()); - gfxFloat x1 = NS_round(XMost()); - gfxFloat y1 = NS_round(YMost()); + // Note that don't use NS_round here. See the comment for this method in gfxRect.h + gfxFloat x0 = NS_floor(X() + 0.5); + gfxFloat y0 = NS_floor(Y() + 0.5); + gfxFloat x1 = NS_floor(XMost() + 0.5); + gfxFloat y1 = NS_floor(YMost() + 0.5); pos.x = x0; pos.y = y0;