build-woff.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 (--system)
  10. # Arguments:
  11. # --system (optional) - build with a system installed version
  12. # of build dependencies
  13. #
  14. # NOTE: If you modify the source, you must build new ttf files
  15. # PRIOR to execution of this script. This script builds
  16. # directly from previous ttf builds, not source files.
  17. #
  18. # ///////////////////////////////////////////////////////////////////
  19. # The sfnt2woff-zopfli build directory.
  20. BUILD="$HOME/sfnt2woff-zopfli-build"
  21. # sfnt2woff-zopfli version
  22. SFNTWOFF_VERSION="1.1.0"
  23. SFNTWOFF="sfnt2woff-zopfli-$SFNTWOFF_VERSION"
  24. # Path to sfnt2woff-zopfli executable
  25. SFNTWOFF_BIN="$BUILD/$SFNTWOFF/sfnt2woff-zopfli"
  26. ZOPFLI_ITERATIONS="3"
  27. # The font build directory paths and file paths for the woff builds
  28. TTF_BUILD="build/ttf"
  29. WOFF_BUILD="build/web/fonts"
  30. REGULAR_TTF="Hack-Regular.ttf"
  31. REGULAR_PRE="Hack-Regular.woff"
  32. REGULAR_WOFF="hack-regular.woff"
  33. BOLD_TTF="Hack-Bold.ttf"
  34. BOLD_PRE="Hack-Bold.woff"
  35. BOLD_WOFF="hack-bold.woff"
  36. ITALIC_TTF="Hack-Italic.ttf"
  37. ITALIC_PRE="Hack-Italic.woff"
  38. ITALIC_WOFF="hack-italic.woff"
  39. BOLDITALIC_TTF="Hack-BoldItalic.ttf"
  40. BOLDITALIC_PRE="Hack-BoldItalic.woff"
  41. BOLDITALIC_WOFF="hack-bolditalic.woff"
  42. # test for number of arguments
  43. if [ $# -gt 1 ]
  44. then
  45. echo "Inappropriate arguments included in your command." 1>&2
  46. echo "Usage: ./build-woff.sh (--system)" 1>&2
  47. exit 1
  48. fi
  49. # determine if system installed executable on PATH is requested for build
  50. # then test for presence of the sfnt2woff-zopfli build dependency based upon where it should be located
  51. if [ "$1" = "--system" ]; then
  52. SFNTWOFF_BIN="sfnt2woff-zopfli"
  53. if ! which $SFNTWOFF_BIN; then
  54. echo "Unable to identify sfnt2woff-zopfli executable on system PATH. Please install and try again." 1>&2
  55. exit 1
  56. else
  57. # display version of installed sfnt2woff-zopfli
  58. echo "Beginning web font build with $SFNTWOFF_BIN"
  59. fi
  60. fi
  61. # test for sfnt2woff-zopfli with default build approach
  62. if [ $# -eq 0 ]; then
  63. if [ -f "$SFNTWOFF_BIN" ]; then
  64. echo "Beginning web font build with $SFNTWOFF_BIN"
  65. else
  66. echo "Unable to locate sfnt2woff-zopfli on the path $SFNTWOFF_BIN. Please install this build dependency and then repeat your build attempt." 1>&2
  67. exit 1
  68. fi
  69. fi
  70. # Build woff files from ttf files
  71. # regular set
  72. if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$REGULAR_TTF"; then
  73. echo "Failed to build $REGULAR_WOFF from $REGULAR_TTF." 1>&2
  74. exit 1
  75. else
  76. echo "Regular woff set successfully built from $REGULAR_TTF"
  77. fi
  78. # bold set
  79. if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$BOLD_TTF"; then
  80. echo "Failed to build $BOLD_WOFF from $BOLD_TTF" 1>&2
  81. exit 1
  82. else
  83. echo "Bold woff set successfully built from $BOLD_TTF"
  84. fi
  85. # italic set
  86. if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$ITALIC_TTF"; then
  87. echo "Failed to build $BOLD_WOFF from $ITALIC_TTF" 1>&2
  88. exit 1
  89. else
  90. echo "Italic woff set successfully built from $ITALIC_TTF"
  91. fi
  92. # bold italic set
  93. if ! "$SFNTWOFF_BIN" -n $ZOPFLI_ITERATIONS "$TTF_BUILD/$BOLDITALIC_TTF"; then
  94. echo "Failed to build $BOLDITALIC_WOFF from $BOLDITALIC_TTF" 1>&2
  95. exit 1
  96. else
  97. echo "Bold Italic woff set successfully built from $BOLDITALIC_TTF"
  98. fi
  99. echo "Moving woff files to build directory..."
  100. # create directory if it does not exist
  101. # (occurs with git + empty directories)
  102. if ! [ -d "$WOFF_BUILD" ]; then
  103. mkdir $WOFF_BUILD
  104. fi
  105. # move woff files to appropriate build directory
  106. mv "$TTF_BUILD/$REGULAR_PRE" "$WOFF_BUILD/$REGULAR_WOFF"
  107. mv "$TTF_BUILD/$BOLD_PRE" "$WOFF_BUILD/$BOLD_WOFF"
  108. mv "$TTF_BUILD/$ITALIC_PRE" "$WOFF_BUILD/$ITALIC_WOFF"
  109. mv "$TTF_BUILD/$BOLDITALIC_PRE" "$WOFF_BUILD/$BOLDITALIC_WOFF"
  110. echo " "
  111. if [ -f "$WOFF_BUILD/$REGULAR_WOFF" ]; then
  112. echo "Regular woff build path: $WOFF_BUILD/$REGULAR_WOFF"
  113. fi
  114. if [ -f "$WOFF_BUILD/$BOLD_WOFF" ]; then
  115. echo "Bold woff build path: $WOFF_BUILD/$BOLD_WOFF"
  116. fi
  117. if [ -f "$WOFF_BUILD/$ITALIC_WOFF" ]; then
  118. echo "Italic woff build path: $WOFF_BUILD/$ITALIC_WOFF"
  119. fi
  120. if [ -f "$WOFF_BUILD/$BOLDITALIC_WOFF" ]; then
  121. echo "Bold Italic woff build path: $WOFF_BUILD/$BOLDITALIC_WOFF"
  122. fi