1
1
mirror of https://github.com/tonsky/FiraCode.git synced 2024-11-20 19:48:59 +03:00
FiraCode/script/bake_in_features.sh
Fabian Preuß 31adb247e5 feat: allow hardcoding of features via arguments to build script
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.
2022-03-15 15:34:25 +01:00

29 lines
853 B
Bash
Executable File

#!/bin/bash
set -o errexit -o nounset -o pipefail
cd "$(dirname "$0")/.."
glyphs_file=${FIRACODE_GLYPHS_FILE:-"FiraCode.glyphs"}
code_blocks=()
for feat in "$@"; do
file="features/${feat}.fea"
if [ ! -f "${file}" ]; then
echo "Error: No file for feature ${feat} found!" >&2
exit 1
fi
# don't grab the "lookup" surroundings or comments or whitespace lines
code="$(grep -v '^[[:space:]]*lookup\|^[[:space:]]*}\|^[[:space:]]*#\|^[[:space:]]*$' "${file}")" \
|| { echo "Error: No code for feature ${feat} found!" >&2; exit 1; }
code_blocks+=("$(tr '\n' ' ' <<< "${code}")")
done
# code block is one line above name declaration
linenum=$(sed -n "/name = calt;/=" "${glyphs_file}")
linenum=$((linenum - 1))
# replace end of line (";) with code on specified line number
sed -i -e "${linenum}s@\";\$@\n${code_blocks[*]}\";@" "${glyphs_file}"