Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow hardcoding of features via arguments to build script #1387

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
*.zip
FiraCode_liga.glyphs
FiraCode_mess.glyphs
target
clojure/*.edn
FiraCode\ (Autosaved).glyphs
FiraCode_VF.glyphs
.cpcache
master_ufo
instance_ufo
venv
.DS_Store
*.numbers
distr/ttf
distr/otf
distr/woff
distr/woff2
distr/variable_ttf

distr/*/

*.glyphs
!FiraCode.glyphs

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ make
make package
```

If you want to *permanently enable* certain style sets or character variations, maybe because your editor of choice does not allow you to toggle these individually, you can provide the desired features as a comma separated list to the build script via the `-f / --features` flag.<br>Default: none.

To separate different versions of your font you can specify the desired font family name with the `-n / --family-name` flag. The special value 'features' will append a sorted, space separated list of enabled features to the default family name.<br>Default: "Fira Code"

You can also limit the font weights that will be created with the `-w / --weights` option.<br>Default: "Light,Regular,Retina,Medium,SemiBold,Bold"

```bash
# locally in your shell
./script/build.sh --features "ss02,ss08,ss10,cv03,cv07,cv14" --family-name "Fira Code straight" --weights "Regular,Bold"

# or via a docker container (creates the family name 'Fira Code cv01 cv02 cv06 cv31 onum ss01 ss03 ss04 zero')
docker run --rm -v "${PWD}":/opt tonsky/firacode:latest ./script/build.sh -f "cv01,cv02,cv06,ss01,zero,onum,ss03,ss04,cv31" -n "features"
```

### Credits

- Author: Nikita Prokopov [@nikitonsky](https://twitter.com/nikitonsky)
Expand Down
12 changes: 12 additions & 0 deletions features/cv01.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Name: alternate lowercase a

sub a by a.cv01;
sub aacute by aacute.cv01;
sub abreve by abreve.cv01;
sub acircumflex by acircumflex.cv01;
sub adieresis by adieresis.cv01;
sub agrave by agrave.cv01;
sub amacron by amacron.cv01;
sub aogonek by aogonek.cv01;
sub aring by aring.cv01;
sub atilde by atilde.cv01;
7 changes: 7 additions & 0 deletions features/cv02.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Name: single story lowercase g

sub g by g.cv02;
sub gbreve by gbreve.cv02;
sub gcircumflex by gcircumflex.cv02;
sub gcommaaccent by gcommaaccent.cv02;
sub gdotaccent by gdotaccent.cv02;
13 changes: 13 additions & 0 deletions features/cv03.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Name: lowercase I without any horizontal decorations

sub i by i.cv03;
sub idotless by idotless.cv03;
sub iacute by iacute.cv03;
sub ibreve by ibreve.cv03;
sub icircumflex by icircumflex.cv03;
sub idieresis by idieresis.cv03;
sub idotaccent by idotaccent.cv03;
sub igrave by igrave.cv03;
sub imacron by imacron.cv03;
sub iogonek by iogonek.cv03;
sub itilde by itilde.cv03;
13 changes: 13 additions & 0 deletions features/cv04.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Name: lowercase I with horizontal left line at the top

sub i by i.cv04;
sub idotless by idotless.cv04;
sub iacute by iacute.cv04;
sub ibreve by ibreve.cv04;
sub icircumflex by icircumflex.cv04;
sub idieresis by idieresis.cv04;
sub idotaccent by idotaccent.cv04;
sub igrave by igrave.cv04;
sub imacron by imacron.cv04;
sub iogonek by iogonek.cv04;
sub itilde by itilde.cv04;
13 changes: 13 additions & 0 deletions features/cv05.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Name: lowercase I with horizontal left line at the top and right line at the bottom

sub i by i.cv05;
sub idotless by idotless.cv05;
sub iacute by iacute.cv05;
sub ibreve by ibreve.cv05;
sub icircumflex by icircumflex.cv05;
sub idieresis by idieresis.cv05;
sub idotaccent by idotaccent.cv05;
sub igrave by igrave.cv05;
sub imacron by imacron.cv05;
sub iogonek by iogonek.cv05;
sub itilde by itilde.cv05;
13 changes: 13 additions & 0 deletions features/cv06.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Name: lowercase I with horizontal left line at the top and curved right hook at the bottom

sub i by i.cv06;
sub idotless by idotless.cv06;
sub iacute by iacute.cv06;
sub ibreve by ibreve.cv06;
sub icircumflex by icircumflex.cv06;
sub idieresis by idieresis.cv06;
sub idotaccent by idotaccent.cv06;
sub igrave by igrave.cv06;
sub imacron by imacron.cv06;
sub iogonek by iogonek.cv06;
sub itilde by itilde.cv06;
8 changes: 8 additions & 0 deletions features/cv07.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Name: lowercase L without any horizontal decorations

sub l by l.cv07;
sub lacute by lacute.cv07;
sub lcaron by lcaron.cv07;
sub lcommaaccent by lcommaaccent.cv07;
sub ldot by ldot.cv07;
sub lslash by lslash.cv07;
8 changes: 8 additions & 0 deletions features/cv08.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Name: lowercase L with horizontal left line at the top

sub l by l.cv08;
sub lacute by lacute.cv08;
sub lcaron by lcaron.cv08;
sub lcommaaccent by lcommaaccent.cv08;
sub ldot by ldot.cv08;
sub lslash by lslash.cv08;
8 changes: 8 additions & 0 deletions features/cv09.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Name: lowercase L with horizontal left line at the top and right line at the bottom

sub l by l.cv09;
sub lacute by lacute.cv09;
sub lcaron by lcaron.cv09;
sub lcommaaccent by lcommaaccent.cv09;
sub ldot by ldot.cv09;
sub lslash by lslash.cv09;
8 changes: 8 additions & 0 deletions features/cv10.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Name: lowercase L with horizontal left line at the top and horizontal base

sub l by l.cv10;
sub lacute by lacute.cv10;
sub lcaron by lcaron.cv10;
sub lcommaaccent by lcommaaccent.cv10;
sub ldot by ldot.cv10;
sub lslash by lslash.cv10;
4 changes: 4 additions & 0 deletions features/cv11.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Name: zero without anything inside

sub zero by zero.cv11;
sub zero.tosf by zero.tosf.cv11;
4 changes: 4 additions & 0 deletions features/cv12.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Name: zero with a backslash inside

sub zero by zero.cv12;
sub zero.tosf by zero.tosf.cv12;
4 changes: 4 additions & 0 deletions features/cv13.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Name: zero with a vertical line inside

sub zero by zero.cv13;
sub zero.tosf by zero.tosf.cv13;
8 changes: 8 additions & 0 deletions features/cv14.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Name: 3 with straight lines for the top half

sub three by three.cv14;
sub three.tosf by three.tosf.cv14;
sub threeinferior by threeinferior.cv14;
sub three.dnom by three.dnom.cv14;
sub three.numr by three.numr.cv14;
sub threesuperior by threesuperior.cv14;
3 changes: 3 additions & 0 deletions features/cv17.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Name: Top-aligned tilde

sub asciitilde by asciitilde.cv17;
5 changes: 5 additions & 0 deletions features/cv18.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Name: percent sign with dots instead of hollow circles

sub percent by percent.cv18;
sub perthousand by perthousand.cv18;
sub percent_percent.liga by percent_percent.liga.cv18;
4 changes: 2 additions & 2 deletions features/cv25.fea
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
lookup period_hyphen {
ignore sub period period' hyphen;
ignore sub period' hyphen hyphen;
sub period.spacer hyphen' by period_hyphen.cv32;
sub period.spacer hyphen' by period_hyphen.cv25;
sub period' hyphen by period.spacer;
} period_hyphen;
} period_hyphen;
5 changes: 5 additions & 0 deletions features/cv29.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Name: Rounded curly braces {}

sub braceleft by braceleft.cv29;
sub braceright by braceright.cv29;
sub numbersign_braceleft.liga by numbersign_braceleft.liga.cv29;
18 changes: 18 additions & 0 deletions features/cv30.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Name: longer pipe symbol

sub bar by bar.cv30;
sub bar_bar.liga by bar_bar.liga.cv30;
sub bar_bar_bar.liga by bar_bar_bar.liga.cv30;
sub bar_bar_equal_middle.seq by bar_bar_equal_middle.seq.cv30;
sub bar_equal_middle.seq by bar_equal_middle.seq.cv30;
sub bar_bar_equal_end.seq by bar_bar_equal_end.seq.cv30;
sub bar_bar_equal_start.seq by bar_bar_equal_start.seq.cv30;
sub bar_bar_hyphen_middle.seq by bar_bar_hyphen_middle.seq.cv30;
sub bar_hyphen_middle.seq by bar_hyphen_middle.seq.cv30;
sub bar_bar_hyphen_end.seq by bar_bar_hyphen_end.seq.cv30;
sub bar_bar_hyphen_start.seq by bar_bar_hyphen_start.seq.cv30;
sub bar_equal_end.seq by bar_equal_end.seq.cv30;
sub bar_equal_start.seq by bar_equal_start.seq.cv30;
sub bar_hyphen_end.seq by bar_hyphen_end.seq.cv30;
sub bar_hyphen_start.seq by bar_hyphen_start.seq.cv30;
sub bar_underscore_middle.seq by bar_underscore_middle.seq.cv30;
4 changes: 4 additions & 0 deletions features/cv31.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Name: Circular parentheses

sub parenleft by parenleft.cv31;
sub parenright by parenright.cv31;
4 changes: 2 additions & 2 deletions features/cv32.fea
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
lookup period_equal {
ignore sub period period' equal;
ignore sub period' equal equal;
sub period.spacer equal' by period_equal.cv25;
sub period.spacer equal' by period_equal.cv32;
sub period' equal by period.spacer;
} period_equal;
} period_equal;
4 changes: 4 additions & 0 deletions features/zero.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Name: Zero with a dot inside

sub zero by zero.zero;
sub zero.tosf by zero.tosf.zero;
28 changes: 28 additions & 0 deletions script/bake_in_features.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/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}"
Daxtorim marked this conversation as resolved.
Show resolved Hide resolved
100 changes: 96 additions & 4 deletions script/build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,100 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
cd "`dirname $0`"
set -o errexit -o pipefail
cd "$(dirname "$0")"

./build_ttf.sh
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
./build_woff.sh

rm -f "${FIRACODE_GLYPHS_FILE}"
Loading