Skip to content

Commit 8b20d07

Browse files
acrolletliborm85
andauthored
Fix sets tab order to "Structure" when a document is tagged #1260 (#1449)
* 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]>
1 parent baeff0f commit 8b20d07

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Update fontkit to 2.0
66
- Update linebreak to 1.1
77
- Add support for spot colors
8+
- Fix sets tab order to "Structure" when a document is tagged
89
- Fix measuring text when OpenType features are passed in to .text()
910

1011
### [v0.15.2] - 2024-12-15
108 Bytes
Binary file not shown.

lib/mixins/markings.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export default {
138138
return this._root.data.MarkInfo;
139139
},
140140

141+
hasMarkInfoDictionary() {
142+
return !!this._root.data.MarkInfo;
143+
},
144+
141145
getStructTreeRoot() {
142146
if (!this._root.data.StructTreeRoot) {
143147
this._root.data.StructTreeRoot = this.ref({

lib/page.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,15 @@ class PDFPage {
155155
return this.content.write(chunk);
156156
}
157157

158+
// Set tab order if document is tagged for accessibility.
159+
_setTabOrder() {
160+
if (!this.dictionary.Tabs && this.document.hasMarkInfoDictionary()) {
161+
this.dictionary.data.Tabs = 'S';
162+
}
163+
}
164+
158165
end() {
166+
this._setTabOrder();
159167
this.dictionary.end();
160168
this.resources.data.ColorSpace = this.resources.data.ColorSpace || {};
161169
for (let color of Object.values(this.document.spotColors)) {

tests/unit/markings.spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,47 @@ EMC
623623
`(My Title)`,
624624
`endobj`
625625
]);
626+
expect(docData).toContainChunk([
627+
`10 0 obj`,
628+
/\/Tabs \/S/,
629+
`endobj`
630+
]);
631+
});
632+
});
633+
634+
describe('untagged document', () => {
635+
test('taborder not set for unmarked content', () => {
636+
document = new PDFDocument({
637+
info: {
638+
CreationDate: new Date(Date.UTC(2018, 1, 1)),
639+
Title: "My Title"
640+
},
641+
displayTitle: true,
642+
compress: false,
643+
pdfVersion: '1.5',
644+
tagged: false,
645+
lang: 'en-AU'
646+
});
647+
648+
const docData = logData(document);
649+
650+
document.end();
651+
652+
expect(docData).toContainChunk([
653+
`3 0 obj`,
654+
/\/Lang \(en-AU\)/,
655+
`endobj`
656+
]);
657+
expect(docData).not.toContainChunk([
658+
`3 0 obj`,
659+
/\/MarkInfo 5 0 R/,
660+
`endobj`
661+
]);
662+
expect(docData).not.toContainChunk([
663+
`10 0 obj`,
664+
/\/Tabs \/S/,
665+
`endobj`
666+
]);
626667
});
627668
});
628669

0 commit comments

Comments
 (0)