1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[api-minor] Render high-res partial page views when falling back to CSS zoom (bug 1492303)

When rendering big PDF pages at high zoom levels, we currently fall back
to CSS zoom to avoid rendering canvases with too many pixels. This
causes zoomed in PDF to look blurry, and the text to be potentially
unreadable.

This commit adds support for rendering _part_ of a page (called
`PDFPageDetailView` in the code), so that we can render portion of a
page in a smaller canvas without hiting the maximun canvas size limit.

Specifically, we render an area of that page that is slightly larger
than the area that is visible on the screen (100% larger in each
direction, unless we have to limit it due to the maximum canvas size).
As the user scrolls around the page, we re-render a new area centered
around what is currently visible.
This commit is contained in:
Nicolò Ribaudo 2024-12-11 13:58:52 +01:00
parent 06257f782e
commit 458b2ee402
No known key found for this signature in database
GPG key ID: AAFDA9101C58F338
14 changed files with 1142 additions and 116 deletions

View file

@ -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", {
@ -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() {