File: build-subsets.sh

package info (click to toggle)
fonts-hack 3.003-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 31,560 kB
  • sloc: sh: 811; python: 129; makefile: 34; xml: 30
file content (466 lines) | stat: -rwxr-xr-x 14,066 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
#!/bin/sh

# //////////////////////////////////////////////////////////////////////
#
# build-subsets.sh
#  A shell script that builds the Hack web font subsets from UFO source
#  Copyright 2018 Christopher Simpkins
#  MIT License
#
#  Usage: ./build-subsets.sh
#
#  NOTE: must install build dependencies in:
#        1) build-ttf.sh
#        2) build-woff.sh
#        3) build-woff2.sh
#       before you execute this script.  You can do this with:
#
#
#       $ ./build-ttf.sh --install-dependencies
#       $ ./build-woff.sh --install-dependencies
#       $ ./build-woff2.sh --install-dependencies
#
# //////////////////////////////////////////////////////////////////////

# ttfautohint local install path from Werner Lemberg's ttfautohint-build.sh install script
#   - This is revised to ttfautohint on the user's PATH if this local install is not identified
#     then the identified ttfautohint is used to execute hinting.  Versions of ttfautohint < 1.6 exit with status
#     code 1 due to use of -R option
#   - The intent is to support use of ttfautohint installed on a user's PATH (e.g. they've previously installed it)
TTFAH="$HOME/ttfautohint-build/local/bin/ttfautohint"

# The sfnt2woff-zopfli build directory.
SFNTWOFF_BUILD="$HOME/sfnt2woff-zopfli-build"

# sfnt2woff-zopfli version
SFNTWOFF_VERSION="1.1.0"
SFNTWOFF="sfnt2woff-zopfli-$SFNTWOFF_VERSION"

# Path to sfnt2woff-zopfli executable
SFNTWOFF_BIN="$SFNTWOFF_BUILD/$SFNTWOFF/sfnt2woff-zopfli"
ZOPFLI_ITERATIONS="3"

# The woff2 git clone directory.
WOFF2_BUILD="$HOME"
# woff2 executable path
WOFF2_BIN="$WOFF2_BUILD/woff2/woff2_compress"

# temporary source directory for subset source files
TEMP_SOURCE="source/temp"

# The font build directory paths and file paths for the woff builds
TTF_BUILD="master_ttf"

REGULAR_TTF="Hack-Regular.ttf"
REGULAR_WOFF_PRE="Hack-Regular.woff"
REGULAR_WOFF="hack-regular-subset.woff"
REGULAR_WOFF2_PRE="Hack-Regular.woff2"
REGULAR_WOFF2="hack-regular-subset.woff2"

BOLD_TTF="Hack-Bold.ttf"
BOLD_WOFF_PRE="Hack-Bold.woff"
BOLD_WOFF="hack-bold-subset.woff"
BOLD_WOFF2_PRE="Hack-Bold.woff2"
BOLD_WOFF2="hack-bold-subset.woff2"

ITALIC_TTF="Hack-Italic.ttf"
ITALIC_WOFF_PRE="Hack-Italic.woff"
ITALIC_WOFF="hack-italic-subset.woff"
ITALIC_WOFF2_PRE="Hack-Italic.woff2"
ITALIC_WOFF2="hack-italic-subset.woff2"

BOLDITALIC_TTF="Hack-BoldItalic.ttf"
BOLDITALIC_WOFF_PRE="Hack-BoldItalic.woff"
BOLDITALIC_WOFF="hack-bolditalic-subset.woff"
BOLDITALIC_WOFF2_PRE="Hack-BoldItalic.woff2"
BOLDITALIC_WOFF2="hack-bolditalic-subset.woff2"

# release directory path for web fonts
WEB_BUILD="build/web/fonts"

# test for number of arguments
if [ $# -gt 0 ]
	then
	    echo "Inappropriate arguments included in your command." 1>&2
	    echo "Usage: ./build-subsets.sh" 1>&2
	    exit 1
fi

# ////////////////////////////////////////
#
#
#  Confirm that dependencies are installed
#
#
# ////////////////////////////////////////

INSTALLFLAG=0

echo "Confirming that build dependencies are installed..."
echo " "

# fontmake installed
if ! which fontmake
	then
	    echo "fontmake was not found.  Please install all build dependencies with 'make build-with-dependencies', then attempt your build again." 1>&2
	    INSTALLFLAG=1
fi

# fontTools python library can be imported
if ! python -c "import fontTools"
	then
	    echo "The fontTools library was not found.  Please install all build dependencies with 'make build-with-dependencies', then attempt your build again." 1>&2
	    INSTALLFLAG=1
else
	echo "fontTools Python library identified"
fi

# ttfautohint installed
#   - tests for install to local path from ttfautohint-build.sh script
#   - if not found on this path, tests for install on system PATH - if found, revises TTFAH to the string "ttfautohint" for execution of instruction sets
if ! [ -f "$TTFAH" ]
	then
	    if ! which ttfautohint
	    	then
	            echo "ttfautohint was not found.  Please install all build dependencies with 'make build-with-dependencies', then attempt your build again." 1>&2
	            INSTALLFLAG=1
	    else
	    	TTFAH="ttfautohint"  # revise TTFAH variable to ttfautohint installed on the user's PATH for excecution of hints below
	    	echo "ttfautohint executable identified"
	    fi
	else
		echo "ttfautohint executable identified"
fi

# sfntwoff-zopfli installed
if ! [ -f "$SFNTWOFF_BIN" ]
	then
	    echo "sfnt2woff-zopfli was not found on the path $SFNTWOFF_BIN.  Please install all build dependencies with 'make build-with-dependencies', then attempt your build again." 1>&2
	    INSTALLFLAG=1
else
	echo "sfnt2woff-zopfli executable identified"
fi

# woff2 installed
if ! [ -f "$WOFF2_BIN" ]
	then
	    echo "woff2_compress was not found on the path $WOFF2_BIN.  Please install all build dependencies with 'make build-with-dependencies', then attempt your build again." 1>&2
	    INSTALLFLAG=1
else
	echo "woff2_compress executable identified"
fi

# if any of the dependency installs failed, exit and do not attempt build, notify user
if [ $INSTALLFLAG -eq 1 ]
	then
	    echo "Build canceled." 1>&2
	    exit 1
fi

# ////////////////////////////////////////////////
#
#
#  Create temporary source files with lib.plist
#    replacements that include subset definitions
#
#
# ////////////////////////////////////////////////

# cleanup any previously created temp directory that was not removed
if ! [ -d "$TEMP_SOURCE" ]; then
	rm -rf $TEMP_SOURCE
fi

# create temp directory for subset source files
mkdir $TEMP_SOURCE

# copy source to temporary directory
cp -r source/Hack-Regular.ufo $TEMP_SOURCE/Hack-Regular.ufo
cp -r source/Hack-Italic.ufo $TEMP_SOURCE/Hack-Italic.ufo
cp -r source/Hack-Bold.ufo $TEMP_SOURCE/Hack-Bold.ufo
cp -r source/Hack-BoldItalic.ufo $TEMP_SOURCE/Hack-BoldItalic.ufo

# copy lib.plist files with subset definitions to temporary source directories
cp source/subset-lib/lib-regular.plist $TEMP_SOURCE/Hack-Regular.ufo/lib.plist
cp source/subset-lib/lib-italic.plist $TEMP_SOURCE/Hack-Italic.ufo/lib.plist
cp source/subset-lib/lib-bold.plist $TEMP_SOURCE/Hack-Bold.ufo/lib.plist
cp source/subset-lib/lib-bolditalic.plist $TEMP_SOURCE/Hack-BoldItalic.ufo/lib.plist

# /////////////////////////////////////////////
#
#
#  Begin subset ttf font build from UFO source
#
#
# /////////////////////////////////////////////

echo "Starting web font subset build..."
echo " "

# remove master_ttf directory if a previous build failed + exited early and it was not cleaned up
if [ -d "master_ttf" ]; then
	rm -rf master_ttf
fi

# build regular subset

if ! fontmake --subset -u "$TEMP_SOURCE/Hack-Regular.ufo" -o ttf
	then
	    echo "Unable to build the Hack-Regular variant subset.  Build canceled." 1>&2
	    exit 1
fi

# build bold subset
if ! fontmake --subset -u "$TEMP_SOURCE/Hack-Bold.ufo" -o ttf
	then
	    echo "Unable to build the Hack-Bold variant subset.  Build canceled." 1>&2
	    exit 1
fi

# build italic subset
if ! fontmake --subset -u "$TEMP_SOURCE/Hack-Italic.ufo" -o ttf
	then
	    echo "Unable to build the Hack-Italic variant subset.  Build canceled." 1>&2
	    exit 1
fi

# build bold italic subset

if ! fontmake --subset -u "$TEMP_SOURCE/Hack-BoldItalic.ufo" -o ttf
	then
	    echo "Unable to build the Hack-BoldItalic variant subset.  Build canceled." 1>&2
	    exit 1
fi


# /////////////////////////////////////////////
#
#
#  Post build fixes
#
#
# /////////////////////////////////////////////

# DSIG table fix with adapted fontbakery Python script
echo " "
echo "Attempting DSIG table fixes with fontbakery..."
echo " "
if ! python postbuild_processing/fixes/fix-dsig.py master_ttf/*.ttf
	then
	    echo "Unable to complete DSIG table fixes on the release files"
	    exit 1
fi

# fstype value fix with adapted fontbakery Python script
echo " "
echo "Attempting fstype fixes with fontbakery..."
echo " "
if ! python postbuild_processing/fixes/fix-fstype.py master_ttf/*.ttf
	then
	    echo "Unable to complete fstype fixes on the release files"
	    exit 1
fi

# /////////////////////////////////////////////
#
#
#  Hinting of ttf subsets
#
#
# /////////////////////////////////////////////

echo " "
echo "Attempting ttfautohint hinting..."
echo " "
# make a temporary directory for the hinted files
mkdir master_ttf/hinted

# Hack-Regular.ttf
if ! "$TTFAH" -l 6 -r 50 -x 10 -H 181 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Regular-TA.txt" "master_ttf/Hack-Regular.ttf" "master_ttf/hinted/Hack-Regular.ttf"
	then
	    echo "Unable to execute ttfautohint on the Hack-Regular variant subset.  Build canceled." 1>&2
	    exit 1
fi
echo "master_ttf/Hack-Regular.ttf subset - successful hinting with ttfautohint"

# Hack-Bold.ttf
if ! "$TTFAH" -l 6 -r 50 -x 10 -H 260 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Bold-TA.txt" "master_ttf/Hack-Bold.ttf" "master_ttf/hinted/Hack-Bold.ttf"
	then
	    echo "Unable to execute ttfautohint on the Hack-Bold variant subset.  Build canceled." 1>&2
	    exit 1
fi
echo "master_ttf/Hack-Bold.ttf subset - successful hinting with ttfautohint"

# Hack-Italic.ttf
if ! "$TTFAH" -l 6 -r 50 -x 10 -H 145 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Italic-TA.txt" "master_ttf/Hack-Italic.ttf" "master_ttf/hinted/Hack-Italic.ttf"
	then
	    echo "Unable to execute ttfautohint on the Hack-Italic variant subset.  Build canceled." 1>&2
	    exit 1
fi
echo "master_ttf/Hack-Italic.ttf subset - successful hinting with ttfautohint"

# Hack-BoldItalic.ttf
if ! "$TTFAH" -l 6 -r 50 -x 10 -H 265 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-BoldItalic-TA.txt" "master_ttf/Hack-BoldItalic.ttf" "master_ttf/hinted/Hack-BoldItalic.ttf"
	then
	    echo "Unable to execute ttfautohint on the Hack-BoldItalic variant subset.  Build canceled." 1>&2
	    exit 1
fi
echo "master_ttf/Hack-BoldItalic.ttf subset - successful hinting with ttfautohint"
echo " "

# /////////////////////////////////////////////
#
#
#  Build woff subsets
#
#
# /////////////////////////////////////////////

# regular set
if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$REGULAR_TTF"; then
	echo "Failed to build $REGULAR_WOFF from $REGULAR_TTF." 1>&2
	exit 1
else
	echo "Regular woff subset successfully built from $REGULAR_TTF"
fi

# bold set
if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$BOLD_TTF"; then
	echo "Failed to build $BOLD_WOFF from $BOLD_TTF" 1>&2
	exit 1
else
	echo "Bold woff subset successfully built from $BOLD_TTF"
fi

# italic set
if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$ITALIC_TTF"; then
	echo "Failed to build $BOLD_WOFF from $ITALIC_TTF" 1>&2
	exit 1
else
	echo "Italic woff subset successfully built from $ITALIC_TTF"
fi

# bold italic set
if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$BOLDITALIC_TTF"; then
	echo "Failed to build $BOLDITALIC_WOFF from $BOLDITALIC_TTF" 1>&2
	exit 1
else
	echo "Bold Italic woff subset successfully built from $BOLDITALIC_TTF"
fi

# /////////////////////////////////////////////
#
#
#  Build woff2 subsets
#
#
# /////////////////////////////////////////////

echo " "

# regular set
if ! "$WOFF2_BIN" "$TTF_BUILD/$REGULAR_TTF"; then
	echo "Failed to build woff2 subset from $REGULAR_TTF." 1>&2
	exit 1
else
	echo "Regular woff2 font subset successfully built from $REGULAR_TTF"
fi

# bold set
if ! "$WOFF2_BIN" "$TTF_BUILD/$BOLD_TTF"; then
	echo "Failed to build woff2 subset from $BOLD_TTF" 1>&2
	exit 1
else
	echo "Bold woff2 subset successfully built from $BOLD_TTF"
fi

# italic set
if ! "$WOFF2_BIN" "$TTF_BUILD/$ITALIC_TTF"; then
	echo "Failed to build woff2 subset from $ITALIC_TTF" 1>&2
	exit 1
else
	echo "Italic woff2 subset successfully built from $ITALIC_TTF"
fi

# bold italic set
if ! "$WOFF2_BIN" "$TTF_BUILD/$BOLDITALIC_TTF"; then
	echo "Failed to build woff2 subset from $BOLDITALIC_TTF" 1>&2
	exit 1
else
	echo "Bold Italic woff2 subset successfully built from $BOLDITALIC_TTF"
fi


# //////////////////////////////////////////////
#
#
#  Move web font subset files to build directory
#
#
# //////////////////////////////////////////////

# create the build directory if it does not exist
if ! [ -d "$WEB_BUILD" ]; then
	mkdir $WEB_BUILD
fi

echo " "
echo "Moving woff files to build directory..."

# move woff files to appropriate build directory
mv "$TTF_BUILD/$REGULAR_WOFF_PRE" "$WEB_BUILD/$REGULAR_WOFF"
mv "$TTF_BUILD/$BOLD_WOFF_PRE" "$WEB_BUILD/$BOLD_WOFF"
mv "$TTF_BUILD/$ITALIC_WOFF_PRE" "$WEB_BUILD/$ITALIC_WOFF"
mv "$TTF_BUILD/$BOLDITALIC_WOFF_PRE" "$WEB_BUILD/$BOLDITALIC_WOFF"

if [ -f "$WEB_BUILD/$REGULAR_WOFF" ]; then
	echo "Regular woff build path: $WEB_BUILD/$REGULAR_WOFF"
fi

if [ -f "$WEB_BUILD/$BOLD_WOFF" ]; then
	echo "Bold woff build path: $WEB_BUILD/$BOLD_WOFF"
fi

if [ -f "$WEB_BUILD/$ITALIC_WOFF" ]; then
	echo "Italic woff build path: $WEB_BUILD/$ITALIC_WOFF"
fi

if [ -f "$WEB_BUILD/$BOLDITALIC_WOFF" ]; then
	echo "Bold Italic woff build path: $WEB_BUILD/$BOLDITALIC_WOFF"
fi

echo "Moving woff2 files to build directory..."

# move woff files to appropriate build directory
mv "$TTF_BUILD/$REGULAR_WOFF2_PRE" "$WEB_BUILD/$REGULAR_WOFF2"
mv "$TTF_BUILD/$BOLD_WOFF2_PRE" "$WEB_BUILD/$BOLD_WOFF2"
mv "$TTF_BUILD/$ITALIC_WOFF2_PRE" "$WEB_BUILD/$ITALIC_WOFF2"
mv "$TTF_BUILD/$BOLDITALIC_WOFF2_PRE" "$WEB_BUILD/$BOLDITALIC_WOFF2"

if [ -f "$WEB_BUILD/$REGULAR_WOFF2" ]; then
	echo "Regular woff2 subset build path: $WEB_BUILD/$REGULAR_WOFF2"
fi

if [ -f "$WEB_BUILD/$BOLD_WOFF2" ]; then
	echo "Bold woff2 subset build path: $WEB_BUILD/$BOLD_WOFF2"
fi

if [ -f "$WEB_BUILD/$ITALIC_WOFF2" ]; then
	echo "Italic woff2 subset build path: $WEB_BUILD/$ITALIC_WOFF2"
fi

if [ -f "$WEB_BUILD/$BOLDITALIC_WOFF2" ]; then
	echo "Bold Italic woff2 subset build path: $WEB_BUILD/$BOLDITALIC_WOFF2"
fi

# //////////////////////////////////////////////
#
#
#  Cleanup temp directory
#
#
# //////////////////////////////////////////////

rm -rf master_ttf
rm -rf "$TEMP_SOURCE"