xsrf / easyeda-svg-import

Simple SVG Importer for EasyEDA PCB that doesn't convert everything to Comic Sans 😄
85 stars 8 forks source link

Reimport of SVG not showing text location changes #10

Closed djex closed 3 years ago

djex commented 3 years ago

First off thank you for this extension. I was struggling for days trying to get PNG / SVG import to not look like cartoon vomit in EasyEDA with no luck. Any ways not sure if this is a bug or not but I've run into an issue where re-importing the same svg file but with different text locations does not import the updated locations but uses the original ones. It's almost like there is a cached version of the original svg somewhere that it's using. I've checked the svg in multiple viewers and they all show the new locations just fine so I'm at a loss here. This only seems to happen with text objects that are converted to paths.

To explain better:

  1. I created a new file in Inkscape
  2. I added some text and shapes
  3. Converted text and shape objects to paths
  4. Saved it as an svg
  5. Imported using your extension into EasyEDA. Works great. Everything is where it's suppose to be.
  6. Went back into Inkscape and changed the locations of the text.
  7. Saved the svg
  8. Re-imported the svg using your extension but this time the text locations do not change and are in their original location.

This issue seems to be reproduceable. I don't know much about the SVG format but I'm thinking it might have something to do with how Inkscape writes the svg?

EDIT: So looked into it further and it seems for some reason Inkscape does not modify the d= attribute of text but adds in a transform="translate(81.642857,73.327381) attribute instead which I believe your extension does not take into account. Going to look into how I can get Inkscape not to use the transform attribute if possible but maybe also possible to add this into the extension?

xsrf commented 3 years ago

Hey, yes, I do have a suspicion. You basically have an SVG that contains a path / multiple paths that assemble the text. These paths are just lists of x/y coordinates joined together. To move the path, SVG gives you more than just one option. One is to just add the same vector to each point of the path, which would result in a new path with different coordinates. Another way is to leave the path untouched and just annotate to it, that it should be translated by a specific vector. I guess inkscape is doint the latter here and since my extension really only supports importing paths (the contents of paths), this is not supported and the path remains unchanged.

SVGs are just XML files. You can open both SVGs in a text editor and look at the difference. You should be able to spot the difference and tell if I'm right. If so, there might be an option in Inkscape to force it to recalculate the actual paths but I'm not sure... I'll have a look. Let me know what you find out.

xsrf commented 3 years ago

Okay, your edit confirms that ;) I'll have a look if I can implement that, but to be honest, I'm not sure if I want to. There are hundreds of options that can affect an SVG path and I won't support them all. I thought about finding a library that could potentially do that - parse the complete svg and reduce it to simple paths - but I haven't found one so far...

For your case - why can't you move the text in EasyEDA or move the origin for the 2nd import?

djex commented 3 years ago

Okay, your edit confirms that ;) I'll have a look if I can implement that, but to be honest, I'm not sure if I want to. There are hundreds of options that can affect an SVG path and I won't support them all. I thought about finding a library that could potentially do that - parse the complete svg and reduce it to simple paths - but I haven't found one so far...

For your case - why can't you move the text in EasyEDA or move the origin for the 2nd import?

Ok so in Inkscape I found if you ungroup the text path it will remove the translate attribute and update the x y coordinates. Kind of an annoying work around because now it adds in a few more steps when I want to move text around. Ungroup > select all individual letters > move > group.

And yes I could just move the text after I import into EasyEDA but I would like to work from one base copy and not have to change the EasyEDA import all the time.

djex commented 3 years ago

Ok found a better work around in Inkscape. Might want to include this in your readme?

  1. Create a text object.
  2. Select text object. Path > Object to Path.
  3. Object > Ungorup
  4. Path > Combine

This works great as now all your letters will be in one path and not in individual paths.

xsrf commented 3 years ago

Thx for trying this. I guess just moving and then hitting Ungroup and the Group would also recalculate the path. Additionally, for text, using combine is a really good idea since you don't want that many multiple paths. I'll try that, mabe make some screenshots and add it to the readme, sure. Thank you!

xsrf commented 3 years ago

I've added the tips to the readme. For text, you don't need to ungroup, just to Path and combine. For translating/moving objects, just move them and then hit ungroup and group again.