build.sh 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. # install Harfbuzz ttfautohint dependency (>v0.9.19)
  47. curl -L https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-1.4.8.tar.bz2 -o harfbuzz.tar.bz2
  48. tar -xvjf harfbuzz.tar.bz2
  49. harfbuzz-1.4.8/configure
  50. harfbuzz-1.4.8/make
  51. if ! sudo harfbuzz-1.4.8/make install; then
  52. echo "Unable to install ttfautohint dependency Harbuzz from source. Please install dependencies manually and repeat this script without the --install-dependencies flag" 1>&2
  53. exit 1
  54. fi
  55. curl -L https://sourceforge.net/projects/freetype/files/ttfautohint/1.6/ttfautohint-1.6.tar.gz/download -o ttfautohint.tar.gz
  56. tar -xvzf ttfautohint.tar.gz
  57. ttfautohint-1.6/configure --with-qt=no
  58. ttfautohint-1.6/make
  59. if ! sudo ttfautohint-1.6/make install; then
  60. 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
  61. exit 1
  62. fi
  63. if [ -f "ttfautohint-1.6.tar.gz" ]
  64. then
  65. rm ttfautohint-1.6.tar.gz
  66. fi
  67. if [ -d "ttfautohint-1.6" ]
  68. then
  69. rm -rf ttfautohint-1.6
  70. fi
  71. fi
  72. # confirm installs
  73. installflag=0
  74. # fontmake installed
  75. if ! which fontmake
  76. then
  77. echo "Unable to install fontmake with 'pip install fontmake'. Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
  78. installflag=1
  79. fi
  80. # fontTools python library can be imported
  81. if ! python -c "import fontTools"
  82. then
  83. echo "Unable to install fontTools with 'pip install fonttools'. Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
  84. installflag=1
  85. fi
  86. # ttfautohint installed
  87. if ! which ttfautohint
  88. then
  89. echo "Unable to install ttfautohint from source. Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
  90. installflag=1
  91. fi
  92. # if any of the dependency installs failed, exit and do not attempt build, notify user
  93. if [ $installflag -eq 1 ]
  94. then
  95. echo "Build canceled." 1>&2
  96. exit 1
  97. fi
  98. fi
  99. # Desktop ttf font build
  100. echo "Starting build..."
  101. echo " "
  102. # remove any existing release files from the build directory
  103. if [ -f "build/ttf/Hack-Regular.ttf" ]; then
  104. rm build/ttf/Hack-Regular.ttf
  105. fi
  106. if [ -f "build/ttf/Hack-Italic.ttf" ]; then
  107. rm build/ttf/Hack-Italic.ttf
  108. fi
  109. if [ -f "build/ttf/Hack-Bold.ttf" ]; then
  110. rm build/ttf/Hack-Bold.ttf
  111. fi
  112. if [ -f "build/ttf/Hack-BoldItalic.ttf" ]; then
  113. rm build/ttf/Hack-BoldItalic.ttf
  114. fi
  115. # remove master_ttf directory if a previous build failed + exited early and it was not cleaned up
  116. if [ -d "master_ttf" ]; then
  117. rm -rf master_ttf
  118. fi
  119. # build regular set
  120. if ! fontmake -u "source/Hack-Regular.ufo" -o ttf
  121. then
  122. echo "Unable to build the Hack-Regular variant set. Build canceled." 1>&2
  123. exit 1
  124. fi
  125. # build bold set
  126. if ! fontmake -u "source/Hack-Bold.ufo" -o ttf
  127. then
  128. echo "Unable to build the Hack-Bold variant set. Build canceled." 1>&2
  129. exit 1
  130. fi
  131. # build italic set
  132. if ! fontmake -u "source/Hack-Italic.ufo" -o ttf
  133. then
  134. echo "Unable to build the Hack-Italic variant set. Build canceled." 1>&2
  135. exit 1
  136. fi
  137. # build bold italic set
  138. if ! fontmake -u "source/Hack-BoldItalic.ufo" -o ttf
  139. then
  140. echo "Unable to build the Hack-BoldItalic variant set. Build canceled." 1>&2
  141. exit 1
  142. fi
  143. # Desktop ttf font post build fixes
  144. # DSIG table fix with adapted fontbakery Python script
  145. echo " "
  146. echo "Attempting DSIG table fixes with fontbakery..."
  147. echo " "
  148. if ! python postbuild_processing/fixes/fix-dsig.py master_ttf/*.ttf
  149. then
  150. echo "Unable to complete DSIG table fixes on the release files"
  151. exit 1
  152. fi
  153. # fstype value fix with adapted fontbakery Python script
  154. echo " "
  155. echo "Attempting fstype fixes with fontbakery..."
  156. echo " "
  157. if ! python postbuild_processing/fixes/fix-fstype.py master_ttf/*.ttf
  158. then
  159. echo "Unable to complete fstype fixes on the release files"
  160. exit 1
  161. fi
  162. # Desktop ttf font hinting
  163. echo " "
  164. echo "Attempting ttfautohint hinting..."
  165. echo " "
  166. # make a temporary directory for the hinted files
  167. mkdir master_ttf/hinted
  168. # Hack-Regular.ttf
  169. 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"
  170. then
  171. echo "Unable to execute ttfautohint on the Hack-Regular variant set. Build canceled." 1>&2
  172. exit 1
  173. fi
  174. echo "master_ttf/Hack-Regular.ttf - successful hinting with ttfautohint"
  175. # Hack-Bold.ttf
  176. 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"
  177. then
  178. echo "Unable to execute ttfautohint on the Hack-Bold variant set. Build canceled." 1>&2
  179. exit 1
  180. fi
  181. echo "master_ttf/Hack-Bold.ttf - successful hinting with ttfautohint"
  182. # Hack-Italic.ttf
  183. 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"
  184. then
  185. echo "Unable to execute ttfautohint on the Hack-Italic variant set. Build canceled." 1>&2
  186. exit 1
  187. fi
  188. echo "master_ttf/Hack-Italic.ttf - successful hinting with ttfautohint"
  189. # Hack-BoldItalic.ttf
  190. 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"
  191. then
  192. echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set. Build canceled." 1>&2
  193. exit 1
  194. fi
  195. echo "master_ttf/Hack-BoldItalic.ttf - successful hinting with ttfautohint"
  196. echo " "
  197. # Move release files to build directory
  198. echo " "
  199. mv master_ttf/hinted/Hack-Regular.ttf build/ttf/Hack-Regular.ttf
  200. echo "master_ttf/Hack-Regular.ttf was moved to build/ttf/Hack-Regular.ttf"
  201. mv master_ttf/hinted/Hack-Italic.ttf build/ttf/Hack-Italic.ttf
  202. echo "master_ttf/Hack-Italic.ttf was moved to build/ttf/Hack-Italic.ttf"
  203. mv master_ttf/hinted/Hack-Bold.ttf build/ttf/Hack-Bold.ttf
  204. echo "master_ttf/Hack-Bold.ttf was moved to build/ttf/Hack-Bold.ttf"
  205. mv master_ttf/hinted/Hack-BoldItalic.ttf build/ttf/Hack-BoldItalic.ttf
  206. echo "master_ttf/Hack-BoldItalic.ttf was moved to build/ttf/Hack-BoldItalic.ttf"
  207. # Remove master_ttf directory
  208. rm -rf master_ttf
  209. echo " "
  210. echo "Build complete. Release files are available in the build directory."