WOFF builder

This commit is contained in:
minjaesong
2026-03-02 12:35:50 +09:00
parent cce9d62bd1
commit db327d8357
7 changed files with 37 additions and 7 deletions

3
.gitignore vendored
View File

@@ -17,3 +17,6 @@ tmp_*
*/__pycache__ */__pycache__
OTFbuild/*.ttf OTFbuild/*.ttf
OTFbuild/*.otf OTFbuild/*.otf
OTFbuild/*.woff
OTFbuild/*.woff2
*.fea

View File

@@ -1,18 +1,14 @@
# OTFbuild # 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 ## Building
```bash ```bash
pip install fonttools # builds both OTF and WOFF2
python3 OTFbuild/build_font.py src/assets -o OTFbuild/TerrarumSansBitmap.otf make all
``` ```
Options:
- `--no-bitmap` — skip EBDT/EBLC bitmap strike (faster builds for iteration)
- `--no-features` — skip GSUB/GPOS OpenType features
## Debugging with HarfBuzz ## Debugging with HarfBuzz
Install `uharfbuzz` for shaping tests: 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 | | `opentype_features.py` | Generates GSUB/GPOS feature code for feaLib |
| `keming_machine.py` | Generates kerning pairs from glyph kern masks | | `keming_machine.py` | Generates kerning pairs from glyph kern masks |
| `hangul.py` | Hangul syllable composition and jamo GSUB data | | `hangul.py` | Hangul syllable composition and jamo GSUB data |
| `otf2woff2.py` | OTF to WOFF2 wrapper |
### OpenType features generated (`opentype_features.py`) ### OpenType features generated (`opentype_features.py`)

19
OTFbuild/Makefile Normal file
View File

@@ -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

Binary file not shown.

10
OTFbuild/otf2woff2.py Executable file
View File

@@ -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}")

View File

@@ -1 +1,2 @@
fonttools>=4.47.0 fonttools>=4.47.0
brotli>=1.1.0

BIN
demo.PNG

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 KiB

After

Width:  |  Height:  |  Size: 167 KiB