diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/generate-cjk-glyph-atlas.sh | 98 | ||||
| -rwxr-xr-x | scripts/m6c-package.sh | 19 | ||||
| -rwxr-xr-x | scripts/macos-package.sh | 18 |
3 files changed, 135 insertions, 0 deletions
diff --git a/scripts/generate-cjk-glyph-atlas.sh b/scripts/generate-cjk-glyph-atlas.sh new file mode 100755 index 0000000..01a1d93 --- /dev/null +++ b/scripts/generate-cjk-glyph-atlas.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash +set -euo pipefail + +export LC_ALL=C.UTF-8 + +SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)" +FONT_PATH="${CJK_FONT_PATH:-/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc}" +MANIFEST="$REPO_ROOT/src/LivingVillage.Desktop/Assets/cjk-glyphs.txt" +OUTPUT="$REPO_ROOT/src/LivingVillage.Desktop/Assets/cjk-glyph-atlas.png" +CELL_PIXELS=24 +COLUMNS=16 +POINT_SIZE=20 + +for command_name in convert identify; do + if ! command -v "$command_name" >/dev/null 2>&1; then + printf 'Required command is missing: %s\n' "$command_name" >&2 + exit 127 + fi +done + +if [[ ! -f "$FONT_PATH" ]]; then + printf 'CJK font not found: %s\n' "$FONT_PATH" >&2 + exit 2 +fi + +if [[ ! -f "$MANIFEST" ]]; then + printf 'CJK glyph manifest not found: %s\n' "$MANIFEST" >&2 + exit 2 +fi + +mapfile -t manifest_lines < "$MANIFEST" +character_count=${#manifest_lines[@]} +if (( character_count == 0 )); then + printf 'CJK glyph manifest is empty: %s\n' "$MANIFEST" >&2 + exit 2 +fi + +characters="" +declare -A seen_characters=() +for index in "${!manifest_lines[@]}"; do + character="${manifest_lines[$index]}" + if [[ ${#character} -ne 1 ]]; then + printf 'CJK glyph manifest line %s must contain exactly one character: %s\n' "$((index + 1))" "$MANIFEST" >&2 + exit 2 + fi + if [[ ${seen_characters[$character]+present} ]]; then + printf 'CJK glyph manifest contains a duplicate character on line %s: %s\n' "$((index + 1))" "$MANIFEST" >&2 + exit 2 + fi + seen_characters[$character]=1 + characters+="$character" +done + +rows=$(( (character_count + COLUMNS - 1) / COLUMNS )) +width=$(( COLUMNS * CELL_PIXELS )) +height=$(( rows * CELL_PIXELS )) +temporary_root="$(mktemp -d)" +trap 'rm -rf "$temporary_root"' EXIT + +temporary_atlas="$temporary_root/cjk-glyph-atlas.png" +convert -size "${width}x${height}" xc:none -alpha on "$temporary_atlas" + +for (( index = 0; index < character_count; index++ )); do + character="${characters:index:1}" + column=$(( index % COLUMNS )) + row=$(( index / COLUMNS )) + x=$(( column * CELL_PIXELS )) + y=$(( row * CELL_PIXELS )) + cell="$temporary_root/cell-$index.png" + next_atlas="$temporary_root/atlas-$index.png" + + convert \ + -size "${CELL_PIXELS}x${CELL_PIXELS}" \ + xc:none \ + -alpha on \ + -font "$FONT_PATH" \ + -pointsize "$POINT_SIZE" \ + -fill white \ + -gravity center \ + -antialias \ + -annotate +0+0 "$character" \ + "$cell" + convert "$temporary_atlas" "$cell" -geometry "+${x}+${y}" -composite "$next_atlas" + mv "$next_atlas" "$temporary_atlas" +done + +convert "$temporary_atlas" -strip "$OUTPUT" +actual_dimensions="$(identify -format '%wx%h' "$OUTPUT")" +expected_dimensions="${width}x${height}" +if [[ "$actual_dimensions" != "$expected_dimensions" ]]; then + printf 'Generated atlas dimensions %s; expected %s\n' "$actual_dimensions" "$expected_dimensions" >&2 + exit 1 +fi + +printf 'CJK_GLYPH_ATLAS=%s\n' "$OUTPUT" +printf 'CJK_GLYPH_COUNT=%s\n' "$character_count" +printf 'CJK_GLYPH_DIMENSIONS=%s\n' "$actual_dimensions" diff --git a/scripts/m6c-package.sh b/scripts/m6c-package.sh index d887ea6..89ae6a4 100755 --- a/scripts/m6c-package.sh +++ b/scripts/m6c-package.sh @@ -46,6 +46,25 @@ else fi fi +for asset in Assets/cjk-glyph-atlas.png Assets/cjk-glyphs.txt; do + if [[ ! -s "$APP_DIR/$asset" ]]; then + printf 'Required CJK asset is missing from the Linux package: %s\n' "$APP_DIR/$asset" >&2 + exit 1 + fi +done + +mapfile -t cjk_manifest_lines < "$APP_DIR/Assets/cjk-glyphs.txt" +if [[ "${#cjk_manifest_lines[@]}" -ne 188 ]]; then + printf 'Packaged CJK manifest contains %s lines; expected 188: %s\n' "${#cjk_manifest_lines[@]}" "$APP_DIR/Assets/cjk-glyphs.txt" >&2 + exit 1 +fi +for cjk_manifest_line in "${cjk_manifest_lines[@]}"; do + if [[ ${#cjk_manifest_line} -ne 1 ]]; then + printf 'Packaged CJK manifest contains a line that is not one character: %s\n' "$APP_DIR/Assets/cjk-glyphs.txt" >&2 + exit 1 + fi +done + cp "$SCRIPT_DIR/m6c-run.sh" "$PACKAGE_ROOT/run-living-village.sh" chmod +x "$PACKAGE_ROOT/run-living-village.sh" cp "$REPO_ROOT/README.md" "$PACKAGE_ROOT/README.md" diff --git a/scripts/macos-package.sh b/scripts/macos-package.sh index 10c80b8..3255898 100755 --- a/scripts/macos-package.sh +++ b/scripts/macos-package.sh @@ -270,6 +270,24 @@ for rid in osx-arm64 osx-x64; do cp "$REPO_ROOT/docs/assets-and-licenses.md" "$app_dir/Contents/Resources/ASSETS-AND-LICENSES.md" chmod +x "$app_dir/Contents/MacOS/LivingVillage" "$app_dir/Contents/MacOS/LivingVillage.Desktop" + for asset in cjk-glyph-atlas.png cjk-glyphs.txt; do + if [[ ! -s "$app_dir/Contents/MacOS/Assets/$asset" ]]; then + printf 'BLOCKED: required CJK asset is missing for %s: %s\n' "$rid" "$app_dir/Contents/MacOS/Assets/$asset" >&2 + exit 1 + fi + done + mapfile -t cjk_manifest_lines < "$app_dir/Contents/MacOS/Assets/cjk-glyphs.txt" + if [[ "${#cjk_manifest_lines[@]}" -ne 188 ]]; then + printf 'BLOCKED: packaged CJK manifest for %s contains %s lines; expected 188\n' "$rid" "${#cjk_manifest_lines[@]}" >&2 + exit 1 + fi + for cjk_manifest_line in "${cjk_manifest_lines[@]}"; do + if [[ ${#cjk_manifest_line} -ne 1 ]]; then + printf 'BLOCKED: packaged CJK manifest for %s contains a line that is not one character\n' "$rid" >&2 + exit 1 + fi + done + if ! file -b "$app_dir/Contents/MacOS/LivingVillage.Desktop" >> "$mach_o_report"; then printf 'BLOCKED: failed to inspect bundled apphost for %s\n' "$rid" >&2 exit 1 |
