0

I have an SVG file with some stroked paths in it (exported from a Cairo program), which I'm editing in Inkscape.

paths

I want to import it into FontForge, but for that, I need these to be filled paths—that is, I need to create the path that makes an outline around this shape, and fill that.

This seems like it should be a job for Path > Stroke to Path, but when I do that, it gets distorted.

after stroke to path

From searching online, it seems like the solution is to use Path > Break Apart first (to split it into individual paths), then Path > Union afterward. But when I use Path > Break Apart, everything goes wrong:

after break apart

Yikes! This isn't the shape I want! It seems like Break Apart is getting rid of the style of the path, so it ends up with a black fill and no stroke.

Why is Break Apart doing this? I've made sure my path isn't in a group, for starters, but I don't know what else to try.

Or, am I on the wrong track, and there's a different and better way to turn a stroked path into an identical-looking filled path?

3
  • I don't see a way to attach an SVG here, but I can upload it to Google Drive or something if that helps.
    – Draconis
    Commented Jun 3 at 22:37
  • 1
    You can either embed it in img tag or simply paste the source of the SVG file in the code snippet, see here Commented Jun 4 at 6:50
  • I can't reproduce the problem. It might have something to do with the way the original object has been constructed. Path > Stroke to Path will generally work with anything made in Inkscape. If you are using other software to make it, then import it into Inkscape, then that might be the source of problem. You can share SVGs over at svgshare.com - no login is required. Just post the link here.
    – Billy Kerr
    Commented Jun 4 at 13:39

1 Answer 1

0

This is bizarre, and I think arguably a bug in Inkscape!

In an SVG file, there are two different ways to specify the properties of a <path>. One is to use a bunch of different properties, stroke-width="0.05" stroke-linecap="round" and so on. The other is to consolidate all of those into a single style property, style="stroke-width:0.05;stroke-linecap:round;".

Inkscape seems to handle them both just fine. But if you open an SVG file that uses the first style, with separate properties, they aren't quite imported right! They'll seem to work, but any path operations (like the Break Apart I was trying to do) will lose all of those properties.

The solution is to make sure all SVG files you open in Inkscape use the second style, in which case the properties will actually be set correctly and will survive path operations. So now I have a Python script that modifies the SVG file before I import it:

import lxml.etree as et

def clean_xml(file):
    SAFE_ATTRS = {'d', 'transform', 'style'} # The attributes we don't want to change
    tree = et.parse(file)
    for path in tree.getroot().iter():
        if not path.tag.endswith('path'): continue
        if 'style' in path.attrib: continue # Already has a style
        style = []
        iterator = list(path.attrib.items()) # So we can edit while iterating
        for key, val in iterator:
            if key in SAFE_ATTRS: continue
            style.append(f'{key}:{val};')
            del path.attrib[key]
        path.attrib['style'] = ''.join(style)
    tree.write(file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.