printrun-src/testfiles/grid.svg

changeset 15
0bbb006204fc
equal deleted inserted replaced
14:51bf56ba3c10 15:0bbb006204fc
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <svg xmlns="http://www.w3.org/2000/svg" onload='init()' width="150mm" height="150mm" version="1.1">
3 <script type='text/ecmascript'>
4 <![CDATA[
5 function getParameterByName(name)
6 {
7 name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
8 var regexS = "[\\?&]" + name + "=([^&#]*)";
9 var regex = new RegExp(regexS);
10 var results = regex.exec(window.location.search);
11 if(results == null)
12 return "";
13 else
14 return decodeURIComponent(results[1].replace(/\+/g, " "));
15 }
16
17 function init() {
18 var width = getParameterByName('width') || 150;
19 var height = getParameterByName('height') || 150;
20 var gridheight = getParameterByName('gridheight') || 10;
21 var gridwidth = getParameterByName('gridwidth') || 10;
22 var lineheight = getParameterByName('lineheight') || 0.5;
23 var linewidth = getParameterByName('linewidth') || 0.5;
24
25 var lineblockheight = (gridheight/2)-lineheight;
26 var lineblockwidth = (gridwidth/2)-linewidth;
27
28 console.log(lineblockheight,lineblockwidth)
29
30
31 document.getElementsByTagName('svg')[0].setAttribute('width',width+'mm');
32 document.getElementsByTagName('svg')[0].setAttribute('height',height+'mm');
33
34
35 document.getElementsByTagName('pattern')[0].setAttribute('height',gridheight+'mm');
36 document.getElementsByTagName('pattern')[0].setAttribute('width',gridwidth+'mm');
37
38 document.getElementsByClassName('background')[0].setAttribute('height',gridheight+'mm');
39 document.getElementsByClassName('background')[0].setAttribute('width',gridwidth+'mm');
40
41 var blocks = document.getElementsByClassName('block');
42 for (var i in blocks){
43 if (blocks[i] instanceof SVGRectElement){
44 blocks[i].setAttribute('height', lineblockheight+'mm');
45 blocks[i].setAttribute('width', lineblockwidth+'mm');
46 }
47 }
48
49 document.getElementsByClassName('topright')[0].setAttribute('x',lineblockwidth+'mm');
50 document.getElementsByClassName('bottomleft')[0].setAttribute('y',lineblockheight+'mm');
51 document.getElementsByClassName('bottomright')[0].setAttribute('x',lineblockwidth+'mm');
52 document.getElementsByClassName('bottomright')[0].setAttribute('y',lineblockheight+'mm');
53
54 }
55 ]]>
56 </script>
57
58 <defs>
59 <pattern id="grd" patternUnits="userSpaceOnUse" width="10mm" height="10mm">
60 <rect class="background" width="10mm" height="10mm" fill="red"/>
61 <rect class="block topleft" width="4.9mm" height="4.9mm"/>
62 <rect class="block topright" width="4.9mm" height="4.9mm" x="4.9mm"/>
63 <rect class="block bottomleft" width="4.9mm" height="4.9mm" y="4.9mm"/>
64 <rect class="block bottomright" width="4.9mm" height="4.9mm" x="4.9mm" y="4.9mm"/>
65 </pattern>
66 </defs>
67 <rect height="100%" width="100%" fill="url(#grd)"/>
68 </svg>

mercurial