|
31 | 31 | from fontTools.fontBuilder import FontBuilder
|
32 | 32 | from fontTools.pens.ttGlyphPen import TTGlyphPen
|
33 | 33 |
|
| 34 | +
|
34 | 35 | def drawTestGlyph(pen):
|
35 | 36 | pen.moveTo((100, 100))
|
36 | 37 | pen.lineTo((100, 1000))
|
37 | 38 | pen.qCurveTo((200, 900), (400, 900), (500, 1000))
|
38 | 39 | pen.lineTo((500, 100))
|
39 | 40 | pen.closePath()
|
40 | 41 |
|
41 |
| -fb = FontBuilder(1024, isTTF=True) |
42 |
| -fb.setupGlyphOrder([".notdef", ".null", "A", "a"]) |
43 |
| -fb.setupCharacterMap({65: "A", 97: "a"}) |
44 | 42 |
|
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} |
46 | 47 |
|
47 | 48 | familyName = "HelloTestFont"
|
48 | 49 | 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 | +) |
52 | 60 |
|
53 | 61 | pen = TTGlyphPen(None)
|
54 | 62 | drawTestGlyph(pen)
|
55 | 63 | 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} |
57 | 65 | fb.setupGlyf(glyphs)
|
58 |
| -
|
59 | 66 | metrics = {}
|
60 | 67 | glyphTable = fb.font["glyf"]
|
61 | 68 | for gn, advanceWidth in advanceWidths.items():
|
62 | 69 | metrics[gn] = (advanceWidth, glyphTable[gn].xMin)
|
63 | 70 | fb.setupHorizontalMetrics(metrics)
|
64 |
| -
|
65 |
| -fb.setupHorizontalHeader(ascent=824, descent=200) |
| 71 | +fb.setupHorizontalHeader(ascent=824, descent=-200) |
66 | 72 | fb.setupNameTable(nameStrings)
|
67 |
| -fb.setupOS2() |
| 73 | +fb.setupOS2(sTypoAscender=824) |
68 | 74 | fb.setupPost()
|
69 |
| -
|
70 | 75 | fb.save("test.ttf")
|
71 | 76 | ```
|
72 | 77 |
|
|
0 commit comments