Zooom / Pan and smooth scroll support for PDFs#51
Open
r-menezes wants to merge 3 commits into
Open
Conversation
Before, the viewport was always fixed to the top-left of the rendered
bitmap. This commit adds full pan and scroll support by using modifing
the Kitty place command.
Core rendering fix (display_page):
- Track pan_x/pan_y (center of viewport in PDF points) on Document;
- Compute img_off_x/img_off_y (pixel crop offsets into the bitmap) and
visible_w/visible_h (clipped display dimensions) from the pan
position
- Pass x/y/w/h/c/r to the Kitty place command so the terminal crops
the
stored bitmap to the visible region instead of always showing pixel
(0,0)
- Guard swallow_keys() behind was_stale so the 100ms input drain only
fires after a slow full pixmap transfer, not after a cheap pan
update (this also makes navigating the PDF faster when it is loaded)
Navigation (view loop):
- j/k/h/l pan the viewport when zoomed; crossing the page boundary
triggers a page change and carries the overflow distance forward,
giving continuous scroll across pages
- J/K always change page (no pan), L/H always change chapter
- Pan step is time-proportional (elapsed * 10 normalised to 100 ms
baseline) when no explicit count prefix is given, so scroll velocity
stays constant regardless of render frame rate
- W (zoom reset) also clears pan_x/pan_y to re-center the page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This seems easily to be one of the most developed solutions to read PDFs in the terminal. But I was missing the ability to zoom in, so I tried to implement something rough myself.
Disclaimer: It was written with the assistance of Claude/Gemini, but I reviewed the entire code.
How it works:
Pressing
+now zooms in the PDF, and hjkl pans the zoomed PDF around. When you find the top/end of a page while moving up/down, it naturally loads and moves to the bottom/top of the previous/following page.To improve the FPS, there is some logic to allow faster updates if there is not an expensive operation going on.
This was made possible by slightly changing the Kitty protocol command to include additional info of pixel offsets and crop dimensions.
Key bindings summary
+/-Wj/kh/lJ/KL/H