Skip to content

Commit

Permalink
Replace parentStructureTag to parentStructElem in GFSEContentItem
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Oct 25, 2023
1 parent 32ce058 commit 4193b93
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.verapdf.gf.model.factory.operators;

import org.verapdf.cos.COSBase;
import org.verapdf.cos.COSObject;
import org.verapdf.gf.model.impl.pd.util.PDResourcesHandler;
import org.verapdf.gf.model.tools.TransparencyBehaviour;
import org.verapdf.model.tools.constants.Operators;
Expand Down Expand Up @@ -96,12 +97,12 @@ public boolean isLastParsedContainsTransparency() {
}

public List<org.verapdf.model.operator.Operator> operatorsFromTokens(List<Object> rawTokens,
PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject, String parentStructureTag, String parentsTags) {
PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject, COSObject parentStructElem, String parentsTags) {
List<org.verapdf.model.operator.Operator> result = new ArrayList<>();
List<COSBase> arguments = new ArrayList<>();
this.isLastParsedContainsTransparency = false;
OperatorParser parser = new OperatorParser(inheritedGraphicState, structureElementAccessObject, resourcesHandler, parentStructureTag, parentsTags);
OperatorParser parser = new OperatorParser(inheritedGraphicState, structureElementAccessObject, resourcesHandler, parentStructElem, parentsTags);

for (Object rawToken : rawTokens) {
if (rawToken instanceof COSBase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ class OperatorParser {
private final Stack<GFOpMarkedContent> markedContentStack = new Stack<>();
private final StructureElementAccessObject structureElementAccessObject;
private final TransparencyGraphicsState transparencyGraphicState = new TransparencyGraphicsState();
private final String parentStructureTag;
private final COSObject parentStructElem;
private final String parentsTags;

private boolean insideText = false;

OperatorParser(GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject,
PDResourcesHandler resourcesHandler, String parentStructureTag, String parentsTags) {
StructureElementAccessObject structureElementAccessObject,
PDResourcesHandler resourcesHandler, COSObject parentStructElem, String parentsTags) {
if (inheritedGraphicState == null) {
this.graphicState = new GraphicState(resourcesHandler);
} else {
this.graphicState = inheritedGraphicState.clone();
}
this.graphicState.setInitialGraphicState(this.graphicState);
this.structureElementAccessObject = structureElementAccessObject;
this.parentStructureTag = parentStructureTag;
this.parentStructElem = parentStructElem;
this.parentsTags = parentsTags;
}

Expand Down Expand Up @@ -517,12 +517,12 @@ void parseOperator(List<org.verapdf.model.operator.Operator> processedOperators,
mcid = markedContentStack.peek().getInheritedMCID();
parentsTags = markedContentStack.peek().getParentsTags();
}
String parentStructureTag = getParentStructureTag(structureElementAccessObject, mcid);
if (parentStructureTag == null) {
parentStructureTag = this.parentStructureTag;
COSObject parentStructElem = getParentStructElem(structureElementAccessObject, mcid);
if (parentStructElem == null) {
parentStructElem = this.parentStructElem;
}
GFOp_Do op_do = new GFOp_Do(arguments, resourcesHandler.getXObject(getLastCOSName(arguments)),
resourcesHandler, this.graphicState.clone(), parentStructureTag, parentsTags);
resourcesHandler, this.graphicState.clone(), parentStructElem, parentsTags);
List<org.verapdf.model.pdlayer.PDXObject> pdxObjects = op_do.getXObject();
if (!pdxObjects.isEmpty()) {
GFPDXObject xobj = (GFPDXObject) pdxObjects.get(0);
Expand Down Expand Up @@ -690,13 +690,13 @@ private GFOpMarkedContent getCurrentMarkedContent() {
return this.markedContentStack.peek();
}

private String getParentStructureTag(StructureElementAccessObject structureElementAccessObject, Long mcid) {
private COSObject getParentStructElem(StructureElementAccessObject structureElementAccessObject, Long mcid) {
PDStructTreeRoot structTreeRoot = StaticResources.getDocument().getStructTreeRoot();
if (structTreeRoot != null) {
PDNumberTreeNode parentTreeRoot = structTreeRoot.getParentTree();
COSObject structureElement = parentTreeRoot == null ? null : structureElementAccessObject.getStructureElement(parentTreeRoot, mcid);
if (structureElement != null && !structureElement.empty()) {
return structureElement.getNameKeyStringValue(ASAtom.S);
return structureElement;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public String getParentLang() {
if (markedContent == null) {
return null;
}
List<CosLang> lang = markedContent.getLang();
List<CosLang> lang = markedContent.getLang();
if (lang != null && lang.size() != 0) {
return lang.get(0).getunicodeValue();
}
Expand All @@ -162,17 +162,8 @@ public String getParentLang() {
return markedContent.getParentLang();
}

public String getParentStructureTag() {
if (markedContent != null) {
if (GFOp_BDC.OP_BDC_TYPE.equals(markedContent.getObjectType())) {
String structTag = ((GFOp_BDC)markedContent).getstructureTag();
if (structTag != null) {
return structTag;
}
}
return markedContent.getParentStructureTag();
}
return null;
public COSObject getParentStructElem() {
return markedContent != null ? markedContent.getParentStructElem() : null;
}

/**
Expand Down Expand Up @@ -241,10 +232,6 @@ public COSString getInheritedActualText() {
return getInheritedStringAttribute(ASAtom.ACTUAL_TEXT);
}

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

public COSString getInheritedStringAttribute(ASAtom key) {
if (markedContent != null) {
COSString string = markedContent.getInheritedStringAttribute(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,27 @@ public List<? extends Object> getLinkedObjects(
}
}

public String getstructureTag() {
public COSObject getParentStructElem() {
COSObject structElem = getStructElem();
return structElem != null ? structElem : super.getParentStructElem();
}

private COSObject getStructElem() {
Long mcid = getMCID();
PDStructTreeRoot structTreeRoot = StaticResources.getDocument().getStructTreeRoot();
if (structTreeRoot != null && mcid != null) {
PDNumberTreeNode parentTreeRoot = structTreeRoot.getParentTree();
COSObject structureElement = parentTreeRoot == null ? null : structureElementAccessObject.getStructureElement(parentTreeRoot, mcid);
if (structureElement != null && !structureElement.empty()) {
return structureElement.getNameKeyStringValue(ASAtom.S);
return structureElement;
}
}
return null;
}

public String getstructParentLang() {
Long mcid = getMCID();
PDStructTreeRoot structTreeRoot = StaticResources.getDocument().getStructTreeRoot();
if (structTreeRoot == null || mcid == null) {
return null;
}
PDNumberTreeNode parentTreeRoot = structTreeRoot.getParentTree();
if (parentTreeRoot == null ) {
return null;
}
COSObject structureElement = structureElementAccessObject.getStructureElement(parentTreeRoot, mcid);
if (structureElement == null || structureElement.empty()) {
COSObject structureElement = getStructElem();
if (structureElement == null) {
return null;
}
String baseLang = structureElement.getStringKey(ASAtom.LANG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.verapdf.gf.model.impl.operator.xobject;

import org.verapdf.cos.COSBase;
import org.verapdf.cos.COSObject;
import org.verapdf.gf.model.factory.operators.GraphicState;
import org.verapdf.gf.model.impl.operator.base.GFOperator;
import org.verapdf.gf.model.impl.pd.images.GFPDXObject;
Expand Down Expand Up @@ -49,17 +50,17 @@ public class GFOp_Do extends GFOperator implements Op_Do {
private final org.verapdf.pd.images.PDXObject pbXObject;
private final PDResourcesHandler resourcesHandler;
private final GraphicState inheritedGraphicState;
private final String parentStructureTag;
private final COSObject parentStructElem;
private final String parentsTags;

public GFOp_Do(List<COSBase> arguments, org.verapdf.pd.images.PDXObject pdXObject,
PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState,
String parentStructureTag, String parentsTags) {
COSObject parentStructElem, String parentsTags) {
super(arguments, OP_DO_TYPE);
this.pbXObject = pdXObject;
this.resourcesHandler = resourcesHandler;
this.inheritedGraphicState = inheritedGraphicState;
this.parentStructureTag = parentStructureTag;
this.parentStructElem = parentStructElem;
this.parentsTags = parentsTags;
}

Expand All @@ -80,7 +81,7 @@ public List<org.verapdf.model.pdlayer.PDXObject> getXObject() {
return Collections.emptyList();
}
PDXObject typedPDXObject = GFPDXObject.getTypedPDXObject(this.pbXObject, this.resourcesHandler,
inheritedGraphicState, this.parentStructureTag, this.parentsTags);
inheritedGraphicState, this.parentStructElem, this.parentsTags);
if (typedPDXObject != null) {
List<PDXObject> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(typedPDXObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public String getstructParentStandardType() {
return null;
}

private COSObject getParentDictionary() {
protected COSObject getParentDictionary() {
PDStructTreeRoot structTreeRoot = StaticResources.getDocument().getStructTreeRoot();
Long structParent = ((PDAnnotation) this.simplePDObject).getStructParent();
if (structTreeRoot != null && structParent != null) {
Expand Down Expand Up @@ -391,7 +391,7 @@ private void addAppearance(List<PDXForm> list, PDAppearanceStream toAdd) {
if (toAdd != null) {
PDResourcesHandler resources = this.resources.getExtendedResources(toAdd.getResources());
List<CosLang> annotLang = getLang();
GFPDXForm xForm = new GFPDXForm(toAdd, resources, null, getstructParentType(), "",
GFPDXForm xForm = new GFPDXForm(toAdd, resources, null, getParentDictionary(), "",
annotLang.isEmpty() ? null : annotLang.get(0).getunicodeValue());
this.containsTransparency |= xForm.containsTransparency();
list.add(xForm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class GFPDContentStream extends GFPDObject implements PDContentStream {
private boolean containsTransparency = false;
private final GraphicState inheritedGraphicState;
private final StructureElementAccessObject structureElementAccessObject;
protected String parentStructureTag;
protected COSObject parentStructElem;
protected String parentsTags;

public GFPDContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler,
Expand All @@ -79,9 +79,9 @@ public GFPDContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourc
public GFPDContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler,
GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject,
String parentStructureTag, String parentsTags) {
COSObject parentStructElem, String parentsTags) {
this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject,
parentStructureTag, parentsTags, CONTENT_STREAM_TYPE);
parentStructElem, parentsTags, CONTENT_STREAM_TYPE);
}

public GFPDContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler,
Expand All @@ -98,11 +98,11 @@ public GFPDContentStream(org.verapdf.pd.PDContentStream contentStream,
PDResourcesHandler resourcesHandler,
GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject,
String parentStructureTag, String parentsTags, final String type) {
COSObject parentStructElem, String parentsTags, final String type) {
this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, type);
this.parentStructureTag = getParentStructureTag(structureElementAccessObject);
if (this.parentStructureTag == null) {
this.parentStructureTag = parentStructureTag;
this.parentStructElem = getParentStructureElem(structureElementAccessObject);
if (this.parentStructElem == null) {
this.parentStructElem = parentStructElem;
}
this.parentsTags = parentsTags;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ protected void parseOperators() {
streamParser.parseTokens();
OperatorFactory operatorFactory = new OperatorFactory();
List<Operator> result = operatorFactory.operatorsFromTokens(streamParser.getTokens(),
resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentStructureTag, parentsTags);
resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentStructElem, parentsTags);
this.containsTransparency = operatorFactory.isLastParsedContainsTransparency();
this.operators = Collections.unmodifiableList(result);
} finally {
Expand Down Expand Up @@ -198,13 +198,13 @@ public boolean isContainsTransparency() {
return containsTransparency;
}

private String getParentStructureTag(StructureElementAccessObject structureElementAccessObject) {
private COSObject getParentStructureElem(StructureElementAccessObject structureElementAccessObject) {
PDStructTreeRoot structTreeRoot = StaticResources.getDocument().getStructTreeRoot();
if (structTreeRoot != null) {
PDNumberTreeNode parentTreeRoot = structTreeRoot.getParentTree();
COSObject structureElement = parentTreeRoot == null ? null : structureElementAccessObject.getStructureElement(parentTreeRoot, null);
if (structureElement != null && !structureElement.empty()) {
return structureElement.getNameKeyStringValue(ASAtom.S);
return structureElement;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ public class GFPDDocument extends GFPDObject implements PDDocument {
* Link name for annotations structure tree root of document
*/
public static final String STRUCTURE_TREE_ROOT = "StructTreeRoot";
/**
* Link name for alternate presentation of names tree of document
*/
public static final String ALTERNATE_PRESENTATIONS = "AlternatePresentations";
/**
* Link name for optional content properties of the document
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.verapdf.gf.model.impl.pd;


import org.verapdf.cos.COSObject;
import org.verapdf.gf.model.factory.operators.GraphicState;
import org.verapdf.gf.model.impl.operator.markedcontent.GFOp_BDC;
import org.verapdf.gf.model.impl.operator.markedcontent.GFOp_BMC;
Expand Down Expand Up @@ -48,28 +49,26 @@ public class GFPDSemanticContentStream extends GFPDContentStream implements PDSe

private String defaultLang;

public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream,
PDResourcesHandler resourcesHandler,
public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler,
GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject) {
super(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, SEMANTIC_CONTENT_STREAM_TYPE);
}

public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream,
PDResourcesHandler resourcesHandler,
GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject,
String parentStructureTag, String parentsTags) {
super(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentStructureTag,
public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream, PDResourcesHandler resourcesHandler,
GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject,
COSObject parentStructElem, String parentsTags) {
super(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentStructElem,
parentsTags, SEMANTIC_CONTENT_STREAM_TYPE);
}

public GFPDSemanticContentStream(org.verapdf.pd.PDContentStream contentStream,
PDResourcesHandler resourcesHandler,
GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject,
String parentStructureTag, String parentsTags, String defaultLang) {
this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentStructureTag,
COSObject parentStructElem, String parentsTags, String defaultLang) {
this(contentStream, resourcesHandler, inheritedGraphicState, structureElementAccessObject, parentStructElem,
parentsTags);
this.defaultLang = defaultLang;
}
Expand All @@ -96,15 +95,15 @@ private List<SEContentItem> getContentItem() {
String type = operators.get(i).getObjectType();
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), parentStructureTag,
list.add(new GFSEUnmarkedContent(operators.subList(unmarkedContentIndex, i), parentStructElem,
parentsTags, defaultLang));
}
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), parentStructureTag,
list.add(new GFSEMarkedContent(operators.subList(markedContentIndex, i + 1), parentStructElem,
parentsTags, defaultLang));
markedContentIndex = i;
unmarkedContentIndex = i + 1;
Expand All @@ -114,7 +113,7 @@ private List<SEContentItem> getContentItem() {
}
if (unmarkedContentIndex != operators.size()) {
list.add(new GFSEUnmarkedContent(operators.subList(unmarkedContentIndex, operators.size()),
parentStructureTag, parentsTags, defaultLang));
parentStructElem, parentsTags, defaultLang));
}
return Collections.unmodifiableList(list);
}
Expand Down
Loading

0 comments on commit 4193b93

Please sign in to comment.