Add GNU Unifont

This commit is contained in:
syimyuzya 2021-12-04 13:14:47 +08:00
parent f5bd6d1046
commit 79aac655b3
5 changed files with 39 additions and 2 deletions

View File

@ -229,7 +229,7 @@ function Font:render(text, texturew, textureh, style)
return ""
end
local x, y, codepoint
local x, y, codepoint, glyph
local texture = ""
local textheight = self:get_height(#lines)
@ -258,8 +258,13 @@ function Font:render(text, texturew, textureh, style)
-- Add image only if it is visible (at least partly)
if x + self.widths[codepoint] >= 0 and x <= texturew then
if self.get_glyph == nil then
glyph = string.format("font_%s_%04x.png", self.name, codepoint)
else
glyph = self.get_glyph(codepoint):gsub("[\\^:]", "\\%0")
end
texture = texture..
string.format(":%d,%d=font_%s_%04x.png", x, y, self.name, codepoint)
string.format(":%d,%d=%s", x, y, glyph)
end
x = x + self.widths[codepoint]
end

1
unifont/depends.txt Normal file
View File

@ -0,0 +1 @@
font_api

28
unifont/init.lua Normal file
View File

@ -0,0 +1,28 @@
local widths = {}
for i = 0,65535 do
widths[i] = 16
end
for i = 32,126 do
widths[i] = 8
end
local function get_glyph(codepoint)
if codepoint == 0 or codepoint > 0xffff then
codepoint = 0xfffd
end
local x = codepoint % 256
local y = math.floor(codepoint / 256)
return string.format("font_unifont_sheet.png^[sheet:256x256:%d,%d", x, y)
end
font_api.register_font(
"unifont",
{
default = true,
margintop = 2,
linespacing = -1,
height = 16,
widths = widths,
get_glyph = get_glyph,
}
)

3
unifont/mod.conf Normal file
View File

@ -0,0 +1,3 @@
name=unifont
description=GNU Unifont (full Unicode Plane 0 coverage) for font_api
depends=font_api

Binary file not shown.

After

Width:  |  Height:  |  Size: 955 KiB