Skip to content

Commit 6a3525a

Browse files
yulian-gaponenkoiText-CI
authored andcommitted
Make CompareTool compare page dictionaries as usual dictionaries if both cmp and out page dicts are not in the doc's page trees
DEVSIX-2137 Autoported commit. Original commit hash: [8941ee367]
1 parent 57a4bc8 commit 6a3525a

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

itext/itext.kernel/itext/kernel/utils/CompareTool.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,14 +1579,19 @@ private bool CompareObjects(PdfObject outObj, PdfObject cmpObj, CompareTool.Obje
15791579
outPagesRef.Add(outRefKey.GetDocument().GetPage(i).GetPdfObject().GetIndirectReference());
15801580
}
15811581
}
1582-
if (cmpPagesRef.Contains(cmpRefKey) && cmpPagesRef.IndexOf(cmpRefKey) == outPagesRef.IndexOf(outRefKey)) {
1583-
return true;
1584-
}
1585-
if (compareResult != null && currentPath != null) {
1586-
compareResult.AddError(currentPath, MessageFormatUtil.Format("The dictionaries refer to different pages. Expected page number: {0}. Found: {1}"
1587-
, cmpPagesRef.IndexOf(cmpRefKey) + 1, outPagesRef.IndexOf(outRefKey)) + 1);
1582+
// If at least on of the page dictionaries is in the document's page tree, we don't proceed with deep comparison,
1583+
// because pages are compared at different level, so we compare only their index.
1584+
// However only if both page dictionaries are not in the document's page trees, we continue to comparing them as normal dictionaries.
1585+
if (cmpPagesRef.Contains(cmpRefKey) || outPagesRef.Contains(outRefKey)) {
1586+
if (cmpPagesRef.Contains(cmpRefKey) && cmpPagesRef.IndexOf(cmpRefKey) == outPagesRef.IndexOf(outRefKey)) {
1587+
return true;
1588+
}
1589+
if (compareResult != null && currentPath != null) {
1590+
compareResult.AddError(currentPath, MessageFormatUtil.Format("The dictionaries refer to different pages. Expected page number: {0}. Found: {1}"
1591+
, cmpPagesRef.IndexOf(cmpRefKey) + 1, outPagesRef.IndexOf(outRefKey) + 1));
1592+
}
1593+
return false;
15881594
}
1589-
return false;
15901595
}
15911596
if (cmpDirectObj.IsDictionary()) {
15921597
if (!CompareDictionariesExtended((PdfDictionary)outDirectObj, (PdfDictionary)cmpDirectObj, currentPath, compareResult

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
680a4df24ec910b99f69f92ed2867a2bd25a494a
1+
8941ee367cc2b99fbe8bd3cb63f391bdf2f167af

0 commit comments

Comments
 (0)