Skip to content

Instantly share code, notes, and snippets.

@shellj
Last active November 10, 2023 06:57
Show Gist options
  • Save shellj/e94be1a093177a41250a62a33b52ca59 to your computer and use it in GitHub Desktop.
Save shellj/e94be1a093177a41250a62a33b52ca59 to your computer and use it in GitHub Desktop.
fontforge 精简 fontawesome 字体
# 需要使用 fontforge 的 ffpython 执行
import fontforge
# 可以在 fontawesome.com 找到 glyph ,字体里面 glyphname 加了 uni 前缀
glyphs = [
"unif09a", #facebook
"unif099", #twitter
"unif16d", #instagram
"unie07b", #tiktok
"unif09b", #github
"unif167", #youtube
"unif2c6", #telegram
"unif0d2", #pinterest
"unif1b6", #steam
]
font = fontforge.open("C:\\Users\\aaa\\Downloads\\fontawesome-free-6.4.2-web\\webfonts\\fa-brands-400.woff2")
assert isinstance(font, fontforge.font)
selection = font.selection
assert isinstance(selection, fontforge.selection)
selection.all()
names = []
for i in selection.byGlyphs:
assert isinstance(i, fontforge.glyph)
print(i.glyphname)
gly = i.glyphname.lower()
if gly not in glyphs:
font.removeGlyph(i)
else:
names.append(i.glyphname)
font.generate("C:\\Users\\aaa\\Downloads\\fontawesome-free-6.4.2-web\\webfonts\\fa-brands-400-sub.woff2")
@shellj
Copy link
Author

shellj commented Nov 8, 2023

@shellj
Copy link
Author

shellj commented Nov 9, 2023

或者可以通过 fantasticon 从 svg 文件直接生成字体,这样更方便,参考这篇文章

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