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