From eed1c37d0de28004621198b9189ec8efbe847a25 Mon Sep 17 00:00:00 2001 From: Maxim Date: Thu, 26 Oct 2023 17:14:09 +0300 Subject: [PATCH] PDF/UA-2. Add new methods --- .../verapdf/gf/model/impl/pd/GFPDAnnot.java | 19 +++++++++++++ .../model/impl/pd/gfse/GFSEContentItem.java | 24 ++++++++++++++++ .../gf/model/impl/pd/gfse/GFSEImageItem.java | 4 +++ .../model/impl/pd/gfse/GFSELineArtItem.java | 6 ++++ .../model/impl/pd/gfse/GFSEShadingItem.java | 5 ++++ .../impl/pd/gfse/GFSESimpleContentItem.java | 28 +++++++++++++++++++ .../gf/model/impl/pd/gfse/GFSETextItem.java | 6 ++++ 7 files changed, 92 insertions(+) diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java index 9c0e22932..36e56b267 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java @@ -46,6 +46,7 @@ import org.verapdf.pd.structure.PDStructTreeRoot; import org.verapdf.pdfa.flavours.PDFAFlavour; import org.verapdf.tools.StaticResources; +import org.verapdf.tools.TaggedPDFConstants; import org.verapdf.tools.TaggedPDFRoleMapHelper; import java.util.ArrayList; @@ -314,6 +315,24 @@ public Boolean getcontainsA() { return this.simplePDObject.knownKey(ASAtom.A); } + @Override + public Boolean getisArtifact() { + TaggedPDFRoleMapHelper taggedPDFRoleMapHelper = StaticResources.getRoleMapHelper(); + if (taggedPDFRoleMapHelper != null) { + COSObject parentDictionary = getParentDictionary(); + if (parentDictionary != null) { + PDStructElem structElem = new PDStructElem(parentDictionary, taggedPDFRoleMapHelper.getRoleMap()); + while (structElem != null) { + if (TaggedPDFConstants.ARTIFACT.equals(GFSEFactory.getStructureElementStandardType(structElem))) { + return true; + } + structElem = structElem.getParent(); + } + } + } + return false; + } + @Override public List getLinkedObjects(String link) { switch (link) { diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEContentItem.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEContentItem.java index e522c3b95..b537bd129 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEContentItem.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEContentItem.java @@ -29,6 +29,7 @@ import org.verapdf.model.selayer.SEContentItem; import org.verapdf.pd.structure.PDStructElem; import org.verapdf.tools.StaticResources; +import org.verapdf.tools.TaggedPDFConstants; import org.verapdf.tools.TaggedPDFRoleMapHelper; import java.util.Collections; @@ -101,4 +102,27 @@ public String getparentStandardTag() { return null; } + @Override + public String getActualText() { + return null; + } + + @Override + public Boolean getisArtifact() { + return hasParentWithStandardType(TaggedPDFConstants.ARTIFACT); + } + + protected Boolean hasParentWithStandardType(String standardType) { + TaggedPDFRoleMapHelper taggedPDFRoleMapHelper = StaticResources.getRoleMapHelper(); + if (parentStructElem != null) { + PDStructElem structElem = new PDStructElem(parentStructElem, taggedPDFRoleMapHelper.getRoleMap()); + while (structElem != null) { + if (standardType.equals(GFSEFactory.getStructureElementStandardType(structElem))) { + return true; + } + structElem = structElem.getParent(); + } + } + return false; + } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEImageItem.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEImageItem.java index 201a88c74..a7a47c58c 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEImageItem.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEImageItem.java @@ -40,4 +40,8 @@ public GFSEImageItem(String objectType, GFOpMarkedContent parentMarkedContentOpe super(objectType, parentMarkedContentOperator, parentStructElem, parentsTags); } + @Override + public String getitemType() { + return IMAGE_CONTENT_ITEM_TYPE; + } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSELineArtItem.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSELineArtItem.java index af78f7fb3..d2a70e910 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSELineArtItem.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSELineArtItem.java @@ -32,6 +32,8 @@ public class GFSELineArtItem extends GFSESimpleContentItem implements SELineArtI public static final String LINE_ART_ITEM_TYPE = "SELineArtItem"; + private static final String LINE_ART_CONTENT_ITEM_TYPE = "lineArt"; + GFOpPathPaint opPathPaint; public GFSELineArtItem(GFOpPathPaint opPathPaint, COSObject parentStructElem, String parentsTags) { @@ -45,4 +47,8 @@ public GFSELineArtItem(GFOpPathPaint opPathPaint, GFOpMarkedContent parentMarked this.opPathPaint = opPathPaint; } + @Override + public String getitemType() { + return LINE_ART_CONTENT_ITEM_TYPE; + } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEShadingItem.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEShadingItem.java index 1bdc1828e..a83f83b16 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEShadingItem.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEShadingItem.java @@ -31,6 +31,7 @@ public class GFSEShadingItem extends GFSESimpleContentItem implements SEShadingItem { public static final String SHADING_ITEM_TYPE = "SEShadingItem"; + private static final String SHADING_CONTENT_ITEM_TYPE = "shading"; private GFOp_sh op_sh; @@ -46,4 +47,8 @@ public GFSEShadingItem(GFOp_sh op_sh, GFOpMarkedContent parentMarkedContentOpera } + @Override + public String getitemType() { + return SHADING_CONTENT_ITEM_TYPE; + } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSESimpleContentItem.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSESimpleContentItem.java index ae673cb75..61659f44e 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSESimpleContentItem.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSESimpleContentItem.java @@ -22,7 +22,9 @@ import org.verapdf.cos.COSObject; import org.verapdf.gf.model.impl.operator.markedcontent.GFOpMarkedContent; +import org.verapdf.cos.COSString; import org.verapdf.model.selayer.SESimpleContentItem; +import org.verapdf.tools.TaggedPDFConstants; /** * @author Maxim Plushchov @@ -37,4 +39,30 @@ public GFSESimpleContentItem(String objectType, GFOpMarkedContent parentMarkedCo COSObject parentStructElem, String parentsTags) { super(objectType, parentMarkedContentOperator, parentStructElem, parentsTags); } + + @Override + public String getActualText() { + if (parentMarkedContentOperator != null) { + COSString actualText = parentMarkedContentOperator.getInheritedActualText(); + if (actualText != null) { + return actualText.getString(); + } + } + return null; + } + + @Override + public String getitemType() { + return null; + } + + @Override + public Boolean getisFigure() { + return hasParentWithStandardType(TaggedPDFConstants.FIGURE); + } + + @Override + public Boolean getisFormula() { + return hasParentWithStandardType(TaggedPDFConstants.FORMULA); + } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSETextItem.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSETextItem.java index f402b7a74..4ba306eb8 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSETextItem.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSETextItem.java @@ -35,6 +35,7 @@ public class GFSETextItem extends GFSESimpleContentItem implements SETextItem { public static final String TEXT_ITEM_TYPE = "SETextItem"; + private static final String TEXT_CONTENT_ITEM_TYPE = "text"; private final GFOpTextShow opTextShow; private final String defaultLang; @@ -78,4 +79,9 @@ public String getLang() { String parentLang = parentMarkedContentOperator.getParentLang(); return parentLang != null ? parentLang : this.defaultLang; } + + @Override + public String getitemType() { + return TEXT_CONTENT_ITEM_TYPE; + } }