Skip to content

Commit

Permalink
Support ClassMap
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Dec 5, 2023
1 parent 0f4d11a commit 0dbaa99
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/verapdf/as/ASAtom.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public class ASAtom implements Comparable<ASAtom> {
public static final ASAtom CID_TO_GID_MAP = new ASAtom("CIDToGIDMap");
public static final ASAtom CID_SET = new ASAtom("CIDSet");
public static final ASAtom CID_SYSTEM_INFO = new ASAtom("CIDSystemInfo");
public static final ASAtom CLASS_MAP = new ASAtom("ClassMap");
public static final ASAtom CLR_F = new ASAtom("ClrF");
public static final ASAtom CLR_FF = new ASAtom("ClrFf");
public static final ASAtom CMAP = new ASAtom("CMap");
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/verapdf/pd/structure/PDStructTreeRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public Map<ASAtom, ASAtom> getRoleMap() {
return Collections.emptyMap();
}

public COSObject getClassMap() {
return getKey(ASAtom.CLASS_MAP);
}

public PDNumberTreeNode getParentTree() {
COSObject parentTree = getKey(ASAtom.PARENT_TREE);
if (parentTree != null && parentTree.getType().isDictionaryBased()) {
Expand Down
39 changes: 32 additions & 7 deletions src/main/java/org/verapdf/tools/AttributeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,46 @@ private static Long getIntegerAttributeValue(org.verapdf.pd.PDObject simplePDObj
}

private static COSObject getAttributeValue(org.verapdf.pd.PDObject simplePDObject, ASAtom attributeName, String O,
COSObjType type) {
COSObject attributeValue = getAttributeValue(simplePDObject.getKey(ASAtom.A), attributeName, O, type);
if (attributeValue == null) {
COSObject className = simplePDObject.getKey(ASAtom.C);
COSObject classMap = StaticResources.getDocument().getStructTreeRoot().getClassMap();
if (className != null && classMap != null) {
if (className.getType() == COSObjType.COS_NAME) {
attributeValue = getAttributeValue(classMap.getKey(className.getName()),
attributeName, O, type);
} else if (className.getType() == COSObjType.COS_ARRAY) {
for (COSObject entry : (COSArray)className.getDirectBase()) {
if (entry != null && entry.getType() == COSObjType.COS_NAME) {
attributeValue = getAttributeValue(classMap.getKey(entry.getName()),
attributeName, O, type);
if (attributeValue != null) {
break;
}
}
}
}
}
}
return attributeValue != null ? attributeValue : COSObject.getEmpty();
}

private static COSObject getAttributeValue(COSObject attributeObject, ASAtom attributeName, String O,
COSObjType type) {
COSObject aValue = simplePDObject.getKey(ASAtom.A);
if (aValue == null) {
return COSObject.getEmpty();
if (attributeObject == null) {
return null;
}
if (aValue.getType() == COSObjType.COS_ARRAY) {
for (COSObject object : (COSArray) aValue.getDirectBase()) {
if (attributeObject.getType() == COSObjType.COS_ARRAY) {
for (COSObject object : (COSArray) attributeObject.getDirectBase()) {
COSObject value = getAttributeValue(object, attributeName, O);
if (value.getType() == type) {
return value;
}
}
}
COSObject value = getAttributeValue(aValue, attributeName, O);
return value.getType() == type ? value : COSObject.getEmpty();
COSObject value = getAttributeValue(attributeObject, attributeName, O);
return value.getType() == type ? value : null;
}

private static COSObject getAttributeValue(COSObject object, ASAtom attributeName, String O) {
Expand Down

0 comments on commit 0dbaa99

Please sign in to comment.