build.sh 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/bin/bash
  2. # /////////////////////////////////////////////////////////////////
  3. #
  4. # build.sh
  5. # A shell script that builds the Hack fonts from UFO source
  6. # Copyright 2017 Christopher Simpkins
  7. # MIT License
  8. #
  9. # Usage: ./build.sh (--install-dependencies)
  10. # Arguments:
  11. # --install-dependencies (optional) - installs all
  12. # build dependencies prior to the build script execution
  13. #
  14. # /////////////////////////////////////////////////////////////////
  15. # test for number of arguments
  16. if [ $# -gt 1 ]
  17. then
  18. echo "Inappropriate arguments included in your command." 1>&2
  19. echo "Usage: ./build.sh (--install-dependencies)" 1>&2
  20. exit 1
  21. fi
  22. if [ "$1" = "--install-dependencies" ]
  23. then
  24. # fontmake
  25. pip install --upgrade fontmake
  26. # fontTools (installed with fontmake at this time. leave this as dependency check as python scripts for fixes require it should fontTools eliminate dep)
  27. pip install --upgrade fonttools
  28. # ttfautohint v1.6 (must be pinned to v1.6 and above for Hack instruction sets)
  29. # begin with OS X check for platform specific ttfautohint install using Homebrew, install from source on other platforms
  30. platformstr=$(uname)
  31. if [ "$platformstr" = "Darwin" ]; then
  32. # test for homebrew install
  33. if ! which homebrew
  34. then
  35. echo "Please manually install Homebrew (https://brew.sh/) before the execution of this script with the --install-dependencies flag on the OS X platform." 1>&2
  36. exit 1
  37. fi
  38. # install Homebrew release of ttfautohint (this installs all dependencies necessary for build)
  39. # use --upgrade flag to confirm latest version installed as need 1.6+
  40. if ! brew install --upgrade ttfautohint
  41. then
  42. echo "Unable to install ttfautohint with Homebrew. Please attempt to install this dependency manually and repeat this script without the --install-dependencies flag." 1>&2
  43. exit 1
  44. fi
  45. else
  46. curl -L https://sourceforge.net/projects/freetype/files/ttfautohint/1.6/ttfautohint-1.6.tar.gz/download -o ttfautohint.tar.gz
  47. tar -xvzf ttfautohint.tar.gz
  48. ttfautohint-1.6/configure --with-qt=no
  49. ttfautohint-1.6/make
  50. if ! sudo ttfautohint-1.6/make install; then
  51. echo "Unable to install ttfautohint from source. Please attempt to manually install this dependency and repeat this script without the --install-dependencies flag" 1>&2
  52. exit 1
  53. fi
  54. if [ -f "ttfautohint-1.6.tar.gz" ]
  55. then
  56. rm ttfautohint-1.6.tar.gz
  57. fi
  58. if [ -d "ttfautohint-1.6" ]
  59. then
  60. rm -rf ttfautohint-1.6
  61. fi
  62. fi
  63. # confirm installs
  64. installflag=0
  65. # fontmake installed
  66. if ! which fontmake
  67. then
  68. echo "Unable to install fontmake with 'pip install fontmake'. Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
  69. installflag=1
  70. fi
  71. # fontTools python library can be imported
  72. if ! python -c "import fontTools"
  73. then
  74. echo "Unable to install fontTools with 'pip install fonttools'. Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
  75. installflag=1
  76. fi
  77. # ttfautohint installed
  78. if ! which ttfautohint
  79. then
  80. echo "Unable to install ttfautohint from source. Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
  81. installflag=1
  82. fi
  83. # if any of the dependency installs failed, exit and do not attempt build, notify user
  84. if [ $installflag -eq 1 ]
  85. then
  86. echo "Build canceled." 1>&2
  87. exit 1
  88. fi
  89. fi
  90. # Desktop ttf font build
  91. echo "Starting build..."
  92. echo " "
  93. # remove any existing release files from the build directory
  94. if [ -f "build/ttf/Hack-Regular.ttf" ]; then
  95. rm build/ttf/Hack-Regular.ttf
  96. fi
  97. if [ -f "build/ttf/Hack-Italic.ttf" ]; then
  98. rm build/ttf/Hack-Italic.ttf
  99. fi
  100. if [ -f "build/ttf/Hack-Bold.ttf" ]; then
  101. rm build/ttf/Hack-Bold.ttf
  102. fi
  103. if [ -f "build/ttf/Hack-BoldItalic.ttf" ]; then
  104. rm build/ttf/Hack-BoldItalic.ttf
  105. fi
  106. # remove master_ttf directory if a previous build failed + exited early and it was not cleaned up
  107. if [ -d "master_ttf" ]; then
  108. rm -rf master_ttf
  109. fi
  110. # build regular set
  111. if ! fontmake -u "source/Hack-Regular.ufo" -o ttf
  112. then
  113. echo "Unable to build the Hack-Regular variant set. Build canceled." 1>&2
  114. exit 1
  115. fi
  116. # build bold set
  117. if ! fontmake -u "source/Hack-Bold.ufo" -o ttf
  118. then
  119. echo "Unable to build the Hack-Bold variant set. Build canceled." 1>&2
  120. exit 1
  121. fi
  122. # build italic set
  123. if ! fontmake -u "source/Hack-Italic.ufo" -o ttf
  124. then
  125. echo "Unable to build the Hack-Italic variant set. Build canceled." 1>&2
  126. exit 1
  127. fi
  128. # build bold italic set
  129. if ! fontmake -u "source/Hack-BoldItalic.ufo" -o ttf
  130. then
  131. echo "Unable to build the Hack-BoldItalic variant set. Build canceled." 1>&2
  132. exit 1
  133. fi
  134. # Desktop ttf font post build fixes
  135. # DSIG table fix with adapted fontbakery Python script
  136. echo " "
  137. echo "Attempting DSIG table fixes with fontbakery..."
  138. echo " "
  139. if ! python postbuild_processing/fixes/fix-dsig.py master_ttf/*.ttf
  140. then
  141. echo "Unable to complete DSIG table fixes on the release files"
  142. exit 1
  143. fi
  144. # fstype value fix with adapted fontbakery Python script
  145. echo " "
  146. echo "Attempting fstype fixes with fontbakery..."
  147. echo " "
  148. if ! python postbuild_processing/fixes/fix-fstype.py master_ttf/*.ttf
  149. then
  150. echo "Unable to complete fstype fixes on the release files"
  151. exit 1
  152. fi
  153. # Desktop ttf font hinting
  154. echo " "
  155. echo "Attempting ttfautohint hinting..."
  156. echo " "
  157. # make a temporary directory for the hinted files
  158. mkdir master_ttf/hinted
  159. # Hack-Regular.ttf
  160. if ! ttfautohint -l 6 -r 50 -x 10 -H 181 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Regular-TA.txt" "master_ttf/Hack-Regular.ttf" "master_ttf/hinted/Hack-Regular.ttf"
  161. then
  162. echo "Unable to execute ttfautohint on the Hack-Regular variant set. Build canceled." 1>&2
  163. exit 1
  164. fi
  165. echo "master_ttf/Hack-Regular.ttf - successful hinting with ttfautohint"
  166. # Hack-Bold.ttf
  167. if ! ttfautohint -l 6 -r 50 -x 10 -H 260 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Bold-TA.txt" "master_ttf/Hack-Bold.ttf" "master_ttf/hinted/Hack-Bold.ttf"
  168. then
  169. echo "Unable to execute ttfautohint on the Hack-Bold variant set. Build canceled." 1>&2
  170. exit 1
  171. fi
  172. echo "master_ttf/Hack-Bold.ttf - successful hinting with ttfautohint"
  173. # Hack-Italic.ttf
  174. if ! ttfautohint -l 6 -r 50 -x 10 -H 145 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Italic-TA.txt" "master_ttf/Hack-Italic.ttf" "master_ttf/hinted/Hack-Italic.ttf"
  175. then
  176. echo "Unable to execute ttfautohint on the Hack-Italic variant set. Build canceled." 1>&2
  177. exit 1
  178. fi
  179. echo "master_ttf/Hack-Italic.ttf - successful hinting with ttfautohint"
  180. # Hack-BoldItalic.ttf
  181. if ! ttfautohint -l 6 -r 50 -x 10 -H 265 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-BoldItalic-TA.txt" "master_ttf/Hack-BoldItalic.ttf" "master_ttf/hinted/Hack-BoldItalic.ttf"
  182. then
  183. echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set. Build canceled." 1>&2
  184. exit 1
  185. fi
  186. echo "master_ttf/Hack-BoldItalic.ttf - successful hinting with ttfautohint"
  187. echo " "
  188. # Move release files to build directory
  189. echo " "
  190. mv master_ttf/hinted/Hack-Regular.ttf build/ttf/Hack-Regular.ttf
  191. echo "master_ttf/Hack-Regular.ttf was moved to build/ttf/Hack-Regular.ttf"
  192. mv master_ttf/hinted/Hack-Italic.ttf build/ttf/Hack-Italic.ttf
  193. echo "master_ttf/Hack-Italic.ttf was moved to build/ttf/Hack-Italic.ttf"
  194. mv master_ttf/hinted/Hack-Bold.ttf build/ttf/Hack-Bold.ttf
  195. echo "master_ttf/Hack-Bold.ttf was moved to build/ttf/Hack-Bold.ttf"
  196. mv master_ttf/hinted/Hack-BoldItalic.ttf build/ttf/Hack-BoldItalic.ttf
  197. echo "master_ttf/Hack-BoldItalic.ttf was moved to build/ttf/Hack-BoldItalic.ttf"
  198. # Remove master_ttf directory
  199. rm -rf master_ttf
  200. echo " "
  201. echo "Build complete. Release files are available in the build directory."