1 description("This test checks resetTransform in canvas v5");
3 var canvas = document.createElement('canvas');
4 document.body.appendChild(canvas);
5 canvas.setAttribute('width', '100');
6 canvas.setAttribute('height', '100');
7 var ctx = canvas.getContext('2d');
9 debug("resetTransform should reset other transforms.");
13 ctx.fillStyle = 'green';
14 ctx.fillRect(0, 0, 100, 100);
17 var imageData = ctx.getImageData(98, 98, 1, 1);
18 var imgdata = imageData.data;
19 shouldBe("imgdata[0]", "0");
20 shouldBe("imgdata[1]", "128");
21 shouldBe("imgdata[2]", "0");
23 debug("resetTransform should not affect CTM outside of save() and restore().");
28 ctx.fillStyle = 'green';
29 ctx.fillRect(0, 0, 100, 100);
31 ctx.fillStyle = 'red';
32 ctx.fillRect(0, 0, 100, 100);
35 imageData = ctx.getImageData(98, 98, 1, 1);
36 imgdata = imageData.data;
37 shouldBe("imgdata[0]", "0");
38 shouldBe("imgdata[1]", "128");
39 shouldBe("imgdata[2]", "0");
41 imageData = ctx.getImageData(48, 48, 1, 1);
42 imgdata = imageData.data;
43 shouldBe("imgdata[0]", "255");
44 shouldBe("imgdata[1]", "0");
45 shouldBe("imgdata[2]", "0");
47 debug("resetTransform should restore the path transform to identity.");
48 /* This should draw a green rectangle on on top of a red one. The red should not be visible. */
55 ctx.fillStyle = 'red';
57 ctx.translate(200, 0);
59 ctx.fillStyle = 'green';
63 imageData = ctx.getImageData(50, 50, 1, 1);
64 imgdata = imageData.data;
65 shouldBe("imgdata[0]", "0");
66 shouldBe("imgdata[1]", "128");
67 shouldBe("imgdata[2]", "0");
69 debug("resetTransform should resolve the non-invertible CTM state.");
71 ctx.fillStyle = 'red';
72 ctx.fillRect(0, 0, 100, 100);
80 ctx.fillStyle = 'green';
84 imageData = ctx.getImageData(98, 98, 1, 1);
85 imgdata = imageData.data;
86 shouldBe("imgdata[0]", "0");
87 shouldBe("imgdata[1]", "128");
88 shouldBe("imgdata[2]", "0");
90 debug("The path object should not be updated on the non-invertible CTM state.");
91 debug("resetTransform should restore the path object just before CTM became non-invertible.");
93 ctx.fillStyle = 'red';
94 ctx.fillRect(0, 0, 100, 100);
100 ctx.lineTo(100, 100);
101 ctx.resetTransform();
103 ctx.fillStyle = 'green';
107 imageData = ctx.getImageData(98, 98, 1, 1);
108 imgdata = imageData.data;
109 shouldBe("imgdata[0]", "255");
110 shouldBe("imgdata[1]", "0");
111 shouldBe("imgdata[2]", "0");
113 imageData = ctx.getImageData(98, 48, 1, 1);
114 imgdata = imageData.data;
115 shouldBe("imgdata[0]", "0");
116 shouldBe("imgdata[1]", "128");
117 shouldBe("imgdata[2]", "0");