Skip to content

fix(text): render Devanagari and other complex scripts correctly#8895

Open
willeastcott wants to merge 1 commit into
mainfrom
fix/devanagari-grapheme-clustering
Open

fix(text): render Devanagari and other complex scripts correctly#8895
willeastcott wants to merge 1 commit into
mainfrom
fix/devanagari-grapheme-clustering

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Fixes #4102.

string.getSymbols split Devanagari into one symbol per code point, so vowel signs (matras) detached from their consonant and conjuncts never formed — text rendered garbled and out of order as reported.

getSymbols now forms proper grapheme clusters: a base character plus its trailing combining marks (\p{M}), ZWJ/ZWNJ joiners and virama-joined consonants. Because CanvasFont rasterizes each symbol with the browser's text shaper, whole syllables now shape into a single correctly-composed glyph (Devanagari, plus Arabic, Tamil, etc.).

Bitmap/MSDF fonts have per-code-point atlases that don't contain a multi-code-point cluster, so TextElement expands any font-missing cluster back into its code points — they render exactly as before.

Tested: added getSymbols unit tests for Devanagari vowel signs and conjuncts; existing emoji/flag/ZWJ cases are unchanged; verified end-to-end that a real CanvasFont atlas now contains correctly-shaped Hindi clusters.

🤖 Generated with Claude Code

getSymbols now keeps a base character together with its trailing combining
marks, ZWJ/ZWNJ joiners and virama-joined consonants as a single grapheme
cluster. This lets CanvasFont shape whole syllables via the browser's text
shaper, instead of laying out each code point as a separate glyph. Fonts
with per-code-point atlases (bitmap/MSDF) expand any missing cluster back to
its code points, so they render as before.

Fixes #4102

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hindi text does not render correctly

1 participant