Skip to content

Commit 4bd34ed

Browse files
aaronbellmadig
andauthored
Updating scripts for OTF and WOFF2 (#260)
Modified the build.py script to add in OTF generation, and also created a second build script that created WOFF2 files from the TTF files (if TSI data removed). Requirements.txt updated to include WOFF2 compression library. * Update build.py Co-authored-by: Nikolaus Waxweiler <[email protected]> * Trying again to remove unnecessary hints Not sure how these got back in. Removing again. * Adding PSautohint functionality * Modifying code via feedback * Tweaking error strings * modifying build time for otf files Co-authored-by: Aaron <[email protected]> Co-authored-by: Nikolaus Waxweiler <[email protected]>
1 parent a8bbd67 commit 4bd34ed

File tree

134 files changed

+67
-5154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+67
-5154
lines changed

build.py

+47-33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import ufo2ft
88
import ufoLib2
99
import vttLib
10+
import sys
11+
import subprocess
1012

1113
INPUT_DIR = Path("sources")
1214
OUTPUT_DIR = Path("build")
@@ -44,42 +46,49 @@ def _set(instance):
4446

4547

4648
def build_font_instance(generator, instance_descriptor, *steps):
47-
instance = generator.generate_instance(instance_descriptor)
48-
49-
for step in steps:
50-
step(instance)
51-
52-
setattr(instance.info, "openTypeOS2Panose", [2, 11, 6, 9, 2, 0, 0, 2, 0, 4])
53-
54-
instance.info.openTypeGaspRangeRecords =[
55-
{
56-
"rangeMaxPPEM" : 9,
57-
"rangeGaspBehavior" : [1,3]
58-
},
59-
{
60-
"rangeMaxPPEM" : 50,
61-
"rangeGaspBehavior" : [0,1,2,3]
62-
},
63-
{
64-
"rangeMaxPPEM" : 65535,
65-
"rangeGaspBehavior" : [1,3]
66-
},
67-
]
49+
for format in ["ttf","otf"]:
50+
instance = generator.generate_instance(instance_descriptor)
51+
52+
for step in steps:
53+
step(instance)
54+
55+
instance.info.openTypeOS2Panose = [2, 11, 6, 9, 2, 0, 0, 2, 0, 4]
56+
57+
if format == "ttf":
58+
instance.info.openTypeGaspRangeRecords =[
59+
{
60+
"rangeMaxPPEM" : 9,
61+
"rangeGaspBehavior" : [1,3]
62+
},
63+
{
64+
"rangeMaxPPEM" : 50,
65+
"rangeGaspBehavior" : [0,1,2,3]
66+
},
67+
{
68+
"rangeMaxPPEM" : 65535,
69+
"rangeGaspBehavior" : [1,3]
70+
},
71+
]
6872

69-
familyName = instance.info.familyName
70-
file_name = f"{familyName}.ttf".replace(" ", "")
71-
file_path = OUTPUT_DIR / file_name
73+
familyName = instance.info.familyName
7274

73-
print(f"[{familyName}] Compiling")
74-
instance_font = ufo2ft.compileTTF(instance, removeOverlaps=True, inplace=True)
75+
file_stem = instance.info.familyName.replace(" ", "")
76+
file_path = (OUTPUT_DIR / file_stem).with_suffix(f".{format}")
7577

76-
print(f"[{familyName}] Merging VTT")
77-
vttLib.transfer.merge_from_file(instance_font, VTT_DATA_FILE)
78+
print(f"[{familyName}] Compiling")
79+
if format == "ttf":
80+
instance_font = ufo2ft.compileTTF(instance, removeOverlaps=True, inplace=True)
81+
else:
82+
instance_font = ufo2ft.compileOTF(instance, removeOverlaps=True, inplace=True)
7883

79-
print(f"[{familyName}] Saving")
80-
instance_font.save(file_path)
84+
if format == "ttf":
85+
print(f"[{familyName}] Merging VTT")
86+
vttLib.transfer.merge_from_file(instance_font, VTT_DATA_FILE)
8187

82-
print(f"[{familyName}] Done: {file_path}")
88+
print(f"[{familyName}] Saving")
89+
instance_font.save(file_path)
90+
91+
print(f"[{familyName}] Done: {file_path}")
8392

8493

8594
if __name__ == "__main__":
@@ -167,5 +176,10 @@ def build_font_instance(generator, instance_descriptor, *steps):
167176
step_merge_nf,
168177
)
169178

170-
print("All done")
171-
print("*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***")
179+
print("Autohinting OTFs")
180+
181+
for file in Path("build").glob("*.otf"):
182+
subprocess.run(['psautohint --log "build/log.txt" '+str(file)], shell=True)
183+
184+
print("All done")
185+
print("*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***")

build_WOFF.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
from pathlib import Path
3+
4+
from fontTools import ttLib
5+
6+
for file in Path("build").glob("*.ttf"):
7+
ttfile = ttLib.TTFont(file)
8+
9+
if "TSI0" in ttfile:
10+
print(f"[{file}] – ERROR: VTT production tables present, WOFF not generated")
11+
print("Please ship from VTT")
12+
else:
13+
print(f"{file}: Generating WOFF2")
14+
ttfile.flavor = "woff2"
15+
ttfile.save(file.with_suffix(".woff2"))
16+
17+
print("All done")
18+
print("*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***")

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
appdirs==1.4.3 # via fs
99
attrs==19.1.0 # via fontmake, ufolib2
1010
booleanoperations==0.8.2 # via fontmake, ufo2ft
11+
Brotli==1.0.7 # for WOFF2 generation
1112
compreffor==0.4.6.post1 # via ufo2ft
1213
cu2qu==1.6.6 # via fontmake, ufo2ft
1314
defcon[lxml]==0.6.0 # via fontmake, glyphslib, mutatormath, ufo2ft
@@ -18,6 +19,7 @@ fs==2.4.11 # via fonttools
1819
glyphslib==5.0.1 # via fontmake
1920
lxml==4.4.1 # via fonttools
2021
mutatormath==2.1.2 # via fontmake
22+
psautohint==2.0.1 # for OTF generation
2123
pyclipper==1.1.0.post1 # via booleanoperations
2224
pyparsing==2.4.2
2325
pytz==2019.2 # via fs

sources/CascadiaCode-Regular.ufo/glyphs/blackC_ircle.glif

-14
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,4 @@ H18533
2121
<point x="284" y="185"/>
2222
</contour>
2323
</outline>
24-
<lib>
25-
<dict>
26-
<key>assembly</key>
27-
<string>PUSHW[ ] /* 1 value pushed */
28-
0
29-
CALL[ ] /* CallFunction */
30-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
31-
PUSHW[ ] /* 3 values pushed */
32-
15 5 3
33-
CALL[ ] /* CallFunction */
34-
IUP[0] /* InterpolateUntPts */
35-
IUP[1] /* InterpolateUntPts */</string>
36-
</dict>
37-
</lib>
3824
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackD_iamond.glif

-14
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,4 @@ uni25C6
1313
<point x="0" y="710" type="line"/>
1414
</contour>
1515
</outline>
16-
<lib>
17-
<dict>
18-
<key>assembly</key>
19-
<string>PUSHW[ ] /* 1 value pushed */
20-
0
21-
CALL[ ] /* CallFunction */
22-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
23-
PUSHW[ ] /* 3 values pushed */
24-
1 3 3
25-
CALL[ ] /* CallFunction */
26-
IUP[0] /* InterpolateUntPts */
27-
IUP[1] /* InterpolateUntPts */</string>
28-
</dict>
29-
</lib>
3016
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackH_exagon.glif

-14
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,4 @@ uni2B22
1515
<point x="80" y="410" type="line"/>
1616
</contour>
1717
</outline>
18-
<lib>
19-
<dict>
20-
<key>assembly</key>
21-
<string>PUSHW[ ] /* 1 value pushed */
22-
0
23-
CALL[ ] /* CallFunction */
24-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
25-
PUSHW[ ] /* 3 values pushed */
26-
4 1 3
27-
CALL[ ] /* CallFunction */
28-
IUP[0] /* InterpolateUntPts */
29-
IUP[1] /* InterpolateUntPts */</string>
30-
</dict>
31-
</lib>
3218
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackH_orizontalE_llipse.glif

-14
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,4 @@ uni2B2C
2121
<point x="284" y="395"/>
2222
</contour>
2323
</outline>
24-
<lib>
25-
<dict>
26-
<key>assembly</key>
27-
<string>PUSHW[ ] /* 1 value pushed */
28-
0
29-
CALL[ ] /* CallFunction */
30-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
31-
PUSHW[ ] /* 3 values pushed */
32-
15 5 3
33-
CALL[ ] /* CallFunction */
34-
IUP[0] /* InterpolateUntPts */
35-
IUP[1] /* InterpolateUntPts */</string>
36-
</dict>
37-
</lib>
3824
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackI_nW_hiteD_iamond.glif

-14
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,4 @@ uni25C8
2525
<point x="424" y="710" type="line"/>
2626
</contour>
2727
</outline>
28-
<lib>
29-
<dict>
30-
<key>assembly</key>
31-
<string>PUSHW[ ] /* 1 value pushed */
32-
0
33-
CALL[ ] /* CallFunction */
34-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
35-
PUSHW[ ] /* 3 values pushed */
36-
0 2 3
37-
CALL[ ] /* CallFunction */
38-
IUP[0] /* InterpolateUntPts */
39-
IUP[1] /* InterpolateUntPts */</string>
40-
</dict>
41-
</lib>
4228
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackL_argeC_ircle.glif

-14
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,4 @@ uni2B24
2121
<point x="238" y="110"/>
2222
</contour>
2323
</outline>
24-
<lib>
25-
<dict>
26-
<key>assembly</key>
27-
<string>PUSHW[ ] /* 1 value pushed */
28-
0
29-
CALL[ ] /* CallFunction */
30-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
31-
PUSHW[ ] /* 3 values pushed */
32-
15 5 3
33-
CALL[ ] /* CallFunction */
34-
IUP[0] /* InterpolateUntPts */
35-
IUP[1] /* InterpolateUntPts */</string>
36-
</dict>
37-
</lib>
3824
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackL_argeS_quare.glif

-14
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,4 @@ uni2B1B
1313
<point x="0" y="1310" type="line"/>
1414
</contour>
1515
</outline>
16-
<lib>
17-
<dict>
18-
<key>assembly</key>
19-
<string>PUSHW[ ] /* 1 value pushed */
20-
0
21-
CALL[ ] /* CallFunction */
22-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
23-
PUSHW[ ] /* 3 values pushed */
24-
0 1 3
25-
CALL[ ] /* CallFunction */
26-
IUP[0] /* InterpolateUntPts */
27-
IUP[1] /* InterpolateUntPts */</string>
28-
</dict>
29-
</lib>
3016
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackM_ediumD_iamond.glif

-24
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,4 @@ uni2B25
1313
<point x="212" y="710" type="line"/>
1414
</contour>
1515
</outline>
16-
<lib>
17-
<dict>
18-
<key>assembly</key>
19-
<string>PUSHW[ ] /* 1 value pushed */
20-
0
21-
CALL[ ] /* CallFunction */
22-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
23-
PUSHW[ ] /* 3 values pushed */
24-
1 3 3
25-
CALL[ ] /* CallFunction */
26-
SVTCA[1] /* SetFreedomAndProjectionVectorToAxis */
27-
PUSHW[ ] /* 3 values pushed */
28-
2 0 3
29-
CALL[ ] /* CallFunction */
30-
PUSHW[ ] /* 1 value pushed */
31-
2
32-
SRP0[ ] /* SetRefPoint0 */
33-
PUSHW[ ] /* 1 value pushed */
34-
5
35-
MDRP[11100] /* MoveDirectRelPt */
36-
IUP[0] /* InterpolateUntPts */
37-
IUP[1] /* InterpolateUntPts */</string>
38-
</dict>
39-
</lib>
4016
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackM_ediumD_ownT_riangleC_entred.glif

-18
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,4 @@ uni2BC6
1212
<point x="262" y="1040" type="line"/>
1313
</contour>
1414
</outline>
15-
<lib>
16-
<dict>
17-
<key>assembly</key>
18-
<string>PUSHW[ ] /* 1 value pushed */
19-
0
20-
CALL[ ] /* CallFunction */
21-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
22-
PUSHW[ ] /* 3 values pushed */
23-
0 1 3
24-
CALL[ ] /* CallFunction */
25-
SVTCA[1] /* SetFreedomAndProjectionVectorToAxis */
26-
PUSHW[ ] /* 3 values pushed */
27-
0 2 3
28-
CALL[ ] /* CallFunction */
29-
IUP[0] /* InterpolateUntPts */
30-
IUP[1] /* InterpolateUntPts */</string>
31-
</dict>
32-
</lib>
3315
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackM_ediumL_eftT_riangleC_entred.glif

-18
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,4 @@ uni2BC7
1212
<point x="266" y="710" type="line"/>
1313
</contour>
1414
</outline>
15-
<lib>
16-
<dict>
17-
<key>assembly</key>
18-
<string>PUSHW[ ] /* 1 value pushed */
19-
0
20-
CALL[ ] /* CallFunction */
21-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
22-
PUSHW[ ] /* 3 values pushed */
23-
0 1 3
24-
CALL[ ] /* CallFunction */
25-
SVTCA[1] /* SetFreedomAndProjectionVectorToAxis */
26-
PUSHW[ ] /* 3 values pushed */
27-
0 2 3
28-
CALL[ ] /* CallFunction */
29-
IUP[0] /* InterpolateUntPts */
30-
IUP[1] /* InterpolateUntPts */</string>
31-
</dict>
32-
</lib>
3315
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackM_ediumL_ozenge.glif

-18
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,4 @@ uni2B27
1313
<point x="328" y="710" type="line"/>
1414
</contour>
1515
</outline>
16-
<lib>
17-
<dict>
18-
<key>assembly</key>
19-
<string>PUSHW[ ] /* 1 value pushed */
20-
0
21-
CALL[ ] /* CallFunction */
22-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
23-
PUSHW[ ] /* 3 values pushed */
24-
1 3 3
25-
CALL[ ] /* CallFunction */
26-
SVTCA[1] /* SetFreedomAndProjectionVectorToAxis */
27-
PUSHW[ ] /* 3 values pushed */
28-
2 0 3
29-
CALL[ ] /* CallFunction */
30-
IUP[0] /* InterpolateUntPts */
31-
IUP[1] /* InterpolateUntPts */</string>
32-
</dict>
33-
</lib>
3416
</glyph>

sources/CascadiaCode-Regular.ufo/glyphs/blackM_ediumR_ightT_riangleC_entred.glif

-18
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,4 @@ uni2BC8
1212
<point x="360" y="1048" type="line"/>
1313
</contour>
1414
</outline>
15-
<lib>
16-
<dict>
17-
<key>assembly</key>
18-
<string>PUSHW[ ] /* 1 value pushed */
19-
0
20-
CALL[ ] /* CallFunction */
21-
SVTCA[0] /* SetFreedomAndProjectionVectorToAxis */
22-
PUSHW[ ] /* 3 values pushed */
23-
0 2 3
24-
CALL[ ] /* CallFunction */
25-
SVTCA[1] /* SetFreedomAndProjectionVectorToAxis */
26-
PUSHW[ ] /* 3 values pushed */
27-
1 0 3
28-
CALL[ ] /* CallFunction */
29-
IUP[0] /* InterpolateUntPts */
30-
IUP[1] /* InterpolateUntPts */</string>
31-
</dict>
32-
</lib>
3315
</glyph>

0 commit comments

Comments
 (0)