build-ttf.sh 6.7 KB

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