diff --git a/src/gui/render.cpp b/src/gui/render.cpp index 7d4c299..d549c27 100644 --- a/src/gui/render.cpp +++ b/src/gui/render.cpp @@ -681,7 +681,7 @@ int Render::CreateMainWindow() { // for window region action SDL_SetWindowHitTest(main_window_, HitTestCallback, this); - SetupFontAndStyle(); + SetupFontAndStyle(true); ImGuiStyle& style = ImGui::GetStyle(); style.ScaleAllSizes(dpi_scale_); @@ -750,7 +750,7 @@ int Render::CreateStreamWindow() { // for window region action SDL_SetWindowHitTest(stream_window_, HitTestCallback, this); - SetupFontAndStyle(); + SetupFontAndStyle(false); SDL_SetRenderScale(stream_renderer_, dpi_scale_, dpi_scale_); @@ -793,7 +793,7 @@ int Render::DestroyStreamWindow() { return 0; } -int Render::SetupFontAndStyle() { +int Render::SetupFontAndStyle(bool main_window) { float font_size = 32.0f; // Setup Dear ImGui style @@ -815,7 +815,11 @@ int Render::SetupFontAndStyle() { // Load system Chinese font as fallback config.MergeMode = false; config.FontDataOwnedByAtlas = false; - system_chinese_font_ = nullptr; + if (main_window) { + main_windows_system_chinese_font_ = nullptr; + } else { + stream_windows_system_chinese_font_ = nullptr; + } #if defined(_WIN32) // Windows: Try Microsoft YaHei (微软雅黑) first, then SimSun (宋体) @@ -841,20 +845,37 @@ int Render::SetupFontAndStyle() { std::ifstream font_file(font_paths[i], std::ios::binary); if (font_file.good()) { font_file.close(); - system_chinese_font_ = - io.Fonts->AddFontFromFileTTF(font_paths[i], font_size, &config, - io.Fonts->GetGlyphRangesChineseFull()); - if (system_chinese_font_ != nullptr) { - LOG_INFO("Loaded system Chinese font: {}", font_paths[i]); - break; + if (main_window) { + main_windows_system_chinese_font_ = + io.Fonts->AddFontFromFileTTF(font_paths[i], font_size, &config, + io.Fonts->GetGlyphRangesChineseFull()); + if (main_windows_system_chinese_font_ != nullptr) { + LOG_INFO("Loaded system Chinese font: {}", font_paths[i]); + break; + } + } else { + stream_windows_system_chinese_font_ = + io.Fonts->AddFontFromFileTTF(font_paths[i], font_size, &config, + io.Fonts->GetGlyphRangesChineseFull()); + if (stream_windows_system_chinese_font_ != nullptr) { + LOG_INFO("Loaded system Chinese font: {}", font_paths[i]); + break; + } } } } // If no system font found, use default font - if (system_chinese_font_ == nullptr) { - system_chinese_font_ = io.Fonts->AddFontDefault(&config); - LOG_WARN("System Chinese font not found, using default font"); + if (main_window) { + if (main_windows_system_chinese_font_ == nullptr) { + main_windows_system_chinese_font_ = io.Fonts->AddFontDefault(&config); + LOG_WARN("System Chinese font not found, using default font"); + } + } else { + if (stream_windows_system_chinese_font_ == nullptr) { + stream_windows_system_chinese_font_ = io.Fonts->AddFontDefault(&config); + LOG_WARN("System Chinese font not found, using default font"); + } } ImGui::StyleColorsLight(); diff --git a/src/gui/render.h b/src/gui/render.h index 9b5f900..53313d5 100644 --- a/src/gui/render.h +++ b/src/gui/render.h @@ -180,7 +180,7 @@ class Render { int DestroyMainWindow(); int CreateStreamWindow(); int DestroyStreamWindow(); - int SetupFontAndStyle(); + int SetupFontAndStyle(bool main_window); int DestroyMainWindowContext(); int DestroyStreamWindowContext(); int DrawMainWindow(); @@ -313,7 +313,8 @@ class Render { SDL_Window* main_window_ = nullptr; SDL_Renderer* main_renderer_ = nullptr; ImGuiContext* main_ctx_ = nullptr; - ImFont* system_chinese_font_ = nullptr; // System Chinese font for fallback + ImFont* main_windows_system_chinese_font_ = nullptr; + ImFont* stream_windows_system_chinese_font_ = nullptr; bool exit_ = false; const int sdl_refresh_ms_ = 16; // ~60 FPS #if _WIN32 diff --git a/src/gui/windows/request_permission_window.mm b/src/gui/windows/request_permission_window.mm index 473b379..3a207c3 100644 --- a/src/gui/windows/request_permission_window.mm +++ b/src/gui/windows/request_permission_window.mm @@ -138,8 +138,8 @@ int Render::RequestPermissionWindow() { ImGui::SetWindowFontScale(0.3f); // use system font - if (system_chinese_font_ != nullptr) { - ImGui::PushFont(system_chinese_font_); + if (main_windows_system_chinese_font_ != nullptr) { + ImGui::PushFont(main_windows_system_chinese_font_); } ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetTextLineHeight() + 5.0f); @@ -191,7 +191,7 @@ int Render::RequestPermissionWindow() { ImGui::SetWindowFontScale(0.45f); // pop system font - if (system_chinese_font_ != nullptr) { + if (main_windows_system_chinese_font_ != nullptr) { ImGui::PopFont(); } diff --git a/src/gui/windows/update_notification_window.cpp b/src/gui/windows/update_notification_window.cpp index f45c67d..9949949 100644 --- a/src/gui/windows/update_notification_window.cpp +++ b/src/gui/windows/update_notification_window.cpp @@ -111,8 +111,8 @@ int Render::UpdateNotificationWindow() { float scrollable_height = window_height - UPDATE_NOTIFICATION_RESERVED_HEIGHT; - if (system_chinese_font_ != nullptr) { - ImGui::PushFont(system_chinese_font_); + if (main_windows_system_chinese_font_ != nullptr) { + ImGui::PushFont(main_windows_system_chinese_font_); } // scrollable content area ImGui::SetCursorPosX(window_width * 0.05f); @@ -163,7 +163,7 @@ int Render::UpdateNotificationWindow() { ImGui::EndChild(); // pop system font - if (system_chinese_font_ != nullptr) { + if (main_windows_system_chinese_font_ != nullptr) { ImGui::PopFont(); }