[英]Setting default units in svg (Python svgwrite)
I'm generating SVG drawings using python's svgwrite. 我正在使用python的svgwrite生成SVG图形。 Every time I want to draw something, I find myself doing this ugly awkward thing:
每当我想要画一些东西时,我发现自己做了这个丑陋的尴尬事情:
line = drawing.line(start = "%dmm" % start, end = "%dmm" % end)
I wish I could just do: 我希望我能做到:
line = drawing.line(start = start, end = end)
Is there a way to set the default units to 'mm' for the entire svg drawing? 有没有办法将整个svg绘图的默认单位设置为'mm'?
A possible way is to set the viewBox attribute along with the document sizing, 一种可能的方法是将viewBox属性与文档大小调整一起设置,
dwg = svgwrite.Drawing('myDrawing.svg', size=('170mm', '130mm'), viewBox=('0 0 170 130'))
dwg.add(dwg.line(start=(30, 30), end=(50,50)))
dwg.save()
produces for me, 为我生产,
<?xml version="1.0" encoding="utf-8" ?>
<svg baseProfile="full" height="130mm" version="1.1" viewBox="0 0 170 130" width="170mm"
xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"><defs /><line x1="30" x2="50" y1="30" y2="50" /> </svg>
I just found that you can do this: 我刚发现你可以这样做:
from svgwrite import cm, mm
dwg = svgwrite.Drawing('my_drawing.svg', height='10cm', width='10cm')
dwg.add(dwg.line((0*cm, 0*cm), (10*cm, 10*cm))
dwg.save()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.