Skip to content

Commit 47479eb

Browse files
Merge branch 'free_refs_improvements' into develop
2 parents ed9fabe + f6d90f6 commit 47479eb

Some content is hidden

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

49 files changed

+1607
-253
lines changed

forms/src/main/java/com/itextpdf/forms/PdfAcroForm.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -707,18 +707,18 @@ public void flattenFields() {
707707
}
708708

709709
PdfArray fFields = getFields();
710-
removeObjectFromArray(fFields, fieldObject);
710+
fFields.remove(fieldObject);
711711
if (annotation != null) {
712712
page.removeAnnotation(annotation);
713713
}
714714
PdfDictionary parent = fieldObject.getAsDictionary(PdfName.Parent);
715715
if (parent != null) {
716716
PdfArray kids = parent.getAsArray(PdfName.Kids);
717-
removeObjectFromArray(kids, fieldObject);
717+
kids.remove(fieldObject);
718718
// TODO what if parent was in it's turn the only child of it's parent (parent of parent)?
719719
// shouldn't we remove them recursively? check it
720720
if (kids.isEmpty()) {
721-
removeObjectFromArray(fFields, parent);
721+
fFields.remove(parent);
722722
}
723723
}
724724
}
@@ -755,13 +755,15 @@ public boolean removeField(String fieldName) {
755755

756756
PdfDictionary parent = field.getParent();
757757
if (parent != null) {
758-
removeObjectFromArray(parent.getAsArray(PdfName.Kids), fieldObject);
758+
parent.getAsArray(PdfName.Kids).remove(fieldObject);
759759
fields.remove(fieldName);
760760
return true;
761761
}
762762

763-
if (removeObjectFromArray(getFields(), fieldObject)) {
764-
fields.remove(fieldName);
763+
PdfArray fieldsPdfArray = getFields();
764+
if (fieldsPdfArray.contains(fieldObject)) {
765+
fieldsPdfArray.remove(fieldObject);
766+
this.fields.remove(fieldName);
765767
return true;
766768
}
767769
return false;
@@ -904,9 +906,6 @@ private PdfDictionary processKids(PdfArray kids, PdfDictionary parent, PdfPage p
904906
} else {
905907
for (int i = 0; i < kids.size(); i++) {
906908
PdfObject kid = kids.get(i);
907-
if (kid.isIndirectReference()) {
908-
kid = ((PdfIndirectReference) kid).getRefersTo();
909-
}
910909
PdfArray otherKids = ((PdfDictionary) kid).getAsArray(PdfName.Kids);
911910
if (otherKids != null) {
912911
processKids(otherKids, (PdfDictionary) kid, page);
@@ -1100,15 +1099,4 @@ private Set<PdfFormField> prepareFieldsForFlattening(PdfFormField field) {
11001099
}
11011100
return preparedFields;
11021101
}
1103-
1104-
private boolean removeObjectFromArray(PdfArray array, PdfObject toRemove) {
1105-
if (array.contains(toRemove)) {
1106-
array.remove(toRemove);
1107-
return true;
1108-
} else if (array.contains(toRemove.getIndirectReference())) {
1109-
array.remove(toRemove.getIndirectReference());
1110-
return true;
1111-
}
1112-
return false;
1113-
}
11141102
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,6 @@ public PdfFormField setValue(String value) {
991991
if (kids != null) {
992992
for (int i = 0; i < kids.size(); i++) {
993993
PdfObject kid = kids.get(i);
994-
if (kid.isIndirectReference()) {
995-
kid = ((PdfIndirectReference) kid).getRefersTo();
996-
}
997994
PdfFormField field = new PdfFormField((PdfDictionary) kid);
998995
field.font = font;
999996
field.fontSize = fontSize;
@@ -1473,9 +1470,6 @@ public List<PdfWidgetAnnotation> getWidgets() {
14731470
if (kids != null) {
14741471
for (int i = 0; i < kids.size(); i++) {
14751472
PdfObject kid = kids.get(i);
1476-
if (kid.isIndirectReference()) {
1477-
kid = ((PdfIndirectReference) kid).getRefersTo();
1478-
}
14791473
subType = ((PdfDictionary) kid).getAsName(PdfName.Subtype);
14801474
if (subType != null && subType.equals(PdfName.Widget)) {
14811475
widgets.add((PdfWidgetAnnotation) PdfAnnotation.makeAnnotation(kid));
@@ -1966,9 +1960,6 @@ public boolean regenerateField() {
19661960
if (null != kids) {
19671961
for (int i = 0; i < kids.size(); i++) {
19681962
PdfObject kid = kids.get(i);
1969-
if (kid.isIndirectReference()) {
1970-
kid = ((PdfIndirectReference) kid).getRefersTo();
1971-
}
19721963
PdfFormField field = new PdfFormField((PdfDictionary) kid);
19731964
PdfWidgetAnnotation widget = field.getWidgets().get(0);
19741965
PdfDictionary buttonValues = field.getPdfObject().getAsDictionary(PdfName.AP).getAsDictionary(PdfName.N);

io/src/main/java/com/itextpdf/io/LogMessageConstant.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,57 +49,61 @@ This file is part of the iText (R) project.
4949
public final class LogMessageConstant {
5050

5151
public static final String ACTION_WAS_SET_TO_LINK_ANNOTATION_WITH_DESTINATION = "Action was set for a link annotation containing destination. The old destination will be cleared.";
52+
public static final String ALREADY_FLUSHED_INDIRECT_OBJECT_MADE_FREE = "An attempt is made to free already flushed indirect object reference. Indirect reference wasn't freed.";
5253
public static final String ATTEMPT_TO_MOVE_TO_FLUSHED_PARENT = "An attempt is made to move the tag tree pointer to the tag parent which has been already flushed. Tag tree pointer is moved to the root tag instead.";
54+
public static final String CALCULATE_HASHCODE_FOR_MODIFIED_PDFNUMBER = "Calculate hashcode for modified PdfNumber.";
5355
public static final String CLIP_ELEMENT = "Element content was clipped because some height properties are set.";
56+
public static final String COLORANT_INTENSITIES_INVALID = "Some of colorant intensities are invalid: they are bigger than 1 or less than 0. We will force them to become 1 or 0 respectively.";
5457
public static final String COLOR_NOT_FOUND = "Color \"{0}\" not found.";
5558
public static final String COLOR_NOT_PARSED = "Color \"{0}\" was not parsed. It has invalid value. Defaulting to black color.";
56-
public static final String COLORANT_INTENSITIES_INVALID = "Some of colorant intensities are invalid: they are bigger than 1 or less than 0. We will force them to become 1 or 0 respectively.";
5759
public static final String COULD_NOT_FIND_GLYPH_WITH_CODE = "Could not find glyph with the following code: {0}";
5860
public static final String DESTINATION_NOT_PERMITTED_WHEN_ACTION_IS_SET = "Destinations are not permitted for link annotations that already have actions. The old action will be removed.";
59-
public static final String DOCUMENT_ALREADY_HAS_FIELD = "The document already has field {0}. Annotations of the fields with this name will be added to the existing one as children. If you want to have separate fields, please, rename them manually before copying.";
60-
public static final String DOCUMENT_SERIALIZATION_EXCEPTION_RAISED = "Unhandled exception while serialization";
6161
public static final String DIRECTONLY_OBJECT_CANNOT_BE_INDIRECT = "DirectOnly object cannot be indirect";
6262
public static final String DOCFONT_HAS_ILLEGAL_DIFFERENCES = "Document Font has illegal differences array. Entry {0} references a glyph ID over 255 and will be ignored.";
63-
public static final String GRAPHICS_STATE_WAS_DELETED = "Graphics state is always deleted after event dispatching. If you want to preserve it in renderer info, use preserveGraphicsState method after receiving renderer info.";
63+
public static final String DOCUMENT_ALREADY_HAS_FIELD = "The document already has field {0}. Annotations of the fields with this name will be added to the existing one as children. If you want to have separate fields, please, rename them manually before copying.";
64+
public static final String DOCUMENT_SERIALIZATION_EXCEPTION_RAISED = "Unhandled exception while serialization";
6465
public static final String ELEMENT_DOES_NOT_FIT_AREA = "Element does not fit current area. {0}";
6566
public static final String ELEMENT_WAS_FORCE_PLACED_KEEP_WITH_NEXT_WILL_BE_IGNORED = "Element was placed in a forced way. Keep with next property will be ignored";
6667
public static final String ENCOUNTERED_INVALID_MCR = "Corrupted tag structure: encountered invalid marked content reference - it doesn't refer to any page or any mcid. This content reference will be ignored.";
67-
public static final String EXCEPTION_WHILE_UPDATING_XMPMETADATA = "Exception while updating XmpMetadata";
6868
public static final String EXCEPTION_WHILE_CREATING_DEFAULT_FONT = "Exception while creating default font (Helvetica, WinAnsi)";
69+
public static final String EXCEPTION_WHILE_UPDATING_XMPMETADATA = "Exception while updating XmpMetadata";
6970
public static final String FILE_CHANNEL_CLOSING_FAILED = "Closing of the file channel this source is based on failed.";
71+
public static final String FLUSHED_OBJECT_CONTAINS_REFERENCE_WHICH_NOT_REFER_TO_ANY_OBJECT = "Flushed object contains indirect reference which doesn't refer to any other object (e.g. this reference might be a free reference). Null object will be written instead.";
7072
public static final String FONT_HAS_INVALID_GLYPH = "Font {0} has invalid glyph: {1}";
71-
public static final String FORBID_RELEASE_IS_SET = "ForbidRelease flag is set and release is called. Releasing will not be performed.";
7273
public static final String FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT = "The Font Property must be a PdfFont object";
74+
public static final String FORBID_RELEASE_IS_SET = "ForbidRelease flag is set and release is called. Releasing will not be performed.";
7375
public static final String FORM_FIELD_WAS_FLUSHED = "A form field was flushed. There's no way to create this field in the AcroForm dictionary.";
76+
public static final String GRAPHICS_STATE_WAS_DELETED = "Graphics state is always deleted after event dispatching. If you want to preserve it in renderer info, use preserveGraphicsState method after receiving renderer info.";
7477
public static final String IMAGE_HAS_AMBIGUOUS_SCALE = "The image cannot be auto scaled and scaled by a certain parameter simultaneously";
7578
public static final String IMAGE_HAS_JBIG2DECODE_FILTER = "Image cannot be inline if it has JBIG2Decode filter. It will be added as an ImageXObject";
76-
public static final String IMAGE_HAS_MASK = "Image cannot be inline if it has a Mask";
7779
public static final String IMAGE_HAS_JPXDECODE_FILTER = "Image cannot be inline if it has JPXDecode filter. It will be added as an ImageXObject";
80+
public static final String IMAGE_HAS_MASK = "Image cannot be inline if it has a Mask";
7881
public static final String IMAGE_SIZE_CANNOT_BE_MORE_4KB = "Inline image size cannot be more than 4KB. It will be added as an ImageXObject";
7982
public static final String INCORRECT_PAGEROTATION = "Encounterd a page rotation that was not a multiple of 90°/ (Pi/2) when generating default appearances for form fields";
83+
public static final String INDIRECT_REFERENCE_USED_IN_FLUSHED_OBJECT_MADE_FREE = "An attempt is made to free an indirect reference which was already used in the flushed object. Indirect reference wasn't freed.";
8084
public static final String INLINE_BLOCK_ELEMENT_WILL_BE_CLIPPED = "Inline block element does not fit into parent element and will be clipped";
8185
public static final String INPUT_STREAM_CONTENT_IS_LOST_ON_PDFSTREAM_SERIALIZATION = "PdfStream contains not null input stream. It's content will be lost in serialized object.";
8286
public static final String INVALID_INDIRECT_REFERENCE = "Invalid indirect reference {0} {1} R";
8387
public static final String INVALID_KEY_VALUE_KEY_0_HAS_NULL_VALUE = "Invalid key value: key {0} has null value.";
8488
public static final String LAST_ROW_IS_NOT_COMPLETE = "Last row is not completed. Table bottom border may collapse as you do not expect it";
85-
public static final String CALCULATE_HASHCODE_FOR_MODIFIED_PDFNUMBER = "Calculate hashcode for modified PdfNumber.";
8689
public static final String MAKE_COPY_OF_CATALOG_DICTIONARY_IS_FORBIDDEN = "Make copy of Catalog dictionary is forbidden.";
8790
public static final String NAME_ALREADY_EXISTS_IN_THE_NAME_TREE = "Name \"{0}\" already exists in the name tree; old value will be replaced by the new one.";
88-
public static final String NO_FIELDS_IN_ACROFORM = "Required AcroForm entry /Fields does not exist in the document. Empty array /Fields will be created.";
8991
public static final String NOT_TAGGED_PAGES_IN_TAGGED_DOCUMENT = "Not tagged pages are copied to the tagged document. Destination document now may contain not tagged content.";
92+
public static final String NO_FIELDS_IN_ACROFORM = "Required AcroForm entry /Fields does not exist in the document. Empty array /Fields will be created.";
9093
public static final String NUM_TREE_SHALL_NOT_END_WITH_KEY = "Number tree ends with a key which is invalid according to the PDF specification.";
91-
public static final String PDF_READER_CLOSING_FAILED = "PdfReader closing failed due to the error occurred!";
92-
public static final String PDF_WRITER_CLOSING_FAILED = "PdfWriter closing failed due to the error occurred!";
93-
public static final String POPUP_ENTRY_IS_NOT_POPUP_ANNOTATION = "Popup entry in the markup annotations refers not to the annotation with Popup subtype.";
9494
public static final String OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED = "Occupied area has not been initialized. {0}";
9595
public static final String OCSP_STATUS_IS_REVOKED = "OCSP status is revoked.";
9696
public static final String OCSP_STATUS_IS_UNKNOWN = "OCSP status is unknown.";
9797
public static final String ONE_OF_GROUPED_SOURCES_CLOSING_FAILED = "Closing of one of the grouped sources failed.";
9898
public static final String ONLY_ONE_OF_ARTBOX_OR_TRIMBOX_CAN_EXIST_IN_THE_PAGE = "Only one of artbox or trimbox can exist on the page. The trimbox will be deleted";
99+
public static final String OPENTYPE_GDEF_TABLE_ERROR = "OpenType GDEF table error: {0}";
99100
public static final String PDF_OBJECT_FLUSHING_NOT_PERFORMED = "PdfObject flushing is not performed: PdfDocument is opened in append mode and the object is not marked as modified ( see PdfObject#setModified() ).";
101+
public static final String PDF_READER_CLOSING_FAILED = "PdfReader closing failed due to the error occurred!";
102+
public static final String PDF_WRITER_CLOSING_FAILED = "PdfWriter closing failed due to the error occurred!";
103+
public static final String POPUP_ENTRY_IS_NOT_POPUP_ANNOTATION = "Popup entry in the markup annotations refers not to the annotation with Popup subtype.";
100104
public static final String PROPERTY_IN_PERCENTS_NOT_SUPPORTED = "Property {0} in percents is not supported";
101-
public static final String RECTANGLE_HAS_NEGATIVE_SIZE = "The {0} rectangle has negative size. It will not be displayed.";
102105
public static final String RECTANGLE_HAS_NEGATIVE_OR_ZERO_SIZES = "The {0} rectangle has negative or zero sizes. It will not be displayed.";
106+
public static final String RECTANGLE_HAS_NEGATIVE_SIZE = "The {0} rectangle has negative size. It will not be displayed.";
103107
public static final String REGISTERING_DIRECTORY = "Registering directory";
104108
public static final String REMOVING_PAGE_HAS_ALREADY_BEEN_FLUSHED = "The removing page has already been flushed.";
105109
public static final String RENDERER_WAS_NOT_ABLE_TO_PROCESS_KEEP_WITH_NEXT = "The renderer was not able to process keep with next property properly";
@@ -110,13 +114,12 @@ public final class LogMessageConstant {
110114
public static final String TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH = "Table width is more than expected due to min width of cell(s).";
111115
public static final String TAG_STRUCTURE_CONTEXT_WILL_BE_REINITIALIZED_ON_SERIALIZATION = "Tag structure context is not null and will be reinitialized in the copy of document. The copy may lose some data";
112116
public static final String TAG_STRUCTURE_INIT_FAILED = "Tag structure initialization failed, tag structure is ignored, it might be corrupted.";
117+
public static final String TOUNICODE_CMAP_MORE_THAN_2_BYTES_NOT_SUPPORTED = "ToUnicode CMap more than 2 bytes not supported.";
113118
public static final String UNEXPECTED_BEHAVIOUR_DURING_TABLE_ROW_COLLAPSING = "Unexpected behaviour during table row collapsing. Calculated rowspan was less then 1.";
114119
public static final String UNKNOWN_CMAP = "Unknown CMap {0}";
115120
public static final String UNKNOWN_COLOR_FORMAT_MUST_BE_RGB_OR_RRGGBB = "Unknown color format: must be rgb or rrggbb.";
116121
public static final String UNKNOWN_ERROR_WHILE_PROCESSING_CMAP = "Unknown error while processing CMap.";
117-
public static final String TOUNICODE_CMAP_MORE_THAN_2_BYTES_NOT_SUPPORTED = "ToUnicode CMap more than 2 bytes not supported.";
118122
public static final String WRITER_ENCRYPTION_IS_IGNORED_APPEND = "Writer encryption will be ignored, because append mode is used. Document will preserve the original encryption (or will stay unencrypted)";
119123
public static final String WRITER_ENCRYPTION_IS_IGNORED_PRESERVE = "Writer encryption will be ignored, because preservation of encryption is enabled. Document will preserve the original encryption (or will stay unencrypted)";
120124
public static final String XREF_ERROR = "Error occurred while reading cross reference table. Cross reference table will be rebuilt.";
121-
public static final String OPENTYPE_GDEF_TABLE_ERROR = "OpenType GDEF table error: {0}";
122125
}

0 commit comments

Comments
 (0)