mirror of
https://github.com/pyrollo/display_modpack.git
synced 2024-12-04 20:13:44 +01:00
Removed a debug trick and fixed indentation
This commit is contained in:
parent
80b616ab97
commit
076adbe8ab
41
font.lua
41
font.lua
@ -43,7 +43,7 @@ local function get_next_char(text, pos)
|
|||||||
-- 1 byte char, ascii equivalent codepoints
|
-- 1 byte char, ascii equivalent codepoints
|
||||||
if msb < 0x80 then
|
if msb < 0x80 then
|
||||||
return msb, pos + 1
|
return msb, pos + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 4 bytes char not managed (Only 16 bits codepoints are managed)
|
-- 4 bytes char not managed (Only 16 bits codepoints are managed)
|
||||||
if msb >= 0xF0 then
|
if msb >= 0xF0 then
|
||||||
@ -64,7 +64,7 @@ local function get_next_char(text, pos)
|
|||||||
pos + 2
|
pos + 2
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Not an UTF char
|
-- Not an UTF char
|
||||||
return 0, pos + 1
|
return 0, pos + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ function font_api.Font:get_width(line)
|
|||||||
|
|
||||||
local char
|
local char
|
||||||
local width = 0
|
local width = 0
|
||||||
local pos = 1
|
local pos = 1
|
||||||
|
|
||||||
-- TODO: Use iterator
|
-- TODO: Use iterator
|
||||||
while pos <= #line do
|
while pos <= #line do
|
||||||
@ -187,11 +187,10 @@ function font_api.Font:make_line_texture(line, texturew, x, y)
|
|||||||
|
|
||||||
-- Replace chars with no texture by the NULL(0) char
|
-- Replace chars with no texture by the NULL(0) char
|
||||||
if self.widths[char] == nil
|
if self.widths[char] == nil
|
||||||
or char == 88
|
|
||||||
then
|
then
|
||||||
print(string.format("["..font_api.name
|
print(string.format("["..font_api.name
|
||||||
.."] Missing char %d (%04x)",char,char))
|
.."] Missing char %d (%04x)",char,char))
|
||||||
char = 0
|
char = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add image only if it is visible (at least partly)
|
-- Add image only if it is visible (at least partly)
|
||||||
@ -220,27 +219,27 @@ function font_api.Font:make_text_texture(text, texturew, textureh, maxlines,
|
|||||||
halign, valign, color)
|
halign, valign, color)
|
||||||
local texture = ""
|
local texture = ""
|
||||||
local lines = {}
|
local lines = {}
|
||||||
local textheight = 0
|
local textheight = 0
|
||||||
local y
|
local y
|
||||||
|
|
||||||
-- Split text into lines (limited to maxlines fist lines)
|
-- Split text into lines (limited to maxlines fist lines)
|
||||||
for num, line in pairs(split_lines(text, maxlines)) do
|
for num, line in pairs(split_lines(text, maxlines)) do
|
||||||
lines[num] = { text = line, width = self:get_width(line) }
|
lines[num] = { text = line, width = self:get_width(line) }
|
||||||
end
|
end
|
||||||
|
|
||||||
textheight = self:get_height(#lines)
|
textheight = self:get_height(#lines)
|
||||||
|
|
||||||
if #lines then
|
if #lines then
|
||||||
if valign == "top" then
|
if valign == "top" then
|
||||||
y = 0
|
y = 0
|
||||||
elseif valign == "bottom" then
|
elseif valign == "bottom" then
|
||||||
y = textureh - textheight
|
y = textureh - textheight
|
||||||
else
|
else
|
||||||
y = (textureh - textheight) / 2
|
y = (textureh - textheight) / 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
y = y + (self.margintop or 0)
|
y = y + (self.margintop or 0)
|
||||||
|
|
||||||
for _, line in pairs(lines) do
|
for _, line in pairs(lines) do
|
||||||
if halign == "left" then
|
if halign == "left" then
|
||||||
|
Loading…
Reference in New Issue
Block a user