Skip to content

Commit

Permalink
Merge pull request #592 from veraPDF/pdfua2_methods
Browse files Browse the repository at this point in the history
PDF/UA-2. Add new methods. Remove unnecessary methods
  • Loading branch information
MaximPlusov authored and Git User committed Oct 19, 2023
1 parent afeac88 commit b2ca608
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -88,4 +89,8 @@ public Long gethexCount() {
return Long.valueOf(this.hexCount);
}

@Override
public Boolean getcontainsPUA() {
return PUAHelper.containPUA(baseObject.getString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@
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;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand All @@ -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";

Expand All @@ -74,8 +71,6 @@ public Boolean getisEncrypted() {
@Override
public List<? extends Object> getLinkedObjects(String link) {
switch (link) {
case CATALOG:
return this.getCatalog();
case ENCRYPT:
return this.getEncrypt();
case INFO:
Expand Down Expand Up @@ -104,16 +99,4 @@ private List<CosInfo> getInfo() {
}
return Collections.emptyList();
}

private List<CosIndirect> getCatalog() {
List<CosIndirect> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* 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;

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -161,8 +159,6 @@ public List<? extends Object> getLinkedObjects(String link) {
switch (link) {
case RI:
return this.getRI();
case FONT_SIZE:
return this.getFontSize();
case HALFTONE:
return this.getHalftone();
case CUSTOM_FUNCTIONS:
Expand All @@ -185,18 +181,6 @@ private List<CosRenderingIntent> getRI() {
return Collections.emptyList();
}

private List<CosNumber> getFontSize() {
COSNumber fontSize = ((org.verapdf.pd.PDExtGState) this.simplePDObject)
.getCOSFontSize();
if (fontSize != null) {
List<CosNumber> result = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
result.add(GFCosNumber.fromPDFParserNumber(fontSize));
return Collections.unmodifiableList(result);
}

return Collections.emptyList();
}

private List<PDHalftone> getHalftone() {
org.verapdf.pd.PDHalftone halftone = ((org.verapdf.pd.PDExtGState) simplePDObject).getHalftone();
if (halftone != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -53,10 +62,16 @@ public String getID() {

@Override
public List<? extends Object> 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<PDAction> getAction() {
Expand All @@ -69,4 +84,24 @@ private List<PDAction> getAction() {
}
return Collections.emptyList();
}

private List<PDDestination> getDestination() {
COSObject destination = ((PDOutlineItem) simplePDObject).getDestination();
if (!destination.empty()) {
List<PDDestination> destinations = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
destinations.add(new GFPDDestination(destination));
return Collections.unmodifiableList(destinations);
}
return Collections.emptyList();
}

private List<CosTextString> getTitle() {
COSObject title = this.simplePDObject.getKey(ASAtom.TITLE);
if (title != null && title.getType() == COSObjType.COS_STRING) {
List<CosTextString> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new GFCosTextString((COSString) title.getDirectBase()));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,22 @@
*/
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
*/
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<? extends Object> getLinkedObjects(String link) {
if (D.equals(link)) {
return this.getD();
}
return super.getLinkedObjects(link);
}

private List<CosNumber> getD() {
List<COSNumber> numbers = ((PDAction) simplePDObject).getCOSArrayD();
if (!numbers.isEmpty()) {
List<CosNumber> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Loading

0 comments on commit b2ca608

Please sign in to comment.