svg_utils icon indicating copy to clipboard operation
svg_utils copied to clipboard

SVGFigure does not set width and height element if created directly

Open akhmerov opened this issue 3 years ago • 3 comments
trafficstars

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.

akhmerov avatar Dec 09 '21 13:12 akhmerov

Hi @akhmerov, which version (or Git commit) of svgutils is this about?

hartwork avatar Dec 09 '21 13:12 hartwork

I observed this both on 0.3.4 and master (4abf7fb)

akhmerov avatar Dec 09 '21 13:12 akhmerov

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) 

Knochi avatar Feb 14 '22 12:02 Knochi

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))

myzonexu avatar Sep 22 '22 08:09 myzonexu

indeed we don't set the SVG tag attributes when width or height is an integer/string

btel avatar Sep 27 '22 20:09 btel