drawsvg icon indicating copy to clipboard operation
drawsvg copied to clipboard

Change viewport (new setViewPort method)

Open Unpronoucabl opened this issue 4 years ago • 1 comments

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

Unpronoucabl avatar May 22 '21 00:05 Unpronoucabl

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.

cduck avatar May 23 '21 23:05 cduck

Closing as stale.

cduck avatar Feb 12 '23 05:02 cduck