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 May 30, 2024
2 parents b32157c + 2de8c47 commit 12a952c
Show file tree
Hide file tree
Showing 46 changed files with 529 additions and 395 deletions.
32 changes: 32 additions & 0 deletions itext.tests/itext.kernel.tests/itext/kernel/pdf/ParentTreeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,38 @@ public virtual void Test06() {
NUnit.Framework.Assert.IsTrue(CheckParentTree(outFile, cmpFile));
}

[NUnit.Framework.Test]
public virtual void ObjRefAsStreamTest() {
String pdf = sourceFolder + "objRefAsStream.pdf";
String outPdf = destinationFolder + "objRefAsStream.pdf";
String cmpPdf = sourceFolder + "cmp_objRefAsStream.pdf";
PdfDocument taggedPdf = new PdfDocument(new PdfReader(pdf), CompareTool.CreateTestPdfWriter(outPdf));
taggedPdf.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff"
));
}

[NUnit.Framework.Test]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TAG_STRUCTURE_INIT_FAILED)]
public virtual void ObjRefAsInvalidType() {
String pdf = sourceFolder + "objRefAsInvalidType.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(pdf));
NUnit.Framework.Assert.IsNull(doc.GetStructTreeRoot());
}

[NUnit.Framework.Test]
public virtual void UnregisterObjRefAsStreamTest() {
String pdf = sourceFolder + "objRefAsStream.pdf";
String outPdf = destinationFolder + "objRefAsStreamUnregisterMcr.pdf";
String cmpPdf = sourceFolder + "cmp_objRefAsStreamUnregisterMcr.pdf";
PdfDocument taggedPdf = new PdfDocument(new PdfReader(pdf), CompareTool.CreateTestPdfWriter(outPdf));
PdfStructElem elem = (PdfStructElem)taggedPdf.GetStructTreeRoot().GetKids()[0].GetKids()[0];
elem.RemoveKid(0);
taggedPdf.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff"
));
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.STRUCT_PARENT_INDEX_MISSED_AND_RECREATED, Count = 4)]
public virtual void AllObjRefDontHaveStructParentTest() {
Expand Down
15 changes: 15 additions & 0 deletions itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfCopyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,21 @@ public virtual void CopyPagesLinkAnnotationTest() {
));
}

[NUnit.Framework.Test]
public virtual void ObjRefAsStreamCopyTest() {
String pdf = sourceFolder + "objRefAsStream.pdf";
String outPdf = destinationFolder + "objRefAsStreamCopy.pdf";
String cmpPdf = sourceFolder + "cmp_objRefAsStreamCopy.pdf";
PdfDocument pdfFile = new PdfDocument(new PdfReader(pdf));
PdfDocument copiedFile = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf));
copiedFile.SetTagged();
pdfFile.CopyPagesTo(1, 1, copiedFile);
pdfFile.Close();
copiedFile.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff"
));
}

[NUnit.Framework.Test]
public virtual void CopyDocWithFullDDictionary() {
String outFileName = destinationFolder + "copyDocWithDDictionary.pdf";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using iText.Kernel.Pdf;
using iText.Test;

namespace iText.Kernel.Pdf.Tagging {
[NUnit.Framework.Category("UnitTest")]
public class PdfObjRefUnitTest : ExtendedITextTest {
[NUnit.Framework.Test]
public virtual void RefObjAsStreamTest() {
PdfDictionary @ref = new PdfStream();
@ref.Put(PdfName.Name, new PdfString("reference"));
PdfDictionary obj = new PdfDictionary();
obj.Put(PdfName.Obj, @ref);
PdfObjRef objRef = new PdfObjRef(obj, new PdfStructElem(new PdfDictionary()));
NUnit.Framework.Assert.IsTrue(objRef.GetReferencedObject() is PdfStream);
NUnit.Framework.Assert.IsTrue(objRef.GetReferencedObject().ContainsKey(PdfName.Name));
}

[NUnit.Framework.Test]
public virtual void RefObjAsInvalidTypeTest() {
PdfDictionary obj = new PdfDictionary();
obj.Put(PdfName.Obj, new PdfString("incorrect type"));
PdfObjRef objRef = new PdfObjRef(obj, new PdfStructElem(new PdfDictionary()));
NUnit.Framework.Assert.IsNull(objRef.GetReferencedObject());
}
}
}
Binary file not shown.
Binary file not shown.
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 @@ -463,6 +463,7 @@ public virtual void ThreeColumnsWithSquareCellAndCellWithExplicitHeightTest() {
templateColumns.Add(GridValue.CreateUnitValue(new UnitValue(UnitValue.POINT, 100.0f)));
using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) {
GridContainer grid = new GridContainer();
grid.SetBackgroundColor(ColorConstants.GREEN);
SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1);
grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, templateColumns);
Paragraph paragraph1 = new Paragraph("One");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ You should have received a copy of the GNU Affero General Public License
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;
using iText.Layout.Logs;
using iText.Layout.Properties;
using iText.Test;
using iText.Test.Attributes;

namespace iText.Layout.Element.Gridcontainer {
[NUnit.Framework.Category("IntegrationTest")]
Expand Down Expand Up @@ -156,23 +158,38 @@ public virtual void EmptyGridContainerTest() {
, DESTINATION_FOLDER, "diff"));
}

private GridContainer CreateGridBoxWithSizedDiv() {
GridContainer gridcontainer0 = new GridContainer();
gridcontainer0.SetProperty(Property.COLUMN_GAP_BORDER, null);
gridcontainer0.SetProperty(Property.GRID_TEMPLATE_COLUMNS, JavaUtil.ArraysAsList(new UnitValue(1, 150.0f),
new UnitValue(1, 150.0f), new UnitValue(1, 150.0f)));
gridcontainer0.SetProperty(Property.COLUMN_GAP, 12.0f);
gridcontainer0.SetBackgroundColor(ColorConstants.RED);
for (int i = 0; i < 4; i++) {
Div div1 = new Div();
div1.SetBackgroundColor(ColorConstants.YELLOW);
div1.SetHeight(20);
div1.SetWidth(30);
div1.SetProperty(Property.COLUMN_GAP_BORDER, null);
div1.SetProperty(Property.COLUMN_GAP, 12.0f);
gridcontainer0.Add(div1);
}
return gridcontainer0;
// TODO DEVSIX-8340
[NUnit.Framework.Test]
public virtual void OverflowGridContainerTest() {
String fileName = DESTINATION_FOLDER + "overflowGridContainer.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fileName));
Document document = new Document(pdfDocument);
GridContainer gridcontainer0 = CreateGridBoxWithText();
gridcontainer0.SetBackgroundColor(ColorConstants.MAGENTA);
gridcontainer0.SetProperty(Property.GRID_TEMPLATE_ROWS, JavaUtil.ArraysAsList(GridValue.CreateUnitValue(new
UnitValue(1, 500.0f)), GridValue.CreateUnitValue(new UnitValue(1, 500.0f)), GridValue.CreateUnitValue(
new UnitValue(1, 500.0f))));
gridcontainer0.Add(new iText.Layout.Element.Image(ImageDataFactory.Create(SOURCE_FOLDER + "rock_texture.jpg"
)).SetHeight(150));
document.Add(gridcontainer0);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, SOURCE_FOLDER + "cmp_overflowGridContainer.pdf"
, DESTINATION_FOLDER, "diff"));
}

[NUnit.Framework.Test]
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, LogLevel = LogLevelConstants.WARN)]
public virtual void NothingResultTest() {
String fileName = DESTINATION_FOLDER + "nothingResult.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fileName));
Document document = new Document(pdfDocument);
GridContainer gridcontainer = new GridContainer();
gridcontainer.Add(new iText.Layout.Element.Image(ImageDataFactory.Create(SOURCE_FOLDER + "rock_texture.jpg"
)).SetHeight(1200));
document.Add(gridcontainer);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, SOURCE_FOLDER + "cmp_nothingResult.pdf"
, DESTINATION_FOLDER, "diff"));
}

private GridContainer CreateGridBoxWithText() {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 12a952c

Please sign in to comment.