Skip to content

Commit 3abbe88

Browse files
author
joris.schellekens
committed
Merge branch 'develop' of ssh://git.itextsupport.com:7999/i7j/itextcore into develop
2 parents 0f255bf + 46fe38c commit 3abbe88

File tree

41 files changed

+147
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+147
-92
lines changed

forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ This file is part of the iText (R) project.
8686
import com.itextpdf.layout.property.Property;
8787
import com.itextpdf.layout.property.TextAlignment;
8888
import com.itextpdf.layout.property.VerticalAlignment;
89-
import org.slf4j.Logger;
90-
import org.slf4j.LoggerFactory;
9189

9290
import java.io.IOException;
9391
import java.nio.charset.StandardCharsets;
@@ -96,6 +94,9 @@ This file is part of the iText (R) project.
9694
import java.util.List;
9795
import java.util.Set;
9896

97+
import org.slf4j.Logger;
98+
import org.slf4j.LoggerFactory;
99+
99100
/**
100101
* This class represents a single field or field group in an {@link com.itextpdf.forms.PdfAcroForm
101102
* AcroForm}.
@@ -1911,6 +1912,7 @@ public boolean regenerateField() {
19111912
appearance.getResources().addFont(getDocument(), localFont);
19121913
PdfDictionary ap = new PdfDictionary();
19131914
ap.put(PdfName.N, appearance.getPdfObject());
1915+
ap.setModified();
19141916
put(PdfName.AP, ap);
19151917

19161918
return true;

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public class PdfPage extends PdfObjectWrapper<PdfDictionary> {
7373
private static final long serialVersionUID = -952395541908379500L;
7474
private PdfResources resources = null;
7575
private int mcid = -1;
76-
private int structParents = -1;
7776
PdfPages parentPages;
7877
private List<PdfName> excludedKeys = new ArrayList<>(Arrays.asList(
7978
PdfName.Parent,
@@ -106,8 +105,6 @@ protected PdfPage(PdfDocument pdfDocument, PageSize pageSize) {
106105
getPdfObject().put(PdfName.MediaBox, new PdfArray(pageSize));
107106
getPdfObject().put(PdfName.TrimBox, new PdfArray(pageSize));
108107
if (pdfDocument.isTagged()) {
109-
structParents = (int) pdfDocument.getNextStructParentIndex();
110-
getPdfObject().put(PdfName.StructParents, new PdfNumber(structParents));
111108
setTabOrder(PdfName.S);
112109
}
113110
}
@@ -391,10 +388,6 @@ public PdfPage copyTo(PdfDocument toDocument, IPdfPageExtraCopier copier) {
391388
page.addAnnotation(-1, newAnnot, false);
392389
}
393390
}
394-
if (toDocument.isTagged()) {
395-
page.structParents = (int) toDocument.getNextStructParentIndex();
396-
page.getPdfObject().put(PdfName.StructParents, new PdfNumber(page.structParents));
397-
}
398391

399392
if (copier != null) {
400393
copier.copy(this, page);
@@ -720,17 +713,10 @@ public int getNextMcid() {
720713
* Gets {@link Integer} key of the page’s entry in the structural parent tree.
721714
*
722715
* @return {@link Integer} key of the page’s entry in the structural parent tree.
716+
* If page has no entry in the structural parent tree, returned value is -1.
723717
*/
724718
public Integer getStructParentIndex() {
725-
if (structParents == -1) {
726-
PdfNumber n = getPdfObject().getAsNumber(PdfName.StructParents);
727-
if (n != null) {
728-
structParents = n.intValue();
729-
} else {
730-
structParents = (int) getDocument().getNextStructParentIndex();
731-
}
732-
}
733-
return structParents;
719+
return getPdfObject().getAsNumber(PdfName.StructParents) != null ? getPdfObject().getAsNumber(PdfName.StructParents).intValue() : -1;
734720
}
735721

736722
/**

kernel/src/main/java/com/itextpdf/kernel/pdf/tagging/ParentTreeHandler.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public PdfObjRef findObjRefByStructParentIndex(PdfDictionary pageDict, int struc
122122
}
123123

124124
public int getNextMcidForPage(PdfPage page) {
125-
TreeMap<Integer, PdfMcr> pageMcrs = pageToPageMcrs.get(page.getPdfObject().getIndirectReference());
125+
TreeMap<Integer, PdfMcr> pageMcrs = (TreeMap) getPageMarkedContentReferences(page);
126126
if (pageMcrs == null || pageMcrs.size() == 0) {
127127
return 0;
128128
} else {
@@ -146,7 +146,7 @@ public void createParentTreeEntryForPage(PdfPage page) {
146146
return;
147147
}
148148
pageToPageMcrs.remove(page.getPdfObject().getIndirectReference());
149-
updateStructParentTreeEntries(page.getStructParentIndex(), mcrs);
149+
updateStructParentTreeEntries(page, mcrs);
150150
structTreeRoot.setModified();
151151
}
152152

@@ -269,7 +269,7 @@ private void registerAllMcrs() {
269269
}
270270
}
271271

272-
private void updateStructParentTreeEntries(Integer pageStructParentIndex, Map<Integer, PdfMcr> mcrs) {
272+
private void updateStructParentTreeEntries(PdfPage page, Map<Integer, PdfMcr> mcrs) {
273273
// element indexes in parentsOfPageMcrs shall be the same as mcid of one of their kids.
274274
// See "Finding Structure Elements from Content Items" in pdf spec.
275275
PdfArray parentsOfPageMcrs = new PdfArray();
@@ -289,10 +289,11 @@ private void updateStructParentTreeEntries(Integer pageStructParentIndex, Map<In
289289
}
290290
}
291291

292-
293292
if (parentsOfPageMcrs.size() > 0) {
294293
parentsOfPageMcrs.makeIndirect(structTreeRoot.getDocument());
295-
parentTree.addEntry(pageStructParentIndex, parentsOfPageMcrs);
294+
int structParents = (int) page.getStructParentIndex() != -1 ? (int) page.getStructParentIndex() : (int) page.getDocument().getNextStructParentIndex();
295+
page.getPdfObject().put(PdfName.StructParents, new PdfNumber(structParents));
296+
parentTree.addEntry((Integer) structParents, parentsOfPageMcrs);
296297
structTreeRoot.getDocument().checkIsoConformance(parentsOfPageMcrs, IsoKey.TAG_STRUCTURE_ELEMENT);
297298
parentsOfPageMcrs.flush();
298299
}

kernel/src/main/java/com/itextpdf/kernel/utils/CompareTool.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,25 @@ public CompareResult compareByCatalog(PdfDocument outDocument, PdfDocument cmpDo
187187
Set<PdfName> ignoredCatalogEntries = new LinkedHashSet<>(Arrays.asList(PdfName.Metadata));
188188
compareDictionariesExtended(outDocument.getCatalog().getPdfObject(), cmpDocument.getCatalog().getPdfObject(),
189189
catalogPath, compareResult, ignoredCatalogEntries);
190+
191+
// Method compareDictionariesExtended eventually calls compareObjects method which doesn't compare page objects.
192+
// At least for now compare page dictionaries explicitly here like this.
193+
if (cmpPagesRef == null || outPagesRef == null) {
194+
return compareResult;
195+
}
196+
197+
if (outPagesRef.size() != cmpPagesRef.size() && !compareResult.isMessageLimitReached()) {
198+
compareResult.addError(catalogPath, "Documents have different numbers of pages.");
199+
}
200+
for (int i = 0; i < Math.min(cmpPagesRef.size(), outPagesRef.size()); i++) {
201+
if (compareResult.isMessageLimitReached()) {
202+
break;
203+
}
204+
ObjectPath currentPath = new ObjectPath(cmpPagesRef.get(i), outPagesRef.get(i));
205+
PdfDictionary outPageDict = (PdfDictionary) outPagesRef.get(i).getRefersTo();
206+
PdfDictionary cmpPageDict = (PdfDictionary) cmpPagesRef.get(i).getRefersTo();
207+
compareDictionariesExtended(outPageDict, cmpPageDict, currentPath, compareResult);
208+
}
190209
return compareResult;
191210
}
192211

0 commit comments

Comments
 (0)