From 5af352e65abbdad1da522baff3c78c893d514b78 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 24 Sep 2020 19:13:09 +0200 Subject: [PATCH] Need to reset the streams when printing --- src/core/annotation.js | 10 +++++ test/unit/annotation_spec.js | 84 ++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/src/core/annotation.js b/src/core/annotation.js index 2a078c676..cf2f6ffcb 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -1733,6 +1733,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { this.checkedAppearance = normalAppearance.get(this.data.exportValue); this.uncheckedAppearance = normalAppearance.get("Off") || null; + + this._streams.push(this.checkedAppearance); + if (this.uncheckedAppearance) { + this._streams.push(this.uncheckedAppearance); + } } _processRadioButton(params) { @@ -1767,6 +1772,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { this.checkedAppearance = normalAppearance.get(this.data.buttonValue); this.uncheckedAppearance = normalAppearance.get("Off") || null; + + this._streams.push(this.checkedAppearance); + if (this.uncheckedAppearance) { + this._streams.push(this.uncheckedAppearance); + } } _processPushButton(params) { diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index a7713bedf..45fd9f93d 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -2045,6 +2045,90 @@ describe("annotation", function () { }, done.fail); }); + it("should render checkboxes for printing two times", function (done) { + const appearanceStatesDict = new Dict(); + const normalAppearanceDict = new Dict(); + const checkedAppearanceDict = new Dict(); + const uncheckedAppearanceDict = new Dict(); + + const checkedStream = new StringStream("0.1 0.2 0.3 rg"); + checkedStream.dict = checkedAppearanceDict; + + const uncheckedStream = new StringStream("0.3 0.2 0.1 rg"); + uncheckedStream.dict = uncheckedAppearanceDict; + + checkedAppearanceDict.set("BBox", [0, 0, 8, 8]); + checkedAppearanceDict.set("FormType", 1); + checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]); + normalAppearanceDict.set("Checked", checkedStream); + normalAppearanceDict.set("Off", uncheckedStream); + appearanceStatesDict.set("N", normalAppearanceDict); + + buttonWidgetDict.set("AP", appearanceStatesDict); + buttonWidgetDict.set("AS", Name.get("Off")); + + const buttonWidgetRef = Ref.get(1249, 0); + const xref = new XRefMock([ + { ref: buttonWidgetRef, data: buttonWidgetDict }, + ]); + const task = new WorkerTask("test print"); + + AnnotationFactory.create( + xref, + buttonWidgetRef, + pdfManagerMock, + idFactoryMock + ) + .then(annotation => { + const annotationStorage = {}; + annotationStorage[annotation.data.id] = true; + return Promise.all([ + annotation, + annotation.getOperatorList( + partialEvaluator, + task, + false, + annotationStorage + ), + ]); + }) + .then(([annotation, opList]) => { + expect(opList.argsArray.length).toEqual(3); + expect(opList.fnArray).toEqual([ + OPS.beginAnnotation, + OPS.setFillRGBColor, + OPS.endAnnotation, + ]); + expect(opList.argsArray[1]).toEqual( + new Uint8ClampedArray([26, 51, 76]) + ); + return annotation; + }) + .then(annotation => { + const annotationStorage = {}; + annotationStorage[annotation.data.id] = true; + return annotation.getOperatorList( + partialEvaluator, + task, + false, + annotationStorage + ); + }) + .then(opList => { + expect(opList.argsArray.length).toEqual(3); + expect(opList.fnArray).toEqual([ + OPS.beginAnnotation, + OPS.setFillRGBColor, + OPS.endAnnotation, + ]); + expect(opList.argsArray[1]).toEqual( + new Uint8ClampedArray([26, 51, 76]) + ); + done(); + }) + .catch(done.fail); + }); + it("should save checkboxes", function (done) { const appearanceStatesDict = new Dict(); const normalAppearanceDict = new Dict();