1
0
mirror of https://github.com/ryanoasis/nerd-fonts.git synced 2024-12-13 17:18:37 +02:00
nerd-fonts/bin/scripts/generate-font-image-previews.sh
Fini Jastrow 3444b5755f generate-font-image-previews: Fix and Refactor [skip-ci]
[why]
The script is not running with current (i.e. year 2022) release versions
of Inkscape.

The script does not warn if a font is not installed (and creates a
garbage preview instead).

[how]
Rewrite the script that is uses Inkscape actions instead of verbs. Verbs
are already removed in Inkscape HEAD.

Check if needed font is indeed installed.

Do not generate useless Symbols Only font preview (it needs a specific
different one, I suppose).

Disable `svgo`. Maybe we should generate PNGs instead?

Change path for created images, so that it is already correct for the
gh-pages and we could use the github-pages-deploy-action to publish them.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-09-13 12:13:16 +02:00

43 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Nerd Fonts Version: 2.2.2
# Script Version: 1.0.1
# 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/inkscape-template-font-preview.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 [ -z "$imagePreviewFont" ]; then
echo "[Skipping] $patchedName"
continue
fi
fc-list -q "$imagePreviewFont" \
&& generate_preview "$imagePreviewFont" "$patchedName Nerd Font" \
|| echo "[Missing] $imagePreviewFont"
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}${fontText}.svg"
inkscape "${output_dir}${fontText}.svg" "--actions=select-all;object-to-path;export-filename:${output_dir}${fontText}.svg;export-do;quit-inkscape" 2>/dev/null
# svgo "${output_dir}${fontText}.svg"
}
main "$@"; exit