diff --git a/.gitignore b/.gitignore index 2c431da..a6b8e21 100755 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ tmp_* */__pycache__ OTFbuild/*.ttf OTFbuild/*.otf +OTFbuild/*.woff +OTFbuild/*.woff2 +*.fea diff --git a/OTFbuild/CLAUDE.md b/OTFbuild/CLAUDE.md index 6bcbb88..2a016b4 100644 --- a/OTFbuild/CLAUDE.md +++ b/OTFbuild/CLAUDE.md @@ -1,18 +1,14 @@ # OTFbuild -Python toolchain that builds an OpenType (CFF) font from the TGA sprite sheets used by the bitmap font engine. +Python toolchain that builds an OpenType (CFF) and Web Open Font (WOFF2) font from the TGA sprite sheets used by the bitmap font engine. ## Building ```bash -pip install fonttools -python3 OTFbuild/build_font.py src/assets -o OTFbuild/TerrarumSansBitmap.otf +# builds both OTF and WOFF2 +make all ``` -Options: -- `--no-bitmap` — skip EBDT/EBLC bitmap strike (faster builds for iteration) -- `--no-features` — skip GSUB/GPOS OpenType features - ## Debugging with HarfBuzz Install `uharfbuzz` for shaping tests: @@ -118,6 +114,7 @@ print(f"{name}: advance={w}, has_outlines={has_outlines}") | `opentype_features.py` | Generates GSUB/GPOS feature code for feaLib | | `keming_machine.py` | Generates kerning pairs from glyph kern masks | | `hangul.py` | Hangul syllable composition and jamo GSUB data | +| `otf2woff2.py` | OTF to WOFF2 wrapper | ### OpenType features generated (`opentype_features.py`) diff --git a/OTFbuild/Makefile b/OTFbuild/Makefile new file mode 100644 index 0000000..98d0411 --- /dev/null +++ b/OTFbuild/Makefile @@ -0,0 +1,19 @@ +PYTHON ?= python3 +ASSETS ?= ../src/assets +OTF = TerrarumSansBitmap.otf +WOFF2 = TerrarumSansBitmap.woff2 + +all: $(OTF) $(WOFF2) + +$(OTF): $(wildcard $(ASSETS)/*.tga) build_font.py font_builder.py glyph_parser.py \ + bitmap_tracer.py tga_reader.py keming_machine.py hangul.py sheet_config.py \ + opentype_features.py + $(PYTHON) build_font.py $(ASSETS) -o $@ + +$(WOFF2): $(OTF) otf2woff2.py + $(PYTHON) otf2woff2.py $< $@ + +clean: + rm -f $(OTF) $(WOFF2) + +.PHONY: all clean diff --git a/OTFbuild/calligra_font_tests.odt b/OTFbuild/calligra_font_tests.odt index a834aef..c280fb5 100644 Binary files a/OTFbuild/calligra_font_tests.odt and b/OTFbuild/calligra_font_tests.odt differ diff --git a/OTFbuild/otf2woff2.py b/OTFbuild/otf2woff2.py new file mode 100755 index 0000000..2cc9323 --- /dev/null +++ b/OTFbuild/otf2woff2.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +"""Convert an OTF/TTF font to WOFF2 format.""" +import sys +from fontTools.ttLib import TTFont + +src, dst = sys.argv[1], sys.argv[2] +font = TTFont(src) +font.flavor = 'woff2' +font.save(dst) +print(f" Written {dst}") diff --git a/OTFbuild/requirements.txt b/OTFbuild/requirements.txt index f1ba9b0..9671785 100644 --- a/OTFbuild/requirements.txt +++ b/OTFbuild/requirements.txt @@ -1 +1,2 @@ fonttools>=4.47.0 +brotli>=1.1.0 diff --git a/demo.PNG b/demo.PNG index 5298cfa..1275a31 100644 Binary files a/demo.PNG and b/demo.PNG differ