Skip to content

Commit

Permalink
Merge pull request #612 from veraPDF/links_methods
Browse files Browse the repository at this point in the history
Update some link methods
  • Loading branch information
MaximPlusov authored Nov 17, 2023
2 parents 503c1db + e3b102d commit 18f42e8
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,9 @@ void parseOperator(List<org.verapdf.model.operator.Operator> processedOperators,
}
GFOp_Do op_do = new GFOp_Do(arguments, resourcesHandler.getXObject(getLastCOSName(arguments)),
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);
this.transparencyGraphicState.setVeraXObject(xobj);
org.verapdf.model.pdlayer.PDXObject pdxObject = op_do.getXObject();
if (pdxObject != null) {
this.transparencyGraphicState.setVeraXObject((GFPDXObject)pdxObject);
}
processedOperators.add(op_do);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,21 @@ protected List<CosDict> getPropertiesDict() {
return Collections.emptyList();
}

public List<CosLang> getLang() {
COSObject lang = getAttribute(ASAtom.LANG, COSObjType.COS_STRING);
public List<CosLang> getLinkLang() {
COSString lang = getLang();
if (lang != null) {
List<CosLang> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new GFCosLang((COSString) lang.getDirectBase()));
list.add(new GFCosLang(lang));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

public COSString getLang() {
COSObject lang = getAttribute(ASAtom.LANG, COSObjType.COS_STRING);
return lang != null ? (COSString) lang.getDirectBase() : null;
}

public String getParentsTags() {
COSName tagName = getTag();
String tag = "";
Expand Down Expand Up @@ -157,9 +162,9 @@ public String getParentLang() {
if (markedContent == null) {
return null;
}
List<CosLang> lang = markedContent.getLang();
if (lang != null && lang.size() != 0) {
return lang.get(0).getunicodeValue();
COSString lang = markedContent.getLang();
if (lang != null) {
return lang.getString();
}
if (GFOp_BDC.OP_BDC_TYPE.equals(markedContent.getObjectType())) {
String structParentLang = ((GFOp_BDC)markedContent).getstructParentLang();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public List<? extends Object> getLinkedObjects(
case PROPERTIES:
return this.getPropertiesDict();
case LANG:
return this.getLang();
return this.getLinkLang();
default:
return super.getLinkedObjects(link);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class GFOp_Do extends GFOperator implements Op_Do {
/** Name of link to the XObject */
public static final String X_OBJECT = "xObject";

private List<PDXObject> xObjects = null;
private PDXObject xObject;

private final org.verapdf.pd.images.PDXObject pbXObject;
private final PDResourcesHandler resourcesHandler;
Expand All @@ -62,35 +62,37 @@ public GFOp_Do(List<COSBase> arguments, org.verapdf.pd.images.PDXObject pdXObjec
this.inheritedGraphicState = inheritedGraphicState;
this.parentStructElem = parentStructElem;
this.parentsTags = parentsTags;
this.xObject = getXObject();
}

@Override
public List<? extends Object> getLinkedObjects(String link) {
if (X_OBJECT.equals(link)) {
return this.getXObject();
return this.getListXObject();
}
return super.getLinkedObjects(link);
}

/**
* @return XObject object from veraPDF model used in current operator
*/
public List<org.verapdf.model.pdlayer.PDXObject> getXObject() {
if (this.xObjects == null) {
if (this.pbXObject == null) {
return Collections.emptyList();
}
PDXObject typedPDXObject = GFPDXObject.getTypedPDXObject(this.pbXObject, this.resourcesHandler,
inheritedGraphicState, this.parentStructElem, this.parentsTags);
if (typedPDXObject != null) {
List<PDXObject> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(typedPDXObject);
this.xObjects = Collections.unmodifiableList(list);
} else {
this.xObjects = Collections.emptyList();
}
public List<PDXObject> getListXObject() {
if (this.xObject != null) {
List<PDXObject> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(xObject);
return Collections.unmodifiableList(list);
}
return this.xObjects;
return Collections.emptyList();
}

public PDXObject getXObject() {
if (this.pbXObject == null) {
return null;
}
this.xObject = GFPDXObject.getTypedPDXObject(this.pbXObject, this.resourcesHandler, inheritedGraphicState,
this.parentStructElem, this.parentsTags);
return this.xObject;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,17 @@ protected COSObject getParentDictionary() {
return null;
}

private List<CosLang> getLang() {
private List<CosLang> getLinkLang() {
COSString lang = getLang();
if (lang != null) {
List<CosLang> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new GFCosLang(lang));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

public COSString getLang() {
PDStructTreeRoot structTreeRoot = StaticResources.getDocument().getStructTreeRoot();
Long structParent = ((PDAnnotation)this.simplePDObject).getStructParent();
if (structTreeRoot != null && structParent != null) {
Expand All @@ -238,13 +248,11 @@ private List<CosLang> getLang() {
if (structureElement != null) {
COSObject baseLang = structureElement.getKey(ASAtom.LANG);
if (baseLang != null && baseLang.getType() == COSObjType.COS_STRING) {
List<CosLang> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new GFCosLang((COSString) baseLang.getDirectBase()));
return Collections.unmodifiableList(list);
return (COSString) baseLang.getDirectBase();
}
}
}
return Collections.emptyList();
return null;
}

private List<CosBM> getBM() {
Expand Down Expand Up @@ -343,7 +351,7 @@ public List<? extends Object> getLinkedObjects(String link) {
case APPEARANCE:
return this.getAppearance();
case LANG:
return this.getLang();
return this.getLinkLang();
case BM:
return this.getBM();
default:
Expand Down Expand Up @@ -426,9 +434,9 @@ private void addContentStreamsFromAppearanceEntry(PDAppearanceEntry appearanceEn
private void addAppearance(List<PDXForm> list, PDAppearanceStream toAdd) {
if (toAdd != null) {
PDResourcesHandler resources = this.resources.getExtendedResources(toAdd.getResources());
List<CosLang> annotLang = getLang();
COSString annotLang = getLang();
GFPDXForm xForm = new GFPDXForm(toAdd, resources, null, getParentDictionary(), "",
annotLang.isEmpty() ? null : annotLang.get(0).getunicodeValue(), isSignature());
annotLang == null ? null : annotLang.getString(), isSignature());
this.containsTransparency |= xForm.containsTransparency();
list.add(xForm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private List<FontProgram> getFontProgram() {
}
if (TYPE0_STRING.equals(this.getSubtype())) {
GFFontProgram font = new GFFontProgram(fontProgram,
(GFPDFont) ((GFPDType0Font) this).getLinkedObjects(GFPDType0Font.DESCENDANT_FONTS).get(0));
(GFPDFont) ((GFPDType0Font) this).getDescendantFont());
return getFontProgramList(font);
}
GFFontProgram font = new GFFontProgram(fontProgram,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public class GFPDType0Font extends GFPDFont implements PDType0Font {
public static final String DESCENDANT_FONTS = "DescendantFonts";
public static final String ENCODING = "Encoding";

private PDCIDFont descendantFont;
private final PDCIDFont descendantFont;
private org.verapdf.pd.font.PDCIDFont cidFont;

public GFPDType0Font(org.verapdf.pd.font.PDType0Font font, RenderingMode renderingMode) {
super(font, renderingMode, TYPE_0_FONT_TYPE);
this.descendantFont = this.getDescendantFont();
this.descendantFont = this.calculateDescendantFont();
((org.verapdf.pd.font.PDType0Font) this.pdFont).setFontProgramFromDescendant(this.cidFont);
this.fontProgramParsed = this.descendantFont != null
&& ((GFPDCIDFont) this.descendantFont).isFontProgramParsed();
Expand Down Expand Up @@ -87,7 +87,11 @@ private List<PDCIDFont> getDescendantFonts() {
return Collections.emptyList();
}

private PDCIDFont getDescendantFont() {
public PDCIDFont getDescendantFont() {
return this.descendantFont;
}

private PDCIDFont calculateDescendantFont() {
COSDictionary cidFontDict = ((org.verapdf.pd.font.PDType0Font) this.pdFont).getDescendantFont();
if (cidFontDict != null) {
org.verapdf.pd.font.PDCIDFont cidFont = new org.verapdf.pd.font.PDCIDFont(cidFontDict,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.verapdf.gf.model.impl.pd.images.GFPDXImage;
import org.verapdf.model.baselayer.Object;
import org.verapdf.model.coslayer.CosLang;
import org.verapdf.model.coslayer.CosName;
import org.verapdf.model.operator.Operator;
import org.verapdf.model.pdlayer.PDXObject;
import org.verapdf.model.selayer.SEContentItem;
Expand Down Expand Up @@ -113,9 +112,9 @@ private List<SEContentItem> getContentItem() {
} else if (op instanceof GFOp_EI) {
list.add(new GFSEInlineImageItem((GFOp_EI)op, this));
} else if (op instanceof GFOp_Do) {
List<PDXObject> xObjects = ((GFOp_Do)op).getXObject();
if (xObjects != null && xObjects.size() != 0 && ASAtom.IMAGE.getValue().equals(xObjects.get(0).getSubtype())) {
list.add(new GFSEImageXObjectItem((GFOp_Do)op, (GFPDXImage)xObjects.get(0), this));
PDXObject xObject = ((GFOp_Do)op).getXObject();
if (xObject != null && ASAtom.IMAGE.getValue().equals(xObject.getSubtype())) {
list.add(new GFSEImageXObjectItem((GFOp_Do)op, (GFPDXImage)xObject, this));
}
}
}
Expand All @@ -124,7 +123,7 @@ private List<SEContentItem> getContentItem() {
}

public List<CosLang> getLinkLang() {
return operator.getLang();
return operator.getLinkLang();
}

@Override
Expand Down Expand Up @@ -175,9 +174,9 @@ public String getparentsTags() {

@Override
public String getLang() {
List<CosLang> lang = operator.getLang();
if (lang != null && lang.size() != 0) {
return lang.get(0).getunicodeValue();
COSString lang = operator.getLang();
if (lang != null) {
return lang.getString();
}
if (GFOp_BDC.OP_BDC_TYPE.equals(operator.getObjectType())) {
String structParentLang = ((GFOp_BDC)operator).getstructParentLang();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ private List<SEContentItem> getContentItem() {
} else if (operator instanceof GFOp_EI) {
list.add(new GFSEInlineImageItem((GFOp_EI)operator, this));
} else if (operator instanceof GFOp_Do) {
List<PDXObject> xObjects = ((GFOp_Do)operator).getXObject();
if (xObjects != null && xObjects.size() != 0 && ASAtom.IMAGE.getValue().equals(xObjects.get(0).getSubtype())) {
list.add(new GFSEImageXObjectItem((GFOp_Do)operator, (GFPDXImage)xObjects.get(0), this));
PDXObject xObject = ((GFOp_Do)operator).getXObject();
if (xObject != null && ASAtom.IMAGE.getValue().equals(xObject.getSubtype())) {
list.add(new GFSEImageXObjectItem((GFOp_Do)operator, (GFPDXImage)xObject, this));
}
}
}
Expand Down

0 comments on commit 18f42e8

Please sign in to comment.