Skip to content
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

ROB: Cope with utf16 character for space calculation #1155

Merged
merged 2 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion PyPDF2/_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def build_char_map(
pass
# I conside the space_code is available on one byte
if isinstance(space_code, str):
sp = space_code.encode("charmap")[0]
try: # one byte
sp = space_code.encode("charmap")[0]
except Exception:
sp = space_code.encode("utf-16-be")
sp = sp[0] + 256 * sp[1]
else:
sp = space_code
sp_width = compute_space_width(ft, sp, space_width)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def test_rotate_45():
(True, "https://arxiv.org/pdf/2201.00200.pdf", [0, 1, 5, 6]),
(True, "https://arxiv.org/pdf/2201.00022.pdf", [0, 1, 5, 10]),
(True, "https://arxiv.org/pdf/2201.00029.pdf", [0, 1, 6, 10]),
# #1145
(True, "https://github.com/py-pdf/PyPDF2/files/9174594/2017.pdf", [0]),
# 6 instead of 5: as there is an issue in page 5 (missing objects)
# and too complex to handle the warning without hiding real regressions
(True, "https://arxiv.org/pdf/1601.03642.pdf", [0, 1, 5, 7]),
Expand Down