nerd-fonts/bin/scripts/generate-font-image-previews.sh
Fini Jastrow 0e434c2b9a generate-font-image-previews: Fit svg canvas to drawing [skip ci]
[why]
The generated svg's canvas is far too big.
I remember shadowy that one had to resize the canvas manually...

[how]
Switch back from Actions to Verbs, because only there we can resize the
canvas automatically.

Note commit
  3444b5755  generate-font-image-previews: Fix and Refactor [skip-ci]

Verbs seem to be still possible. There is currently no Action for the
same thing.
So we revert 3444b5755 to Ryan's original code (in principle) with the
same verbs.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-12-19 21:19:29 +01:00

59 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Nerd Fonts Version: 2.3.0-RC
# Script Version: 1.2.0
# Create font previews.
# All fonts need to be installed (or no preview is generated)
# Files should end up in the gh-pages branch
set -e
ver=$(inkscape --version)
echo "Check generator version: $ver"
output_dir="../../assets/img/previews/"
template_svg="lib/template-font-preview.svg"
template2_svg="lib/template-font-preview2.svg"
main() {
mkdir -p "$output_dir"
for i in $(jq '.fonts | keys | .[]' lib/fonts.json); do
patchedName=$(jq -r ".fonts[$i].patchedName" lib/fonts.json);
imagePreviewFont=$(jq -r ".fonts[$i].imagePreviewFont" lib/fonts.json);
# if [ "$imagePreviewFont" != "$patchedName Nerd Font" ]; then
# echo "[mismatch] $imagePreviewFont != $patchedName Nerd Font"
# fi
if [ -z "$imagePreviewFont" ]; then
echo "[Skipping] $patchedName"
continue
fi
if $( fc-list -q "${imagePreviewFont}:charset=41" ); then
generate_preview "$imagePreviewFont" "$patchedName Nerd Font"
elif $( fc-list -q "${imagePreviewFont}" ); then
generate_preview_symbols "$imagePreviewFont" "$patchedName Nerd Font"
else
echo "[Missing] $imagePreviewFont"
fi
done
}
generate_preview() {
font=$1
fontText=$2
echo "[Generating] $font"
sed -e "s/000000/ffffff/" -e "s/sans-serif/${font}/" -e "s/Font Name/${fontText}/" <"$template_svg" >"${output_dir}${font}.svg"
inkscape "${output_dir}${font}.svg" -g "--verb=EditSelectAll;ObjectToPath;FileVacuum;FitCanvasToDrawing;FileSave;FileQuit" 2>/dev/null
# svgo "${output_dir}${font}.svg"
}
generate_preview_symbols() {
font=$1
fontText=$2
echo "[Gen. Symb.] $font"
sed -e "s/000000/ffffff/" -e "40,80s/sans-serif/${font}/" -e "s/Font Name/${fontText}/" <"$template2_svg" >"${output_dir}${font}.svg"
inkscape "${output_dir}${font}.svg" -g "--verb=EditSelectAll;ObjectToPath;FileVacuum;FitCanvasToDrawing;FileSave;FileQuit" 2>/dev/null
# svgo "${output_dir}${font}.svg"
}
main "$@"; exit