drawsvg
drawsvg copied to clipboard
Change viewport (new setViewPort method)
New to git, so I'm sure there's an easier way to do this, but here's the code (from drawing.py, 51):
def setRenderSize(self, w=None, h=None):
self.renderWidth = w
self.renderHeight = h
if origin == 'center':
self.viewBox = (-width/2, -height/2, width, height)
return
Haven't tested the code, and it already works well on most borwsers/etc, but I'm trying to develop on Kivy, and they barely support SVG files.
Feedback is welcome
EDIT: looks like you may need to make the 'origin' global, or create a setViewPort func
If I understand correctly, you want to change the drawing's view port size.
setRenderSize changes the final image scale, not the internal coordinate system. There is currently no way to edit the view port after a drawing has been created. You could make a Pull Request to add a method setViewPort contining these lines to do this.
For now, you could just edit the viewBox of a drawing directly:
d = draw.Drawing(...)
...
width = ...
height = ...
d.viewBox = (-width/2, -height/2, width, height)
but this may result in badly scaled SVGs.
Closing as stale.