Skip to content

Commit

Permalink
[RELEASE] Merge branch 'release/7.0.6' into 7.0-master
Browse files Browse the repository at this point in the history
  • Loading branch information
amedee committed Jan 16, 2018
2 parents 1ad59bf + 07a7fff commit dcb33bd
Show file tree
Hide file tree
Showing 93 changed files with 3,982 additions and 1,660 deletions.
2 changes: 1 addition & 1 deletion barcodes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>7.0.5</version>
<version>7.0.6</version>
</parent>

<artifactId>barcodes</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion font-asian/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>7.0.5</version>
<version>7.0.6</version>
</parent>

<artifactId>font-asian</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion forms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>7.0.5</version>
<version>7.0.6</version>
</parent>

<artifactId>forms</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected PdfChoiceFormField(PdfDictionary pdfObject) {

/**
* Returns <code>Ch</code>, the form type for choice form fields.
*
*
* @return the form type, as a {@link PdfName}
*/
@Override
Expand All @@ -86,7 +86,7 @@ public PdfName getFormType() {

/**
* Sets the index of the first visible option in a scrollable list.
*
*
* @param index the index of the first option
* @return current {@link PdfChoiceFormField}
*/
Expand All @@ -106,7 +106,7 @@ public PdfNumber getTopIndex() {

/**
* Sets the selected items in the field.
*
*
* @param indices a sorted array of indices representing selected items in the field
* @return current {@link PdfChoiceFormField}
*/
Expand Down Expand Up @@ -185,7 +185,7 @@ public PdfChoiceFormField setListSelected(int[] optionNumbers) {

/**
* Gets the currently selected items in the field
*
*
* @return a sorted array of indices representing the currently selected items in the field
*/
public PdfArray getIndices() {
Expand All @@ -203,7 +203,7 @@ public PdfChoiceFormField setCombo(boolean combo) {

/**
* If true, the field is a combo box; if false, the field is a list box.
*
*
* @return whether or not the field is now a combo box.
*/
public boolean isCombo() {
Expand Down Expand Up @@ -232,7 +232,7 @@ public boolean isEdit() {
}

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

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

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

/**
* If true, more than one of the field???s option items may be selected simultaneously; if false, at most one item shall be selected.
* If true, more than one of the field's option items may be selected simultaneously; if false, at most one item shall be selected.
* @return whether or not multiple selection is currently allowed
*/
public boolean isMultiSelect() {
Expand Down
39 changes: 17 additions & 22 deletions forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public static PdfChoiceFormField createChoice(PdfDocument doc, Rectangle rect, S
field.put(PdfName.Opt, options);
field.setFieldFlags(flags);
field.setFieldName(name);
field.getPdfObject().put(PdfName.V, new PdfString(value));
field.getPdfObject().put(PdfName.V, new PdfString(value, PdfEncodings.UNICODE_BIG));
if ((flags & PdfChoiceFormField.FF_COMBO) == 0) {
value = field.optionsArrayToString(options);
}
Expand Down Expand Up @@ -1035,13 +1035,10 @@ public PdfFormField setValue(String value, boolean generateAppearance) {
put(PdfName.V, new PdfString(value, PdfEncodings.UNICODE_BIG));
}

if (PdfName.Btn.equals(formType) && (getFieldFlags() & PdfButtonFormField.FF_PUSH_BUTTON) == 0) {
if (generateAppearance) {
regenerateField();
}
} else {
if (generateAppearance) {
regenerateField();
}

this.setModified();
return this;
}
Expand Down Expand Up @@ -1901,12 +1898,11 @@ public boolean regenerateField() {

} else {
if (!getFieldFlag(PdfChoiceFormField.FF_COMBO)) {
PdfNumber topIndex = ((PdfChoiceFormField) this).getTopIndex();
PdfArray options = (PdfArray) getOptions().clone();
if (topIndex != null) {
PdfObject object = options.get(topIndex.intValue());
options.remove(topIndex.intValue());
options.add(0, object);
PdfNumber topIndex = this.getPdfObject().getAsNumber(PdfName.TI);
PdfArray options = getOptions();
if (null != options) {
PdfArray visibleOptions = null != topIndex ? new PdfArray(options.subList(topIndex.intValue(), options.size() - 1)) : (PdfArray) options.clone();
value = optionsArrayToString(visibleOptions);
}
value = optionsArrayToString(options);
}
Expand Down Expand Up @@ -2427,8 +2423,8 @@ protected Rectangle getRect(PdfDictionary field) {
protected static PdfArray processOptions(String[][] options) {
PdfArray array = new PdfArray();
for (String[] option : options) {
PdfArray subArray = new PdfArray(new PdfString(option[0]));
subArray.add(new PdfString(option[1]));
PdfArray subArray = new PdfArray(new PdfString(option[0], PdfEncodings.UNICODE_BIG));
subArray.add(new PdfString(option[1], PdfEncodings.UNICODE_BIG));
array.add(subArray);
}
return array;
Expand All @@ -2437,7 +2433,7 @@ protected static PdfArray processOptions(String[][] options) {
protected static PdfArray processOptions(String[] options) {
PdfArray array = new PdfArray();
for (String option : options) {
array.add(new PdfString(option));
array.add(new PdfString(option, PdfEncodings.UNICODE_BIG));
}
return array;
}
Expand Down Expand Up @@ -3226,21 +3222,20 @@ private void applyRotation(PdfFormXObject xObject, float height, float width) {
}
}

private String optionsArrayToString(PdfArray options) {
String value = "";
private static String optionsArrayToString(PdfArray options) {
StringBuffer stringBuffer = new StringBuffer();
for (PdfObject obj : options) {
if (obj.isString()) {
value += ((PdfString) obj).toUnicodeString() + '\n';
stringBuffer.append(((PdfString) obj).toUnicodeString()).append('\n');
} else if (obj.isArray()) {
PdfObject element = ((PdfArray) obj).get(1);
if (element.isString()) {
value += ((PdfString) element).toUnicodeString() + '\n';
stringBuffer.append(((PdfString) element).toUnicodeString()).append('\n');
}
}
}
value = value.substring(0, value.length() - 1);

return value;
stringBuffer.deleteCharAt(stringBuffer.length() - 1); // last '\n'
return stringBuffer.toString();
}

private static double degreeToRadians(double angle) {
Expand Down
40 changes: 36 additions & 4 deletions forms/src/test/java/com/itextpdf/forms/PdfFormFieldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ This file is part of the iText (R) project.
import com.itextpdf.io.LogMessageConstant;
import com.itextpdf.io.source.ByteArrayOutputStream;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.*;
import com.itextpdf.kernel.utils.CompareTool;
import com.itextpdf.test.ExtendedITextTest;
import com.itextpdf.test.annotations.LogMessage;
Expand Down Expand Up @@ -362,4 +359,39 @@ public void acroFieldDictionaryNoFields() throws IOException, InterruptedExcepti
Assert.fail(errorMessage);
}
}

@Test
public void regenerateAppearance() throws IOException, InterruptedException {
String input = "regenerateAppearance.pdf";
String output = "regenerateAppearance.pdf";
PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + input ),
new PdfWriter(destinationFolder + output),
new StampingProperties().useAppendMode());
PdfAcroForm acro = PdfAcroForm.getAcroForm(document, false);
int i = 1;
for (Map.Entry<String, PdfFormField> entry : acro.getFormFields().entrySet()) {
if (entry.getKey().contains("field")) {
PdfFormField field = entry.getValue();
field.setValue("test" + i++, false);
}
}
document.close();
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + output,
sourceFolder + "cmp_" + output, destinationFolder, "diff"));
}
@Test
public void regenerateAppearance2() throws IOException, InterruptedException {
String input = "regenerateAppearance2.pdf";
String output = "regenerateAppearance2.pdf";
PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + input ),
new PdfWriter(destinationFolder + output),
new StampingProperties().useAppendMode());
PdfAcroForm acro = PdfAcroForm.getAcroForm(document, false);
acro.setNeedAppearances(true);
PdfFormField field = acro.getField("number");
field.setValue("20150044DR");
document.close();
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + output,
sourceFolder + "cmp_" + output, destinationFolder, "diff"));
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion hyph/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>7.0.5</version>
<version>7.0.6</version>
</parent>

<artifactId>hyph</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>7.0.5</version>
<version>7.0.6</version>
</parent>

<artifactId>io</artifactId>
Expand Down
1 change: 1 addition & 0 deletions io/src/main/java/com/itextpdf/io/IOException.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class IOException extends RuntimeException {
public static final String ExpectedIhdrMarker = "Expected IHDR marker.";
public static final String ExpectedJp2hMarker = "Expected JP2H marker.";
public static final String ExpectedJpMarker = "Expected JP marker.";
public static final String ExpectedTrailingZeroBitsForByteAlignedLines = "Expected trailing zero bits for byte-aligned lines";
public static final String ExtraSamplesAreNotSupported = "Extra samples are not supported.";
public static final String FdfStartxrefNotFound = "FDF startxref not found.";
public static final String FirstScanlineMustBe1dEncoded = "First scanline must be 1D encoded.";
Expand Down
1 change: 1 addition & 0 deletions io/src/main/java/com/itextpdf/io/LogMessageConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public final class LogMessageConstant {
public static final String INVALID_KEY_VALUE_KEY_0_HAS_NULL_VALUE = "Invalid key value: key {0} has null value.";
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";
public static final String MAKE_COPY_OF_CATALOG_DICTIONARY_IS_FORBIDDEN = "Make copy of Catalog dictionary is forbidden.";
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.";
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.";
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.";
public static final String NO_FIELDS_IN_ACROFORM = "Required AcroForm entry /Fields does not exist in the document. Empty array /Fields will be created.";
Expand Down
4 changes: 4 additions & 0 deletions io/src/main/java/com/itextpdf/io/codec/TIFFConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ public class TIFFConstants {
* data not compressed
*/
public static final int GROUP4OPT_UNCOMPRESSED = 0x2;
/**
* fill to byte boundary
*/
public static final int GROUP4OPT_FILLBITS = 0x4;
/**
* units of resolutions
*/
Expand Down
12 changes: 12 additions & 0 deletions io/src/main/java/com/itextpdf/io/codec/TIFFFaxDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ public void decodeT6(byte[] buffer,
// has not been tested due to lack of test images using this optional

uncompressedMode = (int) ((tiffT6Options & 0x02) >> 1);
fillBits = (int) ((tiffT6Options & 0x04) >> 2);

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

if (fillBits == 1) {
// filter shall expect extra 0 bits before each
// encoded line so that the line begins on a byte boundary
if (bitPointer > 0) {
int bitsLeft = 8 - bitPointer;
if (nextNBits(bitsLeft) != 0) {
throw new IOException(IOException.ExpectedTrailingZeroBitsForByteAlignedLines);
}
}
}

// Reset search start position for getNextChangingElement
lastChangingElement = 0;

Expand Down
1 change: 1 addition & 0 deletions io/src/main/java/com/itextpdf/io/font/FontProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ protected void setFontName(String psFontName) {
fontNames.setFontName(psFontName);
}

@Deprecated
protected void checkFilePath(String path) {
if (path != null && !FontConstants.BUILTIN_FONTS_14.contains(path) && !FileUtil.fileExists(path)) {
throw new IOException(IOException.FontFile1NotFound).setMessageParams(path);
Expand Down
2 changes: 0 additions & 2 deletions io/src/main/java/com/itextpdf/io/font/TrueTypeFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ protected TrueTypeFont() {
}

public TrueTypeFont(String path) throws java.io.IOException {
checkFilePath(path);
fontParser = new OpenTypeParser(path);
fontParser.loadTables(true);
initializeFontProperties();
Expand All @@ -101,7 +100,6 @@ public TrueTypeFont(byte[] ttf) throws java.io.IOException {
}

TrueTypeFont(String ttcPath, int ttcIndex) throws java.io.IOException {
checkFilePath(ttcPath);
fontParser = new OpenTypeParser(ttcPath, ttcIndex);
fontParser.loadTables(true);
initializeFontProperties();
Expand Down
2 changes: 0 additions & 2 deletions io/src/main/java/com/itextpdf/io/font/Type1Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ protected Type1Font() {

protected Type1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb) throws java.io.IOException {
this();
checkFilePath(metricsPath);
checkFilePath(binaryPath);

fontParser = new Type1Parser(metricsPath, binaryPath, afm, pfb);
process();
Expand Down
Loading

0 comments on commit dcb33bd

Please sign in to comment.