Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/cjk unicode lookup #5421

Merged
merged 16 commits into from
Feb 2, 2025
17 changes: 10 additions & 7 deletions src/render/glyph_manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {loadGlyphRange} from '../style/load_glyph_range';

import TinySDF from '@mapbox/tiny-sdf';
import {unicodeBlockLookup} from '../util/is_char_in_unicode_block';
import {AlphaImage} from '../util/image';

import type {StyleGlyph} from '../style/style_glyph';
Expand Down Expand Up @@ -119,14 +120,16 @@ export class GlyphManager {
}

_doesCharSupportLocalGlyph(id: number): boolean {
// The CJK Unified Ideographs blocks and Hangul Syllables blocks are
// spread across many glyph PBFs and are typically accessed very
// randomly. Preferring local rendering for these blocks reduces
// wasteful bandwidth consumption. For visual consistency within CJKV
// text, also include any other CJKV or siniform ideograph or hangul,
// hiragana, or katakana character.
return !!this.localIdeographFontFamily &&
/\p{Ideo}|\p{sc=Hang}|\p{sc=Hira}|\p{sc=Kana}/u.test(String.fromCodePoint(id));
unicodeBlockLookup['CJK Unified Ideographs'](id) ||
unicodeBlockLookup['Hangul Syllables'](id) ||
unicodeBlockLookup['Hiragana'](id) ||
unicodeBlockLookup['Katakana'](id) || // includes "ー"
// symbols
unicodeBlockLookup['CJK Unified Ideographs Extension G'](id) || // 𠀀
unicodeBlockLookup['CJK Symbols and Punctuation'](id) || // 、。〃〄々〆〇〈〉《》「
unicodeBlockLookup['Halfwidth and Fullwidth Forms'](id); // !?"#$%&

}

_tinySDF(entry: Entry, stack: string, id: number): StyleGlyph {
Expand Down
10 changes: 5 additions & 5 deletions src/util/is_char_in_unicode_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Kangxi Radicals': (char) => char >= 0x2F00 && char <= 0x2FDF,
'Ideographic Description Characters': (char) => char >= 0x2FF0 && char <= 0x2FFF,
'CJK Symbols and Punctuation': (char) => char >= 0x3000 && char <= 0x303F,
// 'Hiragana': (char) => char >= 0x3040 && char <= 0x309F,
'Hiragana': (char) => char >= 0x3040 && char <= 0x309F,
'Katakana': (char) => char >= 0x30A0 && char <= 0x30FF,
// 'Bopomofo': (char) => char >= 0x3100 && char <= 0x312F,
// 'Hangul Compatibility Jamo': (char) => char >= 0x3130 && char <= 0x318F,
Expand All @@ -124,7 +124,7 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
'CJK Compatibility': (char) => char >= 0x3300 && char <= 0x33FF,
// 'CJK Unified Ideographs Extension A': (char) => char >= 0x3400 && char <= 0x4DBF,
'Yijing Hexagram Symbols': (char) => char >= 0x4DC0 && char <= 0x4DFF,
// 'CJK Unified Ideographs': (char) => char >= 0x4E00 && char <= 0x9FFF,
'CJK Unified Ideographs': (char) => char >= 0x4E00 && char <= 0x9FFF,
// 'Yi Syllables': (char) => char >= 0xA000 && char <= 0xA48F,
// 'Yi Radicals': (char) => char >= 0xA490 && char <= 0xA4CF,
// 'Lisu': (char) => char >= 0xA4D0 && char <= 0xA4FF,
Expand All @@ -151,7 +151,7 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Latin Extended-E': (char) => char >= 0xAB30 && char <= 0xAB6F,
// 'Cherokee Supplement': (char) => char >= 0xAB70 && char <= 0xABBF,
// 'Meetei Mayek': (char) => char >= 0xABC0 && char <= 0xABFF,
// 'Hangul Syllables': (char) => char >= 0xAC00 && char <= 0xD7AF,
'Hangul Syllables': (char) => char >= 0xAC00 && char <= 0xD7AF,
// 'Hangul Jamo Extended-B': (char) => char >= 0xD7B0 && char <= 0xD7FF,
// 'High Surrogates': (char) => char >= 0xD800 && char <= 0xDB7F,
// 'High Private Use Surrogates': (char) => char >= 0xDB80 && char <= 0xDBFF,
Expand All @@ -166,7 +166,7 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
'CJK Compatibility Forms': (char) => char >= 0xFE30 && char <= 0xFE4F,
'Small Form Variants': (char) => char >= 0xFE50 && char <= 0xFE6F,
// 'Arabic Presentation Forms-B': (char) => char >= 0xFE70 && char <= 0xFEFF,
'Halfwidth and Fullwidth Forms': (char) => char >= 0xFF00 && char <= 0xFFEF
'Halfwidth and Fullwidth Forms': (char) => char >= 0xFF00 && char <= 0xFFEF,
// 'Specials': (char) => char >= 0xFFF0 && char <= 0xFFFF,
// 'Linear B Syllabary': (char) => char >= 0x10000 && char <= 0x1007F,
// 'Linear B Ideograms': (char) => char >= 0x10080 && char <= 0x100FF,
Expand Down Expand Up @@ -335,7 +335,7 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'CJK Unified Ideographs Extension E': (char) => char >= 0x2B820 && char <= 0x2CEAF,
// 'CJK Unified Ideographs Extension F': (char) => char >= 0x2CEB0 && char <= 0x2EBEF,
// 'CJK Unified Ideographs Extension I': (char) => char >= 0x2EBF0 && char <= 0x2EE5F,
// 'CJK Unified Ideographs Extension G': (char) => char >= 0x30000 && char <= 0x3134F,
'CJK Unified Ideographs Extension G': (char) => char >= 0x30000 && char <= 0x3134F,
// 'CJK Unified Ideographs Extension H': (char) => char >= 0x31350 && char <= 0x323AF,
// 'CJK Compatibility Ideographs Supplement': (char) => char >= 0x2F800 && char <= 0x2FA1F,
// 'Tags': (char) => char >= 0xE0000 && char <= 0xE007F,
Expand Down
Loading