1
0
mirror of https://github.com/pyrollo/display_modpack.git synced 2024-11-16 07:10:30 +01:00
display_modpack/unifont/init.lua

54 lines
1.4 KiB
Lua
Raw Normal View History

2021-12-04 09:43:52 +01:00
--[[
Unifont for Font API
Copyright 2021 SyiMyuZya
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
--]]
2021-12-04 06:14:47 +01:00
local widths = {}
for i = 0,0xd7ff do
widths[i] = 16
end
for i = 0xe000,0xfffd do
2021-12-04 06:14:47 +01:00
widths[i] = 16
end
local halfwidth = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/halfwidth.lua")
for i, codepoint in ipairs(halfwidth) do
widths[codepoint] = 8
2021-12-04 06:14:47 +01:00
end
local function get_glyph(codepoint)
if codepoint == 0 or codepoint > 0xffff or widths[codepoint] == nil then
2021-12-04 06:14:47 +01:00
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,
marginbottom = 2,
linespacing = -3,
2021-12-04 06:14:47 +01:00
height = 16,
widths = widths,
getglyph = get_glyph,
2021-12-04 06:14:47 +01:00
}
)