#include "XCUIBackend/XCUIEditorFontSetup.h" #include namespace XCEngine { namespace Editor { namespace XCUIBackend { namespace { constexpr float kUiFontSize = 18.0f; constexpr const char* kPrimaryUiFontPath = "C:/Windows/Fonts/segoeui.ttf"; constexpr const char* kChineseFallbackFontPath = "C:/Windows/Fonts/msyh.ttc"; bool BuildDefaultXCUIEditorFontAtlas(::ImFontAtlas& atlas, ::ImFont*& outDefaultFont) { outDefaultFont = nullptr; atlas.Clear(); ImFontConfig baseConfig = {}; baseConfig.OversampleH = 2; baseConfig.OversampleV = 1; baseConfig.PixelSnapH = true; outDefaultFont = atlas.AddFontFromFileTTF( kPrimaryUiFontPath, kUiFontSize, &baseConfig, atlas.GetGlyphRangesDefault()); if (outDefaultFont != nullptr) { ImFontConfig mergeConfig = baseConfig; mergeConfig.MergeMode = true; mergeConfig.PixelSnapH = true; atlas.AddFontFromFileTTF( kChineseFallbackFontPath, kUiFontSize, &mergeConfig, atlas.GetGlyphRangesChineseSimplifiedCommon()); } else { outDefaultFont = atlas.AddFontFromFileTTF( kChineseFallbackFontPath, kUiFontSize, &baseConfig, atlas.GetGlyphRangesChineseSimplifiedCommon()); } if (outDefaultFont == nullptr) { ImFontConfig fallbackConfig = baseConfig; fallbackConfig.SizePixels = kUiFontSize; outDefaultFont = atlas.AddFontDefault(&fallbackConfig); } return outDefaultFont != nullptr; } } // namespace bool ConfigureDefaultXCUIEditorFontsForCurrentContext() { ImGuiIO& io = ImGui::GetIO(); ImFont* uiFont = nullptr; if (!BuildDefaultXCUIEditorFontAtlas(*io.Fonts, uiFont)) { return false; } io.FontDefault = uiFont; return io.FontDefault != nullptr; } } // namespace XCUIBackend } // namespace Editor } // namespace XCEngine