Skip to content

Commit f764ddd

Browse files
committed
2 parents 75f05dd + 90383a8 commit f764ddd

File tree

105 files changed

+2930
-1329
lines changed

Some content is hidden

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

105 files changed

+2930
-1329
lines changed

gnu-agpl-v3.0.md

Lines changed: 651 additions & 0 deletions
Large diffs are not rendered by default.

src/core/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[assembly: AssemblyConfiguration("")]
1313
[assembly: AssemblyCompany("iText Group NV")]
1414
[assembly: AssemblyProduct("iTextSharp")]
15-
[assembly: AssemblyCopyright("Copyright (C) 1999-2014 by Bruno Lowagie and Paulo Soares. All Rights Reserved.")]
15+
[assembly: AssemblyCopyright("Copyright (C) 1999-2016 by iText Group NV")]
1616
[assembly: AssemblyTrademark("")]
1717
[assembly: AssemblyCulture("")]
1818
[assembly: InternalsVisibleTo("itextsharp.pdfa, PublicKey=00240000048000009400000006020000002400005253413100040000010001008b21ed5b3fc1c11996390981fe22bbe71a39a9e11d3c2cefddd6ee92920fa871f9666ae0fa941af0280d0653df048ae2d93f8c5e2d820dba3c8df9ed468c8be40a6fffeb32aa481a254f0fb9f37aa7c3ec1c0acd2c009746bbdafcb75bcdbcecb7caf1f0f4b6e7d013906ba60b66eb1c8298e4efb052caf6cece4bf1816902cc"),]
@@ -32,4 +32,4 @@
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
3434

35-
[assembly: AssemblyVersion("5.5.9")]
35+
[assembly: AssemblyVersion("5.5.10")]

src/core/iTextSharp/testutils/CompareTool.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,14 @@ private bool CompareDictionariesExtended(PdfDictionary outDict, PdfDictionary cm
808808
if (compareResult != null && currentPath != null)
809809
compareResult.AddError(currentPath, String.Format("PdfDictionary {0} entry: Expected: {1}. Found: {2}", key.ToString(), cmpObj.ToString(), outObj.ToString()));
810810
dictsAreSame = false;
811-
}
812-
String cmpName = cmpObj.ToString().Substring(cmpObj.ToString().IndexOf('+'));
813-
String outName = outObj.ToString().Substring(outObj.ToString().IndexOf('+'));
814-
if (!cmpName.Equals(outName)) {
815-
if (compareResult != null && currentPath != null)
816-
compareResult.AddError(currentPath, String.Format("PdfDictionary {0} entry: Expected: {1}. Found: {2}", key.ToString(), cmpObj.ToString(), outObj.ToString()));
817-
dictsAreSame = false;
811+
} else {
812+
String cmpName = cmpObj.ToString().Substring(cmpObj.ToString().IndexOf('+'));
813+
String outName = outObj.ToString().Substring(outObj.ToString().IndexOf('+'));
814+
if (!cmpName.Equals(outName)) {
815+
if (compareResult != null && currentPath != null)
816+
compareResult.AddError(currentPath, String.Format("PdfDictionary {0} entry: Expected: {1}. Found: {2}", key.ToString(), cmpObj.ToString(), outObj.ToString()));
817+
dictsAreSame = false;
818+
}
818819
}
819820
continue;
820821
}

src/core/iTextSharp/text/Image.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,28 @@ public static Image GetInstance(System.Drawing.Image image, BaseColor color, boo
702702
transparency[0] = transparency[1] = (transparentPixel >> 16) & 0xff;
703703
transparency[2] = transparency[3] = (transparentPixel >> 8) & 0xff;
704704
transparency[4] = transparency[5] = transparentPixel & 0xff;
705+
// Added by Michael Klink
706+
// Check whether this value for transparent pixels
707+
// has already been used for a non-transparent one
708+
// before this position
709+
for (int prevPixelI = 0; prevPixelI <= i; prevPixelI++) {
710+
for (int prevPixelJ = 0; prevPixelJ < (prevPixelI == i ? j : h); prevPixelJ++) {
711+
int prevPxV = bm.GetPixel(prevPixelI, prevPixelJ).ToArgb();
712+
if ((prevPxV & 0xffffff) == transparentPixel) {
713+
// found a prior use of the transparentPixel color
714+
// and, therefore, cannot make use of this color
715+
// for transparency; we could still use an image
716+
// mask but for simplicity let's use a soft mask
717+
// which already is implemented here
718+
shades = true;
719+
break;
720+
}
721+
}
722+
}
705723
}
706-
} else if ((pxv & 0xffffff) != transparentPixel) {
724+
} else if (((pxv & 0xffffff) != transparentPixel) && (alpha == 0)) {
725+
shades = true;
726+
} else if (((pxv & 0xffffff) == transparentPixel) && (alpha != 0)) {
707727
shades = true;
708728
}
709729
}

src/core/iTextSharp/text/Version.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public sealed class Version {
7575
* This String contains the version number of this iText release.
7676
* For debugging purposes, we request you NOT to change this constant.
7777
*/
78-
static private String release = "5.5.9";
78+
static private String release = "5.5.10";
7979

8080
/**
8181
* This String contains the iText version as shown in the producer line.

src/core/iTextSharp/text/pdf/AcroFields.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,8 @@ virtual public bool RemoveField(String name, int page) {
17471747
continue;
17481748
PdfIndirectReference refi = item.GetWidgetRef(k);
17491749
PdfDictionary wd = item.GetWidget( k );
1750-
PdfDictionary pageDic = reader.GetPageN(pageV);
1751-
PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
1750+
PdfDictionary pageDic = reader.GetPageN(pageV); //Returns null in case of floating, orphaned fields
1751+
PdfArray annots = pageDic != null ? pageDic.GetAsArray(PdfName.ANNOTS): null;//Account for floating, orphaned fields
17521752
if (annots != null) {
17531753
if (RemoveRefFromArray(annots, refi) == 0) {
17541754
pageDic.Remove(PdfName.ANNOTS);

src/core/iTextSharp/text/pdf/BarcodeDatamatrix.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public class BarcodeDatamatrix {
148148
private int width;
149149
private int ws;
150150
private int options;
151-
151+
private bool forceSquareSize = false;
152+
152153
/**
153154
* Creates an instance of this class.
154155
*/
@@ -722,7 +723,7 @@ virtual public int Generate(byte[] text, int textOffset, int textSize) {
722723
}
723724
e += extCount;
724725
for (k = 0; k < dmSizes.Length; ++k) {
725-
if (dmSizes[k].dataSize >= e)
726+
if (dmSizes[k].dataSize >= e && (!forceSquareSize || dmSizes[k].width == dmSizes[k].height))
726727
break;
727728
}
728729
dm = dmSizes[k];
@@ -987,6 +988,10 @@ virtual public int Options {
987988
}
988989
}
989990

991+
public virtual bool ForceSquareSize {
992+
set { forceSquareSize = value; }
993+
}
994+
990995
internal class Placement {
991996
private int nrow;
992997
private int ncol;

src/core/iTextSharp/text/pdf/BidiLine.cs

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,28 @@ virtual public bool GetParagraph(int runDirection) {
176176
if (totalTextLength == 0)
177177
return true;
178178

179-
if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
179+
if (runDirection != PdfWriter.RUN_DIRECTION_NO_BIDI) {
180180
if (orderLevels.Length < totalTextLength) {
181181
orderLevels = new byte[pieceSize];
182182
indexChars = new int[pieceSize];
183183
}
184184

185185
ArabicLigaturizer.ProcessNumbers(text, 0, totalTextLength, arabicOptions);
186-
BidiOrder order = new BidiOrder(text, 0, totalTextLength, (sbyte)(runDirection == PdfWriter.RUN_DIRECTION_RTL ? 1 : 0));
186+
sbyte paragraphEmbeddingLevel;
187+
switch (runDirection)
188+
{
189+
case PdfWriter.RUN_DIRECTION_LTR:
190+
paragraphEmbeddingLevel = 0;
191+
break;
192+
case PdfWriter.RUN_DIRECTION_RTL:
193+
paragraphEmbeddingLevel = 1;
194+
break;
195+
case PdfWriter.RUN_DIRECTION_DEFAULT:
196+
default:
197+
paragraphEmbeddingLevel = -1;
198+
break;
199+
}
200+
BidiOrder order = new BidiOrder(text, 0, totalTextLength, paragraphEmbeddingLevel);
187201
byte[] od = order.GetLevels();
188202
for (int k = 0; k < totalTextLength; ++k) {
189203
orderLevels[k] = od[k];
@@ -243,7 +257,7 @@ virtual public void Save() {
243257
Array.Copy(text, 0, storedText, 0, totalTextLength);
244258
Array.Copy(detailChunks, 0, storedDetailChunks, 0, totalTextLength);
245259
}
246-
if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
260+
if (runDirection != PdfWriter.RUN_DIRECTION_NO_BIDI) {
247261
if (storedOrderLevels.Length < totalTextLength) {
248262
storedOrderLevels = new byte[totalTextLength];
249263
storedIndexChars = new int[totalTextLength];
@@ -264,7 +278,7 @@ virtual public void Restore() {
264278
Array.Copy(storedText, 0, text, 0, totalTextLength);
265279
Array.Copy(storedDetailChunks, 0, detailChunks, 0, totalTextLength);
266280
}
267-
if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
281+
if (runDirection != PdfWriter.RUN_DIRECTION_NO_BIDI) {
268282
Array.Copy(storedOrderLevels, currentChar, orderLevels, currentChar, totalTextLength - currentChar);
269283
Array.Copy(storedIndexChars, currentChar, indexChars, currentChar, totalTextLength - currentChar);
270284
}
@@ -348,6 +362,7 @@ virtual public PdfLine ProcessLine(float leftX, float width, int alignment, int
348362
float charWidth = 0;
349363
PdfChunk lastValidChunk = null;
350364
TabStop tabStop = null;
365+
IList<TabStop> rtlTabsToBeAligned = new List<TabStop>();
351366
float tabStopAnchorPosition = float.NaN;
352367
float tabPosition = float.NaN;
353368
bool surrogate = false;
@@ -394,14 +409,7 @@ virtual public PdfLine ProcessLine(float leftX, float width, int alignment, int
394409
if (ck.IsAttribute(Chunk.TABSETTINGS)) {
395410
lastSplit = currentChar;
396411
if (tabStop != null) {
397-
float tabStopPosition = tabStop.GetPosition(tabPosition, originalWidth - width,
398-
tabStopAnchorPosition);
399-
width = originalWidth - (tabStopPosition + (originalWidth - width - tabPosition));
400-
if (width < 0) {
401-
tabStopPosition += width;
402-
width = 0;
403-
}
404-
tabStop.Position = tabStopPosition;
412+
width = ProcessTabStop(tabStop, tabPosition, originalWidth, width, tabStopAnchorPosition, isRTL, rtlTabsToBeAligned);
405413
}
406414

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

470478
if (tabStop != null) {
471-
float tabStopPosition = tabStop.GetPosition(tabPosition, originalWidth - width, tabStopAnchorPosition);
472-
width -= tabStopPosition - tabPosition;
473-
if (width < 0) {
474-
tabStopPosition += width;
475-
width = 0;
479+
width = ProcessTabStop(tabStop, tabPosition, originalWidth, width, tabStopAnchorPosition, isRTL, rtlTabsToBeAligned);
480+
}
481+
if (rtlTabsToBeAligned != null) {
482+
foreach (TabStop rtlTabStop in rtlTabsToBeAligned) {
483+
rtlTabStop.Position = originalWidth - width - rtlTabStop.Position;
476484
}
477-
if (!isRTL)
478-
tabStop.Position = tabStopPosition;
479-
else
480-
tabStop.Position = originalWidth - width - tabPosition;
481485
}
482486

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

528+
private float ProcessTabStop(TabStop tabStop, float tabPosition, float originalWidth, float width, float tabStopAnchorPosition, bool isRTL, IList<TabStop> rtlTabsToBeAligned)
529+
{
530+
float tabStopPosition = tabStop.GetPosition(tabPosition, originalWidth - width, tabStopAnchorPosition);
531+
width -= tabStopPosition - tabPosition;
532+
if (width < 0)
533+
{
534+
tabStopPosition += width;
535+
width = 0;
536+
}
537+
if (!isRTL)
538+
{
539+
tabStop.Position = tabStopPosition;
540+
}
541+
else
542+
{
543+
tabStop.Position = tabPosition; // This will be mirrored when we know exact line width
544+
rtlTabsToBeAligned.Add(tabStop);
545+
}
546+
return width;
547+
}
548+
524549
/**
525550
* Call this after processLine() to know if any word was split into several lines.
526551
* @return
@@ -608,7 +633,7 @@ virtual public List<PdfChunk> CreateArrayOfPdfChunks(int startIdx, int endIdx) {
608633
}
609634

610635
virtual public List<PdfChunk> CreateArrayOfPdfChunks(int startIdx, int endIdx, PdfChunk extraPdfChunk) {
611-
bool bidi = (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL);
636+
bool bidi = (runDirection != PdfWriter.RUN_DIRECTION_NO_BIDI);
612637
if (bidi)
613638
Reorder(startIdx, endIdx);
614639
List<PdfChunk> ar = new List<PdfChunk>();
@@ -656,14 +681,14 @@ virtual public int[] GetWord(int startIdx, int idx) {
656681
int first = idx;
657682
// forward
658683
for (; last < totalTextLength; ++last) {
659-
if (!char.IsLetter(text[last]) && !char.IsDigit(text[last]))
684+
if (!char.IsLetter(text[last]) && !char.IsDigit(text[last]) && text[last] != '\u00AD')
660685
break;
661686
}
662687
if (last == idx)
663688
return null;
664689
// backward
665690
for (; first >= startIdx; --first) {
666-
if (!char.IsLetter(text[first]) && !char.IsDigit(text[first]))
691+
if (!char.IsLetter(text[first]) && !char.IsDigit(text[first]) && text[first] != '\u00AD')
667692
break;
668693
}
669694
++first;

src/core/iTextSharp/text/pdf/ColumnText.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class ColumnText{
8080
private readonly ILogger LOGGER = LoggerFactory.GetLogger(typeof(PdfPTable));
8181

8282
/** Eliminate the arabic vowels */
83-
public int AR_NOVOWEL = ArabicLigaturizer.ar_novowel;
83+
public const int AR_NOVOWEL = ArabicLigaturizer.ar_novowel;
8484
/** Compose the tashkeel in the ligatures. */
8585
public const int AR_COMPOSEDTASHKEEL = ArabicLigaturizer.ar_composedtashkeel;
8686
/** Do some extra double ligatures. */
@@ -127,7 +127,7 @@ public class ColumnText{
127127
*/
128128
public const int DIGIT_TYPE_AN_EXTENDED = ArabicLigaturizer.DIGIT_TYPE_AN_EXTENDED;
129129

130-
protected int runDirection = PdfWriter.RUN_DIRECTION_DEFAULT;
130+
protected int runDirection = PdfWriter.RUN_DIRECTION_NO_BIDI;
131131
public static float GLOBAL_SPACE_CHAR_RATIO = 0;
132132

133133
/** Signals that there is no more text available. */
@@ -871,9 +871,7 @@ virtual public int Go(bool simulate, IElement elementToGo) {
871871
PdfContentByte graphics = null;
872872
PdfContentByte text = null;
873873
firstLineY = float.NaN;
874-
int localRunDirection = PdfWriter.RUN_DIRECTION_NO_BIDI;
875-
if (runDirection != PdfWriter.RUN_DIRECTION_DEFAULT)
876-
localRunDirection = runDirection;
874+
int localRunDirection = runDirection;
877875
if (canvas != null) {
878876
graphics = canvas;
879877
pdf = canvas.PdfDocument;
@@ -934,6 +932,7 @@ virtual public int Go(bool simulate, IElement elementToGo) {
934932
}
935933
yLine -= currentLeading;
936934
if (!simulate && !dirty) {
935+
// TODO this is not quite right. Currently, reversed chars may appear whenever bidi algorithm was applied, which is run direction is not NO_BIDI
937936
if (line.isRTL && canvas.IsTagged()) {
938937
canvas.BeginMarkedContentSequence(PdfName.REVERSEDCHARS);
939938
rtl = true;
@@ -971,15 +970,14 @@ virtual public int Go(bool simulate, IElement elementToGo) {
971970
}
972971
line = bidiLine.ProcessLine(x1, x2 - x1 - firstIndent - rightIndent, alignment, localRunDirection, arabicOptions, minY, yLine, descender);
973972
if (!simulate && !dirty) {
973+
// TODO this is not quite right. Currently, reversed chars may appear whenever bidi algorithm was applied, which is run direction is not NO_BIDI
974974
if (line.isRTL && canvas.IsTagged()) {
975975
canvas.BeginMarkedContentSequence(PdfName.REVERSEDCHARS);
976976
rtl = true;
977977
}
978978
text.BeginText();
979979
dirty = true;
980980
}
981-
line = bidiLine.ProcessLine(x1, x2 - x1 - firstIndent - rightIndent, alignment, localRunDirection,
982-
arabicOptions, minY, yLine, descender);
983981
if (line == null)
984982
{
985983
status = NO_MORE_TEXT;
@@ -1520,7 +1518,11 @@ virtual protected int GoComposite(bool simulate) {
15201518
// INITIALISATIONS
15211519
// get the PdfPTable element
15221520
PdfPTable table = (PdfPTable) element;
1523-
1521+
1522+
int backedUpRunDir = runDirection; // storing original run direction just in case
1523+
runDirection = table.RunDirection; // using table run direction
1524+
isRTL = runDirection == PdfWriter.RUN_DIRECTION_RTL;
1525+
15241526
// tables without a body are dismissed
15251527
if (table.Size <= table.HeaderRows) {
15261528
compositeElements.RemoveAt(0);
@@ -1881,6 +1883,10 @@ virtual protected int GoComposite(bool simulate) {
18811883
rowIdx = k;
18821884
return NO_MORE_COLUMN;
18831885
}
1886+
1887+
// restoring original run direction
1888+
runDirection = backedUpRunDir;
1889+
isRTL = runDirection == PdfWriter.RUN_DIRECTION_RTL;
18841890
}
18851891
else if (element.Type == Element.YMARK) {
18861892
if (!simulate) {

src/core/iTextSharp/text/pdf/PdfChunk.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ internal float GetCharWidth(int c) {
988988
}
989989

990990
public static bool NoPrint(int c) {
991-
return ((c >= 0x200b && c <= 0x200f) || (c >= 0x202a && c <= 0x202e));
991+
return ((c >= 0x200b && c <= 0x200f) || (c >= 0x202a && c <= 0x202e) || c == '\u00AD');
992992
}
993993
}
994994
}

0 commit comments

Comments
 (0)