fix(textkit): preserve run attributes during bidi reordering#3303
Open
matangot wants to merge 1 commit intodiegomura:masterfrom
Open
fix(textkit): preserve run attributes during bidi reordering#3303matangot wants to merge 1 commit intodiegomura:masterfrom
matangot wants to merge 1 commit intodiegomura:masterfrom
Conversation
The previous bidiReordering implementation shuffled individual glyphs across run boundaries using character-level index remapping. This caused run attributes (color, font-weight, font-style, etc.) to be lost when rendering RTL text with nested styled <Text> elements. For example, `<Text dir='rtl'>עברית <Text color='red'>קשה</Text> שפה</Text>` would render with all text in the default color because glyphs from the red-styled run were moved into the default-styled run. The fix replaces character-level glyph shuffling with run-level reordering: 1. Apply UAX diegomura#9 L2 algorithm at the run level to determine visual run order (instead of character-level index remapping) 2. Reverse glyphs/positions within RTL runs (odd bidiLevel) 3. Preserve all run attributes intact since glyphs never cross run boundaries This also removes the dependency on bidi-js in bidiReordering.ts (the bidi engine for computing embedding levels still uses it separately in engines/bidi.ts). Fixes diegomura#2900
|
|
Tested your fix and it resolved the issue for us in Arabic text renders. Thanks for digging into this, a release including it would be very useful. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2900
The
bidiReorderingimplementation shuffled individual glyphs across run boundaries using character-level index remapping (getItemAtIndex). This caused run attributes (color, font-weight, font-style, links, etc.) to be lost when rendering RTL text with nested styled<Text>elements.Before (broken):
Glyphs from the red-styled run were remapped into the default-styled run, losing the red color. Bold, italic, and links were similarly corrupted.
Root cause:
reorderLine()usedindices.slice(run.start, run.end)to get reordered character positions, thengetItemAtIndex()fetched glyphs from other runs at those positions. The fetched glyphs were placed back into the current run — stripping the original run's attributes.Fix: Replace character-level glyph shuffling with run-level reordering:
bidiLevel)This also removes the
bidi-jsdependency frombidiReordering.ts(the bidi engine for computing embedding levels still uses it inengines/bidi.ts).Test plan
colorattribute after reordering