Skip to content

Commit

Permalink
fixup! Render high-res partial page views when falling back to CSS zoom
Browse files Browse the repository at this point in the history
Make sure that the `#detailArea` is not used from a previous computation
with a different scale.

The `#detailArea` can become out of date when very quickly alternating
between scrolling and zooming. This causes the canvas to be too big,
even if then the rendered contents have the right scale.

This commit:
1. changes `#shouldRenderDifferentArea` so that, whenever the scale
   changes, it forces re-computing what is the size of the new canvas
   to render.
2. making sure to trash the detail area of pages that are not visible
   anymore, so that we don't risk trying to render it before calling
   update().
  • Loading branch information
nicolo-ribaudo committed Jan 22, 2025
1 parent b3f0b52 commit f6ed873
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 11 additions & 3 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,13 +1369,21 @@ class PDFPageDetailView extends PDFPageViewBase {
return true;
}

const {
width: maxWidth,
height: maxHeight,
scale,
} = this.pageView.viewport;

if (this.#detailArea.scale !== scale) {
return true;
}

const paddingLeftSize = visibleArea.minX - minDetailX;
const paddingRightSize = maxDetailX - visibleArea.maxX;
const paddingTopSize = visibleArea.minY - minDetailY;
const paddingBottomSize = maxDetailY - visibleArea.maxY;

const { width: maxWidth, height: maxHeight } = this.pageView.viewport;

// If the user is moving in any direction such that the remaining area
// rendered outside of the screen is less than MOVEMENT_TRESHOLD of the
// padding we render on each side, trigger a re-render. This is so that if
Expand Down Expand Up @@ -1449,7 +1457,7 @@ class PDFPageDetailView extends PDFPageViewBase {
const width = maxX - minX;
const height = maxY - minY;

this.#detailArea = { minX, minY, width, height };
this.#detailArea = { minX, minY, width, height, scale: viewport.scale };

this.reset({ keepCanvas: true });
}
Expand Down
7 changes: 7 additions & 0 deletions web/pdf_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1682,8 +1682,15 @@ class PDFViewer {
const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
this.#buffer.resize(newCacheSize, visible.ids);

const visiblePagesSet = new Set();
for (const { view, visibleArea } of visiblePages) {
view.updateVisibleArea(visibleArea);
visiblePagesSet.add(view);
}
for (const view of this._pages) {
if (!visiblePagesSet.has(view)) {
view.updateVisibleArea(null);
}
}

this.renderingQueue.renderHighestPriority(visible);
Expand Down

0 comments on commit f6ed873

Please sign in to comment.