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 cad8b45 commit 8a5bbb0
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ public String getAP() {
return this.ap;
}

@Override
public Boolean getcontainsAppearances() {
if (this.appearance == null) {
parseAppearance();
}
return !this.appearance.isEmpty();
}

@Override
public Long getF() {
return isFKeyPresent ? Long.valueOf(this.annotationFlag) : null;
Expand Down Expand Up @@ -292,7 +300,22 @@ public String getstructParentObjectKey() {
return null;
}

private List<CosLang> getLang() {
@Override
public Boolean getcontainsLang() {
return getLang() != null;
}

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

private String getLang() {
PDStructureTreeRoot structTreeRoot = this.document.getDocumentCatalog().getStructureTreeRoot();
int structParent = ((PDAnnotation) this.simplePDObject).getStructParent();
if (structTreeRoot != null && structParent != 0) {
Expand All @@ -302,18 +325,13 @@ private List<CosLang> getLang() {
PDParentTreeValue treeValue = parentTreeRoot == null ? null : (PDParentTreeValue) parentTreeRoot.getValue(structParent);
structureElement = treeValue == null ? null : treeValue.getCOSObject();
} catch (IOException e) {
return Collections.emptyList();
return null;
}
if (structureElement instanceof COSDictionary) {
String lang = ((COSDictionary) structureElement).getNameAsString(COSName.LANG);
if (lang != null) {
List<CosLang> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new PBCosLang(new COSString(lang)));
return Collections.unmodifiableList(list);
}
return ((COSDictionary) structureElement).getNameAsString(COSName.LANG);
}
}
return Collections.emptyList();
return null;
}

@Override
Expand Down Expand Up @@ -373,7 +391,7 @@ public List<? extends Object> getLinkedObjects(String link) {
case APPEARANCE:
return this.getAppearance();
case LANG:
return this.getLang();
return this.getLinkLang();
case BM:
return this.getBM();
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ private List<PDPerms> getPerms() {
return Collections.emptyList();
}

@Override
public Boolean getcontainsMetadata() {
org.apache.pdfbox.pdmodel.common.PDMetadata meta = this.catalog != null ? this.catalog.getMetadata() : null;
return meta != null && PBoxPDMetadata.isMetadataObject(meta.getCOSObject());
}

@Override
public Boolean getcontainsStructTreeRoot() {
return this.catalog != null && this.catalog.getStructureTreeRoot() != null;
}

@Override
public Boolean getcontainsAlternatePresentations() {
if (this.catalog != null) {
Expand Down Expand Up @@ -371,5 +382,10 @@ private List<CosLang> getLang() {
}
return Collections.emptyList();
}

@Override
public Boolean getcontainsLang() {
return this.catalog != null && catalog.getCOSObject().getDictionaryObject(COSName.LANG) instanceof COSString;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public Boolean getcontainsAA() {
((COSDictionary) pageObject).containsKey(COSName.AA);
}

@Override
public Boolean getcontainsLang() {
return false;
}

@Override
public String getTU() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Boolean getcontainsTransparency() {
parseContentStream();
}
if (this.annotations == null) {
this.annotations = parseAnnotataions();
this.annotations = parseAnnotations();
}
return Boolean.valueOf(this.containsTransparency);
}
Expand Down Expand Up @@ -304,13 +304,22 @@ private List<PDAdditionalActions> getActions() {

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() {
if (this.annotations == null) {
this.annotations = parseAnnotations();
}

return !this.annotations.isEmpty();
}

private List<PDAnnot> parseAnnotations() {
try {
List<PDAnnotation> pdfboxAnnotations = ((org.apache.pdfbox.pdmodel.PDPage) this.simplePDObject)
.getAnnotations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ public String getstandardType() {
return null;
}

@Override
public Boolean getcontainsLang() {
COSBase baseLang = ((COSDictionary) this.simplePDObject).getDictionaryObject(COSName.LANG);
return baseLang instanceof COSString;
}

@Override
public String getparentLang() {
COSDictionary parentDict = (COSDictionary)((COSDictionary) this.simplePDObject).getDictionaryObject(COSName.P);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public String getCMapName() {
return this.cMap.getName();
}

@Override
public Boolean getcontainsEmbeddedFile() {
return this.simplePDObject instanceof COSStream;
}

@Override
public List<? extends Object> getLinkedObjects(String link) {
switch (link) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,22 @@ public List<? extends Object> getLinkedObjects(String link) {
}

private List<FontProgram> getFontFile() {
FontProgram fontProgram = getFontProgram();
if (fontProgram != null) {
return PBoxPDFont.getFontProgramList(fontProgram);
}
return Collections.emptyList();
}

@Override
public Boolean getcontainsFontFile() {
return getFontProgram() != null;
}

private FontProgram getFontProgram() {
if (!getSubtype().equals(FontFactory.TYPE_3) && (this.pdFontLike.isEmbedded())) {
if (getSubtype().equals(FontFactory.TRUE_TYPE)) {
PBoxTrueTypeFontProgram trueTypeFontProgram = new PBoxTrueTypeFontProgram(
((PDTrueTypeFont) this.pdFontLike).getTrueTypeFont(), getisSymbolic());
return PBoxPDFont.getFontProgramList(trueTypeFontProgram);
return new PBoxTrueTypeFontProgram(((PDTrueTypeFont) this.pdFontLike).getTrueTypeFont(), getisSymbolic());
}
PDFontDescriptor fontDescriptor = pdFontLike.getFontDescriptor();
PDStream fontFile;
Expand All @@ -153,10 +164,10 @@ private List<FontProgram> getFontFile() {
fontFile = fontDescriptor.getFontFile3();
}
if (fontFile != null) {
return PBoxPDFont.getFontProgramList(new PBoxFontProgram(fontFile));
return new PBoxFontProgram(fontFile);
}
}
return Collections.emptyList();
return null;
}

private static List<FontProgram> getFontProgramList(FontProgram fontProgram) {
Expand Down

0 comments on commit 8a5bbb0

Please sign in to comment.