From 673ca100d4c8b9235a2723ef4629a0b22b4935fb Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 2 Mar 2026 13:03:53 +0900 Subject: [PATCH] builder now has opentype sanitiser --- OTFbuild/build_font.py | 18 ++++++++++++++++++ OTFbuild/font_builder.py | 4 ++++ OTFbuild/requirements.txt | 1 + 3 files changed, 23 insertions(+) diff --git a/OTFbuild/build_font.py b/OTFbuild/build_font.py index f9156f2..462ec45 100644 --- a/OTFbuild/build_font.py +++ b/OTFbuild/build_font.py @@ -70,6 +70,24 @@ def main(): 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() diff --git a/OTFbuild/font_builder.py b/OTFbuild/font_builder.py index b1b358a..e9e15d4 100644 --- a/OTFbuild/font_builder.py +++ b/OTFbuild/font_builder.py @@ -53,6 +53,10 @@ def _should_have_cmap(cp): return True if 0x1B000 <= cp <= 0x1B16F: return True + # Unicode noncharacters — never map these (U+FFFE, U+FFFF are reserved; + # format 4 cmap uses 0xFFFF as a sentinel, so mapping it causes OTS rejection) + if cp >= 0xFFFE and cp <= 0xFFFF: + return False # Everything in standard Unicode ranges (up to 0xFFFF plus SMP) if cp <= 0xFFFF: return True diff --git a/OTFbuild/requirements.txt b/OTFbuild/requirements.txt index 9671785..6d02800 100644 --- a/OTFbuild/requirements.txt +++ b/OTFbuild/requirements.txt @@ -1,2 +1,3 @@ fonttools>=4.47.0 brotli>=1.1.0 +opentype-sanitizer>=9.2.0