Skip to content

Commit

Permalink
Merge pull request #19128 from nicolo-ribaudo/draw-page-portion
Browse files Browse the repository at this point in the history
[api-minor] Render high-res partial page views when falling back to CSS zoom (bug 1492303)
  • Loading branch information
Snuffleupagus authored Feb 21, 2025
2 parents b4e26dc + dc5d6aa commit 553ec7b
Show file tree
Hide file tree
Showing 15 changed files with 1,460 additions and 305 deletions.
38 changes: 24 additions & 14 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3232,17 +3232,27 @@ class PDFObjects {
class RenderTask {
#internalRenderTask = null;

/**
* Callback for incremental rendering -- a function that will be called
* each time the rendering is paused. To continue rendering call the
* function that is the first argument to the callback.
* @type {function}
*/
onContinue = null;

/**
* A function that will be synchronously called when the rendering tasks
* finishes with an error (either because of an actual error, or because the
* rendering is cancelled).
*
* @type {function}
* @param {Error} error
*/
onError = null;

constructor(internalRenderTask) {
this.#internalRenderTask = internalRenderTask;

/**
* Callback for incremental rendering -- a function that will be called
* each time the rendering is paused. To continue rendering call the
* function that is the first argument to the callback.
* @type {function}
*/
this.onContinue = null;

if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
// For testing purposes.
Object.defineProperty(this, "getOperatorList", {
Expand Down Expand Up @@ -3399,13 +3409,13 @@ class InternalRenderTask {
}
InternalRenderTask.#canvasInUse.delete(this._canvas);

this.callback(
error ||
new RenderingCancelledException(
`Rendering cancelled, page ${this._pageIndex + 1}`,
extraDelay
)
error ||= new RenderingCancelledException(
`Rendering cancelled, page ${this._pageIndex + 1}`,
extraDelay
);
this.callback(error);

this.task.onError?.(error);
}

operatorListChanged() {
Expand Down
14 changes: 11 additions & 3 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ import os from "os";

const isMac = os.platform() === "darwin";

function loadAndWait(filename, selector, zoom, setups, options) {
function loadAndWait(filename, selector, zoom, setups, options, viewport) {
return Promise.all(
global.integrationSessions.map(async session => {
const page = await session.browser.newPage();

if (viewport) {
await page.setViewport(viewport);
}

// In order to avoid errors because of checks which depend on
// a locale.
await page.evaluateOnNewDocument(() => {
Expand Down Expand Up @@ -566,8 +570,12 @@ function waitForAnnotationModeChanged(page) {

function waitForPageRendered(page) {
return createPromise(page, resolve => {
window.PDFViewerApplication.eventBus.on("pagerendered", resolve, {
once: true,
const { eventBus } = window.PDFViewerApplication;
eventBus.on("pagerendered", function handler(e) {
if (!e.isDetailView) {
resolve();
eventBus.off("pagerendered", handler);
}
});
});
}
Expand Down
Loading

0 comments on commit 553ec7b

Please sign in to comment.