Skip to content

Commit

Permalink
iText 5.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
amedee committed Sep 16, 2015
2 parents 03d92fa + 28ef583 commit f3fca4e
Show file tree
Hide file tree
Showing 339 changed files with 9,679 additions and 1,605 deletions.
4 changes: 2 additions & 2 deletions itext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<artifactId>itextpdf</artifactId>
<packaging>jar</packaging>
<name>iText, a Free Java-PDF library</name>
<version>5.5.6</version>
<version>5.5.7</version>
<description>iText, a free Java-PDF library</description>
<!-- General Info -->
<url>http://itextpdf.com</url>
Expand Down Expand Up @@ -307,4 +307,4 @@
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
</properties>
</project>
</project>
31 changes: 23 additions & 8 deletions itext/src/main/java/com/itextpdf/testutils/CompareTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ public String toString() {

@Override
public int hashCode() {
int hashCode = baseCmpObject.hashCode() * 31 + baseOutObject.hashCode();
int hashCode1 = baseCmpObject != null ? baseCmpObject.hashCode() : 1;
int hashCode2 = baseOutObject != null ? baseOutObject.hashCode() : 1;
int hashCode = hashCode1 * 31 + hashCode2;
for (PathItem pathItem : path) {
hashCode *= 31;
hashCode += pathItem.hashCode();
Expand Down Expand Up @@ -282,7 +284,8 @@ public Node toXmlNode(Document document) {
}

protected class CompareResult {
protected HashMap<ObjectPath, String> differences = new HashMap<ObjectPath, String>();
// LinkedHashMap to retain order. HashMap has different order in Java6/7 and Java8
protected Map<ObjectPath, String> differences = new LinkedHashMap<ObjectPath, String>();
protected int messageLimit = 1;

public CompareResult(int messageLimit) {
Expand Down Expand Up @@ -447,7 +450,7 @@ private String compare(String outPath, String differenceImagePrefix, Map<Integer

if (targetDir.exists()) {
String gsParams = this.gsParams.replace("<outputfile>", outPath + cmpImage).replace("<inputfile>", cmpPdf);
Process p = Runtime.getRuntime().exec(gsExec + gsParams);
Process p = runProcess(gsExec , gsParams);
BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line;
Expand All @@ -461,7 +464,7 @@ private String compare(String outPath, String differenceImagePrefix, Map<Integer
bre.close();
if (p.waitFor() == 0) {
gsParams = this.gsParams.replace("<outputfile>", outPath + outImage).replace("<inputfile>", outPdf);
p = Runtime.getRuntime().exec(gsExec + gsParams);
p = runProcess(gsExec , gsParams);
bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = bri.readLine()) != null) {
Expand Down Expand Up @@ -500,7 +503,7 @@ private String compare(String outPath, String differenceImagePrefix, Map<Integer
if (!cmpResult) {
if (compareExec != null && new File(compareExec).exists()) {
String compareParams = this.compareParams.replace("<image1>", imageFiles[i].getAbsolutePath()).replace("<image2>", cmpImageFiles[i].getAbsolutePath()).replace("<difference>", outPath + differenceImagePrefix + Integer.toString(i + 1) + ".png");
p = Runtime.getRuntime().exec(compareExec + compareParams);
p = runProcess(compareExec , compareParams);
bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = bre.readLine()) != null) {
System.out.println(line);
Expand Down Expand Up @@ -547,6 +550,18 @@ private String compare(String outPath, String differenceImagePrefix, Map<Integer
return null;
}

private Process runProcess(String execPath, String params) throws IOException, InterruptedException {
StringTokenizer st = new StringTokenizer(params);
String[] cmdArray = new String[st.countTokens() + 1];
cmdArray[0] = execPath;
for (int i = 1; st.hasMoreTokens(); ++i)
cmdArray[i] = st.nextToken();

Process p = Runtime.getRuntime().exec(cmdArray);

return p;
}

public String compare(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer, List<Rectangle>> ignoredAreas) throws IOException, InterruptedException, DocumentException {
init(outPdf, cmpPdf);
return compare(outPath, differenceImagePrefix, ignoredAreas);
Expand Down Expand Up @@ -601,8 +616,8 @@ private String compareByContent(String outPath, String differenceImagePrefix, Ma

PdfObject outOcProperties = outReader.getCatalog().get(PdfName.OCPROPERTIES);
PdfObject cmpOcProperties = cmpReader.getCatalog().get(PdfName.OCPROPERTIES);
RefKey outOcPropertiesRef = outOcProperties == null ? null : new RefKey((PdfIndirectReference)outOcProperties);
RefKey cmpOcPropertiesRef = cmpOcProperties == null ? null : new RefKey((PdfIndirectReference)cmpOcProperties);
RefKey outOcPropertiesRef = outOcProperties instanceof PdfIndirectReference ? new RefKey((PdfIndirectReference)outOcProperties) : null;
RefKey cmpOcPropertiesRef = cmpOcProperties instanceof PdfIndirectReference ? new RefKey((PdfIndirectReference)cmpOcProperties) : null;
compareObjects(outOcProperties, cmpOcProperties, new ObjectPath(outOcPropertiesRef, cmpOcPropertiesRef), compareResult);

outReader.close();
Expand Down Expand Up @@ -739,7 +754,7 @@ private boolean compareDictionariesExtended(PdfDictionary outDict, PdfDictionary
}
boolean dictsAreSame = true;
// Iterate through the union of the keys of the cmp and out dictionaries!
Set<PdfName> mergedKeys = new HashSet<PdfName>(cmpDict.getKeys());
Set<PdfName> mergedKeys = new TreeSet<PdfName>(cmpDict.getKeys());
mergedKeys.addAll(outDict.getKeys());
for (PdfName key : mergedKeys) {
if (key.compareTo(PdfName.PARENT) == 0 || key.compareTo(PdfName.P) == 0) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
*/
package com.itextpdf.text;

public class AccessibleElementId implements Comparable<AccessibleElementId> {
import java.io.Serializable;

public class AccessibleElementId implements Comparable<AccessibleElementId>, Serializable {

private static int id_counter = 0;
private int id = 0;
Expand Down
11 changes: 10 additions & 1 deletion itext/src/main/java/com/itextpdf/text/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,18 @@ public float getWidthPoint() {
*/

public boolean hasAttributes() {
return attributes != null;
return attributes != null && !attributes.isEmpty();
}

/**
* Checks the accessible attributes of this <CODE>Chunk</CODE>.
*
* @return false if there aren't any.
*/
public boolean hasAccessibleAttributes() {
return accessibleAttributes != null && !accessibleAttributes.isEmpty();
}

/**
* Gets the attributes for this <CODE>Chunk</CODE>.
* <P>
Expand Down
8 changes: 6 additions & 2 deletions itext/src/main/java/com/itextpdf/text/DocWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
*/
package com.itextpdf.text;

import com.itextpdf.text.pdf.OutputStreamCounter;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Properties;

import com.itextpdf.text.pdf.OutputStreamCounter;

/**
* An abstract <CODE>Writer</CODE> class for documents.
* <P>
Expand Down Expand Up @@ -418,13 +418,17 @@ public void setCloseStream(boolean closeStream) {
}

/**
* This implementation only returns false and doesn't do anything. Perhaps you were looking for the similarly named method of the Document class.
*
* @see com.itextpdf.text.DocListener#setMarginMirroring(boolean)
*/
public boolean setMarginMirroring(boolean MarginMirroring) {
return false;
}

/**
* This implementation only returns false and doesn't do anything. Perhaps you were looking for the similarly named method of the Document class.
*
* @see com.itextpdf.text.DocListener#setMarginMirroring(boolean)
* @since 2.1.6
*/
Expand Down
79 changes: 47 additions & 32 deletions itext/src/main/java/com/itextpdf/text/DocumentException.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,55 @@
/**
* Signals that an error has occurred in a <CODE>Document</CODE>.
*
* @see BadElementException
* @see Document
* @see DocWriter
* @see DocListener
* @see BadElementException
* @see Document
* @see DocWriter
* @see DocListener
*/

public class DocumentException extends Exception {

/** A serial version UID */
private static final long serialVersionUID = -2191131489390840739L;
private static final long serialVersionUID = -2191131489390840739L;

/**
* Creates a Document exception.
*
* @param ex
* an exception that has to be turned into a DocumentException
*/
public DocumentException(Exception ex) {
super(ex);
}

// constructors

/**
* Constructs a <CODE>DocumentException</CODE> without a message.
*/
public DocumentException() {
super();
}

/**
* Constructs a <code>DocumentException</code> with a message.
*
* @param message
* a message describing the exception
*/
public DocumentException(String message) {
super(message);
}

/**
* Creates a Document exception.
* @param ex an exception that has to be turned into a DocumentException
*/
public DocumentException(Exception ex) {
super(ex);
}

// constructors

/**
* Constructs a <CODE>DocumentException</CODE> without a message.
*/
public DocumentException() {
super();
}

/**
* Constructs a <code>DocumentException</code> with a message.
*
* @param message a message describing the exception
*/
public DocumentException(String message) {
super(message);
}
/**
* Constructs a <code>DocumentException</code> with a message and a
* Exception.
*
* @param message
* a message describing the exception
* @param ex
* an exception that has to be turned into a DocumentException
*/
public DocumentException(String message, Exception ex) {
super(message, ex);
}
}
3 changes: 1 addition & 2 deletions itext/src/main/java/com/itextpdf/text/Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,7 @@ public boolean isStandardFont() {
* Replaces the attributes that are equal to <VAR>null</VAR> with the
* attributes of a given font.
*
* @param font
* the font of a bigger element class
* @param font the font of a lower element class (ex. this - paragraph font, font - chunk font)
* @return a <CODE>Font</CODE>
*/
public Font difference(final Font font) {
Expand Down
47 changes: 38 additions & 9 deletions itext/src/main/java/com/itextpdf/text/FontFactoryImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@
*/
package com.itextpdf.text;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Set;

import com.itextpdf.text.Font.FontFamily;
import com.itextpdf.text.log.Level;
import com.itextpdf.text.log.Logger;
import com.itextpdf.text.log.LoggerFactory;
import com.itextpdf.text.pdf.BaseFont;

import java.io.File;
import java.io.IOException;
import java.util.*;

/**
* If you are using True Type fonts, you can declare the paths of the different ttf- and ttc-files
* to this class first and then create fonts in your code using one of the getFont method
Expand Down Expand Up @@ -417,8 +415,16 @@ public void registerFamily(final String familyName, final String fullName, final
break;
}
}
if (!inserted)
if (!inserted) {
tmp.add(fullName);
String newFullName = fullName.toLowerCase();
if (newFullName.endsWith("regular")) {
//remove "regular" at the end of the font name
newFullName = newFullName.substring(0, newFullName.length() - 7).trim();
//insert this font name at the first position for higher priority
tmp.add(0, fullName.substring(0, newFullName.length()));
}
}
}
}
}
Expand Down Expand Up @@ -446,12 +452,22 @@ public void register(final String path, final String alias) {
Object allNames[] = BaseFont.getAllFontNames(path, BaseFont.WINANSI, null);
trueTypeFonts.put(((String)allNames[0]).toLowerCase(), path);
if (alias != null) {
trueTypeFonts.put(alias.toLowerCase(), path);
String lcAlias = alias.toLowerCase();
trueTypeFonts.put(lcAlias, path);
if (lcAlias.endsWith("regular")) {
//do this job to give higher priority to regular fonts in comparison with light, narrow, etc
saveCopyOfRegularFont(lcAlias, path);
}
}
// register all the font names with all the locales
String[][] names = (String[][])allNames[2]; //full name
for (String[] name : names) {
trueTypeFonts.put(name[3].toLowerCase(), path);
String lcName = name[3].toLowerCase();
trueTypeFonts.put(lcName, path);
if (lcName.endsWith("regular")) {
//do this job to give higher priority to regular fonts in comparison with light, narrow, etc
saveCopyOfRegularFont(lcName, path);
}
}
String fullName = null;
String familyName = null;
Expand Down Expand Up @@ -512,6 +528,19 @@ else if (path.toLowerCase().endsWith(".afm") || path.toLowerCase().endsWith(".pf
}
}

// remove regular and correct last symbol
// do this job to give higher priority to regular fonts in comparison with light, narrow, etc
// Don't use this method for not regular fonts!
protected boolean saveCopyOfRegularFont(String regularFontName, String path) {
//remove "regular" at the end of the font name
String alias = regularFontName.substring(0, regularFontName.length() - 7).trim();
if (!trueTypeFonts.containsKey(alias)) {
trueTypeFonts.put(alias, path);
return true;
}
return false;
}

/** Register all the fonts in a directory.
* @param dir the directory
* @return the number of fonts registered
Expand Down
6 changes: 6 additions & 0 deletions itext/src/main/java/com/itextpdf/text/GreekList.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ public boolean add(Element o) {
return false;
}

@Override
public List cloneShallow() {
GreekList clone = new GreekList();
populateProperties(clone);
return clone;
}
}
15 changes: 15 additions & 0 deletions itext/src/main/java/com/itextpdf/text/List.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ else if (o instanceof List) {
return false;
}

public List cloneShallow() {
List clone = new List();
populateProperties(clone);
return clone;
}

protected void populateProperties(List clone) {
clone.indentationLeft = indentationLeft;
clone.indentationRight = indentationRight;
clone.autoindent = autoindent;
clone.alignindent = alignindent;
clone.symbolIndent = symbolIndent;
clone.symbol = symbol;
}

// extra methods

/** Makes sure all the items in the list have the same indentation. */
Expand Down
Loading

0 comments on commit f3fca4e

Please sign in to comment.