Skip to content

Commit 79b6892

Browse files
committed
Ensure that pre-rendering works correctly with spreadModes at higher zoom levels
Having recently worked with this code, in PR 14096 (and indirectly in PR 14112), I happened to notice a pre-existing issue with spreadModes at higher zoom levels. The `PDFRenderingQueue` code was written back when the viewer only supported "normal" vertical scrolling, and some edge-cases related to spreadModes are thus not perfectly supported. Depending on the zoom level, it's possible that there are "holes" in the currently visible page layout, and those pages will not be pre-rendered as you'd expect. *Steps to reproduce:* 0. Open the viewer, e.g. https://mozilla.github.io/pdf.js/web/viewer.html 1. Enable vertical scrolling. 2. Enable the ODD spreadMode. 3. Scroll down, such that both pages 1 and 3 are visible. 4. Zoom-in until *only* page 1 and 3 are visible. 5. Open the devtools and, using the DOM Inspector, notice how page 2 is *not* being pre-rendered despite all surrounding pages being rendered.
1 parent f6d9d91 commit 79b6892

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

web/pdf_rendering_queue.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,30 @@ class PDFRenderingQueue {
126126
return view;
127127
}
128128
}
129+
const firstId = visible.first.id,
130+
lastId = visible.last.id;
131+
132+
// All the visible views have rendered; try to handle any "holes" in the
133+
// page layout (can happen e.g. with spreadModes at higher zoom levels).
134+
if (lastId - firstId > 1) {
135+
const holeIds = new Set();
136+
for (let i = 0, ii = lastId - firstId; i <= ii; i++) {
137+
holeIds.add(scrolledDown ? firstId + i : lastId - i);
138+
}
139+
for (let i = 0; i < numVisible; i++) {
140+
holeIds.delete(visibleViews[i].id);
141+
}
142+
for (const id of holeIds) {
143+
const holeView = views[id - 1];
144+
if (holeView && !this.isViewFinished(holeView)) {
145+
return holeView;
146+
}
147+
}
148+
}
129149

130150
// All the visible views have rendered; try to render next/previous page.
131151
// (IDs start at 1, so no need to add 1 when `scrolledDown === true`.)
132-
let preRenderIndex = scrolledDown ? visible.last.id : visible.first.id - 2;
152+
let preRenderIndex = scrolledDown ? lastId : firstId - 2;
133153
let preRenderView = views[preRenderIndex];
134154

135155
if (preRenderView && !this.isViewFinished(preRenderView)) {

0 commit comments

Comments
 (0)