35 lines
1.3 KiB
Luau
35 lines
1.3 KiB
Luau
-- tools/fixtures/_bitmapfonts_ours.luau: our bitmap font writers' output for the reference tools to read back (run by
|
|
-- tools/fixtures/bitmapfonts.py / psf.py after they wrote the source fonts to tests/gen/<src>.luau:
|
|
-- `luau _bitmapfonts_ours.luau -a <src> <format> [version]`): decodes each source font with its format, encodes it
|
|
-- with <format> (default bdf) and prints "<case> <hex>" lines.
|
|
local F = require("@rosetta")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Deflate = require("@rosetta/codecs/compress/Deflate")
|
|
|
|
local srcName, outFormat, version = ...
|
|
local Src = if srcName == "psf_src" then require("@tests/gen/psf_src") else require("@tests/gen/bitmapfonts_src")
|
|
local enc = F.format(outFormat or "bdf") :: any
|
|
|
|
local function hex(b: buffer): string
|
|
local t = table.create(buffer.len(b))
|
|
for i = 0, buffer.len(b) - 1 do
|
|
t[i + 1] = string.format("%02x", buffer.readu8(b, i))
|
|
end
|
|
return table.concat(t)
|
|
end
|
|
|
|
for _, c in Src.fonts do
|
|
local data = buffer.fromstring(c.data)
|
|
if c.gz then
|
|
data = Deflate.gunzip(data, 0, buffer.len(data)) :: buffer
|
|
end
|
|
local mod = F.format(c.format) :: any
|
|
local font = if mod then mod.decode(Bytes.reader(data)) else nil
|
|
if font and enc then
|
|
local out = enc.encode(font, { version = tonumber(version) })
|
|
if out then
|
|
print(c.name .. " " .. hex(out))
|
|
end
|
|
end
|
|
end
|