From 0a3f8b3f5d494cbe64d11fb1ff0af592f28bfeb8 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sat, 31 Oct 2026 15:10:09 -0500 Subject: [PATCH] ws-arch2: bitmap font tests compare non-Unicode fonts by their own codes; fon types --- src/Formats/font/fon/init.luau | 2 +- tests/font/_bitmap.luau | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Formats/font/fon/init.luau b/src/Formats/font/fon/init.luau index b4dbcf1..a952523 100644 --- a/src/Formats/font/fon/init.luau +++ b/src/Formats/font/fon/init.luau @@ -258,7 +258,7 @@ function Fon.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end list = { { 0, r:size() } } end - local fonts = {} + local fonts: { any } = {} local firstErr: Err.Err? = nil for _, res in list do if res[1] + 118 <= r:size() then diff --git a/tests/font/_bitmap.luau b/tests/font/_bitmap.luau index ea23133..aa7d3e5 100644 --- a/tests/font/_bitmap.luau +++ b/tests/font/_bitmap.luau @@ -1,10 +1,20 @@ -- shared by the bitmap font tests: compare(t, font, ref, label) checks every glyph FreeType rendered (code point, --- bitmap size, left / top offsets, advance, pixels) against font:rasterize(font:glyphIndex(cp)). +-- bitmap size, left / top offsets, advance, pixels) against font:rasterize(font:glyphIndex(cp)) (by the font's own +-- codes when FreeType had no Unicode charmap). local B = {} function B.compare(t: any, font: any, ref: any, label: string) for _, g in ref.glyphs do local gi = font:glyphIndex(g.cp) + if ref.unicode == false and font.meta.encodings then + -- FreeType used the font's own codes (not Unicode): find the glyph by its code + for k, enc in font.meta.encodings do + if enc == g.cp then + gi = k - 1 + break + end + end + end local img = font:rasterize(gi, 16) local tag = string.format("%s U+%04X", label, g.cp) t:check(img, tag .. ": rasterize")