-
Notifications
You must be signed in to change notification settings - Fork 1
/
fix-contour-width.py
executable file
·33 lines (28 loc) · 841 Bytes
/
fix-contour-width.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
#!/usr/bin/env fontforge
import fontforge
import psMat
from sys import argv, stderr
from GlyphComment import getfield
fontforge.setPrefs('CoverageFormatsAllowed', 1)
if len(argv) < 4:
stderr.write("Usage: "+argv[0]+" ratio infile outfile\n")
quit(1)
widthScale = None
widthList = {}
try:
widthScale = float(argv[1])
except ValueError:
import csv
reader = csv.reader(open(argv[1]), delimiter='\t')
for data in reader:
widthList[data[0]] = float(data[3])
font = fontforge.open(argv[2])
for glyph in font.glyphs():
if glyph.isWorthOutputting():
kagename = getfield(glyph, "Kage")
glyphWidth = glyph.width
glyphScale = widthList[kagename] if kagename in widthList else widthScale
if glyphScale != 1.0:
glyph.transform(psMat.scale(glyphScale, 1.0), ("partialRefs", "round"))
glyph.width = glyphWidth
font.save(argv[3])