summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-16 17:30:52 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-16 17:30:52 +0100
commit253c967318e6a75c6c4947b01f12ee3797db1b40 (patch)
tree662c8638ab0be7efec6793dc5e980a163425209d
parent4b917c469bffdb8f390d126934a60c2bbebca7b4 (diff)
load font & ranges based on pc locale
-rw-r--r--fonts/NotoSansSC.hbin0 -> 49120728 bytes
-rw-r--r--fonts/NotoSansThai.hbin0 -> 222380 bytes
-rw-r--r--fonts/NotoSerifTC.hbin0 -> 35164738 bytes
-rw-r--r--imgui/imgui_spectrum.cpp48
-rw-r--r--src/fonts.cpp94
-rw-r--r--src/fonts.h15
-rw-r--r--src/windows/main_windows.cpp43
7 files changed, 148 insertions, 52 deletions
diff --git a/fonts/NotoSansSC.h b/fonts/NotoSansSC.h
new file mode 100644
index 0000000..5ecb2ca
--- /dev/null
+++ b/fonts/NotoSansSC.h
Binary files differ
diff --git a/fonts/NotoSansThai.h b/fonts/NotoSansThai.h
new file mode 100644
index 0000000..e0531c4
--- /dev/null
+++ b/fonts/NotoSansThai.h
Binary files differ
diff --git a/fonts/NotoSerifTC.h b/fonts/NotoSerifTC.h
new file mode 100644
index 0000000..8d26847
--- /dev/null
+++ b/fonts/NotoSerifTC.h
Binary files differ
diff --git a/imgui/imgui_spectrum.cpp b/imgui/imgui_spectrum.cpp
index 47cca36..928ad96 100644
--- a/imgui/imgui_spectrum.cpp
+++ b/imgui/imgui_spectrum.cpp
@@ -6,51 +6,6 @@
namespace ImGui {
namespace Spectrum {
- void LoadFont(float size) {
- ImGuiIO& io = ImGui::GetIO();
- ImFontConfig config;
- config.MergeMode = true;
-
- static const ImWchar arrow_r[] =
- {
- 0x2192, 0x2193, // → character.
- 0,
- };
-
- static const ImWchar triangles[] =
- {
- 0x25B6, 0x25BC, // ▶ ▼ characters.
- 0,
- };
-
- ImFontGlyphRangesBuilder builder;
- ImVector<ImWchar> ranges;
- builder.AddRanges(io.Fonts->GetGlyphRangesDefault());
- builder.AddRanges(arrow_r);
- builder.AddRanges(triangles);
- builder.BuildRanges(&ranges);
-
- ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(
- SourceSansProRegular_compressed_data,
- SourceSansProRegular_compressed_size,
- size, nullptr, ranges.Data);
-
- IM_ASSERT(font != nullptr);
- io.FontDefault = font;
-
- // Uncomment if you want these glyphs. Fonts can be found in fonts/ folder.
- // io.Fonts->AddFontFromMemoryCompressedTTF(
- // GmarketSans_compressed_data,
- // GmarketSans_compressed_size,
- // size, &config, io.Fonts->GetGlyphRangesKorean());
-
- // io.Fonts->AddFontFromMemoryCompressedTTF(
- // NotoSansJP_compressed_data,
- // NotoSansJP_compressed_size,
- // size, &config, io.Fonts->GetGlyphRangesJapanese());
-
- io.Fonts->Build();
- }
void StyleColorsSpectrum() {
ImGuiStyle* style = &ImGui::GetStyle();
@@ -109,8 +64,5 @@ namespace ImGui {
colors[ImGuiCol_TableRowBg] = ColorConvertU32ToFloat4(Color(0xFFFFFF));
colors[ImGuiCol_TableRowBgAlt] = ColorConvertU32ToFloat4(Spectrum::GRAY100);
}
-
-
-
}
}
diff --git a/src/fonts.cpp b/src/fonts.cpp
new file mode 100644
index 0000000..3c1c520
--- /dev/null
+++ b/src/fonts.cpp
@@ -0,0 +1,94 @@
+#include "fonts.h"
+#include "../fonts/SourceSansProRegular.h"
+#include "../fonts/GmarketSans.h"
+#include "../fonts/NotoSansJP.h"
+#include "../fonts/NotoSerifTC.h"
+#include "../fonts/NotoSansSC.h"
+#include "../fonts/NotoSansThai.h"
+#include "imgui.h"
+
+#include <stdio.h>
+
+void ts_load_fonts(float size, ts_font_range locale) {
+ ImGuiIO& io = ImGui::GetIO();
+ ImFontConfig config;
+ config.MergeMode = true;
+
+ static const ImWchar arrow_r[] =
+ {
+ 0x2192, 0x2193, // → character.
+ 0,
+ };
+
+ static const ImWchar triangles[] =
+ {
+ 0x25B6, 0x25BC, // ▶ ▼ characters.
+ 0,
+ };
+
+ // We always use Source Sans Regular for the english, cyrillic and greek alphabet.
+ // other languages will be displayed in their respective font.
+
+ ImFontGlyphRangesBuilder builder;
+ ImVector<ImWchar> ranges;
+ builder.AddRanges(arrow_r);
+ builder.AddRanges(triangles);
+
+ builder.AddRanges(io.Fonts->GetGlyphRangesDefault());
+ if (locale == FONT_RANGE_GREEK)
+ builder.AddRanges(io.Fonts->GetGlyphRangesGreek());
+
+ if (locale == FONT_RANGE_CYRILLIC)
+ builder.AddRanges(io.Fonts->GetGlyphRangesCyrillic());
+
+ builder.BuildRanges(&ranges);
+
+ ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(
+ SourceSansProRegular_compressed_data,
+ SourceSansProRegular_compressed_size,
+ size, nullptr, ranges.Data);
+
+ IM_ASSERT(font != nullptr);
+ io.FontDefault = font;
+
+ // Fonts can be found in fonts/ folder.
+ if (locale == FONT_RANGE_KOREAN) {
+ size /= 1.5f;
+ io.Fonts->AddFontFromMemoryCompressedTTF(
+ GmarketSans_compressed_data,
+ GmarketSans_compressed_size,
+ size, &config, io.Fonts->GetGlyphRangesKorean());
+ }
+ else if (locale == FONT_RANGE_JAPANESE) {
+ io.Fonts->AddFontFromMemoryCompressedTTF(
+ NotoSansJP_compressed_data,
+ NotoSansJP_compressed_size,
+ size, &config, io.Fonts->GetGlyphRangesJapanese());
+ }
+ else if (locale == FONT_RANGE_CHINESE_FULL) {
+ io.Fonts->AddFontFromMemoryCompressedTTF(
+ NotoSerifTC_compressed_data,
+ NotoSerifTC_compressed_size,
+ size, &config, io.Fonts->GetGlyphRangesChineseFull());
+ }
+ else if (locale == FONT_RANGE_CHINESE_SIMPLE) {
+ io.Fonts->AddFontFromMemoryCompressedTTF(
+ NotoSansSC_compressed_data,
+ NotoSansSC_compressed_size,
+ size, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
+ }
+ else if (locale == FONT_RANGE_THAI) {
+ io.Fonts->AddFontFromMemoryCompressedTTF(
+ NotoSansThai_compressed_data,
+ NotoSansThai_compressed_size,
+ size, &config, io.Fonts->GetGlyphRangesThai());
+ }
+ else if (locale == FONT_RANGE_VIETNAMESE) {
+ io.Fonts->AddFontFromMemoryCompressedTTF(
+ NotoSansJP_compressed_data,
+ NotoSansJP_compressed_size,
+ size, &config, io.Fonts->GetGlyphRangesVietnamese());
+ }
+
+ io.Fonts->Build();
+} \ No newline at end of file
diff --git a/src/fonts.h b/src/fonts.h
new file mode 100644
index 0000000..4a3bb93
--- /dev/null
+++ b/src/fonts.h
@@ -0,0 +1,15 @@
+#pragma once
+
+typedef enum t_ts_font_range {
+ FONT_RANGE_ENGLISH,
+ FONT_RANGE_GREEK,
+ FONT_RANGE_KOREAN,
+ FONT_RANGE_JAPANESE,
+ FONT_RANGE_CHINESE_FULL,
+ FONT_RANGE_CHINESE_SIMPLE,
+ FONT_RANGE_CYRILLIC,
+ FONT_RANGE_THAI,
+ FONT_RANGE_VIETNAMESE,
+} ts_font_range;
+
+void ts_load_fonts(float size, ts_font_range locale); \ No newline at end of file
diff --git a/src/windows/main_windows.cpp b/src/windows/main_windows.cpp
index b7f29f7..3d136fb 100644
--- a/src/windows/main_windows.cpp
+++ b/src/windows/main_windows.cpp
@@ -11,6 +11,7 @@
#include "memory_bucket.h"
#include "image.h"
#include "config.h"
+#include "fonts.h"
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@@ -109,6 +110,43 @@ void ts_platform_set_window_title(utf8_int8_t* str) {
SetWindowTextW(window_handle, wchar_buffer);
}
+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;
+}
+
int main(int, char**)
{
if (OleInitialize(NULL) != S_OK) {
@@ -149,17 +187,14 @@ int main(int, char**)
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.IniFilename = _ts_platform_get_config_file_path(config_path);
- // Setup Dear ImGui style
ImGui::Spectrum::StyleColorsSpectrum();
- ImGui::Spectrum::LoadFont(18.0f);
- //ImGui::StyleColorsLight();
- // Setup Platform/Renderer backends
ImGui_ImplWin32_InitForOpenGL(hwnd);
ImGui_ImplOpenGL3_Init();
QueryPerformanceFrequency(&Frequency);
+ ts_load_fonts(18.0f, _ts_get_FONT_RANGE_to_load());
ts_load_images();
ts_load_config();