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>
This commit is contained in:
Fini Jastrow 2022-09-13 12:05:26 +02:00
parent fae0b4cb16
commit 3444b5755f
2 changed files with 25 additions and 14 deletions

View file

@ -1,18 +1,31 @@
#!/bin/bash #!/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() { main() {
output_dir="/home/ryan/projects/nerd-fonts-gh-pages/assets/img/previews/"
template_svg="lib/inkscape-template-font-preview.svg"
mkdir -p "$output_dir" mkdir -p "$output_dir"
for i in $(jq '.fonts | keys | .[]' lib/fonts.json); do for i in $(jq '.fonts | keys | .[]' lib/fonts.json); do
patchedName=$(jq -r ".fonts[$i].patchedName" lib/fonts.json); patchedName=$(jq -r ".fonts[$i].patchedName" lib/fonts.json);
#unpatchedName=$(jq -r ".fonts[$i].unpatchedName" lib/fonts.json);
imagePreviewFont=$(jq -r ".fonts[$i].imagePreviewFont" lib/fonts.json); imagePreviewFont=$(jq -r ".fonts[$i].imagePreviewFont" lib/fonts.json);
if [ -z "$imagePreviewFont" ]; then
echo "[Skipping] $patchedName"
continue
fi
generate_preview "$imagePreviewFont" "$patchedName Nerd Font" fc-list -q "$imagePreviewFont" \
&& generate_preview "$imagePreviewFont" "$patchedName Nerd Font" \
|| echo "[Missing] $imagePreviewFont"
done done
} }
@ -20,11 +33,10 @@ main() {
generate_preview() { generate_preview() {
font=$1 font=$1
fontText=$2 fontText=$2
echo "generating image preview for font: '$font'" echo "[Generating] $font"
sed -e "s/000000/ffffff/" -e "s/sans-serif/${font}/" -e "s/Font Name/${fontText}/" <"$template_svg" >"${output_dir}${fontText}.svg" sed -e "s/000000/ffffff/" -e "s/sans-serif/${font}/" -e "s/Font Name/${fontText}/" <"$template_svg" >"${output_dir}${fontText}.svg"
inkscape -f "${output_dir}${fontText}.svg" --with-gui --verb EditSelectAll --verb ObjectToPath --verb FileVacuum --verb FitCanvasToDrawing --verb FileSave --verb FileQuit &>/dev/null & 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" # svgo "${output_dir}${fontText}.svg"
} }
main "$@"; exit main "$@"; exit

View file

@ -372,7 +372,7 @@
"unpatchedName": "Symbols Template 1000 EM", "unpatchedName": "Symbols Template 1000 EM",
"patchedName": "Symbols-1000-em Nerd Font Complete", "patchedName": "Symbols-1000-em Nerd Font Complete",
"folderName": "NerdFontsSymbolsOnly", "folderName": "NerdFontsSymbolsOnly",
"imagePreviewFont": "Symbols Nerd Font", "imagePreviewFont": "",
"linkPreviewFont": false, "linkPreviewFont": false,
"description": "Just the Nerd Font Icons. I.e Symbol font only. 1000 EM size" "description": "Just the Nerd Font Icons. I.e Symbol font only. 1000 EM size"
}, },
@ -380,7 +380,7 @@
"unpatchedName": "Symbols Template 2048 EM", "unpatchedName": "Symbols Template 2048 EM",
"patchedName": "Symbols-2048-em Nerd Font Complete", "patchedName": "Symbols-2048-em Nerd Font Complete",
"folderName": "NerdFontsSymbolsOnly", "folderName": "NerdFontsSymbolsOnly",
"imagePreviewFont": "Symbols Nerd Font", "imagePreviewFont": "",
"linkPreviewFont": false, "linkPreviewFont": false,
"description": "Just the Nerd Font Icons. I.e Symbol font only. 2048 EM size" "description": "Just the Nerd Font Icons. I.e Symbol font only. 2048 EM size"
}, },
@ -426,4 +426,3 @@
} }
] ]
} }