Add Proper Unicode Glyph Ranges for Each Language

This commit is contained in:
GreenComfyTea
2023-05-25 12:18:34 +03:00
parent 865512f8d6
commit cd2aa12d3c
9 changed files with 148 additions and 15 deletions

View File

@@ -36,11 +36,47 @@ local package = package;
this.language_folder = "MHR Overlay\\languages\\";
--[[
EXAMPLE:
unicode_glyph_ranges = {
0x0020, 0x00FF, -- Basic Latin + Latin Supplement
0x2000, 0x206F, -- General Punctuation
0x3000, 0x30FF, -- CJK Symbols and Punctuations, Hiragana, Katakana
0x31F0, 0x31FF, -- Katakana Phonetic Extensions
0x4e00, 0x9FAF, -- CJK Ideograms
0xFF00, 0xFFEF, -- Half-width characters
0
},
]]
--[[
EXAMPLE:
unicode_glyph_ranges = {
0x0020, 0x00FF, -- Basic Latin + Latin Supplement
0x0400, 0x052F, -- Cyrillic
0x2000, 0x206F, -- General Punctuation
0xFF00, 0xFFEF, -- Half-width characters
0
},
]]
--[[
EXAMPLE:
unicode_glyph_ranges = {
0x0020, 0x00FF, -- Basic Latin + Latin Supplement
0x1100, 0x11FF, -- Hangul Jamo
0x2000, 0x206F, -- General Punctuation
0x3130, 0x318F, -- Hangul Compatibility Jamo
0xAC00, 0xD7AF, -- Hangul Syllables
0xFF00, 0xFFEF, -- Half-width characters
0
},
]]
this.current_language = {};
this.default_language = {
font_name = "NotoSansKR-Bold.otf",
font_name = "",
unicode_glyph_ranges = {0},
parts = {
head = "Head",
neck = "Neck",

View File

@@ -215,6 +215,14 @@ function this.number.round(value)
return math.floor(value + 0.5);
end
function this.number.is_odd(value)
return value % 2 ~= 0;
end
function this.number.is_even(value)
return value % 2 == 0;
end
function this.string.trim(str)
return str:match("^%s*(.-)%s*$");
end

View File

@@ -62,7 +62,7 @@ local ValueType = ValueType;
local package = package;
this.font = nil;
this.font_range = {0x1, 0xFFFF, 0};
this.full_font_range = {0x1, 0xFFFF, 0};
this.is_opened = false;
this.status = "OK";
@@ -146,8 +146,22 @@ this.menu_font_changed = false;
this.config_name_input = "";
function this.reload_font(pop_push)
this.font = imgui.load_font(language.current_language.font_name,
config.current_config.global_settings.menu_font.size, this.font_range);
local cached_language = language.current_language;
local font_range = cached_language.unicode_glyph_ranges;
if cached_language.font_name == "" then
font_range = nil;
elseif cached_language.unicode_glyph_ranges == nil
or utils.table.is_empty(cached_language.unicode_glyph_ranges)
or #cached_language.unicode_glyph_ranges == 1
or not utils.number.is_odd(#cached_language.unicode_glyph_ranges) then
font_range = this.full_font_range;
end
this.font = imgui.load_font(cached_language.font_name, config.current_config.global_settings.menu_font.size, font_range);
if pop_push then
imgui.pop_font();
@@ -321,17 +335,18 @@ function this.draw()
imgui.set_next_window_pos(this.window_position, 1 << 3, this.window_pivot);
imgui.set_next_window_size(this.window_size, 1 << 3);
imgui.push_font(this.font);
this.is_opened = imgui.begin_window(
language.current_language.customization_menu.mod_name .. " v" .. config.current_config.version, this.is_opened,
this.window_flags);
if not this.is_opened then
imgui.pop_font();
imgui.end_window();
return;
end
imgui.push_font(this.font);
local config_changed = false;
local language_changed = false;
local modifiers_changed = false;