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

Add logic to track rendering area of various PDF ops #19043

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
16 changes: 15 additions & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
NodeStandardFontDataFactory,
} from "display-node_utils";
import { CanvasGraphics } from "./canvas.js";
import { CanvasRecorder } from "./canvas_recorder.js";
import { DOMCanvasFactory } from "./canvas_factory.js";
import { DOMCMapReaderFactory } from "display-cmap_reader_factory";
import { DOMFilterFactory } from "./filter_factory.js";
Expand Down Expand Up @@ -1513,9 +1514,22 @@ class PDFPageProxy {
this._pumpOperatorList(intentArgs);
}

const recordingContext =
this._pdfBug &&
globalThis.StepperManager?.enabled &&
!this._recordedGroups
? new CanvasRecorder(canvasContext)
: null;

const complete = error => {
intentState.renderTasks.delete(internalRenderTask);

if (recordingContext) {
this._recordedGroups =
CanvasRecorder.getFinishedGroups(recordingContext);
internalRenderTask.stepper.setOperatorGroups(this._recordedGroups);
}

// Attempt to reduce memory usage during *printing*, by always running
// cleanup immediately once rendering has finished.
if (this._maybeCleanupAfterRender || intentPrint) {
Expand Down Expand Up @@ -1548,7 +1562,7 @@ class PDFPageProxy {
callback: complete,
// Only include the required properties, and *not* the entire object.
params: {
canvasContext,
canvasContext: recordingContext ?? canvasContext,
viewport,
transform,
background,
Expand Down
Loading
Loading