Skip to content

Commit

Permalink
Move standard structure types methods from validation
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Nov 24, 2023
1 parent abb32d2 commit 9531347
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main/java/org/verapdf/pd/structure/PDStructElem.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
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 java.util.List;
Expand Down Expand Up @@ -128,4 +131,34 @@ public String getRoleMapToSameNamespaceTag() {
public List<Object> getChildren() {
return TaggedPDFHelper.getStructElemChildren(getObject(), rootRoleMap);
}

public static StructureType getStructureElementStandardStructureType(PDStructElem pdStructElem) {
PDFFlavour flavour = StaticResources.getFlavour();
if (flavour == PDFFlavour.PDFA_4 || flavour == PDFFlavour.PDFA_4_E || flavour == PDFFlavour.PDFA_4_F ||
flavour == PDFFlavour.PDFUA_2 || flavour == PDFFlavour.WCAG2_1) {
StructureType defaultStructureType = pdStructElem.getDefaultStructureType();
if (defaultStructureType != null) {
return defaultStructureType;
}
}
if (flavour != PDFFlavour.PDFA_4 && flavour != PDFFlavour.PDFA_4_E && flavour != PDFFlavour.PDFA_4_F &&
flavour != PDFFlavour.PDFUA_2) {
StructureType type = pdStructElem.getStructureType();
if (type != null) {
return StructureType.createStructureType(ASAtom.getASAtom(
StaticResources.getRoleMapHelper().getStandardType(type.getType())));
}
}
return null;
}

public static String getStructureElementStandardType(PDStructElem pdStructElem) {
StructureType type = getStructureElementStandardStructureType(pdStructElem);
return type != null ? type.getType().getValue() : null;
}

public static boolean isMathStandardType(StructureType standardStructureType) {
return StaticResources.getFlavour() == PDFFlavour.PDFUA_2 && standardStructureType != null &&
TaggedPDFConstants.MATH_ML_NAMESPACE.equals(standardStructureType.getNameSpaceURI());
}
}

0 comments on commit 9531347

Please sign in to comment.