-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfullwidth.py
executable file
·51 lines (49 loc) · 1.97 KB
/
fullwidth.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
#!/usr/local/bin/fontforge
import sys
import fontforge
import psMat
import math
font = fontforge.open(sys.argv[1])
font.encoding='UnicodeBmp'
font.selection.select(('ranges',), 0x21, 0x7e)
font.selection.select(('more',), 0xa5)
font.copy()
font.selection.select(('ranges',), 0xff01, 0xff5e)
font.selection.select(('more',), 0xffe5)
font.paste()
if font.italicangle:
font.transform(psMat.skew(font.italicangle * math.pi / 180.0))
font.transform(psMat.scale(1.5, 1.0))
font.transform(psMat.translate(153.25, 0))
font[0xff03].transform(psMat.skew(-10 * math.pi / 180.0))
font[0xff10].transform(psMat.skew(30 * math.pi / 180.0))
font[0xff15].transform(psMat.skew(-5 * math.pi / 180.0))
for glyph in font.selection.byGlyphs:
if glyph.encoding == 0xffe5:
glyph.glyphname = font[0xa5].glyphname + 'monospace'
else:
glyph.glyphname = font[glyph.encoding - 0xff00 + 0x20].glyphname + 'monospace'
glyph.width = 1226
newLayer = fontforge.layer()
for contour in glyph.layers[1]:
newContour = fontforge.contour()
for i in range(0, len(contour)):
delta1 = (contour[(i + 1) % len(contour)].x - contour[i].x, contour[(i + 1) % len(contour)].y - contour[i].y)
delta2 = (contour[i].x - contour[i - 1].x, contour[i].y - contour[i - 1].y)
angle1 = math.atan2(delta1[1], delta1[0])
angle2 = math.atan2(delta2[1], delta2[0])
angle = angle1 if abs(math.sin(angle1)) >= abs(math.sin(angle2)) else angle2
if (delta1[1] * delta2[1] >= 0) or (abs(delta1[0]) < 15) or (abs(delta2[0]) < 15):
newContour += fontforge.point(contour[i].x + 20 * math.sin(angle), contour[i].y, contour[i].on_curve)
else:
newContour += contour[i]
newContour.closed = True
newLayer += newContour
glyph.layers[1] = newLayer
font[0xff03].transform(psMat.skew(10 * math.pi / 180.0))
font[0xff10].transform(psMat.skew(-30 * math.pi / 180.0))
font[0xff15].transform(psMat.skew(5 * math.pi / 180.0))
if font.italicangle:
font.transform(psMat.skew(-font.italicangle * math.pi / 180.0))
font.autoHint()
font.save(sys.argv[2])