Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2014 15:14
What would you like to do?
Notes on mass-importing SVG outlines into FontForge via Python

Notes on dumping SVG outlines into a FontForge file

Sources I've looked at:

I have a hunch that createMappedChar() doesn't work unless you've done loadNameList('glyphlist.txt') or loadNameList('aglfn.txt') (BSD-licensed Adobe glyph lists). An alternative seems to be to go by codepoint with createChar().

import fontforge
#fontforge.loadNameList('aglfn.txt') # Might be optional

#font ='existing.sfd')
font = fontforge.font() # new font

glyphNameAndOutlineFilename = {
    ('A', 'capital-a-glyph.svg'),
    ('Adieresis', 'capital-adieresis-glyph.svg'),

#characterAndOutlineFilename = {
#   ('A', 'capital-a-glyph.svg'),
#   ('Ä', 'capital-adieresis-glyph.svg'),
#   ...

for name, filename in glyphNameAndOutlineFilename:
    glyph = font.createMappedChar(name)
    # May need to set glyph.width here

#for c, filename in characterAndOutlineFilename:
#   glyph = font.createChar(ord(c))
#   glyph.importOutlines(filename)
#   # May need to set glyph.width here

Copy link

deszcz commented Jul 26, 2015

And i get:

Multiple names when parsing glyphlist for unicode ae
Failed to parse color
Failed to parse color
Internal Error: Some fragments did not join
Failed to parse color
Failed to parse color
Rename A by U0041
Rename B by U0042

Copy link

pelson commented Mar 24, 2017

A critical piece that I needed was to set the font's encoding:

font.encoding = "UnicodeFull"

Without that, I was finding:

>>> font.createMappedChar('a').unicode

Rather than the expected 97.

Copy link

They still lose color for me ....

Copy link

psmay commented Nov 7, 2020

As in color emoji? I don't think FontForge has any support for that.

Copy link

Looks like you're right. Issue here for color support fontforge/fontforge#677

Copy link

br750 commented May 24, 2021

Hello, there is a way to set RBearing when i use a script to creat font from SVG ? Thank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment