feat(core): render local CJK glyphs at 2x texture resolution (#4304)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Taku Fukada
2026-07-01 20:52:01 +09:00
committed by GitHub
parent 60f15190c3
commit 887e6021e6
22 changed files with 357 additions and 84 deletions

View File

@@ -18,6 +18,10 @@ namespace {
return codepoint >= (first) && codepoint <= (last); \
}
inline bool isInRange(char16_t codepoint, char16_t first, char16_t last) {
return codepoint >= first && codepoint <= last;
}
// The following table comes from <http://www.unicode.org/Public/12.0.0/ucd/Blocks.txt>.
// Keep it synchronized with <http://www.unicode.org/Public/UCD/latest/ucd/Blocks.txt>.
@@ -411,8 +415,59 @@ bool allowsIdeographicBreaking(char16_t chr) {
}
bool allowsFixedWidthGlyphGeneration(char16_t chr) {
// Mirrors conservative set of characters used in glyph_manager.js/_tinySDF
return isInCJKUnifiedIdeographs(chr) || isInHangulSyllables(chr) || isInKatakana(chr) || isInHiragana(chr);
// Mirrors the BMP ranges in GL JS's codePointUsesLocalIdeographFontFamily.
// Astral-plane ranges are not included because GlyphID only carries BMP
// codepoints for local glyph generation.
return
// Bopomofo tone marks.
isInRange(chr, 0x02EA, 0x02EB) ||
// Hangul Jamo.
isInHangulJamo(chr) ||
// CJK Radicals Supplement, Kangxi Radicals.
isInCJKRadicalsSupplement(chr) || isInKangxiRadicals(chr) ||
// CJK Symbols and Punctuation, Hiragana, Katakana.
isInCJKSymbolsandPunctuation(chr) || isInHiragana(chr) || isInKatakana(chr) ||
// Bopomofo.
isInRange(chr, 0x3105, 0x312F) ||
// Hangul Compatibility Jamo.
isInRange(chr, 0x3131, 0x318E) ||
// Bopomofo Extended through CJK Unified Ideographs Extension A.
isInBopomofoExtended(chr) || isInCJKStrokes(chr) || isInKatakanaPhoneticExtensions(chr) ||
isInEnclosedCJKLettersandMonths(chr) || isInCJKCompatibility(chr) || isInCJKUnifiedIdeographsExtensionA(chr) ||
// CJK Unified Ideographs and Yi Syllables.
isInCJKUnifiedIdeographs(chr) || isInRange(chr, 0xA000, 0xA48C) ||
// Yi Radicals.
isInRange(chr, 0xA490, 0xA4C6) ||
// Hangul Jamo Extended-A.
isInRange(chr, 0xA960, 0xA97C) ||
// Hangul Syllables and Hangul Jamo Extended-B.
isInHangulSyllables(chr) || isInRange(chr, 0xD7B0, 0xD7C6) ||
// Hangul Jamo Extended-B.
isInRange(chr, 0xD7CB, 0xD7FB) ||
// CJK Compatibility Ideographs.
isInRange(chr, 0xF900, 0xFA6D) ||
// CJK Compatibility Ideographs.
isInRange(chr, 0xFA70, 0xFAD9) ||
// Vertical Forms.
isInVerticalForms(chr) ||
// CJK Compatibility Forms.
isInCJKCompatibilityForms(chr) ||
// Halfwidth and Fullwidth Forms.
isInHalfwidthandFullwidthForms(chr);
}
bool glyphRangeIsEntirelyLocallyGenerated(char16_t rangeStart) {
// Some ranges (notably 0xFF00, where Halfwidth/Fullwidth Forms ends at
// 0xFFEF and the Specials block continues to 0xFFFD) mix locally-rendered
// and non-local codepoints, so it is not safe to infer the whole range
// from the first codepoint alone.
constexpr uint32_t glyphsPerRange = 256;
for (uint32_t offset = 0; offset < glyphsPerRange; ++offset) {
if (!allowsFixedWidthGlyphGeneration(static_cast<char16_t>(rangeStart + offset))) {
return false;
}
}
return true;
}
bool allowsVerticalWritingMode(const std::u16string& string) {