|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# ///////////////////////////////////////////////////////////////// |
| 4 | +# |
| 5 | +# build-ttf.sh |
| 6 | +# A shell script that builds the Hack ttf fonts from UFO source |
| 7 | +# Copyright 2018 Christopher Simpkins |
| 8 | +# MIT License |
| 9 | +# |
| 10 | +# Usage: ./build-ttf.sh (--install-dependencies) |
| 11 | +# Arguments: |
| 12 | +# --install-dependencies (optional) - installs all |
| 13 | +# build dependencies prior to the build script execution |
| 14 | +# |
| 15 | +# ///////////////////////////////////////////////////////////////// |
| 16 | + |
| 17 | +# ttfautohint local install path from Werner Lemberg's ttfautohint-build.sh install script |
| 18 | +# - This is revised to ttfautohint on the user's PATH if this local install is not identified |
| 19 | +# then the identified ttfautohint is used to execute hinting. Versions of ttfautohint < 1.6 exit with status |
| 20 | +# code 1 due to use of -R option |
| 21 | +# - The intent is to support use of ttfautohint installed on a user's PATH (e.g. they've previously installed it) |
| 22 | +TTFAH="$HOME/ttfautohint-build/local/bin/ttfautohint" |
| 23 | + |
| 24 | +# test for number of arguments |
| 25 | +if [ $# -gt 1 ] |
| 26 | + then |
| 27 | + echo "Inappropriate arguments included in your command." 1>&2 |
| 28 | + echo "Usage: ./build-ttf.sh (--install-dependencies)" 1>&2 |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +# Optional build dependency install request with syntax `./build.sh --install-dependencies` |
| 33 | +if [ "$1" = "--install-dependencies" ] |
| 34 | + then |
| 35 | + # fontmake |
| 36 | + pip install --upgrade fontmake |
| 37 | + # fontTools (installed with fontmake at this time. leave this as dependency check as python scripts for fixes require it should fontTools eliminate dep) |
| 38 | + pip install --upgrade fonttools |
| 39 | + # ttfautohint v1.6 (must be pinned to v1.6 and above for Hack instruction sets) |
| 40 | + tools/scripts/install/ttfautohint-build.sh |
| 41 | + |
| 42 | +fi |
| 43 | + |
| 44 | +# confirm executable installs and library imports for build dependencies |
| 45 | +INSTALLFLAG=0 |
| 46 | + |
| 47 | +echo "Confirming that build dependencies are installed..." |
| 48 | +echo " " |
| 49 | +# fontmake installed |
| 50 | +if ! which fontmake |
| 51 | + then |
| 52 | + 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 |
| 53 | + INSTALLFLAG=1 |
| 54 | +fi |
| 55 | +# fontTools python library can be imported |
| 56 | +if ! python -c "import fontTools" |
| 57 | + then |
| 58 | + 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 |
| 59 | + INSTALLFLAG=1 |
| 60 | +else |
| 61 | + echo "fontTools Python library identified" |
| 62 | +fi |
| 63 | +# ttfautohint installed |
| 64 | +# - tests for install to local path from ttfautohint-build.sh script |
| 65 | +# - 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 |
| 66 | +if ! [ -f "$TTFAH" ] |
| 67 | + then |
| 68 | + if ! which ttfautohint |
| 69 | + then |
| 70 | + echo "Unable to install ttfautohint from source. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2 |
| 71 | + INSTALLFLAG=1 |
| 72 | + else |
| 73 | + TTFAH="ttfautohint" # revise TTFAH variable to ttfautohint installed on the user's PATH for excecution of hints below |
| 74 | + fi |
| 75 | +fi |
| 76 | +# if any of the dependency installs failed, exit and do not attempt build, notify user |
| 77 | +if [ $INSTALLFLAG -eq 1 ] |
| 78 | + then |
| 79 | + echo "Build canceled." 1>&2 |
| 80 | + exit 1 |
| 81 | +fi |
| 82 | + |
| 83 | +# Desktop ttf font build |
| 84 | + |
| 85 | +echo "Starting build..." |
| 86 | +echo " " |
| 87 | + |
| 88 | +# remove any existing release files from the build directory |
| 89 | +if [ -f "build/ttf/Hack-Regular.ttf" ]; then |
| 90 | + rm build/ttf/Hack-Regular.ttf |
| 91 | +fi |
| 92 | + |
| 93 | +if [ -f "build/ttf/Hack-Italic.ttf" ]; then |
| 94 | + rm build/ttf/Hack-Italic.ttf |
| 95 | +fi |
| 96 | + |
| 97 | +if [ -f "build/ttf/Hack-Bold.ttf" ]; then |
| 98 | + rm build/ttf/Hack-Bold.ttf |
| 99 | +fi |
| 100 | + |
| 101 | +if [ -f "build/ttf/Hack-BoldItalic.ttf" ]; then |
| 102 | + rm build/ttf/Hack-BoldItalic.ttf |
| 103 | +fi |
| 104 | + |
| 105 | +# remove master_ttf directory if a previous build failed + exited early and it was not cleaned up |
| 106 | + |
| 107 | +if [ -d "master_ttf" ]; then |
| 108 | + rm -rf master_ttf |
| 109 | +fi |
| 110 | + |
| 111 | +# build regular set |
| 112 | + |
| 113 | +if ! fontmake -u "source/Hack-Regular.ufo" -o ttf |
| 114 | + then |
| 115 | + echo "Unable to build the Hack-Regular variant set. Build canceled." 1>&2 |
| 116 | + exit 1 |
| 117 | +fi |
| 118 | + |
| 119 | +# build bold set |
| 120 | +if ! fontmake -u "source/Hack-Bold.ufo" -o ttf |
| 121 | + then |
| 122 | + echo "Unable to build the Hack-Bold variant set. Build canceled." 1>&2 |
| 123 | + exit 1 |
| 124 | +fi |
| 125 | + |
| 126 | +# build italic set |
| 127 | +if ! fontmake -u "source/Hack-Italic.ufo" -o ttf |
| 128 | + then |
| 129 | + echo "Unable to build the Hack-Italic variant set. Build canceled." 1>&2 |
| 130 | + exit 1 |
| 131 | +fi |
| 132 | + |
| 133 | +# build bold italic set |
| 134 | + |
| 135 | +if ! fontmake -u "source/Hack-BoldItalic.ufo" -o ttf |
| 136 | + then |
| 137 | + echo "Unable to build the Hack-BoldItalic variant set. Build canceled." 1>&2 |
| 138 | + exit 1 |
| 139 | +fi |
| 140 | + |
| 141 | +# Desktop ttf font post build fixes |
| 142 | + |
| 143 | +# DSIG table fix with adapted fontbakery Python script |
| 144 | +echo " " |
| 145 | +echo "Attempting DSIG table fixes with fontbakery..." |
| 146 | +echo " " |
| 147 | +if ! python postbuild_processing/fixes/fix-dsig.py master_ttf/*.ttf |
| 148 | + then |
| 149 | + echo "Unable to complete DSIG table fixes on the release files" |
| 150 | + exit 1 |
| 151 | +fi |
| 152 | + |
| 153 | +# fstype value fix with adapted fontbakery Python script |
| 154 | +echo " " |
| 155 | +echo "Attempting fstype fixes with fontbakery..." |
| 156 | +echo " " |
| 157 | +if ! python postbuild_processing/fixes/fix-fstype.py master_ttf/*.ttf |
| 158 | + then |
| 159 | + echo "Unable to complete fstype fixes on the release files" |
| 160 | + exit 1 |
| 161 | +fi |
| 162 | + |
| 163 | +# Desktop ttf font hinting |
| 164 | + |
| 165 | +echo " " |
| 166 | +echo "Attempting ttfautohint hinting..." |
| 167 | +echo " " |
| 168 | +# make a temporary directory for the hinted files |
| 169 | +mkdir master_ttf/hinted |
| 170 | + |
| 171 | +# Hack-Regular.ttf |
| 172 | +if ! "$TTFAH" -l 6 -r 50 -x 10 -H 181 -D latn -f latn -w G -W -t -X "" -I -m "postbuild_processing/tt-hinting/Hack-Regular-TA.txt" "master_ttf/Hack-Regular.ttf" "master_ttf/hinted/Hack-Regular.ttf" |
| 173 | + then |
| 174 | + echo "Unable to execute ttfautohint on the Hack-Regular variant set. Build canceled." 1>&2 |
| 175 | + exit 1 |
| 176 | +fi |
| 177 | +echo "master_ttf/Hack-Regular.ttf - successful hinting with ttfautohint" |
| 178 | + |
| 179 | +# Hack-Bold.ttf |
| 180 | +if ! "$TTFAH" -l 6 -r 50 -x 10 -H 260 -D latn -f latn -w G -W -t -X "" -I -m "postbuild_processing/tt-hinting/Hack-Bold-TA.txt" "master_ttf/Hack-Bold.ttf" "master_ttf/hinted/Hack-Bold.ttf" |
| 181 | + then |
| 182 | + echo "Unable to execute ttfautohint on the Hack-Bold variant set. Build canceled." 1>&2 |
| 183 | + exit 1 |
| 184 | +fi |
| 185 | +echo "master_ttf/Hack-Bold.ttf - successful hinting with ttfautohint" |
| 186 | + |
| 187 | +# Hack-Italic.ttf |
| 188 | +if ! "$TTFAH" -l 6 -r 50 -x 10 -H 145 -D latn -f latn -w G -W -t -X "" -I -m "postbuild_processing/tt-hinting/Hack-Italic-TA.txt" "master_ttf/Hack-Italic.ttf" "master_ttf/hinted/Hack-Italic.ttf" |
| 189 | + then |
| 190 | + echo "Unable to execute ttfautohint on the Hack-Italic variant set. Build canceled." 1>&2 |
| 191 | + exit 1 |
| 192 | +fi |
| 193 | +echo "master_ttf/Hack-Italic.ttf - successful hinting with ttfautohint" |
| 194 | + |
| 195 | +# Hack-BoldItalic.ttf |
| 196 | +if ! "$TTFAH" -l 6 -r 50 -x 10 -H 265 -D latn -f latn -w G -W -t -X "" -I -m "postbuild_processing/tt-hinting/Hack-BoldItalic-TA.txt" "master_ttf/Hack-BoldItalic.ttf" "master_ttf/hinted/Hack-BoldItalic.ttf" |
| 197 | + then |
| 198 | + echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set. Build canceled." 1>&2 |
| 199 | + exit 1 |
| 200 | +fi |
| 201 | +echo "master_ttf/Hack-BoldItalic.ttf - successful hinting with ttfautohint" |
| 202 | +echo " " |
| 203 | + |
| 204 | +# Move release files to build directory |
| 205 | +echo " " |
| 206 | + |
| 207 | +# create directory if it does not exist |
| 208 | +# (occurs with git + empty directories) |
| 209 | +if ! [ -d build/ttf ]; then |
| 210 | + mkdir build/ttf |
| 211 | +fi |
| 212 | + |
| 213 | +mv master_ttf/hinted/Hack-Regular.ttf build/ttf/Hack-Regular.ttf |
| 214 | +echo "Regular ttf build path: build/ttf/Hack-Regular.ttf" |
| 215 | +mv master_ttf/hinted/Hack-Italic.ttf build/ttf/Hack-Italic.ttf |
| 216 | +echo "Italic ttf build path: build/ttf/Hack-Italic.ttf" |
| 217 | +mv master_ttf/hinted/Hack-Bold.ttf build/ttf/Hack-Bold.ttf |
| 218 | +echo "Bold ttf build path: build/ttf/Hack-Bold.ttf" |
| 219 | +mv master_ttf/hinted/Hack-BoldItalic.ttf build/ttf/Hack-BoldItalic.ttf |
| 220 | +echo "Bold Italic ttf build path: build/ttf/Hack-BoldItalic.ttf" |
| 221 | + |
| 222 | +# Remove master_ttf directory |
| 223 | +rm -rf master_ttf |
0 commit comments