Skip to content

Fix Windows OCR word order for RTL languages#20537

Open
islambenmebarekdz-collab wants to merge 1 commit into
nvaccess:masterfrom
islambenmebarekdz-collab:fix/windows-ocr-rtl-word-order
Open

Fix Windows OCR word order for RTL languages#20537
islambenmebarekdz-collab wants to merge 1 commit into
nvaccess:masterfrom
islambenmebarekdz-collab:fix/windows-ocr-rtl-word-order

Conversation

@islambenmebarekdz-collab

Copy link
Copy Markdown

Link to issue number:

Fixes #20475

Summary of the issue:

Windows OCR returns words in left-to-right coordinate order even when the recognizer language is right-to-left. As a result, NVDA speaks and navigates Arabic and Hebrew OCR results with the word order reversed.

Description of user facing changes:

Windows OCR results for right-to-left languages are now spoken and navigated in reading order. Embedded left-to-right runs, such as an English phrase within an Arabic sentence, retain their internal order.

Description of developer facing changes:

The Windows OCR bridge now determines the layout direction from OcrEngine.RecognizerLanguage. It sorts recognized words from right to left for RTL languages and restores the logical order of contiguous LTR word runs. A Universal API contract check preserves compatibility with Windows versions predating Language.LayoutDirection, falling back to the Arabic and Hebrew script identifiers.

Description of development approach:

Each OCR line is copied to a vector before serialization. For an RTL recognizer language, the vector is stably sorted by descending horizontal coordinate. Windows character-type information is then used to identify and reverse contiguous LTR runs within the reordered line.

Testing strategy:

  • Reproduced with installed NVDA 2026.1.1 and Windows OCR ar-SA: مرحبا بكم في عالم البرمجة was returned as البرمجة عالم في بكم مرحبا.
  • Built the full source target successfully with warnings treated as errors, including x64, ARM64, and ARM64EC OCR helpers.
  • Tested the patched x64 helper end to end with real Windows OCR:
    • Arabic: مرحبا بكم في عالم البرمجة retained the expected reading order.
    • English: Welcome to the world of programming remained unchanged.
    • Mixed RTL/LTR: مرحبا good morning جميعا retained both the RTL sentence order and the internal order of the English phrase.
  • Ran the 29 existing contentRecog unit tests successfully.
  • Ran runlint.bat and runcheckpot.bat successfully.

Known issues with pull request:

None known. An automated test was not added because the ordering is implemented in the native WinRT OCR bridge and depends on real OCR output; it was covered with manual end-to-end tests against the built DLL.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation (not required beyond the change log)
    • Developer / Technical Documentation (not required; no developer API change)
    • Context sensitive help for GUI changes (not applicable)
  • Testing:
    • Unit tests (existing contentRecog suite)
    • System (end to end) tests (real Windows OCR helper)
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers (not applicable)
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@islambenmebarekdz-collab
islambenmebarekdz-collab marked this pull request as ready for review July 21, 2026 08:18
@islambenmebarekdz-collab
islambenmebarekdz-collab requested a review from a team as a code owner July 21, 2026 08:18
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.

Windows OCR reads RTL text (Arabic/Hebrew) in reverse order (LTR). Proposed algorithmic fix.

1 participant