mirror of
https://github.com/tonsky/FiraCode.git
synced 2024-08-16 08:20:37 +03:00
31adb247e5
All features that were not already in their own files were pulled out of FiraCode.glyphs into individual files. There is no way I will write a parser for the glyphs file to do that at runtime. The build script will then read the code in these feature files and appends it to the `calt` property inside the glyphs file. Features to be baked in can be given to build.sh as a comma separated list with the `-f / --features` flag. To more easily generate multiple font versions with different features baked in, there are flags `-n / --family-name` for build.sh that will allow users to set a custom family name for the font. The special value "features" will append the feature list to the font name. The family name is exported and used by the other build scripts as a directory to separate different font versions. The filenames were not changed, the directory name is enough separation. The flag `-g / --generate-glyphs-only` will cause the script to exit after the custom glyphs file has been created without actually building the font. The custom .glyphs file will be saved as `${family_name}.glyphs`. Via another flag, `-w / --weights`, a comma separated list of font weights to be generated can be given to build.sh. The README received a hint to the new capabilities. Fixed a mixup of cv25 and cv32. The .gitignore was adjusted to better deal with the new directories and files.
101 lines
2.6 KiB
Bash
Executable File
101 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
set -o errexit -o pipefail
|
|
cd "$(dirname "$0")"
|
|
|
|
features=()
|
|
weights=()
|
|
gen_glyphs_file_only=0
|
|
use_features_for_family_name=0
|
|
export FIRACODE_FAMILY_NAME="Fira Code"
|
|
|
|
########### Parsing inputs ########### {{{
|
|
check_required_args()
|
|
{
|
|
if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then
|
|
echo "Error: Missing argument for '$1'" >&2
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
while [ $# -gt 0 ]; do
|
|
# split parameters like '-f="1,2,3"' into '-f "1,2,3"'
|
|
[[ "$1" == -*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}"
|
|
case "$1" in
|
|
-f | --features)
|
|
check_required_args "$1" "$2" || exit 1
|
|
# turn comma separated list into sorted array
|
|
IFS=',' read -r -a features <<< "$(echo "$2" | tr ',' '\n' | sort -u | tr '\n' ',')"
|
|
shift 2 # remove two params (flag + arg)
|
|
;;
|
|
-w | --weights)
|
|
check_required_args "$1" "$2" || exit 1
|
|
IFS=',' read -r -a weights <<< "$2"
|
|
shift 2 # remove two params (flag + arg)
|
|
;;
|
|
-n | --family-name)
|
|
check_required_args "$1" "$2" || exit 1
|
|
if [ "$2" = "features" ]; then
|
|
use_features_for_family_name=1
|
|
else
|
|
FIRACODE_FAMILY_NAME=$2
|
|
fi
|
|
shift 2 # remove two params (flag + arg)
|
|
;;
|
|
-g | --generate-glyphs-only)
|
|
gen_glyphs_file_only=1
|
|
shift 1
|
|
;;
|
|
-*) # unsupported flags
|
|
echo "Error: Unsupported flag '$1'" >&2
|
|
exit 1
|
|
;;
|
|
*) # positional parameters
|
|
echo "Error: No use case for positional paramter '$1'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
########### ############## ########### }}}
|
|
|
|
# Create a temporary file that can be manipulated without messing with the original
|
|
FIRACODE_GLYPHS_FILE=$(mktemp --suffix=".glyphs")
|
|
export FIRACODE_GLYPHS_FILE
|
|
cp ../FiraCode.glyphs "${FIRACODE_GLYPHS_FILE}"
|
|
|
|
feat_string=""
|
|
if [ -n "${features[*]}" ]; then
|
|
echo "Creating font with these features: ${features[*]}"
|
|
./bake_in_features.sh "${features[@]}"
|
|
|
|
feat_string=" ${features[*]}"
|
|
fi
|
|
|
|
if [ "${use_features_for_family_name}" -ne 0 ]; then
|
|
FIRACODE_FAMILY_NAME=${FIRACODE_FAMILY_NAME}${feat_string}
|
|
fi
|
|
|
|
if [ "${FIRACODE_FAMILY_NAME}" != "Fira Code" ]; then
|
|
tmp_glyphs=$(mktemp --suffix=".glyphs")
|
|
echo "Creating font with family name: ${FIRACODE_FAMILY_NAME}"
|
|
|
|
awk '/familyName = "Fira Code";/ {$0=nc}1' nc="familyName = \"${FIRACODE_FAMILY_NAME}\";" \
|
|
"${FIRACODE_GLYPHS_FILE}" > "${tmp_glyphs}"
|
|
|
|
mv "${tmp_glyphs}" "${FIRACODE_GLYPHS_FILE}"
|
|
fi
|
|
|
|
cp "${FIRACODE_GLYPHS_FILE}" "../${FIRACODE_FAMILY_NAME}.glyphs"
|
|
echo "Generated glyphs file: ${FIRACODE_FAMILY_NAME}.glyphs"
|
|
|
|
if [ "${gen_glyphs_file_only}" -ne 0 ]; then
|
|
echo "Custom .glyphs file created. Exiting here!"
|
|
exit 0
|
|
fi
|
|
|
|
./build_ttf.sh "${weights[@]}"
|
|
./build_variable.sh
|
|
./build_woff2.sh
|
|
./build_woff.sh
|
|
|
|
rm -f "${FIRACODE_GLYPHS_FILE}"
|