2022-09-13 12:05:26 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-11-26 19:49:56 +02:00
|
|
|
# Nerd Fonts Version: 3.1.1
|
2024-01-15 15:24:38 +02:00
|
|
|
# Script Version: 1.2.3
|
2022-09-13 12:05:26 +02:00
|
|
|
# Create font previews.
|
|
|
|
# All fonts need to be installed (or no preview is generated)
|
|
|
|
# Files should end up in the gh-pages branch
|
2019-08-15 22:57:52 +02:00
|
|
|
|
2022-09-13 12:05:26 +02:00
|
|
|
set -e
|
|
|
|
ver=$(inkscape --version)
|
|
|
|
echo "Check generator version: $ver"
|
2019-08-15 22:57:52 +02:00
|
|
|
|
2022-09-13 12:05:26 +02:00
|
|
|
output_dir="../../assets/img/previews/"
|
2022-12-19 18:07:20 +02:00
|
|
|
template_svg="lib/template-font-preview.svg"
|
2022-12-19 18:10:38 +02:00
|
|
|
template2_svg="lib/template-font-preview2.svg"
|
2019-08-15 22:57:52 +02:00
|
|
|
|
2022-09-13 12:05:26 +02:00
|
|
|
main() {
|
2019-09-12 23:22:39 +02:00
|
|
|
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);
|
2023-11-13 18:35:48 +02:00
|
|
|
if [ "$imagePreviewFont" != "$patchedName Nerd Font" ] && [ "$imagePreviewFont" != "$patchedName NF" ]; then
|
2023-04-28 16:55:13 +02:00
|
|
|
echo "[mismatch] (Fam vs name) $imagePreviewFont <=> $patchedName"
|
|
|
|
fi
|
2022-09-13 12:05:26 +02:00
|
|
|
if [ -z "$imagePreviewFont" ]; then
|
|
|
|
echo "[Skipping] $patchedName"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2023-06-01 10:50:33 +02:00
|
|
|
if fc-list -q "${imagePreviewFont}:charset=41" ; then
|
2022-12-19 18:10:38 +02:00
|
|
|
generate_preview "$imagePreviewFont" "$patchedName Nerd Font"
|
2023-06-01 10:50:33 +02:00
|
|
|
elif fc-list -q "${imagePreviewFont}" ; then
|
2022-12-19 18:10:38 +02:00
|
|
|
generate_preview_symbols "$imagePreviewFont" "$patchedName Nerd Font"
|
|
|
|
else
|
|
|
|
echo "[Missing] $imagePreviewFont"
|
|
|
|
fi
|
2019-09-12 23:22:39 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
generate_preview() {
|
|
|
|
font=$1
|
|
|
|
fontText=$2
|
2022-09-13 12:05:26 +02:00
|
|
|
echo "[Generating] $font"
|
2022-12-19 18:10:38 +02:00
|
|
|
sed -e "s/000000/ffffff/" -e "s/sans-serif/${font}/" -e "s/Font Name/${fontText}/" <"$template_svg" >"${output_dir}${font}.svg"
|
2023-07-26 08:55:35 +02:00
|
|
|
inkscape "${output_dir}${font}.svg" --actions="select-all; object-to-path; vacuum-defs; fit-canvas-to-selection; export-filename:${output_dir}${font}.svg; export-do"
|
2022-12-19 18:10:38 +02:00
|
|
|
# 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"
|
2023-07-26 08:55:35 +02:00
|
|
|
inkscape "${output_dir}${font}.svg" --actions="select-all; object-to-path; vacuum-defs; fit-canvas-to-selection; export-filename:${output_dir}${font}.svg; export-do"
|
2022-12-19 18:10:38 +02:00
|
|
|
# svgo "${output_dir}${font}.svg"
|
2019-09-12 23:22:39 +02:00
|
|
|
}
|
|
|
|
|
2024-01-15 15:24:38 +02:00
|
|
|
######
|
|
|
|
# For the two following helpers you need to enable THIS first:
|
|
|
|
#
|
|
|
|
# This is not 100% correct because the config.cfg is not evaluated
|
|
|
|
if false; then
|
|
|
|
cd ../../src/unpatched-fonts
|
|
|
|
image_font_files=( )
|
|
|
|
while IFS= read -d $'\n' -r f; do
|
|
|
|
dir=$(dirname "${f}")
|
|
|
|
# fontforge ~/git/nerd-fonts/font-patcher ~/git/nerd-fonts/src/unpatched-fonts/"${f}" -c --debug 3
|
|
|
|
dest=${dir}/$(fontforge ../../font-patcher --dry "${f}" --debug 2 2>/dev/null | grep 'DEBUG: =====> Filename' | sed "s/[^']*'//;s/'.*//")
|
|
|
|
echo "Found font filename: $dest"
|
|
|
|
image_font_files+=( "${dest}" )
|
|
|
|
done < <(jq -r '.fonts | .[] | ."imagePreviewFontSource"' ../../bin/scripts/lib/fonts.json)
|
|
|
|
cd -
|
|
|
|
fi
|
2023-01-30 08:55:58 +02:00
|
|
|
|
|
|
|
# Enable this to get a list of instruction to install all the needed fonts
|
|
|
|
#
|
|
|
|
# for f in "${image_font_files[@]}"; do
|
|
|
|
# echo "cp '../../patched-fonts/$f' ~/.local/share/fonts"
|
|
|
|
# done
|
|
|
|
# exit
|
|
|
|
|
|
|
|
# Enable this to get a list of Family names
|
|
|
|
#
|
|
|
|
# for f in "${image_font_files[@]}"; do
|
2023-11-19 23:22:11 +02:00
|
|
|
# fc-query "../../patched-fonts/$f" '-f %{family}\n' || true
|
2023-01-30 08:55:58 +02:00
|
|
|
# done
|
2023-11-13 17:30:25 +02:00
|
|
|
# exit
|
2023-01-30 08:55:58 +02:00
|
|
|
|
2019-09-12 23:22:39 +02:00
|
|
|
main "$@"; exit
|