diff --git a/itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs index 116ab5a49c..4d378d6d0e 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs @@ -84,6 +84,24 @@ public virtual void MergeDocumentOutlinesWithNullDestinationTest01() { , destinationFolder, "diff_")); } + [NUnit.Framework.Test] + [LogMessage(iText.IO.Logs.IoLogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)] + public virtual void MergeDocumentOutlinesWithExplicitRemoteDestinationTest() { + String resultFile = destinationFolder + "mergeDocumentWithRemoteGoToTest.pdf"; + String filename1 = sourceFolder + "docWithRemoteGoTo.pdf"; + String filename2 = sourceFolder + "doc1.pdf"; + PdfDocument sourceDocument1 = new PdfDocument(new PdfReader(filename1)); + PdfDocument sourceDocument2 = new PdfDocument(new PdfReader(filename2)); + PdfMerger resultDocument = new PdfMerger(new PdfDocument(CompareTool.CreateTestPdfWriter(resultFile))); + resultDocument.Merge(sourceDocument1, 1, 1); + resultDocument.Merge(sourceDocument2, 1, 1); + resultDocument.Close(); + sourceDocument1.Close(); + sourceDocument2.Close(); + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(resultFile, sourceFolder + "cmp_mergeDocumentWithRemoteGoToTest.pdf" + , destinationFolder, "diff_")); + } + [NUnit.Framework.Test] public virtual void MergeDocumentWithCycleRefInAcroFormTest() { String filename1 = sourceFolder + "doc1.pdf"; diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergeDocumentWithRemoteGoToTest.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergeDocumentWithRemoteGoToTest.pdf new file mode 100644 index 0000000000..15b15e3b5d Binary files /dev/null and b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/cmp_mergeDocumentWithRemoteGoToTest.pdf differ diff --git a/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/docWithRemoteGoTo.pdf b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/docWithRemoteGoTo.pdf new file mode 100644 index 0000000000..bbf7a0674a Binary files /dev/null and b/itext.tests/itext.kernel.tests/resources/itext/kernel/utils/PdfMergerTest/docWithRemoteGoTo.pdf differ diff --git a/itext.tests/itext.layout.tests/itext/layout/AlignmentTest.cs b/itext.tests/itext.layout.tests/itext/layout/AlignmentTest.cs index 6f2c7aeeac..452f0bfdd1 100644 --- a/itext.tests/itext.layout.tests/itext/layout/AlignmentTest.cs +++ b/itext.tests/itext.layout.tests/itext/layout/AlignmentTest.cs @@ -45,6 +45,9 @@ public class AlignmentTest : ExtendedITextTest { private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory + "/test/itext/layout/AlignmentTest/"; + private static readonly String FONTS_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext + .CurrentContext.TestDirectory) + "/resources/itext/layout/fonts/"; + [NUnit.Framework.OneTimeSetUp] public static void BeforeClass() { CreateOrClearDestinationFolder(DESTINATION_FOLDER); @@ -519,6 +522,23 @@ public virtual void FlexItemHorizontalAlignmentTest() { , "diff")); } + [NUnit.Framework.Test] + public virtual void JustifiedAlignmentWithZeroFreeSpaceTest() { + String outFileName = DESTINATION_FOLDER + "justifiedAlignmentWithZeroFreeSpaceTest.pdf"; + String cmpFileName = SOURCE_FOLDER + "cmp_justifiedAlignmentWithZeroFreeSpaceTest.pdf"; + using (PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName))) { + Document document = new Document(pdfDoc); + PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansCJKjp-Regular.otf"); + Text t1 = new Text("期期期").SetFont(font); + Text t2 = new Text("期期期").SetFont(font); + Paragraph p = new Paragraph(t1).Add(t2).SetSpacingRatio(1).SetWidth(60).SetTextAlignment(TextAlignment.JUSTIFIED + ); + document.Add(p); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER + , "diff")); + } + private static void CreateDocumentWithInlineAlignment(String outPdf, String cmpPdf, InlineVerticalAlignmentType? verticalAlignment1) { CreateDocumentWithInlineAlignment(outPdf, cmpPdf, verticalAlignment1, null); diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/AlignmentTest/cmp_justifiedAlignmentWithZeroFreeSpaceTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/AlignmentTest/cmp_justifiedAlignmentWithZeroFreeSpaceTest.pdf new file mode 100644 index 0000000000..6f18d61daf Binary files /dev/null and b/itext.tests/itext.layout.tests/resources/itext/layout/AlignmentTest/cmp_justifiedAlignmentWithZeroFreeSpaceTest.pdf differ diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs b/itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs index c566b3ccb7..9536cd3253 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs @@ -780,14 +780,14 @@ internal virtual PdfDestination CopyDestination(PdfObject dest, IDictionary page2page + , PdfDocument toDocument, PdfObject pageObject) { + foreach (PdfPage oldPage in page2page.Keys) { + if (oldPage.GetPdfObject() == pageObject) { + // in the copiedArray old page ref will be correctly replaced by the new page ref + // as this page is already copied + PdfArray copiedArray = (PdfArray)dest.CopyTo(toDocument, false, NullCopyFilter.GetInstance()); + return new PdfExplicitDestination(copiedArray); + } + } + return null; + } + private bool IsEqualSameNameDestExist(IDictionary page2page, PdfDocument toDocument, PdfString srcDestName, PdfArray srcDestArray, PdfPage oldPage) { PdfArray sameNameDest = (PdfArray)toDocument.GetCatalog().GetNameTree(PdfName.Dests).GetNames().Get(srcDestName diff --git a/itext/itext.layout/itext/layout/renderer/LineRenderer.cs b/itext/itext.layout/itext/layout/renderer/LineRenderer.cs index 7774be49b3..39af7ad3a4 100644 --- a/itext/itext.layout/itext/layout/renderer/LineRenderer.cs +++ b/itext/itext.layout/itext/layout/renderer/LineRenderer.cs @@ -729,7 +729,7 @@ public virtual void Justify(float width) { int baseCharsCount = BaseCharactersCount(); float baseFactor = freeWidth / (ratio * numberOfSpaces + (1 - ratio) * (baseCharsCount - 1)); //Prevent a NaN when trying to justify a single word with spacing_ratio == 1.0 - if (float.IsInfinity(baseFactor)) { + if (float.IsInfinity(baseFactor) || float.IsNaN(baseFactor)) { baseFactor = 0; } float wordSpacing = ratio * baseFactor; diff --git a/port-hash b/port-hash index 1c918581c7..94e18e2fbf 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -a390afa1f077eb736e61e6d66d74a7f35354e0e4 +238107cd5532d937fc246b97f60c8f1599786f9d