Skip to content

Commit 67ff34f

Browse files
committed
PDF/UA-2. Fix differentTargetAnnotObjectKey calculation
1 parent 0e86c53 commit 67ff34f

3 files changed

Lines changed: 17 additions & 25 deletions

File tree

validation-model/src/main/java/org/verapdf/gf/model/impl/containers/StaticContainers.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class StaticContainers {
5050

5151
private static final ThreadLocal<Set<COSKey>> fileSpecificationKeys = new ThreadLocal<>();
5252

53-
private static final ThreadLocal<Map<COSKey, Set<COSKey>>> destinationToStructParentsMap = new ThreadLocal<>();
53+
private static final ThreadLocal<Map<COSKey, Map<COSKey, String>>> structParentToDestinationToAnnotMap = new ThreadLocal<>();
5454

5555
private static final ThreadLocal<Stack<COSKey>> transparencyVisitedContentStreams = new ThreadLocal<>();
5656

@@ -74,7 +74,7 @@ public static void clearAllContainers() {
7474
cachedColorSpaces.set(new HashMap<>());
7575
cachedFonts.set(new HashMap<>());
7676
fileSpecificationKeys.set(new HashSet<>());
77-
destinationToStructParentsMap.set(new HashMap<>());
77+
structParentToDestinationToAnnotMap.set(new HashMap<>());
7878
transparencyVisitedContentStreams.set(new Stack<>());
7979
cachedGlyphs.set(new HashMap<>());
8080
noteIDSet.set(new HashSet<>());
@@ -124,15 +124,15 @@ public static void setInconsistentSeparations(List<String> inconsistentSeparatio
124124
StaticContainers.inconsistentSeparations.set(inconsistentSeparations);
125125
}
126126

127-
public static Map<COSKey, Set<COSKey>> getDestinationToStructParentsMap() {
128-
if (destinationToStructParentsMap.get() == null) {
129-
destinationToStructParentsMap.set(new HashMap<>());
127+
public static Map<COSKey, Map<COSKey, String>> getStructParentToDestinationToAnnotMap() {
128+
if (structParentToDestinationToAnnotMap.get() == null) {
129+
structParentToDestinationToAnnotMap.set(new HashMap<>());
130130
}
131-
return destinationToStructParentsMap.get();
131+
return structParentToDestinationToAnnotMap.get();
132132
}
133133

134-
public static void setDestinationToStructParentsMap(Map<COSKey, Set<COSKey>> destinationToStructParentsMap) {
135-
StaticContainers.destinationToStructParentsMap.set(destinationToStructParentsMap);
134+
public static void setStructParentToDestinationToAnnotMap(Map<COSKey, Map<COSKey, String>> structParentToDestinationToAnnotMap) {
135+
StaticContainers.structParentToDestinationToAnnotMap.set(structParentToDestinationToAnnotMap);
136136
}
137137

138138
public static Map<String, PDColorSpace> getCachedColorSpaces() {

validation-model/src/main/java/org/verapdf/gf/model/impl/external/GFEmbeddedFile.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.verapdf.gf.model.GFModelParser;
2828
import org.verapdf.gf.model.impl.containers.StaticContainers;
2929
import org.verapdf.gf.model.impl.pd.colors.GFPDSeparation;
30-
import org.verapdf.parser.PDFFlavour;
3130
import org.verapdf.tools.TaggedPDFRoleMapHelper;
3231
import org.verapdf.model.external.EmbeddedFile;
3332
import org.verapdf.model.operator.Glyph;
@@ -131,7 +130,7 @@ private static boolean isValidPdfaStream(final InputStream toValidate, final PDF
131130
private Set<String> noteIDSet;
132131
private Set<COSKey> xFormKeysSet;
133132
private Set<COSKey> fileSpecificationKeys;
134-
private Map<COSKey, Set<COSKey>> destinationToStructParentsMap;
133+
private Map<COSKey, Map<COSKey, String>> structParentToDestinationToAnnotMap;
135134
private Stack<COSKey> transparencyVisitedContentStreams;
136135
private Map<String, PDFont> cachedPDFonts;
137136
private Map<String, Map<String, Glyph>> cachedGlyphs;
@@ -157,7 +156,7 @@ private void saveStaticContainersState() {
157156
this.cachedColorSpaces = StaticContainers.getCachedColorSpaces();
158157
this.cachedPDFonts = StaticContainers.getCachedFonts();
159158
this.fileSpecificationKeys = StaticContainers.getFileSpecificationKeys();
160-
this.destinationToStructParentsMap = StaticContainers.getDestinationToStructParentsMap();
159+
this.structParentToDestinationToAnnotMap = StaticContainers.getStructParentToDestinationToAnnotMap();
161160
this.noteIDSet = StaticContainers.getNoteIDSet();
162161
this.xFormKeysSet = StaticContainers.getXFormKeysSet();
163162
this.transparencyVisitedContentStreams = StaticContainers.getTransparencyVisitedContentStreams();
@@ -187,7 +186,7 @@ private void restoreSavedSCState() {
187186
StaticContainers.setCachedColorSpaces(this.cachedColorSpaces);
188187
StaticContainers.setCachedFonts(this.cachedPDFonts);
189188
StaticContainers.setFileSpecificationKeys(this.fileSpecificationKeys);
190-
StaticContainers.setDestinationToStructParentsMap(this.destinationToStructParentsMap);
189+
StaticContainers.setStructParentToDestinationToAnnotMap(this.structParentToDestinationToAnnotMap);
191190
StaticContainers.setNoteIDSet(this.noteIDSet);
192191
StaticContainers.setXFormKeysSet(this.xFormKeysSet);
193192
StaticContainers.setTransparencyVisitedContentStreams(this.transparencyVisitedContentStreams);

validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDLinkAnnot.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,15 @@ private void calculateStructDestinationProperties() {
9494
return;
9595
}
9696
COSKey structDestinationKey = structDestination.getKey();
97-
for (Map.Entry<COSKey, Set<COSKey>> entry : StaticContainers.getDestinationToStructParentsMap().entrySet()) {
98-
if (structDestinationKey.equals(entry.getKey())) {
99-
continue;
100-
}
101-
for (COSKey structParentObjectKey : entry.getValue()) {
102-
if (structParentKey.equals(structParentObjectKey)) {
103-
differentTargetAnnotObjectKey = structParentObjectKey.toString();
104-
break;
105-
}
106-
}
107-
if (differentTargetAnnotObjectKey != null) {
97+
Map<COSKey, String> destinationToAnnotMap = StaticContainers.getStructParentToDestinationToAnnotMap()
98+
.computeIfAbsent(structParentKey, k -> new HashMap<>());
99+
for (Map.Entry<COSKey, String> entry : destinationToAnnotMap.entrySet()) {
100+
if (!structDestinationKey.equals(entry.getKey())) {
101+
differentTargetAnnotObjectKey = entry.getValue();
108102
break;
109103
}
110104
}
111-
StaticContainers.getDestinationToStructParentsMap().computeIfAbsent(structDestinationKey,
112-
k -> new HashSet<>()).add(structParentKey);
105+
StaticContainers.getStructParentToDestinationToAnnotMap().get(structParentKey).put(structDestinationKey, getobjectKey());
113106
}
114107

115108
private COSObject getStructureDestinationObject() {

0 commit comments

Comments
 (0)