mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 01:35:43 +02:00
[api-minor] Add intent
support to the PDFPageProxy.getOperatorList
method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods. Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now. Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future. Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists). *Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
This commit is contained in:
parent
f1ae7d7b0e
commit
03cf28bf17
7 changed files with 121 additions and 17 deletions
|
@ -1149,7 +1149,7 @@ class PDFDocumentProxy {
|
|||
* Page annotation parameters.
|
||||
*
|
||||
* @typedef {Object} GetAnnotationsParameters
|
||||
* @property {string} intent - Determines the annotations that will be fetched,
|
||||
* @property {string} [intent] - Determines the annotations that are fetched,
|
||||
* can be either 'display' (viewable annotations) or 'print' (printable
|
||||
* annotations). If the parameter is omitted, all annotations are fetched.
|
||||
*/
|
||||
|
@ -1187,6 +1187,14 @@ class PDFDocumentProxy {
|
|||
* states set.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page getOperatorList parameters.
|
||||
*
|
||||
* @typedef {Object} GetOperatorListParameters
|
||||
* @property {string} [intent] - Rendering intent, can be 'display' or 'print'.
|
||||
* The default value is 'display'.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Structure tree node. The root node will have a role "Root".
|
||||
*
|
||||
|
@ -1299,12 +1307,18 @@ class PDFPageProxy {
|
|||
* {Array} of the annotation objects.
|
||||
*/
|
||||
getAnnotations({ intent = null } = {}) {
|
||||
if (!this._annotationsPromise || this._annotationsIntent !== intent) {
|
||||
const renderingIntent =
|
||||
intent === "display" || intent === "print" ? intent : null;
|
||||
|
||||
if (
|
||||
!this._annotationsPromise ||
|
||||
this._annotationsIntent !== renderingIntent
|
||||
) {
|
||||
this._annotationsPromise = this._transport.getAnnotations(
|
||||
this._pageIndex,
|
||||
intent
|
||||
renderingIntent
|
||||
);
|
||||
this._annotationsIntent = intent;
|
||||
this._annotationsIntent = renderingIntent;
|
||||
}
|
||||
return this._annotationsPromise;
|
||||
}
|
||||
|
@ -1332,7 +1346,7 @@ class PDFPageProxy {
|
|||
/**
|
||||
* Begins the process of rendering a page to the desired context.
|
||||
*
|
||||
* @param {RenderParameters} params Page render parameters.
|
||||
* @param {RenderParameters} params - Page render parameters.
|
||||
* @returns {RenderTask} An object that contains a promise that is
|
||||
* resolved when the page finishes rendering.
|
||||
*/
|
||||
|
@ -1473,10 +1487,12 @@ class PDFPageProxy {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {GetOperatorListParameters} params - Page getOperatorList
|
||||
* parameters.
|
||||
* @returns {Promise<PDFOperatorList>} A promise resolved with an
|
||||
* {@link PDFOperatorList} object that represents page's operator list.
|
||||
* {@link PDFOperatorList} object that represents the page's operator list.
|
||||
*/
|
||||
getOperatorList() {
|
||||
getOperatorList({ intent = "display" } = {}) {
|
||||
function operatorListChanged() {
|
||||
if (intentState.operatorList.lastChunk) {
|
||||
intentState.opListReadCapability.resolve(intentState.operatorList);
|
||||
|
@ -1485,7 +1501,9 @@ class PDFPageProxy {
|
|||
}
|
||||
}
|
||||
|
||||
const renderingIntent = "oplist";
|
||||
const renderingIntent = `oplist-${
|
||||
intent === "print" ? "print" : "display"
|
||||
}`;
|
||||
let intentState = this._intentStates.get(renderingIntent);
|
||||
if (!intentState) {
|
||||
intentState = Object.create(null);
|
||||
|
@ -1600,7 +1618,7 @@ class PDFPageProxy {
|
|||
force: true,
|
||||
});
|
||||
|
||||
if (intent === "oplist") {
|
||||
if (intent.startsWith("oplist-")) {
|
||||
// Avoid errors below, since the renderTasks are just stubs.
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue