From 7c3b90eb9834ae605c679be2c240d36715225acc Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 16 Mar 2024 18:33:49 +0100 Subject: locale loading unix --- fonts/NotoSansJP.h | Bin 44466502 -> 22085023 bytes fonts/NotoSansSC.h | Bin 49120728 -> 24396622 bytes fonts/NotoSansThai.h | Bin 222380 -> 110442 bytes fonts/NotoSerifTC.h | Bin 35164738 -> 17465147 bytes src/fonts.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/fonts.h | 5 ++++- src/unix/main_unix.cpp | 20 +++++++++++++++++++- src/windows/main_windows.cpp | 37 +++---------------------------------- 8 files changed, 62 insertions(+), 36 deletions(-) diff --git a/fonts/NotoSansJP.h b/fonts/NotoSansJP.h index 54d11c3..52d9953 100644 Binary files a/fonts/NotoSansJP.h and b/fonts/NotoSansJP.h differ diff --git a/fonts/NotoSansSC.h b/fonts/NotoSansSC.h index 5ecb2ca..ab7fcd4 100644 Binary files a/fonts/NotoSansSC.h and b/fonts/NotoSansSC.h differ diff --git a/fonts/NotoSansThai.h b/fonts/NotoSansThai.h index e0531c4..27c5033 100644 Binary files a/fonts/NotoSansThai.h and b/fonts/NotoSansThai.h differ diff --git a/fonts/NotoSerifTC.h b/fonts/NotoSerifTC.h index 8d26847..d796634 100644 Binary files a/fonts/NotoSerifTC.h and b/fonts/NotoSerifTC.h differ diff --git a/src/fonts.cpp b/src/fonts.cpp index 3c1c520..34df8f4 100644 --- a/src/fonts.cpp +++ b/src/fonts.cpp @@ -9,6 +9,42 @@ #include +ts_font_range ts_locale_to_range(wchar_t* buffer) { + ts_font_range result = FONT_RANGE_ENGLISH; + if (wcscmp(buffer, L"el-GR") == 0) result = FONT_RANGE_GREEK; + if (wcscmp(buffer, L"ko-KR") == 0) result = FONT_RANGE_KOREAN; + if (wcscmp(buffer, L"ja-JP") == 0) result = FONT_RANGE_JAPANESE; + + if (wcscmp(buffer, L"be-BY") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"bg-BG") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"ru-RU") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"ru-MD") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"ro-MD") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"kk-KZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"tt-RU") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"ky-KG") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"mn-MN") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"az-Cyrl-AZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"uz-Cyrl-UZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"sr-Cyrl-CS") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"sr-Latn-CS") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"az-AZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"uz-UZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"sr-CS") == 0) result = FONT_RANGE_CYRILLIC; + + if (wcscmp(buffer, L"bo-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; + if (wcscmp(buffer, L"zh-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; + if (wcscmp(buffer, L"mn-Mong-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; + if (wcscmp(buffer, L"zh-HK") == 0) result = FONT_RANGE_CHINESE_FULL; + if (wcscmp(buffer, L"zh-TW") == 0) result = FONT_RANGE_CHINESE_FULL; + if (wcscmp(buffer, L"zh-SG") == 0) result = FONT_RANGE_CHINESE_SIMPLE; + if (wcscmp(buffer, L"zh-MO") == 0) result = FONT_RANGE_CHINESE_FULL; + + if (wcscmp(buffer, L"th-TH") == 0) result = FONT_RANGE_THAI; + if (wcscmp(buffer, L"vi-VN") == 0) result = FONT_RANGE_VIETNAMESE; + return result; +} + void ts_load_fonts(float size, ts_font_range locale) { ImGuiIO& io = ImGui::GetIO(); ImFontConfig config; diff --git a/src/fonts.h b/src/fonts.h index 4a3bb93..ef2a23d 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -1,5 +1,7 @@ #pragma once +#include + typedef enum t_ts_font_range { FONT_RANGE_ENGLISH, FONT_RANGE_GREEK, @@ -12,4 +14,5 @@ typedef enum t_ts_font_range { FONT_RANGE_VIETNAMESE, } ts_font_range; -void ts_load_fonts(float size, ts_font_range locale); \ No newline at end of file +void ts_load_fonts(float size, ts_font_range locale); +ts_font_range ts_locale_to_range(wchar_t* locale); \ No newline at end of file diff --git a/src/unix/main_unix.cpp b/src/unix/main_unix.cpp index 0c58d02..ef8dd88 100644 --- a/src/unix/main_unix.cpp +++ b/src/unix/main_unix.cpp @@ -8,6 +8,7 @@ #include "array.h" #include "memory_bucket.h" #include "image.h" +#include "fonts.h" #include "config.h" #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #define GL_SILENCE_DEPRECATION #if defined(IMGUI_IMPL_OPENGL_ES2) #include @@ -69,6 +71,22 @@ static void drop_callback(GLFWwindow* window, int count, const char** paths) } } +ts_font_range _ts_get_font_range_to_load() { + wchar_t buffer[50] = {0}; + char* ll = setlocale(LC_ALL, NULL); + mbstowcs (buffer, ll, 50); + + wchar_t* iter = buffer; + while (*iter) { + if (*iter == ' ') *iter = 0; + if (*iter == '.') *iter = 0; + if (*iter == '@') *iter = 0; + iter++; + } + + return ts_locale_to_range(buffer); +} + // Main code int main(int, char**) { @@ -126,8 +144,8 @@ int main(int, char**) // Setup Dear ImGui style ImGui::Spectrum::StyleColorsSpectrum(); - ImGui::Spectrum::LoadFont(18.0f); + ts_load_fonts(18.0f, _ts_get_font_range_to_load()); ts_load_images(); ts_load_config(); diff --git a/src/windows/main_windows.cpp b/src/windows/main_windows.cpp index 3d136fb..becb1c1 100644 --- a/src/windows/main_windows.cpp +++ b/src/windows/main_windows.cpp @@ -110,41 +110,10 @@ void ts_platform_set_window_title(utf8_int8_t* str) { SetWindowTextW(window_handle, wchar_buffer); } -ts_font_range _ts_get_FONT_RANGE_to_load() { +ts_font_range _ts_get_font_range_to_load() { wchar_t buffer[50]; GetUserDefaultLocaleName(buffer, 50); - - ts_font_range result = FONT_RANGE_ENGLISH; - if (wcscmp(buffer, L"el-GR") == 0) result = FONT_RANGE_GREEK; - if (wcscmp(buffer, L"ko-KR") == 0) result = FONT_RANGE_KOREAN; - if (wcscmp(buffer, L"ja-JP") == 0) result = FONT_RANGE_JAPANESE; - - if (wcscmp(buffer, L"be-BY") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"bg-BG") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"ru-RU") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"ru-MD") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"ro-MD") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"kk-KZ") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"tt-RU") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"ky-KG") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"mn-MN") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"az-Cyrl-AZ") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"uz-Cyrl-UZ") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"sr-Cyrl-CS") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"sr-Latn-CS") == 0) result = FONT_RANGE_CYRILLIC; - - if (wcscmp(buffer, L"bo-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; - if (wcscmp(buffer, L"zh-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; - if (wcscmp(buffer, L"mn-Mong-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; - if (wcscmp(buffer, L"zh-HK") == 0) result = FONT_RANGE_CHINESE_FULL; - if (wcscmp(buffer, L"zh-TW") == 0) result = FONT_RANGE_CHINESE_FULL; - if (wcscmp(buffer, L"zh-SG") == 0) result = FONT_RANGE_CHINESE_SIMPLE; - if (wcscmp(buffer, L"zh-MO") == 0) result = FONT_RANGE_CHINESE_FULL; - - if (wcscmp(buffer, L"th-TH") == 0) result = FONT_RANGE_THAI; - if (wcscmp(buffer, L"vi-VN") == 0) result = FONT_RANGE_VIETNAMESE; - - return result; + return ts_locale_to_range(buffer); } int main(int, char**) @@ -194,7 +163,7 @@ int main(int, char**) QueryPerformanceFrequency(&Frequency); - ts_load_fonts(18.0f, _ts_get_FONT_RANGE_to_load()); + ts_load_fonts(18.0f, _ts_get_font_range_to_load()); ts_load_images(); ts_load_config(); -- cgit v1.2.3-70-g09d2