Hi!
Im trying to write a script to import a sequence of SVGs into glyphs with the stroke widhts and stroke endings intact.
So far I managed to import SVG paths, but it is pretty much the same as using File/Import/Contours. The information about the stroke attributes is lost and they are interpreted as shapes.
What I would like to achieve would be similar to when you copy and paste a path from e.g. Illustrator. Here the paths have strokes, but no stroke endings. Ideally the stroke endings would also be imported.
Do you know how this could be done?
This is the code I have used so far:
import os
from Foundation import NSURL
thisFont = Glyphs.font
directory = "/SVG_test/svg/"
for fileName in os.listdir(directory):
if fileName.endswith(".svg"):
svgFilePath = directory+fileName
#print(svgFilePath)
svgFileUrl = NSURL.alloc().initFileURLWithPath_(svgFilePath)
glyphName = fileName.replace(".svg","")
#print(glyphName)
activeLayer = thisFont.selectedFontMaster.id
#print(activeLayer)
layerOfGlyph = thisFont.glyphs[glyphName].layers[activeLayer]
layerOfGlyph.importOutlinesFromURL_scale_error_(svgFileUrl, 1, None)
I hoped that importOutlinesFromURL_scale_error_() could maybe help me, but I couldn’t find out more about how it works in the docu …
I imagine that I’d need to parse the SVG to find out the stroke widths and attributes of each path, but I’m not sure if this is possible.
I also couldn’t find any info about stroke endings in the docu … Is there a way to apply them programmatically?