mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +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
|
@ -702,7 +702,13 @@ class Annotation {
|
|||
|
||||
return resourcesPromise.then(resources => {
|
||||
const opList = new OperatorList();
|
||||
opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
|
||||
opList.addOp(OPS.beginAnnotation, [
|
||||
data.id,
|
||||
data.rect,
|
||||
transform,
|
||||
matrix,
|
||||
]);
|
||||
|
||||
return evaluator
|
||||
.getOperatorList({
|
||||
stream: appearance,
|
||||
|
@ -1307,6 +1313,7 @@ class WidgetAnnotation extends Annotation {
|
|||
|
||||
const transform = getTransformMatrix(this.data.rect, bbox, matrix);
|
||||
operatorList.addOp(OPS.beginAnnotation, [
|
||||
this.data.id,
|
||||
this.data.rect,
|
||||
transform,
|
||||
matrix,
|
||||
|
|
|
@ -366,12 +366,16 @@ class Page {
|
|||
|
||||
// Collect the operator list promises for the annotations. Each promise
|
||||
// is resolved with the complete operator list for a single annotation.
|
||||
const annotationIntent = intent.startsWith("oplist-")
|
||||
? intent.split("-")[1]
|
||||
: intent;
|
||||
const opListPromises = [];
|
||||
for (const annotation of annotations) {
|
||||
if (
|
||||
(intent === "display" &&
|
||||
(annotationIntent === "display" &&
|
||||
annotation.mustBeViewed(annotationStorage)) ||
|
||||
(intent === "print" && annotation.mustBePrinted(annotationStorage))
|
||||
(annotationIntent === "print" &&
|
||||
annotation.mustBePrinted(annotationStorage))
|
||||
) {
|
||||
opListPromises.push(
|
||||
annotation
|
||||
|
|
|
@ -594,14 +594,14 @@ class OperatorList {
|
|||
|
||||
// Close to chunk size.
|
||||
static get CHUNK_SIZE_ABOUT() {
|
||||
return shadow(this, "CHUNK_SIZE_ABOUT", OperatorList.CHUNK_SIZE - 5);
|
||||
return shadow(this, "CHUNK_SIZE_ABOUT", this.CHUNK_SIZE - 5);
|
||||
}
|
||||
|
||||
constructor(intent, streamSink) {
|
||||
this._streamSink = streamSink;
|
||||
this.fnArray = [];
|
||||
this.argsArray = [];
|
||||
if (streamSink && intent !== "oplist") {
|
||||
if (streamSink && !(intent && intent.startsWith("oplist-"))) {
|
||||
this.optimizer = new QueueOptimizer(this);
|
||||
} else {
|
||||
this.optimizer = new NullOptimizer(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue