Skip to content

Commit dcb33bd

Browse files
committed
[RELEASE] Merge branch 'release/7.0.6' into 7.0-master
2 parents 1ad59bf + 07a7fff commit dcb33bd

File tree

93 files changed

+3982
-1660
lines changed

Some content is hidden

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

93 files changed

+3982
-1660
lines changed

barcodes/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.itextpdf</groupId>
77
<artifactId>root</artifactId>
8-
<version>7.0.5</version>
8+
<version>7.0.6</version>
99
</parent>
1010

1111
<artifactId>barcodes</artifactId>

font-asian/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.itextpdf</groupId>
77
<artifactId>root</artifactId>
8-
<version>7.0.5</version>
8+
<version>7.0.6</version>
99
</parent>
1010

1111
<artifactId>font-asian</artifactId>

forms/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.itextpdf</groupId>
77
<artifactId>root</artifactId>
8-
<version>7.0.5</version>
8+
<version>7.0.6</version>
99
</parent>
1010

1111
<artifactId>forms</artifactId>

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected PdfChoiceFormField(PdfDictionary pdfObject) {
7676

7777
/**
7878
* Returns <code>Ch</code>, the form type for choice form fields.
79-
*
79+
*
8080
* @return the form type, as a {@link PdfName}
8181
*/
8282
@Override
@@ -86,7 +86,7 @@ public PdfName getFormType() {
8686

8787
/**
8888
* Sets the index of the first visible option in a scrollable list.
89-
*
89+
*
9090
* @param index the index of the first option
9191
* @return current {@link PdfChoiceFormField}
9292
*/
@@ -106,7 +106,7 @@ public PdfNumber getTopIndex() {
106106

107107
/**
108108
* Sets the selected items in the field.
109-
*
109+
*
110110
* @param indices a sorted array of indices representing selected items in the field
111111
* @return current {@link PdfChoiceFormField}
112112
*/
@@ -185,7 +185,7 @@ public PdfChoiceFormField setListSelected(int[] optionNumbers) {
185185

186186
/**
187187
* Gets the currently selected items in the field
188-
*
188+
*
189189
* @return a sorted array of indices representing the currently selected items in the field
190190
*/
191191
public PdfArray getIndices() {
@@ -203,7 +203,7 @@ public PdfChoiceFormField setCombo(boolean combo) {
203203

204204
/**
205205
* If true, the field is a combo box; if false, the field is a list box.
206-
*
206+
*
207207
* @return whether or not the field is now a combo box.
208208
*/
209209
public boolean isCombo() {
@@ -232,7 +232,7 @@ public boolean isEdit() {
232232
}
233233

234234
/**
235-
* If true, the field???s option items shall be sorted alphabetically.
235+
* If true, the field's option items shall be sorted alphabetically.
236236
* This flag is intended for use by writers, not by readers.
237237
* @param sort whether or not to sort the items
238238
* @return current {@link PdfChoiceFormField}
@@ -242,7 +242,7 @@ public PdfChoiceFormField setSort(boolean sort) {
242242
}
243243

244244
/**
245-
* If true, the field???s option items shall be sorted alphabetically.
245+
* If true, the field's option items shall be sorted alphabetically.
246246
* This flag is intended for use by writers, not by readers.
247247
* @return whether or not the items are currently sorted
248248
*/
@@ -251,7 +251,7 @@ public boolean isSort() {
251251
}
252252

253253
/**
254-
* If true, more than one of the field???s option items may be selected
254+
* If true, more than one of the field's option items may be selected
255255
* simultaneously; if false, at most one item shall be selected.
256256
* @param multiSelect whether or not to allow multiple selection
257257
* @return current {@link PdfChoiceFormField}
@@ -261,7 +261,7 @@ public PdfChoiceFormField setMultiSelect(boolean multiSelect) {
261261
}
262262

263263
/**
264-
* If true, more than one of the field???s option items may be selected simultaneously; if false, at most one item shall be selected.
264+
* If true, more than one of the field's option items may be selected simultaneously; if false, at most one item shall be selected.
265265
* @return whether or not multiple selection is currently allowed
266266
*/
267267
public boolean isMultiSelect() {

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

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public static PdfChoiceFormField createChoice(PdfDocument doc, Rectangle rect, S
629629
field.put(PdfName.Opt, options);
630630
field.setFieldFlags(flags);
631631
field.setFieldName(name);
632-
field.getPdfObject().put(PdfName.V, new PdfString(value));
632+
field.getPdfObject().put(PdfName.V, new PdfString(value, PdfEncodings.UNICODE_BIG));
633633
if ((flags & PdfChoiceFormField.FF_COMBO) == 0) {
634634
value = field.optionsArrayToString(options);
635635
}
@@ -1035,13 +1035,10 @@ public PdfFormField setValue(String value, boolean generateAppearance) {
10351035
put(PdfName.V, new PdfString(value, PdfEncodings.UNICODE_BIG));
10361036
}
10371037

1038-
if (PdfName.Btn.equals(formType) && (getFieldFlags() & PdfButtonFormField.FF_PUSH_BUTTON) == 0) {
1039-
if (generateAppearance) {
1040-
regenerateField();
1041-
}
1042-
} else {
1038+
if (generateAppearance) {
10431039
regenerateField();
10441040
}
1041+
10451042
this.setModified();
10461043
return this;
10471044
}
@@ -1901,12 +1898,11 @@ public boolean regenerateField() {
19011898

19021899
} else {
19031900
if (!getFieldFlag(PdfChoiceFormField.FF_COMBO)) {
1904-
PdfNumber topIndex = ((PdfChoiceFormField) this).getTopIndex();
1905-
PdfArray options = (PdfArray) getOptions().clone();
1906-
if (topIndex != null) {
1907-
PdfObject object = options.get(topIndex.intValue());
1908-
options.remove(topIndex.intValue());
1909-
options.add(0, object);
1901+
PdfNumber topIndex = this.getPdfObject().getAsNumber(PdfName.TI);
1902+
PdfArray options = getOptions();
1903+
if (null != options) {
1904+
PdfArray visibleOptions = null != topIndex ? new PdfArray(options.subList(topIndex.intValue(), options.size() - 1)) : (PdfArray) options.clone();
1905+
value = optionsArrayToString(visibleOptions);
19101906
}
19111907
value = optionsArrayToString(options);
19121908
}
@@ -2427,8 +2423,8 @@ protected Rectangle getRect(PdfDictionary field) {
24272423
protected static PdfArray processOptions(String[][] options) {
24282424
PdfArray array = new PdfArray();
24292425
for (String[] option : options) {
2430-
PdfArray subArray = new PdfArray(new PdfString(option[0]));
2431-
subArray.add(new PdfString(option[1]));
2426+
PdfArray subArray = new PdfArray(new PdfString(option[0], PdfEncodings.UNICODE_BIG));
2427+
subArray.add(new PdfString(option[1], PdfEncodings.UNICODE_BIG));
24322428
array.add(subArray);
24332429
}
24342430
return array;
@@ -2437,7 +2433,7 @@ protected static PdfArray processOptions(String[][] options) {
24372433
protected static PdfArray processOptions(String[] options) {
24382434
PdfArray array = new PdfArray();
24392435
for (String option : options) {
2440-
array.add(new PdfString(option));
2436+
array.add(new PdfString(option, PdfEncodings.UNICODE_BIG));
24412437
}
24422438
return array;
24432439
}
@@ -3226,21 +3222,20 @@ private void applyRotation(PdfFormXObject xObject, float height, float width) {
32263222
}
32273223
}
32283224

3229-
private String optionsArrayToString(PdfArray options) {
3230-
String value = "";
3225+
private static String optionsArrayToString(PdfArray options) {
3226+
StringBuffer stringBuffer = new StringBuffer();
32313227
for (PdfObject obj : options) {
32323228
if (obj.isString()) {
3233-
value += ((PdfString) obj).toUnicodeString() + '\n';
3229+
stringBuffer.append(((PdfString) obj).toUnicodeString()).append('\n');
32343230
} else if (obj.isArray()) {
32353231
PdfObject element = ((PdfArray) obj).get(1);
32363232
if (element.isString()) {
3237-
value += ((PdfString) element).toUnicodeString() + '\n';
3233+
stringBuffer.append(((PdfString) element).toUnicodeString()).append('\n');
32383234
}
32393235
}
32403236
}
3241-
value = value.substring(0, value.length() - 1);
3242-
3243-
return value;
3237+
stringBuffer.deleteCharAt(stringBuffer.length() - 1); // last '\n'
3238+
return stringBuffer.toString();
32443239
}
32453240

32463241
private static double degreeToRadians(double angle) {

forms/src/test/java/com/itextpdf/forms/PdfFormFieldTest.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ This file is part of the iText (R) project.
4949
import com.itextpdf.io.LogMessageConstant;
5050
import com.itextpdf.io.source.ByteArrayOutputStream;
5151
import com.itextpdf.kernel.geom.Rectangle;
52-
import com.itextpdf.kernel.pdf.PdfDocument;
53-
import com.itextpdf.kernel.pdf.PdfPage;
54-
import com.itextpdf.kernel.pdf.PdfReader;
55-
import com.itextpdf.kernel.pdf.PdfWriter;
52+
import com.itextpdf.kernel.pdf.*;
5653
import com.itextpdf.kernel.utils.CompareTool;
5754
import com.itextpdf.test.ExtendedITextTest;
5855
import com.itextpdf.test.annotations.LogMessage;
@@ -362,4 +359,39 @@ public void acroFieldDictionaryNoFields() throws IOException, InterruptedExcepti
362359
Assert.fail(errorMessage);
363360
}
364361
}
362+
363+
@Test
364+
public void regenerateAppearance() throws IOException, InterruptedException {
365+
String input = "regenerateAppearance.pdf";
366+
String output = "regenerateAppearance.pdf";
367+
PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + input ),
368+
new PdfWriter(destinationFolder + output),
369+
new StampingProperties().useAppendMode());
370+
PdfAcroForm acro = PdfAcroForm.getAcroForm(document, false);
371+
int i = 1;
372+
for (Map.Entry<String, PdfFormField> entry : acro.getFormFields().entrySet()) {
373+
if (entry.getKey().contains("field")) {
374+
PdfFormField field = entry.getValue();
375+
field.setValue("test" + i++, false);
376+
}
377+
}
378+
document.close();
379+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + output,
380+
sourceFolder + "cmp_" + output, destinationFolder, "diff"));
381+
}
382+
@Test
383+
public void regenerateAppearance2() throws IOException, InterruptedException {
384+
String input = "regenerateAppearance2.pdf";
385+
String output = "regenerateAppearance2.pdf";
386+
PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + input ),
387+
new PdfWriter(destinationFolder + output),
388+
new StampingProperties().useAppendMode());
389+
PdfAcroForm acro = PdfAcroForm.getAcroForm(document, false);
390+
acro.setNeedAppearances(true);
391+
PdfFormField field = acro.getField("number");
392+
field.setValue("20150044DR");
393+
document.close();
394+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + output,
395+
sourceFolder + "cmp_" + output, destinationFolder, "diff"));
396+
}
365397
}

hyph/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.itextpdf</groupId>
77
<artifactId>root</artifactId>
8-
<version>7.0.5</version>
8+
<version>7.0.6</version>
99
</parent>
1010

1111
<artifactId>hyph</artifactId>

io/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.itextpdf</groupId>
77
<artifactId>root</artifactId>
8-
<version>7.0.5</version>
8+
<version>7.0.6</version>
99
</parent>
1010

1111
<artifactId>io</artifactId>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public class IOException extends RuntimeException {
9292
public static final String ExpectedIhdrMarker = "Expected IHDR marker.";
9393
public static final String ExpectedJp2hMarker = "Expected JP2H marker.";
9494
public static final String ExpectedJpMarker = "Expected JP marker.";
95+
public static final String ExpectedTrailingZeroBitsForByteAlignedLines = "Expected trailing zero bits for byte-aligned lines";
9596
public static final String ExtraSamplesAreNotSupported = "Extra samples are not supported.";
9697
public static final String FdfStartxrefNotFound = "FDF startxref not found.";
9798
public static final String FirstScanlineMustBe1dEncoded = "First scanline must be 1D encoded.";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public final class LogMessageConstant {
8989
public static final String INVALID_KEY_VALUE_KEY_0_HAS_NULL_VALUE = "Invalid key value: key {0} has null value.";
9090
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";
9191
public static final String MAKE_COPY_OF_CATALOG_DICTIONARY_IS_FORBIDDEN = "Make copy of Catalog dictionary is forbidden.";
92+
public static final String METHOD_IS_NOT_IMPLEMENTED_BY_DEFAULT_OTHER_METHOD_WILL_BE_USED = "Method {0} is not implemented by default: please, override and implement it. {1} will be used instead.";
9293
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.";
9394
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.";
9495
public static final String NO_FIELDS_IN_ACROFORM = "Required AcroForm entry /Fields does not exist in the document. Empty array /Fields will be created.";

io/src/main/java/com/itextpdf/io/codec/TIFFConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ public class TIFFConstants {
427427
* data not compressed
428428
*/
429429
public static final int GROUP4OPT_UNCOMPRESSED = 0x2;
430+
/**
431+
* fill to byte boundary
432+
*/
433+
public static final int GROUP4OPT_FILLBITS = 0x4;
430434
/**
431435
* units of resolutions
432436
*/

io/src/main/java/com/itextpdf/io/codec/TIFFFaxDecoder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ public void decodeT6(byte[] buffer,
941941
// has not been tested due to lack of test images using this optional
942942

943943
uncompressedMode = (int) ((tiffT6Options & 0x02) >> 1);
944+
fillBits = (int) ((tiffT6Options & 0x04) >> 2);
944945

945946
// Local cached reference
946947
int[] cce = currChangingElems;
@@ -971,6 +972,17 @@ public void decodeT6(byte[] buffer,
971972
// Start decoding the scanline at startX in the raster
972973
bitOffset = startX;
973974

975+
if (fillBits == 1) {
976+
// filter shall expect extra 0 bits before each
977+
// encoded line so that the line begins on a byte boundary
978+
if (bitPointer > 0) {
979+
int bitsLeft = 8 - bitPointer;
980+
if (nextNBits(bitsLeft) != 0) {
981+
throw new IOException(IOException.ExpectedTrailingZeroBitsForByteAlignedLines);
982+
}
983+
}
984+
}
985+
974986
// Reset search start position for getNextChangingElement
975987
lastChangingElement = 0;
976988

io/src/main/java/com/itextpdf/io/font/FontProgram.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ protected void setFontName(String psFontName) {
279279
fontNames.setFontName(psFontName);
280280
}
281281

282+
@Deprecated
282283
protected void checkFilePath(String path) {
283284
if (path != null && !FontConstants.BUILTIN_FONTS_14.contains(path) && !FileUtil.fileExists(path)) {
284285
throw new IOException(IOException.FontFile1NotFound).setMessageParams(path);

io/src/main/java/com/itextpdf/io/font/TrueTypeFont.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ protected TrueTypeFont() {
8888
}
8989

9090
public TrueTypeFont(String path) throws java.io.IOException {
91-
checkFilePath(path);
9291
fontParser = new OpenTypeParser(path);
9392
fontParser.loadTables(true);
9493
initializeFontProperties();
@@ -101,7 +100,6 @@ public TrueTypeFont(byte[] ttf) throws java.io.IOException {
101100
}
102101

103102
TrueTypeFont(String ttcPath, int ttcIndex) throws java.io.IOException {
104-
checkFilePath(ttcPath);
105103
fontParser = new OpenTypeParser(ttcPath, ttcIndex);
106104
fontParser.loadTables(true);
107105
initializeFontProperties();

io/src/main/java/com/itextpdf/io/font/Type1Font.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ protected Type1Font() {
9090

9191
protected Type1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb) throws java.io.IOException {
9292
this();
93-
checkFilePath(metricsPath);
94-
checkFilePath(binaryPath);
9593

9694
fontParser = new Type1Parser(metricsPath, binaryPath, afm, pfb);
9795
process();

0 commit comments

Comments
 (0)