svg_utils
svg_utils copied to clipboard
Issues with SVGFigure Width and Height not being set
In the following code, I wanted to create an sag with a size of 1000 by 1000. Stepping through the code the values of the width and the height were not set because they generated an exception in the Width and Height Setters. This resulted in the width and the height not being set.
Please note that I tried many combinations of values for width and height.
# create an empty image
unit_fig = svgutils.transform.SVGFigure(width=1000.0, height=1000.0)
When the code reach the setter, the line self._width = value.value would fail.
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))
I replaced self._width = value. This fixed my problem.
robert
I'd expect SVGFigure(width=1000.0, height=1000.0) to raise AttributeErrorwhich is handled at https://github.com/btel/svg_utils/blob/10a082008a40a387cd80ef044c3efe6a8aa79bd6/src/svgutils/transform.py#L244 . Which version of svgutils are you running?
PS: Works for me with 0.3.4:
# cd "$(mktemp -d)"
# virtualenv --python=python3.9 venv
# source venv/bin/activate
# pip install svgutils==0.3.4
# python -c $'import svgutils\nsvgutils.transform.SVGFigure(width=1000.0, height=1000.0)' && echo 'no exception'
no exception
Hello I used pip3 install svgutils
I believe it is version 0.3.4
How would I check?
On Apr 16, 2021, at 10:41 AM, Sebastian Pipping @.***> wrote:
I'd expect that to raise AttributeErrorwhich is handled at https://github.com/btel/svg_utils/blob/10a082008a40a387cd80ef044c3efe6a8aa79bd6/src/svgutils/transform.py#L244 . Which version of svgutils are you running?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
# pip show svgutils | fgrep Version:
Version: 0.3.4
Hello Again
I took your example where no exception was generated and ran the following test. Use your code to generate a figure. Save that figure and look for the width and the height values in the svg file.
No Value for Width or Height are saved to the file. This indicated that the values for Width and Height are not being saved.
~ % cat tmp.svg
~ %Python 3.9.2 (default, Mar 15 2021, 17:37:51) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
import svgutils fig = svgutils.transform.SVGFigure(width=1000.0, height=1000.0) fig.save('tmp.svg') print(fig.width) None print(fig.height) None
Please note I stepped through the code and the width and the height values are not saved.
Robert
I confirm: the written SVG file does not carry width and height with svgutils 0.3.4. I guess #62 was not the full deal, then.
If you look at the code for the Width and the Height the "value.value" does not work.
ef width(self, value): self._width = value.value
Yes, that is why AttributeError is caught. The code doesn't consider all cases yet, I suppose.
There is also an issue setting a value to a percentage, since the Unit class doesn't recognize it. But maybe it's another issue?