Skip to content

Commit 1959f7d

Browse files
yulian-gaponenkoiText-CI
authored andcommitted
Improve StructTreeRoot documentation
DEVSIX-4812
1 parent 9a47f5f commit 1959f7d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfDocument.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,8 @@ public PdfDocument setTagged() {
10771077
/**
10781078
* Gets {@link PdfStructTreeRoot} of tagged document.
10791079
*
1080-
* @return {@link PdfStructTreeRoot} in case tagged document, otherwise false.
1080+
* @return {@link PdfStructTreeRoot} in case document is tagged, otherwise it returns null.
1081+
*
10811082
* @see #isTagged()
10821083
* @see #getNextStructParentIndex()
10831084
*/
@@ -1089,6 +1090,7 @@ public PdfStructTreeRoot getStructTreeRoot() {
10891090
* Gets next parent index of tagged document.
10901091
*
10911092
* @return -1 if document is not tagged, or >= 0 if tagged.
1093+
*
10921094
* @see #isTagged()
10931095
* @see #getNextStructParentIndex()
10941096
*/

kernel/src/main/java/com/itextpdf/kernel/pdf/tagging/PdfStructTreeRoot.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ This file is part of the iText (R) project.
6868
import java.util.Map;
6969
import java.util.concurrent.ConcurrentHashMap;
7070

71+
/**
72+
* Represents a wrapper-class for structure tree root dictionary. See ISO-32000-1 "14.7.2 Structure hierarchy".
73+
*/
7174
public class PdfStructTreeRoot extends PdfObjectWrapper<PdfDictionary> implements IStructureNode {
7275

7376
private static final long serialVersionUID = 2168384302241193868L;
@@ -77,21 +80,40 @@ public class PdfStructTreeRoot extends PdfObjectWrapper<PdfDictionary> implement
7780

7881
private static Map<String, PdfName> staticRoleNames = new ConcurrentHashMap<>();
7982

83+
/**
84+
* Creates a new structure tree root instance, this initializes empty logical structure in the document.
85+
* This class also handles global state of parent tree, so it's not expected to create multiple instances
86+
* of this class. Instead, use {@link PdfDocument#getStructTreeRoot()}.
87+
*
88+
* @param document a document to which new instance of struct tree root will be bound
89+
*/
8090
public PdfStructTreeRoot(PdfDocument document) {
8191
this((PdfDictionary) new PdfDictionary().makeIndirect(document), document);
8292
getPdfObject().put(PdfName.Type, PdfName.StructTreeRoot);
8393
}
8494

85-
public PdfStructTreeRoot(PdfDictionary pdfObject, PdfDocument document) {
86-
super(pdfObject);
95+
/**
96+
* Creates wrapper instance for already existing logical structure tree root in the document.
97+
* This class also handles global state of parent tree, so it's not expected to create multiple instances
98+
* of this class. Instead, use {@link PdfDocument#getStructTreeRoot()}.
99+
*
100+
* @param structTreeRootDict a dictionary that defines document structure tree root
101+
* @param document a document, which contains given structure tree root dictionary
102+
*/
103+
public PdfStructTreeRoot(PdfDictionary structTreeRootDict, PdfDocument document) {
104+
super(structTreeRootDict);
87105
this.document = document;
88106
if (this.document == null) {
89-
ensureObjectIsAddedToDocument(pdfObject);
90-
this.document = pdfObject.getIndirectReference().getDocument();
107+
ensureObjectIsAddedToDocument(structTreeRootDict);
108+
this.document = structTreeRootDict.getIndirectReference().getDocument();
91109
}
92110
setForbidRelease();
93111
parentTreeHandler = new ParentTreeHandler(this);
94-
// TODO may be remove?
112+
113+
// Always init role map dictionary in order to avoid inconsistency, because
114+
// iText often initializes it during role mapping resolution anyway.
115+
// In future, better way might be to not write it to the document needlessly
116+
// and avoid possible redundant modifications in append mode.
95117
getRoleMap();
96118
}
97119

0 commit comments

Comments
 (0)