1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Support comb textfields for printing

This commit is contained in:
Calixte Denizet 2020-08-06 16:45:17 +02:00 committed by calixteman
parent b061c300b4
commit 88b112ab0c
2 changed files with 66 additions and 0 deletions

View file

@ -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,