把 svg 檔案批次的方式,匯入字體檔案裡,滿實用的功能,省下很多手動操作的時間,簡易的範例:
https://stackoverflow.com/questions/22124130/import-a-sequence-of-svg-files-into-fontforge-as-glyphs-and-output-a-font-file
import fontforge
font = fontforge.open('blank.sfd')
glyph = font.createMappedChar('A')
glyph.importOutlines('sourceimg.svg')
font.generate('testfont.ttf')
進階範例:
https://gist.github.com/psmay/fd3e7e91893f6012b262
import fontforge
#fontforge.loadNameList('aglfn.txt') # Might be optional
#font = fontforge.open('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)
glyph.importOutlines(filename)
# 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
#font.generate('output-font.ttf')
font.save('output-font.sfd')
相關文章
向量檔匯入字體檔
https://codereview.max-everyday.com/import-svg-to-font/