build-ttf.sh 7.0 KB

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