OLD | NEW |
| (Empty) |
1 description("Ensure correct behavior of canvas with fillRect+shadow after transl
ation+rotation+scaling. A blue and red checkered pattern should be displayed."); | |
2 | |
3 function print(message, color) | |
4 { | |
5 var paragraph = document.createElement("div"); | |
6 paragraph.appendChild(document.createTextNode(message)); | |
7 paragraph.style.fontFamily = "monospace"; | |
8 if (color) | |
9 paragraph.style.color = color; | |
10 document.getElementById("console").appendChild(paragraph); | |
11 } | |
12 | |
13 function shouldBeAround(a, b) | |
14 { | |
15 var evalA; | |
16 try { | |
17 evalA = eval(a); | |
18 } catch(e) { | |
19 evalA = e; | |
20 } | |
21 | |
22 if (Math.abs(evalA - b) < 20) | |
23 print("PASS " + a + " is around " + b , "green") | |
24 else | |
25 print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")",
"red"); | |
26 } | |
27 | |
28 var canvas = document.createElement('canvas'); | |
29 document.body.appendChild(canvas); | |
30 canvas.setAttribute('width', '600'); | |
31 canvas.setAttribute('height', '600'); | |
32 var ctx = canvas.getContext('2d'); | |
33 | |
34 ctx.fillStyle = 'rgba(0, 0, 255, 1.0)'; | |
35 ctx.shadowOffsetX = 100; | |
36 ctx.shadowOffsetY = 100; | |
37 | |
38 ctx.translate(-100, -100); | |
39 ctx.rotate(Math.PI/2); | |
40 ctx.scale(2, 2); | |
41 | |
42 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)'; | |
43 ctx.fillRect(100, -150, 50, 50); | |
44 | |
45 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)'; | |
46 ctx.fillRect(200, -150, 50, 50); | |
47 | |
48 ctx.shadowBlur = 5; | |
49 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)'; | |
50 ctx.fillRect(100, -250, 50, 50); | |
51 | |
52 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)'; | |
53 ctx.fillRect(200, -250, 50, 50); | |
54 | |
55 var d; // imageData.data | |
56 | |
57 // Verify solid shadow. | |
58 d = ctx.getImageData(201, 205, 1, 1).data; | |
59 shouldBe('d[0]', '255'); | |
60 shouldBe('d[1]', '0'); | |
61 shouldBe('d[2]', '0'); | |
62 shouldBe('d[3]', '255'); | |
63 | |
64 d = ctx.getImageData(298, 298, 1, 1).data; | |
65 shouldBe('d[0]', '255'); | |
66 shouldBe('d[1]', '0'); | |
67 shouldBe('d[2]', '0'); | |
68 shouldBe('d[3]', '255'); | |
69 | |
70 d = ctx.getImageData(201, 298, 1, 1).data; | |
71 shouldBe('d[0]', '255'); | |
72 shouldBe('d[1]', '0'); | |
73 shouldBe('d[2]', '0'); | |
74 shouldBe('d[3]', '255'); | |
75 | |
76 // Verify solid alpha shadow. | |
77 d = ctx.getImageData(201, 401, 1, 1).data; | |
78 shouldBe('d[0]', '255'); | |
79 shouldBe('d[1]', '0'); | |
80 shouldBe('d[2]', '0'); | |
81 shouldBeAround('d[3]', '127'); | |
82 | |
83 d = ctx.getImageData(298, 450, 1, 1).data; | |
84 shouldBe('d[0]', '255'); | |
85 shouldBe('d[1]', '0'); | |
86 shouldBe('d[2]', '0'); | |
87 shouldBeAround('d[3]', '127'); | |
88 | |
89 d = ctx.getImageData(205, 498, 1, 1).data; | |
90 shouldBe('d[0]', '255'); | |
91 shouldBe('d[1]', '0'); | |
92 shouldBe('d[2]', '0'); | |
93 shouldBeAround('d[3]', '127'); | |
94 | |
95 // Verify blurry shadow. | |
96 d = ctx.getImageData(399, 205, 1, 1).data; | |
97 shouldBe('d[0]', '255'); | |
98 shouldBe('d[1]', '0'); | |
99 shouldBe('d[2]', '0'); | |
100 shouldBeAround('d[3]', '106'); | |
101 | |
102 d = ctx.getImageData(500, 205, 1, 1).data; | |
103 shouldBe('d[0]', '255'); | |
104 shouldBe('d[1]', '0'); | |
105 shouldBe('d[2]', '0'); | |
106 shouldBeAround('d[3]', '106'); | |
107 | |
108 d = ctx.getImageData(499, 299, 1, 1).data; | |
109 shouldBe('d[0]', '255'); | |
110 shouldBe('d[1]', '0'); | |
111 shouldBe('d[2]', '0'); | |
112 shouldBeAround('d[3]', '83'); | |
113 | |
114 // Verify blurry alpha shadow. | |
115 d = ctx.getImageData(398, 405, 1, 1).data; | |
116 shouldBe('d[0]', '255'); | |
117 shouldBe('d[1]', '0'); | |
118 shouldBe('d[2]', '0'); | |
119 shouldBeAround('d[3]', '36'); | |
120 | |
121 d = ctx.getImageData(405, 501, 1, 1).data; | |
122 shouldBe('d[0]', '255'); | |
123 shouldBe('d[1]', '0'); | |
124 shouldBe('d[2]', '0'); | |
125 shouldBeAround('d[3]', '36'); | |
126 | |
127 d = ctx.getImageData(405, 501, 1, 1).data; | |
128 shouldBe('d[0]', '255'); | |
129 shouldBe('d[1]', '0'); | |
130 shouldBe('d[2]', '0'); | |
131 shouldBeAround('d[3]', '36'); | |
OLD | NEW |