Skip to content

Commit

Permalink
Revert "Fix for PDF accessibility check. (foliojs#1265)"
Browse files Browse the repository at this point in the history
This reverts commit 4700537.

Revert "Add option to define AcroForm fontSize. Fixes foliojs#1088"

This reverts commit 131df9e.
  • Loading branch information
liborm85 committed Jul 2, 2021
1 parent b860a83 commit b1e6d65
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 107 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Expand Up @@ -2,9 +2,6 @@

### Unreleased

- Allow applying 'underline' and 'strike' text styling together on a text
- Allow to specify the AcroForm text fontSize

### [v0.12.1] - 2021-04-10

- Update crypto-js to v3.3 (fix security issue)
Expand Down
1 change: 0 additions & 1 deletion docs/forms.md
Expand Up @@ -62,7 +62,6 @@ a hex color, or a named CSS color value for that option.
- `password` [_boolean_] - The text will be masked (_e.g._ with asterisks).
- `noSpell` [_boolean_] - If set, text entered in the field is not spell-checked
- `format` [_object_] - See the section on **Text Field Formatting** below.
- `fontSize` [_number_] - Sets the fontSize (default or 0 means auto sizing)

```js
doc.formText('leaf2', 10, 60, 200, 40, {
Expand Down
6 changes: 1 addition & 5 deletions lib/mixins/acroform.js
Expand Up @@ -333,12 +333,8 @@ export default {
// add current font to field's resource dict (RD) if not the default acroform font
if (this._acroform.defaultFont !== this._font.name) {
options.DR = { Font: {} };

// Get the fontSize option. If not set use auto sizing
const fontSize = options.fontSize || 0;

options.DR.Font[this._font.id] = this._font.ref();
options.DA = new String(`/${this._font.id} ${fontSize} Tf 0 g`);
options.DA = new String(`/${this._font.id} 0 Tf 0 g`);
}
return options;
},
Expand Down
21 changes: 10 additions & 11 deletions lib/mixins/markings.js
Expand Up @@ -14,8 +14,7 @@ export default {
this.structChildren = [];

if (options.tagged) {
this.getMarkInfoDictionary().data.Marked = true;
this.getStructTreeRoot();
this.getMarkingsDictionary().data.Marked = true;
}
},

Expand Down Expand Up @@ -131,17 +130,17 @@ export default {
return pageMarkings;
},

getMarkInfoDictionary() {
if (!this._root.data.MarkInfo) {
this._root.data.MarkInfo = this.ref({});
getMarkingsDictionary() {
if (!this._root.data.Markings) {
this._root.data.Markings = this.ref({});
}
return this._root.data.MarkInfo;
return this._root.data.Markings;
},

getStructTreeRoot() {
if (!this._root.data.StructTreeRoot) {
this._root.data.StructTreeRoot = this.ref({
Type: 'StructTreeRoot',
Type: "StructTreeRoot",
ParentTree: new PDFNumberTree(),
ParentTreeNextKey: 0
});
Expand All @@ -154,8 +153,8 @@ export default {
},

createStructParentTreeNextKey() {
// initialise the MarkInfo dictionary
this.getMarkInfoDictionary();
// initialise the Markings dictionary
this.getMarkingsDictionary();

const structTreeRoot = this.getStructTreeRoot();
const key = structTreeRoot.data.ParentTreeNextKey++;
Expand All @@ -169,8 +168,8 @@ export default {
structTreeRoot.end();
this.structChildren.forEach((structElem) => structElem.end());
}
if (this._root.data.MarkInfo) {
this._root.data.MarkInfo.end();
if (this._root.data.Markings) {
this._root.data.Markings.end();
}
}

Expand Down
25 changes: 6 additions & 19 deletions lib/mixins/text.js
Expand Up @@ -371,8 +371,8 @@ export default {
this.addNamedDestination(options.destination, 'XYZ', x, y, null);
}

// create underline
if (options.underline) {
// create underline or strikethrough line
if (options.underline || options.strike) {
this.save();
if (!options.stroke) {
this.strokeColor(...(this._fillColor || []));
Expand All @@ -382,25 +382,12 @@ export default {
this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10);
this.lineWidth(lineWidth);

let lineY = (y + this.currentLineHeight()) - lineWidth
this.moveTo(x, lineY);
this.lineTo(x + renderedWidth, lineY);
this.stroke();
this.restore();
}

// create strikethrough line
if (options.strike) {
this.save();
if (!options.stroke) {
this.strokeColor(...(this._fillColor || []));
const d = options.underline ? 1 : 2;
let lineY = y + this.currentLineHeight() / d;
if (options.underline) {
lineY -= lineWidth;
}

const lineWidth =
this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10);
this.lineWidth(lineWidth);

let lineY = y + this.currentLineHeight() / 2;
this.moveTo(x, lineY);
this.lineTo(x + renderedWidth, lineY);
this.stroke();
Expand Down
34 changes: 0 additions & 34 deletions tests/unit/acroform.spec.js
Expand Up @@ -222,40 +222,6 @@ describe('acroform', () => {
expect(docData).toContainChunk(expected);
});

test('font size', () => {
const expected = [
'11 0 obj',
'<<\n' +
'/fontSize 16\n' +
'/FT /Tx\n' +
'/DR <<\n' +
'/Font <<\n' +
'/F2 10 0 R\n' +
'>>\n' +
'>>\n' +
'/DA (/F2 16 Tf 0 g)\n' +
'/T (text)\n' +
'/Subtype /Widget\n' +
'/F 4\n' +
'/Type /Annot\n' +
'/Rect [20 752 70 772]\n' +
'/Border [0 0 0]\n' +
'/C [0 0 0]\n' +
'/FontSize 16\n' +
'>>',
'endobj'
];
doc.registerFont('myfont1', 'tests/fonts/Roboto-Regular.ttf');
doc.initForm();
const docData = logData(doc);
let opts = {
fontSize: 16
};
doc.font('myfont1').formText('text', 20, 20, 50, 20, opts);
expect(docData.length).toBe(3);
expect(docData).toContainChunk(expected);
});

test('field heirarchy', () => {
const expected = [
'13 0 obj',
Expand Down
39 changes: 9 additions & 30 deletions tests/unit/markings.spec.js
Expand Up @@ -289,7 +289,7 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/MarkInfo 9 0 R/,
/\/Markings 9 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
Expand Down Expand Up @@ -369,7 +369,7 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/MarkInfo 9 0 R/,
/\/Markings 9 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
Expand Down Expand Up @@ -441,7 +441,7 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/MarkInfo 13 0 R/,
/\/Markings 13 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
Expand Down Expand Up @@ -569,7 +569,7 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/MarkInfo 5 0 R/,
/\/Markings 5 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
Expand All @@ -579,47 +579,26 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/ViewerPreferences 7 0 R/,
/\/ViewerPreferences 6 0 R/,
`endobj`
]);

expect(docData).toContainChunk([
`3 0 obj`,
/\/StructTreeRoot 6 0 R/,
`endobj`
]);

expect(docData).toContainChunk([
`6 0 obj`,
`<<
/Type /StructTreeRoot
/ParentTree <<
/Nums [
]
>>
/ParentTreeNextKey 0
>>`,
`endobj`
]);


expect(docData).toContainChunk([
`7 0 obj`,
/\/DisplayDocTitle true/,
`endobj`
]);
expect(docData).toContainChunk([
`trailer`,
/\/Info 11 0 R/,
/\/Info 10 0 R/,
`startxref`
]);
expect(docData).toContainChunk([
`11 0 obj`,
/\/Title 15 0 R/,
`10 0 obj`,
/\/Title 14 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
`15 0 obj`,
`14 0 obj`,
`(My Title)`,
`endobj`
]);
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions tests/visual/text.spec.js
Expand Up @@ -30,10 +30,6 @@ describe('text', function() {
doc.text('Strike', 100, 130, {
strike: true
});
doc.text('Strike', 100, 160, {
underline:true,
strike: true
});
});
});

Expand Down

0 comments on commit b1e6d65

Please sign in to comment.