forked from source-foundry/Hack
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-ttf.sh
executable file
·223 lines (189 loc) · 7.58 KB
/
build-ttf.sh
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
#!/bin/sh
# /////////////////////////////////////////////////////////////////
#
# build-ttf.sh
# A shell script that builds the Hack ttf fonts from UFO source
# Copyright 2017 Christopher Simpkins
# MIT License
#
# Usage: ./build-ttf.sh (--install-dependencies)
# Arguments:
# --install-dependencies (optional) - installs all
# build dependencies prior to the build script execution
#
# /////////////////////////////////////////////////////////////////
# 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"
# test for number of arguments
if [ $# -gt 1 ]
then
echo "Inappropriate arguments included in your command." 1>&2
echo "Usage: ./build-ttf.sh (--install-dependencies)" 1>&2
exit 1
fi
# Optional build dependency install request with syntax `./build.sh --install-dependencies`
if [ "$1" = "--install-dependencies" ]
then
# fontmake
pip install --upgrade fontmake
# fontTools (installed with fontmake at this time. leave this as dependency check as python scripts for fixes require it should fontTools eliminate dep)
pip install --upgrade fonttools
# ttfautohint v1.6 (must be pinned to v1.6 and above for Hack instruction sets)
tools/scripts/install/ttfautohint-build.sh
fi
# confirm executable installs and library imports for build dependencies
INSTALLFLAG=0
echo "Confirming that build dependencies are installed..."
echo " "
# fontmake installed
if ! which fontmake
then
echo "Unable to install fontmake with 'pip install fontmake'. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
INSTALLFLAG=1
fi
# fontTools python library can be imported
if ! python -c "import fontTools"
then
echo "Unable to install fontTools with 'pip install fonttools'. Please attempt a manual install of this build dependency and then repeat your build attempt." 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 "Unable to install ttfautohint from source. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
INSTALLFLAG=1
else
TTFAH="ttfautohint" # revise TTFAH variable to ttfautohint installed on the user's PATH for excecution of hints below
fi
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
# Desktop ttf font build
echo "Starting build..."
echo " "
# remove any existing release files from the build directory
if [ -f "build/ttf/Hack-Regular.ttf" ]; then
rm build/ttf/Hack-Regular.ttf
fi
if [ -f "build/ttf/Hack-Italic.ttf" ]; then
rm build/ttf/Hack-Italic.ttf
fi
if [ -f "build/ttf/Hack-Bold.ttf" ]; then
rm build/ttf/Hack-Bold.ttf
fi
if [ -f "build/ttf/Hack-BoldItalic.ttf" ]; then
rm build/ttf/Hack-BoldItalic.ttf
fi
# 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 set
if ! fontmake -u "source/Hack-Regular.ufo" -o ttf
then
echo "Unable to build the Hack-Regular variant set. Build canceled." 1>&2
exit 1
fi
# build bold set
if ! fontmake -u "source/Hack-Bold.ufo" -o ttf
then
echo "Unable to build the Hack-Bold variant set. Build canceled." 1>&2
exit 1
fi
# build italic set
if ! fontmake -u "source/Hack-Italic.ufo" -o ttf
then
echo "Unable to build the Hack-Italic variant set. Build canceled." 1>&2
exit 1
fi
# build bold italic set
if ! fontmake -u "source/Hack-BoldItalic.ufo" -o ttf
then
echo "Unable to build the Hack-BoldItalic variant set. Build canceled." 1>&2
exit 1
fi
# Desktop ttf font 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
# Desktop ttf font hinting
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 set. Build canceled." 1>&2
exit 1
fi
echo "master_ttf/Hack-Regular.ttf - 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 set. Build canceled." 1>&2
exit 1
fi
echo "master_ttf/Hack-Bold.ttf - 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 set. Build canceled." 1>&2
exit 1
fi
echo "master_ttf/Hack-Italic.ttf - 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 set. Build canceled." 1>&2
exit 1
fi
echo "master_ttf/Hack-BoldItalic.ttf - successful hinting with ttfautohint"
echo " "
# Move release files to build directory
echo " "
# create directory if it does not exist
# (occurs with git + empty directories)
if ! [ -d build/ttf ]; then
mkdir build/ttf
fi
mv master_ttf/hinted/Hack-Regular.ttf build/ttf/Hack-Regular.ttf
echo "Regular ttf build path: build/ttf/Hack-Regular.ttf"
mv master_ttf/hinted/Hack-Italic.ttf build/ttf/Hack-Italic.ttf
echo "Italic ttf build path: build/ttf/Hack-Italic.ttf"
mv master_ttf/hinted/Hack-Bold.ttf build/ttf/Hack-Bold.ttf
echo "Bold ttf build path: build/ttf/Hack-Bold.ttf"
mv master_ttf/hinted/Hack-BoldItalic.ttf build/ttf/Hack-BoldItalic.ttf
echo "Bold Italic ttf build path: build/ttf/Hack-BoldItalic.ttf"
# Remove master_ttf directory
rm -rf master_ttf