content/canvas/test/test_2d.fillText.gradient.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/test_2d.fillText.gradient.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<title>Canvas test: 2d.composite.canvas.xor</title>
     1.6 +<script src="/tests/SimpleTest/SimpleTest.js"></script>
     1.7 +<link rel="stylesheet" href="/tests/SimpleTest/test.css">
     1.8 +<body>
     1.9 +<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
    1.10 +<script>
    1.11 +function isPixel(ctx, x,y, r,g,b,a, pos, colour, d) {
    1.12 +    var pixel = ctx.getImageData(x, y, 1, 1);
    1.13 +    var pr = pixel.data[0],
    1.14 +        pg = pixel.data[1],
    1.15 +        pb = pixel.data[2],
    1.16 +        pa = pixel.data[3];
    1.17 +    ok(r-d <= pr && pr <= r+d &&
    1.18 +       g-d <= pg && pg <= g+d &&
    1.19 +       b-d <= pb && pb <= b+d &&
    1.20 +       a-d <= pa && pa <= a+d,
    1.21 +       "pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d);
    1.22 +}
    1.23 +
    1.24 +SimpleTest.waitForExplicitFinish();
    1.25 +addLoadEvent(function () {
    1.26 +
    1.27 +var canvas = document.getElementById('c');
    1.28 +var ctx = canvas.getContext('2d');
    1.29 +                                var text                = "I";
    1.30 +                                var colorTop    = 'rgba(255,0,0,1)';
    1.31 +                                var colorBottom = 'rgba(0,255,0,1)';
    1.32 +                                var inset               = 10;
    1.33 +                                var grad                = ctx.createLinearGradient(inset, inset, inset, inset + 30);
    1.34 +                                
    1.35 +                                // add color stops
    1.36 +                                grad.addColorStop(0, colorTop);
    1.37 +                                grad.addColorStop(1, colorBottom);
    1.38 +                                
    1.39 +                                ctx.fillStyle               = grad;
    1.40 +                                ctx.textBaseline    = 'top';
    1.41 +                                ctx.font                    = '110px sans-serif'
    1.42 +                                ctx.fillText(text, -10, -20);
    1.43 +                                ctx.fillText(text, -8, -20);
    1.44 +                                ctx.fillText(text, -6, -20);
    1.45 +                                ctx.fillText(text, -4, -20);
    1.46 +                                ctx.fillText(text, -2, -20);
    1.47 +                                ctx.fillText(text, 0, -20);
    1.48 +                                ctx.fillText(text, 2, -20);
    1.49 +                                ctx.fillText(text, 4, -20);
    1.50 +                                ctx.fillText(text, 6, -20);
    1.51 +
    1.52 +                                isPixel(ctx, 15,0, 255,0,0,255, "15,0", "255,0,0,255", 5);
    1.53 +                                isPixel(ctx, 15,49, 0,255,0,255, "15,49", "0,255,0,255", 5);
    1.54 +SimpleTest.finish();
    1.55 +
    1.56 +});
    1.57 +</script>
    1.58 +

mercurial