Bug 720721. Properly transform the clip path in DrawTargetCG. r=mwoodrow

This is a little tricky because we can't put a save/restore pair
around the operation because then we'll loose the clip.
This commit is contained in:
Jeff Muizelaar 2012-01-24 15:14:50 -05:00
parent 73a1588f02
commit 84e78d7e00
4 changed files with 47 additions and 0 deletions

View File

@ -43,6 +43,9 @@
//CG_EXTERN void CGContextSetCompositeOperation (CGContextRef, PrivateCGCompositeMode);
// A private API that Cairo has been using for a long time
CG_EXTERN void CGContextSetCTM(CGContextRef, CGAffineTransform);
namespace mozilla {
namespace gfx {
@ -923,7 +926,12 @@ DrawTargetCG::PushClipRect(const Rect &aRect)
{
CGContextSaveGState(mCg);
/* We go through a bit of trouble to temporarilly set the transform
* while we add the path */
CGAffineTransform previousTransform = CGContextGetCTM(mCg);
CGContextConcatCTM(mCg, GfxMatrixToCGAffineTransform(mTransform));
CGContextClipToRect(mCg, RectToCGRect(aRect));
CGContextSetCTM(mCg, previousTransform);
}
@ -946,7 +954,14 @@ DrawTargetCG::PushClip(const Path *aPath)
}
/* We go through a bit of trouble to temporarilly set the transform
* while we add the path. XXX: this could be improved if we keep
* the CTM as resident state on the DrawTarget. */
CGContextSaveGState(mCg);
CGContextConcatCTM(mCg, GfxMatrixToCGAffineTransform(mTransform));
CGContextAddPath(mCg, cgPath->GetPath());
CGContextRestoreGState(mCg);
if (cgPath->GetFillRule() == FILL_EVEN_ODD)
CGContextEOClip(mCg);
else

View File

@ -75,3 +75,4 @@ fails-if(/Mac\x20OS\x20X\x2010\.[56]/.test(http.oscpu)) == 672646-alpha-radial-g
!= 693610-1.html 693610-1-notref.html # bug 693610: multiple glyph runs should not be overprinted
== transformed-clip.html transformed-clip-ref.html

View File

@ -0,0 +1,15 @@
<html>
<body>
<canvas width="500" height="500"></canvas>
<script>
var canvas = document.getElementsByTagName('canvas')[0];
var ctx = canvas.getContext('2d');
ctx.fillStyle = "red";
ctx.beginPath();
ctx.rect(250, 250, 50, 50);
ctx.clip();
ctx.fillRect(0,0,500,500);
</script>
</body>
</html>

View File

@ -0,0 +1,16 @@
<html>
<body>
<canvas width="500" height="500"></canvas>
<script>
var canvas = document.getElementsByTagName('canvas')[0];
var ctx = canvas.getContext('2d');
ctx.translate(500, 500);
ctx.fillStyle = "red";
ctx.beginPath();
ctx.rect(-250, -250, 50, 50);
ctx.clip();
ctx.fillRect(-500,-500,500,500);
</script>
</body>
</html>