-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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 support for optional marked content. #12095
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ import { GlobalWorkerOptions } from "./worker_options.js"; | |
import { isNodeJS } from "../shared/is_node.js"; | ||
import { MessageHandler } from "../shared/message_handler.js"; | ||
import { Metadata } from "./metadata.js"; | ||
import { OptionalContentConfig } from "./optional_content_config.js"; | ||
import { PDFDataTransportStream } from "./transport_stream.js"; | ||
import { WebGLContext } from "./webgl.js"; | ||
|
||
|
@@ -788,6 +789,15 @@ class PDFDocumentProxy { | |
return this._transport.getOutline(); | ||
} | ||
|
||
/** | ||
* @returns {Promise<OptionalContentConfig | null>} A promise that is resolved | ||
* with an {@link OptionalContentConfig} that will have all the optional | ||
* content groups (if the document has any). | ||
*/ | ||
getOptionalContentConfig() { | ||
return this._transport.getOptionalContentConfig(); | ||
} | ||
|
||
/** | ||
* @returns {Promise<Array<string | null>>} A promise that is resolved with | ||
* an {Array} that contains the permission flags for the PDF document, or | ||
|
@@ -965,6 +975,11 @@ class PDFDocumentProxy { | |
* image). The default value is 'rgb(255,255,255)'. | ||
* @property {Object} [annotationStorage] - Storage for annotation data in | ||
* forms. | ||
* @property {Promise} [optionalContentConfigPromise] - A promise that should | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once #12156 lands, this should be changed to mention the promise type and to have each line start with two spaces as per the standard. |
||
* resolve with an {OptionalContentConfig} created from | ||
* PDFDocumentProxy.getOptionalContentConfig. If null, the | ||
* config will be automatically fetched with the default | ||
* visibility states set. | ||
*/ | ||
|
||
/** | ||
|
@@ -1088,6 +1103,7 @@ class PDFPageProxy { | |
canvasFactory = null, | ||
background = null, | ||
annotationStorage = null, | ||
optionalContentConfigPromise = null, | ||
}) { | ||
if (this._stats) { | ||
this._stats.time("Overall"); | ||
|
@@ -1098,6 +1114,10 @@ class PDFPageProxy { | |
// this call to render. | ||
this.pendingCleanup = false; | ||
|
||
if (!optionalContentConfigPromise) { | ||
optionalContentConfigPromise = this._transport.getOptionalContentConfig(); | ||
} | ||
|
||
let intentState = this._intentStates.get(renderingIntent); | ||
if (!intentState) { | ||
intentState = Object.create(null); | ||
|
@@ -1191,16 +1211,22 @@ class PDFPageProxy { | |
intentState.renderTasks.push(internalRenderTask); | ||
const renderTask = internalRenderTask.task; | ||
|
||
intentState.displayReadyCapability.promise | ||
.then(transparency => { | ||
Promise.all([ | ||
intentState.displayReadyCapability.promise, | ||
optionalContentConfigPromise, | ||
]) | ||
.then(([transparency, optionalContentConfig]) => { | ||
if (this.pendingCleanup) { | ||
complete(); | ||
return; | ||
} | ||
if (this._stats) { | ||
this._stats.time("Rendering"); | ||
} | ||
internalRenderTask.initializeGraphics(transparency); | ||
internalRenderTask.initializeGraphics({ | ||
transparency, | ||
optionalContentConfig, | ||
}); | ||
internalRenderTask.operatorListChanged(); | ||
}) | ||
.catch(complete); | ||
|
@@ -2546,6 +2572,14 @@ class WorkerTransport { | |
return this.messageHandler.sendWithPromise("GetOutline", null); | ||
} | ||
|
||
getOptionalContentConfig() { | ||
return this.messageHandler | ||
.sendWithPromise("GetOptionalContentConfig", null) | ||
.then(results => { | ||
return new OptionalContentConfig(results); | ||
}); | ||
} | ||
|
||
getPermissions() { | ||
return this.messageHandler.sendWithPromise("GetPermissions", null); | ||
} | ||
|
@@ -2759,7 +2793,7 @@ const InternalRenderTask = (function InternalRenderTaskClosure() { | |
}); | ||
} | ||
|
||
initializeGraphics(transparency = false) { | ||
initializeGraphics({ transparency = false, optionalContentConfig }) { | ||
if (this.cancelled) { | ||
return; | ||
} | ||
|
@@ -2797,7 +2831,8 @@ const InternalRenderTask = (function InternalRenderTaskClosure() { | |
this.objs, | ||
this.canvasFactory, | ||
this.webGLContext, | ||
imageLayer | ||
imageLayer, | ||
optionalContentConfig | ||
); | ||
this.gfx.beginDrawing({ | ||
transform, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it actually make sense to simply move this check into the
next
handling below and throw aFormatError
instead?I.e. something similar to the
next
code that's used e.g. when parsingOPS.paintXObject
earlier in this file.Really sorry about the back-and-forth in some of these comments, but it's quite a lot of added code/functionality to "unpack" here and at first glance I unfortunately overlooked some of the finer details.
The overall functionality seem to work very nicely though :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started to do do this, but sometimes the marked content isn't an "OC" which then causes us to wait async when we really don't need to.