Skip to content

Commit fa8fd5a

Browse files
committed
Support comb textfields for printing
1 parent 0ce33be commit fa8fd5a

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
@@ -982,6 +982,16 @@ class WidgetAnnotation extends Annotation {
982982
const vPadding = defaultPadding + Math.abs(descent) * fontSize;
983983
const defaultAppearance = this.data.defaultAppearance;
984984

985+
if (this.data.comb) {
986+
return this._getCombAppearance(
987+
defaultAppearance,
988+
value,
989+
totalWidth,
990+
hPadding,
991+
vPadding
992+
);
993+
}
994+
985995
if (this.data.multiLine) {
986996
return this._getMultilineAppearance(
987997
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
@@ -1717,6 +1717,46 @@ describe("annotation", function () {
17171717
done();
17181718
}, done.fail);
17191719
});
1720+
1721+
it("should render comb for printing", function (done) {
1722+
textWidgetDict.set("Ff", AnnotationFieldFlag.COMB);
1723+
textWidgetDict.set("MaxLen", 4);
1724+
1725+
const textWidgetRef = Ref.get(271, 0);
1726+
const xref = new XRefMock([
1727+
{ ref: textWidgetRef, data: textWidgetDict },
1728+
fontRefObj,
1729+
]);
1730+
const task = new WorkerTask("test print");
1731+
partialEvaluator.xref = xref;
1732+
1733+
AnnotationFactory.create(
1734+
xref,
1735+
textWidgetRef,
1736+
pdfManagerMock,
1737+
idFactoryMock
1738+
)
1739+
.then(annotation => {
1740+
const id = annotation.data.id;
1741+
const annotationStorage = {};
1742+
annotationStorage[id] = "aa(aa)a\\";
1743+
return annotation._getAppearance(
1744+
partialEvaluator,
1745+
task,
1746+
annotationStorage
1747+
);
1748+
}, done.fail)
1749+
.then(appearance => {
1750+
expect(appearance).toEqual(
1751+
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 2 2 Tm" +
1752+
" (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (\\() Tj" +
1753+
" 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj" +
1754+
" 8.00 0 Td (\\)) Tj 8.00 0 Td (a) Tj" +
1755+
" 8.00 0 Td (\\\\) Tj ET Q EMC"
1756+
);
1757+
done();
1758+
}, done.fail);
1759+
});
17201760
});
17211761

17221762
describe("ButtonWidgetAnnotation", function () {

0 commit comments

Comments
 (0)