From 8e2a2a158d1c7e20141694a08b9dba0d2b4d1367 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Thu, 21 Dec 2017 21:47:16 +0100 Subject: [PATCH] Bug fix on UTF-8 computation. --- font_lib/font_default.lua | 4 ++-- font_lib/init.lua | 18 +++++++++++++----- font_lib/textures/font_default_00c0.png | Bin 0 -> 160 bytes font_lib/tools/make_font_lua.sh | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 font_lib/textures/font_default_00c0.png diff --git a/font_lib/font_default.lua b/font_lib/font_default.lua index fef847a..2bd8093 100644 --- a/font_lib/font_default.lua +++ b/font_lib/font_default.lua @@ -1,12 +1,12 @@ --[[ - generated by ./make_font_mod.sh Sun Dec 17 21:23:59 CET 2017 + generated by tools/make_font_lua.sh Thu Dec 21 21:45:53 CET 2017 --]] font_lib.register_font( 'default', 12, - { [0]=6, [32]=4, [33]=3, [34]=4, [35]=7, [36]=6, [37]=8, [38]=8, [39]=3, [40]=4, [41]=4, [42]=4, [43]=7, [44]=3, [45]=5, [46]=3, [47]=5, [48]=6, [49]=4, [50]=6, [51]=6, [52]=7, [53]=6, [54]=6, [55]=6, [56]=6, [57]=6, [58]=3, [59]=3, [60]=5, [61]=6, [62]=5, [63]=6, [64]=11, [65]=8, [66]=7, [67]=8, [68]=7, [69]=6, [70]=6, [71]=8, [72]=7, [73]=3, [74]=6, [75]=8, [76]=6, [77]=10, [78]=8, [79]=8, [80]=7, [81]=8, [82]=7, [83]=7, [84]=7, [85]=7, [86]=8, [87]=11, [88]=8, [89]=9, [90]=7, [91]=4, [92]=5, [93]=4, [94]=5, [95]=7, [96]=3, [97]=7, [98]=6, [99]=5, [100]=6, [101]=6, [102]=5, [103]=6, [104]=6, [105]=3, [106]=3, [107]=7, [108]=3, [109]=9, [110]=6, [111]=6, [112]=6, [113]=6, [114]=5, [115]=6, [116]=4, [117]=6, [118]=6, [119]=8, [120]=7, [121]=6, [122]=6, [123]=5, [124]=3, [125]=5, [126]=6, [138]=6, [141]=3, [161]=3, [177]=6, [191]=6, [193]=8, [194]=8, [195]=8, [196]=8, [197]=8, [198]=10, [199]=8, [200]=6, [201]=6, [202]=6, [203]=6, [204]=3, [205]=3, [206]=3, [207]=3, [208]=8, [209]=8, [210]=8, [211]=8, [212]=8, [213]=8, [214]=8, [215]=6, [216]=8, [217]=7, [218]=7, [219]=7, [220]=7, [221]=9, [224]=7, [225]=7, [226]=7, [227]=7, [228]=7, [229]=7, [230]=9, [231]=5, [232]=6, [233]=6, [234]=6, [235]=6, [236]=3, [237]=3, [238]=3, [239]=3, [242]=6, [244]=6, [245]=6, [246]=6, [247]=6, [249]=6, [250]=6, [251]=6, [252]=6, [253]=6, [255]=6 } + { [0]=6, [32]=4, [33]=3, [34]=4, [35]=7, [36]=6, [37]=8, [38]=8, [39]=3, [40]=4, [41]=4, [42]=4, [43]=7, [44]=3, [45]=5, [46]=3, [47]=5, [48]=6, [49]=4, [50]=6, [51]=6, [52]=7, [53]=6, [54]=6, [55]=6, [56]=6, [57]=6, [58]=3, [59]=3, [60]=5, [61]=6, [62]=5, [63]=6, [64]=11, [65]=8, [66]=7, [67]=8, [68]=7, [69]=6, [70]=6, [71]=8, [72]=7, [73]=3, [74]=6, [75]=8, [76]=6, [77]=10, [78]=8, [79]=8, [80]=7, [81]=8, [82]=7, [83]=7, [84]=7, [85]=7, [86]=8, [87]=11, [88]=8, [89]=9, [90]=7, [91]=4, [92]=5, [93]=4, [94]=5, [95]=7, [96]=3, [97]=7, [98]=6, [99]=5, [100]=6, [101]=6, [102]=5, [103]=6, [104]=6, [105]=3, [106]=3, [107]=7, [108]=3, [109]=9, [110]=6, [111]=6, [112]=6, [113]=6, [114]=5, [115]=6, [116]=4, [117]=6, [118]=6, [119]=8, [120]=7, [121]=6, [122]=6, [123]=5, [124]=3, [125]=5, [126]=6, [138]=6, [141]=3, [161]=3, [177]=6, [191]=6, [192]=8, [193]=8, [194]=8, [195]=8, [196]=8, [197]=8, [198]=10, [199]=8, [200]=6, [201]=6, [202]=6, [203]=6, [204]=3, [205]=3, [206]=3, [207]=3, [208]=8, [209]=8, [210]=8, [211]=8, [212]=8, [213]=8, [214]=8, [215]=6, [216]=8, [217]=7, [218]=7, [219]=7, [220]=7, [221]=9, [224]=7, [225]=7, [226]=7, [227]=7, [228]=7, [229]=7, [230]=9, [231]=5, [232]=6, [233]=6, [234]=6, [235]=6, [236]=3, [237]=3, [238]=3, [239]=3, [242]=6, [244]=6, [245]=6, [246]=6, [247]=6, [249]=6, [250]=6, [251]=6, [252]=6, [253]=6, [255]=6 } ); 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 diff --git a/font_lib/textures/font_default_00c0.png b/font_lib/textures/font_default_00c0.png new file mode 100644 index 0000000000000000000000000000000000000000..4652acfd0f0f655be4f231cb92a32088a045c013 GIT binary patch literal 160 zcmeAS@N?(olHy`uVBq!ia0vp^96-#&!2%?|PB#$)QcOwS?k)`f+xyS#2l6-zJR*x3 z7`TN&n2}-D90{Nxdx@v7EBiwpQ4uBH!t0V!Kp{g<7sn8e>r;CT`4|)g4sm__AAjwr zahF~h^DG92x!s|e-Ao0m=IuUJEydpDz4edLeV(<+?0k=2&gBDYX7F_Nb6Mw<&;$TI C|0~u2 literal 0 HcmV?d00001 diff --git a/font_lib/tools/make_font_lua.sh b/font_lib/tools/make_font_lua.sh index b751612..4559341 100755 --- a/font_lib/tools/make_font_lua.sh +++ b/font_lib/tools/make_font_lua.sh @@ -35,7 +35,7 @@ done echo "--[[ -$luafile generated by $scriptname $(date) +$luafile generated by $scriptname $(LANG=en_US date) --]]