mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-14 19:26:56 -04:00
Desktop builds made with CRAFT_FONTS_DIR now load craft-fonts' 12 Arabic families into the document font database. Noto Sans Arabic comes first and is the fallback for Arabic text. Cairo, Tajawal, Almarai, IBM Plex Sans Arabic, Noto Kufi Arabic, Amiri, Alexandria, Fustat, Reem Kufi, Aref Ruqaa and Gulzar can be picked by name from the font menus. The web build doesn't embed these fonts because they would make the wasm too large. It fetches them from beside the wasm instead: - crates/text/web-fonts.txt lists each face as startup or background. - build.rs turns that list into vectorcraft_text::WEB_FONTS, with each face's URL (fonts/<sha16>/<file>) and SRI hash taken from the craft-fonts manifest. - packaging/web/copy-fonts.sh, a Trunk post_build hook, copies the font files and their OFL licences there. - apps/vectorcraft-web/src/fonts.rs fetches Noto Sans Arabic before the app starts, so Arabic text never shows as boxes. It loads the other faces in the background and logs `web font …` for any that fail. Because fonts can now arrive after startup, the Type tool's layout cache also checks the font database's generation, so text lays out again when new fonts arrive. _headers and .htaccess serve fonts/* as font/ttf and cache it as immutable. packaging/web/README.md and docs/development.md explain the fonts folder, and ROADMAP.md lists the Arabic typefaces under Type. Also adds Ahmed Moussa to contributors/people.toml. Signed-off-by: Ahmed Moussa <[email protected]>
32 lines
1.6 KiB
Bash
Executable File
32 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Trunk post_build hook (apps/vectorcraft-web/Trunk.toml): copy the craft-fonts faces listed in
|
|
# crates/text/web-fonts.txt from $CRAFT_FONTS_DIR into the site, each at
|
|
# fonts/<first 16 hex digits of its SHA-256>/<file> with its licence beside it: the URLs
|
|
# crates/text/build.rs puts in WEB_FONTS. A no-op without CRAFT_FONTS_DIR.
|
|
set -eu
|
|
[ -n "${CRAFT_FONTS_DIR:-}" ] || exit 0
|
|
: "${TRUNK_STAGING_DIR:?run me as a Trunk post_build hook (TRUNK_STAGING_DIR unset)}"
|
|
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
|
LIST="$ROOT/crates/text/web-fonts.txt"
|
|
MANIFEST="$CRAFT_FONTS_DIR/fonts/manifest.txt"
|
|
[ -f "$MANIFEST" ] || { echo "copy-fonts: $MANIFEST not found" >&2; exit 1; }
|
|
|
|
sha256() {
|
|
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1
|
|
else shasum -a 256 "$1" | cut -d' ' -f1; fi
|
|
}
|
|
|
|
grep -v '^[[:space:]]*#' "$LIST" | grep -v '^[[:space:]]*$' | while IFS= read -r line; do
|
|
family=$(printf '%s\n' "$line" | awk -F' [|] ' '{print $2}')
|
|
style=$(printf '%s\n' "$line" | awk -F' [|] ' '{print $3}')
|
|
row=$(awk -F' [|] ' -v f="$family" -v s="$style" '$1 == f && $2 == s { print $3 "|" $6 "|" $7; exit }' "$MANIFEST")
|
|
[ -n "$row" ] || { echo "copy-fonts: $family $style is not in $MANIFEST" >&2; exit 1; }
|
|
file=${row%%|*}; rest=${row#*|}; licence=${rest%%|*}; sha=${rest#*|}
|
|
got=$(sha256 "$CRAFT_FONTS_DIR/$file")
|
|
[ "$got" = "$sha" ] || { echo "copy-fonts: $file: sha256 $got, manifest says $sha" >&2; exit 1; }
|
|
dest="$TRUNK_STAGING_DIR/fonts/$(printf '%s' "$sha" | cut -c1-16)"
|
|
mkdir -p "$dest"
|
|
cp "$CRAFT_FONTS_DIR/$file" "$dest/"
|
|
cp "$CRAFT_FONTS_DIR/$licence" "$dest/"
|
|
done
|