From 8e2a2a158d1c7e20141694a08b9dba0d2b4d1367 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Thu, 21 Dec 2017 21:47:16 +0100 Subject: Bug fix on UTF-8 computation. --- font_lib/init.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'font_lib/init.lua') 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 -- cgit v1.2.3