diff --git a/src/core/annotation.js b/src/core/annotation.js index 10dc4cf766a7a..715d8c98cbceb 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -983,6 +983,16 @@ class WidgetAnnotation extends Annotation { const defaultAppearance = this.data.defaultAppearance; const alignment = this.data.textAlignment; + if (this.data.comb) { + return this._getCombAppearance( + defaultAppearance, + value, + totalWidth, + hPadding, + vPadding + ); + } + if (this.data.multiLine) { return this._getMultilineAppearance( defaultAppearance, @@ -1129,6 +1139,22 @@ class TextWidgetAnnotation extends WidgetAnnotation { this.data.maxLen !== null; } + _getCombAppearance(defaultAppearance, text, width, hPadding, vPadding) { + const combWidth = (width / this.data.maxLen).toFixed(2); + const buf = []; + for (const character of text) { + buf.push(`(${escapeString(character)}) Tj`); + } + + const renderedComb = buf.join(` ${combWidth} 0 Td `); + return ( + "/Tx BMC q BT " + + defaultAppearance + + ` 1 0 0 1 ${hPadding} ${vPadding} Tm ${renderedComb}` + + " ET Q EMC" + ); + } + _getMultilineAppearance( defaultAppearance, text, diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 5e53827d46d04..5789a20d3c1f3 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -1781,6 +1781,46 @@ describe("annotation", function () { done(); }, done.fail); }); + + it("should render comb for printing", function (done) { + textWidgetDict.set("Ff", AnnotationFieldFlag.COMB); + textWidgetDict.set("MaxLen", 4); + + const textWidgetRef = Ref.get(271, 0); + const xref = new XRefMock([ + { ref: textWidgetRef, data: textWidgetDict }, + fontRefObj, + ]); + const task = new WorkerTask("test print"); + partialEvaluator.xref = xref; + + AnnotationFactory.create( + xref, + textWidgetRef, + pdfManagerMock, + idFactoryMock + ) + .then(annotation => { + const id = annotation.data.id; + const annotationStorage = {}; + annotationStorage[id] = "aa(aa)a\\"; + return annotation._getAppearance( + partialEvaluator, + task, + annotationStorage + ); + }, done.fail) + .then(appearance => { + expect(appearance).toEqual( + "/Tx BMC q BT /Helv 5 Tf 1 0 0 1 2 2 Tm" + + " (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (\\() Tj" + + " 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj" + + " 8.00 0 Td (\\)) Tj 8.00 0 Td (a) Tj" + + " 8.00 0 Td (\\\\) Tj ET Q EMC" + ); + done(); + }, done.fail); + }); }); describe("ButtonWidgetAnnotation", function () {