init.luau unwrap: a single-stream archive whose entry is a .pcf / .psf / .bdf loads as that font (category font).
31 lines
1.0 KiB
Luau
31 lines
1.0 KiB
Luau
-- tools/fixtures/_bitmapfonts_ours.luau: our bitmap font writers' output for FreeType to read back (run by
|
|
-- tools/fixtures/bitmapfonts.py after it wrote tests/gen/bitmapfonts_src.luau): decodes each source font with its
|
|
-- format and prints "<case> <hex of our BDF>" lines.
|
|
local F = require("@formats")
|
|
local Bytes = require("@formats/core/Bytes")
|
|
local Deflate = require("@formats/codecs/compress/Deflate")
|
|
local Src = require("@tests/gen/bitmapfonts_src")
|
|
|
|
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 F.format("bdf") then
|
|
local out = (F.format("bdf") :: any).encode(font)
|
|
if out then
|
|
print(c.name .. " " .. hex(out))
|
|
end
|
|
end
|
|
end
|