Skip to content

Commit

Permalink
Merge pull request #327 from veraPDF/appearance_xform
Browse files Browse the repository at this point in the history
Change appearance link from PDContentStream to PDXForm in PDAnnot
  • Loading branch information
MaximPlusov authored Oct 23, 2023
2 parents a076105 + c3c2326 commit a3c30dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@
import org.verapdf.model.impl.pb.pd.annotations.PBoxPDPrinterMarkAnnot;
import org.verapdf.model.impl.pb.pd.annotations.PBoxPDTrapNetAnnot;
import org.verapdf.model.impl.pb.pd.annotations.PBoxPDWidgetAnnot;
import org.verapdf.model.pdlayer.PDAction;
import org.verapdf.model.pdlayer.PDAdditionalActions;
import org.verapdf.model.pdlayer.PDAnnot;
import org.verapdf.model.pdlayer.PDContentStream;
import org.verapdf.model.impl.pb.pd.images.PBoxPDXForm;
import org.verapdf.model.pdlayer.*;
import org.verapdf.model.tools.resources.PDInheritableResources;
import org.verapdf.pdfa.flavours.PDFAFlavour;

Expand Down Expand Up @@ -100,7 +98,7 @@ public class PBoxPDAnnot extends PBoxPDObject implements PDAnnot {
private final PDFAFlavour flavour;
private final PDPage pdPage;

private List<PDContentStream> appearance = null;
private List<PDXForm> appearance = null;
private List<CosBM> blendMode = null;
private boolean containsTransparency = false;

Expand Down Expand Up @@ -425,7 +423,7 @@ private List<PDAction> getA() {
* @return normal appearance stream (N key in the appearance dictionary) of
* the annotation
*/
private List<PDContentStream> getAppearance() {
private List<PDXForm> getAppearance() {
if (this.appearance == null) {
parseAppearance();
}
Expand All @@ -450,7 +448,7 @@ private void parseAppearance() {
COSBase downAppearanceBase = dictionary.getDictionaryObject(COSName.D);
COSBase rolloverAppearanceBase = dictionary.getDictionaryObject(COSName.R);
if (normalAppearanceBase != null || downAppearanceBase != null || rolloverAppearanceBase != null) {
List<PDContentStream> appearances = new ArrayList<>();
List<PDXForm> appearances = new ArrayList<>();
addContentStreamsFromAppearanceEntry(normalAppearanceBase, appearances);
addContentStreamsFromAppearanceEntry(downAppearanceBase, appearances);
addContentStreamsFromAppearanceEntry(rolloverAppearanceBase, appearances);
Expand All @@ -463,7 +461,7 @@ private void parseAppearance() {
}
}

private void addContentStreamsFromAppearanceEntry(COSBase appearanceEntry, List<PDContentStream> appearances) {
private void addContentStreamsFromAppearanceEntry(COSBase appearanceEntry, List<PDXForm> appearances) {
if (appearanceEntry != null) {
PDAppearanceEntry newAppearance = new PDAppearanceEntry(appearanceEntry);
if (newAppearance.isStream()) {
Expand All @@ -477,15 +475,13 @@ private void addContentStreamsFromAppearanceEntry(COSBase appearanceEntry, List<
}
}

private void addAppearance(List<PDContentStream> list, PDAppearanceStream toAdd) {
private void addAppearance(List<PDXForm> list, PDAppearanceStream toAdd) {
if (toAdd != null) {
PDInheritableResources resources = PDInheritableResources.getInstance(this.pageResources,
toAdd.getResources());
PBoxPDContentStream stream = new PBoxPDContentStream(toAdd, resources, this.document, this.flavour);
this.containsTransparency |= stream.isContainsTransparency();
org.apache.pdfbox.pdmodel.graphics.form.PDGroup group = toAdd.getGroup();
this.containsTransparency |= group != null && COSName.TRANSPARENCY.equals(group.getSubType());
list.add(stream);
PBoxPDXForm xForm = new PBoxPDXForm(toAdd, resources, this.document, this.flavour);
this.containsTransparency |= xForm.containsTransparency();
list.add(xForm);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.verapdf.model.impl.pb.pd.actions.PBoxPDGoToAction;
import org.verapdf.model.impl.pb.pd.actions.PBoxPDGoToRemoteAction;
import org.verapdf.model.impl.pb.pd.actions.PBoxPDNamedAction;
import org.verapdf.model.impl.pb.pd.images.PBoxPDXForm;
import org.verapdf.model.pdlayer.PDAnnot;

import java.io.IOException;
Expand Down Expand Up @@ -112,7 +113,7 @@ public void testAppearanceLink() {
List<? extends Object> action = actual.getLinkedObjects(PBoxPDAnnot.APPEARANCE);
Assert.assertEquals(1, action.size());
for (Object object : action) {
Assert.assertEquals(PBoxPDContentStream.CONTENT_STREAM_TYPE, object.getObjectType());
Assert.assertEquals(PBoxPDXForm.X_FORM_TYPE, object.getObjectType());
}
}

Expand Down

0 comments on commit a3c30dc

Please sign in to comment.