From c83e31a0f2209b6e712c7e9af1013933e1cab895 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 28 Jul 2022 13:37:37 +0200 Subject: [PATCH] Ensure that the `isUsingOwnCanvas`-parameter is consistently included 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. --- src/core/annotation.js | 6 ++++-- test/unit/api_spec.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index d59a7d5278bc36..df5f79284678f0 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -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(); @@ -1709,6 +1710,7 @@ class WidgetAnnotation extends Annotation { this.data.rect, transform, this.getRotationMatrix(annotationStorage), + /* isUsingOwnCanvas = */ false, ]); const stream = new StringStream(content); diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index f932ec378766a3..1546e5b51e4c91 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -2506,6 +2506,12 @@ 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, }); @@ -2513,6 +2519,12 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`) 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, }); @@ -2520,6 +2532,12 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`) 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