Skip to content

Commit

Permalink
Merge pull request #607 from veraPDF/widget_lbl
Browse files Browse the repository at this point in the history
PDF/UA-2. Add method getcontainsLbl to GFPDWidgetAnnot
  • Loading branch information
MaximPlusov authored and Git User committed Nov 6, 2023
1 parent 8f3058a commit 2f79b53
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ abstract class MetadataFixerImpl implements MetadataFixer {
private static final Logger LOGGER = Logger.getLogger(MetadataFixerImpl.class.getCanonicalName());

private static final Map<String, String> attributes = Collections.unmodifiableMap(mkAttsMap());

private static final String ADD_PROPERTY_TO_METADATA_FROM_INFO_DICTIONARY = "Added '%s' to metadata from info dictionary";
private static final String ADD_PROPERTY_TO_INFO_DICTIONARY_FROM_METADATA = "Added '%s' to info dictionary from metadata";

protected MetadataFixerImpl() {
// enabled only for nested classes
Expand Down Expand Up @@ -233,15 +236,15 @@ private static void fixProperty(MetadataFixerResultImpl.Builder resultBuilder, B
String key = attributes.get(attribute);
if (metaValue == null) {
doSaveAction(schema, attribute, infoValue);
resultBuilder.addFix("Added '" + key + "' to metadata from info dictionary");
resultBuilder.addFix(String.format(ADD_PROPERTY_TO_METADATA_FROM_INFO_DICTIONARY, key));
} else {
if (METADATA_AUTHOR.equals(attribute) && ((DublinCore)schema).getAuthorSize() > 1) {
doSaveAction(schema, attribute, metaValue);
resultBuilder.addFix("Merged several creators into one in metadata");
}
if (!metaValue.equals(infoValue)) {
doSaveAction(info, attribute, metaValue);
resultBuilder.addFix("Added '" + attribute + "' to info dictionary from metadata");
resultBuilder.addFix(String.format(ADD_PROPERTY_TO_INFO_DICTIONARY_FROM_METADATA, attribute));
}
}
}
Expand All @@ -257,7 +260,7 @@ private static void fixCalendarProperty(MetadataFixerResultImpl.Builder resultBu
}
if (metaCalendar == null) {
doSaveAction(schema, attribute, infoValue);
resultBuilder.addFix("Added '" + attributes.get(attribute) + "' to metadata from info dictionary");
resultBuilder.addFix(String.format(ADD_PROPERTY_TO_METADATA_FROM_INFO_DICTIONARY, attributes.get(attribute)));
} else {
if (metaCalendar.get(Calendar.MILLISECOND) != 0) {
metaCalendar.set(Calendar.MILLISECOND, 0);
Expand All @@ -267,7 +270,7 @@ private static void fixCalendarProperty(MetadataFixerResultImpl.Builder resultBu
Calendar infoCalendar = DateConverter.toCalendar(infoValue);
if (!infoValue.matches(PDF_DATE_FORMAT_REGEX) || metaCalendar.compareTo(infoCalendar) != 0) {
doSaveAction(info, attribute, DateConverter.toXMPDateFormat(metaCalendar));
resultBuilder.addFix("Added '" + attribute + "' to info dictionary from metadata");
resultBuilder.addFix(String.format(ADD_PROPERTY_TO_INFO_DICTIONARY_FROM_METADATA, attribute));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public class MetadataImpl implements Metadata {
private static final String YEAR_202X = "0000";
private static final String YEAR_REGEX = "^\\d{4}$";

private static String ADD_PROPERTY_MESSAGE = "Added property %s with value %s to Identification schema";
private static String REMOVE_PROPERTY_MESSAGE = "Removed property %s from Identification schema";
private static String SET_PROPERTY_MESSAGE = "Set property %s value to %s in Identification schema";
private static final String ADD_PROPERTY_MESSAGE = "Added property '%s' with value '%s' to Identification schema";
private static final String REMOVE_PROPERTY_MESSAGE = "Removed property '%s' from Identification schema";
private static final String SET_PROPERTY_MESSAGE = "Set property '%s' value to '%s' in Identification schema";


private final VeraPDFMeta metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ void parseOperator(List<org.verapdf.model.operator.Operator> processedOperators,
break;
case Operators.BDC:
PDFAFlavour.Specification specification = StaticContainers.getFlavour().getPart();
if (specification == PDFAFlavour.Specification.ISO_19005_3
|| specification == PDFAFlavour.Specification.ISO_19005_4) {
if (specification == PDFAFlavour.Specification.ISO_19005_3) {
checkAFKey(arguments, resourcesHandler);
}
GFOp_BDC bdcOp = new GFOp_BDC(arguments, resourcesHandler, getCurrentMarkedContent(), structureElementAccessObject, parentsTags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public GFCosDocument(COSDocument cosDocument) {
this.lastID = getTrailerID(cosDocument.getLastTrailer().getKey(ASAtom.ID));
this.firstPageID = getTrailerID(cosDocument.getFirstTrailer().getKey(ASAtom.ID));
PDFAFlavour.Specification specification = StaticContainers.getFlavour().getPart();
if (specification == PDFAFlavour.Specification.ISO_19005_3
|| specification == PDFAFlavour.Specification.ISO_19005_4) {
if (specification == PDFAFlavour.Specification.ISO_19005_3) {
FileSpecificationKeysHelper.registerFileSpecificationKeys(cosDocument);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,9 @@ public String getmostCommonOrientation() {
.collect(Collectors.toList());
return SQUARE_ORIENTATION.equals(twoTheMostFrequent.get(0)) && twoTheMostFrequent.size() == 2 ? twoTheMostFrequent.get(1) : twoTheMostFrequent.get(0);
}

@Override
public Boolean getcontainsXRefStream() {
return document.getDocument().isContainsXRefStream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private boolean hasStandardType(){
if (flavour.getPart() == PDFAFlavour.Specification.ISO_19005_1) {
return TaggedPDFHelper.getPdf14StandardRoleTypes().contains(type.getType().getValue());
}
if (flavour.getPart() == PDFAFlavour.Specification.ISO_19005_4) {
if (flavour.getPart() == PDFAFlavour.Specification.ISO_19005_4 || flavour == PDFAFlavour.PDFUA_2) {
return TaggedPDFHelper.isStandardType(type);
}
if (flavour.getPart() == PDFAFlavour.Specification.WCAG_2_1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
import org.verapdf.as.ASAtom;
import org.verapdf.cos.COSObject;
import org.verapdf.gf.model.impl.pd.GFPDAnnot;
import org.verapdf.gf.model.impl.pd.gfse.GFSEFactory;
import org.verapdf.gf.model.impl.pd.util.PDResourcesHandler;
import org.verapdf.model.pdlayer.PDWidgetAnnot;
import org.verapdf.pd.PDAnnotation;
import org.verapdf.pd.PDPage;
import org.verapdf.pd.annotations.PDWidgetAnnotation;
import org.verapdf.pd.structure.PDStructElem;
import org.verapdf.tools.StaticResources;
import org.verapdf.tools.TaggedPDFConstants;
import org.verapdf.tools.TaggedPDFRoleMapHelper;

/**
* @author Maxim Plushchov
Expand All @@ -49,4 +54,23 @@ public String getTU() {
return ((PDAnnotation) simplePDObject).getTU();
}

@Override
public Boolean getcontainsLbl() {
TaggedPDFRoleMapHelper taggedPDFRoleMapHelper = StaticResources.getRoleMapHelper();
if (taggedPDFRoleMapHelper == null) {
return false;
}
COSObject parent = getParentDictionary();
if (parent != null) {
PDStructElem parentStructElem = new PDStructElem(parent, taggedPDFRoleMapHelper.getRoleMap());
for (PDStructElem child : parentStructElem.getStructChildren()) {
if (TaggedPDFConstants.LBL.equals(GFSEFactory.getStructureElementStandardType(child)) &&
!child.getChildren().isEmpty()) {
return true;
}
}
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public String getparentStructureTag() {
@Override
public String getparentStandardTag() {
TaggedPDFRoleMapHelper taggedPDFRoleMapHelper = StaticResources.getRoleMapHelper();
if (parentStructElem != null) {
if (parentStructElem != null && taggedPDFRoleMapHelper != null) {
PDStructElem structElem = new PDStructElem(parentStructElem, taggedPDFRoleMapHelper.getRoleMap());
return GFSEFactory.getStructureElementStandardType(structElem);
}
Expand All @@ -114,7 +114,7 @@ public Boolean getisArtifact() {

protected Boolean hasParentWithStandardType(String standardType) {
TaggedPDFRoleMapHelper taggedPDFRoleMapHelper = StaticResources.getRoleMapHelper();
if (parentStructElem != null) {
if (parentStructElem != null && taggedPDFRoleMapHelper != null) {
PDStructElem structElem = new PDStructElem(parentStructElem, taggedPDFRoleMapHelper.getRoleMap());
while (structElem != null) {
if (standardType.equals(GFSEFactory.getStructureElementStandardType(structElem))) {
Expand Down

0 comments on commit 2f79b53

Please sign in to comment.