build.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. set -o errexit -o pipefail
  3. cd "$(dirname "$0")"
  4. features=()
  5. weights=()
  6. gen_glyphs_file_only=0
  7. use_features_for_family_name=0
  8. export FIRACODE_FAMILY_NAME="Fira Code"
  9. ########### Parsing inputs ########### {{{
  10. check_required_args()
  11. {
  12. if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then
  13. echo "Error: Missing argument for '$1'" >&2
  14. return 1
  15. fi
  16. return 0
  17. }
  18. while [ $# -gt 0 ]; do
  19. # split parameters like '-f="1,2,3"' into '-f "1,2,3"'
  20. [[ "$1" == -*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}"
  21. case "$1" in
  22. -f | --features)
  23. check_required_args "$1" "$2" || exit 1
  24. # turn comma separated list into sorted array
  25. IFS=',' read -r -a features <<< "$(echo "$2" | tr ',' '\n' | sort -u | tr '\n' ',')"
  26. shift 2 # remove two params (flag + arg)
  27. ;;
  28. -w | --weights)
  29. check_required_args "$1" "$2" || exit 1
  30. IFS=',' read -r -a weights <<< "$2"
  31. shift 2 # remove two params (flag + arg)
  32. ;;
  33. -n | --family-name)
  34. check_required_args "$1" "$2" || exit 1
  35. if [ "$2" = "features" ]; then
  36. use_features_for_family_name=1
  37. else
  38. FIRACODE_FAMILY_NAME=$2
  39. fi
  40. shift 2 # remove two params (flag + arg)
  41. ;;
  42. -g | --generate-glyphs-only)
  43. gen_glyphs_file_only=1
  44. shift 1
  45. ;;
  46. -*) # unsupported flags
  47. echo "Error: Unsupported flag '$1'" >&2
  48. exit 1
  49. ;;
  50. *) # positional parameters
  51. echo "Error: No use case for positional paramter '$1'" >&2
  52. exit 1
  53. ;;
  54. esac
  55. done
  56. ########### ############## ########### }}}
  57. # Create a temporary file that can be manipulated without messing with the original
  58. FIRACODE_GLYPHS_FILE=$(mktemp)
  59. mv "${FIRACODE_GLYPHS_FILE}" "${FIRACODE_GLYPHS_FILE}.glyphs"
  60. FIRACODE_GLYPHS_FILE="${FIRACODE_GLYPHS_FILE}.glyphs"
  61. export FIRACODE_GLYPHS_FILE
  62. cp ../FiraCode.glyphs "${FIRACODE_GLYPHS_FILE}"
  63. feat_string=""
  64. if [ -n "${features[*]}" ]; then
  65. echo "Creating font with these features: ${features[*]}"
  66. ./bake_in_features.sh "${features[@]}"
  67. feat_string=" ${features[*]}"
  68. fi
  69. if [ "${use_features_for_family_name}" -ne 0 ]; then
  70. FIRACODE_FAMILY_NAME=${FIRACODE_FAMILY_NAME}${feat_string}
  71. fi
  72. if [ "${FIRACODE_FAMILY_NAME}" != "Fira Code" ]; then
  73. tmp_glyphs=$(mktemp)
  74. echo "Creating font with family name: ${FIRACODE_FAMILY_NAME}"
  75. awk '/familyName = "Fira Code";/ {$0=nc}1' nc="familyName = \"${FIRACODE_FAMILY_NAME}\";" \
  76. "${FIRACODE_GLYPHS_FILE}" > "${tmp_glyphs}"
  77. mv "${tmp_glyphs}" "${FIRACODE_GLYPHS_FILE}"
  78. fi
  79. cp "${FIRACODE_GLYPHS_FILE}" "../${FIRACODE_FAMILY_NAME}.glyphs"
  80. echo "Generated glyphs file: ${FIRACODE_FAMILY_NAME}.glyphs"
  81. if [ "${gen_glyphs_file_only}" -ne 0 ]; then
  82. echo "Custom .glyphs file created. Exiting here!"
  83. exit 0
  84. fi
  85. ./build_otf.sh "${weights[@]}"
  86. ./build_ttf.sh "${weights[@]}"
  87. ./build_variable.sh
  88. ./build_woff2.sh
  89. ./build_woff.sh
  90. rm -f "${FIRACODE_GLYPHS_FILE}"