OLD | NEW |
1 <!doctype html> | 1 <script src="../../resources/testharness.js"></script> |
2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | 3 <body> |
7 <script src="script-tests/canvas-fill-rule.js"></script> | 4 <script> |
| 5 |
| 6 var tmpimg = document.createElement('canvas'); |
| 7 tmpimg.width = 200; |
| 8 tmpimg.height = 200; |
| 9 ctx = tmpimg.getContext('2d'); |
| 10 |
| 11 // Create the image for blending test with images. |
| 12 var img = document.createElement('canvas'); |
| 13 img.width = 100; |
| 14 img.height = 100; |
| 15 var imgCtx = img.getContext('2d'); |
| 16 |
| 17 function checkResult(expectedColors, sigma) { |
| 18 var pixel = ctx.getImageData(50, 50, 1, 1).data; |
| 19 for (var i = 0; i < 4; i++) |
| 20 assert_approx_equals(pixel[i], expectedColors[i], sigma); |
| 21 } |
| 22 |
| 23 test(function(t) { |
| 24 // Testing default fill |
| 25 ctx.fillStyle = 'rgb(255,0,0)'; |
| 26 ctx.beginPath(); |
| 27 ctx.fillRect(0, 0, 100, 100); |
| 28 ctx.fillStyle = 'rgb(0,255,0)'; |
| 29 ctx.beginPath(); |
| 30 ctx.rect(0, 0, 100, 100); |
| 31 ctx.rect(25, 25, 50, 50); |
| 32 ctx.fill(); |
| 33 checkResult([0, 255, 0, 255], 5); |
| 34 |
| 35 // Testing nonzero fill |
| 36 ctx.fillStyle = 'rgb(255,0,0)'; |
| 37 ctx.beginPath(); |
| 38 ctx.fillRect(0, 0, 100, 100); |
| 39 ctx.fillStyle = 'rgb(0,255,0)'; |
| 40 ctx.beginPath(); |
| 41 ctx.rect(0, 0, 100, 100); |
| 42 ctx.rect(25, 25, 50, 50); |
| 43 ctx.fill('nonzero'); |
| 44 checkResult([0, 255, 0, 255], 5); |
| 45 |
| 46 // Testing evenodd fill |
| 47 ctx.fillStyle = 'rgb(255,0,0)'; |
| 48 ctx.beginPath(); |
| 49 ctx.fillRect(0, 0, 100, 100); |
| 50 ctx.fillStyle = 'rgb(0,255,0)'; |
| 51 ctx.beginPath(); |
| 52 ctx.rect(0, 0, 100, 100); |
| 53 ctx.rect(25, 25, 50, 50); |
| 54 ctx.fill('evenodd'); |
| 55 checkResult([255, 0, 0, 255], 5); |
| 56 }, "Series of tests to ensure correct results of the winding rule."); |
| 57 </script> |
8 </body> | 58 </body> |
OLD | NEW |