-
Notifications
You must be signed in to change notification settings - Fork 9.4k
AtlasEngine: Enable RTL text shaping via bidi analysis (#20156) #20159
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
Open
Qmoony
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
Qmoony:fix/arabic-rtl-text-shaping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The block above is some nice reference code to have! Thank you for working on it!
We should probably think about unifying it with the existing logic, however.
BTW judging by the lack of {} around conditions, I bet it was done by Claude though, right? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed review and the architecture outline!
You're right on both counts:
זאת בדיקה.test before pushing though.
Your proposed refactoring makes sense — accumulate line state first, then
split/merge runs, then glyph placement last. That would also fix the mixed-direction
span case naturally.
I see two paths forward:
iterate on the full refactor in a follow-up.
reversal code here as reference.
I'm leaning toward Option A since it already improves the common case (pure RTL
text without mixed formatting), but I'll defer to your preference on this.
Happy to take this to a discussion issue first if you'd rather align on the design
up front.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude is bad at implicit research, e.g. checking for existing code styles, if you don't tell it to. That's perhaps also why today's system prompts are like 10000 lines long. "Alignment" my 🍑. lol
Jokes aside, I'd prefer option B, because we (the maintainers) are always pressed on time. If we don't do it right now, we won't ever have any incentive to fix it later. So, if we care to make it good, we have to make it good from the get go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with B — pushed 13f06b9. The pipeline now does
analysis → split runs:AnalyzeScript+AnalyzeBidirun once on the whole buffer line in_flushBufferLine_mapRegularTextclamps font fallback andGetTextComplexityat script/bidi boundaries via a new_nextAnalysisBoundaryhelper, so every range entering_mapComplexis guaranteed uniform in direction and script_mapComplexdropped its inlineAnalyzeBidi/AnalyzeScriptcalls, the per-script-run loop, and the "mixed → LTR" fallback (structurally impossible now)Verified locally:
זאת בדיקה(the Hebrew + space case @Avid29 reported)Hello זאת/abc العربية xyz(mixed LTR+RTL on one line)بسم الله الرحمن الرحيم(multi-word Arabic, per-word cursive joining intact)No visible regressions in ASCII, CJK, emoji, combining marks, ligatures, or built-in box-drawing glyphs.
Still out of scope:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lhecker — gentle nudge on this one. 🙂
The Option B refactor you asked for (analysis-authoritative segmentation: accumulate the line, run AnalyzeScript/AnalyzeBidi once in _flushBufferLine, clamp font-fallback and GetTextComplexity at script+bidi boundaries, drop the per-script-run loop and the "mixed → LTR" fallback) was pushed and is described in detail in this thread. It resolves the זאת בדיקה space / mixed-direction case @Avid29 reported — verified locally against Hebrew+space, mixed LTR/RTL on one line, and multi-word Arabic, with no regressions in ASCII / CJK / emoji / combining marks / ligatures / box-drawing.
One note on the recent force-push (13f06b9 → 25aa9c7): it only stripped a commit-message trailer — the tree is byte-identical (git range-diff confirms a message-only change), so the local validation above still holds and nothing in the code changed since your last look.