Skip to content

Commit

Permalink
Fix sets tab order to "Structure" when a document is tagged #1260 (#1449
Browse files Browse the repository at this point in the history
)

* Set tab order when document is tagged

* Update approach and add inverse test

* Revert page dictionary setup

* Update lib/mixins/markings.js

* Update kitchen-sink-accessible.pdf

* Update CHANGELOG.md

---------

Co-authored-by: Libor M. <[email protected]>
  • Loading branch information
acrollet and liborm85 authored Dec 26, 2024
1 parent baeff0f commit 8b20d07
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Update fontkit to 2.0
- Update linebreak to 1.1
- Add support for spot colors
- Fix sets tab order to "Structure" when a document is tagged
- Fix measuring text when OpenType features are passed in to .text()

### [v0.15.2] - 2024-12-15
Expand Down
Binary file modified examples/kitchen-sink-accessible.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions lib/mixins/markings.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export default {
return this._root.data.MarkInfo;
},

hasMarkInfoDictionary() {
return !!this._root.data.MarkInfo;
},

getStructTreeRoot() {
if (!this._root.data.StructTreeRoot) {
this._root.data.StructTreeRoot = this.ref({
Expand Down
8 changes: 8 additions & 0 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ class PDFPage {
return this.content.write(chunk);
}

// Set tab order if document is tagged for accessibility.
_setTabOrder() {
if (!this.dictionary.Tabs && this.document.hasMarkInfoDictionary()) {
this.dictionary.data.Tabs = 'S';
}
}

end() {
this._setTabOrder();
this.dictionary.end();
this.resources.data.ColorSpace = this.resources.data.ColorSpace || {};
for (let color of Object.values(this.document.spotColors)) {
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/markings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,47 @@ EMC
`(My Title)`,
`endobj`
]);
expect(docData).toContainChunk([
`10 0 obj`,
/\/Tabs \/S/,
`endobj`
]);
});
});

describe('untagged document', () => {
test('taborder not set for unmarked content', () => {
document = new PDFDocument({
info: {
CreationDate: new Date(Date.UTC(2018, 1, 1)),
Title: "My Title"
},
displayTitle: true,
compress: false,
pdfVersion: '1.5',
tagged: false,
lang: 'en-AU'
});

const docData = logData(document);

document.end();

expect(docData).toContainChunk([
`3 0 obj`,
/\/Lang \(en-AU\)/,
`endobj`
]);
expect(docData).not.toContainChunk([
`3 0 obj`,
/\/MarkInfo 5 0 R/,
`endobj`
]);
expect(docData).not.toContainChunk([
`10 0 obj`,
/\/Tabs \/S/,
`endobj`
]);
});
});

Expand Down

0 comments on commit 8b20d07

Please sign in to comment.