Implemented GetGlyphRangesChineseSimplifiedOfficial (#2756)

This commit is contained in:
gir489 authored and GitHub committed 2024-02-22 16:53:04 +01:00
1 parent affa94b98c
commit b150009e28
2 files changed
+35 -1

No files matched your search

+34 -1
View File
@@ -124,12 +124,45 @@ namespace big
return {};
}
const ImWchar* font_mgr::GetGlyphRangesChineseSimplifiedOfficial()
{
// Store all official characters for Simplified Chinese.
// Sourced from https://en.wikipedia.org/wiki/Table_of_General_Standard_Chinese_Characters
// (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.)
static const short accumulative_offsets_from_0x4E00[] = {0, 1, 2, 4, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 2, 1, 2, 3, 1, 2, 3, 2, 2, 4, 1, 1, 1, 2, 1, 4, 1, 2, 3, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 3, 1, 1, 1, 1, 1, 5, 3, 7, 1, 2, 5, 6, 8, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 3, 2, 1, 4, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 4, 1, 2, 1, 2, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 3, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 2, 2, 1, 1, 3, 2, 1, 1, 4, 2, 1, 2, 1, 1, 4, 2, 2, 2, 7, 1, 1, 1, 2, 1, 1, 1, 1, 6, 1, 1, 1, 1, 3, 1, 1, 2, 1, 1, 1, 1, 1, 3, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 1, 3, 2, 3, 7, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 4, 3, 3, 1, 3, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 4, 1, 2, 2, 2, 2, 3, 3,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5, 2, 1, 2, 1, 2, 2, 5, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 3, 1, 1, 1, 4, 4, 5, 2, 1, 2, 2,Line truncated
static ImWchar base_ranges[] = // not zero-terminated
{
0x0020,
0x00FF, // Basic Latin + Latin Supplement
0x3000,
0x30FF, // Punctuations, Hiragana, Katakana
0x31F0,
0x31FF, // Katakana Phonetic Extensions
0xFF00,
0xFFEF, // Half-width characters
};
static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(accumulative_offsets_from_0x4E00) * 2 + 1] = {0};
if (!full_ranges[0])
{
memcpy(full_ranges, base_ranges, sizeof(base_ranges));
ImWchar* out_ranges = full_ranges + IM_ARRAYSIZE(base_ranges);
int base_codepoint = 0x4E00;
for (int n = 0; n < IM_ARRAYSIZE(accumulative_offsets_from_0x4E00); n++, out_ranges += 2)
{
out_ranges[0] = out_ranges[1] = (ImWchar)(base_codepoint + accumulative_offsets_from_0x4E00[n]);
base_codepoint += accumulative_offsets_from_0x4E00[n];
}
out_ranges[0] = 0;
}
return &full_ranges[0];
}
const ImWchar* font_mgr::get_imgui_alphabet_type()
{
auto& io = ImGui::GetIO();
switch (m_require_extra)
{
case eAlphabetType::CHINESE: return io.Fonts->GetGlyphRangesChineseFull();
case eAlphabetType::CHINESE: return GetGlyphRangesChineseSimplifiedOfficial();
case eAlphabetType::CYRILLIC: return io.Fonts->GetGlyphRangesCyrillic();
case eAlphabetType::JAPANESE: return io.Fonts->GetGlyphRangesJapanese();
case eAlphabetType::KOREAN: return io.Fonts->GetGlyphRangesKorean();
+1
View File
@@ -34,6 +34,7 @@ namespace big
void rebuild();
file get_available_font_file_for_alphabet_type();
const ImWchar* GetGlyphRangesChineseSimplifiedOfficial();
const ImWchar* get_imgui_alphabet_type();
};
}