Skip to content

Commit

Permalink
Ensure that the isUsingOwnCanvas-parameter is consistently included…
Browse files Browse the repository at this point in the history
… in operatorLists (PR 14247 follow-up)

Currently some `OPS.beginAnnotation` arguments will contain a `Number` value for the `isUsingOwnCanvas`-parameter, or in some cases an `undefined` value, which is inconsistent from an API perspective.
  • Loading branch information
Snuffleupagus authored and rousek committed Aug 10, 2022
1 parent 54d98ec commit c83e31a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,9 @@ class Annotation {
) {
const data = this.data;
let appearance = this.appearance;
const isUsingOwnCanvas =
this.data.hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY;
const isUsingOwnCanvas = !!(
this.data.hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY
);
if (!appearance) {
if (!isUsingOwnCanvas) {
return new OperatorList();
Expand Down Expand Up @@ -1709,6 +1710,7 @@ class WidgetAnnotation extends Annotation {
this.data.rect,
transform,
this.getRotationMatrix(annotationStorage),
/* isUsingOwnCanvas = */ false,
]);

const stream = new StringStream(content);
Expand Down
18 changes: 18 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2506,20 +2506,38 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
expect(opListAnnotEnable.argsArray.length).toBeGreaterThan(140);
expect(opListAnnotEnable.lastChunk).toEqual(true);

let firstAnnotIndex = opListAnnotEnable.fnArray.indexOf(
OPS.beginAnnotation
);
let isUsingOwnCanvas = opListAnnotEnable.argsArray[firstAnnotIndex][4];
expect(isUsingOwnCanvas).toEqual(false);

const opListAnnotEnableForms = await pdfPage.getOperatorList({
annotationMode: AnnotationMode.ENABLE_FORMS,
});
expect(opListAnnotEnableForms.fnArray.length).toBeGreaterThan(30);
expect(opListAnnotEnableForms.argsArray.length).toBeGreaterThan(30);
expect(opListAnnotEnableForms.lastChunk).toEqual(true);

firstAnnotIndex = opListAnnotEnableForms.fnArray.indexOf(
OPS.beginAnnotation
);
isUsingOwnCanvas = opListAnnotEnableForms.argsArray[firstAnnotIndex][4];
expect(isUsingOwnCanvas).toEqual(true);

const opListAnnotEnableStorage = await pdfPage.getOperatorList({
annotationMode: AnnotationMode.ENABLE_STORAGE,
});
expect(opListAnnotEnableStorage.fnArray.length).toBeGreaterThan(170);
expect(opListAnnotEnableStorage.argsArray.length).toBeGreaterThan(170);
expect(opListAnnotEnableStorage.lastChunk).toEqual(true);

firstAnnotIndex = opListAnnotEnableStorage.fnArray.indexOf(
OPS.beginAnnotation
);
isUsingOwnCanvas = opListAnnotEnableStorage.argsArray[firstAnnotIndex][4];
expect(isUsingOwnCanvas).toEqual(false);

// Sanity check to ensure that the `annotationMode` is correctly applied.
expect(opListAnnotDisable.fnArray.length).toBeLessThan(
opListAnnotEnableForms.fnArray.length
Expand Down

0 comments on commit c83e31a

Please sign in to comment.