Extension to break apart paths into non-overlapping subpaths
Extension to break apart paths into non-overlapping subpaths
I have svgs consisting of complex paths that I would like to break into non-overlapping (sub)paths. Right now I break them apart by hand and then select and recombine the overlapping paths, but I have several hundred of these images and each consists of anywhere from 20 to 130 such overlapping groups. To get an idea of what I am trying to do, imagine a line of text as a complex path: break apart into constituent paths, then recombine each group of paths that form each letter, so that each letter is its own path object. Would it be possible to write an extension for this task?
Re: Extension to break apart paths into non-overlapping subp
If I understand your problem correctly, I think the most difficult part will be determining which sub-paths are overlapping. Depending on how your data is laid out, this could be easy (comparing bounding boxes or circles), or it could be more difficult (finding slight overlaps within the curvature of paths). Either way, I think an extension should be possible.
Re: Extension to break apart paths into non-overlapping subp
You are of course correct that a true test of "non-overlapping" might be quite difficult. But for my purposes, a very simple idea of non-overlapping would be sufficient. As my example of the letters in a line of text indicates, checking the horizontal coordinates of the bounding box would actually be good enough. In fact I find that part of the problem perfectly straightforward. I was more wondering about how to combine paths. Am I correct that one would have to do this "by hand," that is modify the XML? Are there any modules for this kind of thing that are already written?
Re: Extension to break apart paths into non-overlapping subp
No, that won't work, due to kerning.A better method would be to check if any point of one of the paths (anchors and handles) is within the "envelope" (polygon that contains all anchors and handles) of the other. This isn't correct either but a lot less likely to fail with letters. But in all cases it will be very hard to handle diacritic marks and characters made of separate strokes (typical in the korean alphabet, but this will also happen in the latin alphabet with some font designs).spaelti wrote:You are of course correct that a true test of "non-overlapping" might be quite difficult. But for my purposes, a very simple idea of non-overlapping would be sufficient. As my example of the letters in a line of text indicates, checking the horizontal coordinates of the bounding box would actually be good enough.
Combining the paths is the very easy part.spaelti wrote:In fact I find that part of the problem perfectly straightforward. I was more wondering about how to combine paths. Am I correct that one would have to do this "by hand," that is modify the XML? Are there any modules for this kind of thing that are already written?
Re: Extension to break apart paths into non-overlapping subp
ofnuts wrote:No, that won't work, due to kerning.A better method would be to check if any point of one of the paths (anchors and handles) is within the "envelope" (polygon that contains all anchors and handles) of the other.spaelti wrote:You are of course correct that a true test of "non-overlapping" might be quite difficult. But for my purposes, a very simple idea of non-overlapping would be sufficient. As my example of the letters in a line of text indicates, checking the horizontal coordinates of the bounding box would actually be good enough.
It WILL work for me, because that is what I want. I want to separate the paths whenever there is a vertical strip of whitespace separating them. The bit about letters was only for illustration.
ofnuts wrote:Combining the paths is the very easy part.spaelti wrote:In fact I find that part of the problem perfectly straightforward. I was more wondering about how to combine paths. Am I correct that one would have to do this "by hand," that is modify the XML? Are there any modules for this kind of thing that are already written?
Well then, do you have a sample or bit of code that I could use to show me how to do this?
Re: Extension to break apart paths into non-overlapping subp
Well I have now succeeded in creating an extension to do more or less what I wanted. My particular thanks go to Nick -- author of this extension: close_curves, which proved helpful to creating this.
The way this extension works.
The result will be that all the subpaths which overlap, but are separated from other paths with a vertical strip of white-space, will be recombined separately.
Hope it's useful.
The way this extension works.
- Select a complex path
- Do "Break Apart" (shift-control-K)
- Run this extension
The result will be that all the subpaths which overlap, but are separated from other paths with a vertical strip of white-space, will be recombined separately.
Hope it's useful.
- Attachments
-
- combine_paths.zip
- (3.65 KiB) Downloaded 356 times
Last edited by spaelti on Wed May 30, 2012 5:17 pm, edited 1 time in total.
Re: Extension to break apart paths into non-overlapping subp
spaelti wrote:Well I have now succeeded in creating an extension to do more or less what I wanted.
(…)
Hope it's useful.
Thanks for sharing - could you add an INX file to the archive as well? This would make testing the extension a lot easier ;)
Re: Extension to break apart paths into non-overlapping subp
~suv wrote:Thanks for sharing - could you add an INX file to the archive as well? This would make testing the extension a lot easier
Sorry. I thought I had included that. Has been fixed now.
Re: Extension to break apart paths into non-overlapping subp
Actually I have to say that the .inx file that I included is something that I just created by modifying some other .inx file(s) and I am really not sure that it is completely appropriate. (Presumably the <id> and the namespace can be anything you want??). What about the <dependency> nodes?
But it did work for me.
But it did work for me.