svg_utils icon indicating copy to clipboard operation
svg_utils copied to clipboard

Issues with SVGFigure Width and Height not being set

Open toothrobber opened this issue 4 years ago • 9 comments
trafficstars

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

toothrobber avatar Apr 16 '21 14:04 toothrobber

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?

hartwork avatar Apr 16 '21 14:04 hartwork

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

hartwork avatar Apr 16 '21 14:04 hartwork

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.

toothrobber avatar Apr 16 '21 16:04 toothrobber

# pip show svgutils | fgrep Version:
Version: 0.3.4

hartwork avatar Apr 16 '21 16:04 hartwork

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

toothrobber avatar Apr 18 '21 15:04 toothrobber

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.

hartwork avatar Apr 18 '21 15:04 hartwork

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

toothrobber avatar Apr 18 '21 15:04 toothrobber

Yes, that is why AttributeError is caught. The code doesn't consider all cases yet, I suppose.

hartwork avatar Apr 18 '21 15:04 hartwork

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?

cmahnke avatar Nov 15 '22 08:11 cmahnke