Merge pull request #1661 from massaad/patch-1
[fontBuilder] Make the minimal examples work on windows 10
This commit is contained in:
commit
816c6163f3
@ -31,6 +31,7 @@ Here is how to build a minimal TTF:
|
||||
from fontTools.fontBuilder import FontBuilder
|
||||
from fontTools.pens.ttGlyphPen import TTGlyphPen
|
||||
|
||||
|
||||
def drawTestGlyph(pen):
|
||||
pen.moveTo((100, 100))
|
||||
pen.lineTo((100, 1000))
|
||||
@ -38,35 +39,39 @@ def drawTestGlyph(pen):
|
||||
pen.lineTo((500, 100))
|
||||
pen.closePath()
|
||||
|
||||
fb = FontBuilder(1024, isTTF=True)
|
||||
fb.setupGlyphOrder([".notdef", ".null", "A", "a"])
|
||||
fb.setupCharacterMap({65: "A", 97: "a"})
|
||||
|
||||
advanceWidths = {".notdef": 600, "A": 600, "a": 600, ".null": 600}
|
||||
fb = FontBuilder(1024, isTTF=True)
|
||||
fb.setupGlyphOrder([".notdef", ".null", "space", "A", "a"])
|
||||
fb.setupCharacterMap({32: "space", 65: "A", 97: "a"})
|
||||
advanceWidths = {".notdef": 600, "space": 500, "A": 600, "a": 600, ".null": 0}
|
||||
|
||||
familyName = "HelloTestFont"
|
||||
styleName = "TotallyNormal"
|
||||
nameStrings = dict(familyName=dict(en="HelloTestFont", nl="HalloTestFont"),
|
||||
styleName=dict(en="TotallyNormal", nl="TotaalNormaal"))
|
||||
nameStrings['psName'] = familyName + "-" + styleName
|
||||
version = "0.1"
|
||||
|
||||
nameStrings = dict(
|
||||
familyName=dict(en=familyName, nl="HalloTestFont"),
|
||||
styleName=dict(en=styleName, nl="TotaalNormaal"),
|
||||
uniqueFontIdentifier="fontBuilder: " + familyName + "." + styleName,
|
||||
fullName=familyName + "-" + styleName,
|
||||
psName=familyName + "-" + styleName,
|
||||
version="Version " + version,
|
||||
)
|
||||
|
||||
pen = TTGlyphPen(None)
|
||||
drawTestGlyph(pen)
|
||||
glyph = pen.glyph()
|
||||
glyphs = {".notdef": glyph, "A": glyph, "a": glyph, ".null": glyph}
|
||||
glyphs = {".notdef": glyph, "space": glyph, "A": glyph, "a": glyph, ".null": glyph}
|
||||
fb.setupGlyf(glyphs)
|
||||
|
||||
metrics = {}
|
||||
glyphTable = fb.font["glyf"]
|
||||
for gn, advanceWidth in advanceWidths.items():
|
||||
metrics[gn] = (advanceWidth, glyphTable[gn].xMin)
|
||||
fb.setupHorizontalMetrics(metrics)
|
||||
|
||||
fb.setupHorizontalHeader(ascent=824, descent=200)
|
||||
fb.setupHorizontalHeader(ascent=824, descent=-200)
|
||||
fb.setupNameTable(nameStrings)
|
||||
fb.setupOS2()
|
||||
fb.setupOS2(sTypoAscender=824, usWinAscent=824, usWinDescent=200)
|
||||
fb.setupPost()
|
||||
|
||||
fb.save("test.ttf")
|
||||
```
|
||||
|
||||
@ -76,6 +81,7 @@ And here's how to build a minimal OTF:
|
||||
from fontTools.fontBuilder import FontBuilder
|
||||
from fontTools.pens.t2CharStringPen import T2CharStringPen
|
||||
|
||||
|
||||
def drawTestGlyph(pen):
|
||||
pen.moveTo((100, 100))
|
||||
pen.lineTo((100, 1000))
|
||||
@ -83,35 +89,45 @@ def drawTestGlyph(pen):
|
||||
pen.lineTo((500, 100))
|
||||
pen.closePath()
|
||||
|
||||
fb = FontBuilder(1024, isTTF=False)
|
||||
fb.setupGlyphOrder([".notdef", ".null", "A", "a"])
|
||||
fb.setupCharacterMap({65: "A", 97: "a"})
|
||||
|
||||
advanceWidths = {".notdef": 600, "A": 600, "a": 600, ".null": 600}
|
||||
fb = FontBuilder(1024, isTTF=False)
|
||||
fb.setupGlyphOrder([".notdef", ".null", "space", "A", "a"])
|
||||
fb.setupCharacterMap({32: "space", 65: "A", 97: "a"})
|
||||
advanceWidths = {".notdef": 600, "space": 500, "A": 600, "a": 600, ".null": 0}
|
||||
|
||||
familyName = "HelloTestFont"
|
||||
styleName = "TotallyNormal"
|
||||
nameStrings = dict(familyName=dict(en="HelloTestFont", nl="HalloTestFont"),
|
||||
styleName=dict(en="TotallyNormal", nl="TotaalNormaal"))
|
||||
nameStrings['psName'] = familyName + "-" + styleName
|
||||
version = "0.1"
|
||||
|
||||
nameStrings = dict(
|
||||
familyName=dict(en=familyName, nl="HalloTestFont"),
|
||||
styleName=dict(en=styleName, nl="TotaalNormaal"),
|
||||
uniqueFontIdentifier="fontBuilder: " + familyName + "." + styleName,
|
||||
fullName=familyName + "-" + styleName,
|
||||
psName=familyName + "-" + styleName,
|
||||
version="Version " + version,
|
||||
)
|
||||
|
||||
pen = T2CharStringPen(600, None)
|
||||
drawTestGlyph(pen)
|
||||
charString = pen.getCharString()
|
||||
charStrings = {".notdef": charString, "A": charString, "a": charString, ".null": charString}
|
||||
fb.setupCFF(nameStrings['psName'], {"FullName": nameStrings['psName']}, charStrings, {})
|
||||
|
||||
charStrings = {
|
||||
".notdef": charString,
|
||||
"space": charString,
|
||||
"A": charString,
|
||||
"a": charString,
|
||||
".null": charString,
|
||||
}
|
||||
fb.setupCFF(nameStrings["psName"], {"FullName": nameStrings["psName"]}, charStrings, {})
|
||||
lsb = {gn: cs.calcBounds(None)[0] for gn, cs in charStrings.items()}
|
||||
metrics = {}
|
||||
for gn, advanceWidth in advanceWidths.items():
|
||||
metrics[gn] = (advanceWidth, lsb[gn])
|
||||
fb.setupHorizontalMetrics(metrics)
|
||||
|
||||
fb.setupHorizontalHeader(ascent=824, descent=200)
|
||||
fb.setupNameTable(nameStrings)
|
||||
fb.setupOS2()
|
||||
fb.setupOS2(sTypoAscender=824, usWinAscent=824, usWinDescent=200)
|
||||
fb.setupPost()
|
||||
|
||||
fb.save("test.otf")
|
||||
```
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user