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

+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