-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ENH: Add ActualText tag when we produce RTL appearance stream #3901
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
0948f56
9331528
bd898fa
810f112
2f786a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,8 @@ def test_scale_text(): | |
|
|
||
| layout.rectangle = (0, 0, 160, 360) | ||
| font_size = 0.0 | ||
| text = """Welcome to pypdf | ||
| text = """Welcome to pypdf! | ||
| أهلاً بكم في pypdf! | ||
| pypdf is a free and open source pure-python PDF library capable of splitting, merging, cropping, and | ||
| transforming the pages of PDF files. It can also add custom data, viewing options, and passwords to PDF | ||
| files. pypdf can retrieve text and metadata from PDFs as well. | ||
|
|
@@ -79,12 +80,13 @@ def test_scale_text(): | |
| ) | ||
| assert b"12 Tf" in appearance_stream.get_data() | ||
| assert b"pypdf is a free and open" in appearance_stream.get_data() | ||
| assert b"/Span << /ActualText" in appearance_stream.get_data() | ||
|
|
||
| layout.rectangle = (0, 0, 160, 160) | ||
| appearance_stream = TextStreamAppearance( | ||
| 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() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this change? Isn't the change about new dictionary elements only, and not about the content stream operators itself?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
|
|
||
| layout.rectangle = (0, 0, 160, 12) | ||
| appearance_stream = TextStreamAppearance( | ||
|
|
@@ -142,7 +144,12 @@ def test_appearance_stream_rtl(): | |
| font_color="0 g", | ||
| is_multiline=False | ||
| ) | ||
| hex_glyphs_rtl_enabled = re.findall("<(.+?)>", appearance.get_data().decode())[0] | ||
| # The regex returns two groups. The first matches the text in /Span << /ActualText <[group 0]> >> BDC | ||
| # The second matches the encoded text data. | ||
| decoded_data = re.findall("<([a-zA-Z0-9]+?)> ", appearance.get_data().decode()) | ||
| actual_text = bytes.fromhex(decoded_data[0]).decode("utf-16-be") | ||
| assert actual_text == "\ufeff" + test_string | ||
| hex_glyphs_rtl_enabled = decoded_data[1] | ||
| assert hex_shaped_test_glyphs == hex_glyphs_rtl_enabled | ||
|
|
||
| # RTL support disabled | ||
|
|
@@ -157,7 +164,7 @@ def test_appearance_stream_rtl(): | |
| font_color="0 g", | ||
| is_multiline=False | ||
| ) | ||
| hex_glyphs_rtl_disabled = re.findall("<(.+?)>", appearance.get_data().decode())[0] | ||
| hex_glyphs_rtl_disabled = re.findall("<(.+?)>", appearance.get_data().decode())[1] | ||
|
PJBrs marked this conversation as resolved.
Outdated
|
||
| assert hex_unshaped_test_glyphs == hex_glyphs_rtl_disabled | ||
| # The hex glyph sequences should be different when RTL support is enabled vs disabled | ||
| assert hex_glyphs_rtl_enabled != hex_glyphs_rtl_disabled | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.