2 <title>Canvas test:
2d.line.width.transformed
</title>
3 <!-- Testing: Line stroke widths are affected by scale transformations -->
4 <script src=
"/MochiKit/MochiKit.js"></script>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
8 <canvas id=
"c" width=
"100" height=
"50"><p class=
"fallback">FAIL (fallback content)
</p></canvas>
10 function isPixel(ctx
, x
,y
, r
,g
,b
,a
, pos
, colour
, d
) {
11 var pixel
= ctx
.getImageData(x
, y
, 1, 1);
12 var pr
= pixel
.data
[0],
16 ok(r
-d
<= pr
&& pr
<= r
+d
&&
17 g
-d
<= pg
&& pg
<= g
+d
&&
18 b
-d
<= pb
&& pb
<= b
+d
&&
19 a
-d
<= pa
&& pa
<= a
+d
,
20 "pixel "+pos
+" is "+pr
+","+pg
+","+pb
+","+pa
+"; expected "+colour
+" +/- "+d
);
23 SimpleTest
.waitForExplicitFinish();
24 MochiKit
.DOM
.addLoadEvent(function () {
26 var canvas
= document
.getElementById('c');
27 var ctx
= canvas
.getContext('2d');
29 ctx
.fillStyle
= '#0f0';
30 ctx
.fillRect(0, 0, 100, 50);
33 // Draw a green line over a red box, to check the line is not too small
34 ctx
.fillStyle
= '#f00';
35 ctx
.strokeStyle
= '#0f0';
36 ctx
.fillRect(15, 15, 20, 20);
45 // Draw a green box over a red line, to check the line is not too large
46 ctx
.fillStyle
= '#0f0';
47 ctx
.strokeStyle
= '#f00';
55 ctx
.fillRect(65, 15, 20, 20);
57 isPixel(ctx
, 14,25, 0,255,0,255, "14,25", "0,255,0,255", 0);
58 isPixel(ctx
, 15,25, 0,255,0,255, "15,25", "0,255,0,255", 0);
59 isPixel(ctx
, 16,25, 0,255,0,255, "16,25", "0,255,0,255", 0);
60 isPixel(ctx
, 25,25, 0,255,0,255, "25,25", "0,255,0,255", 0);
61 isPixel(ctx
, 34,25, 0,255,0,255, "34,25", "0,255,0,255", 0);
62 isPixel(ctx
, 35,25, 0,255,0,255, "35,25", "0,255,0,255", 0);
63 isPixel(ctx
, 36,25, 0,255,0,255, "36,25", "0,255,0,255", 0);
65 isPixel(ctx
, 64,25, 0,255,0,255, "64,25", "0,255,0,255", 0);
66 isPixel(ctx
, 65,25, 0,255,0,255, "65,25", "0,255,0,255", 0);
67 isPixel(ctx
, 66,25, 0,255,0,255, "66,25", "0,255,0,255", 0);
68 isPixel(ctx
, 75,25, 0,255,0,255, "75,25", "0,255,0,255", 0);
69 isPixel(ctx
, 84,25, 0,255,0,255, "84,25", "0,255,0,255", 0);
70 isPixel(ctx
, 85,25, 0,255,0,255, "85,25", "0,255,0,255", 0);
71 isPixel(ctx
, 86,25, 0,255,0,255, "86,25", "0,255,0,255", 0);