diff --git a/tests/font/_bitmap.luau b/tests/font/_bitmap.luau index aa7d3e5..02f16fe 100644 --- a/tests/font/_bitmap.luau +++ b/tests/font/_bitmap.luau @@ -1,6 +1,4 @@ --- 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)) (by the font's own --- codes when FreeType had no Unicode charmap). +-- shared by the bitmap font tests: every glyph FreeType rendered against font:rasterize. local B = {} function B.compare(t: any, font: any, ref: any, label: string) diff --git a/tests/font/bdf.luau b/tests/font/bdf.luau index 792bd59..fd738c8 100644 --- a/tests/font/bdf.luau +++ b/tests/font/bdf.luau @@ -1,6 +1,4 @@ --- font/bdf tests: Spleen BDF fonts against FreeType's renders (bitmaps, offsets, advances), properties and metrics; our --- BDF output (of BDF, PCF and outline fonts) read back by FreeType identically (fixture step) and round-tripping; an --- outline font written as BDF; errors; the fuzz pass. Fixtures: tools/fixtures/bitmapfonts.py, tools/fixtures/fonts.py. +-- font/bdf tests: Spleen BDF fonts against FreeType's renders (tools/fixtures/bitmapfonts.py, tools/fixtures/fonts.py). local T = require("@tests/T") local F = require("@rosetta") local Bdf = require("@rosetta/font/bdf") @@ -25,7 +23,6 @@ for _, c in Fx.fonts do t:eq(font.ascent, c.ref.ascent, c.name .. ": ascent") t:eq(-font.descent, c.ref.descent, c.name .. ": descent") t:eq(font.info.family, "Spleen", c.name .. ": family") - -- round trip through our writer local out = Bdf.encode(font) :: buffer local back = Bdf.decode(Bytes.reader(out)) :: any t:check(back and #back.bitmap.glyphs == #font.bitmap.glyphs, c.name .. ": round trip glyph count") @@ -38,14 +35,12 @@ for _, c in Fx.fonts do end end --- an outline font as BDF local ttf = Ttf.decode(Bytes.reader(buffer.fromstring(Fonts.fonts[1].data))) local out, err = Bdf.encode(ttf, { px = 14, chars = "Hello" }) t:check(out, "ttf -> bdf: " .. tostring(err)) local back = Bdf.decode(Bytes.reader(out :: buffer)) :: any t:check(back and back:glyphIndex(72) > 0 and back.unitsPerEm == 14 and back:rasterize(back:glyphIndex(72), 14).width > 3, "ttf -> bdf glyphs") --- errors local function code(s: string): string? local _, e = Bdf.decode(Bytes.reader(buffer.fromstring(s))) return e and e.code diff --git a/tests/font/bmfont.luau b/tests/font/bmfont.luau index 848b0da..1a3e095 100644 --- a/tests/font/bmfont.luau +++ b/tests/font/bmfont.luau @@ -1,8 +1,4 @@ --- font/bmfont tests: the text, XML and binary descriptors (an independent Python writer, glyphs rendered by FreeType) --- decode to the reference description; each variant re-encodes to every variant and decodes back unchanged (binary: --- byte-identical to the Python writer); Font methods (glyphIndex / advance / kern); lazy pages through opts.loadPage --- and the page PNG (glyph crops against FreeType's bitmaps); bake() from a TrueType font; errors; the fuzz pass. --- Fixtures: tools/fixtures/bmfont.py. +-- font/bmfont tests against an independent Python writer and FreeType's bitmaps (tools/fixtures/bmfont.py). local T = require("@tests/T") local F = require("@rosetta") local Bmfont = require("@rosetta/font/bmfont") @@ -47,7 +43,6 @@ local function sameDesc(got: any, want: any, label: string, faceQuotes: boolean) end end --- 1. the three encodings local fonts = {} for _, v in { "text", "xml", "binary" } do local f, err = Bmfont.decode(Bytes.reader(buffer.fromstring(Fx[v]))) @@ -58,7 +53,6 @@ for _, v in { "text", "xml", "binary" } do t:eq(F.detect(Fx[v]), "bmfont", v .. ": F.detect") end --- 2. re-encode every variant to every variant for from, f in fonts do for _, to in { "text", "xml", "binary" } do local b, err = Bmfont.encode(f, { variant = to :: any }) @@ -73,7 +67,6 @@ for from, f in fonts do end t:eq(buffer.tostring(F.save(fonts.xml, nil, { format = "fnt" })):sub(1, 5), " glyph --- pair); our PSF 2 / PSF 1 output read back by psfgettable and the parser (fixture step) and round-tripping; an --- outline font written as PSF; .psfu.gz through the api; errors; the fuzz pass. Fixtures: tools/fixtures/psf.py. +-- font/psf tests against an independent parser and kbd's psfgettable (tools/fixtures/psf.py). local T = require("@tests/T") local F = require("@rosetta") local Psf = require("@rosetta/font/psf") @@ -58,14 +55,12 @@ for _, c in Fx.fonts do end end --- an outline font as PSF 2 local ttf = Ttf.decode(Bytes.reader(buffer.fromstring(Fonts.fonts[1].data))) local out, err = Psf.encode(ttf, { px = 16, chars = "AB" }) t:check(out, "ttf -> psf: " .. tostring(err)) local back = Psf.decode(Bytes.reader(out :: buffer)) :: any t:check(back and back:glyphIndex(66) == 2 and back.meta.source.version == 2, "ttf -> psf glyphs") --- errors local function code(s: string): string? local _, e = Psf.decode(Bytes.reader(buffer.fromstring(s))) return e and e.code diff --git a/tests/font/ttf.luau b/tests/font/ttf.luau index 2469f8b..a7a44c6 100644 --- a/tests/font/ttf.luau +++ b/tests/font/ttf.luau @@ -1,7 +1,4 @@ --- font/ttf tests (and codecs/font/TrueType, codecs/font/Cff): for the imgui-luau TrueType fonts, Source Sans 3 (CFF), a --- 'kern'-table font and a collection: metrics, names, cmap samples, advances / side bearings, outline control boxes and --- areas against fontTools; kerning against HarfBuzz (GPOS) and FreeType ('kern'); rasterize() against FreeType's --- unhinted renders (PSNR); the api; errors; the fuzz pass. Fixtures: tools/fixtures/fonts.py. +-- font/ttf tests (and codecs/font/TrueType, Cff) against fontTools, HarfBuzz and FreeType (tools/fixtures/fonts.py). local T = require("@tests/T") local F = require("@rosetta") local Ttf = require("@rosetta/font/ttf") @@ -31,7 +28,6 @@ local function area(cmds: any): number end local function psnr(img: any, r: any): (number, number) - -- union of both bitmaps, aligned on the pen position local ax0, ay0 = img.meta.left, -img.meta.top local bx0, by0 = r.left, -r.top local x0, y0 = math.min(ax0, bx0), math.min(ay0, by0) @@ -137,7 +133,6 @@ do t:check(nz > 20, "fixtures have non-zero kerning pairs: " .. nz) end --- collections if Fx.ttc then local b = buffer.fromstring(Fx.ttc.data) t:eq(Ttf.count(Bytes.reader(b)), Fx.ttc.count, "collection count") @@ -149,7 +144,6 @@ if Fx.ttc then t:check(f1 and f1.info.family == fonts["collection-1"].info.family, "F.load with opts.index") end --- the api: detection by content, the font facade do local c = Fx.fonts[1] t:eq(F.detect(c.data), "ttf", "F.detect") @@ -166,7 +160,6 @@ do t:check(e and e.code == Err.UNSUPPORTED, "ttf is read-only") end --- errors do local _, e1 = Ttf.decode(Bytes.reader(buffer.fromstring("OTTO"))) t:check(e1 and e1.code == Err.TRUNCATED, "short file: " .. tostring(e1)) @@ -175,7 +168,6 @@ do t:eq(Ttf.sniff(Bytes.reader(buffer.fromstring("wOFF"))), 0, "sniff rejects woff") end --- fuzz: whole-font mutations, then glyph access on whatever still parses do local samples = {} for _, c in Fx.fonts do @@ -198,9 +190,8 @@ do end return f end, samples, { mutations = 30, garbage = 200 }) - -- mutations inside the glyph data only (the header survives, so the outline parsers see the damage) local hits = 0 - local cff = Fx.fonts[#Fx.fonts - 2] -- (any font: the loop below picks the CFF one) + local cff = Fx.fonts[#Fx.fonts - 2] for _, c in Fx.fonts do if c.cff then cff = c diff --git a/tests/font/type1.luau b/tests/font/type1.luau index 3d31c08..918b59f 100644 --- a/tests/font/type1.luau +++ b/tests/font/type1.luau @@ -1,7 +1,4 @@ --- font/type1 tests (and codecs/font/GlyphNames): Latin Modern PFB fonts and a PFA (t1ascii) against fontTools --- (outline control boxes, areas, advances of sample glyphs including flex, hint replacement, seac accents and --- ligatures; code points from glyph names) and FreeType's unhinted renders (PSNR); errors; the fuzz pass. --- Fixtures: tools/fixtures/type1.py. +-- font/type1 tests (and codecs/font/GlyphNames): Latin Modern against fontTools and FreeType (tools/fixtures/type1.py). local T = require("@tests/T") local F = require("@rosetta") local Type1 = require("@rosetta/font/type1") @@ -37,7 +34,6 @@ local function area(cmds: any): number end local function psnr(img: any, r: any): (number, number) - -- union of both bitmaps, aligned on the pen position local ax0, ay0 = img.meta.left, -img.meta.top local bx0, by0 = r.left, -r.top local x0, y0 = math.min(ax0, bx0), math.min(ay0, by0) @@ -65,7 +61,6 @@ local function psnr(img: any, r: any): (number, number) return 10 * math.log10(255 * 255 / (se / n)), ink end - local worst = 99 local samples = {} for _, c in Fx.fonts do diff --git a/tests/font/woff.luau b/tests/font/woff.luau index ac40d98..1c9232f 100644 --- a/tests/font/woff.luau +++ b/tests/font/woff.luau @@ -1,6 +1,4 @@ --- font/woff tests: every fixture font as WOFF 1.0 (fontTools, zlib tables) decodes to the same font as the sfnt itself (font/ttf, checked against --- fontTools / FreeType in tests/font/ttf.luau): metrics, names, every glyph's outline, advance and side bearing, --- cmap and kerning samples; rasterize works; the api detects it; errors; the fuzz pass. Fixtures: tools/fixtures/fonts.py. +-- font/woff tests: fontTools' WOFF 1.0 decodes to the same font as the sfnt (tools/fixtures/fonts.py). local T = require("@tests/T") local F = require("@rosetta") local Woff = require("@rosetta/font/woff") @@ -66,7 +64,6 @@ for _, w in Fx.woff do end t:check(n >= 6, "fixture count") --- the api do local data = Fx.woff[1].woff t:eq(F.detect(data), "woff", "F.detect") @@ -75,7 +72,6 @@ do t:eq(Woff.sniff(Bytes.reader(buffer.fromstring("wOFF"))) + Woff.sniff(Bytes.reader(buffer.fromstring("wOF2"))), 1, "sniff") end --- errors do local data = Fx.woff[1].woff local _, e1 = Woff.decode(Bytes.reader(buffer.fromstring(string.sub(data, 1, 30)))) diff --git a/tests/font/woff2.luau b/tests/font/woff2.luau index 762ffdc..66aa035 100644 --- a/tests/font/woff2.luau +++ b/tests/font/woff2.luau @@ -1,6 +1,5 @@ --- font/woff2 tests: every fixture font as WOFF2 (fontTools: the default glyf / loca transform, and with the hmtx transform too) decodes to the same font as the sfnt itself (font/ttf, checked against --- fontTools / FreeType in tests/font/ttf.luau): metrics, names, every glyph's outline, advance and side bearing, --- cmap and kerning samples; rasterize works; the api detects it; errors; the fuzz pass. Fixtures: tools/fixtures/fonts.py. +-- font/woff2 tests: fontTools' WOFF2 (glyf / loca and hmtx transforms) decodes to the same font as the sfnt. +-- Fixtures: tools/fixtures/fonts.py. local T = require("@tests/T") local F = require("@rosetta") local Woff2 = require("@rosetta/font/woff2") @@ -66,7 +65,6 @@ for _, w in Fx.woff do end t:check(n >= 6, "fixture count") --- the api do local data = Fx.woff[1].woff2 t:eq(F.detect(data), "woff2", "F.detect") @@ -75,7 +73,6 @@ do t:eq(Woff2.sniff(Bytes.reader(buffer.fromstring("wOFF"))) + Woff2.sniff(Bytes.reader(buffer.fromstring("wOF2"))), 1, "sniff") end --- errors do local data = Fx.woff[1].woff2 local _, e1 = Woff2.decode(Bytes.reader(buffer.fromstring(string.sub(data, 1, 30))))