Skip to content

Commit

Permalink
Merge pull request #600 from veraPDF/pdfua2
Browse files Browse the repository at this point in the history
PDF/UA-2. Add new methods
  • Loading branch information
MaximPlusov authored Oct 31, 2023
2 parents 8fc1190 + eed1c37 commit 590ac5b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<? extends Object> getLinkedObjects(String link) {
switch (link) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ public GFSEImageItem(String objectType, GFOpMarkedContent parentMarkedContentOpe
super(objectType, parentMarkedContentOperator, parentStructElem, parentsTags);
}

@Override
public String getitemType() {
return IMAGE_CONTENT_ITEM_TYPE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -45,4 +47,8 @@ public GFSELineArtItem(GFOpPathPaint opPathPaint, GFOpMarkedContent parentMarked
this.opPathPaint = opPathPaint;
}

@Override
public String getitemType() {
return LINE_ART_CONTENT_ITEM_TYPE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -46,4 +47,8 @@ public GFSEShadingItem(GFOp_sh op_sh, GFOpMarkedContent parentMarkedContentOpera

}

@Override
public String getitemType() {
return SHADING_CONTENT_ITEM_TYPE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 590ac5b

Please sign in to comment.