-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix-spaces.py
executable file
·69 lines (61 loc) · 1.53 KB
/
fix-spaces.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python3
from fontParts.world import *
import sys
# Open UFO
ufo = sys.argv[1]
font = OpenFont(ufo)
# Modify UFO
# Find the needed space glyphs
for glyph in font:
if glyph.unicode == 0x0020:
space = glyph
if glyph.unicode == 0x002E:
period = glyph
if glyph.unicode == 0x0030:
zero = glyph
if glyph.unicode == 0x00A0:
nbspace = glyph
if glyph.unicode == 0x2007:
figurespace = glyph
if glyph.unicode == 0x2008:
punctuationspace = glyph
if glyph.unicode == 0x2003:
emspace = glyph
if glyph.unicode == 0x2002:
enspace = glyph
if glyph.unicode == 0x2000:
enquad = glyph
if glyph.unicode == 0x2001:
emquad = glyph
if glyph.unicode == 0x2004:
threeperemspace = glyph
if glyph.unicode == 0x2005:
fourperemspace = glyph
if glyph.unicode == 0x2006:
sixperemspace = glyph
if glyph.unicode == 0x2009:
thinspace = glyph
if glyph.unicode == 0x200A:
hairspace = glyph
if glyph.unicode == 0x202F:
nnbspace = glyph
# Set width of spaces correctly
nbspace.width = space.width
figurespace.width = zero.width
punctuationspace.width = period.width
upm = font.info.unitsPerEm
em = upm
emspace.width = upm
enspace.width = em/2
enquad.width = em/2
emquad.width = em
threeperemspace.width = em/3
fourperemspace.width = em/4
sixperemspace.width = em/6
thinspace.width = em/5
hairspace.width = em/13
nnbspace.width = thinspace.width
# Save UFO
font.changed()
font.save()
font.close()