build-ttf.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #!/bin/sh
  2. # /////////////////////////////////////////////////////////////////
  3. #
  4. # build-ttf.sh
  5. # A shell script that builds the Hack ttf fonts from UFO source
  6. # Copyright 2018 Christopher Simpkins
  7. # MIT License
  8. #
  9. # Usage: ./build-ttf.sh (--system)
  10. # Arguments:
  11. # --system (optional) - use system installed build dependencies
  12. #
  13. # /////////////////////////////////////////////////////////////////
  14. # set SOURCE_DATE_EPOCH to git commit date/time for reproducible builds
  15. SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD)
  16. # default build tooling definitions
  17. TTFAH="$HOME/ttfautohint-build/local/bin/ttfautohint"
  18. FONTMAKE="pipenv run fontmake"
  19. PYTHON="pipenv run python"
  20. INSTALLFLAG=0
  21. # test for number of arguments
  22. if [ $# -gt 1 ]
  23. then
  24. echo "Inappropriate arguments included in your command." 1>&2
  25. echo "Usage: ./build-ttf.sh (--system)" 1>&2
  26. exit 1
  27. fi
  28. # Optional build with system-installed build dependencies instead of pinned build process defined versions
  29. if [ "$1" = "--system" ]
  30. then
  31. # re-define the default executables to executables that exist on PATH
  32. TTFAH="ttfautohint"
  33. FONTMAKE="fontmake"
  34. PYTHON="python3"
  35. echo "================================="
  36. echo " BUILD ENVIRONMENT"
  37. echo "================================="
  38. # test re-defined system-installed build dependency paths
  39. if ! which "$TTFAH"; then
  40. echo "Unable to identify a system installed version of ttfautohint. Please install and try again." 1>&2
  41. INSTALLFLAG=1
  42. else
  43. ttfautohint --version
  44. fi
  45. if ! which "$FONTMAKE"; then
  46. echo "Unable to identify a system installed version of fontmake. Please install and try again." 1>&2
  47. INSTALLFLAG=1
  48. else
  49. "$FONTMAKE" --version
  50. fi
  51. if ! which "$PYTHON"; then
  52. echo "Unable to identify a Python 3 installation. Please install and try again." 1>&2
  53. INSTALLFLAG=1
  54. else
  55. "$PYTHON" --version
  56. fi
  57. echo "================================="
  58. echo " "
  59. echo "================================="
  60. echo " "
  61. fi
  62. # ttfautohint path test for default builds
  63. # test for local ttfautohint install using repository provided install script and defined ttfautohint version (and its dependencies)
  64. # no tests for Python build dependencies here because they are always installed by default & tested in the pipenv virtualenv before these steps
  65. if [ $# -eq 0 ]; then
  66. if ! [ -f "$TTFAH" ]; then
  67. echo "Unable to identify the expected local install path for ttfautohint. Please install and try again." 1>&2
  68. INSTALLFLAG=1
  69. fi
  70. fi
  71. # If any of the dependency checks failed, exit the build and notify user
  72. if [ $INSTALLFLAG -eq 1 ]; then
  73. echo "Build canceled." 1>&2
  74. exit 1
  75. fi
  76. # Desktop ttf font build
  77. echo "Starting build..."
  78. echo " "
  79. # remove any existing release files from the build directory
  80. if [ -f "build/ttf/Hack-Regular.ttf" ]; then
  81. rm build/ttf/Hack-Regular.ttf
  82. fi
  83. if [ -f "build/ttf/Hack-Italic.ttf" ]; then
  84. rm build/ttf/Hack-Italic.ttf
  85. fi
  86. if [ -f "build/ttf/Hack-Bold.ttf" ]; then
  87. rm build/ttf/Hack-Bold.ttf
  88. fi
  89. if [ -f "build/ttf/Hack-BoldItalic.ttf" ]; then
  90. rm build/ttf/Hack-BoldItalic.ttf
  91. fi
  92. # remove master_ttf directory if a previous build failed + exited early and it was not cleaned up
  93. if [ -d "master_ttf" ]; then
  94. rm -rf master_ttf
  95. fi
  96. # build regular set
  97. if ! $FONTMAKE -u "source/Hack-Regular.ufo" -o ttf
  98. then
  99. echo "Unable to build the Hack-Regular variant set. Build canceled." 1>&2
  100. exit 1
  101. fi
  102. # build bold set
  103. if ! $FONTMAKE -u "source/Hack-Bold.ufo" -o ttf
  104. then
  105. echo "Unable to build the Hack-Bold variant set. Build canceled." 1>&2
  106. exit 1
  107. fi
  108. # build italic set
  109. if ! $FONTMAKE -u "source/Hack-Italic.ufo" -o ttf
  110. then
  111. echo "Unable to build the Hack-Italic variant set. Build canceled." 1>&2
  112. exit 1
  113. fi
  114. # build bold italic set
  115. if ! $FONTMAKE -u "source/Hack-BoldItalic.ufo" -o ttf
  116. then
  117. echo "Unable to build the Hack-BoldItalic variant set. Build canceled." 1>&2
  118. exit 1
  119. fi
  120. # Desktop ttf font post build fixes
  121. # DSIG table fix with adapted fontbakery Python script
  122. echo " "
  123. echo "Attempting DSIG table fixes with fontbakery..."
  124. echo " "
  125. if ! $PYTHON postbuild_processing/fixes/fix-dsig.py master_ttf/*.ttf
  126. then
  127. echo "Unable to complete DSIG table fixes on the release files"
  128. exit 1
  129. fi
  130. # fstype value fix with adapted fontbakery Python script
  131. echo " "
  132. echo "Attempting fstype fixes with fontbakery..."
  133. echo " "
  134. if ! $PYTHON postbuild_processing/fixes/fix-fstype.py master_ttf/*.ttf
  135. then
  136. echo "Unable to complete fstype fixes on the release files"
  137. exit 1
  138. fi
  139. # Desktop ttf font hinting
  140. echo " "
  141. echo "Attempting ttfautohint hinting..."
  142. echo " "
  143. # make a temporary directory for the hinted files
  144. mkdir master_ttf/hinted
  145. # Hack-Regular.ttf
  146. 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"
  147. then
  148. echo "Unable to execute ttfautohint on the Hack-Regular variant set. Build canceled." 1>&2
  149. exit 1
  150. fi
  151. echo "master_ttf/Hack-Regular.ttf - successful hinting with ttfautohint"
  152. # Hack-Bold.ttf
  153. 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"
  154. then
  155. echo "Unable to execute ttfautohint on the Hack-Bold variant set. Build canceled." 1>&2
  156. exit 1
  157. fi
  158. echo "master_ttf/Hack-Bold.ttf - successful hinting with ttfautohint"
  159. # Hack-Italic.ttf
  160. 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"
  161. then
  162. echo "Unable to execute ttfautohint on the Hack-Italic variant set. Build canceled." 1>&2
  163. exit 1
  164. fi
  165. echo "master_ttf/Hack-Italic.ttf - successful hinting with ttfautohint"
  166. # Hack-BoldItalic.ttf
  167. 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"
  168. then
  169. echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set. Build canceled." 1>&2
  170. exit 1
  171. fi
  172. echo "master_ttf/Hack-BoldItalic.ttf - successful hinting with ttfautohint"
  173. echo " "
  174. # Move release files to build directory
  175. echo " "
  176. # create directory if it does not exist
  177. # (occurs with git + empty directories)
  178. if ! [ -d build/ttf ]; then
  179. mkdir build/ttf
  180. fi
  181. mv master_ttf/hinted/Hack-Regular.ttf build/ttf/Hack-Regular.ttf
  182. echo "Regular ttf build path: build/ttf/Hack-Regular.ttf"
  183. mv master_ttf/hinted/Hack-Italic.ttf build/ttf/Hack-Italic.ttf
  184. echo "Italic ttf build path: build/ttf/Hack-Italic.ttf"
  185. mv master_ttf/hinted/Hack-Bold.ttf build/ttf/Hack-Bold.ttf
  186. echo "Bold ttf build path: build/ttf/Hack-Bold.ttf"
  187. mv master_ttf/hinted/Hack-BoldItalic.ttf build/ttf/Hack-BoldItalic.ttf
  188. echo "Bold Italic ttf build path: build/ttf/Hack-BoldItalic.ttf"
  189. # Remove master_ttf directory
  190. rm -rf master_ttf