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

why is "moveto" actually "moveby" #91

Open
Knochi opened this issue Feb 14, 2022 · 2 comments
Open

why is "moveto" actually "moveby" #91

Knochi opened this issue Feb 14, 2022 · 2 comments

Comments

@Knochi
Copy link

Knochi commented Feb 14, 2022

Hi,

I'm trying to open a svg file as a template and position objects programmatically.

SVGTest

I expected a new file with the rectangle and the circle but not the triangle (that worked), where circle and rectangle are placed at the same coordinate in the top left corner (that didn't work).

instead, when looking to the resulting svg i can see that elements get the "translate()" transformation, which is move by 20 to the right and 20 to bottom.

import svgutils.transform as sg
from svgutils.compose import Unit
import sys


ovWdth = Unit('1080px')
ovHght = Unit('768px')

fig = sg.SVGFigure(ovWdth,ovHght) 

#load template
tmpl = sg.fromfile('SVGTest.svg')


#get objects
boxObj = tmpl.find_id('rect846')
circObj = tmpl.find_id('path1076')

print(boxObj)

#move objects
boxObj.moveto(20,20)
circObj.moveto(20,20)

#append to figure
fig.append([boxObj, circObj])

#save figure
fig.save('SVGTest_Output.svg')
@JianqiangDing
Copy link

I also met similar issues when using this tool to compose some SVG images, I don't have time to check the code, but according to my experience, I guess this is probably related to the unit your SVG file is saved in (i.e. px or pt). another weird problem is you may do the wrong rotation even if you think you set the right and reasonable parameters(like the rotating pivot), but you may get the wrong final SVG image.
I fix these issues by myself through change each elementary SVG files unit manually using Inkscape (File>Document Properties>Units).
another issue when I use this tool is the code can not get the right width/height if you edit your SVG files using Adobe Illustrator, this is because the format of SVG changed after editing by AI, I fix this issue by "Save as a Copy" through Inkscape.

I do think this tool is fantastic for someone like me to produce publication-quality figures, but it does have some space to improve.

Hope this comment helps you in some way!

@btel
Copy link
Owner

btel commented Sep 27, 2022

yes, agreed. The name of the method is misleading. If you feel like it, please open a MR to rename it. You can delegate moveto to moveby and add a deprectiation warning.

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