2006-10-26 Oliver Hunt <oliver@apple.com>
authoroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2006 18:54:16 +0000 (18:54 +0000)
committeroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2006 18:54:16 +0000 (18:54 +0000)
        Reviewed by Anders.
        Fixes <rdar://problem/4800518> -- needed to update existing
        canvas path elements when transforms are performed on the
        context.

        * html/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::scale):
        (WebCore::CanvasRenderingContext2D::rotate):
        (WebCore::CanvasRenderingContext2D::translate):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17334 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/canvas/canvas-transforms-during-path-expected.checksum [new file with mode: 0644]
LayoutTests/fast/canvas/canvas-transforms-during-path-expected.png [new file with mode: 0644]
LayoutTests/fast/canvas/canvas-transforms-during-path-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/canvas-transforms-during-path.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/CanvasRenderingContext2D.cpp

index 2f883888c761adc7f4356cb5cf0161aa785155f6..d59a4e43e485b1681135551f58ad2f92592cbd6c 100644 (file)
@@ -1,3 +1,13 @@
+2006-10-26  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Anders.
+        Layout test for <rdar://problem/4800518>
+
+        * fast/canvas/canvas-transforms-during-path-expected.checksum: Added.
+        * fast/canvas/canvas-transforms-during-path-expected.png: Added.
+        * fast/canvas/canvas-transforms-during-path-expected.txt: Added.
+        * fast/canvas/canvas-transforms-during-path.html: Added.
+
 2006-10-26  Darin Adler  <darin@apple.com>
 
         Reviewed by Anders.
diff --git a/LayoutTests/fast/canvas/canvas-transforms-during-path-expected.checksum b/LayoutTests/fast/canvas/canvas-transforms-during-path-expected.checksum
new file mode 100644 (file)
index 0000000..8b2bb40
--- /dev/null
@@ -0,0 +1 @@
+b9ab6d56266f079a01f8211fd443e221
\ No newline at end of file
diff --git a/LayoutTests/fast/canvas/canvas-transforms-during-path-expected.png b/LayoutTests/fast/canvas/canvas-transforms-during-path-expected.png
new file mode 100644 (file)
index 0000000..0c32feb
Binary files /dev/null and b/LayoutTests/fast/canvas/canvas-transforms-during-path-expected.png differ
diff --git a/LayoutTests/fast/canvas/canvas-transforms-during-path-expected.txt b/LayoutTests/fast/canvas/canvas-transforms-during-path-expected.txt
new file mode 100644 (file)
index 0000000..5314c6c
--- /dev/null
@@ -0,0 +1,14 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock (anonymous) at (0,0) size 784x100
+        RenderHTMLCanvas {CANVAS} at (0,0) size 100x100 [bgcolor=#008000]
+        RenderText {#text} at (0,0) size 0x0
+      RenderBlock {DIV} at (0,100) size 784x36
+        RenderText {#text} at (0,0) size 676x18
+          text run at (0,0) width 676: "This tests that transforms applied to a canvas, are correctly applied to the stroke path defined in the context. "
+        RenderBR {BR} at (676,14) size 0x0
+        RenderText {#text} at (0,18) size 525x18
+          text run at (0,18) width 525: "The above image should be a green square divided into quarters by two black lines."
diff --git a/LayoutTests/fast/canvas/canvas-transforms-during-path.html b/LayoutTests/fast/canvas/canvas-transforms-during-path.html
new file mode 100644 (file)
index 0000000..ef170f5
--- /dev/null
@@ -0,0 +1,22 @@
+<html>
+  <head>
+    <script type="text/javascript">
+      function main() {
+        var g = document.getElementById("c").getContext("2d");
+        g.beginPath();
+        g.moveTo(50,  0);
+        g.lineTo(50,100);
+        g.translate(50, 50);
+        g.rotate(0.5*3.1415);
+        g.translate(-50, -50);
+        g.moveTo(50,  0);
+        g.lineTo(50,100);
+        g.stroke();
+      }
+    </script>
+  </head>
+  <body onload="main();">
+    <canvas id="c" width="100" height="100" style="background: green"></canvas>
+    <div>This tests that transforms applied to a canvas, are correctly applied to the stroke path defined in the context. <br> The above image should be a green square divided into quarters by two black lines.</div>
+  </body>
+</html>
index e5f278944332fea2b0a204adc3baafaf8eb24808..74789dde55207b8c8f0bf0670113cc83c56d43f4 100644 (file)
@@ -1,3 +1,15 @@
+2006-10-26  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Anders.
+        Fixes <rdar://problem/4800518> -- needed to update existing
+        canvas path elements when transforms are performed on the
+        context.
+
+        * html/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::scale):
+        (WebCore::CanvasRenderingContext2D::rotate):
+        (WebCore::CanvasRenderingContext2D::translate):
+
 2006-10-26  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Darin.
index aca55d2e885169818647afdf3d88d84b727c51c4..0fe00399ad2564666dbd5b5428f0aa420354035c 100644 (file)
@@ -37,6 +37,7 @@
 #include "HTMLNames.h"
 #include "RenderHTMLCanvas.h"
 #include "cssparser.h"
+#include "AffineTransform.h"
 
 namespace WebCore {
 
@@ -276,6 +277,7 @@ void CanvasRenderingContext2D::scale(float sx, float sy)
     if (!c)
         return;
     c->scale(FloatSize(sx, sy));
+    state().m_path.transform(AffineTransform().scale(1.0/sx, 1.0/sy));
 }
 
 void CanvasRenderingContext2D::rotate(float angleInRadians)
@@ -284,6 +286,7 @@ void CanvasRenderingContext2D::rotate(float angleInRadians)
     if (!c)
         return;
     c->rotate(angleInRadians);
+    state().m_path.transform(AffineTransform().rotate(-angleInRadians/M_PI*180));
 }
 
 void CanvasRenderingContext2D::translate(float tx, float ty)
@@ -292,6 +295,7 @@ void CanvasRenderingContext2D::translate(float tx, float ty)
     if (!c)
         return;
     c->translate(tx, ty);
+    state().m_path.transform(AffineTransform().translate(-tx, -ty));
 }
 
 void CanvasRenderingContext2D::setStrokeColor(const String& color)