diff --git a/gfx/src/nsRect.cpp b/gfx/src/nsRect.cpp index e16d489ac641..d4595b801b38 100644 --- a/gfx/src/nsRect.cpp +++ b/gfx/src/nsRect.cpp @@ -328,3 +328,15 @@ PRBool nsIntRect::UnionRect(const nsIntRect &aRect1, const nsIntRect &aRect2) return result; } +// scale the rect but round to smallest containing rect +nsIntRect& nsIntRect::ScaleRoundOut(float aXScale, float aYScale) +{ + nscoord right = NSToCoordCeil(float(XMost()) * aXScale); + nscoord bottom = NSToCoordCeil(float(YMost()) * aYScale); + x = NSToCoordFloor(float(x) * aXScale); + y = NSToCoordFloor(float(y) * aYScale); + width = (right - x); + height = (bottom - y); + return *this; +} + diff --git a/gfx/src/nsRect.h b/gfx/src/nsRect.h index e02e17b6a456..a7d1490d4fbb 100644 --- a/gfx/src/nsRect.h +++ b/gfx/src/nsRect.h @@ -342,6 +342,8 @@ struct NS_GFX nsIntRect { PRInt32 YMost() const {return y + height;} inline nsRect ToAppUnits(nscoord aAppUnitsPerPixel) const; + + nsIntRect& ScaleRoundOut(float aXScale, float aYScale); // Returns a special nsIntRect that's used in some places to signify // "all available space". diff --git a/gfx/src/nsRegion.cpp b/gfx/src/nsRegion.cpp index cb5ef38383cd..fe801ada38ac 100644 --- a/gfx/src/nsRegion.cpp +++ b/gfx/src/nsRegion.cpp @@ -1316,6 +1316,22 @@ nsRegion& nsRegion::ExtendForScaling (float aXMult, float aYMult) *this = region; return *this; } + +nsRegion& nsRegion::ScaleRoundOut (float aXScale, float aYScale) +{ + nsRegion region; + nsRegionRectIterator iter(*this); + for (;;) { + const nsRect* r = iter.Next(); + if (!r) + break; + nsRect rect = *r; + rect.ScaleRoundOut(aXScale, aYScale); + region.Or(region, rect); + } + *this = region; + return *this; +} nsRegion nsRegion::ConvertAppUnitsRoundOut (PRInt32 aFromAPP, PRInt32 aToAPP) const { diff --git a/gfx/src/nsRegion.h b/gfx/src/nsRegion.h index a25daf53f6f7..96a3731ffc19 100644 --- a/gfx/src/nsRegion.h +++ b/gfx/src/nsRegion.h @@ -184,6 +184,7 @@ public: // the region. nsRegion ConvertAppUnitsRoundOut (PRInt32 aFromAPP, PRInt32 aToAPP) const; nsRegion ConvertAppUnitsRoundIn (PRInt32 aFromAPP, PRInt32 aToAPP) const; + nsRegion& ScaleRoundOut(float aXScale, float aYScale); nsIntRegion ToOutsidePixels (nscoord aAppUnitsPerPixel) const; nsRegion& ExtendForScaling (float aXMult, float aYMult); @@ -438,6 +439,12 @@ public: { return FromRect (mImpl.GetLargestRectangle( ToRect(aContainingRect) )); } + + nsIntRegion& ScaleRoundOut (float aXScale, float aYScale) + { + mImpl.ScaleRoundOut(aXScale, aYScale); + return *this; + } nsIntRegion& ExtendForScaling (float aXMult, float aYMult) {