From b2ca6084760152107a5c41172806b1806bfcf424 Mon Sep 17 00:00:00 2001 From: MaximPlusov Date: Thu, 19 Oct 2023 12:25:24 +0300 Subject: [PATCH] Merge pull request #592 from veraPDF/pdfua2_methods PDF/UA-2. Add new methods. Remove unnecessary methods --- .../gf/model/impl/cos/GFCosActualText.java | 6 -- .../gf/model/impl/cos/GFCosString.java | 5 ++ .../gf/model/impl/cos/GFCosTrailer.java | 17 ---- .../verapdf/gf/model/impl/pd/GFPDAnnot.java | 10 +++ .../gf/model/impl/pd/GFPDDestination.java | 83 +++++++++++++++++++ .../gf/model/impl/pd/GFPDExtGState.java | 16 ---- .../verapdf/gf/model/impl/pd/GFPDOutline.java | 41 ++++++++- .../model/impl/pd/actions/GFPDGoToAction.java | 32 +------ .../impl/pd/actions/GFPDGoToRemoteAction.java | 2 +- .../annotations/GFPDFileAttachmentAnnot.java | 6 +- .../impl/pd/annotations/GFPDLinkAnnot.java | 30 +++++++ .../gf/model/impl/pd/font/GFPDCIDFont.java | 8 +- .../verapdf/gf/model/impl/pd/gfse/GFSEL.java | 10 +-- 13 files changed, 179 insertions(+), 87 deletions(-) create mode 100644 validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDDestination.java diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosActualText.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosActualText.java index 7a9b45dd1..52a663ca8 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosActualText.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosActualText.java @@ -21,7 +21,6 @@ package org.verapdf.gf.model.impl.cos; import org.verapdf.cos.COSString; -import org.verapdf.gf.model.impl.operator.textshow.PUAHelper; import org.verapdf.model.coslayer.CosActualText; /** @@ -34,9 +33,4 @@ public class GFCosActualText extends GFCosString implements CosActualText { public GFCosActualText(COSString cosString) { super(cosString, COS_ACTUAL_TEXT_TYPE); } - - @Override - public Boolean getcontainsPUA() { - return PUAHelper.containPUA(((COSString)baseObject).getString()); - } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosString.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosString.java index d86980095..40afd6c5f 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosString.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosString.java @@ -21,6 +21,7 @@ package org.verapdf.gf.model.impl.cos; import org.verapdf.cos.COSString; +import org.verapdf.gf.model.impl.operator.textshow.PUAHelper; import org.verapdf.model.coslayer.CosString; /** @@ -88,4 +89,8 @@ public Long gethexCount() { return Long.valueOf(this.hexCount); } + @Override + public Boolean getcontainsPUA() { + return PUAHelper.containPUA(baseObject.getString()); + } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosTrailer.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosTrailer.java index b7795b1f6..277186425 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosTrailer.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/cos/GFCosTrailer.java @@ -27,7 +27,6 @@ import org.verapdf.cos.COSObject; import org.verapdf.gf.model.impl.pd.GFPDEncryption; import org.verapdf.model.baselayer.Object; -import org.verapdf.model.coslayer.CosIndirect; import org.verapdf.model.coslayer.CosInfo; import org.verapdf.model.coslayer.CosTrailer; import org.verapdf.model.pdlayer.PDEncryption; @@ -35,7 +34,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -48,7 +46,6 @@ public class GFCosTrailer extends GFCosDict implements CosTrailer { /** Type name for GFCosTrailer */ public static final String COS_TRAILER_TYPE = "CosTrailer"; - public static final String CATALOG = "Catalog"; public static final String ENCRYPT = "Encrypt"; public static final String INFO = "Info"; @@ -74,8 +71,6 @@ public Boolean getisEncrypted() { @Override public List getLinkedObjects(String link) { switch (link) { - case CATALOG: - return this.getCatalog(); case ENCRYPT: return this.getEncrypt(); case INFO: @@ -104,16 +99,4 @@ private List getInfo() { } return Collections.emptyList(); } - - private List getCatalog() { - List result = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); - COSObject catalog = this.baseObject.getKey(ASAtom.ROOT); - if (catalog.isIndirect().booleanValue()) { - result.add(new GFCosIndirect((COSIndirect) catalog.get())); - } else { - LOGGER.log(Level.WARNING, "Catalog shall be an indirect reference"); - } - return Collections.unmodifiableList(result); - } - } 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 57a631c94..5d5d360e8 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 @@ -160,6 +160,16 @@ public String getN_type() { } } + @Override + public Boolean getcontainsC() { + return ((PDAnnotation) simplePDObject).getCOSC() != null; + } + + @Override + public Boolean getcontainsIC() { + return ((PDAnnotation) simplePDObject).getCOSIC() != null; + } + @Override public String getFT() { ASAtom ft = ((PDAnnotation) simplePDObject).getFT(); diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDDestination.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDDestination.java new file mode 100644 index 000000000..471e48e70 --- /dev/null +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDDestination.java @@ -0,0 +1,83 @@ +/** + * This file is part of veraPDF Validation, a module of the veraPDF project. + * Copyright (c) 2015, veraPDF Consortium + * 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; + +import org.verapdf.as.ASAtom; +import org.verapdf.cos.COSObjType; +import org.verapdf.cos.COSObject; +import org.verapdf.model.pdlayer.PDDestination; +import org.verapdf.pd.PDNameTreeNode; +import org.verapdf.pd.PDNamesDictionary; +import org.verapdf.tools.StaticResources; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * @author Maxim Plushchov + */ +public class GFPDDestination extends GFPDObject implements PDDestination { + + public static final Logger LOGGER = Logger.getLogger(GFPDDestination.class.getCanonicalName()); + + public static final String DESTINATION_TYPE = "PDDestination"; + + public GFPDDestination(COSObject destination) { + super(destination, DESTINATION_TYPE); + } + + @Override + public Boolean getisStructDestination() { + COSObject destination = simpleCOSObject; + if (destination.getType() == COSObjType.COS_STRING) { + PDNamesDictionary namesDictionary = StaticResources.getDocument().getCatalog().getNamesDictionary(); + if (namesDictionary == null) { + return false; + } + PDNameTreeNode dests = namesDictionary.getDests(); + if (dests != null) { + COSObject dest = dests.getObject(destination.getString()); + if (dest == null) { + LOGGER.log(Level.WARNING, "Named destination " + destination.getString() + " not found in the Dests name tree in the Names dictionary"); + return false; + } + destination = dest; + } + } else if (destination.getType() == COSObjType.COS_NAME) { + COSObject dests = StaticResources.getDocument().getCatalog().getDests(); + if (dests != null) { + COSObject dest = dests.getKey(destination.getName()); + if (dest == null) { + LOGGER.log(Level.WARNING, "Named destination " + destination.getName() + " not found in the Dests dictionary in the catalog"); + return false; + } + destination = dest; + } + } + if (destination.getType() == COSObjType.COS_DICT) { + return destination.knownKey(ASAtom.SD); + } + if (destination.getType() == COSObjType.COS_ARRAY && destination.size() > 0) { + return destination.at(0).knownKey(ASAtom.S); + } + return false; + } +} diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDExtGState.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDExtGState.java index ff817a55b..3e3a043b5 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDExtGState.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDExtGState.java @@ -53,9 +53,7 @@ public class GFPDExtGState extends GFPDResource implements PDExtGState { public static final String EXT_G_STATE_TYPE = "PDExtGState"; public static final String RI = "RI"; - public static final String BM = "BM"; public static final String LINK_BM = "bm"; - public static final String FONT_SIZE = "fontSize"; public static final String HALFTONE = "HT"; public static final String CUSTOM_FUNCTIONS = "customFunctions"; @@ -161,8 +159,6 @@ public List getLinkedObjects(String link) { switch (link) { case RI: return this.getRI(); - case FONT_SIZE: - return this.getFontSize(); case HALFTONE: return this.getHalftone(); case CUSTOM_FUNCTIONS: @@ -185,18 +181,6 @@ private List getRI() { return Collections.emptyList(); } - private List getFontSize() { - COSNumber fontSize = ((org.verapdf.pd.PDExtGState) this.simplePDObject) - .getCOSFontSize(); - if (fontSize != null) { - List result = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); - result.add(GFCosNumber.fromPDFParserNumber(fontSize)); - return Collections.unmodifiableList(result); - } - - return Collections.emptyList(); - } - private List getHalftone() { org.verapdf.pd.PDHalftone halftone = ((org.verapdf.pd.PDExtGState) simplePDObject).getHalftone(); if (halftone != null) { diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDOutline.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDOutline.java index 51b3b6a40..02b250959 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDOutline.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDOutline.java @@ -20,9 +20,16 @@ */ package org.verapdf.gf.model.impl.pd; +import org.verapdf.as.ASAtom; +import org.verapdf.cos.COSObjType; +import org.verapdf.cos.COSObject; +import org.verapdf.cos.COSString; +import org.verapdf.gf.model.impl.cos.GFCosTextString; import org.verapdf.gf.model.impl.pd.actions.GFPDAction; import org.verapdf.model.baselayer.Object; +import org.verapdf.model.coslayer.CosTextString; import org.verapdf.model.pdlayer.PDAction; +import org.verapdf.model.pdlayer.PDDestination; import org.verapdf.model.pdlayer.PDOutline; import org.verapdf.pd.PDOutlineItem; @@ -37,7 +44,9 @@ public class GFPDOutline extends GFPDObject implements PDOutline { public static final String OUTLINE_TYPE = "PDOutline"; + public static final String TITLE = "Title"; public static final String ACTION = "A"; + public static final String DEST = "Dest"; private final String id; @@ -53,10 +62,16 @@ public String getID() { @Override public List getLinkedObjects(String link) { - if (ACTION.equals(link)) { - return this.getAction(); + switch (link) { + case ACTION: + return this.getAction(); + case DEST: + return this.getDestination(); + case TITLE: + return this.getTitle(); + default: + return super.getLinkedObjects(link); } - return super.getLinkedObjects(link); } private List getAction() { @@ -69,4 +84,24 @@ private List getAction() { } return Collections.emptyList(); } + + private List getDestination() { + COSObject destination = ((PDOutlineItem) simplePDObject).getDestination(); + if (!destination.empty()) { + List destinations = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); + destinations.add(new GFPDDestination(destination)); + return Collections.unmodifiableList(destinations); + } + return Collections.emptyList(); + } + + private List getTitle() { + COSObject title = this.simplePDObject.getKey(ASAtom.TITLE); + if (title != null && title.getType() == COSObjType.COS_STRING) { + List list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); + list.add(new GFCosTextString((COSString) title.getDirectBase())); + return Collections.unmodifiableList(list); + } + return Collections.emptyList(); + } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/actions/GFPDGoToAction.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/actions/GFPDGoToAction.java index 7a94a9808..5680489d2 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/actions/GFPDGoToAction.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/actions/GFPDGoToAction.java @@ -20,16 +20,9 @@ */ package org.verapdf.gf.model.impl.pd.actions; -import org.verapdf.cos.COSNumber; -import org.verapdf.gf.model.impl.cos.GFCosNumber; -import org.verapdf.model.baselayer.Object; -import org.verapdf.model.coslayer.CosNumber; import org.verapdf.model.pdlayer.PDGoToAction; import org.verapdf.pd.actions.PDAction; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; /** * @author Maksim Bezrukov @@ -37,33 +30,12 @@ public class GFPDGoToAction extends GFPDAction implements PDGoToAction { public static final String GOTO_ACTION_TYPE = "PDGoToAction"; - public static final String D = "D"; - public GFPDGoToAction(PDAction simplePDObject) { super(simplePDObject, GOTO_ACTION_TYPE); } - protected GFPDGoToAction(PDAction simplePDObject, String type) { - super(simplePDObject, type); - } - @Override - public List getLinkedObjects(String link) { - if (D.equals(link)) { - return this.getD(); - } - return super.getLinkedObjects(link); - } - - private List getD() { - List numbers = ((PDAction) simplePDObject).getCOSArrayD(); - if (!numbers.isEmpty()) { - List result = new ArrayList<>(numbers.size()); - for (COSNumber number : numbers) { - result.add(GFCosNumber.fromPDFParserNumber(number)); - } - return Collections.unmodifiableList(result); - } - return Collections.emptyList(); + public Boolean getcontainsStructDestination() { + return ((PDAction) simplePDObject).containsStructureDestination(); } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/actions/GFPDGoToRemoteAction.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/actions/GFPDGoToRemoteAction.java index 21b848367..4531b14bb 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/actions/GFPDGoToRemoteAction.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/actions/GFPDGoToRemoteAction.java @@ -26,7 +26,7 @@ /** * @author Maksim Bezrukov */ -public class GFPDGoToRemoteAction extends GFPDGoToAction implements PDGoToRemoteAction { +public class GFPDGoToRemoteAction extends GFPDAction implements PDGoToRemoteAction { public static final String GOTO_REMOTE_ACTION_TYPE = "PDGoToRemoteAction"; diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDFileAttachmentAnnot.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDFileAttachmentAnnot.java index dc60adea5..6fe763ebb 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDFileAttachmentAnnot.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDFileAttachmentAnnot.java @@ -45,12 +45,12 @@ public Boolean getcontainsFS() { } @Override - public Boolean getfileSpecContainsAFRelationship() { + public String getAFRelationship() { COSObject fs = simplePDObject.getKey(ASAtom.FS); if (fs != null && fs.getType() == COSObjType.COS_DICT) { - return fs.knownKey(ASAtom.AF_RELATIONSHIP); + return fs.getNameKeyStringValue(ASAtom.AF_RELATIONSHIP); } - return false; + return null; } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDLinkAnnot.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDLinkAnnot.java index c99608dee..b4d706ea4 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDLinkAnnot.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDLinkAnnot.java @@ -20,12 +20,20 @@ */ package org.verapdf.gf.model.impl.pd.annotations; +import org.verapdf.cos.COSObject; import org.verapdf.gf.model.impl.pd.GFPDAnnot; +import org.verapdf.gf.model.impl.pd.GFPDDestination; import org.verapdf.gf.model.impl.pd.util.PDResourcesHandler; +import org.verapdf.model.baselayer.Object; +import org.verapdf.model.pdlayer.PDDestination; import org.verapdf.model.pdlayer.PDLinkAnnot; import org.verapdf.pd.PDAnnotation; import org.verapdf.pd.PDPage; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** * @author Maxim Plushchov */ @@ -33,8 +41,30 @@ public class GFPDLinkAnnot extends GFPDAnnot implements PDLinkAnnot { public static final String LINK_ANNOTATION_TYPE = "PDLinkAnnot"; + public static final String DEST = "Dest"; + public GFPDLinkAnnot(PDAnnotation annot, PDResourcesHandler pageResources, PDPage page) { super(annot, pageResources, page, LINK_ANNOTATION_TYPE); } + @Override + public List getLinkedObjects(String link) { + switch (link) { + case DEST: + return this.getDestination(); + default: + return super.getLinkedObjects(link); + } + } + + private List getDestination() { + COSObject destination = ((PDAnnotation) simplePDObject).getDestination(); + if (!destination.empty()) { + List destinations = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); + destinations.add(new GFPDDestination(destination)); + return Collections.unmodifiableList(destinations); + } + return Collections.emptyList(); + } + } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDCIDFont.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDCIDFont.java index 4ffa16d7b..6e67d3b52 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDCIDFont.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/font/GFPDCIDFont.java @@ -34,9 +34,6 @@ import org.verapdf.model.pdlayer.PDCIDFont; import org.verapdf.pd.font.FontProgram; import org.verapdf.pd.font.PDFont; -import org.verapdf.pd.font.cff.CFFCIDFontProgram; -import org.verapdf.pd.font.cff.CFFFontProgram; -import org.verapdf.pd.font.truetype.CIDFontType2Program; import org.verapdf.pdfa.flavours.PDFAFlavour; import org.verapdf.tools.StaticResources; @@ -129,6 +126,11 @@ public String getCIDToGIDMap() { return null; } + @Override + public Boolean getcontainsCIDSet() { + return ((org.verapdf.pd.font.PDCIDFont) this.pdFont).getCIDSet() != null; + } + /** * @return true if the CIDSet is present and correctly lists all glyphs * present in the embedded font program. diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEL.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEL.java index 113aa2087..9ff0b6520 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEL.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEL.java @@ -41,15 +41,9 @@ public String getListNumbering() { @Override public Boolean getcontainsLabels() { - return containsLabels(this); - } - - private boolean containsLabels(GFPDStructElem elem) { - if (elem.getChildrenStandardTypes().contains(TaggedPDFConstants.LBL)) { - return true; - } for (GFPDStructElem child : getChildren()) { - if (!TaggedPDFConstants.L.equals(child.getstandardType()) && containsLabels(child)) { + if (TaggedPDFConstants.LI.equals(child.getstandardType()) && + child.getChildrenStandardTypes().contains(TaggedPDFConstants.LBL)) { return true; } }