Repository navigation
PDF reader: right-to-left brackets, presentation forms and text drawn forward - #1129
Merged
Merged
Conversation
… forward
Reading Arabic, Persian and Hebrew PDFs into TXT, Markdown, DOCX and the other
text routes, which all share PdfDocumentReader:
- Punctuation at the edges of a number or a Latin run in right-to-left text goes
to the side the text around it puts it on: "(3)" no longer comes out as ")3".
Numbers alone no longer form a run ("10, 20" stays in its order), and a bracket
drawn mirrored ends a Latin run.
- Brackets that only pair up the other way round are turned around, for PDFs
whose ToUnicode entries name the glyph drawn rather than the character.
- Arabic and Hebrew presentation forms become letters, ligatures included.
- A page that draws such text left to right in reading order (no right-to-left
layout, like rhwp) is no longer read backwards: words that start with a letter
that only ends words, and common words backwards, tell it apart.
- The parts of a tabbed right-to-left row read from the right.
Refs #979
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Refs #979
All PDF text routes (TXT, Markdown, DOCX, HWPX, slides, tables) read through
PdfDocumentReader, so these fixes apply to all of them.Bugs fixed
(النسخة 3)came out as(النسخة )3. Punctuation at the edges of a number or Latin run belongs to the text around the run, so it is drawn on the far side. It now goes back to the side it is read on:)1(→(1),.2024→2024., also over several Latin words. A sign that belongs to a number stays with it (50%). Two numbers no longer form a run, so10, 20keeps its order. This matches bidi rules N0 and N1.)text(. Brackets that only pair up the other way round are turned around.ﻻ,ﺔ) become letters.البطولةfrom left to right, and reading it from the right gaveةلوطبلا. The words now tell: on a page where more words start with a letter that only ends words (ة, ى, Hebrew final forms) or are common words backwards than fit the normal reading, the page is read from the left. Pages drawn visually keep their reading. A short page with no such evidence stays as it was, for example the single wordریال.Not reproduced
The issue's own PDF isn't attached, and its screenshot shows a visually correct PDF. PDFs that I could produce and read here were Chrome (Skia) and LibreOffice 26.2.6. Both already read in the right letter order on
main; only the brackets were wrong. So I can't say this fixes the reporter's reversed letters, which is why this isRefs. The reader will flip a page whose words come out backwards, whatever made them so.The route to PowerPoint → PDF is in a separate PR.
How this was checked
ComplexScriptTests: new tests with real Arabic, Persian and Hebrew strings, written glyph by glyph as the shaping engines leave them. 11 of them fail onmain. Also PDF → DOCX.No new dependency. .NET has no public bidi API and SkiaSharp/HarfBuzz only shape, so this uses the reader's existing word and cluster ordering.
🤖 Generated with Claude Code