Files
rosetta/tests/font/_bitmap.luau
T

23 lines
835 B
Luau

-- 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)).
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)
local img = font:rasterize(gi, 16)
local tag = string.format("%s U+%04X", label, g.cp)
t:check(img, tag .. ": rasterize")
if img then
t:eq(img.width, g.width, tag .. ": width")
t:eq(img.height, g.height, tag .. ": height")
t:eq(img.meta.left, g.left, tag .. ": left")
t:eq(img.meta.top, g.top, tag .. ": top")
t:eq(img.meta.advance, g.advance, tag .. ": advance")
t:check(buffer.tostring(img.pixels) == g.pixels, tag .. ": pixels")
end
end
end
return B