build-woff.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/sh
  2. # ///////////////////////////////////////////////////////////////////
  3. #
  4. # build-woff.sh
  5. # A shell script that builds the Hack woff web fonts from ttf files
  6. # Copyright 2018 Christopher Simpkins
  7. # MIT License
  8. #
  9. # Usage: ./build-woff.sh (--install-dependencies)
  10. # Arguments:
  11. # --install-dependencies (optional) - installs all
  12. # build dependencies prior to the build script execution
  13. #
  14. # NOTE: If you change the source, you must build new ttf files
  15. # with build.sh PRIOR to execution of this script.
  16. # This script builds directly from previous ttf builds,
  17. # not source files.
  18. #
  19. # ///////////////////////////////////////////////////////////////////
  20. # The sfnt2woff-zopfli build directory.
  21. BUILD="$HOME/sfnt2woff-zopfli-build"
  22. # sfnt2woff-zopfli version
  23. SFNTWOFF_VERSION="1.1.0"
  24. SFNTWOFF="sfnt2woff-zopfli-$SFNTWOFF_VERSION"
  25. # Path to sfnt2woff-zopfli executable
  26. SFNTWOFF_BIN="$BUILD/$SFNTWOFF/sfnt2woff-zopfli"
  27. ZOPFLI_ITERATIONS="3"
  28. # The font build directory paths and file paths for the woff builds
  29. TTF_BUILD="build/ttf"
  30. WOFF_BUILD="build/web/fonts"
  31. REGULAR_TTF="Hack-Regular.ttf"
  32. REGULAR_PRE="Hack-Regular.woff"
  33. REGULAR_WOFF="hack-regular.woff"
  34. BOLD_TTF="Hack-Bold.ttf"
  35. BOLD_PRE="Hack-Bold.woff"
  36. BOLD_WOFF="hack-bold.woff"
  37. ITALIC_TTF="Hack-Italic.ttf"
  38. ITALIC_PRE="Hack-Italic.woff"
  39. ITALIC_WOFF="hack-italic.woff"
  40. BOLDITALIC_TTF="Hack-BoldItalic.ttf"
  41. BOLDITALIC_PRE="Hack-BoldItalic.woff"
  42. BOLDITALIC_WOFF="hack-bolditalic.woff"
  43. # test for number of arguments
  44. if [ $# -gt 1 ]
  45. then
  46. echo "Inappropriate arguments included in your command." 1>&2
  47. echo "Usage: ./build-woff.sh (--install-dependencies)" 1>&2
  48. exit 1
  49. fi
  50. # Optional build dependency install request with syntax `./build-web.sh --install-dependencies`
  51. if [ "$1" = "--install-dependencies" ]
  52. then
  53. # define the current directory (Hack repository)
  54. CUR_DIR=$(pwd)
  55. if test -d "$BUILD" -o -f "$BUILD"; then
  56. echo "Build directory \`$BUILD' must not exist."
  57. exit 1
  58. fi
  59. mkdir "$BUILD"
  60. cd "$BUILD" || exit 1
  61. echo "#####"
  62. echo "Download archive."
  63. echo "#####"
  64. curl -L -O "https://github.com/bramstein/sfnt2woff-zopfli/archive/v$SFNTWOFF_VERSION.tar.gz"
  65. echo "#####"
  66. echo "Extract archives."
  67. echo "#####"
  68. tar -xzvf "v$SFNTWOFF_VERSION.tar.gz"
  69. cd "$SFNTWOFF" || exit 1
  70. echo "#####"
  71. echo "Build $SFNTWOFF."
  72. echo "#####"
  73. make
  74. # make Hack repository the current directory again following the build
  75. cd "$CUR_DIR" || exit 1
  76. fi
  77. if [ -f "$SFNTWOFF_BIN" ]; then
  78. echo "Beginning web font build with $SFNTWOFF"
  79. else
  80. echo "Unable to locate sfnt2woff-zopfli on the path $SFNTWOFF_BIN. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
  81. exit 1
  82. fi
  83. # Build woff files from ttf files
  84. # regular set
  85. if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$REGULAR_TTF"; then
  86. echo "Failed to build $REGULAR_WOFF from $REGULAR_TTF." 1>&2
  87. exit 1
  88. else
  89. echo "Regular woff set successfully built from $REGULAR_TTF"
  90. fi
  91. # bold set
  92. if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$BOLD_TTF"; then
  93. echo "Failed to build $BOLD_WOFF from $BOLD_TTF" 1>&2
  94. exit 1
  95. else
  96. echo "Bold woff set successfully built from $BOLD_TTF"
  97. fi
  98. # italic set
  99. if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$ITALIC_TTF"; then
  100. echo "Failed to build $BOLD_WOFF from $ITALIC_TTF" 1>&2
  101. exit 1
  102. else
  103. echo "Italic woff set successfully built from $ITALIC_TTF"
  104. fi
  105. # bold italic set
  106. if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$BOLDITALIC_TTF"; then
  107. echo "Failed to build $BOLDITALIC_WOFF from $BOLDITALIC_TTF" 1>&2
  108. exit 1
  109. else
  110. echo "Bold Italic woff set successfully built from $BOLDITALIC_TTF"
  111. fi
  112. echo "Moving woff files to build directory..."
  113. # create directory if it does not exist
  114. # (occurs with git + empty directories)
  115. if ! [ -d "$WOFF_BUILD" ]; then
  116. mkdir $WOFF_BUILD
  117. fi
  118. # move woff files to appropriate build directory
  119. mv "$TTF_BUILD/$REGULAR_PRE" "$WOFF_BUILD/$REGULAR_WOFF"
  120. mv "$TTF_BUILD/$BOLD_PRE" "$WOFF_BUILD/$BOLD_WOFF"
  121. mv "$TTF_BUILD/$ITALIC_PRE" "$WOFF_BUILD/$ITALIC_WOFF"
  122. mv "$TTF_BUILD/$BOLDITALIC_PRE" "$WOFF_BUILD/$BOLDITALIC_WOFF"
  123. echo " "
  124. if [ -f "$WOFF_BUILD/$REGULAR_WOFF" ]; then
  125. echo "Regular woff build path: $WOFF_BUILD/$REGULAR_WOFF"
  126. fi
  127. if [ -f "$WOFF_BUILD/$BOLD_WOFF" ]; then
  128. echo "Bold woff build path: $WOFF_BUILD/$BOLD_WOFF"
  129. fi
  130. if [ -f "$WOFF_BUILD/$ITALIC_WOFF" ]; then
  131. echo "Italic woff build path: $WOFF_BUILD/$ITALIC_WOFF"
  132. fi
  133. if [ -f "$WOFF_BUILD/$BOLDITALIC_WOFF" ]; then
  134. echo "Bold Italic woff build path: $WOFF_BUILD/$BOLDITALIC_WOFF"
  135. fi