add unit support to svg rendering

This commit is contained in:
King Kévin 2015-08-28 12:20:11 +02:00
parent 16fa8a746c
commit 5777739cbb
1 changed files with 9 additions and 2 deletions

View File

@ -99,9 +99,16 @@ function json2svg(json) {
svg.setAttribute('xmlns',svgNS)
svg.setAttribute('version',1.1)
svg.setAttribute('xmlns:inkscape','http://www.inkscape.org/namespaces/inkscape')
// set unit
if (json.unit=="mil") { // mil units are not supported in SVG, convert to inch
svg.setAttribute('height',(json.height/1000)+'in')
svg.setAttribute('width',(json.width/1000)+'in')
} else {
svg.setAttribute('height',json.height+''+json.unit)
svg.setAttribute('width',json.width+''+json.unit)
}
svg.setAttribute('viewBox','0 0 '+json.width+' '+json.height)
// add info
svg.setAttribute('height',json.height)
svg.setAttribute('width',json.width)
var svg_title = document.createElementNS(svgNS,'title');
svg_title.textContent = json.name;
svg.appendChild(svg_title);