Importing SVG default scaling

Hi Guys,

When importing SVG files via “File > Import Contours” , the SVG content get automatically scaled to fit between the Baseline and the Ascender values. A good default scaling option… but…

Can it be tweaked to fit the imported SVG between the “descender” and the ascender instead?

Or better yet: Can a script or plugin be made for customizing the import scaling options with more liberty (for different importing scenarios, instead of always using just the default scaling)?

Thanks!

There’s a custom parameter point-to-unit ratio. Not sure if applies to import of SVGs though.

1 Like

This is a bit more code than I had hoped:

import objc
from AppKit import NSURL, NSXMLDocument, NSAffineTransform
from GlyphsApp import GSLayer
GSSVGtoPath = objc.lookUpClass("GSSVGtoPath")

height = 100
fileURL = NSURL.fileURLWithPath_("path/to/file.svg")

doc = NSXMLDocument.alloc().initWithContentsOfURL_options_error_(fileURL, 0, None)[0]
SVG = doc.rootElement()

importer = GSSVGtoPath.new()
layer = GSLayer()
importer.drawSVG_layer_scale_error_(SVG, layer, 1, None)

transform = NSAffineTransform.new()
transform.translateXBy_yBy_(0, height)
transform.scaleXBy_yBy_(1, -1)
layer.transform(transform)

Layer.shapes = layer.shapes
1 Like