29668110211118a982e2d85af9e499076d4cf7ff
[profile/ivi/qtdeclarative.git] / tests / auto / quick / qquickcanvasitem / data / tst_svgpath.qml
1 import QtQuick 2.0
2
3 CanvasTestCase {
4    id:testCase
5    name: "svgpath"
6    function init_data() { return testData("2d"); }
7    function test_svgpath(row) {
8        var canvas = createCanvasObject(row);
9        var ctx = canvas.getContext('2d');
10        var svgs = [
11                    // Absolute coordinates, explicit commands.
12                     "M50 0 V50 H0 Q0 25 25 25 T50 0 C25 0 50 50 25 50 S25 0 0 0 Z",
13                    // Absolute coordinates, implicit commands.
14                     "M50 0 50 50 0 50 Q0 25 25 25 Q50 25 50 0 C25 0 50 50 25 50 C0 50 25 0 0 0 Z",
15                    // Relative coordinates, explicit commands.
16                     "m50 0 v50 h-50 q0 -25 25 -25 t25 -25 c-25 0 0 50 -25 50 s0 -50 -25 -50 z",
17                    // Relative coordinates, implicit commands.
18                     "m50 0 0 50 -50 0 q0 -25 25 -25 25 0 25 -25 c-25 0 0 50 -25 50 -25 0 0 -50 -25 -50 z",
19                    // Absolute coordinates, explicit commands, minimal whitespace.
20                     "m50 0v50h-50q0-25 25-25t25-25c-25 0 0 50-25 50s0-50-25-50z",
21                    // Absolute coordinates, explicit commands, extra whitespace.
22                     " M  50  0  V  50  H  0  Q 0  25   25 25 T  50 0 C 25   0 50  50 25 50 S  25 0 0  0 Z"
23                   ];
24
25        var blues = [
26                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27                     1, 1, 0, 0, 0, 0, 0, 0, 0, 1,
28                     1, 1, 1, 0, 0, 0, 0, 0, 1, 1,
29                     1, 1, 1, 0, 0, 0, 0, 0, 1, 1,
30                     1, 1, 1, 0, 0, 0, 0, 0, 1, 0,
31                     1, 1, 1, 0, 0, 1, 1, 1, 0, 0,
32                     1, 1, 0, 1, 1, 1, 1, 1, 0, 0,
33                     1, 0, 0, 1, 1, 1, 1, 1, 0, 0,
34                     1, 0, 0, 1, 1, 1, 1, 1, 0, 0,
35                     1, 0, 0, 0, 1, 1, 1, 0, 0, 0
36                    ];
37
38        ctx.fillRule = Qt.OddEvenFill;
39        for (var i = 0; i < svgs.length; i++) {
40            ctx.fillStyle = "blue";
41            ctx.fillRect(0, 0, 50, 50);
42            ctx.fillStyle = "red";
43            ctx.path = svgs[i];
44            ctx.fill();
45            var x, y;
46            for (x=0; x < 10; x++) {
47                for (y=0; y < 10; y++) {
48                    if (blues[y * 10 + x]) {
49                        comparePixel(ctx, x * 5, y * 5, 0, 0, 255, 255);
50                    } else {
51                        comparePixel(ctx, x * 5, y * 5, 255, 0, 0, 255);
52                    }
53                }
54            }
55        }
56    }
57 }