Skip to content

Commit

Permalink
Add new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Oct 8, 2024
1 parent 7f3c6a9 commit 216166f
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ private List<CosLang> getLinkLang() {
}
return Collections.emptyList();
}

@Override
public Boolean getcontainsLang() {
return getLang() != null;
}

public COSString getLang() {
PDStructTreeRoot structTreeRoot = StaticResources.getDocument().getStructTreeRoot();
Expand Down Expand Up @@ -406,29 +411,51 @@ boolean isContainsTransparency() {
}

private List<PDXForm> parseAppearance() {
List<PDXForm> appearances = new ArrayList<>();
PDAppearanceEntry normalAppearance = ((PDAnnotation) simplePDObject).getNormalAppearance();
PDAppearanceEntry downAppearance = ((PDAnnotation) simplePDObject).getDownAppearance();
PDAppearanceEntry rolloverAppearance = ((PDAnnotation) simplePDObject).getRolloverAppearance();
if (normalAppearance != null || downAppearance != null || rolloverAppearance != null) {
List<PDXForm> appearances = new ArrayList<>();
if (normalAppearance != null) {
addContentStreamsFromAppearanceEntry(normalAppearance, appearances);
}
PDAppearanceEntry downAppearance = ((PDAnnotation) simplePDObject).getDownAppearance();
if (downAppearance != null) {
addContentStreamsFromAppearanceEntry(downAppearance, appearances);
}
PDAppearanceEntry rolloverAppearance = ((PDAnnotation) simplePDObject).getRolloverAppearance();
if (rolloverAppearance != null) {
addContentStreamsFromAppearanceEntry(rolloverAppearance, appearances);
return Collections.unmodifiableList(appearances);
}
return Collections.emptyList();
return Collections.unmodifiableList(appearances);
}

@Override
public Boolean getcontainsAppearances() {
PDAppearanceEntry normalAppearance = ((PDAnnotation) simplePDObject).getNormalAppearance();
if (normalAppearance != null) {
return containsAppearances(normalAppearance);
}
PDAppearanceEntry downAppearance = ((PDAnnotation) simplePDObject).getDownAppearance();
if (downAppearance != null) {
return containsAppearances(downAppearance);
}
PDAppearanceEntry rolloverAppearance = ((PDAnnotation) simplePDObject).getRolloverAppearance();
if (rolloverAppearance != null) {
return containsAppearances(rolloverAppearance);
}
return false;
}

private boolean containsAppearances(PDAppearanceEntry appearanceEntry) {
return !appearanceEntry.isSubDictionary() || !appearanceEntry.getSubDictionary().isEmpty();
}

private void addContentStreamsFromAppearanceEntry(PDAppearanceEntry appearanceEntry, List<PDXForm> appearances) {
if (appearanceEntry != null) {
if (appearanceEntry.isSubDictionary()) {
Map<ASAtom, PDAppearanceStream> subDictionary = appearanceEntry.getSubDictionary();
for (PDAppearanceStream stream : subDictionary.values()) {
addAppearance(appearances, stream);
}
} else {
addAppearance(appearances, appearanceEntry.getAppearanceStream());
if (appearanceEntry.isSubDictionary()) {
Map<ASAtom, PDAppearanceStream> subDictionary = appearanceEntry.getSubDictionary();
for (PDAppearanceStream stream : subDictionary.values()) {
addAppearance(appearances, stream);
}
} else {
addAppearance(appearances, appearanceEntry.getAppearanceStream());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ private List<PDMetadata> getMetadata() {
return Collections.emptyList();
}

@Override
public Boolean getcontainsMetadata() {
org.verapdf.pd.PDMetadata meta = this.catalog != null ? this.catalog.getMetadata() : null;
return meta != null && org.verapdf.pd.PDMetadata.isMetadataObject(meta.getObject());
}

private List<OutputIntents> getOutputIntents() {
if (this.outputIntents == null) {
this.outputIntents = parseOutputIntents();
Expand Down Expand Up @@ -268,6 +274,11 @@ private List<PDStructTreeRoot> getStructureTreeRoot() {
return Collections.emptyList();
}

@Override
public Boolean getcontainsStructTreeRoot() {
return document.getStructTreeRoot() != null;
}

private List<PDPerms> getPerms() {
if (this.catalog != null) {
COSObject perms = this.catalog.getKey(ASAtom.PERMS);
Expand Down Expand Up @@ -307,6 +318,12 @@ private List<CosLang> getLang() {
return Collections.emptyList();
}

@Override
public Boolean getcontainsLang() {
COSObject baseLang = this.catalog != null ? catalog.getKey(ASAtom.LANG) : null;
return baseLang != null && baseLang.getType() == COSObjType.COS_STRING;
}

@Override
public String getVersion() {
return catalog != null ? catalog.getVersion() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ public Boolean getcontainsAA() {
return this.simplePDObject.knownKey(ASAtom.AA);
}

private List<CosLang> getLang() {
private List<CosLang> getLinkLang() {
COSString lang = getLang();
if (lang != null) {
List<CosLang> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new GFCosLang(lang));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

private COSString getLang() {
PDStructTreeRoot structTreeRoot = StaticResources.getDocument().getStructTreeRoot();
Long structParent = ((org.verapdf.pd.form.PDFormField)this.simplePDObject).getStructParent();
if (structTreeRoot != null && structParent != null) {
Expand All @@ -89,13 +99,16 @@ private List<CosLang> getLang() {
if (structureElement != null) {
COSObject baseLang = structureElement.getKey(ASAtom.LANG);
if (baseLang != null && baseLang.getType() == COSObjType.COS_STRING) {
List<CosLang> 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;
}

@Override
public Boolean getcontainsLang() {
return getLang() != null;
}

@Override
Expand All @@ -114,7 +127,7 @@ public List<? extends Object> getLinkedObjects(String link) {
case ADDITIONAL_ACTION:
return this.getAdditionalAction();
case LANG:
return this.getLang();
return this.getLinkLang();
case KIDS:
return this.getKids();
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,18 @@ private List<PDGroup> getGroup() {

private List<PDAnnot> getAnnotations() {
if (this.annotations == null) {
this.annotations = parseAnnotataions();
this.annotations = parseAnnotations();
}

return this.annotations;
}

private List<PDAnnot> parseAnnotataions() {
@Override
public Boolean getcontainsAnnotations() {
return !((org.verapdf.pd.PDPage) simplePDObject).getAnnotations().isEmpty();
}

private List<PDAnnot> parseAnnotations() {
StaticContainers.getTransparencyVisitedContentStreams().clear();
List<PDAnnotation> annots = ((org.verapdf.pd.PDPage) simplePDObject).getAnnotations();
if (!annots.isEmpty()) {
Expand Down Expand Up @@ -299,7 +304,7 @@ public Boolean getcontainsTransparency() {
this.contentStreams = parseContentStream();
}
if (this.annotations == null) {
this.annotations = parseAnnotataions();
this.annotations = parseAnnotations();
}
return this.containsTransparency;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ private List<CosLang> getLang() {
return Collections.emptyList();
}

@Override
public Boolean getcontainsLang() {
return ((org.verapdf.pd.structure.PDStructElem) this.simplePDObject).getLang() != null;
}

@Override
public String getparentLang() {
Set<COSKey> keys = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ private List<CMapFile> getEmbeddedFile() {
}
return Collections.emptyList();
}

@Override
public Boolean getcontainsEmbeddedFile() {
return this.pdcMap.getcMap().getType() == COSObjType.COS_STREAM;
}

/**
* @return link to the CMap referenced by the key /UseCMap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ private static List<FontProgram> getFontProgramList(FontProgram fontProgram) {
return Collections.unmodifiableList(list);
}

@Override
public Boolean getcontainsFontFile() {
return this.pdFont.getFontProgram() != null && this.fontProgramParsed;
}

/**
* @return link to the name Object referenced by BaseFont key.
*/
Expand Down

0 comments on commit 216166f

Please sign in to comment.