Improve PDF.js zoom functionality; add configurability#1518
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@demiankatz from a quick read this looks good overall and I like that it's configurable now. From testing zooming in and out seems to work fine, as I'm not sure exactly what the calculations in |
There's probably a much more mathematically intelligent way to handle the zooming than what we're currently doing, but geometry is not my strength, so I basically just extended the existing algorithm in a way that retains existing behavior while extending past its existing limitations. Previously, the code just added or subtracted 0.5 to the zoom factor, which meant that you couldn't zoom at a finer grain once you hit 0.5. I extended that by multiplying by 1.5 once we're in those smaller numbers, which provides a theoretically less limited zoom capability. It's all still based on arbitrary magic numbers, though! I'd love to do better, but I'm probably not the best person to develop a replacement algorithm. Hopefully I've rearranged the code so that it's easier to drop one in now, though. :-) |
|
I tested this PR via the Vercel viewer. Big improvement! The test branch allows for a much better zooming experience. In dev, the image is too large to fit on the screen unless you're in full screen mode. In the test branch, the zoom options span the full range from the whole image being teeny tiny to a comfortable viewing size to gigantic, all at either normal browser widths or at full screen. It's useful for the reader to have this range of options. The only thing I'd ask for is a button next to the + and - to reset to the default (or to a size that fills the screen). Thanks for your work on this! It will make the UV much more friendly for users of PDFs. |
|
Thanks, @sturkel89 and @Geoffsc. I agree that a reset button would be helpful, but I think that goes along with revising the zooming algorithm to have a better starting point and more logical progression, which is beyond what I currently have time to do. I'll merge this as-is since I think it's a significant improvement, and we can do further work in a follow-up as time permits and need dictates. |
There were several problems with PDF.js zoom functionality:
This PR fixes the issues:
I'm sure there is room for further improvement, especially in terms of the algorithm for zooming, but at least this code centralizes everything into support methods that can be more easily customized and changed in future.
Here is a good manifest for testing purposes:
https://digital.library.villanova.edu/Item/vudl:189057/Manifest
This contains a very large PDF -- you can't zoom out far enough to see the whole thing on screen at once with the default settings, but if you adjust the new config parameters, you can view it more comfortably.