aboutsummaryrefslogtreecommitdiff
path: root/font_lib/init.lua
diff options
context:
space:
mode:
authorPierre-Yves Rollo <dev@pyrollo.com>2017-12-21 21:47:16 +0100
committerPierre-Yves Rollo <dev@pyrollo.com>2017-12-21 21:47:16 +0100
commit8e2a2a158d1c7e20141694a08b9dba0d2b4d1367 (patch)
tree0a4696a5e13bf948167562f78bd57b668e6e33b7 /font_lib/init.lua
parent46d2ce085ea47f7f9b86ec74858c6cc1317b04a6 (diff)
downloaddisplay_modpack-8e2a2a158d1c7e20141694a08b9dba0d2b4d1367.tar.gz
display_modpack-8e2a2a158d1c7e20141694a08b9dba0d2b4d1367.tar.bz2
display_modpack-8e2a2a158d1c7e20141694a08b9dba0d2b4d1367.zip
Bug fix on UTF-8 computation.
Diffstat (limited to 'font_lib/init.lua')
-rw-r--r--font_lib/init.lua18
1 files changed, 13 insertions, 5 deletions
diff --git a/font_lib/init.lua b/font_lib/init.lua
index c1cee07..9b10e76 100644
--- a/font_lib/init.lua
+++ b/font_lib/init.lua
@@ -47,6 +47,11 @@ local function get_next_char(text, pos)
pos = pos + 1
local char = text:sub(pos, pos):byte()
+ -- 1 byte char
+ if char < 0x80 then
+ return char, pos
+ end
+
-- 4 bytes char not managed
if char >= 0xF0 then
pos = pos + 3
@@ -60,13 +65,14 @@ local function get_next_char(text, pos)
end
-- 2 bytes char (little endian)
- if char >= 0x80 then
+ if char >= 0xC2 then
pos = pos + 1
- return char * 0x100 + text:sub(pos, pos):byte(), pos
+ return (char - 0xC2) * 0x40 + text:sub(pos, pos):byte(), pos
end
-
- -- 1 byte char
- return char, pos
+
+ -- Not an UTF char
+ return 0, pos
+
end
-- Returns font properties to be used according to font_name
@@ -151,6 +157,8 @@ function font_lib.make_line_texture(font_name, text, width, x, y)
x, y, font.name, char)
end
x = x + font.widths[char]
+ else
+ print(string.format("Missing char %d (%04x)",char,char))
end
end
end