-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathPDStructElem.java
More file actions
177 lines (151 loc) · 5.62 KB
/
PDStructElem.java
File metadata and controls
177 lines (151 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* This file is part of veraPDF Parser, a module of the veraPDF project.
* Copyright (c) 2015-2025, veraPDF Consortium <info@verapdf.org>
* All rights reserved.
*
* veraPDF Parser is free software: you can redistribute it and/or modify
* it under the terms of either:
*
* The GNU General public license GPLv3+.
* You should have received a copy of the GNU General Public License
* along with veraPDF Parser as the LICENSE.GPL file in the root of the source
* tree. If not, see http://www.gnu.org/licenses/ or
* https://www.gnu.org/licenses/gpl-3.0.en.html.
*
* The Mozilla Public License MPLv2+.
* You should have received a copy of the Mozilla Public License along with
* veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
* If a copy of the MPL was not distributed with this file, you can obtain one at
* http://mozilla.org/MPL/2.0/.
*/
package org.verapdf.pd.structure;
import org.verapdf.as.ASAtom;
import org.verapdf.cos.COSName;
import org.verapdf.cos.COSObjType;
import org.verapdf.cos.COSObject;
import org.verapdf.cos.COSString;
import org.verapdf.cos.COSKey;
import org.verapdf.parser.PDFFlavour;
import org.verapdf.tools.StaticResources;
import org.verapdf.tools.TaggedPDFConstants;
import org.verapdf.tools.TaggedPDFHelper;
import org.verapdf.tools.TaggedPDFRoleMapHelper;
import java.util.List;
/**
* @author Maksim Bezrukov
*/
public class PDStructElem extends PDStructTreeNode {
public PDStructElem(COSObject obj) {
super(obj);
}
public ASAtom getType() {
return getObject().getNameKey(ASAtom.TYPE);
}
public COSName getCOSStructureType() {
COSObject object = getKey(ASAtom.S);
if (object != null && object.getType() == COSObjType.COS_NAME) {
return (COSName) object.getDirectBase();
}
return null;
}
public COSString getLang() {
COSObject object = getKey(ASAtom.LANG);
if (object != null && object.getType() == COSObjType.COS_STRING) {
return (COSString) object.getDirectBase();
}
return null;
}
public PDStructureNameSpace getNameSpace() {
COSObject object = getKey(ASAtom.NS);
if (object != null && object.getType() == COSObjType.COS_DICT) {
return PDStructureNameSpace.createNameSpace(object);
}
return null;
}
public StructureType getStructureType() {
return StructureType.createStructureType(getKey(ASAtom.S), getKey(ASAtom.NS));
}
public COSObject getActualText() {
return getKey(ASAtom.ACTUAL_TEXT);
}
public COSObject getRef() {
return getKey(ASAtom.REF);
}
public boolean containsRef() {
return knownKey(ASAtom.REF);
}
public String getAlternateDescription() {
return getStringKey(ASAtom.ALT);
}
public String getExpandedAbbreviation() {
return getStringKey(ASAtom.E);
}
public PDStructElem getParent() {
COSObject parentObject = getKey(ASAtom.P);
if (parentObject != null) {
return new PDStructElem(parentObject);
}
return null;
}
public COSKey getPageObjectNumber() {
COSObject object = getObject().getKey(ASAtom.PG);
if (object != null) {
return object.getKey();
}
return null;
}
public StructureType getDefaultStructureType() {
return getDefaultStructureType(this.getStructureType());
}
public static StructureType getDefaultStructureType(StructureType structureType) {
return TaggedPDFHelper.getDefaultStructureType(structureType);
}
public String getRoleMapToSameNamespaceTag() {
return TaggedPDFHelper.getRoleMapToSameNamespaceTag(getStructureType());
}
public static StructureType getStructureElementStandardStructureType(PDStructElem pdStructElem) {
return getStructureTypeStandardStructureType(pdStructElem.getStructureType());
}
public static StructureType getStructureTypeStandardStructureType(StructureType type) {
List<PDFFlavour> flavour = StaticResources.getFlavour();
if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0)) {
StructureType defaultStructureType = PDStructElem.getDefaultStructureType(type);
if (defaultStructureType != null) {
return defaultStructureType;
}
}
if (!PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0)) {
if (type != null) {
return StructureType.createStructureType(ASAtom.getASAtom(
StaticResources.getRoleMapHelper().getStandardType(type.getType())), type.getNameSpace());
}
}
return null;
}
public static String getStructureTypeStandardType(StructureType structureType) {
StructureType type = getStructureTypeStandardStructureType(structureType);
return type != null ? type.getType().getValue() : null;
}
public static String getStructureElementStandardType(PDStructElem pdStructElem) {
StructureType type = getStructureElementStandardStructureType(pdStructElem);
return type != null ? type.getType().getValue() : null;
}
public static boolean isStandardStructureType(StructureType type) {
List<PDFFlavour> flavour = StaticResources.getFlavour();
boolean isStandard = false;
if (PDFFlavour.isFlavourPDFSpecification(flavour, PDFFlavour.PDFSpecification.ISO_32000_2_0)) {
isStandard = TaggedPDFHelper.isStandardType(type);
} else if (type != null) {
isStandard |= TaggedPDFRoleMapHelper.isStandardType(type);
}
return isStandard;
}
public static boolean isMathStandardType(StructureType standardStructureType) {
return PDFFlavour.isPDFUA2RelatedFlavour(StaticResources.getFlavour()) && standardStructureType != null &&
TaggedPDFConstants.MATH_ML_NAMESPACE.equals(standardStructureType.getNameSpaceURI());
}
public static boolean isPassThroughTag(String structureType) {
return TaggedPDFConstants.NON_STRUCT.equals(structureType) || TaggedPDFConstants.DIV.equals(structureType) ||
TaggedPDFConstants.PART.equals(structureType);
}
}