@@ -68,6 +68,9 @@ This file is part of the iText (R) project.
68
68
import java .util .Map ;
69
69
import java .util .concurrent .ConcurrentHashMap ;
70
70
71
+ /**
72
+ * Represents a wrapper-class for structure tree root dictionary. See ISO-32000-1 "14.7.2 Structure hierarchy".
73
+ */
71
74
public class PdfStructTreeRoot extends PdfObjectWrapper <PdfDictionary > implements IStructureNode {
72
75
73
76
private static final long serialVersionUID = 2168384302241193868L ;
@@ -77,21 +80,40 @@ public class PdfStructTreeRoot extends PdfObjectWrapper<PdfDictionary> implement
77
80
78
81
private static Map <String , PdfName > staticRoleNames = new ConcurrentHashMap <>();
79
82
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
+ */
80
90
public PdfStructTreeRoot (PdfDocument document ) {
81
91
this ((PdfDictionary ) new PdfDictionary ().makeIndirect (document ), document );
82
92
getPdfObject ().put (PdfName .Type , PdfName .StructTreeRoot );
83
93
}
84
94
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 );
87
105
this .document = document ;
88
106
if (this .document == null ) {
89
- ensureObjectIsAddedToDocument (pdfObject );
90
- this .document = pdfObject .getIndirectReference ().getDocument ();
107
+ ensureObjectIsAddedToDocument (structTreeRootDict );
108
+ this .document = structTreeRootDict .getIndirectReference ().getDocument ();
91
109
}
92
110
setForbidRelease ();
93
111
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.
95
117
getRoleMap ();
96
118
}
97
119
0 commit comments