Skip to content

Commit

Permalink
PDF/UA-2. Add new methods.
Browse files Browse the repository at this point in the history
Remove unnecessary methods
  • Loading branch information
MaximPlusov committed Oct 19, 2023
1 parent eb22fa0 commit 2db0ba1
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package org.verapdf.model.impl.pb.cos;

import org.verapdf.model.impl.pb.operator.textshow.PUAHelper;
import org.verapdf.model.coslayer.CosActualText;
import org.apache.pdfbox.cos.COSString;

Expand All @@ -34,9 +33,4 @@ public class PBCosActualText extends PBCosString implements CosActualText {
public PBCosActualText(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 @@ -22,6 +22,7 @@

import org.apache.pdfbox.cos.COSString;
import org.verapdf.model.coslayer.CosString;
import org.verapdf.model.impl.pb.operator.textshow.PUAHelper;

/**
* Current class is representation of CosString interface of abstract model.
Expand Down Expand Up @@ -85,4 +86,9 @@ public Boolean getcontainsOnlyHex() {
public Long gethexCount() {
return this.hexCount;
}

@Override
public Boolean getcontainsPUA() {
return PUAHelper.containPUA(((COSString)baseObject).getString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.pdmodel.PDDocument;
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.impl.pb.pd.PBoxPDEncryption;
Expand Down Expand Up @@ -73,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 All @@ -84,13 +80,6 @@ public List<? extends Object> getLinkedObjects(String link) {
}
}

private List<CosIndirect> getCatalog() {
List<CosIndirect> catalog = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
COSBase base = ((COSDictionary) this.baseObject).getItem(COSName.ROOT);
catalog.add(new PBCosIndirect((COSObject) base, this.document, this.flavour));
return Collections.unmodifiableList(catalog);
}

private List<PDEncryption> getEncrypt() {
COSBase base = ((COSDictionary)this.baseObject).getDictionaryObject(COSName.ENCRYPT);
if (base != null && base instanceof COSDictionary) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ public String getN_type() {
return this.nType;
}

@Override
public Boolean getcontainsC() {
COSBase colorArray = ((PDAnnotation) this.simplePDObject).getCOSObject().getDictionaryObject(COSName.C);
return colorArray instanceof COSArray;
}

@Override
public Boolean getcontainsIC() {
COSBase colorArray = ((PDAnnotation) this.simplePDObject).getCOSObject().getDictionaryObject(COSName.IC);
return colorArray instanceof COSArray;
}

@Override
public String getFT() {
return this.ft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@
package org.verapdf.model.impl.pb.pd;

import org.apache.pdfbox.cos.*;
import org.apache.pdfbox.pdmodel.graphics.PDFontSetting;
import org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState;
import org.apache.pdfbox.pdmodel.graphics.state.RenderingIntent;
import org.verapdf.model.baselayer.Object;
import org.verapdf.model.coslayer.CosBM;
import org.verapdf.model.coslayer.CosNumber;
import org.verapdf.model.coslayer.CosRenderingIntent;
import org.verapdf.model.impl.pb.cos.PBCosBM;
import org.verapdf.model.impl.pb.cos.PBCosNumber;
import org.verapdf.model.impl.pb.cos.PBCosRenderingIntent;
import org.verapdf.model.impl.pb.pd.functions.PBoxPDFunction;
import org.verapdf.model.pdlayer.PDExtGState;
Expand Down Expand Up @@ -136,8 +133,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 Down Expand Up @@ -185,19 +180,6 @@ private List<CosRenderingIntent> getRI() {
return Collections.emptyList();
}

private List<CosNumber> getFontSize() {
PDFontSetting fontSetting = ((PDExtendedGraphicsState) this.simplePDObject)
.getFontSetting();
if (fontSetting != null) {
List<CosNumber> result = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
COSNumber size = (COSNumber) ((COSArray) fontSetting.getCOSObject()).get(1);
result.add(PBCosNumber.fromPDFBoxNumber(size));
return Collections.unmodifiableList(result);
}

return Collections.emptyList();
}

private List<PDHalftone> getHalftone() {
COSDictionary dict = ((PDExtendedGraphicsState) this.simplePDObject).getCOSObject();
COSBase halftone = dict.getDictionaryObject(COSName.getPDFName("HT"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class PBoxPDOutline extends PBoxPDObject implements PDOutline {
public static final String OUTLINE_TYPE = "PDOutline";

public static final String ACTION = "A";
public static final String DEST = "Dest";
public static final String TITLE = "Title";

private final String id;

Expand All @@ -55,10 +57,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 Collections.emptyList();
case TITLE:
return Collections.emptyList();
default:
return super.getLinkedObjects(link);
}
return super.getLinkedObjects(link);
}

private List<PDAction> getAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,9 @@
*/
package org.verapdf.model.impl.pb.pd.actions;

import org.apache.pdfbox.cos.*;
import org.apache.pdfbox.pdmodel.interactive.action.PDAction;
import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo;
import org.verapdf.model.baselayer.Object;
import org.verapdf.model.coslayer.CosNumber;
import org.verapdf.model.impl.pb.cos.PBCosNumber;
import org.verapdf.model.pdlayer.PDGoToAction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* @author Timur Kamalov
*/
Expand All @@ -45,33 +36,8 @@ public PBoxPDGoToAction(PDActionGoTo simplePDObject) {
super(simplePDObject, GOTO_ACTION_TYPE);
}

public PBoxPDGoToAction(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);
public Boolean getcontainsStructDestination() {
return null;
}

public List<CosNumber> getD() {
COSDictionary cosDictionary = ((PDAction) simplePDObject).getCOSObject();
if (cosDictionary != null) {
COSBase dEntry = cosDictionary.getDictionaryObject(COSName.D);
if (dEntry instanceof COSArray) {
List<CosNumber> result = new ArrayList<>();
for (COSBase cosBase : (COSArray) dEntry) {
if (cosBase instanceof COSNumber) {
result.add(PBCosNumber.fromPDFBoxNumber(cosBase));
}
}
return Collections.unmodifiableList(result);
}
}
return Collections.emptyList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* @author Timur Kamalov
*/
public class PBoxPDGoToRemoteAction extends PBoxPDGoToAction implements PDGoToRemoteAction {
public class PBoxPDGoToRemoteAction extends PBoxPDAction 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 @@ -24,19 +24,34 @@
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
import org.verapdf.model.baselayer.Object;
import org.verapdf.model.impl.pb.pd.PBoxPDAnnot;
import org.verapdf.model.pdlayer.PDLinkAnnot;
import org.verapdf.pdfa.flavours.PDFAFlavour;

import java.util.Collections;
import java.util.List;

/**
* @author Maxim Plushchov
*/
public class PBoxPDLinkAnnot extends PBoxPDAnnot implements PDLinkAnnot {

public static final String LINK_ANNOTATION_TYPE = "PDLinkAnnot";

public static final String DEST = "Dest";

public PBoxPDLinkAnnot(PDAnnotation annot, PDResources pageResources, PDDocument document, PDFAFlavour flavour, PDPage pdPage) {
super(annot, pageResources, document, flavour, LINK_ANNOTATION_TYPE, pdPage);
}

@Override
public List<? extends Object> getLinkedObjects(String link) {
switch (link) {
case DEST:
return Collections.emptyList();
default:
return super.getLinkedObjects(link);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public String getCIDToGIDMap() {
return null;
}

@Override
public Boolean getcontainsCIDSet() {
return getCIDSetStream() != null;
}

@Override
public Boolean getcidSetListsAllGlyphs() {
PDStream cidSet = getCIDSetStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ public void testGetIsEncryptedMethod() {
Assert.assertTrue(((CosTrailer) actual).getisEncrypted().booleanValue());
}

@Test
public void testCatalogLink() {
List<? extends Object> catalog = actual.getLinkedObjects(PBCosTrailer.CATALOG);
Assert.assertEquals(catalog.size(), 1);
Assert.assertTrue(catalog.get(0) instanceof CosIndirect);
}

@Test
public void testEncryptLink() {
List<? extends Object> encrypt = actual.getLinkedObjects(PBCosTrailer.ENCRYPT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,4 @@ public void testRenderingIntentLink() {
Assert.assertEquals(PBCosRenderingIntent.COS_RENDERING_INTENT_TYPE, object.getObjectType());
}
}

@Test
public void testFontSize() {
List<? extends Object> fontSize = actual.getLinkedObjects(PBoxPDExtGState.FONT_SIZE);
Assert.assertEquals(0, fontSize.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,4 @@ public void testNextLink() {
Assert.assertEquals(1, nextAction.size());
Assert.assertEquals(PBoxPDNamedAction.NAMED_ACTION_TYPE, nextAction.get(0).getObjectType());
}

@Test
public void testDLink() {
List<? extends Object> link = actual.getLinkedObjects(PBoxPDGoToAction.D);
Assert.assertEquals(0, link.size());
}

}

0 comments on commit 2db0ba1

Please sign in to comment.