Batch Replace Glyphs #2133
Unanswered
connordavenport
asked this question in
Q&A
Replies: 1 comment 3 replies
-
from fontTools.ttLib import TTFont, newTable
from fontTools.ttLib.tables._g_l_y_f import Glyph
from fontTools.pens.ttGlyphPen import TTGlyphPen
import os
source = 'sourceFont.ttf'
dest = 'destinationFont.ttf'
s = TTFont(source)
d = TTFont(dest)
for key in ["hyphen", "endash", "emdash"]:
glyf = d["glyf"]
sg = s.getGlyphSet()[key]
glyf[key] = Glyph()
pen = TTGlyphPen(None)
sg.draw(pen)
glyf[key] = pen.glyph()
glyf[key].program = sg._glyph.program
d["hmtx"].metrics[key] = s["hmtx"].metrics[key]
d.save(dest) I figured out this very basic version that works with contour-based TTGlyphs. I'd love to see if people have done this with CFF or components. Pens go way over my head :) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey everyone! I've been struggling to figure this one out — does anyone know of a way to batch replace glyphs in a TTFont from a source? Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions