Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ClassMap #609

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading