Skip to content

Commit 32b257e

Browse files
committed
Merge branch 'develop' into devsecops
2 parents 09ef468 + 2d0c66a commit 32b257e

File tree

8 files changed

+65
-10
lines changed

8 files changed

+65
-10
lines changed

itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs

+18
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@ public virtual void MergeDocumentOutlinesWithNullDestinationTest01() {
8484
, destinationFolder, "diff_"));
8585
}
8686

87+
[NUnit.Framework.Test]
88+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)]
89+
public virtual void MergeDocumentOutlinesWithExplicitRemoteDestinationTest() {
90+
String resultFile = destinationFolder + "mergeDocumentWithRemoteGoToTest.pdf";
91+
String filename1 = sourceFolder + "docWithRemoteGoTo.pdf";
92+
String filename2 = sourceFolder + "doc1.pdf";
93+
PdfDocument sourceDocument1 = new PdfDocument(new PdfReader(filename1));
94+
PdfDocument sourceDocument2 = new PdfDocument(new PdfReader(filename2));
95+
PdfMerger resultDocument = new PdfMerger(new PdfDocument(CompareTool.CreateTestPdfWriter(resultFile)));
96+
resultDocument.Merge(sourceDocument1, 1, 1);
97+
resultDocument.Merge(sourceDocument2, 1, 1);
98+
resultDocument.Close();
99+
sourceDocument1.Close();
100+
sourceDocument2.Close();
101+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(resultFile, sourceFolder + "cmp_mergeDocumentWithRemoteGoToTest.pdf"
102+
, destinationFolder, "diff_"));
103+
}
104+
87105
[NUnit.Framework.Test]
88106
public virtual void MergeDocumentWithCycleRefInAcroFormTest() {
89107
String filename1 = sourceFolder + "doc1.pdf";

itext.tests/itext.layout.tests/itext/layout/AlignmentTest.cs

+20
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class AlignmentTest : ExtendedITextTest {
4545
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
4646
+ "/test/itext/layout/AlignmentTest/";
4747

48+
private static readonly String FONTS_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
49+
.CurrentContext.TestDirectory) + "/resources/itext/layout/fonts/";
50+
4851
[NUnit.Framework.OneTimeSetUp]
4952
public static void BeforeClass() {
5053
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
@@ -519,6 +522,23 @@ public virtual void FlexItemHorizontalAlignmentTest() {
519522
, "diff"));
520523
}
521524

525+
[NUnit.Framework.Test]
526+
public virtual void JustifiedAlignmentWithZeroFreeSpaceTest() {
527+
String outFileName = DESTINATION_FOLDER + "justifiedAlignmentWithZeroFreeSpaceTest.pdf";
528+
String cmpFileName = SOURCE_FOLDER + "cmp_justifiedAlignmentWithZeroFreeSpaceTest.pdf";
529+
using (PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName))) {
530+
Document document = new Document(pdfDoc);
531+
PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansCJKjp-Regular.otf");
532+
Text t1 = new Text("期期期").SetFont(font);
533+
Text t2 = new Text("期期期").SetFont(font);
534+
Paragraph p = new Paragraph(t1).Add(t2).SetSpacingRatio(1).SetWidth(60).SetTextAlignment(TextAlignment.JUSTIFIED
535+
);
536+
document.Add(p);
537+
}
538+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
539+
, "diff"));
540+
}
541+
522542
private static void CreateDocumentWithInlineAlignment(String outPdf, String cmpPdf, InlineVerticalAlignmentType?
523543
verticalAlignment1) {
524544
CreateDocumentWithInlineAlignment(outPdf, cmpPdf, verticalAlignment1, null);

itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs

+25-8
Original file line numberDiff line numberDiff line change
@@ -780,14 +780,14 @@ internal virtual PdfDestination CopyDestination(PdfObject dest, IDictionary<PdfP
780780
PdfDestination d = null;
781781
if (dest.IsArray()) {
782782
PdfObject pageObject = ((PdfArray)dest).Get(0);
783-
foreach (PdfPage oldPage in page2page.Keys) {
784-
if (oldPage.GetPdfObject() == pageObject) {
785-
// in the copiedArray old page ref will be correctly replaced by the new page ref
786-
// as this page is already copied
787-
PdfArray copiedArray = (PdfArray)dest.CopyTo(toDocument, false, NullCopyFilter.GetInstance());
788-
d = new PdfExplicitDestination(copiedArray);
789-
break;
790-
}
783+
//12.3.2.2 Explicit destinations
784+
if (pageObject.IsNumber()) {
785+
//Handle remote and embedded destinations
786+
d = CreateDestinationFromPageNum(dest, toDocument);
787+
}
788+
else {
789+
//Handle all other destinations
790+
d = CreateDestinationFromPageRef(dest, page2page, toDocument, pageObject);
791791
}
792792
}
793793
else {
@@ -840,6 +840,23 @@ internal virtual PdfDictionary FillAndGetOcPropertiesDictionary() {
840840
}
841841
//\endcond
842842

843+
private PdfDestination CreateDestinationFromPageNum(PdfObject dest, PdfDocument toDocument) {
844+
return new PdfExplicitDestination((PdfArray)dest.CopyTo(toDocument, false, NullCopyFilter.GetInstance()));
845+
}
846+
847+
private static PdfDestination CreateDestinationFromPageRef(PdfObject dest, IDictionary<PdfPage, PdfPage> page2page
848+
, PdfDocument toDocument, PdfObject pageObject) {
849+
foreach (PdfPage oldPage in page2page.Keys) {
850+
if (oldPage.GetPdfObject() == pageObject) {
851+
// in the copiedArray old page ref will be correctly replaced by the new page ref
852+
// as this page is already copied
853+
PdfArray copiedArray = (PdfArray)dest.CopyTo(toDocument, false, NullCopyFilter.GetInstance());
854+
return new PdfExplicitDestination(copiedArray);
855+
}
856+
}
857+
return null;
858+
}
859+
843860
private bool IsEqualSameNameDestExist(IDictionary<PdfPage, PdfPage> page2page, PdfDocument toDocument, PdfString
844861
srcDestName, PdfArray srcDestArray, PdfPage oldPage) {
845862
PdfArray sameNameDest = (PdfArray)toDocument.GetCatalog().GetNameTree(PdfName.Dests).GetNames().Get(srcDestName

itext/itext.layout/itext/layout/renderer/LineRenderer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ public virtual void Justify(float width) {
729729
int baseCharsCount = BaseCharactersCount();
730730
float baseFactor = freeWidth / (ratio * numberOfSpaces + (1 - ratio) * (baseCharsCount - 1));
731731
//Prevent a NaN when trying to justify a single word with spacing_ratio == 1.0
732-
if (float.IsInfinity(baseFactor)) {
732+
if (float.IsInfinity(baseFactor) || float.IsNaN(baseFactor)) {
733733
baseFactor = 0;
734734
}
735735
float wordSpacing = ratio * baseFactor;

port-hash

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a390afa1f077eb736e61e6d66d74a7f35354e0e4
1+
238107cd5532d937fc246b97f60c8f1599786f9d

0 commit comments

Comments
 (0)