diff --git a/src/core/annotation.js b/src/core/annotation.js index 22842eec727790..177f021553be28 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -982,6 +982,16 @@ class WidgetAnnotation extends Annotation { const vPadding = defaultPadding + Math.abs(descent) * fontSize; const defaultAppearance = this.data.defaultAppearance; + 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 e9a6f62196812c..4cbe7138e8c04c 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -1717,6 +1717,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 () {