build-ttf.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 (--install-dependencies)
  10. # Arguments:
  11. # --install-dependencies (optional) - installs all
  12. # build dependencies prior to the build script execution
  13. #
  14. # /////////////////////////////////////////////////////////////////
  15. # ttfautohint local install path from Werner Lemberg's ttfautohint-build.sh install script
  16. # - This is revised to ttfautohint on the user's PATH if this local install is not identified
  17. # then the identified ttfautohint is used to execute hinting. Versions of ttfautohint < 1.6 exit with status
  18. # code 1 due to use of -R option
  19. # - The intent is to support use of ttfautohint installed on a user's PATH (e.g. they've previously installed it)
  20. TTFAH="$HOME/ttfautohint-build/local/bin/ttfautohint"
  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 (--install-dependencies)" 1>&2
  26. exit 1
  27. fi
  28. # Optional build dependency install request with syntax `./build.sh --install-dependencies`
  29. if [ "$1" = "--install-dependencies" ]
  30. then
  31. # fontmake
  32. pip install --upgrade fontmake
  33. # fontTools (installed with fontmake at this time. leave this as dependency check as python scripts for fixes require it should fontTools eliminate dep)
  34. pip install --upgrade fonttools
  35. # ttfautohint v1.6 (must be pinned to v1.6 and above for Hack instruction sets)
  36. tools/scripts/install/ttfautohint-build.sh
  37. fi
  38. # confirm executable installs and library imports for build dependencies
  39. INSTALLFLAG=0
  40. echo "Confirming that build dependencies are installed..."
  41. echo " "
  42. # fontmake installed
  43. if ! which fontmake
  44. then
  45. echo "Unable to install fontmake with 'pip install fontmake'. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
  46. INSTALLFLAG=1
  47. fi
  48. # fontTools python library can be imported
  49. if ! python -c "import fontTools"
  50. then
  51. echo "Unable to install fontTools with 'pip install fonttools'. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
  52. INSTALLFLAG=1
  53. else
  54. echo "fontTools Python library identified"
  55. fi
  56. # ttfautohint installed
  57. # - tests for install to local path from ttfautohint-build.sh script
  58. # - if not found on this path, tests for install on system PATH - if found, revises TTFAH to the string "ttfautohint" for execution of instruction sets
  59. if ! [ -f "$TTFAH" ]
  60. then
  61. if ! which ttfautohint
  62. then
  63. echo "Unable to install ttfautohint from source. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
  64. INSTALLFLAG=1
  65. else
  66. TTFAH="ttfautohint" # revise TTFAH variable to ttfautohint installed on the user's PATH for excecution of hints below
  67. fi
  68. fi
  69. # if any of the dependency installs failed, exit and do not attempt build, notify user
  70. if [ $INSTALLFLAG -eq 1 ]
  71. then
  72. echo "Build canceled." 1>&2
  73. exit 1
  74. fi
  75. # Desktop ttf font build
  76. echo "Starting build..."
  77. echo " "
  78. # remove any existing release files from the build directory
  79. if [ -f "build/ttf/Hack-Regular.ttf" ]; then
  80. rm build/ttf/Hack-Regular.ttf
  81. fi
  82. if [ -f "build/ttf/Hack-Italic.ttf" ]; then
  83. rm build/ttf/Hack-Italic.ttf
  84. fi
  85. if [ -f "build/ttf/Hack-Bold.ttf" ]; then
  86. rm build/ttf/Hack-Bold.ttf
  87. fi
  88. if [ -f "build/ttf/Hack-BoldItalic.ttf" ]; then
  89. rm build/ttf/Hack-BoldItalic.ttf
  90. fi
  91. # remove master_ttf directory if a previous build failed + exited early and it was not cleaned up
  92. if [ -d "master_ttf" ]; then
  93. rm -rf master_ttf
  94. fi
  95. # build regular set
  96. if ! fontmake -u "source/Hack-Regular.ufo" -o ttf
  97. then
  98. echo "Unable to build the Hack-Regular variant set. Build canceled." 1>&2
  99. exit 1
  100. fi
  101. # build bold set
  102. if ! fontmake -u "source/Hack-Bold.ufo" -o ttf
  103. then
  104. echo "Unable to build the Hack-Bold variant set. Build canceled." 1>&2
  105. exit 1
  106. fi
  107. # build italic set
  108. if ! fontmake -u "source/Hack-Italic.ufo" -o ttf
  109. then
  110. echo "Unable to build the Hack-Italic variant set. Build canceled." 1>&2
  111. exit 1
  112. fi
  113. # build bold italic set
  114. if ! fontmake -u "source/Hack-BoldItalic.ufo" -o ttf
  115. then
  116. echo "Unable to build the Hack-BoldItalic variant set. Build canceled." 1>&2
  117. exit 1
  118. fi
  119. # Desktop ttf font post build fixes
  120. # DSIG table fix with adapted fontbakery Python script
  121. echo " "
  122. echo "Attempting DSIG table fixes with fontbakery..."
  123. echo " "
  124. if ! python postbuild_processing/fixes/fix-dsig.py master_ttf/*.ttf
  125. then
  126. echo "Unable to complete DSIG table fixes on the release files"
  127. exit 1
  128. fi
  129. # fstype value fix with adapted fontbakery Python script
  130. echo " "
  131. echo "Attempting fstype fixes with fontbakery..."
  132. echo " "
  133. if ! python postbuild_processing/fixes/fix-fstype.py master_ttf/*.ttf
  134. then
  135. echo "Unable to complete fstype fixes on the release files"
  136. exit 1
  137. fi
  138. # Desktop ttf font hinting
  139. echo " "
  140. echo "Attempting ttfautohint hinting..."
  141. echo " "
  142. # make a temporary directory for the hinted files
  143. mkdir master_ttf/hinted
  144. # Hack-Regular.ttf
  145. 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"
  146. then
  147. echo "Unable to execute ttfautohint on the Hack-Regular variant set. Build canceled." 1>&2
  148. exit 1
  149. fi
  150. echo "master_ttf/Hack-Regular.ttf - successful hinting with ttfautohint"
  151. # Hack-Bold.ttf
  152. 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"
  153. then
  154. echo "Unable to execute ttfautohint on the Hack-Bold variant set. Build canceled." 1>&2
  155. exit 1
  156. fi
  157. echo "master_ttf/Hack-Bold.ttf - successful hinting with ttfautohint"
  158. # Hack-Italic.ttf
  159. 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"
  160. then
  161. echo "Unable to execute ttfautohint on the Hack-Italic variant set. Build canceled." 1>&2
  162. exit 1
  163. fi
  164. echo "master_ttf/Hack-Italic.ttf - successful hinting with ttfautohint"
  165. # Hack-BoldItalic.ttf
  166. 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"
  167. then
  168. echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set. Build canceled." 1>&2
  169. exit 1
  170. fi
  171. echo "master_ttf/Hack-BoldItalic.ttf - successful hinting with ttfautohint"
  172. echo " "
  173. # Move release files to build directory
  174. echo " "
  175. # create directory if it does not exist
  176. # (occurs with git + empty directories)
  177. if ! [ -d build/ttf ]; then
  178. mkdir build/ttf
  179. fi
  180. mv master_ttf/hinted/Hack-Regular.ttf build/ttf/Hack-Regular.ttf
  181. echo "Regular ttf build path: build/ttf/Hack-Regular.ttf"
  182. mv master_ttf/hinted/Hack-Italic.ttf build/ttf/Hack-Italic.ttf
  183. echo "Italic ttf build path: build/ttf/Hack-Italic.ttf"
  184. mv master_ttf/hinted/Hack-Bold.ttf build/ttf/Hack-Bold.ttf
  185. echo "Bold ttf build path: build/ttf/Hack-Bold.ttf"
  186. mv master_ttf/hinted/Hack-BoldItalic.ttf build/ttf/Hack-BoldItalic.ttf
  187. echo "Bold Italic ttf build path: build/ttf/Hack-BoldItalic.ttf"
  188. # Remove master_ttf directory
  189. rm -rf master_ttf