1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="../../resources/js-test.js"></script>
<style>
canvas {
border: 1px solid #000;
margin: 2px;
}
</style>
<script>
var img;
var imgdata;
function imageLoaded() {
var NUM_IMAGE = 16;
for (var i = 0; i < NUM_IMAGE; i++) {
var canvases = document.getElementById('canvases')
var canvas = document.createElement('canvas');
canvas.width = 9;
canvas.height = 9;
var ctx = canvas.getContext('2d');
var pattern = ctx.createPattern(img, 'no-repeat');
ctx.fillStyle = pattern;
ctx.translate(img.width / 2, img.height / 2);
var angle = 2 * Math.PI * i / NUM_IMAGE;
ctx.rotate(angle);
ctx.translate(- img.width / 2, - img.height / 2);
ctx.fillRect(0, 0, img.width, img.height);
var div = document.createElement('div');
div.appendChild(canvas);
canvases.appendChild(div);
var imageData = ctx.getImageData(4, 4, 1, 1);
imgdata = imageData.data;
shouldBe("imgdata[0]", "0");
shouldBe("imgdata[1]", "255");
shouldBe("imgdata[2]", "0");
}
if (window.testRunner) {
testRunner.notifyDone();
}
}
function runTests() {
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
var patternCanvas = document.createElement('canvas');
patternCanvas.width = 9;
patternCanvas.height = 9;
var patternCtx = patternCanvas.getContext('2d');
patternCtx.fillStyle = '#0F0';
patternCtx.fillRect(3, 3, 3, 3);
img = new Image();
img.onload = imageLoaded;
img.src = patternCanvas.toDataURL();
}
</script>
</head>
<body onload="runTests();">
Visual result below is for debugging purposes only (test uses text baseline only). You should see sixteen canvases with a green dot (rotated square) in the center.
<div id="canvases"></div>
</pre>
</body>
</html>
|