Skip to content

Commit

Permalink
Detect scripts in non-BMP code blocks
Browse files Browse the repository at this point in the history
Enabled local glyph rendering in some additional CJKV code blocks, as well as in Tangut, which is thrash-prone like CJKV. Disabled letter spacing for more cursive scripts.
  • Loading branch information
1ec5 committed Aug 15, 2024
1 parent 8331c87 commit a440cb6
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add constants `MAX_TILE_ZOOM = 25` and `MIN_TILE_ZOOM = 0` as maximum and minimum world tile zoom (Z) values; replace hardcoded instances with those constants.
- Add functions `isInBoundsForTileZoomXY` and `isInBoundsForZoomLngLat` to check whether a tile ZXY or a zoom+LngLat is in the world bounds; use `MAX_TILE_ZOOM` and `MIN_TILE_ZOOM` in those checks; replace existing hardcoded checks with those functions.
- Render uncommon Chinese, Japanese, Korean, and Vietnamese characters. ([#4550](https://github.com/maplibre/maplibre-gl-js/pull/4550))
- _...Add new stuff here..._

### 🐞 Bug fixes
Expand Down
4 changes: 1 addition & 3 deletions src/render/glyph_manager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {loadGlyphRange} from '../style/load_glyph_range';

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

import type {StyleGlyph} from '../style/style_glyph';
import type {RequestManager} from '../util/request_manager';
import type {GetGlyphsResponse} from '../util/actor_messages';
import {charAllowsIdeographicBreaking} from '../util/script_detection';

type Entry = {
// null means we've requested the range, but the glyph wasn't included in the result.
Expand Down Expand Up @@ -137,11 +137,9 @@ export class GlyphManager {
* other siniform code blocks prefer local rendering.
*/
_doesCharSupportLocalGlyph(id: number): boolean {
/* eslint-disable new-cap */
return !!this.localIdeographFontFamily &&
(/\p{Ideo}|\p{sc=Hang}|\p{sc=Hira}|\p{sc=Kana}/u.test(String.fromCodePoint(id)) ||
charAllowsIdeographicBreaking(id));
/* eslint-enable new-cap */
}

_tinySDF(entry: Entry, stack: string, id: number): StyleGlyph {
Expand Down
98 changes: 49 additions & 49 deletions src/util/is_char_in_unicode_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Cyrillic': (char) => char >= 0x0400 && char <= 0x04FF,
// 'Cyrillic Supplement': (char) => char >= 0x0500 && char <= 0x052F,
// 'Armenian': (char) => char >= 0x0530 && char <= 0x058F,
//'Hebrew': (char) => char >= 0x0590 && char <= 0x05FF,
// 'Hebrew': (char) => char >= 0x0590 && char <= 0x05FF,
// 'Arabic': (char) => char >= 0x0600 && char <= 0x06FF,
//'Syriac': (char) => char >= 0x0700 && char <= 0x074F,
// 'Syriac': (char) => char >= 0x0700 && char <= 0x074F,
// 'Arabic Supplement': (char) => char >= 0x0750 && char <= 0x077F,
// 'Thaana': (char) => char >= 0x0780 && char <= 0x07BF,
// 'NKo': (char) => char >= 0x07C0 && char <= 0x07FF,
Expand Down Expand Up @@ -109,7 +109,7 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Cyrillic Extended-A': (char) => char >= 0x2DE0 && char <= 0x2DFF,
// 'Supplemental Punctuation': (char) => char >= 0x2E00 && char <= 0x2E7F,
'CJK Radicals Supplement': (char) => char >= 0x2E80 && char <= 0x2EFF,
// 'Kangxi Radicals': (char) => char >= 0x2F00 && char <= 0x2FDF,
'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,
Expand All @@ -119,7 +119,7 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
'Kanbun': (char) => char >= 0x3190 && char <= 0x319F,
// 'Bopomofo Extended': (char) => char >= 0x31A0 && char <= 0x31BF,
'CJK Strokes': (char) => char >= 0x31C0 && char <= 0x31EF,
// 'Katakana Phonetic Extensions': (char) => char >= 0x31F0 && char <= 0x31FF,
'Katakana Phonetic Extensions': (char) => char >= 0x31F0 && char <= 0x31FF,
'Enclosed CJK Letters and Months': (char) => char >= 0x3200 && char <= 0x32FF,
'CJK Compatibility': (char) => char >= 0x3300 && char <= 0x33FF,
// 'CJK Unified Ideographs Extension A': (char) => char >= 0x3400 && char <= 0x4DBF,
Expand Down Expand Up @@ -199,7 +199,7 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Hatran': (char) => char >= 0x108E0 && char <= 0x108FF,
// 'Phoenician': (char) => char >= 0x10900 && char <= 0x1091F,
// 'Lydian': (char) => char >= 0x10920 && char <= 0x1093F,
// 'Meroitic Hieroglyphs': (char) => char >= 0x10980 && char <= 0x1099F,
'Meroitic Hieroglyphs': (char) => char >= 0x10980 && char <= 0x1099F,
// 'Meroitic Cursive': (char) => char >= 0x109A0 && char <= 0x109FF,
// 'Kharoshthi': (char) => char >= 0x10A00 && char <= 0x10A5F,
// 'Old South Arabian': (char) => char >= 0x10A60 && char <= 0x10A7F,
Expand All @@ -218,7 +218,7 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Arabic Extended-C': (char) => char >= 0x10EC0 && char <= 0x10EFF,
// 'Old Sogdian': (char) => char >= 0x10F00 && char <= 0x10F2F,
// 'Sogdian': (char) => char >= 0x10F30 && char <= 0x10F6F,
// 'Old Uyghur': (char) => char >= 0x10F70 && char <= 0x10FAF,
'Old Uyghur': (char) => char >= 0x10F70 && char <= 0x10FAF,
// 'Chorasmian': (char) => char >= 0x10FB0 && char <= 0x10FDF,
// 'Elymaic': (char) => char >= 0x10FE0 && char <= 0x10FFF,
// 'Brahmi': (char) => char >= 0x11000 && char <= 0x1107F,
Expand All @@ -235,19 +235,19 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Tulu-Tigalari': (char) => char >= 0x11380 && char <= 0x113FF,
// 'Newa': (char) => char >= 0x11400 && char <= 0x1147F,
// 'Tirhuta': (char) => char >= 0x11480 && char <= 0x114DF,
// 'Siddham': (char) => char >= 0x11580 && char <= 0x115FF,
'Siddham': (char) => char >= 0x11580 && char <= 0x115FF,
// 'Modi': (char) => char >= 0x11600 && char <= 0x1165F,
// 'Mongolian Supplement': (char) => char >= 0x11660 && char <= 0x1167F,
'Mongolian Supplement': (char) => char >= 0x11660 && char <= 0x1167F,
// 'Takri': (char) => char >= 0x11680 && char <= 0x116CF,
// 'Myanmar Extended-C': (char) => char >= 0x116D0 && char <= 0x116FF,
// 'Ahom': (char) => char >= 0x11700 && char <= 0x1174F,
// 'Dogra': (char) => char >= 0x11800 && char <= 0x1184F,
// 'Warang Citi': (char) => char >= 0x118A0 && char <= 0x118FF,
// 'Dives Akuru': (char) => char >= 0x11900 && char <= 0x1195F,
// 'Nandinagari': (char) => char >= 0x119A0 && char <= 0x119FF,
// 'Zanabazar Square': (char) => char >= 0x11A00 && char <= 0x11A4F,
// 'Soyombo': (char) => char >= 0x11A50 && char <= 0x11AAF,
// 'Unified Canadian Aboriginal Syllabics Extended-A': (char) => char >= 0x11AB0 && char <= 0x11ABF,
'Zanabazar Square': (char) => char >= 0x11A00 && char <= 0x11A4F,
'Soyombo': (char) => char >= 0x11A50 && char <= 0x11AAF,
'Unified Canadian Aboriginal Syllabics Extended-A': (char) => char >= 0x11AB0 && char <= 0x11ABF,
// 'Pau Cin Hau': (char) => char >= 0x11AC0 && char <= 0x11AFF,
// 'Devanagari Extended-A': (char) => char >= 0x11B00 && char <= 0x11B5F,
// 'Sunuwar': (char) => char >= 0x11BC0 && char <= 0x11BFF,
Expand All @@ -263,10 +263,10 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Cuneiform Numbers and Punctuation': (char) => char >= 0x12400 && char <= 0x1247F,
// 'Early Dynastic Cuneiform': (char) => char >= 0x12480 && char <= 0x1254F,
// 'Cypro-Minoan': (char) => char >= 0x12F90 && char <= 0x12FFF,
// 'Egyptian Hieroglyphs': (char) => char >= 0x13000 && char <= 0x1342F,
// 'Egyptian Hieroglyph Format Controls': (char) => char >= 0x13430 && char <= 0x1345F,
// 'Egyptian Hieroglyphs Extended-A': (char) => char >= 0x13460 && char <= 0x143FF,
// 'Anatolian Hieroglyphs': (char) => char >= 0x14400 && char <= 0x1467F,
'Egyptian Hieroglyphs': (char) => char >= 0x13000 && char <= 0x1342F,
'Egyptian Hieroglyph Format Controls': (char) => char >= 0x13430 && char <= 0x1345F,
'Egyptian Hieroglyphs Extended-A': (char) => char >= 0x13460 && char <= 0x143FF,
'Anatolian Hieroglyphs': (char) => char >= 0x14400 && char <= 0x1467F,
// 'Gurung Khema': (char) => char >= 0x16100 && char <= 0x1613F,
// 'Bamum Supplement': (char) => char >= 0x16800 && char <= 0x16A3F,
// 'Mro': (char) => char >= 0x16A40 && char <= 0x16A6F,
Expand All @@ -276,29 +276,29 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Kirat Rai': (char) => char >= 0x16D40 && char <= 0x16D7F,
// 'Medefaidrin': (char) => char >= 0x16E40 && char <= 0x16E9F,
// 'Miao': (char) => char >= 0x16F00 && char <= 0x16F9F,
// 'Ideographic Symbols and Punctuation': (char) => char >= 0x16FE0 && char <= 0x16FFF,
// 'Tangut': (char) => char >= 0x17000 && char <= 0x187FF,
// 'Tangut Components': (char) => char >= 0x18800 && char <= 0x18AFF,
// 'Khitan Small Script': (char) => char >= 0x18B00 && char <= 0x18CFF,
// 'Tangut Supplement': (char) => char >= 0x18D00 && char <= 0x18D7F,
// 'Kana Extended-B': (char) => char >= 0x1AFF0 && char <= 0x1AFFF,
// 'Kana Supplement': (char) => char >= 0x1B000 && char <= 0x1B0FF,
// 'Kana Extended-A': (char) => char >= 0x1B100 && char <= 0x1B12F,
// 'Small Kana Extension': (char) => char >= 0x1B130 && char <= 0x1B16F,
// 'Nushu': (char) => char >= 0x1B170 && char <= 0x1B2FF,
// 'Duployan': (char) => char >= 0x1BC00 && char <= 0x1BC9F,
'Ideographic Symbols and Punctuation': (char) => char >= 0x16FE0 && char <= 0x16FFF,
'Tangut': (char) => char >= 0x17000 && char <= 0x187FF,
'Tangut Components': (char) => char >= 0x18800 && char <= 0x18AFF,
'Khitan Small Script': (char) => char >= 0x18B00 && char <= 0x18CFF,
'Tangut Supplement': (char) => char >= 0x18D00 && char <= 0x18D7F,
'Kana Extended-B': (char) => char >= 0x1AFF0 && char <= 0x1AFFF,
'Kana Supplement': (char) => char >= 0x1B000 && char <= 0x1B0FF,
'Kana Extended-A': (char) => char >= 0x1B100 && char <= 0x1B12F,
'Small Kana Extension': (char) => char >= 0x1B130 && char <= 0x1B16F,
'Nushu': (char) => char >= 0x1B170 && char <= 0x1B2FF,
'Duployan': (char) => char >= 0x1BC00 && char <= 0x1BC9F,
// 'Shorthand Format Controls': (char) => char >= 0x1BCA0 && char <= 0x1BCAF,
// 'Symbols for Legacy Computing Supplement': (char) => char >= 0x1CC00 && char <= 0x1CEBF,
// 'Znamenny Musical Notation': (char) => char >= 0x1CF00 && char <= 0x1CFCF,
// 'Byzantine Musical Symbols': (char) => char >= 0x1D000 && char <= 0x1D0FF,
// 'Musical Symbols': (char) => char >= 0x1D100 && char <= 0x1D1FF,
'Znamenny Musical Notation': (char) => char >= 0x1CF00 && char <= 0x1CFCF,
'Byzantine Musical Symbols': (char) => char >= 0x1D000 && char <= 0x1D0FF,
'Musical Symbols': (char) => char >= 0x1D100 && char <= 0x1D1FF,
// 'Ancient Greek Musical Notation': (char) => char >= 0x1D200 && char <= 0x1D24F,
// 'Kaktovik Numerals': (char) => char >= 0x1D2C0 && char <= 0x1D2DF,
// 'Mayan Numerals': (char) => char >= 0x1D2E0 && char <= 0x1D2FF,
// 'Tai Xuan Jing Symbols': (char) => char >= 0x1D300 && char <= 0x1D35F,
// 'Counting Rod Numerals': (char) => char >= 0x1D360 && char <= 0x1D37F,
'Mayan Numerals': (char) => char >= 0x1D2E0 && char <= 0x1D2FF,
'Tai Xuan Jing Symbols': (char) => char >= 0x1D300 && char <= 0x1D35F,
'Counting Rod Numerals': (char) => char >= 0x1D360 && char <= 0x1D37F,
// 'Mathematical Alphanumeric Symbols': (char) => char >= 0x1D400 && char <= 0x1D7FF,
// 'Sutton SignWriting': (char) => char >= 0x1D800 && char <= 0x1DAAF,
'Sutton SignWriting': (char) => char >= 0x1D800 && char <= 0x1DAAF,
// 'Latin Extended-G': (char) => char >= 0x1DF00 && char <= 0x1DFFF,
// 'Glagolitic Supplement': (char) => char >= 0x1E000 && char <= 0x1E02F,
// 'Cyrillic Extended-D': (char) => char >= 0x1E030 && char <= 0x1E08F,
Expand All @@ -312,22 +312,22 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Adlam': (char) => char >= 0x1E900 && char <= 0x1E95F,
// 'Indic Siyaq Numbers': (char) => char >= 0x1EC70 && char <= 0x1ECBF,
// 'Ottoman Siyaq Numbers': (char) => char >= 0x1ED00 && char <= 0x1ED4F,
// 'Arabic Mathematical Alphabetic Symbols': (char) => char >= 0x1EE00 && char <= 0x1EEFF,
// 'Mahjong Tiles': (char) => char >= 0x1F000 && char <= 0x1F02F,
// 'Domino Tiles': (char) => char >= 0x1F030 && char <= 0x1F09F,
// 'Playing Cards': (char) => char >= 0x1F0A0 && char <= 0x1F0FF,
// 'Enclosed Alphanumeric Supplement': (char) => char >= 0x1F100 && char <= 0x1F1FF,
'Arabic Mathematical Alphabetic Symbols': (char) => char >= 0x1EE00 && char <= 0x1EEFF,
'Mahjong Tiles': (char) => char >= 0x1F000 && char <= 0x1F02F,
'Domino Tiles': (char) => char >= 0x1F030 && char <= 0x1F09F,
'Playing Cards': (char) => char >= 0x1F0A0 && char <= 0x1F0FF,
'Enclosed Alphanumeric Supplement': (char) => char >= 0x1F100 && char <= 0x1F1FF,
'Enclosed Ideographic Supplement': (char) => char >= 0x1F200 && char <= 0x1F2FF,
// 'Miscellaneous Symbols and Pictographs': (char) => char >= 0x1F300 && char <= 0x1F5FF,
// 'Emoticons': (char) => char >= 0x1F600 && char <= 0x1F64F,
// 'Ornamental Dingbats': (char) => char >= 0x1F650 && char <= 0x1F67F,
// 'Transport and Map Symbols': (char) => char >= 0x1F680 && char <= 0x1F6FF,
// 'Alchemical Symbols': (char) => char >= 0x1F700 && char <= 0x1F77F,
// 'Geometric Shapes Extended': (char) => char >= 0x1F780 && char <= 0x1F7FF,
'Miscellaneous Symbols and Pictographs': (char) => char >= 0x1F300 && char <= 0x1F5FF,
'Emoticons': (char) => char >= 0x1F600 && char <= 0x1F64F,
'Ornamental Dingbats': (char) => char >= 0x1F650 && char <= 0x1F67F,
'Transport and Map Symbols': (char) => char >= 0x1F680 && char <= 0x1F6FF,
'Alchemical Symbols': (char) => char >= 0x1F700 && char <= 0x1F77F,
'Geometric Shapes Extended': (char) => char >= 0x1F780 && char <= 0x1F7FF,
// 'Supplemental Arrows-C': (char) => char >= 0x1F800 && char <= 0x1F8FF,
// 'Supplemental Symbols and Pictographs': (char) => char >= 0x1F900 && char <= 0x1F9FF,
// 'Chess Symbols': (char) => char >= 0x1FA00 && char <= 0x1FA6F,
// 'Symbols and Pictographs Extended-A': (char) => char >= 0x1FA70 && char <= 0x1FAFF,
'Supplemental Symbols and Pictographs': (char) => char >= 0x1F900 && char <= 0x1F9FF,
'Chess Symbols': (char) => char >= 0x1FA00 && char <= 0x1FA6F,
'Symbols and Pictographs Extended-A': (char) => char >= 0x1FA70 && char <= 0x1FAFF,
// 'Symbols for Legacy Computing': (char) => char >= 0x1FB00 && char <= 0x1FBFF,
// 'CJK Unified Ideographs Extension B': (char) => char >= 0x20000 && char <= 0x2A6DF,
// 'CJK Unified Ideographs Extension C': (char) => char >= 0x2A700 && char <= 0x2B73F,
Expand All @@ -340,6 +340,6 @@ export const unicodeBlockLookup: UnicodeBlockLookup = {
// 'CJK Compatibility Ideographs Supplement': (char) => char >= 0x2F800 && char <= 0x2FA1F,
// 'Tags': (char) => char >= 0xE0000 && char <= 0xE007F,
// 'Variation Selectors Supplement': (char) => char >= 0xE0100 && char <= 0xE01EF,
// 'Supplementary Private Use Area-A': (char) => char >= 0xF0000 && char <= 0xFFFFF,
// 'Supplementary Private Use Area-B': (char) => char >= 0x100000 && char <= 0x10FFFF,
'Supplementary Private Use Area-A': (char) => char >= 0xF0000 && char <= 0xFFFFF,
'Supplementary Private Use Area-B': (char) => char >= 0x100000 && char <= 0x10FFFF
};
Loading

0 comments on commit a440cb6

Please sign in to comment.