Skip to content
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

Improve viewer resolution #64

Merged
merged 9 commits into from
Aug 16, 2024
Merged

Improve viewer resolution #64

merged 9 commits into from
Aug 16, 2024

Conversation

lfoppiano
Copy link
Owner

@lfoppiano lfoppiano commented Aug 14, 2024

This PR attempts to improve the PDF resolution in the viewer, that, even if we are following the solution found in many places, it's not satisfying.

We introduced a variable called resolution_boost that apply a boost on how the resolution is calculated. The value goes from 2 to 10, with default to 1.
The canvas of the PDF pages is built by getting the Viewport (unscaled) and calculating the scaling ratio by dividing the expected width and the actual viewport width.

When the canvas is created, we use the scaled viewport dimensions and we multiply by a ratio value due to the density of pixels of the device (given by window.devicePixelRatio), in the current version, this value is either 1 or 2 (retina displays).

However, the quality of the PDF shown still is not optimal.
So we added a boost ratio that will be a multiplied for the calculated ratio:

      const ratio = (window.devicePixelRatio || 1) * resolutionRatioBoost

this approach, gave acceptable results in our experiments. Nevertheless, we did not find any explanation and it might be used incorrectly.

image

Higher ratio is definitely more resource-demanding on the browser, so use carefully, and, at your own risk :-)

@lfoppiano lfoppiano requested a review from t29mato August 14, 2024 19:59
@lfoppiano lfoppiano added enhancement New feature or request frontend Part related to the Javascript frontend component labels Aug 14, 2024
@lfoppiano lfoppiano marked this pull request as ready for review August 14, 2024 20:00
@lfoppiano lfoppiano merged commit 0541f60 into main Aug 16, 2024
12 of 14 checks passed
@lfoppiano lfoppiano deleted the improve-viewer-resolution branch August 16, 2024 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request frontend Part related to the Javascript frontend component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant