fix: render real-size partial images at the document-to-pixel scale - #702
Merged
espresso3389 merged 1 commit intoSep 2, 2026
Conversation
`_requestRealSizePartialImage` was called with `pageScale`, which is `scale * (pageRect.size / page.size)`. Inside `_createRealSizePartialImage` that value is used as a document-to-pixel factor again (`fullWidth: pageRect.width * scale`), so the layout ratio is counted twice. With the default layouts the ratio is 1 and the two are identical, so nothing changes. With a custom `layoutPages` that lays pages out at a size other than their natural one, the high-resolution partial image is rendered at `ratio` times the resolution the viewer actually needs, and the page stays blurry no matter how far the user zooms in. Pass `scale` instead: it is the document-to-physical-pixel factor the partial renderer expects. The `pageScale > previewScaleLimit` threshold keeps using `pageScale`, which is correct there -- it compares a page-points-to-pixels density against the preview render scale.
palmoni5
force-pushed
the
fix-partial-render-scale-custom-layout
branch
from
August 30, 2026 09:31
7ef4c93 to
2379b99
Compare
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.
Problem
A custom
layoutPagesthat does not lay pages out at their natural point size gets a permanently blurry page when the user zooms in — the high-resolution partial render never reaches the resolution the viewer is actually displaying, and zooming further does not help.Cause
In
_paintPagesCustom:scaleis_currentZoom * devicePixelRatio— the document-units-to-physical-pixels factor.pageScalemultiplies it by the layout ratior = pageRect.size / page.size, which is the right quantity for thepreviewScaleLimitcomparison, becausepreviewScaleLimitis a page-points-to-pixels density (the preview is rendered aspage.width * previewScaleLimit).But
_createRealSizePartialImagethen uses the value it receives as a document-to-pixel factor again:So
ris counted twice:With the built-in layouts
r == 1, so the two are equal and nothing is wrong — which is why this only shows up with a customlayoutPages. Withr = 0.5(a two-page book-style spread laid out at half size, which is how I hit this) the partial image is rendered at half the required resolution and is upscaled 2x on screen. The error is proportional, so it never improves with more zoom.Fix
Pass
scalerather thanpageScaleto_requestRealSizePartialImage. The threshold comparison keeps usingpageScale, which is correct there.This is a no-op for every layout with
r == 1, i.e. all built-in layouts.Testing
To be explicit about what I have and have not checked: the analysis above is derived from reading the code, and I have not yet run a visual before/after in a built app. What I can state is that the change is provably a no-op wherever
r == 1(pageScaleandscaleare equal there by definition), which covers every built-in layout, so the risk to existing users is nil.Happy to add a regression test if you can point me at where you would want it — the value is computed inside a private paint method, so I did not see an obvious seam in
packages/pdfrx/test.