ws-apifix: an outline font saved as BMFont writes its pages (opts.files; without a destination F.save returns them as a third value { [page file] = PNG bytes }; caps.extraFiles); pages named after the destination

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4DBugandClaude Opus 5.5 committed 2026-10-31 14:03:45 -05:00
1 parent 4557a3c792
commit 2abada340b
6 files changed
+83 -9

No files matched your search

+1 -1
View File
@@ -45,7 +45,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | usda | .usda .usd .usdz | yes | yes | materials: true, animation: true, cameras: true, lights: true, polygons: true, vertexColors: true, usdz: "read", usdc: false | `tests/model/usda.luau` |
| model | vox | .vox | yes | yes | voxels: true, sceneGraph: true, materials: true | `tests/model/vox.luau` |
| cad | step | .step .stp .p21 | yes | yes | complexEntities: true, sections: true, brep: "plugin", tessellate: "plugin" | `tests/cad/step.luau` |
| font | bmfont | .fnt | yes | yes | bitmap: true, variants: "text", "xml", "binary" | `tests/font/bmfont.luau` |
| font | bmfont | .fnt | yes | yes | bitmap: true, variants: "text", "xml", "binary", extraFiles: true | `tests/font/bmfont.luau` |
| font | ttf | .ttf .otf .ttc .otc | yes | - | outlines: "truetype", "cff", collection: true, kerning: true | `tests/font/ttf.luau` |
| font | woff | .woff | yes | - | outlines: "truetype", "cff" | `tests/font/woff.luau` |
| font | woff2 | .woff2 | yes | - | outlines: "truetype", "cff", transforms: "glyf", "loca", "hmtx" | `tests/font/woff2.luau` |
+12 -2
View File
@@ -219,8 +219,18 @@ local again = assert(F.font.load(bin, { pages = baked.pages }))
assert(again:advance(again:glyphIndex(string.byte("H"))) == baked:advance(baked:glyphIndex(string.byte("H"))))
```
`F.save(ttf, nil, { format = "bmfont", px = 16 })` bakes too, but returns only the descriptor: the page images are
not written anywhere. Use `bake` when you need the pages.
`F.save(ttf, dest, { format = "bmfont", px = 16, chars = ... })` bakes too, and writes the page PNGs next to the
`.fnt`, named after it (`ui.fnt` gets `ui_0.png`, ...; `file` sets another prefix). Without a destination it
returns the pages as a third value, `{ [page file name] = PNG buffer }` (the names the descriptor uses), or puts
them into your `opts.files` table when you pass one. A BMFont whose pages are loaded saves them the same way.
```luau
local ttf = assert(F.font.load(ttfBytes))
local fnt, _, pages = F.save(ttf, nil, { format = "bmfont", px = 16, chars = "Hi", file = "hud" })
assert(fnt and pages and F.detect(pages["hud_0.png"]) == "png")
local bm = assert(F.font.load(fnt, { loadPage = function(file) return pages[file] end }))
assert(bm:rasterize(bm:glyphIndex(string.byte("H"))))
```
## Formats