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

wrong width and height attributes of drawing obj #362

Open
ronak1009 opened this issue Nov 23, 2022 · 1 comment
Open

wrong width and height attributes of drawing obj #362

ronak1009 opened this issue Nov 23, 2022 · 1 comment

Comments

@ronak1009
Copy link

ronak1009 commented Nov 23, 2022

I observed that the dimensions of the drawing object have got interchanged between height and width of the svg.

import svglib.svglib as svglib
svgStr = ""
bbytes = io.StringIO(svgStr)
dwg = svglib.svg2rlg(bbytes)
print(f" dwg original {drawing.width=}, {drawing.height=}")

Now, I want to resize this drawing to fix the bounding box (size if dynamic) for pdf creation using reportlab, the resize does not work properly.

To resize:

scale = min( [(maxWidth- 5*mm)/dwg.width,             (maxHeight- 2*mm)/dwg.height])
dwg.width = dwg.width * scale
dwg.height =dwg.height * scale
dwg.scale(sx, sy)

The diagram gets scaled but something seems to be not proper.

dwg original dwg.width=450.0, dwg.height=700.0
--- scale ---
avail maxWidth=504.56692913385825 , maxHeight=657.9685039370078
sx=0.7005624296962879, sy=0.7005624296962879
dwg.width=490.39370078740154 , dwg.height=315.2530933633296

--- scale ---
avail maxWidth=504.56692913385825 , maxHeight=657.9685039370078
sx=1.0, sy=1.0
dwg.width=490.39370078740154 , dwg.height=315.2530933633296

In the attached snap of the PDF generated, the block outside box is the bounding box and the svg does not fit into it correctly, The output of the dimensions are shown above and that gives a false impression that the drawing dwg is within the correct bounding box.

image

Attaching the svg
svgSample.txt

@deeplook
Copy link
Owner

Sorry, but your code doesn't execute...

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

2 participants