PNG / SVG Export

OK, here is a snippet you can paste in Window > Macro Panel. Select the glyphs and run the code from the macro window. It will prompt you for a folder and then store the SVGs with glyph names and an .svg suffix:

from AppKit import NSSize
GlyphAsImage = NSClassFromString("GlyphAsImage")
folder = GetFolder(allowsMultipleSelection=False)
if folder:
	folderURL = NSURL.fileURLWithPath_(folder)
	for layer in Font.selectedLayers:
		preset = {
			"active": True,
			"name": "SVG",
			"size": layer.ascender,
			"factor": 1,
			"format": "SVG"
		}
		layerSize = NSSize(layer.width, layer.ascender)
		svgData = GlyphAsImage.svgDataWithLayer_origSize_settings_(layer, layerSize, preset)
		svgFileName = layer.parent.name + ".svg"
		svgURL = folderURL.URLByAppendingPathComponent_(svgFileName)
		svgData.writeToURL_atomically_(svgURL, False)

(edit by @GeorgSeifert: I simplified the code a bit)

1 Like

Hey, thanks!!

I am trying to figure out how to get SVG from GSinstance instead of selectedLayers.
I guess trying to use the filter will not work. Right?

Which direction should I look for?

Interpolate the layers and pass them through this one by one. Best to use an export plug-in.

1 Like

To get an interpolated layer:

instance = Font.instances[1]
interpolatedFont = instance.interpolatedFontProxy
interpolatedGlyph = interpolatedFont.glyphs["A"]
interpolatedLayer = interpolatedGlyph.layers[0]
1 Like

Hi Mekka,
Can I get a script that export the selected glyphs as png images?

  1. I need to be able to select the image size (for example 512x512, or 716x716, or whatever)
  2. I need to be able to draw a rectangle to represent the bbox
  3. Ideally, a small line to represent also the baseline and the xheight (just a tiny little short line, for example from 0,0 to 0,10 on the baseline)

It all need to be centered inside the png image, having a little 10px margin arround it.
If you need more detail, get in touch with me via Skype.

Thanks!

Why don’t you use DrawBot for this? You can use DrawBot straight from within Glyphs.

You can do that natively from Glyphs. Take a look at the PS and EPS export plugins.