@@ -38,6 +38,11 @@ import {
3838 PrintAnnotationStorage ,
3939 SerializableEmpty ,
4040} from "./annotation_storage.js" ;
41+ import {
42+ CanvasBBoxTracker ,
43+ CanvasDependencyTracker ,
44+ CanvasImagesTracker ,
45+ } from "./canvas_dependency_tracker.js" ;
4146import {
4247 deprecated ,
4348 isDataScheme ,
@@ -68,7 +73,6 @@ import {
6873 NodeStandardFontDataFactory ,
6974 NodeWasmFactory ,
7075} from "display-node_utils" ;
71- import { CanvasDependencyTracker } from "./canvas_dependency_tracker.js" ;
7276import { CanvasGraphics } from "./canvas.js" ;
7377import { DOMCanvasFactory } from "./canvas_factory.js" ;
7478import { DOMCMapReaderFactory } from "display-cmap_reader_factory" ;
@@ -1273,6 +1277,7 @@ class PDFDocumentProxy {
12731277 * annotation ids with canvases used to render them.
12741278 * @property {PrintAnnotationStorage } [printAnnotationStorage]
12751279 * @property {boolean } [isEditing] - Render the page in editing mode.
1280+ * @property {boolean } [recordImages] - Record the location of images in the PDF
12761281 * @property {boolean } [recordOperations] - Record the dependencies and bounding
12771282 * boxes of all PDF operations that render onto the canvas.
12781283 * @property {OperationsFilter } [operationsFilter] - If provided, only
@@ -1357,6 +1362,7 @@ class PDFPageProxy {
13571362 this . destroyed = false ;
13581363 this . recordedBBoxes = null ;
13591364 this . #pagesMapper = pagesMapper ;
1365+ this . imageCoordinates = null ;
13601366 }
13611367
13621368 /**
@@ -1488,6 +1494,7 @@ class PDFPageProxy {
14881494 pageColors = null ,
14891495 printAnnotationStorage = null ,
14901496 isEditing = false ,
1497+ recordImages = false ,
14911498 recordOperations = false ,
14921499 operationsFilter = null ,
14931500 } ) {
@@ -1539,6 +1546,7 @@ class PDFPageProxy {
15391546 ) ;
15401547 const shouldRecordOperations =
15411548 ! this . recordedBBoxes && ( recordOperations || recordForDebugger ) ;
1549+ const shouldRecordImages = ! this . imageCoordinates && recordImages ;
15421550
15431551 const complete = error => {
15441552 intentState . renderTasks . delete ( internalRenderTask ) ;
@@ -1557,6 +1565,10 @@ class PDFPageProxy {
15571565 }
15581566 }
15591567
1568+ if ( shouldRecordImages && ! error ) {
1569+ this . imageCoordinates = internalRenderTask . gfx ?. imagesTracker . take ( ) ;
1570+ }
1571+
15601572 // Attempt to reduce memory usage during *printing*, by always running
15611573 // cleanup immediately once rendering has finished.
15621574 if ( intentPrint ) {
@@ -1585,18 +1597,30 @@ class PDFPageProxy {
15851597 }
15861598 } ;
15871599
1600+ let dependencyTracker = null ;
1601+ let bboxTracker = null ;
1602+ if ( shouldRecordOperations || shouldRecordImages ) {
1603+ bboxTracker = new CanvasBBoxTracker (
1604+ canvas ,
1605+ intentState . operatorList . length
1606+ ) ;
1607+ }
1608+ if ( shouldRecordOperations ) {
1609+ dependencyTracker = new CanvasDependencyTracker (
1610+ bboxTracker ,
1611+ recordForDebugger
1612+ ) ;
1613+ }
1614+
15881615 const internalRenderTask = new InternalRenderTask ( {
15891616 callback : complete ,
15901617 // Only include the required properties, and *not* the entire object.
15911618 params : {
15921619 canvas,
15931620 canvasContext,
1594- dependencyTracker : shouldRecordOperations
1595- ? new CanvasDependencyTracker (
1596- canvas ,
1597- intentState . operatorList . length ,
1598- recordForDebugger
1599- )
1621+ dependencyTracker : dependencyTracker ?? bboxTracker ,
1622+ imagesTracker : shouldRecordImages
1623+ ? new CanvasImagesTracker ( canvas )
16001624 : null ,
16011625 viewport,
16021626 transform,
@@ -3288,6 +3312,10 @@ class RenderTask {
32883312 ( separateAnnots . canvas && annotationCanvasMap ?. size > 0 )
32893313 ) ;
32903314 }
3315+
3316+ get imageCoordinates ( ) {
3317+ return this . _internalRenderTask . imageCoordinates || null ;
3318+ }
32913319}
32923320
32933321/**
@@ -3345,6 +3373,7 @@ class InternalRenderTask {
33453373 this . _canvasContext = params . canvas ? null : params . canvasContext ;
33463374 this . _enableHWA = enableHWA ;
33473375 this . _dependencyTracker = params . dependencyTracker ;
3376+ this . _imagesTracker = params . imagesTracker ;
33483377 this . _operationsFilter = operationsFilter ;
33493378 }
33503379
@@ -3375,7 +3404,13 @@ class InternalRenderTask {
33753404 this . stepper . init ( this . operatorList ) ;
33763405 this . stepper . nextBreakPoint = this . stepper . getNextBreakPoint ( ) ;
33773406 }
3378- const { viewport, transform, background, dependencyTracker } = this . params ;
3407+ const {
3408+ viewport,
3409+ transform,
3410+ background,
3411+ dependencyTracker,
3412+ imagesTracker,
3413+ } = this . params ;
33793414
33803415 // When printing in Firefox, we get a specific context in mozPrintCallback
33813416 // which cannot be created from the canvas itself.
@@ -3395,7 +3430,8 @@ class InternalRenderTask {
33953430 { optionalContentConfig } ,
33963431 this . annotationCanvasMap ,
33973432 this . pageColors ,
3398- dependencyTracker
3433+ dependencyTracker ,
3434+ imagesTracker
33993435 ) ;
34003436 this . gfx . beginDrawing ( {
34013437 transform,
0 commit comments