-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
BUG: Handle indirect objects in font width calculations #2967
BUG: Handle indirect objects in font width calculations #2967
Conversation
Thanks for the report and PR. Could you please add a corresponding test as well? Regarding your other remark:
Feel free to fix this name. There should be no API implications of doing so due to being internal anyway. |
Good point. I'll spend some time familiarising myself with the tests in the repo over the next couple of days and update the PR.
Will do. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2967 +/- ##
=======================================
Coverage 96.36% 96.36%
=======================================
Files 52 52
Lines 8746 8747 +1
Branches 1590 1591 +1
=======================================
+ Hits 8428 8429 +1
Misses 190 190
Partials 128 128 ☔ View full report in Codecov by Sentry. |
Mmh, the exact issue reported in #2966 apparently is not covered by the tests. Shouldn't it reproduce it and thus find the |
That's what should happen - and the code coverage shows that that is happening, except for one edge case (see below). I also confirmed that the test reproduces the problem by reverting _cmap.py to the version on main, and the test failed with the exception I reported in #2966. Re the edge case: I added three checks against Hope that makes sense, but let me know if I'm wrong about the possibility of |
Skimming through the code, the only place where if "/DW" in ft1:
font_width_map["default"] = cast(float, ft1["/DW"].get_object())
else:
font_width_map["default"] = default_font_width Please note that I have not tested this myself, but IMHO |
Thanks for the extra insight. Happy to revert the not covered line. Indeed, by pointing at Another thing I noticed looking at Since raising the bug report and opening the PR, I've since seen #2286, so a variant of this problem has been seen and fixed before; so it looks like a recent regression. But, nonetheless, it seems challenging to provoke PDF libraries to create files that cover all code paths through that function. I'm therefore going to change only the code path(s) that I can see encounter an |
Unresolved About the regression part, I am not sure - this would require verification with older pypdf versions. It might just be one of the aforementioned cases we never had test coverage for (despite the corresponding line possibly be marked as covered for other reasons). |
Makes sense. I've compromised slightly on my previous stance of only adding checks for |
Thanks. I have committed some further simplifications of the code and will probably merge it later on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the report and fix.
Thanks for your patience as I learned about PDF document internal structure and the library implementation. |
Closes #2966
This handles indirect objects when calculating font widths