build-ttf.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. # ttfautohint v1.6 (must be pinned to v1.6 and above for Hack instruction sets)
  28. tools/scripts/install/ttfautohint-build.sh
  29. fi
  30. # confirm executable installs and library imports for build dependencies
  31. INSTALLFLAG=0
  32. # ttfautohint installed
  33. # - tests for install to local path from ttfautohint-build.sh script
  34. # - 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
  35. if ! [ -f "$TTFAH" ]
  36. then
  37. if ! which ttfautohint
  38. then
  39. echo "Unable to install ttfautohint from source. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
  40. INSTALLFLAG=1
  41. else
  42. TTFAH="ttfautohint" # revise TTFAH variable to ttfautohint installed on the user's PATH for excecution of hints below
  43. fi
  44. fi
  45. # if any of the dependency installs failed, exit and do not attempt build, notify user
  46. if [ $INSTALLFLAG -eq 1 ]
  47. then
  48. echo "Build canceled." 1>&2
  49. exit 1
  50. fi
  51. # Desktop ttf font build
  52. echo "Starting build..."
  53. echo " "
  54. # remove any existing release files from the build directory
  55. if [ -f "build/ttf/Hack-Regular.ttf" ]; then
  56. rm build/ttf/Hack-Regular.ttf
  57. fi
  58. if [ -f "build/ttf/Hack-Italic.ttf" ]; then
  59. rm build/ttf/Hack-Italic.ttf
  60. fi
  61. if [ -f "build/ttf/Hack-Bold.ttf" ]; then
  62. rm build/ttf/Hack-Bold.ttf
  63. fi
  64. if [ -f "build/ttf/Hack-BoldItalic.ttf" ]; then
  65. rm build/ttf/Hack-BoldItalic.ttf
  66. fi
  67. # remove master_ttf directory if a previous build failed + exited early and it was not cleaned up
  68. if [ -d "master_ttf" ]; then
  69. rm -rf master_ttf
  70. fi
  71. # build regular set
  72. if ! pipenv run fontmake -u "source/Hack-Regular.ufo" -o ttf
  73. then
  74. echo "Unable to build the Hack-Regular variant set. Build canceled." 1>&2
  75. exit 1
  76. fi
  77. # build bold set
  78. if ! pipenv run fontmake -u "source/Hack-Bold.ufo" -o ttf
  79. then
  80. echo "Unable to build the Hack-Bold variant set. Build canceled." 1>&2
  81. exit 1
  82. fi
  83. # build italic set
  84. if ! pipenv run fontmake -u "source/Hack-Italic.ufo" -o ttf
  85. then
  86. echo "Unable to build the Hack-Italic variant set. Build canceled." 1>&2
  87. exit 1
  88. fi
  89. # build bold italic set
  90. if ! pipenv run fontmake -u "source/Hack-BoldItalic.ufo" -o ttf
  91. then
  92. echo "Unable to build the Hack-BoldItalic variant set. Build canceled." 1>&2
  93. exit 1
  94. fi
  95. # Desktop ttf font post build fixes
  96. # DSIG table fix with adapted fontbakery Python script
  97. echo " "
  98. echo "Attempting DSIG table fixes with fontbakery..."
  99. echo " "
  100. if ! pipenv run python postbuild_processing/fixes/fix-dsig.py master_ttf/*.ttf
  101. then
  102. echo "Unable to complete DSIG table fixes on the release files"
  103. exit 1
  104. fi
  105. # fstype value fix with adapted fontbakery Python script
  106. echo " "
  107. echo "Attempting fstype fixes with fontbakery..."
  108. echo " "
  109. if ! pipenv run python postbuild_processing/fixes/fix-fstype.py master_ttf/*.ttf
  110. then
  111. echo "Unable to complete fstype fixes on the release files"
  112. exit 1
  113. fi
  114. # Desktop ttf font hinting
  115. echo " "
  116. echo "Attempting ttfautohint hinting..."
  117. echo " "
  118. # make a temporary directory for the hinted files
  119. mkdir master_ttf/hinted
  120. # Hack-Regular.ttf
  121. 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"
  122. then
  123. echo "Unable to execute ttfautohint on the Hack-Regular variant set. Build canceled." 1>&2
  124. exit 1
  125. fi
  126. echo "master_ttf/Hack-Regular.ttf - successful hinting with ttfautohint"
  127. # Hack-Bold.ttf
  128. 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"
  129. then
  130. echo "Unable to execute ttfautohint on the Hack-Bold variant set. Build canceled." 1>&2
  131. exit 1
  132. fi
  133. echo "master_ttf/Hack-Bold.ttf - successful hinting with ttfautohint"
  134. # Hack-Italic.ttf
  135. 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"
  136. then
  137. echo "Unable to execute ttfautohint on the Hack-Italic variant set. Build canceled." 1>&2
  138. exit 1
  139. fi
  140. echo "master_ttf/Hack-Italic.ttf - successful hinting with ttfautohint"
  141. # Hack-BoldItalic.ttf
  142. 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"
  143. then
  144. echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set. Build canceled." 1>&2
  145. exit 1
  146. fi
  147. echo "master_ttf/Hack-BoldItalic.ttf - successful hinting with ttfautohint"
  148. echo " "
  149. # Move release files to build directory
  150. echo " "
  151. # create directory if it does not exist
  152. # (occurs with git + empty directories)
  153. if ! [ -d build/ttf ]; then
  154. mkdir build/ttf
  155. fi
  156. mv master_ttf/hinted/Hack-Regular.ttf build/ttf/Hack-Regular.ttf
  157. echo "Regular ttf build path: build/ttf/Hack-Regular.ttf"
  158. mv master_ttf/hinted/Hack-Italic.ttf build/ttf/Hack-Italic.ttf
  159. echo "Italic ttf build path: build/ttf/Hack-Italic.ttf"
  160. mv master_ttf/hinted/Hack-Bold.ttf build/ttf/Hack-Bold.ttf
  161. echo "Bold ttf build path: build/ttf/Hack-Bold.ttf"
  162. mv master_ttf/hinted/Hack-BoldItalic.ttf build/ttf/Hack-BoldItalic.ttf
  163. echo "Bold Italic ttf build path: build/ttf/Hack-BoldItalic.ttf"
  164. # Remove master_ttf directory
  165. rm -rf master_ttf