build.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. # remove any existing release files from the build directory
  92. if [ -f "build/ttf/Hack-Regular.ttf" ]; then
  93. rm build/ttf/Hack-Regular.ttf
  94. fi
  95. if [ -f "build/ttf/Hack-Italic.ttf" ]; then
  96. rm build/ttf/Hack-Italic.ttf
  97. fi
  98. if [ -f "build/ttf/Hack-Bold.ttf" ]; then
  99. rm build/ttf/Hack-Bold.ttf
  100. fi
  101. if [ -f "build/ttf/Hack-BoldItalic.ttf" ]; then
  102. rm build/ttf/Hack-BoldItalic.ttf
  103. fi
  104. # remove master_ttf directory if a previous build failed + exited early and it was not cleaned up
  105. if [ -d "master_ttf" ]; then
  106. rm -rf master_ttf
  107. fi
  108. # build regular set
  109. if ! fontmake -u "source/Hack-Regular.ufo" -o ttf
  110. then
  111. echo "Unable to build the Hack-Regular variant set. Build canceled." 1>&2
  112. exit 1
  113. fi
  114. # build bold set
  115. if ! fontmake -u "source/Hack-Bold.ufo" -o ttf
  116. then
  117. echo "Unable to build the Hack-Bold variant set. Build canceled." 1>&2
  118. exit 1
  119. fi
  120. # build italic set
  121. if ! fontmake -u "source/Hack-Italic.ufo" -o ttf
  122. then
  123. echo "Unable to build the Hack-Italic variant set. Build canceled." 1>&2
  124. exit 1
  125. fi
  126. # build bold italic set
  127. if ! fontmake -u "source/Hack-BoldItalic.ufo" -o ttf
  128. then
  129. echo "Unable to build the Hack-BoldItalic variant set. Build canceled." 1>&2
  130. exit 1
  131. fi
  132. # Desktop ttf font hinting
  133. # make a temporary directory for the hinted files
  134. mkdir master_ttf/hinted
  135. # Hack-Regular.ttf
  136. 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"
  137. then
  138. echo "Unable to execute ttfautohint on the Hack-Regular variant set. Build canceled." 1>&2
  139. exit 1
  140. fi
  141. # Hack-Bold.ttf
  142. 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"
  143. then
  144. echo "Unable to execute ttfautohint on the Hack-Bold variant set. Build canceled." 1>&2
  145. exit 1
  146. fi
  147. # Hack-Italic.ttf
  148. 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"
  149. then
  150. echo "Unable to execute ttfautohint on the Hack-Italic variant set. Build canceled." 1>&2
  151. exit 1
  152. fi
  153. # Hack-BoldItalic.ttf
  154. 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"
  155. then
  156. echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set. Build canceled." 1>&2
  157. exit 1
  158. fi
  159. # Desktop ttf font post build fixes
  160. # TODO dsig table fix
  161. # TODO fstype integer fix
  162. # Move release files to build directory
  163. mv master_ttf/hinted/Hack-Regular.ttf build/ttf/Hack-Regular.ttf
  164. echo "Hack-Regular.ttf was moved to release directory on path build/ttf/Hack-Regular.ttf"
  165. mv master_ttf/hinted/Hack-Italic.ttf build/ttf/Hack-Italic.ttf
  166. echo "Hack-Italic.ttf was moved to release directory on path build/ttf/Hack-Italic.ttf"
  167. mv master_ttf/hinted/Hack-Bold.ttf build/ttf/Hack-Bold.ttf
  168. echo "Hack-Bold.ttf was moved to release directory on path build/ttf/Hack-Bold.ttf"
  169. mv master_ttf/hinted/Hack-BoldItalic.ttf build/ttf/Hack-BoldItalic.ttf
  170. echo "Hack-BoldItalic.ttf was moved to release directory on path build/ttf/Hack-BoldItalic.ttf"
  171. # Remove master_ttf directory
  172. rm -rf master_ttf