Files
omarchy/test/shell.d/fontconfig-cjk-test.sh
T

71 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
if ! command -v fc-match >/dev/null || [[ $(fc-list : file) != *NotoSansCJK-Regular.ttc* ]]; then
skip "fontconfig CJK variants need fc-match and noto-fonts-cjk"
exit 0
fi
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
{
echo '<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd"><fontconfig>'
echo "<dir>/usr/share/fonts</dir><cachedir>$test_tmp/cache</cachedir>"
for conf in /etc/fonts/conf.d/*.conf; do
if [[ ${conf##*/} == "50-omarchy.conf" ]]; then
echo "<include>$ROOT/default/fontconfig/conf.avail/50-omarchy.conf</include>"
else
echo "<include>$conf</include>"
fi
done
echo '</fontconfig>'
} >"$test_tmp/fonts.conf"
export FONTCONFIG_FILE="$test_tmp/fonts.conf"
fc-cache >/dev/null
declare -A latin=([sans-serif]="Liberation Sans" [serif]="Liberation Serif" [monospace]="JetBrainsMono Nerd Font")
declare -A cjk=([sans-serif]="Noto Sans CJK" [serif]="Noto Serif CJK" [monospace]="Noto Sans Mono CJK")
declare -A variant=(
[zh]=SC [zh-cn]=SC [zh-sg]=SC [zh-hans]=SC [zh-hans-cn]=SC [zh-hans-hk]=SC
[zh-tw]=TC [zh-hant]=TC [zh-hant-tw]=TC
[zh-hk]=HK [zh-mo]=HK [zh-hant-hk]=HK [zh-hant-mo]=HK
[yue]=HK [yue-hk]=HK [yue-hant]=HK [yue-hant-hk]=HK [yue-hant-cn]=HK
[yue-hans]=SC [yue-hans-cn]=SC [yue-hans-hk]=SC [yue-cn]=SC
[ja]=JP [ja-jp]=JP [ko]=KR [ko-kr]=KR
)
family() { LANG=$1 fc-match -f '%{family[0]}' "$2"; }
for locale in C.UTF-8 zh_CN.UTF-8; do
for tag in "${!variant[@]}"; do
for generic in sans-serif serif monospace; do
actual=$(family "$locale" "$generic:lang=$tag")
[[ $actual == "${latin[$generic]}" ]] || fail "$locale $generic:lang=$tag keeps Latin in ${latin[$generic]}" "$actual"
actual=$(family "$locale" "$generic:lang=$tag:charset=9aa8")
expected="${cjk[$generic]} ${variant[$tag]}"
[[ $actual == "$expected" ]] || fail "$locale $generic:lang=$tag sets Han in $expected" "$actual"
done
done
pass "$locale: tagged CJK keeps Omarchy's Latin families and sets Han in the tag's variant"
done
for generic in sans-serif serif monospace; do
actual=$(family zh_CN.UTF-8 "$generic")
[[ $actual == "${latin[$generic]}" ]] || fail "zh_CN untagged $generic keeps ${latin[$generic]}" "$actual"
actual=$(family zh_CN.UTF-8 "$generic:charset=9aa8")
[[ $actual == "${cjk[$generic]} SC" ]] || fail "zh_CN untagged $generic sets Han in SC" "$actual"
done
pass "a Chinese locale keeps Omarchy's Latin families and sets untagged Han in SC"
[[ $(LANG=C.UTF-8 fc-pattern --config "sans-serif:lang=ja" family) == *'"Noto Sans CJK JP"(s)'* ]] ||
fail "lang=ja binds its variant strongly, so the prefix check below can see one"
for tag in jam kok; do
actual=$(LANG=C.UTF-8 fc-pattern --config "sans-serif:lang=$tag" family)
[[ ! $actual =~ CJK\ [A-Z]+\"\(s\) ]] || fail "lang=$tag is not taken for Japanese or Korean" "$actual"
done
pass "languages that only share a prefix with ja or ko get no CJK variant"