-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Correct URL area with rotated texts in PDFs #23288
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
Correct URL area with rotated texts in PDFs #23288
Conversation
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping @matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
Fixed errors thrown by flake8
I believe that there are a few issues here, although it is on the right track:
I suggest explicitly computing the additional locations a to f as in #23205 and use those to determine the rest. (Also, there should ideally be some sort of test although I can honestly not come up with anything reasonable...) |
Created a new function that calculates the vertices of the rectangle rotated around x,y by angle. Changed spelling of _get_coordinated_from_angle
A rectangle that surrounds the URL text is calculated
I believe I've fixed points 1 & 4 and the last point about computing a-f. Not sure if I've implemented the QuadPoints correctly. |
Realised a mistake in my equations
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Corrected variable name
I am not sure how one can test this easily, but it would be great if you could manually run it and see if the clickable area ends up where it is expected (and that the PDF viewer does not complain etc). The example code in the original issue should be a simple example. |
Would you mind telling how to import the module I've made? Tried copying the |
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Changed spelling in comment
It depends on how you did install Matplotlib. If you installed from source in edit mode ( If not, it probably still should work in general, but errors like this may happen. (I edit in Spyder and there I need to start two new shells before I get the update, but the error you get is maybe not like that.) Sometimes it may be easier just to copy the relevant parts into an existing install since there may be other things that have changed in the file that are not compatible with your installed version. I can try to fetch it and try it out, probably tomorrow evening, if you do not succeed. |
I realized that there are some tests for embedding URL already: matplotlib/lib/matplotlib/tests/test_backend_pdf.py Lines 224 to 272 in 047254d
Basically one could just copy those, but rotate the text. Then one can list the expected rect and quadpoints and test against those. |
I took the liberty to change the title and replace the word "solves" with "closes" in the description. In that way #23205 will automatically be closed when this is merged. (You can see on the right hand side under Development that it is now linked.) |
baebd65
to
a99c3ec
Compare
I tested it manually and it didn't really work. Hence, I submitted a PR to your branch, see eindH#1 There is an inconsistency in the PDF specification and every viewer I have tested. The specs says that QuadPoints should be ignored if any point lies outside of Rect. However, if any point in QuadPoints is on the border of Rect it will be ignored. Here are two files. link_nogap.pdf has the boundaries of the QuadPoints as Rect, link.pdf extends the boundaries 0.00001 (as we print with five decimal digits), so 0.00072 points wider than theoretical... With the new change, this only happens when the rectangle is rotated something other than an integer multiple of 90. |
URL rotation fixes
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Thanks for those changes. Is there anything that needs doing to raise it for review? |
I think this is good to go now. Just a friendly reminder to whoever merges this to squash the commits in to a single one. (Maybe we should also ask for a third approval since I feel sort of directly involved in the code...) |
I squash merged this in case anyone was keeping track of individual commits... |
PR Summary
This ticket closes #23205
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).