Skip to content

Commit 0a6dd44

Browse files
author
vitali.prudnikovich
committed
Fix MergeWithSameNamedOCGTest test to do not accept possible false positive
DEVSIX-6093
1 parent 9561a1a commit 0a6dd44

File tree

5 files changed

+6
-1
lines changed

5 files changed

+6
-1
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/OcgPropertiesCopier.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ private static void copyOCGs(Set<PdfIndirectReference> fromOcgsToCopy, PdfDictio
233233

234234
String currentLayerName = toOcg.getAsString(PdfName.Name).toUnicodeString();
235235

236+
// Here we check on existed layer names only in destination document but not in source document.
237+
// That is why there is no something like layerNames.add(currentLayerName); after this if statement
236238
if (layerNames.contains(currentLayerName)) {
237239
hasConflictingNames = true;
238240
int i = 0;

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ protected PdfObject copyObject(PdfObject obj, PdfDocument documentTo, boolean al
285285
}
286286

287287
SerializedObjectContent serializedContent = null;
288-
if (properties.smartMode && tryToFindDuplicate && !checkTypeOfPdfDictionary(obj, PdfName.Page) && !checkTypeOfPdfDictionary(obj, PdfName.OCG)) {
288+
if (properties.smartMode && tryToFindDuplicate && !checkTypeOfPdfDictionary(obj, PdfName.Page) &&
289+
!checkTypeOfPdfDictionary(obj, PdfName.OCG)) {
289290
serializedContent = smartModeSerializer.serializeObject(obj);
290291
PdfIndirectReference objectRef = smartModeSerializer.getSavedSerializedObject(serializedContent);
291292
if (objectRef != null) {

kernel/src/test/java/com/itextpdf/kernel/utils/PdfMergerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ public void MergeWithSameNamedOCGTest() throws IOException, InterruptedException
538538
}
539539

540540
Assert.assertNull(new CompareTool().compareByContent(mergedDocument, cmpDocument, destinationFolder));
541+
// We have to compare visually also because compareByContent doesn't catch the differences in OCGs with the same names
542+
Assert.assertNull(new CompareTool().compareVisually(mergedDocument, cmpDocument, destinationFolder, "diff_"));
541543
}
542544

543545
private void mergePdfs(List<File> sources, String destination) throws IOException {

0 commit comments

Comments
 (0)