mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
[api-minor] Improve thumbnail
handling in documents that contain interactive forms
To improve performance of the sidebar we use the page-canvases to generate the thumbnails whenever possible, since that avoids unnecessary re-rendering when the sidebar is open. This works generally well, however there's an old problem in PDF documents that contain interactive forms (when those are enabled): Note how the thumbnails become partially (or fully) blank, since those Annotations are not included in the OperatorList.[1] We obviously want to keep using the `PDFThumbnailView.setImage`-method for most documents, however we need a way to skip it only for those pages that contain interactive forms. As it turns out it's unfortunately not all that simple to tell, after the fact, from looking only at the OperatorList that some Annotations were skipped. While it might have been possible to try and infer that in the viewer, it'd not have been pretty considering that at the time when rendering finishes the annotationLayer has not yet been built. The overall simplest solution that I could come up with, was instead to include a *summary* of the interactive form-state when doing the final "flushing" of the OperatorList and expose that information in the API. --- [1] Some examples from our test-suite: `annotation-tx2.pdf` where the thumbnail is completely blank, and `bug1737260.pdf` where the thumbnail is missing the "buttons" found on the page.
This commit is contained in:
parent
c7b71a3376
commit
0c31320c12
7 changed files with 185 additions and 101 deletions
|
@ -881,7 +881,11 @@ class Annotation {
|
|||
);
|
||||
if (!appearance) {
|
||||
if (!isUsingOwnCanvas) {
|
||||
return new OperatorList();
|
||||
return {
|
||||
opList: new OperatorList(),
|
||||
separateForm: false,
|
||||
separateCanvas: false,
|
||||
};
|
||||
}
|
||||
appearance = new StringStream("");
|
||||
appearance.dict = new Dict();
|
||||
|
@ -930,7 +934,7 @@ class Annotation {
|
|||
opList.addOp(OPS.endMarkedContent, []);
|
||||
}
|
||||
this.reset();
|
||||
return opList;
|
||||
return { opList, separateForm: false, separateCanvas: isUsingOwnCanvas };
|
||||
}
|
||||
|
||||
async save(evaluator, task, annotationStorage) {
|
||||
|
@ -1619,7 +1623,11 @@ class WidgetAnnotation extends Annotation {
|
|||
// Do not render form elements on the canvas when interactive forms are
|
||||
// enabled. The display layer is responsible for rendering them instead.
|
||||
if (renderForms && !(this instanceof SignatureWidgetAnnotation)) {
|
||||
return new OperatorList();
|
||||
return {
|
||||
opList: new OperatorList(),
|
||||
separateForm: true,
|
||||
separateCanvas: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (!this._hasText) {
|
||||
|
@ -1647,12 +1655,12 @@ class WidgetAnnotation extends Annotation {
|
|||
);
|
||||
}
|
||||
|
||||
const operatorList = new OperatorList();
|
||||
const opList = new OperatorList();
|
||||
|
||||
// Even if there is an appearance stream, ignore it. This is the
|
||||
// behaviour used by Adobe Reader.
|
||||
if (!this._defaultAppearance || content === null) {
|
||||
return operatorList;
|
||||
return { opList, separateForm: false, separateCanvas: false };
|
||||
}
|
||||
|
||||
const matrix = [1, 0, 0, 1, 0, 0];
|
||||
|
@ -1672,10 +1680,10 @@ class WidgetAnnotation extends Annotation {
|
|||
);
|
||||
}
|
||||
if (optionalContent !== undefined) {
|
||||
operatorList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
|
||||
opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
|
||||
}
|
||||
|
||||
operatorList.addOp(OPS.beginAnnotation, [
|
||||
opList.addOp(OPS.beginAnnotation, [
|
||||
this.data.id,
|
||||
this.data.rect,
|
||||
transform,
|
||||
|
@ -1688,14 +1696,14 @@ class WidgetAnnotation extends Annotation {
|
|||
stream,
|
||||
task,
|
||||
resources: this._fieldResources.mergedResources,
|
||||
operatorList,
|
||||
operatorList: opList,
|
||||
});
|
||||
operatorList.addOp(OPS.endAnnotation, []);
|
||||
opList.addOp(OPS.endAnnotation, []);
|
||||
|
||||
if (optionalContent !== undefined) {
|
||||
operatorList.addOp(OPS.endMarkedContent, []);
|
||||
opList.addOp(OPS.endMarkedContent, []);
|
||||
}
|
||||
return operatorList;
|
||||
return { opList, separateForm: false, separateCanvas: false };
|
||||
}
|
||||
|
||||
_getMKDict(rotation) {
|
||||
|
@ -2477,7 +2485,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||
}
|
||||
|
||||
// No appearance
|
||||
return new OperatorList();
|
||||
return {
|
||||
opList: new OperatorList(),
|
||||
separateForm: false,
|
||||
separateCanvas: false,
|
||||
};
|
||||
}
|
||||
|
||||
async save(evaluator, task, annotationStorage) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue