| 1 |
from fontTools.otlLib import builder |
| 2 |
from fontTools import ttLib |
| 3 |
import sys |
| 4 |
|
| 5 |
whichFont = "both" |
| 6 |
if len(sys.argv) > 1: |
| 7 |
whichFont = sys.argv[1] |
| 8 |
|
| 9 |
inItalicFont = "Elstob-Italic-VF.ttf" |
| 10 |
outItalicFont = "Elstob-Italic-VF-withSTAT.ttf" |
| 11 |
inRomanFont = "Elstob-VF.ttf" |
| 12 |
outRomanFont = "Elstob-VF-withSTAT.ttf" |
| 13 |
|
| 14 |
commonWeightDict = dict( |
| 15 |
tag="wght", |
| 16 |
name="Weight", |
| 17 |
values=[ |
| 18 |
dict(nominalValue=200, name="ExtraLight", rangeMinValue=200, rangeMaxValue=250), |
| 19 |
dict(nominalValue=300, name="Light", rangeMinValue=250, rangeMaxValue=350), |
| 20 |
dict(nominalValue=400, name="Regular", flags=0x2, rangeMinValue=350, rangeMaxValue=450), |
| 21 |
dict(nominalValue=500, name="Medium", rangeMinValue=450, rangeMaxValue=550), |
| 22 |
dict(nominalValue=600, name="SemiBold", rangeMinValue=550, rangeMaxValue=650), |
| 23 |
dict(nominalValue=700, name="Bold", rangeMinValue=650, rangeMaxValue=750), |
| 24 |
dict(nominalValue=800, name="ExtraBold", rangeMinValue=750, rangeMaxValue=800), |
| 25 |
dict(value=400, name="Regular", linkedValue=700, flags=0x2) |
| 26 |
] |
| 27 |
) |
| 28 |
|
| 29 |
commonOpticalSizeDict = dict( |
| 30 |
tag="opsz", |
| 31 |
name="Optical size", |
| 32 |
values=[ |
| 33 |
dict(nominalValue=6, name="6pt", rangeMinValue=6, rangeMaxValue=7), |
| 34 |
dict(nominalValue=8, name="8pt", rangeMinValue=7, rangeMaxValue=9), |
| 35 |
dict(nominalValue=10, name="10pt", rangeMinValue=9, rangeMaxValue=11), |
| 36 |
dict(nominalValue=12, name="12pt", flags=0x2, rangeMinValue=11, rangeMaxValue=13), |
| 37 |
dict(nominalValue=14, name="14pt", rangeMinValue=13, rangeMaxValue=16), |
| 38 |
dict(nominalValue=18, name="18pt", rangeMinValue=16, rangeMaxValue=18) |
| 39 |
] |
| 40 |
) |
| 41 |
|
| 42 |
commonGradeDict = dict( |
| 43 |
tag="GRAD", |
| 44 |
name="Grade", |
| 45 |
values=[ |
| 46 |
dict(nominalValue=0, name="LightGrade", flags=0x2, rangeMinValue=0, rangeMaxValue=0.5), |
| 47 |
dict(nominalValue=1, name="HeavyGrade", rangeMinValue=0.5, rangeMaxValue=1) |
| 48 |
] |
| 49 |
) |
| 50 |
|
| 51 |
commonSpacingDict = dict( |
| 52 |
tag="SPAC", |
| 53 |
name="Spacing", |
| 54 |
values=[ |
| 55 |
dict(nominalValue=0, name="NarrowSpacing", flags=0x2, rangeMinValue=0, rangeMaxValue=0.5), |
| 56 |
dict(nominalValue=1, name="WideSpacing", rangeMinValue=0.5, rangeMaxValue=1) |
| 57 |
] |
| 58 |
) |
| 59 |
|
| 60 |
slantDict = dict( |
| 61 |
tag="slnt", |
| 62 |
name="Slant", |
| 63 |
values=[ |
| 64 |
dict(nominalValue=0, name="Slanted", flags=0x2, rangeMinValue=0, rangeMaxValue=7.5), |
| 65 |
dict(nominalValue=15, name="Upright", rangeMinValue=7.5, rangeMaxValue=15) |
| 66 |
] |
| 67 |
) |
| 68 |
|
| 69 |
format2RomanAxes = [ |
| 70 |
commonOpticalSizeDict, commonWeightDict, commonGradeDict, commonSpacingDict, |
| 71 |
dict( |
| 72 |
tag="ital", |
| 73 |
name="Italic", |
| 74 |
values=[dict(value=0, name="Roman", linkedValue=1, flags=0x2)] |
| 75 |
) |
| 76 |
] |
| 77 |
|
| 78 |
format2ItalicAxes = [ |
| 79 |
commonOpticalSizeDict, commonWeightDict, commonGradeDict, commonSpacingDict, slantDict, |
| 80 |
dict( |
| 81 |
tag="ital", |
| 82 |
name="Italic", |
| 83 |
values=[dict(value=1, name="Italic")] |
| 84 |
) |
| 85 |
] |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
if whichFont == "italic" or whichFont == "both": |
| 95 |
ttfont = ttLib.TTFont(inItalicFont) |
| 96 |
builder.buildStatTable(ttfont,format2ItalicAxes) |
| 97 |
ttfont['name'].setName("ElstobItalic", 25, 3, 1, 0x409) |
| 98 |
for inst in ttfont['fvar'].instances: |
| 99 |
if (inst.coordinates['wght'] == 400.0 and inst.coordinates['opsz'] == 12.0 |
| 100 |
and inst.coordinates['GRAD'] == 0.0 and inst.coordinates['slnt'] == 0.0 |
| 101 |
and inst.coordinates['SPAC'] == 0): |
| 102 |
inst.subfamilyNameID = 2 |
| 103 |
inst.postscriptNameID = 6 |
| 104 |
else: |
| 105 |
subfamilyName = ttfont['name'].getName( |
| 106 |
inst.subfamilyNameID,3,1,0x409).toUnicode().replace(" Italic","").replace(" ","") |
| 107 |
inst.postscriptNameID = ttfont['name'].addName("ElstobItalic" + "-" + subfamilyName, |
| 108 |
platforms=((3,1,0x409),)) |
| 109 |
ttfont['name'].removeNames(platformID=1) |
| 110 |
ttfont.save(outItalicFont) |
| 111 |
|
| 112 |
if whichFont == "roman" or whichFont == "both": |
| 113 |
ttfont = ttLib.TTFont(inRomanFont) |
| 114 |
builder.buildStatTable(ttfont,format2RomanAxes) |
| 115 |
ttfont['name'].setName("ElstobRoman", 25, 3, 1, 0x409) |
| 116 |
for inst in ttfont['fvar'].instances: |
| 117 |
if (inst.coordinates['wght'] == 400.0 and inst.coordinates['opsz'] == 12.0 |
| 118 |
and inst.coordinates['GRAD'] == 0.0 and inst.coordinates['SPAC'] == 0): |
| 119 |
inst.subfamilyNameID = 2 |
| 120 |
inst.postscriptNameID = 6 |
| 121 |
else: |
| 122 |
subfamilyName = ttfont['name'].getName( |
| 123 |
inst.subfamilyNameID,3,1,0x409).toUnicode().replace(" ","") |
| 124 |
inst.postscriptNameID = ttfont['name'].addName("ElstobRoman" + "-" + subfamilyName, |
| 125 |
platforms=((3,1,0x409),)) |
| 126 |
ttfont['name'].removeNames(platformID=1) |
| 127 |
ttfont.save(outRomanFont) |