Skip to content

Commit

Permalink
iTextSharp 5.5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-alay committed Nov 27, 2015
2 parents e478cb3 + 3b45604 commit 8691242
Show file tree
Hide file tree
Showing 1,238 changed files with 2,413 additions and 50,780 deletions.
2 changes: 1 addition & 1 deletion src/core/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("5.5.7")]
[assembly: AssemblyVersion("5.5.8")]
2 changes: 1 addition & 1 deletion src/core/System/util/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static int GetArrayHashCode<T>(T[] a) {
return result;
}

public static int compare(float f1, float f2) {
public static int Compare(float f1, float f2) {
if (f1 < f2) {
return -1;
}
Expand Down
285 changes: 233 additions & 52 deletions src/core/iTextSharp/testutils/CompareTool.cs

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/core/iTextSharp/text/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,28 @@ public static float ComputeTabSpace(float width, float tab) {

return tab - width % tab;
}

public static float Max(float[] array) {
float mxm = array[0];
for (int i=1; i < array.Length; i++){
if (array[i]>mxm) {
mxm = array[i];
}
}
return mxm;
}

public static float Min(float[] array) {
float mn = array[0];
for (int i=1; i<array.Length; i++){
if (array[i] < mn){
mn = array[i];
}
}
return mn;
}

}


}
2 changes: 1 addition & 1 deletion src/core/iTextSharp/text/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public sealed class Version {
* This String contains the version number of this iText release.
* For debugging purposes, we request you NOT to change this constant.
*/
static private String release = "5.5.7";
static private String release = "5.5.8";

/**
* This String contains the iText version as shown in the producer line.
Expand Down
7 changes: 5 additions & 2 deletions src/core/iTextSharp/text/pdf/AcroFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,11 @@ virtual public void DecodeGenericDictionary(PdfDictionary merged, BaseField tx)
fontFallBack = true;
}
}
if (fontFallBack) {
else {
fontFallBack = true;
}
}
if (fontFallBack) {
BaseFont bf;
if (!localFonts.TryGetValue((string)dab[DA_FONT], out bf))
{
Expand All @@ -616,7 +620,6 @@ virtual public void DecodeGenericDictionary(PdfDictionary merged, BaseField tx)
}
else
tx.Font = bf;
}
}
}
//rotation, border and backgound color
Expand Down
19 changes: 19 additions & 0 deletions src/core/iTextSharp/text/pdf/BarcodeDatamatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,25 @@ virtual public int Generate(byte[] text, int textOffset, int textSize) {
Draw(data, full, dm);
return DM_NO_ERROR;
}

virtual public void PlaceBarcode(PdfContentByte cb, BaseColor foreground, float moduleHeight, float moduleWidth) {
int w = width + 2*ws;
int h = height + 2*ws;
int stride = (w + 7)/8;
int ptr = 0;
cb.SetColorFill(foreground);
for (int k = 0; k < h; ++k) {
int p = k*stride;
for (int j = 0; j < w; ++j) {
int b = image[p + j/8] & 0xff;
b <<= j%8;
if ((b & 0x80) != 0) {
cb.Rectangle(j*moduleWidth, (h - k - 1)*moduleHeight, moduleWidth, moduleHeight);
}
}
}
cb.Fill();
}

/** Gets an <CODE>Image</CODE> with the barcode. A successful call to the method <CODE>generate()</CODE>
* before calling this method is required.
Expand Down
2 changes: 1 addition & 1 deletion src/core/iTextSharp/text/pdf/DocumentFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void FillMetricsIdentity(IntHashtable widths, int dw) {
int w = dw;
if (widths.ContainsKey(i))
w = widths[i];
metrics.Add(i, new int[] { i, w });
metrics[i] = new int[] { i, w };
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/core/iTextSharp/text/pdf/PRTokeniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public enum TokType {
protected int reference;
protected int generation;
protected bool hexString;

private StringBuilder outBuf;

/**
* Creates a PRTokeniser for the specified {@link RandomAccessSource}.
* The beginning of the file is read to determine the location of the header, and the data source is adjusted
Expand All @@ -87,6 +88,7 @@ public enum TokType {
*/
public PRTokeniser(RandomAccessFileOrArray file) {
this.file = file;
outBuf = new StringBuilder();
}

virtual public void Seek(long pos) {
Expand Down Expand Up @@ -311,7 +313,7 @@ virtual public bool NextToken() {
// Note: We have to initialize stringValue here, after we've looked for the end of the stream,
// to ensure that we don't lose the value of a token that might end exactly at the end
// of the stream
StringBuilder outBuf = new StringBuilder();
outBuf.Length = 0;
stringValue = EMPTY;
switch (ch) {
case '[':
Expand Down
6 changes: 5 additions & 1 deletion src/core/iTextSharp/text/pdf/PdfArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace iTextSharp.text.pdf {
*/

public class PdfArray : PdfObject, IEnumerable<PdfObject> {

// membervariables

/** this is the actual array of PdfObjects */
Expand All @@ -81,6 +81,10 @@ public class PdfArray : PdfObject, IEnumerable<PdfObject> {
public PdfArray() : base(ARRAY) {
arrayList = new List<PdfObject>();
}

public PdfArray(int capcity) : base(ARRAY) {
arrayList = new List<PdfObject>(capcity);
}

/**
* Constructs an <CODE>PdfArray</CODE>-object, containing 1 <CODE>PdfObject</CODE>.
Expand Down
114 changes: 68 additions & 46 deletions src/core/iTextSharp/text/pdf/PdfCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected override ICounter GetCounter() {
private static readonly PdfName iTextTag = new PdfName("_iTextTag_");
internal static int zero = 0;
private HashSet2<Object> mergedRadioButtons = new HashSet2<object>();
private Dictionary<Object, PdfObject> mergedTextFields = new Dictionary<Object, PdfObject>();
private Dictionary<Object, PdfString> mergedTextFields = new Dictionary<Object, PdfString>();

private HashSet2<PdfReader> readersWithImportedStructureTreeRootKids = new HashSet2<PdfReader>();

Expand Down Expand Up @@ -459,7 +459,7 @@ protected virtual PdfIndirectReference CopyIndirect(PRIndirectReference inp) {
* objects contained in it.
*/
virtual protected PdfDictionary CopyDictionary(PdfDictionary inp, bool keepStruct, bool directRootKids) {
PdfDictionary outp = new PdfDictionary();
PdfDictionary outp = new PdfDictionary(inp.Size);
PdfObject type = PdfReader.GetPdfObjectRelease(inp.Get(PdfName.TYPE));

if (keepStruct)
Expand Down Expand Up @@ -547,7 +547,7 @@ virtual protected PdfStream CopyStream(PRStream inp) {
* in it
*/
virtual protected PdfArray CopyArray(PdfArray inp, bool keepStruct, bool directRootKids) {
PdfArray outp = new PdfArray();
PdfArray outp = new PdfArray(inp.Size);

foreach (PdfObject value in inp.ArrayList) {
parentObjects[value] = inp;
Expand Down Expand Up @@ -856,7 +856,7 @@ public override PdfIndirectObject AddToBody(PdfObject objecta, PdfIndirectRefere
mergedSet.Add(iobj);
} else {
unmergedMap[annotId.IntValue] = iobj;
unmergedIndirectRefsMap.Add(new RefKey(iobj.Number, iobj.Generation), iobj);
unmergedIndirectRefsMap[new RefKey(iobj.Number, iobj.Generation)] = iobj;
}
}
}
Expand Down Expand Up @@ -1377,6 +1377,7 @@ internal void MergeField(String name, AcroFields.Item item) {
obj = new Dictionary<String, Object>();
map[s] = obj;
map = (Dictionary<String, Object>)obj;
continue;
} else if (obj is Dictionary<String, Object>) {
map = (Dictionary<String, Object>) obj;
} else {
Expand All @@ -1387,51 +1388,58 @@ internal void MergeField(String name, AcroFields.Item item) {
return;
PdfDictionary merged = item.GetMerged(0);

// if a field with this name already exists, we try to rename it
// so a new field will be created.
if (obj != null) {
s = RenameField(obj, map, merged);
if (obj == null) {
PdfDictionary field = new PdfDictionary();
if (PdfName.SIG.Equals(merged.Get(PdfName.FT)))
hasSignature = true;
foreach (PdfName key in merged.Keys) {
if (fieldKeys.Contains(key))
field.Put(key, merged.Get(key));
}
List<Object> list = new List<Object>();
list.Add(field);
CreateWidgets(list, item);
map[s] = list;
}
// generate a new field
PdfDictionary field = new PdfDictionary();
if (PdfName.SIG.Equals(merged.Get(PdfName.FT)))
hasSignature = true;
foreach (PdfName key in merged.Keys) {
if(fieldKeys.Contains(key))
field.Put(key, merged.Get(key));
else {
List<Object> list = (List<object>) obj;
PdfDictionary field = (PdfDictionary) list[0];
PdfName type1 = field.GetAsName(PdfName.FT);
PdfName type2 = merged.GetAsName(PdfName.FT);
if (type1 == null || !type1.Equals(type2)) {
return;
}
int flag1 = 0;
PdfNumber f1 = field.GetAsNumber(PdfName.FF);
if (f1 != null) {
flag1 = f1.IntValue;
}
int flag2 = 0;
PdfNumber f2 = merged.GetAsNumber(PdfName.FF);
if (f2 != null) {
flag2 = f2.IntValue;
}
if (type1.Equals(PdfName.BTN)) {
if (((flag1 ^ flag2) & PdfFormField.FF_PUSHBUTTON) != 0) {
return;
}
if ((flag1 & PdfFormField.FF_PUSHBUTTON) == 0 &&
((flag1 ^ flag2) & PdfFormField.FF_RADIO) != 0) {
return;
}
} else if (type1.Equals(PdfName.CH)) {
if (((flag1 ^ flag2) & PdfFormField.FF_COMBO) != 0) {
return;
}
}
CreateWidgets(list, item);
}
List<Object> list = new List<Object>();
list.Add(field);
CreateWidgets(list, item);
map[s] = list;

return;
}
}
}

private String RenameField(Object obj, Dictionary<String, Object> map, PdfDictionary merged)
{
String fieldN = null;
if (obj != null) {
PdfString fieldName = merged.GetAsString(PdfName.T);
if (fieldName != null) {
fieldN = fieldName.ToUnicodeString();
}
}
if (fieldN != null) {
for (int i = 1; i < int.MaxValue; i++) {
String tmpFieldName = String.Format("{0}_{1}", fieldN, i);
if (!map.ContainsKey(tmpFieldName)) {
fieldN = tmpFieldName;
break;
}
}
merged.Put(PdfName.T, new PdfString(fieldN));
}
return fieldN;
}


private void CreateWidgets(List<Object> list, AcroFields.Item item) {
for (int k = 0; k < item.Size; ++k) {
list.Add(item.GetPage(k));
Expand Down Expand Up @@ -1587,13 +1595,27 @@ private PdfArray BranchForm(Dictionary<String, Object> level, PdfIndirectReferen
widget.Remove(iTextTag);
if (PdfCopy.IsTextField(field)) {
PdfString v = field.GetAsString(PdfName.V);
PdfObject ap = widget.Get(PdfName.AP);
PdfObject ap = widget.GetDirectObject(PdfName.AP);
if (v != null && ap != null) {
if (!mergedTextFields.ContainsKey(list)) {
mergedTextFields[list] = ap;
mergedTextFields[list] = v;
} else {
PdfObject ap1 = mergedTextFields[list];
widget.Put(PdfName.AP, CopyObject(ap1));
try {
TextField tx = new TextField(this, null, null);
fields[0].DecodeGenericDictionary(widget, tx);
Rectangle box =
PdfReader.GetNormalizedRectangle(widget.GetAsArray(PdfName.RECT));
if (tx.Rotation == 90 || tx.Rotation == 270) {
box = box.Rotate();
}
tx.Box = box;
tx.Text = mergedTextFields[list].ToUnicodeString();
PdfAppearance app = tx.GetAppearance();
((PdfDictionary) ap).Put(PdfName.N, app.IndirectReference);
}
catch (DocumentException ex) {
//do nothing
}
}
}
} else if (PdfCopy.IsCheckButton(field)) {
Expand Down
31 changes: 22 additions & 9 deletions src/core/iTextSharp/text/pdf/PdfDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,21 @@ public class PdfDictionary : PdfObject {
public PdfDictionary() : base(DICTIONARY) {
hashMap = new Dictionary<PdfName,PdfObject>();
}

/**
* Constructs a <CODE>PdfDictionary</CODE>-object of a certain type.
*
* @param type a <CODE>PdfName</CODE>
*/
public PdfDictionary(PdfName type) : this() {
public PdfDictionary(PdfName type)
: this() {
dictionaryType = type;
Put(PdfName.TYPE, dictionaryType);
}

public PdfDictionary(int capacity): base(DICTIONARY) {
hashMap = new Dictionary<PdfName, PdfObject>(capacity);
}

// methods overriding some methods in PdfObject

Expand Down Expand Up @@ -183,11 +188,15 @@ virtual public void PutEx(PdfName key, PdfObject value) {
* copied over
*/
virtual public void PutAll(PdfDictionary dic) {
foreach (KeyValuePair<PdfName, PdfObject> item in dic.hashMap) {
if (hashMap.ContainsKey(item.Key))
hashMap[item.Key] = item.Value;
else
hashMap.Add(item.Key, item.Value);
if (hashMap.Count == 0) {
hashMap = new Dictionary<PdfName, PdfObject>(dic.hashMap);
} else {
foreach (KeyValuePair<PdfName, PdfObject> item in dic.hashMap) {
if (hashMap.ContainsKey(item.Key))
hashMap[item.Key] = item.Value;
else
hashMap.Add(item.Key, item.Value);
}
}
}

Expand Down Expand Up @@ -285,8 +294,12 @@ virtual public bool CheckType(PdfName type) {


virtual public void Merge(PdfDictionary other) {
foreach (PdfName key in other.hashMap.Keys) {
hashMap[key] = other.hashMap[key];
if (hashMap.Count == 0) {
hashMap = new Dictionary<PdfName, PdfObject>(other.hashMap);
} else {
foreach (PdfName key in other.hashMap.Keys) {
hashMap[key] = other.hashMap[key];
}
}
}

Expand Down
Loading

0 comments on commit 8691242

Please sign in to comment.