ENH: Add ActualText tag when we produce RTL appearance stream#3901
ENH: Add ActualText tag when we produce RTL appearance stream#3901PJBrs wants to merge 5 commits into
Conversation
This patch passes both the encoded and unencoded text to the code that produces the actual appearance stream data. Also fix silly comment typo
When copying text from a PDF, it will return the characters in the order that they are encoded. Withe RTL text, this actually is in reverse. Add /ActualText to enable copying text in the correct direction.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3901 +/- ##
=======================================
Coverage 97.86% 97.87%
=======================================
Files 57 57
Lines 10738 10755 +17
Branches 2006 2010 +4
=======================================
+ Hits 10509 10526 +17
Misses 127 127
Partials 102 102 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stefan6419846
left a comment
There was a problem hiding this comment.
I have left some direct remarks.
Please note that it might take a few weeks for me to do a follow-up review as per the pinned issue.
| layout=layout, text=text, font_size=font_size, is_multiline=is_multiline | ||
| ) | ||
| assert b"9.8 Tf" in appearance_stream.get_data() | ||
| assert b"9.6 Tf" in appearance_stream.get_data() |
There was a problem hiding this comment.
Why does this change? Isn't the change about new dictionary elements only, and not about the content stream operators itself?
There was a problem hiding this comment.
I added one line of bidi text to increase test coverage here. Since the test is mainly intended to assert that text scaling works properly, and since I added a line, the font size has decreased as a side effect. Hence this change.
This patch introduces and uses a named tuple for the combination of an unscaled word width, the word itself and the glyphs that encode that word with the current font.
Thanks, I think I addressed all your points.
Have a good time! |
Copying text from a PDF copies text in the order that it is encoded in the PDF. For RTL text, this means that the copied text is in reverse. To remedy that problem, this PR tags such text with /Span /ActualText, which overrides text copying to the direction and encoding in which the text was originally added.
I note that #3514 was just closed. Perhaps this PR should be seen as the epilogue to that closure ;-)
This was assisted by Google Gemini, especially the code that produces that Span in AppearanceStream. But lightly!