1 description("Series of tests to ensure correct behaviour of canvas.setTransform()");
2 var ctx = document.createElement('canvas').getContext('2d');
4 debug("Reset the CTM to the initial matrix");
7 ctx.setTransform(1, 0, 0, 1, 0, 0);
8 ctx.fillStyle = 'green';
9 ctx.fillRect(0, 0, 100, 100);
11 var imageData = ctx.getImageData(1, 1, 98, 98);
12 var imgdata = imageData.data;
13 shouldBe("imgdata[4]", "0");
14 shouldBe("imgdata[5]", "128");
15 shouldBe("imgdata[6]", "0");
17 debug("setTransform should not affect the current path");
19 ctx.rect(0,0,100,100);
21 ctx.setTransform(0.5, 0, 0, 0.5, 10, 10);
22 ctx.fillStyle = 'red';
23 ctx.fillRect(0, 0, 100, 100);
25 ctx.fillStyle = 'green';
26 ctx.fillRect(0, 0, 100, 100);
28 imageData = ctx.getImageData(1, 1, 98, 98);
29 imgdata = imageData.data;
30 shouldBe("imgdata[4]", "0");
31 shouldBe("imgdata[5]", "128");
32 shouldBe("imgdata[6]", "0");
34 debug("setTransform should not affect the CTM outside of save() and restore()");
36 ctx.fillStyle = 'green';
38 ctx.setTransform(0.5, 0, 0, 0.5, 0, 0);
39 ctx.fillStyle = 'red';
40 ctx.fillRect(0, 0, 100, 100);
42 ctx.fillRect(0, 0, 100, 100);
44 imageData = ctx.getImageData(1, 1, 98, 98);
45 imgdata = imageData.data;
46 shouldBe("imgdata[4]", "0");
47 shouldBe("imgdata[5]", "128");
48 shouldBe("imgdata[6]", "0");
51 debug("stop drawing on not-invertible CTM");
53 ctx.fillStyle = 'green';
54 ctx.fillRect(0, 0, 100, 100);
55 ctx.setTransform(0, 0, 0, 0, 0, 0);
56 ctx.fillStyle = 'red';
57 ctx.fillRect(0, 0, 100, 100);
59 imageData = ctx.getImageData(1, 1, 98, 98);
60 imgdata = imageData.data;
61 shouldBe("imgdata[4]", "0");
62 shouldBe("imgdata[5]", "128");
63 shouldBe("imgdata[6]", "0");
65 debug("setTransform with a not-invertible matrix should only stop the drawing up to the next restore()");
69 ctx.setTransform(0, 0, 0, 0, 0, 0);
70 ctx.fillStyle = 'red';
71 ctx.fillRect(0, 0, 100, 100);
73 ctx.fillStyle = 'blue';
74 ctx.fillRect(0, 0, 100, 100);
76 imageData = ctx.getImageData(1, 1, 98, 98);
77 imgdata = imageData.data;
78 shouldBe("imgdata[4]", "0");
79 shouldBe("imgdata[5]", "0");
80 shouldBe("imgdata[6]", "255");
82 debug("setTransform should set transform although CTM is not-invertible");
84 ctx.fillStyle = 'red';
85 ctx.fillRect(0, 0, 100, 100);
86 ctx.setTransform(0, 0, 0, 0, 0, 0);
87 ctx.fillStyle = 'green';
88 ctx.fillRect(0, 0, 100, 100);
89 ctx.setTransform(1, 0, 0, 1, 0, 0);
90 ctx.fillStyle = 'blue';
91 ctx.fillRect(0, 0, 100, 100);
93 imageData = ctx.getImageData(1, 1, 98, 98);
94 imgdata = imageData.data;
95 shouldBe("imgdata[4]", "0");
96 shouldBe("imgdata[5]", "0");
97 shouldBe("imgdata[6]", "255");