build-ttf.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. TTFAH="$HOME/ttfautohint-build/local/bin/ttfautohint"
  17. # test for number of arguments
  18. if [ $# -gt 1 ]
  19. then
  20. echo "Inappropriate arguments included in your command." 1>&2
  21. echo "Usage: ./build-ttf.sh (--install-dependencies)" 1>&2
  22. exit 1
  23. fi
  24. # Optional build dependency install request with syntax `./build.sh --install-dependencies`
  25. if [ "$1" = "--install-dependencies" ]
  26. then
  27. # fontmake
  28. pip install --upgrade fontmake
  29. # fontTools (installed with fontmake at this time. leave this as dependency check as python scripts for fixes require it should fontTools eliminate dep)
  30. pip install --upgrade fonttools
  31. # ttfautohint v1.6 (must be pinned to v1.6 and above for Hack instruction sets)
  32. tools/scripts/install/ttfautohint-build.sh
  33. fi
  34. # confirm executable installs and library imports for build dependencies
  35. INSTALLFLAG=0
  36. echo "Confirming that build dependencies are installed..."
  37. echo " "
  38. # fontmake installed
  39. if ! which fontmake
  40. then
  41. 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
  42. INSTALLFLAG=1
  43. fi
  44. # fontTools python library can be imported
  45. if ! python -c "import fontTools"
  46. then
  47. 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
  48. INSTALLFLAG=1
  49. else
  50. echo "fontTools Python library identified"
  51. fi
  52. # ttfautohint installed
  53. # - tests for install to local path from ttfautohint-build.sh script
  54. # - 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
  55. if ! [ -f "$TTFAH" ]
  56. then
  57. if ! which ttfautohint
  58. then
  59. echo "Unable to install ttfautohint from source. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
  60. INSTALLFLAG=1
  61. else
  62. TTFAH="ttfautohint" # revise TTFAH variable to ttfautohint installed on the user's PATH for excecution of hints below
  63. fi
  64. fi
  65. # if any of the dependency installs failed, exit and do not attempt build, notify user
  66. if [ $INSTALLFLAG -eq 1 ]
  67. 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