Skip to content

Commit

Permalink
iTextSharp 5.5.10
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-alay committed Oct 7, 2016
2 parents 75f05dd + 90383a8 commit f764ddd
Show file tree
Hide file tree
Showing 105 changed files with 2,930 additions and 1,329 deletions.
651 changes: 651 additions & 0 deletions gnu-agpl-v3.0.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/core/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("iText Group NV")]
[assembly: AssemblyProduct("iTextSharp")]
[assembly: AssemblyCopyright("Copyright (C) 1999-2014 by Bruno Lowagie and Paulo Soares. All Rights Reserved.")]
[assembly: AssemblyCopyright("Copyright (C) 1999-2016 by iText Group NV")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("itextsharp.pdfa, PublicKey=00240000048000009400000006020000002400005253413100040000010001008b21ed5b3fc1c11996390981fe22bbe71a39a9e11d3c2cefddd6ee92920fa871f9666ae0fa941af0280d0653df048ae2d93f8c5e2d820dba3c8df9ed468c8be40a6fffeb32aa481a254f0fb9f37aa7c3ec1c0acd2c009746bbdafcb75bcdbcecb7caf1f0f4b6e7d013906ba60b66eb1c8298e4efb052caf6cece4bf1816902cc"),]
Expand All @@ -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.9")]
[assembly: AssemblyVersion("5.5.10")]
15 changes: 8 additions & 7 deletions src/core/iTextSharp/testutils/CompareTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,13 +808,14 @@ private bool CompareDictionariesExtended(PdfDictionary outDict, PdfDictionary cm
if (compareResult != null && currentPath != null)
compareResult.AddError(currentPath, String.Format("PdfDictionary {0} entry: Expected: {1}. Found: {2}", key.ToString(), cmpObj.ToString(), outObj.ToString()));
dictsAreSame = false;
}
String cmpName = cmpObj.ToString().Substring(cmpObj.ToString().IndexOf('+'));
String outName = outObj.ToString().Substring(outObj.ToString().IndexOf('+'));
if (!cmpName.Equals(outName)) {
if (compareResult != null && currentPath != null)
compareResult.AddError(currentPath, String.Format("PdfDictionary {0} entry: Expected: {1}. Found: {2}", key.ToString(), cmpObj.ToString(), outObj.ToString()));
dictsAreSame = false;
} else {
String cmpName = cmpObj.ToString().Substring(cmpObj.ToString().IndexOf('+'));
String outName = outObj.ToString().Substring(outObj.ToString().IndexOf('+'));
if (!cmpName.Equals(outName)) {
if (compareResult != null && currentPath != null)
compareResult.AddError(currentPath, String.Format("PdfDictionary {0} entry: Expected: {1}. Found: {2}", key.ToString(), cmpObj.ToString(), outObj.ToString()));
dictsAreSame = false;
}
}
continue;
}
Expand Down
22 changes: 21 additions & 1 deletion src/core/iTextSharp/text/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,28 @@ public static Image GetInstance(System.Drawing.Image image, BaseColor color, boo
transparency[0] = transparency[1] = (transparentPixel >> 16) & 0xff;
transparency[2] = transparency[3] = (transparentPixel >> 8) & 0xff;
transparency[4] = transparency[5] = transparentPixel & 0xff;
// Added by Michael Klink
// Check whether this value for transparent pixels
// has already been used for a non-transparent one
// before this position
for (int prevPixelI = 0; prevPixelI <= i; prevPixelI++) {
for (int prevPixelJ = 0; prevPixelJ < (prevPixelI == i ? j : h); prevPixelJ++) {
int prevPxV = bm.GetPixel(prevPixelI, prevPixelJ).ToArgb();
if ((prevPxV & 0xffffff) == transparentPixel) {
// found a prior use of the transparentPixel color
// and, therefore, cannot make use of this color
// for transparency; we could still use an image
// mask but for simplicity let's use a soft mask
// which already is implemented here
shades = true;
break;
}
}
}
}
} else if ((pxv & 0xffffff) != transparentPixel) {
} else if (((pxv & 0xffffff) != transparentPixel) && (alpha == 0)) {
shades = true;
} else if (((pxv & 0xffffff) == transparentPixel) && (alpha != 0)) {
shades = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/iTextSharp/text/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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.9";
static private String release = "5.5.10";

/**
* This String contains the iText version as shown in the producer line.
Expand Down
4 changes: 2 additions & 2 deletions src/core/iTextSharp/text/pdf/AcroFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1747,8 +1747,8 @@ virtual public bool RemoveField(String name, int page) {
continue;
PdfIndirectReference refi = item.GetWidgetRef(k);
PdfDictionary wd = item.GetWidget( k );
PdfDictionary pageDic = reader.GetPageN(pageV);
PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
PdfDictionary pageDic = reader.GetPageN(pageV); //Returns null in case of floating, orphaned fields
PdfArray annots = pageDic != null ? pageDic.GetAsArray(PdfName.ANNOTS): null;//Account for floating, orphaned fields
if (annots != null) {
if (RemoveRefFromArray(annots, refi) == 0) {
pageDic.Remove(PdfName.ANNOTS);
Expand Down
9 changes: 7 additions & 2 deletions src/core/iTextSharp/text/pdf/BarcodeDatamatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public class BarcodeDatamatrix {
private int width;
private int ws;
private int options;

private bool forceSquareSize = false;

/**
* Creates an instance of this class.
*/
Expand Down Expand Up @@ -722,7 +723,7 @@ virtual public int Generate(byte[] text, int textOffset, int textSize) {
}
e += extCount;
for (k = 0; k < dmSizes.Length; ++k) {
if (dmSizes[k].dataSize >= e)
if (dmSizes[k].dataSize >= e && (!forceSquareSize || dmSizes[k].width == dmSizes[k].height))
break;
}
dm = dmSizes[k];
Expand Down Expand Up @@ -987,6 +988,10 @@ virtual public int Options {
}
}

public virtual bool ForceSquareSize {
set { forceSquareSize = value; }
}

internal class Placement {
private int nrow;
private int ncol;
Expand Down
73 changes: 49 additions & 24 deletions src/core/iTextSharp/text/pdf/BidiLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,28 @@ virtual public bool GetParagraph(int runDirection) {
if (totalTextLength == 0)
return true;

if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
if (runDirection != PdfWriter.RUN_DIRECTION_NO_BIDI) {
if (orderLevels.Length < totalTextLength) {
orderLevels = new byte[pieceSize];
indexChars = new int[pieceSize];
}

ArabicLigaturizer.ProcessNumbers(text, 0, totalTextLength, arabicOptions);
BidiOrder order = new BidiOrder(text, 0, totalTextLength, (sbyte)(runDirection == PdfWriter.RUN_DIRECTION_RTL ? 1 : 0));
sbyte paragraphEmbeddingLevel;
switch (runDirection)
{
case PdfWriter.RUN_DIRECTION_LTR:
paragraphEmbeddingLevel = 0;
break;
case PdfWriter.RUN_DIRECTION_RTL:
paragraphEmbeddingLevel = 1;
break;
case PdfWriter.RUN_DIRECTION_DEFAULT:
default:
paragraphEmbeddingLevel = -1;
break;
}
BidiOrder order = new BidiOrder(text, 0, totalTextLength, paragraphEmbeddingLevel);
byte[] od = order.GetLevels();
for (int k = 0; k < totalTextLength; ++k) {
orderLevels[k] = od[k];
Expand Down Expand Up @@ -243,7 +257,7 @@ virtual public void Save() {
Array.Copy(text, 0, storedText, 0, totalTextLength);
Array.Copy(detailChunks, 0, storedDetailChunks, 0, totalTextLength);
}
if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
if (runDirection != PdfWriter.RUN_DIRECTION_NO_BIDI) {
if (storedOrderLevels.Length < totalTextLength) {
storedOrderLevels = new byte[totalTextLength];
storedIndexChars = new int[totalTextLength];
Expand All @@ -264,7 +278,7 @@ virtual public void Restore() {
Array.Copy(storedText, 0, text, 0, totalTextLength);
Array.Copy(storedDetailChunks, 0, detailChunks, 0, totalTextLength);
}
if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
if (runDirection != PdfWriter.RUN_DIRECTION_NO_BIDI) {
Array.Copy(storedOrderLevels, currentChar, orderLevels, currentChar, totalTextLength - currentChar);
Array.Copy(storedIndexChars, currentChar, indexChars, currentChar, totalTextLength - currentChar);
}
Expand Down Expand Up @@ -348,6 +362,7 @@ virtual public PdfLine ProcessLine(float leftX, float width, int alignment, int
float charWidth = 0;
PdfChunk lastValidChunk = null;
TabStop tabStop = null;
IList<TabStop> rtlTabsToBeAligned = new List<TabStop>();
float tabStopAnchorPosition = float.NaN;
float tabPosition = float.NaN;
bool surrogate = false;
Expand Down Expand Up @@ -394,14 +409,7 @@ virtual public PdfLine ProcessLine(float leftX, float width, int alignment, int
if (ck.IsAttribute(Chunk.TABSETTINGS)) {
lastSplit = currentChar;
if (tabStop != null) {
float tabStopPosition = tabStop.GetPosition(tabPosition, originalWidth - width,
tabStopAnchorPosition);
width = originalWidth - (tabStopPosition + (originalWidth - width - tabPosition));
if (width < 0) {
tabStopPosition += width;
width = 0;
}
tabStop.Position = tabStopPosition;
width = ProcessTabStop(tabStop, tabPosition, originalWidth, width, tabStopAnchorPosition, isRTL, rtlTabsToBeAligned);
}

tabStop = PdfChunk.GetTabStop(ck, originalWidth - width);
Expand Down Expand Up @@ -468,16 +476,12 @@ virtual public PdfLine ProcessLine(float leftX, float width, int alignment, int
}

if (tabStop != null) {
float tabStopPosition = tabStop.GetPosition(tabPosition, originalWidth - width, tabStopAnchorPosition);
width -= tabStopPosition - tabPosition;
if (width < 0) {
tabStopPosition += width;
width = 0;
width = ProcessTabStop(tabStop, tabPosition, originalWidth, width, tabStopAnchorPosition, isRTL, rtlTabsToBeAligned);
}
if (rtlTabsToBeAligned != null) {
foreach (TabStop rtlTabStop in rtlTabsToBeAligned) {
rtlTabStop.Position = originalWidth - width - rtlTabStop.Position;
}
if (!isRTL)
tabStop.Position = tabStopPosition;
else
tabStop.Position = originalWidth - width - tabPosition;
}

if (currentChar >= totalTextLength) {
Expand Down Expand Up @@ -521,6 +525,27 @@ virtual public PdfLine ProcessLine(float leftX, float width, int alignment, int
return new PdfLine(0, originalWidth, originalWidth - GetWidth(oldCurrentChar, newCurrentChar, originalWidth), alignment, false, CreateArrayOfPdfChunks(oldCurrentChar, newCurrentChar), isRTL);
}

private float ProcessTabStop(TabStop tabStop, float tabPosition, float originalWidth, float width, float tabStopAnchorPosition, bool isRTL, IList<TabStop> rtlTabsToBeAligned)
{
float tabStopPosition = tabStop.GetPosition(tabPosition, originalWidth - width, tabStopAnchorPosition);
width -= tabStopPosition - tabPosition;
if (width < 0)
{
tabStopPosition += width;
width = 0;
}
if (!isRTL)
{
tabStop.Position = tabStopPosition;
}
else
{
tabStop.Position = tabPosition; // This will be mirrored when we know exact line width
rtlTabsToBeAligned.Add(tabStop);
}
return width;
}

/**
* Call this after processLine() to know if any word was split into several lines.
* @return
Expand Down Expand Up @@ -608,7 +633,7 @@ virtual public List<PdfChunk> CreateArrayOfPdfChunks(int startIdx, int endIdx) {
}

virtual public List<PdfChunk> CreateArrayOfPdfChunks(int startIdx, int endIdx, PdfChunk extraPdfChunk) {
bool bidi = (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL);
bool bidi = (runDirection != PdfWriter.RUN_DIRECTION_NO_BIDI);
if (bidi)
Reorder(startIdx, endIdx);
List<PdfChunk> ar = new List<PdfChunk>();
Expand Down Expand Up @@ -656,14 +681,14 @@ virtual public int[] GetWord(int startIdx, int idx) {
int first = idx;
// forward
for (; last < totalTextLength; ++last) {
if (!char.IsLetter(text[last]) && !char.IsDigit(text[last]))
if (!char.IsLetter(text[last]) && !char.IsDigit(text[last]) && text[last] != '\u00AD')
break;
}
if (last == idx)
return null;
// backward
for (; first >= startIdx; --first) {
if (!char.IsLetter(text[first]) && !char.IsDigit(text[first]))
if (!char.IsLetter(text[first]) && !char.IsDigit(text[first]) && text[first] != '\u00AD')
break;
}
++first;
Expand Down
22 changes: 14 additions & 8 deletions src/core/iTextSharp/text/pdf/ColumnText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class ColumnText{
private readonly ILogger LOGGER = LoggerFactory.GetLogger(typeof(PdfPTable));

/** Eliminate the arabic vowels */
public int AR_NOVOWEL = ArabicLigaturizer.ar_novowel;
public const int AR_NOVOWEL = ArabicLigaturizer.ar_novowel;
/** Compose the tashkeel in the ligatures. */
public const int AR_COMPOSEDTASHKEEL = ArabicLigaturizer.ar_composedtashkeel;
/** Do some extra double ligatures. */
Expand Down Expand Up @@ -127,7 +127,7 @@ public class ColumnText{
*/
public const int DIGIT_TYPE_AN_EXTENDED = ArabicLigaturizer.DIGIT_TYPE_AN_EXTENDED;

protected int runDirection = PdfWriter.RUN_DIRECTION_DEFAULT;
protected int runDirection = PdfWriter.RUN_DIRECTION_NO_BIDI;
public static float GLOBAL_SPACE_CHAR_RATIO = 0;

/** Signals that there is no more text available. */
Expand Down Expand Up @@ -871,9 +871,7 @@ virtual public int Go(bool simulate, IElement elementToGo) {
PdfContentByte graphics = null;
PdfContentByte text = null;
firstLineY = float.NaN;
int localRunDirection = PdfWriter.RUN_DIRECTION_NO_BIDI;
if (runDirection != PdfWriter.RUN_DIRECTION_DEFAULT)
localRunDirection = runDirection;
int localRunDirection = runDirection;
if (canvas != null) {
graphics = canvas;
pdf = canvas.PdfDocument;
Expand Down Expand Up @@ -934,6 +932,7 @@ virtual public int Go(bool simulate, IElement elementToGo) {
}
yLine -= currentLeading;
if (!simulate && !dirty) {
// TODO this is not quite right. Currently, reversed chars may appear whenever bidi algorithm was applied, which is run direction is not NO_BIDI
if (line.isRTL && canvas.IsTagged()) {
canvas.BeginMarkedContentSequence(PdfName.REVERSEDCHARS);
rtl = true;
Expand Down Expand Up @@ -971,15 +970,14 @@ virtual public int Go(bool simulate, IElement elementToGo) {
}
line = bidiLine.ProcessLine(x1, x2 - x1 - firstIndent - rightIndent, alignment, localRunDirection, arabicOptions, minY, yLine, descender);
if (!simulate && !dirty) {
// TODO this is not quite right. Currently, reversed chars may appear whenever bidi algorithm was applied, which is run direction is not NO_BIDI
if (line.isRTL && canvas.IsTagged()) {
canvas.BeginMarkedContentSequence(PdfName.REVERSEDCHARS);
rtl = true;
}
text.BeginText();
dirty = true;
}
line = bidiLine.ProcessLine(x1, x2 - x1 - firstIndent - rightIndent, alignment, localRunDirection,
arabicOptions, minY, yLine, descender);
if (line == null)
{
status = NO_MORE_TEXT;
Expand Down Expand Up @@ -1520,7 +1518,11 @@ virtual protected int GoComposite(bool simulate) {
// INITIALISATIONS
// get the PdfPTable element
PdfPTable table = (PdfPTable) element;


int backedUpRunDir = runDirection; // storing original run direction just in case
runDirection = table.RunDirection; // using table run direction
isRTL = runDirection == PdfWriter.RUN_DIRECTION_RTL;

// tables without a body are dismissed
if (table.Size <= table.HeaderRows) {
compositeElements.RemoveAt(0);
Expand Down Expand Up @@ -1881,6 +1883,10 @@ virtual protected int GoComposite(bool simulate) {
rowIdx = k;
return NO_MORE_COLUMN;
}

// restoring original run direction
runDirection = backedUpRunDir;
isRTL = runDirection == PdfWriter.RUN_DIRECTION_RTL;
}
else if (element.Type == Element.YMARK) {
if (!simulate) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/iTextSharp/text/pdf/PdfChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ internal float GetCharWidth(int c) {
}

public static bool NoPrint(int c) {
return ((c >= 0x200b && c <= 0x200f) || (c >= 0x202a && c <= 0x202e));
return ((c >= 0x200b && c <= 0x200f) || (c >= 0x202a && c <= 0x202e) || c == '\u00AD');
}
}
}
Loading

0 comments on commit f764ddd

Please sign in to comment.