| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Test SVG Filters</title> |
| 5 | <script> |
| 6 | var dojoConfig = { |
| 7 | async: true, |
| 8 | gfxRenderer: 'svg' |
| 9 | }; |
| 10 | </script> |
| 11 | <script type="text/javascript" src="../../../dojo/dojo.js"></script> |
| 12 | <script type="text/javascript"> |
| 13 | require([ |
| 14 | 'dojox/gfx', |
| 15 | 'dojox/gfx/svg_mask', |
| 16 | 'dojo/domReady!' |
| 17 | ], function(gfx){ |
| 18 | |
| 19 | var surfaceShape = { |
| 20 | width: 600, |
| 21 | height: 600 |
| 22 | }, |
| 23 | surface = gfx.createSurface('surface', surfaceShape.width, surfaceShape.height); |
| 24 | |
| 25 | var group = surface.createGroup(); |
| 26 | group.createRect(surfaceShape).setFill('blue'); |
| 27 | |
| 28 | // Create mask with the same dimensions as the group |
| 29 | var maskShape = { |
| 30 | width: 1, |
| 31 | height: 1, |
| 32 | maskContentUnits: 'objectBoundingBox' |
| 33 | }; |
| 34 | var mask = surface.createMask(maskShape); |
| 35 | |
| 36 | // By default, the mask is applied as if initialized to black (i.e., #000) |
| 37 | // and will completely mask out objects painted through it. |
| 38 | // Create a white (i.e., #fff) rectangle in the dimensions of the mask |
| 39 | // so no painting is masked out by default. |
| 40 | mask.createRect({ |
| 41 | width: 0.5, |
| 42 | height: 1 |
| 43 | }).setFill('#fff'); |
| 44 | |
| 45 | var margin = 0.1; |
| 46 | mask.createRect({ |
| 47 | x: margin, |
| 48 | y: margin, |
| 49 | width: .5 - margin * 2, |
| 50 | height: 1 - margin * 2 |
| 51 | }).setFill('black'); |
| 52 | |
| 53 | group.setMask(mask); |
| 54 | |
| 55 | var textMargin = 60; |
| 56 | var text = surface.createText({ |
| 57 | x: surfaceShape.width / 2 + textMargin, |
| 58 | y: textMargin, |
| 59 | text: 'Masked Text' |
| 60 | }) |
| 61 | .setFill('red') |
| 62 | .setStroke('purple') |
| 63 | .setFont({ |
| 64 | size: '40px' |
| 65 | }); |
| 66 | var maskForText = surface.createMask(maskShape); |
| 67 | maskForText.createRect({ |
| 68 | width: 1, |
| 69 | height: 1 |
| 70 | }) |
| 71 | .setFill({ |
| 72 | type: 'linear', |
| 73 | x2: 1, |
| 74 | y2: 0, |
| 75 | colors: [ |
| 76 | { offset: 0, color: '#111' }, |
| 77 | { offset: 1, color: '#ddd' } |
| 78 | ] |
| 79 | }); |
| 80 | text.setMask(maskForText); |
| 81 | |
| 82 | var image = surface.createImage({ |
| 83 | x: 300, |
| 84 | y: 100, |
| 85 | width: 300, |
| 86 | height: 300, |
| 87 | src: 'images/maps.png' |
| 88 | }); |
| 89 | var textMask = surface.createMask({}); |
| 90 | textMask.createText({ |
| 91 | x: 375, |
| 92 | y: 250, |
| 93 | text: 'Text Mask' |
| 94 | }) |
| 95 | .setFill('white') |
| 96 | .setFont({ |
| 97 | size: "40px" |
| 98 | }); |
| 99 | image.setMask(textMask); |
| 100 | }); |
| 101 | </script> |
| 102 | </head> |
| 103 | <body> |
| 104 | <div id="surface" style="width: 600px; height: 600px; background: #FFFFE0"></div> |
| 105 | </body> |
| 106 | </html> |