fix: 修复构建字体 bug

This commit is contained in:
Xu 2025-03-22 18:07:14 +08:00
commit 2f46067a29
2 changed files with 10 additions and 10 deletions

View file

@ -7,21 +7,19 @@ struct ImGuiHelper {
static const ImWchar* GetGlyphRangesChineseSimplifiedOfficial() noexcept;
static const ImWchar* GetGlyphRangesChineseTraditionalOfficial() noexcept;
static constexpr ImWchar NUMBER_RANGES[] = { L'0', L'9', 0 };
static constexpr ImWchar NOT_NUMBER_RANGES[] = { 0x20, L'0' - 1, L'9' + 1, 0x7E, 0 };
// Basic Latin
static constexpr ImWchar BASIC_LATIN_RANGES[] = { 0x20, 0x7E, 0 };
static constexpr ImWchar BASIC_LATIN_RANGES[] = { 0x20, 0x7E };
// Basic Latin + Latin-1 Supplement + Latin Extended-A用于土耳其语、匈牙利语等。
// 参见 https://en.wikipedia.org/wiki/Latin_Extended-A
static constexpr ImWchar EXTENDED_LATIN_RANGES[] = { 0x20, 0x17F, 0 };
static constexpr ImWchar EXTENDED_LATIN_RANGES[] = { 0x20, 0x17F };
// Basic Latin + Georgian + Georgian Supplement + Georgian Extended用于格鲁吉亚语。
// https://en.wikipedia.org/wiki/Georgian_scripts
static constexpr ImWchar GEORGIAN_RANGES[] = { 0x20, 0x7E, 0x10A0, 0x10FF, 0x2D00, 0x2D2F, 0x1C90, 0x1CBF, 0 };
static constexpr ImWchar GEORGIAN_RANGES[] = { 0x20, 0x7E, 0x10A0, 0x10FF, 0x2D00, 0x2D2F, 0x1C90, 0x1CBF };
// 不包含 Basic Latin用于 Win11
static constexpr ImWchar GEORGIAN_EXTRA_RANGES[] = { 0x10A0, 0x10FF, 0x2D00, 0x2D2F, 0x1C90, 0x1CBF, 0 };
static constexpr ImWchar GEORGIAN_EXTRA_RANGES[] = { 0x10A0, 0x10FF, 0x2D00, 0x2D2F, 0x1C90, 0x1CBF };
// Tamil用于泰米尔语。Tamil Supplement 超出了 ImWchar16 的存储范围,因此暂不支持。
// 参见 https://en.wikipedia.org/wiki/Tamil_script
static constexpr ImWchar TAMIL_EXTRA_RANGES[] = { 0xB80, 0xBFF, 0 };
static constexpr ImWchar TAMIL_EXTRA_RANGES[] = { 0xB80, 0xBFF };
};
}

View file

@ -401,6 +401,7 @@ static void SetGlyphRanges(std::vector<ImWchar>& uiRanges, const ImWchar (&range
// 指针重载,但不能直接使用指针
template <typename T, typename = std::enable_if_t<std::is_same_v<T, const ImWchar*>>>
static void SetGlyphRanges(std::vector<ImWchar>& uiRanges, T ranges) noexcept {
// 删除末尾的 0
for (const ImWchar* range = ranges; *range; ++range) {
uiRanges.push_back(*range);
}
@ -519,14 +520,15 @@ void OverlayDrawer::_BuildFontUI(
// 等宽的数字字符
config.GlyphMinAdvanceX = config.GlyphMaxAdvanceX = fontSize * 0.42f;
_fontMonoNumbers = fontAtlas.AddFontFromMemoryTTF(
(void*)fontData.data(), (int)fontData.size(), fontSize, &config, ImGuiHelper::NUMBER_RANGES);
(void*)fontData.data(), (int)fontData.size(), fontSize, &config, (const ImWchar*)L"09");
// 其他不等宽的字符
config.MergeMode = true;
config.GlyphMinAdvanceX = 0;
config.GlyphMaxAdvanceX = std::numeric_limits<float>::max();
static constexpr ImWchar NOT_NUMBER_RANGES[] = { 0x20, L'0' - 1, L'9' + 1, 0x7E, 0 };
fontAtlas.AddFontFromMemoryTTF(
(void*)fontData.data(), (int)fontData.size(), fontSize, &config, ImGuiHelper::NOT_NUMBER_RANGES);
(void*)fontData.data(), (int)fontData.size(), fontSize, &config, NOT_NUMBER_RANGES);
}
void OverlayDrawer::_BuildFontFPS(const std::vector<uint8_t>& fontData) noexcept {
@ -551,7 +553,7 @@ void OverlayDrawer::_BuildFontFPS(const std::vector<uint8_t>& fontData) noexcept
config.MergeMode = false;
config.GlyphMinAdvanceX = config.GlyphMaxAdvanceX = fpsSize * 0.42f;
_fontFPS = fontAtlas.AddFontFromMemoryTTF(
(void*)fontData.data(), (int)fontData.size(), fpsSize, &config, ImGuiHelper::NUMBER_RANGES);
(void*)fontData.data(), (int)fontData.size(), fpsSize, &config, (const ImWchar*)L"09");
// 其他不等宽的字符
config.MergeMode = true;