2
0

build-ttf.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. # ttfautohint path test for default builds
  61. # test for local ttfautohint install using repository provided install script and defined ttfautohint version (and its dependencies)
  62. # no tests for Python build dependencies here because they are always installed by default & tested in the pipenv virtualenv before these steps
  63. if [ $# -eq 0 ]; then
  64. if ! [ -f "$TTFAH" ]; then
  65. echo "Unable to identify the expected local install path for ttfautohint. Please install and try again." 1>&2
  66. INSTALLFLAG=1
  67. fi
  68. fi
  69. # If any of the dependency checks failed, exit the build and notify user
  70. if [ $INSTALLFLAG -eq 1 ]; then
  71. echo "Build canceled." 1>&2
  72. exit 1
  73. fi
  74. # Desktop ttf font build
  75. echo "Starting build..."
  76. echo " "
  77. # remove any existing release files from the build directory
  78. if [ -f "build/ttf/Hack-Regular.ttf" ]; then
  79. rm build/ttf/Hack-Regular.ttf
  80. fi
  81. if [ -f "build/ttf/Hack-Italic.ttf" ]; then
  82. rm build/ttf/Hack-Italic.ttf
  83. fi
  84. if [ -f "build/ttf/Hack-Bold.ttf" ]; then
  85. rm build/ttf/Hack-Bold.ttf
  86. fi
  87. if [ -f "build/ttf/Hack-BoldItalic.ttf" ]; then
  88. rm build/ttf/Hack-BoldItalic.ttf
  89. fi
  90. # remove master_ttf directory if a previous build failed + exited early and it was not cleaned up
  91. if [ -d "master_ttf" ]; then
  92. rm -rf master_ttf
  93. fi
  94. # build regular set
  95. if ! $FONTMAKE -u "source/Hack-Regular.ufo" -o ttf
  96. then
  97. echo "Unable to build the Hack-Regular variant set. Build canceled." 1>&2
  98. exit 1
  99. fi
  100. # build bold set
  101. if ! $FONTMAKE -u "source/Hack-Bold.ufo" -o ttf
  102. then
  103. echo "Unable to build the Hack-Bold variant set. Build canceled." 1>&2
  104. exit 1
  105. fi
  106. # build italic set
  107. if ! $FONTMAKE -u "source/Hack-Italic.ufo" -o ttf
  108. then
  109. echo "Unable to build the Hack-Italic variant set. Build canceled." 1>&2
  110. exit 1
  111. fi
  112. # build bold italic set
  113. if ! $FONTMAKE -u "source/Hack-BoldItalic.ufo" -o ttf
  114. then
  115. echo "Unable to build the Hack-BoldItalic variant set. Build canceled." 1>&2
  116. exit 1
  117. fi
  118. # Desktop ttf font post build fixes
  119. # DSIG table fix with adapted fontbakery Python script
  120. echo " "
  121. echo "Attempting DSIG table fixes with fontbakery..."
  122. echo " "
  123. if ! $PYTHON postbuild_processing/fixes/fix-dsig.py master_ttf/*.ttf
  124. then
  125. echo "Unable to complete DSIG table fixes on the release files"
  126. exit 1
  127. fi
  128. # fstype value fix with adapted fontbakery Python script
  129. echo " "
  130. echo "Attempting fstype fixes with fontbakery..."
  131. echo " "
  132. if ! $PYTHON postbuild_processing/fixes/fix-fstype.py master_ttf/*.ttf
  133. then
  134. echo "Unable to complete fstype fixes on the release files"
  135. exit 1
  136. fi
  137. # Desktop ttf font hinting
  138. echo " "
  139. echo "Attempting ttfautohint hinting..."
  140. echo " "
  141. # make a temporary directory for the hinted files
  142. mkdir master_ttf/hinted
  143. # Hack-Regular.ttf
  144. 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"
  145. then
  146. echo "Unable to execute ttfautohint on the Hack-Regular variant set. Build canceled." 1>&2
  147. exit 1
  148. fi
  149. echo "master_ttf/Hack-Regular.ttf - successful hinting with ttfautohint"
  150. # Hack-Bold.ttf
  151. 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"
  152. then
  153. echo "Unable to execute ttfautohint on the Hack-Bold variant set. Build canceled." 1>&2
  154. exit 1
  155. fi
  156. echo "master_ttf/Hack-Bold.ttf - successful hinting with ttfautohint"
  157. # Hack-Italic.ttf
  158. 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"
  159. then
  160. echo "Unable to execute ttfautohint on the Hack-Italic variant set. Build canceled." 1>&2
  161. exit 1
  162. fi
  163. echo "master_ttf/Hack-Italic.ttf - successful hinting with ttfautohint"
  164. # Hack-BoldItalic.ttf
  165. 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"
  166. then
  167. echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set. Build canceled." 1>&2
  168. exit 1
  169. fi
  170. echo "master_ttf/Hack-BoldItalic.ttf - successful hinting with ttfautohint"
  171. echo " "
  172. # Move release files to build directory
  173. echo " "
  174. # create directory if it does not exist
  175. # (occurs with git + empty directories)
  176. if ! [ -d build/ttf ]; then
  177. mkdir build/ttf
  178. fi
  179. mv master_ttf/hinted/Hack-Regular.ttf build/ttf/Hack-Regular.ttf
  180. echo "Regular ttf build path: build/ttf/Hack-Regular.ttf"
  181. mv master_ttf/hinted/Hack-Italic.ttf build/ttf/Hack-Italic.ttf
  182. echo "Italic ttf build path: build/ttf/Hack-Italic.ttf"
  183. mv master_ttf/hinted/Hack-Bold.ttf build/ttf/Hack-Bold.ttf
  184. echo "Bold ttf build path: build/ttf/Hack-Bold.ttf"
  185. mv master_ttf/hinted/Hack-BoldItalic.ttf build/ttf/Hack-BoldItalic.ttf
  186. echo "Bold Italic ttf build path: build/ttf/Hack-BoldItalic.ttf"
  187. # Remove master_ttf directory
  188. rm -rf master_ttf