Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Oct 18, 2024
2 parents 09ef468 + 2d0c66a commit 32b257e
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 10 deletions.
18 changes: 18 additions & 0 deletions itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions itext.tests/itext.layout.tests/itext/layout/AlignmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Binary file not shown.
33 changes: 25 additions & 8 deletions itext/itext.kernel/itext/kernel/pdf/PdfCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,14 @@ internal virtual PdfDestination CopyDestination(PdfObject dest, IDictionary<PdfP
PdfDestination d = null;
if (dest.IsArray()) {
PdfObject pageObject = ((PdfArray)dest).Get(0);
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());
d = new PdfExplicitDestination(copiedArray);
break;
}
//12.3.2.2 Explicit destinations
if (pageObject.IsNumber()) {
//Handle remote and embedded destinations
d = CreateDestinationFromPageNum(dest, toDocument);
}
else {
//Handle all other destinations
d = CreateDestinationFromPageRef(dest, page2page, toDocument, pageObject);
}
}
else {
Expand Down Expand Up @@ -840,6 +840,23 @@ internal virtual PdfDictionary FillAndGetOcPropertiesDictionary() {
}
//\endcond

private PdfDestination CreateDestinationFromPageNum(PdfObject dest, PdfDocument toDocument) {
return new PdfExplicitDestination((PdfArray)dest.CopyTo(toDocument, false, NullCopyFilter.GetInstance()));
}

private static PdfDestination CreateDestinationFromPageRef(PdfObject dest, IDictionary<PdfPage, PdfPage> 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<PdfPage, PdfPage> page2page, PdfDocument toDocument, PdfString
srcDestName, PdfArray srcDestArray, PdfPage oldPage) {
PdfArray sameNameDest = (PdfArray)toDocument.GetCatalog().GetNameTree(PdfName.Dests).GetNames().Get(srcDestName
Expand Down
2 changes: 1 addition & 1 deletion itext/itext.layout/itext/layout/renderer/LineRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a390afa1f077eb736e61e6d66d74a7f35354e0e4
238107cd5532d937fc246b97f60c8f1599786f9d

0 comments on commit 32b257e

Please sign in to comment.