| OLD | NEW |
| (Empty) |
| 1 description("Ensure correct behavior of canvas with path fill + shadow after sca
ling. 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', '1000'); | |
| 31 canvas.setAttribute('height', '1000'); | |
| 32 var ctx = canvas.getContext('2d'); | |
| 33 | |
| 34 ctx.scale(2, 2); | |
| 35 ctx.shadowOffsetX = 100; | |
| 36 ctx.shadowOffsetY = 100; | |
| 37 ctx.fillStyle = 'rgba(0, 0, 255, 1)'; | |
| 38 | |
| 39 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)'; | |
| 40 ctx.beginPath(); | |
| 41 ctx.moveTo(50, 50); | |
| 42 ctx.lineTo(100, 50); | |
| 43 ctx.lineTo(100, 100); | |
| 44 ctx.lineTo(50, 100); | |
| 45 ctx.fill(); | |
| 46 | |
| 47 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)'; | |
| 48 ctx.beginPath(); | |
| 49 ctx.moveTo(50, 150); | |
| 50 ctx.lineTo(100, 150); | |
| 51 ctx.lineTo(100, 200); | |
| 52 ctx.lineTo(50, 200); | |
| 53 ctx.fill(); | |
| 54 | |
| 55 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)'; | |
| 56 ctx.shadowBlur = 10; | |
| 57 ctx.beginPath(); | |
| 58 ctx.moveTo(150, 50); | |
| 59 ctx.lineTo(200, 50); | |
| 60 ctx.lineTo(200, 100); | |
| 61 ctx.lineTo(150, 100); | |
| 62 ctx.fill(); | |
| 63 | |
| 64 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)'; | |
| 65 ctx.beginPath(); | |
| 66 ctx.moveTo(150, 150); | |
| 67 ctx.lineTo(200, 150); | |
| 68 ctx.lineTo(200, 200); | |
| 69 ctx.lineTo(150, 200); | |
| 70 ctx.fill(); | |
| 71 | |
| 72 var d; // imageData.data | |
| 73 | |
| 74 // Verify solid shadow. | |
| 75 d = ctx.getImageData(201, 205, 1, 1).data; | |
| 76 shouldBe('d[0]', '255'); | |
| 77 shouldBe('d[1]', '0'); | |
| 78 shouldBe('d[2]', '0'); | |
| 79 shouldBe('d[3]', '255'); | |
| 80 | |
| 81 d = ctx.getImageData(298, 295, 1, 1).data; | |
| 82 shouldBe('d[0]', '255'); | |
| 83 shouldBe('d[1]', '0'); | |
| 84 shouldBe('d[2]', '0'); | |
| 85 shouldBe('d[3]', '255'); | |
| 86 | |
| 87 d = ctx.getImageData(201, 298, 1, 1).data; | |
| 88 shouldBe('d[0]', '255'); | |
| 89 shouldBe('d[1]', '0'); | |
| 90 shouldBe('d[2]', '0'); | |
| 91 shouldBe('d[3]', '255'); | |
| 92 | |
| 93 // Verify solid alpha shadow. | |
| 94 d = ctx.getImageData(201, 405, 1, 1).data; | |
| 95 shouldBe('d[0]', '255'); | |
| 96 shouldBe('d[1]', '0'); | |
| 97 shouldBe('d[2]', '0'); | |
| 98 shouldBeAround('d[3]', '76'); | |
| 99 | |
| 100 d = ctx.getImageData(298, 405, 1, 1).data; | |
| 101 shouldBe('d[0]', '255'); | |
| 102 shouldBe('d[1]', '0'); | |
| 103 shouldBe('d[2]', '0'); | |
| 104 shouldBeAround('d[3]', '76'); | |
| 105 | |
| 106 d = ctx.getImageData(205, 498, 1, 1).data; | |
| 107 shouldBe('d[0]', '255'); | |
| 108 shouldBe('d[1]', '0'); | |
| 109 shouldBe('d[2]', '0'); | |
| 110 shouldBeAround('d[3]', '76'); | |
| 111 | |
| 112 // Verify blurry shadow. | |
| 113 d = ctx.getImageData(398, 205, 1, 1).data; | |
| 114 shouldBe('d[0]', '255'); | |
| 115 shouldBe('d[1]', '0'); | |
| 116 shouldBe('d[2]', '0'); | |
| 117 shouldBeAround('d[3]', '83'); | |
| 118 | |
| 119 d = ctx.getImageData(501, 205, 1, 1).data; | |
| 120 shouldBe('d[0]', '255'); | |
| 121 shouldBe('d[1]', '0'); | |
| 122 shouldBe('d[2]', '0'); | |
| 123 shouldBeAround('d[3]', '83'); | |
| 124 | |
| 125 d = ctx.getImageData(500, 300, 1, 1).data; | |
| 126 shouldBe('d[0]', '255'); | |
| 127 shouldBe('d[1]', '0'); | |
| 128 shouldBe('d[2]', '0'); | |
| 129 shouldBeAround('d[3]', '53'); | |
| 130 | |
| 131 // Verify blurry alpha shadow. | |
| 132 d = ctx.getImageData(398, 405, 1, 1).data; | |
| 133 shouldBe('d[0]', '255'); | |
| 134 shouldBe('d[1]', '0'); | |
| 135 shouldBe('d[2]', '0'); | |
| 136 shouldBeAround('d[3]', '24'); | |
| 137 | |
| 138 d = ctx.getImageData(405, 501, 1, 1).data; | |
| 139 shouldBe('d[0]', '255'); | |
| 140 shouldBe('d[1]', '0'); | |
| 141 shouldBe('d[2]', '0'); | |
| 142 shouldBeAround('d[3]', '24'); | |
| 143 | |
| 144 d = ctx.getImageData(405, 501, 1, 1).data; | |
| 145 shouldBe('d[0]', '255'); | |
| 146 shouldBe('d[1]', '0'); | |
| 147 shouldBe('d[2]', '0'); | |
| 148 shouldBeAround('d[3]', '24'); | |
| OLD | NEW |