How to add a new glyph to a font with FontTools?

roipoussiere
Posts: 5
I'm trying to add a new glyph to a font. I managed to draw by glyph to a pen, then saved it to a glyph object with:
new_glyph = pen.glyph()Now I would like to do something like:
font.getGlyphSet()["e_m"] = new_glyphor (with a ttf font):
font["glyf"]["e_m"] = new_glyph
How to add a new glyph to a font with FontTools?
Thank you!
Tagged:
0
Comments
-
For anyone interested, the solution was to:1. create a new UFO;2. add the glyph to this UFO;3. compile this UFO to a font of the same type of the source font;4. merge the two fonts with fonttools.merge.1
-
It turns out that you can do this directly in Python, the font object maintains a GlyphOrder and this must have the names of all glyphs; but you can set it with
.setGlyphOrder
. Here's a routine that i use:def AddExtras(font, extras): """Add extra glyphs to a font.""" glyf = font["glyf"] hmtx = font["hmtx"] go = list(font.getGlyphOrder()) go += [glyph.name for glyph in extras] font.setGlyphOrder(go) for glyph in extras: name = glyph.name glyf[name] = glyph hmtx[name] = glyph.width, glyph.lsb
3 -
Actually off-topic because the question was about FontTools, but maybe useful for some to know, is that OTM has a function to simply add glyphs, also from another font. For this the Glyph Copy Tool can be used. This works, of course, also for adding logos. In addition, there is a fully featured glyph editor. Moreover, if needed, the ‘Autohint all unhinted glyphs when saving font’ option for CFF fonts can be invoked via the preferences.1
Categories
- All Categories
- 44 Introductions
- 3.8K Typeface Design
- 815 Font Technology
- 1.1K Technique and Theory
- 633 Type Business
- 450 Type Design Critiques
- 549 Type Design Software
- 30 Punchcutting
- 138 Lettering and Calligraphy
- 85 Technique and Theory
- 53 Lettering Critiques
- 499 Typography
- 308 History of Typography
- 117 Education
- 74 Resources
- 513 Announcements
- 82 Events
- 107 Job Postings
- 156 Type Releases
- 167 Miscellaneous News
- 271 About TypeDrawers
- 53 TypeDrawers Announcements
- 117 Suggestions and Bug Reports