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 Aug 31, 2024
2 parents 271d01e + 2762f84 commit f87e957
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 21 deletions.
20 changes: 20 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 @@ -783,6 +783,26 @@ public virtual void CopyOnlyEmptyOcPropertiesTest() {
, destinationFolder, "diff_"));
}

[LogMessage(iText.IO.Logs.IoLogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)]
[NUnit.Framework.Test]
public virtual void CombineTagRootKidsTest() {
String filename1 = sourceFolder + "tagRootKidsDoc1.pdf";
String filename2 = sourceFolder + "tagRootKidsDoc2.pdf";
String resultFile = destinationFolder + "mergedTags.pdf";
PdfDocument result = new PdfDocument(CompareTool.CreateTestPdfWriter(resultFile));
PdfMerger merger = new PdfMerger(result, new PdfMergerProperties().SetMergeTags(true).SetMergeOutlines(true
)).SetCloseSourceDocuments(true);
PdfDocument input1 = new PdfDocument(new PdfReader(filename1));
merger.Merge(input1, 1, 1);
input1.Close();
PdfDocument input2 = new PdfDocument(new PdfReader(filename2));
merger.Merge(input2, 1, 1);
input2.Close();
merger.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(resultFile, sourceFolder + "cmp_mergedTags.pdf"
, destinationFolder, "diff_"));
}

private PdfDictionary MergeSinglePdfAndGetResultingStructTreeRoot(String pathToMerge) {
IList<FileInfo> sources = new List<FileInfo>();
sources.Add(new FileInfo(sourceFolder + pathToMerge));
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Kernel.Utils;
using iText.Layout.Borders;
using iText.Layout.Element;
using iText.Layout.Exceptions;
using iText.Layout.Properties;
using iText.Test;

Expand Down Expand Up @@ -295,6 +296,12 @@ public virtual void LineThroughTest() {
, "diff_"));
}

[NUnit.Framework.Test]
public virtual void TextInitializationWithNullValueThrowsException() {
Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new Text(null));
NUnit.Framework.Assert.AreEqual(LayoutExceptionMessageConstant.TEXT_CONTENT_CANNOT_BE_NULL, e.Message);
}

[NUnit.Framework.Test]
public virtual void LeadingAndFloatInTextTest() {
// TODO: update cmp file after fixing DEVSIX-4604
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,29 @@ public virtual void BasicThreeColumnsTest() {
));
}

[NUnit.Framework.Test]
public virtual void BorderBoxWithNoBordersTest() {
String filename = DESTINATION_FOLDER + "borderBoxWithNoBordersTest.pdf";
String cmpName = SOURCE_FOLDER + "cmp_borderBoxWithNoBordersTest.pdf";
IList<TemplateValue> templateColumns = new List<TemplateValue>();
templateColumns.Add(new PointValue(150.0f));
templateColumns.Add(new PointValue(150.0f));
using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) {
GridContainer grid = new GridContainer();
grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, templateColumns);
Paragraph child = new Paragraph("First");
child.SetProperty(Property.BOX_SIZING, BoxSizingPropertyValue.BORDER_BOX);
grid.Add(child);
document.Add(grid);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_"
));
}

[NUnit.Framework.Test]
public virtual void BasicTwoColumnsTest() {
String filename = DESTINATION_FOLDER + "basicTwoColumnsTest.pdf";
String cmpName = SOURCE_FOLDER + "cmp_basicTwoColumnsTest.pdf";
String filename = DESTINATION_FOLDER + "borderBoxChild.pdf";
String cmpName = SOURCE_FOLDER + "cmp_borderBoxChild.pdf";
IList<TemplateValue> templateColumns = new List<TemplateValue>();
templateColumns.Add(new PointValue(150.0f));
templateColumns.Add(new PointValue(150.0f));
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<!--TODO DEVSIX-7184: Bump Microsoft.Extensions.Logging when targeting netcoreapp3.1-->
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions itext/itext.commons/itext-commons.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
<dependencies>
<group targetFramework="net461">
<dependency id="Newtonsoft.Json" version="13.0.1" />
<!--TODO DEVSIX-7184: Bump Microsoft.Extensions.Logging when targeting netcoreapp3.1-->
<dependency id="Microsoft.Extensions.Logging" version="5.0.0" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="Newtonsoft.Json" version="13.0.1" />
<!--TODO DEVSIX-7184: Bump Microsoft.Extensions.Logging when targeting netcoreapp3.1-->
<dependency id="Microsoft.Extensions.Logging" version="5.0.0" />
</group>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions itext/itext.commons/itext.commons.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<!--TODO DEVSIX-7184: Bump Microsoft.Extensions.Logging when targeting netcoreapp3.1-->
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
Expand Down
12 changes: 0 additions & 12 deletions itext/itext.kernel/itext/kernel/pdf/tagging/PdfStructTreeRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,6 @@ public virtual PdfMcr FindMcrByMcid(PdfDictionary pageDict, int mcid) {
return GetParentTreeHandler().FindMcrByMcid(pageDict, mcid);
}

public virtual PdfMcr FindMcrByMcid(PdfDocument document, int mcid) {
int amountOfPages = document.GetNumberOfPages();
for (int i = 1; i <= amountOfPages; ++i) {
PdfPage page = document.GetPage(i);
PdfMcr mcr = FindMcrByMcid(page.GetPdfObject(), mcid);
if (mcr != null) {
return mcr;
}
}
return null;
}

public virtual PdfObjRef FindObjRefByStructParentIndex(PdfDictionary pageDict, int structParentIndex) {
return GetParentTreeHandler().FindObjRefByStructParentIndex(pageDict, structParentIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ private void AddStructTreeRootKidsToTheRootTag(IList<IStructureNode> rootKids) {
}
// This boolean is used to "flatten" possible deep "stacking" of the tag structure in case of the multiple pages copying operations.
// This could happen due to the wrapping of all the kids in the createNewRootTag or ensureExistingRootTagIsDocument methods.
// And therefore, we don't need here to resolve mappings, because we exactly know which role we set.
bool kidIsDocument = PdfName.Document.Equals(kid.GetRole());
IRoleMappingResolver mapping = kid.GetRole() == null ? null : context.ResolveMappingToStandardOrDomainSpecificRole
(kid.GetRole().GetValue(), rootTagElement.GetNamespace());
bool kidIsDocument = mapping != null && mapping.CurrentRoleIsStandard() && StandardRoles.DOCUMENT.Equals(mapping
.GetRole());
if (kidIsDocument && kid.GetNamespace() != null && context.TargetTagStructureVersionIs2()) {
// we flatten only tags of document role in standard structure namespace
String kidNamespaceName = kid.GetNamespace().GetNamespaceName();
Expand Down
3 changes: 2 additions & 1 deletion itext/itext.layout/itext/layout/element/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You should have received a copy of the GNU Affero General Public License
using System;
using iText.Kernel.Pdf.Tagging;
using iText.Kernel.Pdf.Tagutils;
using iText.Layout.Exceptions;
using iText.Layout.Properties;
using iText.Layout.Renderer;
using iText.Layout.Tagging;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class Text : AbstractElement<iText.Layout.Element.Text>, ILeafElement, IA
/// </param>
public Text(String text) {
if (null == text) {
throw new ArgumentException();
throw new ArgumentException(LayoutExceptionMessageConstant.TEXT_CONTENT_CANNOT_BE_NULL);
}
this.text = text;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public sealed class LayoutExceptionMessageConstant {

public const String FLEXIBLE_ARENT_ALLOWED_AS_MINIMUM_IN_MINMAX = "Flexible values aren't allowed as minimum in minmax grid function.";

public const String TEXT_CONTENT_CANNOT_BE_NULL = "Text content cannot be null.";

private LayoutExceptionMessageConstant() {
}
}
Expand Down
4 changes: 3 additions & 1 deletion itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ internal virtual float CalculateHeight(float initialHeight) {
rectangle.DecreaseHeight(paddingBottom.GetValue());
}
Border borderBottom = renderer.GetBorders()[AbstractRenderer.BOTTOM_SIDE];
rectangle.DecreaseHeight(borderBottom.GetWidth());
if (borderBottom != null) {
rectangle.DecreaseHeight(borderBottom.GetWidth());
}
}
else {
renderer.ApplyMarginsBordersPaddings(rectangle, false);
Expand Down
15 changes: 13 additions & 2 deletions itext/itext.pdfua/itext/pdfua/checkers/PdfUA1Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,26 @@ private bool IsRealContent(Tuple2<PdfName, PdfDictionary> tag) {
if (properties == null || !properties.ContainsKey(PdfName.MCID)) {
return false;
}
PdfMcr mcr = this.pdfDocument.GetStructTreeRoot().FindMcrByMcid(pdfDocument, (int)properties.GetAsInt(PdfName
.MCID));
PdfMcr mcr = McrExists(pdfDocument, (int)properties.GetAsInt(PdfName.MCID));
if (mcr == null) {
throw new PdfUAConformanceException(PdfUAExceptionMessageConstants.CONTENT_WITH_MCID_BUT_MCID_NOT_FOUND_IN_STRUCT_TREE_ROOT
);
}
return true;
}

private PdfMcr McrExists(PdfDocument document, int mcid) {
int amountOfPages = document.GetNumberOfPages();
for (int i = 1; i <= amountOfPages; ++i) {
PdfPage page = document.GetPage(i);
PdfMcr mcr = document.GetStructTreeRoot().FindMcrByMcid(page.GetPdfObject(), mcid);
if (mcr != null) {
return mcr;
}
}
return null;
}

private void CheckCatalog(PdfCatalog catalog) {
PdfDictionary catalogDict = catalog.GetPdfObject();
if (!catalogDict.ContainsKey(PdfName.Metadata)) {
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1b8017a9a31aaf6bbdd6773e498e11d81d971790
b8f684a0dd103255900f1cf090e811e8c2444b11

0 comments on commit f87e957

Please sign in to comment.