-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpatch-fonts.py
More file actions
55 lines (37 loc) · 1.09 KB
/
Copy pathpatch-fonts.py
File metadata and controls
55 lines (37 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Credit: https://github.com/artisticat1/tikzjax/blob/output-single-file/patchFonts.py
# Execute with "fontforge -lang=py -script patch-fonts.py"
import fontforge
from glob import glob
NOTSIGN = 172
SOFTHYPHEN = 173
def checkGlyphExists(font, glyph):
try:
x = font[glyph]
return True
except:
return False
def replaceGlyph(font, glyph1, glyph2):
glyph1Exists = checkGlyphExists(font, glyph1)
glyph2Exists = checkGlyphExists(font, glyph2)
possible = ( glyph1Exists and (not glyph2Exists) )
if not possible:
print("Unable to replace glyph.")
if not glyph1Exists: print("Glyph 1 doesn't exist.")
if glyph2Exists: print("Glyph 2 already exists.")
return font
font.selection.select(glyph1)
font.copy()
font.selection.select(glyph2)
font.paste()
return font
def getFiles():
files = glob("./css/bakoma/ttf/*")
return files
def main():
files = getFiles()
for file in files:
print(file)
font = fontforge.open(file)
font = replaceGlyph(font, SOFTHYPHEN, NOTSIGN)
font.generate(file)
main()