Skip to content

Commit

Permalink
Merge pull request #609 from veraPDF/signature_content
Browse files Browse the repository at this point in the history
PDF/UA-2. Update content item logic
  • Loading branch information
MaximPlusov authored Nov 9, 2023
2 parents c128a0e + 9852bb4 commit e69959c
Show file tree
Hide file tree
Showing 17 changed files with 273 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,22 @@ public COSString getInheritedActualText() {
return getInheritedStringAttribute(ASAtom.ACTUAL_TEXT);
}

public COSString getInheritedAlt() {
return getInheritedStringAttribute(ASAtom.ALT);
}

public COSString getInheritedStringAttribute(ASAtom key) {
COSString string = getStringAttribute(key);
if (string != null) {
return null;
}
if (markedContent != null) {
COSString string = markedContent.getInheritedStringAttribute(key);
string = markedContent.getInheritedStringAttribute(key);
if (string != null) {
return string;
}
}
return getStringAttribute(key);
return null;
}

public COSString getStringAttribute(ASAtom key) {
Expand All @@ -249,13 +257,17 @@ public COSString getStringAttribute(ASAtom key) {


public Long getInheritedMCID() {
Long mcid = getMCID();
if (mcid != null) {
return mcid;
}
if (markedContent != null) {
Long mcid = markedContent.getInheritedMCID();
mcid = markedContent.getInheritedMCID();
if (mcid != null) {
return mcid;
}
}
return getMCID();
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ private List<PDAction> getA() {
}
return Collections.emptyList();
}

protected boolean isSignature() {
return false;
}

/**
* @return normal appearance stream (N key in the appearance dictionary) of
Expand Down Expand Up @@ -424,7 +428,7 @@ private void addAppearance(List<PDXForm> list, PDAppearanceStream toAdd) {
PDResourcesHandler resources = this.resources.getExtendedResources(toAdd.getResources());
List<CosLang> annotLang = getLang();
GFPDXForm xForm = new GFPDXForm(toAdd, resources, null, getParentDictionary(), "",
annotLang.isEmpty() ? null : annotLang.get(0).getunicodeValue());
annotLang.isEmpty() ? null : annotLang.get(0).getunicodeValue(), isSignature());
this.containsTransparency |= xForm.containsTransparency();
list.add(xForm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.verapdf.gf.model.impl.operator.markedcontent.GFOp_BDC;
import org.verapdf.gf.model.impl.operator.markedcontent.GFOp_BMC;
import org.verapdf.gf.model.impl.operator.markedcontent.GFOp_EMC;
import org.verapdf.gf.model.impl.pd.gfse.GFSEMarkedContent;
import org.verapdf.gf.model.impl.pd.gfse.GFSEUnmarkedContent;
import org.verapdf.gf.model.impl.pd.gfse.contents.GFSEMarkedContent;
import org.verapdf.gf.model.impl.pd.gfse.contents.GFSEUnmarkedContent;
import org.verapdf.gf.model.impl.pd.util.PDResourcesHandler;
import org.verapdf.model.pdlayer.PDSemanticContentStream;
import org.verapdf.model.selayer.SEContentItem;
Expand All @@ -48,6 +48,8 @@ public class GFPDSemanticContentStream extends GFPDContentStream implements PDSe
public static final String SEMANTIC_CONTENT_STREAM_TYPE = "PDSemanticContentStream";

private String defaultLang;

private boolean isSignature = false;

public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler,
GraphicState inheritedGraphicState,
Expand All @@ -63,14 +65,13 @@ public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream, P
parentsTags, SEMANTIC_CONTENT_STREAM_TYPE);
}

public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream,
PDResourcesHandler resourcesHandler,
GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject,
COSObject parentStructElem, String parentsTags, String defaultLang) {
public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler,
GraphicState inheritedGraphicState, StructureElementAccessObject structureElementAccessObject,
COSObject parentStructElem, String parentsTags, String defaultLang, boolean isSignature) {
this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentStructElem,
parentsTags);
this.defaultLang = defaultLang;
this.isSignature = isSignature;
}

@Override
Expand All @@ -96,15 +97,15 @@ private List<SEContentItem> getContentItem() {
if (GFOp_BDC.OP_BDC_TYPE.equals(type) || GFOp_BMC.OP_BMC_TYPE.equals(type)) {
if (markedContentStack.empty() && i != markedContentIndex + 1) {
list.add(new GFSEUnmarkedContent(operators.subList(unmarkedContentIndex, i), parentStructElem,
parentsTags, defaultLang));
parentsTags, defaultLang, isSignature));
}
markedContentStack.push(i);
} else if (GFOp_EMC.OP_EMC_TYPE.equals(type)) {
if (!markedContentStack.empty()) {
markedContentIndex = markedContentStack.pop();
if (markedContentStack.empty()) {
list.add(new GFSEMarkedContent(operators.subList(markedContentIndex, i + 1), parentStructElem,
parentsTags, defaultLang));
parentsTags, defaultLang, isSignature));
markedContentIndex = i;
unmarkedContentIndex = i + 1;
}
Expand All @@ -113,7 +114,7 @@ private List<SEContentItem> getContentItem() {
}
if (unmarkedContentIndex != operators.size()) {
list.add(new GFSEUnmarkedContent(operators.subList(unmarkedContentIndex, operators.size()),
parentStructElem, parentsTags, defaultLang));
parentStructElem, parentsTags, defaultLang, isSignature));
}
return Collections.unmodifiableList(list);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,31 @@ public GFPDWidgetAnnot(PDWidgetAnnotation annot, PDResourcesHandler pageResource

@Override
public String getTU() {
if (((PDWidgetAnnotation) simplePDObject).getT() == null) {
if (!isField()) {
COSObject parent = ((PDWidgetAnnotation) simplePDObject).getParent();
return parent != null ? parent.getStringKey(ASAtom.TU) : null;
}
return ((PDAnnotation) simplePDObject).getTU();
}

private boolean isField() {
return ((PDWidgetAnnotation) simplePDObject).getT() != null;
}

@Override
protected boolean isSignature() {
ASAtom FT = null;
if (!isField()) {
COSObject parent = ((PDWidgetAnnotation) simplePDObject).getParent();
if (parent != null) {
FT = parent.getNameKey(ASAtom.FT);
}
} else {
FT = ((PDAnnotation) simplePDObject).getFT();
}
return ASAtom.SIG.equals(FT);
}

@Override
public Boolean getcontainsLbl() {
TaggedPDFRoleMapHelper taggedPDFRoleMapHelper = StaticResources.getRoleMapHelper();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* This file is part of veraPDF Validation, a module of the veraPDF project.
* Copyright (c) 2015, veraPDF Consortium <[email protected]>
* All rights reserved.
*
* veraPDF Validation is free software: you can redistribute it and/or modify
* it under the terms of either:
*
* The GNU General public license GPLv3+.
* You should have received a copy of the GNU General Public License
* along with veraPDF Validation as the LICENSE.GPL file in the root of the source
* tree. If not, see http://www.gnu.org/licenses/ or
* https://www.gnu.org/licenses/gpl-3.0.en.html.
*
* The Mozilla Public License MPLv2+.
* You should have received a copy of the Mozilla Public License along with
* veraPDF Validation as the LICENSE.MPL file in the root of the source tree.
* If a copy of the MPL was not distributed with this file, you can obtain one at
* http://mozilla.org/MPL/2.0/.
*/
package org.verapdf.gf.model.impl.pd.gfse.contents;

import org.verapdf.model.GenericModelObject;
import org.verapdf.model.selayer.SEContentItem;

/**
* @author Maxim Plushchov
*/
public abstract class GFSEContentItem extends GenericModelObject implements SEContentItem {

public static final String CONTENT_ITEM = "contentItem";

public GFSEContentItem(String objectType) {
super(objectType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,72 +18,39 @@
* If a copy of the MPL was not distributed with this file, you can obtain one at
* http://mozilla.org/MPL/2.0/.
*/
package org.verapdf.gf.model.impl.pd.gfse;
package org.verapdf.gf.model.impl.pd.gfse.contents;

import org.verapdf.as.ASAtom;
import org.verapdf.cos.COSObject;
import org.verapdf.gf.model.impl.operator.markedcontent.GFOpMarkedContent;
import org.verapdf.model.GenericModelObject;
import org.verapdf.model.baselayer.Object;
import org.verapdf.gf.model.impl.pd.gfse.GFSEFactory;
import org.verapdf.model.operator.Operator;
import org.verapdf.model.selayer.SEContentItem;
import org.verapdf.model.selayer.SEGroupedContent;
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;
import java.util.List;

/**
* @author Maxim Plushchov
*/
public abstract class GFSEContentItem extends GenericModelObject implements SEContentItem {

public static final String CONTENT_ITEM = "contentItem";

protected Long parentMCID;
protected GFOpMarkedContent parentMarkedContentOperator;

public abstract class GFSEGroupedContent extends GFSEContentItem implements SEGroupedContent {

List<Operator> operators;
protected COSObject parentStructElem;
protected String parentsTags;

public GFSEContentItem(String objectType, COSObject parentStructElem, String parentsTags) {
super(objectType);
this.parentStructElem = parentStructElem;
this.parentsTags = parentsTags;
}

public GFSEContentItem(String objectType, GFOpMarkedContent parentMarkedContentOperator, COSObject parentStructElem,
String parentsTags) {
protected boolean isSignature;
protected final String defaultLang;

public GFSEGroupedContent(String objectType, COSObject parentStructElem, String parentsTags, String defaultLang,
boolean isSignature) {
super(objectType);
this.parentMarkedContentOperator = parentMarkedContentOperator;
this.parentMCID = parentMarkedContentOperator != null ? parentMarkedContentOperator.getMCID() : null;
this.parentStructElem = parentStructElem;
this.parentsTags = parentsTags;
}

@Override
public String getExtraContext() {
return parentMCID != null ? "mcid:" + parentMCID : null;
}

@Override
public List<? extends Object> getLinkedObjects(String link) {
switch (link) {
case CONTENT_ITEM:
return Collections.emptyList();
default:
return super.getLinkedObjects(link);
}
this.defaultLang = defaultLang;
this.isSignature = isSignature;
}

@Override
public String getparentsTags() {
if (parentMarkedContentOperator != null) {
return parentMarkedContentOperator.getParentsTags();
}
return parentsTags;
}

Expand All @@ -103,8 +70,12 @@ public String getparentStandardTag() {
}

@Override
public String getActualText() {
return null;
public Boolean getisSignature() {
return isSignature;
}

public String getLang() {
return defaultLang;
}

@Override
Expand All @@ -125,4 +96,26 @@ protected Boolean hasParentWithStandardType(String standardType) {
}
return false;
}

public String getInheritedActualText() {
return null;
}

public String getInheritedAlt() {
return null;
}

public Long getMCID() {
return null;
}

@Override
public String getActualText() {
return null;
}

@Override
public String getAlt() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
* If a copy of the MPL was not distributed with this file, you can obtain one at
* http://mozilla.org/MPL/2.0/.
*/
package org.verapdf.gf.model.impl.pd.gfse;
package org.verapdf.gf.model.impl.pd.gfse.contents;

import org.verapdf.cos.COSObject;
import org.verapdf.gf.model.impl.operator.markedcontent.GFOpMarkedContent;
import org.verapdf.model.selayer.SEImageItem;

/**
Expand All @@ -31,13 +29,8 @@ public class GFSEImageItem extends GFSESimpleContentItem implements SEImageItem

private static final String IMAGE_CONTENT_ITEM_TYPE = "image";

public GFSEImageItem(String objectType, COSObject parentStructElem, String parentsTags) {
super(objectType, parentStructElem, parentsTags);
}

public GFSEImageItem(String objectType, GFOpMarkedContent parentMarkedContentOperator,
COSObject parentStructElem, String parentsTags) {
super(objectType, parentMarkedContentOperator, parentStructElem, parentsTags);
public GFSEImageItem(String objectType, GFSEGroupedContent groupedContent) {
super(objectType, groupedContent);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
* If a copy of the MPL was not distributed with this file, you can obtain one at
* http://mozilla.org/MPL/2.0/.
*/
package org.verapdf.gf.model.impl.pd.gfse;
package org.verapdf.gf.model.impl.pd.gfse.contents;

import org.verapdf.cos.COSObject;
import org.verapdf.gf.model.impl.operator.markedcontent.GFOpMarkedContent;
import org.verapdf.gf.model.impl.operator.xobject.GFOp_Do;
import org.verapdf.gf.model.impl.pd.images.GFPDXImage;
import org.verapdf.model.selayer.SEImageXObjectItem;
Expand All @@ -33,20 +31,12 @@ public class GFSEImageXObjectItem extends GFSEImageItem implements SEImageXObjec

public static final String IMAGE_X_OBJECT_ITEM_TYPE = "SEImageXObjectItem";

private GFOp_Do operator;
private GFPDXImage image;
private final GFOp_Do operator;
private final GFPDXImage image;

public GFSEImageXObjectItem(GFOp_Do operator, GFPDXImage image, COSObject parentStructElem, String parentsTags) {
super(IMAGE_X_OBJECT_ITEM_TYPE, parentStructElem, parentsTags);
public GFSEImageXObjectItem(GFOp_Do operator, GFPDXImage image, GFSEGroupedContent groupedContent) {
super(IMAGE_X_OBJECT_ITEM_TYPE, groupedContent);
this.operator = operator;
this.image = image;
}

public GFSEImageXObjectItem(GFOp_Do operator, GFPDXImage image, GFOpMarkedContent parentMarkedContentOperator,
COSObject parentStructElem, String parentsTags) {
super(IMAGE_X_OBJECT_ITEM_TYPE, parentMarkedContentOperator, parentStructElem, parentsTags);
this.operator = operator;
this.image = image;
}

}
Loading

0 comments on commit e69959c

Please sign in to comment.