From e3b102d2d3b7190f166d7223f82da2a66af7ebfb Mon Sep 17 00:00:00 2001 From: Maxim Date: Wed, 15 Nov 2023 12:31:41 +0300 Subject: [PATCH] Update some link methods --- .../factory/operators/OperatorParser.java | 7 ++-- .../markedcontent/GFOpMarkedContent.java | 17 +++++---- .../impl/operator/markedcontent/GFOp_BDC.java | 2 +- .../model/impl/operator/xobject/GFOp_Do.java | 36 ++++++++++--------- .../verapdf/gf/model/impl/pd/GFPDAnnot.java | 24 ++++++++----- .../gf/model/impl/pd/font/GFPDFont.java | 2 +- .../gf/model/impl/pd/font/GFPDType0Font.java | 10 ++++-- .../pd/gfse/contents/GFSEMarkedContent.java | 15 ++++---- .../pd/gfse/contents/GFSEUnmarkedContent.java | 6 ++-- 9 files changed, 68 insertions(+), 51 deletions(-) diff --git a/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorParser.java b/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorParser.java index 988adc087..3bb944c8a 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorParser.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/factory/operators/OperatorParser.java @@ -522,10 +522,9 @@ void parseOperator(List processedOperators, } GFOp_Do op_do = new GFOp_Do(arguments, resourcesHandler.getXObject(getLastCOSName(arguments)), resourcesHandler, this.graphicState.clone(), parentStructElem, parentsTags); - List 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; diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/markedcontent/GFOpMarkedContent.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/markedcontent/GFOpMarkedContent.java index e0b3e0f89..d4e0a6bfe 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/markedcontent/GFOpMarkedContent.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/markedcontent/GFOpMarkedContent.java @@ -119,16 +119,21 @@ protected List getPropertiesDict() { return Collections.emptyList(); } - public List getLang() { - COSObject lang = getAttribute(ASAtom.LANG, COSObjType.COS_STRING); + public List getLinkLang() { + COSString lang = getLang(); if (lang != null) { List 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 = ""; @@ -157,9 +162,9 @@ public String getParentLang() { if (markedContent == null) { return null; } - List 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(); diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/markedcontent/GFOp_BDC.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/markedcontent/GFOp_BDC.java index 6fa99151c..741ae83f0 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/markedcontent/GFOp_BDC.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/markedcontent/GFOp_BDC.java @@ -64,7 +64,7 @@ public List getLinkedObjects( case PROPERTIES: return this.getPropertiesDict(); case LANG: - return this.getLang(); + return this.getLinkLang(); default: return super.getLinkedObjects(link); } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/xobject/GFOp_Do.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/xobject/GFOp_Do.java index 480391c9a..3501568a2 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/xobject/GFOp_Do.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/operator/xobject/GFOp_Do.java @@ -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 xObjects = null; + private PDXObject xObject; private final org.verapdf.pd.images.PDXObject pbXObject; private final PDResourcesHandler resourcesHandler; @@ -62,12 +62,13 @@ public GFOp_Do(List arguments, org.verapdf.pd.images.PDXObject pdXObjec this.inheritedGraphicState = inheritedGraphicState; this.parentStructElem = parentStructElem; this.parentsTags = parentsTags; + this.xObject = getXObject(); } @Override public List getLinkedObjects(String link) { if (X_OBJECT.equals(link)) { - return this.getXObject(); + return this.getListXObject(); } return super.getLinkedObjects(link); } @@ -75,22 +76,23 @@ public List getLinkedObjects(String link) { /** * @return XObject object from veraPDF model used in current operator */ - public List 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 list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); - list.add(typedPDXObject); - this.xObjects = Collections.unmodifiableList(list); - } else { - this.xObjects = Collections.emptyList(); - } + public List getListXObject() { + if (this.xObject != null) { + List 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; + } + + } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java index 17fd413f0..6a7892d90 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java @@ -229,7 +229,17 @@ protected COSObject getParentDictionary() { return null; } - private List getLang() { + private List getLinkLang() { + COSString lang = getLang(); + if (lang != null) { + List 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) { @@ -238,13 +248,11 @@ private List getLang() { if (structureElement != null) { COSObject baseLang = structureElement.getKey(ASAtom.LANG); if (baseLang != null && baseLang.getType() == COSObjType.COS_STRING) { - List 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 getBM() { @@ -343,7 +351,7 @@ public List getLinkedObjects(String link) { case APPEARANCE: return this.getAppearance(); case LANG: - return this.getLang(); + return this.getLinkLang(); case BM: return this.getBM(); default: @@ -426,9 +434,9 @@ private void addContentStreamsFromAppearanceEntry(PDAppearanceEntry appearanceEn private void addAppearance(List list, PDAppearanceStream toAdd) { if (toAdd != null) { PDResourcesHandler resources = this.resources.getExtendedResources(toAdd.getResources()); - List 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); } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDFont.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDFont.java index a4b717fd0..ba383b17e 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDFont.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDFont.java @@ -151,7 +151,7 @@ private List 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, diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDType0Font.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDType0Font.java index dcc4c465c..ffd0da252 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDType0Font.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDType0Font.java @@ -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(); @@ -87,7 +87,11 @@ private List 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, diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEMarkedContent.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEMarkedContent.java index 42eb6db1c..80b46f87c 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEMarkedContent.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEMarkedContent.java @@ -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; @@ -113,9 +112,9 @@ private List getContentItem() { } else if (op instanceof GFOp_EI) { list.add(new GFSEInlineImageItem((GFOp_EI)op, this)); } else if (op instanceof GFOp_Do) { - List 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)); } } } @@ -124,7 +123,7 @@ private List getContentItem() { } public List getLinkLang() { - return operator.getLang(); + return operator.getLinkLang(); } @Override @@ -175,9 +174,9 @@ public String getparentsTags() { @Override public String getLang() { - List 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(); diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEUnmarkedContent.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEUnmarkedContent.java index d76c49f1c..2f7c1ad11 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEUnmarkedContent.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEUnmarkedContent.java @@ -77,9 +77,9 @@ private List getContentItem() { } else if (operator instanceof GFOp_EI) { list.add(new GFSEInlineImageItem((GFOp_EI)operator, this)); } else if (operator instanceof GFOp_Do) { - List 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)); } } }