Skip to content

Commit 816c616

Browse files
Merge pull request fonttools#1661 from massaad/patch-1
[fontBuilder] Make the minimal examples work on windows 10
2 parents 506965d + caa78e1 commit 816c616

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

Lib/fontTools/fontBuilder.py

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,47 @@
3131
from fontTools.fontBuilder import FontBuilder
3232
from fontTools.pens.ttGlyphPen import TTGlyphPen
3333
34+
3435
def drawTestGlyph(pen):
3536
pen.moveTo((100, 100))
3637
pen.lineTo((100, 1000))
3738
pen.qCurveTo((200, 900), (400, 900), (500, 1000))
3839
pen.lineTo((500, 100))
3940
pen.closePath()
4041
41-
fb = FontBuilder(1024, isTTF=True)
42-
fb.setupGlyphOrder([".notdef", ".null", "A", "a"])
43-
fb.setupCharacterMap({65: "A", 97: "a"})
4442
45-
advanceWidths = {".notdef": 600, "A": 600, "a": 600, ".null": 600}
43+
fb = FontBuilder(1024, isTTF=True)
44+
fb.setupGlyphOrder([".notdef", ".null", "space", "A", "a"])
45+
fb.setupCharacterMap({32: "space", 65: "A", 97: "a"})
46+
advanceWidths = {".notdef": 600, "space": 500, "A": 600, "a": 600, ".null": 0}
4647
4748
familyName = "HelloTestFont"
4849
styleName = "TotallyNormal"
49-
nameStrings = dict(familyName=dict(en="HelloTestFont", nl="HalloTestFont"),
50-
styleName=dict(en="TotallyNormal", nl="TotaalNormaal"))
51-
nameStrings['psName'] = familyName + "-" + styleName
50+
version = "0.1"
51+
52+
nameStrings = dict(
53+
familyName=dict(en=familyName, nl="HalloTestFont"),
54+
styleName=dict(en=styleName, nl="TotaalNormaal"),
55+
uniqueFontIdentifier="fontBuilder: " + familyName + "." + styleName,
56+
fullName=familyName + "-" + styleName,
57+
psName=familyName + "-" + styleName,
58+
version="Version " + version,
59+
)
5260
5361
pen = TTGlyphPen(None)
5462
drawTestGlyph(pen)
5563
glyph = pen.glyph()
56-
glyphs = {".notdef": glyph, "A": glyph, "a": glyph, ".null": glyph}
64+
glyphs = {".notdef": glyph, "space": glyph, "A": glyph, "a": glyph, ".null": glyph}
5765
fb.setupGlyf(glyphs)
58-
5966
metrics = {}
6067
glyphTable = fb.font["glyf"]
6168
for gn, advanceWidth in advanceWidths.items():
6269
metrics[gn] = (advanceWidth, glyphTable[gn].xMin)
6370
fb.setupHorizontalMetrics(metrics)
64-
65-
fb.setupHorizontalHeader(ascent=824, descent=200)
71+
fb.setupHorizontalHeader(ascent=824, descent=-200)
6672
fb.setupNameTable(nameStrings)
67-
fb.setupOS2()
73+
fb.setupOS2(sTypoAscender=824, usWinAscent=824, usWinDescent=200)
6874
fb.setupPost()
69-
7075
fb.save("test.ttf")
7176
```
7277
@@ -76,42 +81,53 @@ def drawTestGlyph(pen):
7681
from fontTools.fontBuilder import FontBuilder
7782
from fontTools.pens.t2CharStringPen import T2CharStringPen
7883
84+
7985
def drawTestGlyph(pen):
8086
pen.moveTo((100, 100))
8187
pen.lineTo((100, 1000))
8288
pen.curveTo((200, 900), (400, 900), (500, 1000))
8389
pen.lineTo((500, 100))
8490
pen.closePath()
8591
86-
fb = FontBuilder(1024, isTTF=False)
87-
fb.setupGlyphOrder([".notdef", ".null", "A", "a"])
88-
fb.setupCharacterMap({65: "A", 97: "a"})
8992
90-
advanceWidths = {".notdef": 600, "A": 600, "a": 600, ".null": 600}
93+
fb = FontBuilder(1024, isTTF=False)
94+
fb.setupGlyphOrder([".notdef", ".null", "space", "A", "a"])
95+
fb.setupCharacterMap({32: "space", 65: "A", 97: "a"})
96+
advanceWidths = {".notdef": 600, "space": 500, "A": 600, "a": 600, ".null": 0}
9197
9298
familyName = "HelloTestFont"
9399
styleName = "TotallyNormal"
94-
nameStrings = dict(familyName=dict(en="HelloTestFont", nl="HalloTestFont"),
95-
styleName=dict(en="TotallyNormal", nl="TotaalNormaal"))
96-
nameStrings['psName'] = familyName + "-" + styleName
100+
version = "0.1"
101+
102+
nameStrings = dict(
103+
familyName=dict(en=familyName, nl="HalloTestFont"),
104+
styleName=dict(en=styleName, nl="TotaalNormaal"),
105+
uniqueFontIdentifier="fontBuilder: " + familyName + "." + styleName,
106+
fullName=familyName + "-" + styleName,
107+
psName=familyName + "-" + styleName,
108+
version="Version " + version,
109+
)
97110
98111
pen = T2CharStringPen(600, None)
99112
drawTestGlyph(pen)
100113
charString = pen.getCharString()
101-
charStrings = {".notdef": charString, "A": charString, "a": charString, ".null": charString}
102-
fb.setupCFF(nameStrings['psName'], {"FullName": nameStrings['psName']}, charStrings, {})
103-
114+
charStrings = {
115+
".notdef": charString,
116+
"space": charString,
117+
"A": charString,
118+
"a": charString,
119+
".null": charString,
120+
}
121+
fb.setupCFF(nameStrings["psName"], {"FullName": nameStrings["psName"]}, charStrings, {})
104122
lsb = {gn: cs.calcBounds(None)[0] for gn, cs in charStrings.items()}
105123
metrics = {}
106124
for gn, advanceWidth in advanceWidths.items():
107125
metrics[gn] = (advanceWidth, lsb[gn])
108126
fb.setupHorizontalMetrics(metrics)
109-
110127
fb.setupHorizontalHeader(ascent=824, descent=200)
111128
fb.setupNameTable(nameStrings)
112-
fb.setupOS2()
129+
fb.setupOS2(sTypoAscender=824, usWinAscent=824, usWinDescent=200)
113130
fb.setupPost()
114-
115131
fb.save("test.otf")
116132
```
117133
"""

0 commit comments

Comments
 (0)