I imported a path from external SVG files to the layer l
by using the Python script below:
url = NSURL.alloc().initFileURLWithPath_(file_path)
l.importOutlinesFromURL_scale_error_(url, 1, None)
for p in l.paths:
p.selected = True
p.setAttribute_forKey_(10, "strokeWidth")
p.setAttribute_forKey_(10, "strokeHeight")
# Referenced https://github.com/mekkablue/Glyphs-Scripts/blob/master/Spacing/Center%20Glyphs.py
o = l.selectionBounds.origin
sz = l.selectionBounds.size
for i in l.selection:
if isinstance(i, GSNode):
i.x += (0.5 * (l.width - sz.width) - o.x)
In most cases, the code works well. However, for some SVG files, they are not correctly imported as shown in the screenshot.
Since I’m a new user, I cannot attach any files here. Therefore, I put the sources of the SVG file causing the problem directly below.
<?xml version="1.0" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" baseProfile="full" height="600px" version="1.1" viewBox="1653.8671245 2061.5147245000003 87.3647510000001 96.5015509999996" width="544px">
<defs/>
<path d="M 1664.732,2069.59 C 1664.732,2069.59 1666.972,2072.239 1669.315,2076.212 C 1671.6580000000001,2080.185 1674.102,2085.483 1674.51,2090.78 C 1675.327,2101.375 1671.615,2120.4460000000004 1671.615,2120.4460000000004 M 1698.366,2109.078 L 1698.366,2142.995 L 1698.366,2109.078 M 1661.181,2149.941 L 1733.9180000000001,2142.9939999999997 M 1673.384,2109.078 L 1711.851,2105.809 L 1708.172,2069.59 C 1708.172,2069.59 1697.392,2073.118 1691.3410000000001,2073.936 C 1685.2900000000002,2074.7540000000004 1669.315,2076.212 1669.315,2076.212" fill="none" stroke="#000000" stroke-width="0.08035099999999966"/>
</svg>
I’d like to know whether there is a problem with my script or the SVG file itself.
Also, I’m wondering how to make the script imports SVG files correctly.
Thank you.