#!/usr/bin/env bash # Generate a legacy-format fontconfig.properties for Webswing's app JVM. # # Why this exists: OpenJDK 9+ stopped shipping lib/fontconfig.bfc and queries # libfontconfig at runtime instead. Webswing's WebFontConfiguration still extends # the legacy sun.awt.FontConfiguration, which reads the old properties file. With # no such file the app JVM dies at startup with "Fontconfig head is null". The JVM # honours -Dsun.awt.fontconfig=, so we generate one. # # Font choice matters as much as existence. MegaMek draws armor pips, heat # markers and status icons with symbol codepoints, and Noto Sans covers almost # none of them (of the 18 codepoints MegaMek uses, Noto Sans has exactly one: # U+00B0). Those render as boxes. So: # # base DejaVu - broad symbol coverage on top of normal text # fallback Noto Sans Symbols2 U+2B1D armor pips, U+2744, U+2B71/73 # Material Symbols Rounded MegaMek's bundled Private Use icons # # Do NOT add "Noto Sans Symbols" (no 2) as a further fallback for U+23AF. Its # family name is a prefix of "Noto Sans Symbols2" and the legacy parser # mis-resolves between them: basic punctuation (/ : , parens) starts rendering as # boxes and the armor pips disappear. Verified by screenshot, and reverted. # # Verify coverage changes with the GlyphCoverage probe rather than by eye. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" OUT="${1:-$ROOT/spike-webswing/fontconfig.properties}" MM_HOME="${MM_HOME:-$ROOT/MegaMek-0.51.00}" mkdir -p "$(dirname "$OUT")" command -v fc-match >/dev/null || { echo "ERROR: fc-match not found (install fontconfig)" >&2; exit 1; } resolve() { fc-match -f '%{file}' "$1" 2>/dev/null || true; } xlfd() { printf -- '-*-%s-%s-%s-normal--*-%%d-*-*-p-*-%s' "$1" "$2" "$3" "$4"; } key() { printf 'filename.%s' "$(printf '%s' "$1" | tr ' ' '_')"; } # DejaVu rather than Noto: it carries the symbol coverage MegaMek needs. declare -A FAMILY=( [serif]="DejaVu Serif" [sansserif]="DejaVu Sans" [monospaced]="DejaVu Sans Mono" [dialog]="DejaVu Sans" [dialoginput]="DejaVu Sans Mono" ) { echo "# Generated by scripts/gen-fontconfig.sh - do not edit by hand." echo "version=1" echo echo "sequence.allfonts=latin-1" echo "sequence.fallback=symbols2,micons" echo } > "$OUT" # Component fonts: .