mirror of
https://github.com/curioustorvald/Terrarum-sans-bitmap.git
synced 2026-03-07 20:01:52 +09:00
94 lines
2.7 KiB
Python
94 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Terrarum Sans Bitmap OTF Builder v2 — Python + fonttools
|
|
|
|
Builds a TTF font with both vector-traced outlines (TrueType glyf)
|
|
and embedded bitmap strike (EBDT/EBLC) from TGA sprite sheets.
|
|
|
|
Usage:
|
|
python3 OTFbuild/build_font.py src/assets -o OTFbuild/TerrarumSansBitmap.otf
|
|
|
|
Options:
|
|
--no-bitmap Skip EBDT/EBLC bitmap strike
|
|
--no-features Skip GSUB/GPOS OpenType features
|
|
"""
|
|
|
|
import argparse
|
|
import sys
|
|
import os
|
|
|
|
# Add OTFbuild dir to path for imports
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from font_builder import build_font
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Build Terrarum Sans Bitmap TTF from TGA sprite sheets"
|
|
)
|
|
parser.add_argument(
|
|
"assets_dir",
|
|
help="Path to assets directory containing TGA sprite sheets"
|
|
)
|
|
parser.add_argument(
|
|
"-o", "--output",
|
|
default="OTFbuild/TerrarumSansBitmap.otf",
|
|
help="Output OTF file path (default: OTFbuild/TerrarumSansBitmap.otf)"
|
|
)
|
|
parser.add_argument(
|
|
"--no-bitmap",
|
|
action="store_true",
|
|
help="Skip EBDT/EBLC bitmap strike"
|
|
)
|
|
parser.add_argument(
|
|
"--no-features",
|
|
action="store_true",
|
|
help="Skip GSUB/GPOS OpenType features"
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
if not os.path.isdir(args.assets_dir):
|
|
print(f"Error: assets directory not found: {args.assets_dir}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
# Ensure output directory exists
|
|
output_dir = os.path.dirname(args.output)
|
|
if output_dir:
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
print(f"Terrarum Sans Bitmap OTF Builder v2")
|
|
print(f" Assets: {args.assets_dir}")
|
|
print(f" Output: {args.output}")
|
|
print()
|
|
|
|
build_font(
|
|
assets_dir=args.assets_dir,
|
|
output_path=args.output,
|
|
no_bitmap=args.no_bitmap,
|
|
no_features=args.no_features,
|
|
)
|
|
|
|
# Run OpenType Sanitizer to catch issues browsers would reject
|
|
try:
|
|
import ots
|
|
print("\nRunning OpenType Sanitizer...")
|
|
result = ots.sanitize(args.output, capture_output=True)
|
|
if result.returncode == 0:
|
|
print(" OTS: passed")
|
|
else:
|
|
print(f" OTS: FAILED (exit code {result.returncode})", file=sys.stderr)
|
|
if result.stderr:
|
|
for line in result.stderr.decode().strip().splitlines():
|
|
print(f" {line}", file=sys.stderr)
|
|
sys.exit(1)
|
|
except ImportError:
|
|
print("\nWarning: opentype-sanitizer not installed, skipping OTS validation",
|
|
file=sys.stderr)
|
|
print(" Install with: pip install opentype-sanitizer", file=sys.stderr)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|