svg_utils
svg_utils copied to clipboard
SVGFigure does not set width and height element if created directly
Width and height aren't correctly set in the XML if transform.SVGFigure is created directly:
import svgutils
svgutils.transform.SVGFigure("10cm", "16cm").to_str()
prints
b'<?xml version=\'1.0\' encoding=\'ASCII\' standalone=\'yes\'?>\n<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"/>\n'
This code is used in the tutorial:
https://github.com/btel/svg_utils/blob/4abf7fb18cea0da04b6b2a0bcacbec5daded1662/docs/source/tutorials/scripts/fig_final.py#L5
Therefore I expect that this is not an intended behavior.
Hi @akhmerov, which version (or Git commit) of svgutils is this about?
I observed this both on 0.3.4 and master (4abf7fb)
same here but it works when i take one of the formats from the tests
import svgutils.transform as sg
from svgutils.compose import Unit
ovWdth = Unit('1080px')
ovHght = Unit('768px')
fig = sg.SVGFigure(ovWdth,ovHght)
I think the problem is here: transform.py line:259,271 value.value It works when the value use Unit(),but not work when use int or string @width.setter def width(self, value): self._width = value.value self.root.set("width", str(value)) self.root.set("viewBox", "0 0 %s %s" % (self._width, self._height))
indeed we don't set the SVG tag attributes when width or height is an integer/string