2026-04-05 04:55:25 +08:00
|
|
|
#include "XCUIBackend/XCUIEditorFontSetup.h"
|
|
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 16:26:29 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
bool ConfigureDefaultXCUIEditorFontsForCurrentContext() {
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
ImFont* uiFont = nullptr;
|
|
|
|
|
if (!BuildDefaultXCUIEditorFontAtlas(*io.Fonts, uiFont)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
io.FontDefault = uiFont;
|
|
|
|
|
return io.FontDefault != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 04:55:25 +08:00
|
|
|
} // namespace XCUIBackend
|
|
|
|
|
} // namespace Editor
|
|
|
|
|
} // namespace XCEngine
|