tests/font: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:51:09 -05:00
1 parent 7672980c65
commit 9d80ee11b9
12 files changed
+15 -69

No files matched your search

+1 -3
View File
@@ -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)
+1 -6
View File
@@ -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
+2 -11
View File
@@ -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), "<?xml", "F.save keeps the variant")
-- 3. Font methods
do
local f = fonts.text
local gA, gV = f:glyphIndex(65), f:glyphIndex(86)
@@ -89,7 +82,7 @@ do
t:check(not ok and e and e.code == Err.ARG, "loadPages without a loader")
end
-- 4. lazy pages: the api attaches opts.loadPage; the PNG goes through F.load
-- lazy pages: the api attaches opts.loadPage; the PNG goes through F.load
do
local asked = {}
local f = F.load(Fx.binary, {
@@ -116,7 +109,6 @@ do
t:note("%d glyph crops from the lazily loaded page match FreeType", n)
end
-- 5. bake from a TrueType font
do
local ttf = F.font.load(Fx.ttf)
t:check(ttf, "ttf loads")
@@ -165,7 +157,6 @@ do
t:check(Bmfont.encode(ttf, { px = 16, chars = "Hi", files = {} }) ~= nil, "encode without encodeImage")
end
-- 6. errors and validation
do
local _, e1 = Bmfont.decode(Bytes.reader(buffer.fromstring("BMF\2")))
t:check(e1 and e1.code == Err.UNSUPPORTED, "binary version 2: " .. tostring(e1))
+1 -5
View File
@@ -1,7 +1,4 @@
-- font/eot tests: EOT 1.0 / 2.1 / 2.1 XOR / 2.2 files around DejaVu Sans Mono (TrueType) and Source Sans 3 (CFF) give
-- the header fields and the inner font (units per em, glyph count, cmap glyph ids and advances from fontTools); our
-- EOT writer round-trips (same font bytes, header from the font's tables), XOR too; MTX is unsupported; errors; the fuzz
-- pass. Fixtures: tools/fixtures/eot.py.
-- font/eot tests: DejaVu Sans Mono and Source Sans 3 against fontTools (tools/fixtures/eot.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Eot = require("@rosetta/font/eot")
@@ -32,7 +29,6 @@ for _, c in Fx.cases do
t:eq(font:glyphIndex(g.cp), g.gid, c.name .. ": cmap " .. g.cp)
t:eq(font:advance(g.gid), g.advance, c.name .. ": advance " .. g.cp)
end
-- our writer
for _, xor in { false, true } do
local out, werr = Eot.encode(font, { xor = xor })
t:check(out, c.name .. ": encode: " .. tostring(werr))
+1 -3
View File
@@ -1,6 +1,4 @@
-- font/fon tests: Windows .fnt and NE .fon fonts (one and two strikes) made by FontForge from the Spleen BDFs against
-- FreeType's renders (ASCII: FreeType maps FNT byte codes), strikes and size selection; errors; the fuzz pass.
-- Fixtures: tools/fixtures/bitmapfonts.py.
-- font/fon tests: FontForge's .fnt / .fon from the Spleen BDFs against FreeType (tools/fixtures/bitmapfonts.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Fon = require("@rosetta/font/fon")
+1 -3
View File
@@ -1,6 +1,4 @@
-- font/hershey tests: JHF text with Roman-style glyphs and random stroke glyphs (records wrapped over 72-column lines)
-- against an independent parser (ids, advances, every moveTo / lineTo), ASCII and id mappings, stroked rasterization;
-- errors; the fuzz pass. Fixtures: tools/fixtures/hershey.py.
-- font/hershey tests against an independent parser (tools/fixtures/hershey.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Hershey = require("@rosetta/font/hershey")
+1 -5
View File
@@ -1,7 +1,4 @@
-- font/pcf tests: PCF fonts compiled by bdftopcf with every glyph pad / scan unit / bit and byte order and -t, Tamzen
-- PCFs and X11 misc-misc .pcf.gz fonts against FreeType's renders (bitmaps, offsets, advances) and metrics; charsets
-- other than Unicode / Latin-1 stay unmapped; .pcf.gz through the api; errors; the fuzz pass.
-- Fixtures: tools/fixtures/bitmapfonts.py.
-- font/pcf tests: bdftopcf, Tamzen and X11 misc-misc fonts against FreeType's renders (tools/fixtures/bitmapfonts.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Pcf = require("@rosetta/font/pcf")
@@ -47,7 +44,6 @@ for _, c in Fx.fonts do
end
end
-- errors
local function code(s: string): string?
local _, e = Pcf.decode(Bytes.reader(buffer.fromstring(s)))
return e and e.code
+1 -6
View File
@@ -1,7 +1,4 @@
-- font/psf tests: kbd / Spleen / Tamzen / Terminus / Cozette console fonts (PSF 1 and 2, with and without Unicode
-- tables) against an independent parser (sizes, glyph bitmaps) and kbd's psfgettable (every code point -> 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
+2 -11
View File
@@ -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
+1 -6
View File
@@ -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
+1 -5
View File
@@ -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))))
+2 -5
View File
@@ -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))))