Skip to content

Commit 88b112a

Browse files
committed
Support comb textfields for printing
1 parent b061c30 commit 88b112a

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/core/annotation.js

+26
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,16 @@ class WidgetAnnotation extends Annotation {
983983
const defaultAppearance = this.data.defaultAppearance;
984984
const alignment = this.data.textAlignment;
985985

986+
if (this.data.comb) {
987+
return this._getCombAppearance(
988+
defaultAppearance,
989+
value,
990+
totalWidth,
991+
hPadding,
992+
vPadding
993+
);
994+
}
995+
986996
if (this.data.multiLine) {
987997
return this._getMultilineAppearance(
988998
defaultAppearance,
@@ -1129,6 +1139,22 @@ class TextWidgetAnnotation extends WidgetAnnotation {
11291139
this.data.maxLen !== null;
11301140
}
11311141

1142+
_getCombAppearance(defaultAppearance, text, width, hPadding, vPadding) {
1143+
const combWidth = (width / this.data.maxLen).toFixed(2);
1144+
const buf = [];
1145+
for (const character of text) {
1146+
buf.push(`(${escapeString(character)}) Tj`);
1147+
}
1148+
1149+
const renderedComb = buf.join(` ${combWidth} 0 Td `);
1150+
return (
1151+
"/Tx BMC q BT " +
1152+
defaultAppearance +
1153+
` 1 0 0 1 ${hPadding} ${vPadding} Tm ${renderedComb}` +
1154+
" ET Q EMC"
1155+
);
1156+
}
1157+
11321158
_getMultilineAppearance(
11331159
defaultAppearance,
11341160
text,

test/unit/annotation_spec.js

+40
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,46 @@ describe("annotation", function () {
17811781
done();
17821782
}, done.fail);
17831783
});
1784+
1785+
it("should render comb for printing", function (done) {
1786+
textWidgetDict.set("Ff", AnnotationFieldFlag.COMB);
1787+
textWidgetDict.set("MaxLen", 4);
1788+
1789+
const textWidgetRef = Ref.get(271, 0);
1790+
const xref = new XRefMock([
1791+
{ ref: textWidgetRef, data: textWidgetDict },
1792+
fontRefObj,
1793+
]);
1794+
const task = new WorkerTask("test print");
1795+
partialEvaluator.xref = xref;
1796+
1797+
AnnotationFactory.create(
1798+
xref,
1799+
textWidgetRef,
1800+
pdfManagerMock,
1801+
idFactoryMock
1802+
)
1803+
.then(annotation => {
1804+
const id = annotation.data.id;
1805+
const annotationStorage = {};
1806+
annotationStorage[id] = "aa(aa)a\\";
1807+
return annotation._getAppearance(
1808+
partialEvaluator,
1809+
task,
1810+
annotationStorage
1811+
);
1812+
}, done.fail)
1813+
.then(appearance => {
1814+
expect(appearance).toEqual(
1815+
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 2 2 Tm" +
1816+
" (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (\\() Tj" +
1817+
" 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj" +
1818+
" 8.00 0 Td (\\)) Tj 8.00 0 Td (a) Tj" +
1819+
" 8.00 0 Td (\\\\) Tj ET Q EMC"
1820+
);
1821+
done();
1822+
}, done.fail);
1823+
});
17841824
});
17851825

17861826
describe("ButtonWidgetAnnotation", function () {

0 commit comments

Comments
 (0)