Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with SVGFigure Width and Height not being set #73

Open
toothrobber opened this issue Apr 16, 2021 · 9 comments
Open

Issues with SVGFigure Width and Height not being set #73

toothrobber opened this issue Apr 16, 2021 · 9 comments

Comments

@toothrobber
Copy link

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

@hartwork
Copy link
Collaborator

hartwork commented Apr 16, 2021

I'd expect SVGFigure(width=1000.0, height=1000.0) to raise AttributeErrorwhich is handled at

except AttributeError:
. Which version of svgutils are you running?

@hartwork
Copy link
Collaborator

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

@toothrobber
Copy link
Author

toothrobber commented Apr 16, 2021 via email

@hartwork
Copy link
Collaborator

# pip show svgutils | fgrep Version:
Version: 0.3.4

@toothrobber
Copy link
Author

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

@hartwork
Copy link
Collaborator

hartwork commented Apr 18, 2021

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.

@toothrobber
Copy link
Author

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

@hartwork
Copy link
Collaborator

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

@cmahnke
Copy link

cmahnke commented Nov 15, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants