Skip to content

Commit

Permalink
PDF/UA-2. Add methods getghostRefs to GFSEFENote
Browse files Browse the repository at this point in the history
and getOpenActionDestination to GFPDDocument
  • Loading branch information
MaximPlusov committed Mar 28, 2024
1 parent 99592df commit 86b0c81
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class GFPDDocument extends GFPDObject implements PDDocument {
* Link name for open action of document
*/
public static final String OPEN_ACTION = "OpenAction";
public static final String OPEN_ACTION_DESTINATION = "OpenActionDestination";
/**
* Link name for all outlines of document
*/
Expand Down Expand Up @@ -149,6 +150,8 @@ public List<? extends Object> getLinkedObjects(String link) {
return this.getOutlines();
case OPEN_ACTION:
return this.getOpenAction();
case OPEN_ACTION_DESTINATION:
return this.getOpenActionDestination();
case ACTIONS:
return this.getActions();
case PAGES:
Expand Down Expand Up @@ -185,6 +188,15 @@ private List<PDAction> getOpenAction() {
return Collections.unmodifiableList(actions);
}

private List<PDDestination> getOpenActionDestination() {
List<PDDestination> destinations = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
COSObject openAction = this.catalog.getKey(ASAtom.OPEN_ACTION);
if (openAction != null && openAction.getType() == COSObjType.COS_ARRAY) {
destinations.add(new GFPDDestination(openAction));
}
return Collections.unmodifiableList(destinations);
}

private List<PDAdditionalActions> getActions() {
if (this.catalog != null) {
PDCatalogAdditionalActions additionalActions = this.catalog.getAdditionalActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,7 @@ public String getorphanRefs() {
if (set == null) {
return null;
}
COSObject ref = ((PDStructElem)simplePDObject).getRef();
Set<COSKey> refsKeys = new HashSet<>();
if (ref.getType() == COSObjType.COS_ARRAY) {
for (COSObject elem : (COSArray) ref.getDirectBase()) {
COSKey elementKey = elem.getKey();
if (elementKey != null) {
refsKeys.add(elementKey);
}
}
}
Set<COSKey> refsKeys = getRefKeys();
Set<String> keys = new HashSet<>();
for (COSKey refKey : set) {
if (!refsKeys.contains(refKey)) {
Expand All @@ -69,6 +60,39 @@ public String getorphanRefs() {
return null;
}

@Override
public String getghostRefs() {
Set<COSKey> set = StaticContainers.getStructElementsRefs().get(simpleCOSObject.getKey());
if (set == null) {
set = Collections.emptySet();
}
Set<COSKey> refsKeys = getRefKeys();
Set<String> keys = new HashSet<>();
for (COSKey refKey : refsKeys) {
if (!set.contains(refKey)) {
keys.add(refKey.toString());
}
}
if (!keys.isEmpty()) {
return String.join(",", keys);
}
return null;
}

private Set<COSKey> getRefKeys() {
COSObject ref = ((PDStructElem)simplePDObject).getRef();
Set<COSKey> refsKeys = new HashSet<>();
if (ref.getType() == COSObjType.COS_ARRAY) {
for (COSObject elem : (COSArray) ref.getDirectBase()) {
COSKey elementKey = elem.getKey();
if (elementKey != null) {
refsKeys.add(elementKey);
}
}
}
return refsKeys;
}

public GFSEFENote(PDStructElem structElemDictionary) {
super(structElemDictionary, TaggedPDFConstants.FENOTE, FE_NOTE_STRUCTURE_ELEMENT_TYPE);
}
Expand Down

0 comments on commit 86b0c81

Please sign in to comment.