Skip to content

Commit f51c114

Browse files
authored
make the ttf sample pass FontValidator
I used FontValidator to validate the ttf font. I made some changes to address the errors. Now it passes, but still trying to preview the font in windows raises the same error.
1 parent 56c1a32 commit f51c114

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

Lib/fontTools/fontBuilder.py

Lines changed: 18 additions & 13 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)
6874
fb.setupPost()
69-
7075
fb.save("test.ttf")
7176
```
7277

0 commit comments

Comments
 (0)