diff --git a/src/main/java/org/verapdf/as/ASAtom.java b/src/main/java/org/verapdf/as/ASAtom.java index 89122324..a57b889e 100644 --- a/src/main/java/org/verapdf/as/ASAtom.java +++ b/src/main/java/org/verapdf/as/ASAtom.java @@ -134,6 +134,7 @@ public class ASAtom implements Comparable { 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"); diff --git a/src/main/java/org/verapdf/pd/structure/PDStructTreeRoot.java b/src/main/java/org/verapdf/pd/structure/PDStructTreeRoot.java index 9b501417..46519a5a 100644 --- a/src/main/java/org/verapdf/pd/structure/PDStructTreeRoot.java +++ b/src/main/java/org/verapdf/pd/structure/PDStructTreeRoot.java @@ -64,6 +64,10 @@ public Map 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()) { diff --git a/src/main/java/org/verapdf/tools/AttributeHelper.java b/src/main/java/org/verapdf/tools/AttributeHelper.java index a5232b76..d333a770 100644 --- a/src/main/java/org/verapdf/tools/AttributeHelper.java +++ b/src/main/java/org/verapdf/tools/AttributeHelper.java @@ -4,6 +4,7 @@ import org.verapdf.cos.COSArray; import org.verapdf.cos.COSObjType; import org.verapdf.cos.COSObject; +import org.verapdf.pd.structure.PDStructTreeRoot; public class AttributeHelper { @@ -67,21 +68,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); + if (className != null) { + PDStructTreeRoot structTreeRoot = StaticResources.getDocument().getStructTreeRoot(); + if (className.getType() == COSObjType.COS_NAME) { + attributeValue = getAttributeValue(structTreeRoot.getClassMap().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(structTreeRoot.getClassMap().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) {