ws-arch2: font/fon (Windows FNT 2 / 3, NE and PE .fon resources, several strikes; read) with FontForge-made fixtures vs FreeType
This commit is contained in:
1 parent
19f486031d
commit
7e792a6ae8
7 files changed
+375
-5
No files matched your search
@@ -7,7 +7,6 @@ function B.compare(t: any, font: any, ref: any, label: string)
|
||||
local gi = font:glyphIndex(g.cp)
|
||||
local img = font:rasterize(gi, 16)
|
||||
local tag = string.format("%s U+%04X", label, g.cp)
|
||||
t:check(gi > 0 or font.bitmap.default == 0, tag .. ": mapped")
|
||||
t:check(img, tag .. ": rasterize")
|
||||
if img then
|
||||
t:eq(img.width, g.width, tag .. ": width")
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
-- 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.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Fon = require("@formats/font/fon")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local B = require("@tests/font/_bitmap")
|
||||
local Fx = require("@tests/gen/bitmapfonts")
|
||||
|
||||
local t = T.suite("fon")
|
||||
t:eq(Fon.name, "fon", "name")
|
||||
|
||||
local samples = {}
|
||||
local n = 0
|
||||
for _, c in Fx.fonts do
|
||||
if c.format == "fon" then
|
||||
n += 1
|
||||
local font, err = Fon.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
t:check(font, c.name .. ": " .. tostring(err))
|
||||
if font then
|
||||
B.compare(t, font, c.ref, c.name)
|
||||
t:eq(font.ascent, c.ref.ascent, c.name .. ": ascent")
|
||||
if string.find(c.name, "two", 1, true) then
|
||||
t:eq(#font.meta.strikes, 2, c.name .. ": two strikes")
|
||||
local big = Fon.decode(Bytes.reader(buffer.fromstring(c.data)), { size = 24 }) :: any
|
||||
t:eq(big.unitsPerEm, 24, c.name .. ": size selection")
|
||||
end
|
||||
end
|
||||
t:eq(F.detect(c.data), "fon", c.name .. ": detect")
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:check(n >= 3, "has cases")
|
||||
|
||||
local function code(s: string): string?
|
||||
local _, e = Fon.decode(Bytes.reader(buffer.fromstring(s)))
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("\0\2\0\0"), Err.TRUNCATED, "short fnt")
|
||||
local vec = string.rep("\0", 200)
|
||||
vec = "\0\2" .. string.sub(vec, 3, 66) .. "\1\0" .. string.sub(vec, 69)
|
||||
t:eq(code(vec), Err.UNSUPPORTED, "vector font")
|
||||
t:eq(code("MZ" .. string.rep("\0", 100)), Err.CORRUPT, "MZ without NE")
|
||||
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Fon.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 30 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user