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 27, 2024
2 parents e3daf68 + d9834cd commit 3f8cd18
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/*
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 System;
using iText.Commons.Utils;
using iText.IO.Image;
using iText.Kernel.Colors;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Xobject;
using iText.Kernel.Utils;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;
using iText.Layout.Properties;
using iText.Test;

namespace iText.Layout.Element.Gridcontainer {
[NUnit.Framework.Category("IntegrationTest")]
public class GridContainerLayoutTest : ExtendedITextTest {
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/itext/layout/GridContainerTest/";

public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/layout/GridContainerTest/";

[NUnit.Framework.SetUp]
public virtual void Setup() {
CreateDestinationFolder(DESTINATION_FOLDER);
}

[NUnit.Framework.Test]
public virtual void SimpleBorderBoxSizingTestTest() {
String fileName = DESTINATION_FOLDER + "border.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fileName));
Document document = new Document(pdfDocument);
GridContainer gridcontainer0 = CreateGridBoxWithText();
document.Add(new Paragraph("BOX_SIZING: BORDER_BOX"));
gridcontainer0.SetProperty(Property.BOX_SIZING, BoxSizingPropertyValue.BORDER_BOX);
gridcontainer0.SetBorder(new SolidBorder(ColorConstants.BLACK, 20));
document.Add(gridcontainer0);
document.Add(new Paragraph("BOX_SIZING: CONTENT_BOX"));
GridContainer gridcontainer1 = CreateGridBoxWithText();
gridcontainer1.SetProperty(Property.BOX_SIZING, BoxSizingPropertyValue.CONTENT_BOX);
gridcontainer1.SetBorder(new SolidBorder(ColorConstants.BLACK, 20));
document.Add(gridcontainer1);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, SOURCE_FOLDER + "cmp_border.pdf"
, DESTINATION_FOLDER, "diff"));
}

[NUnit.Framework.Test]
public virtual void SimpleMarginTest() {
String fileName = DESTINATION_FOLDER + "margin.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fileName));
Document document = new Document(pdfDocument);
document.Add(new Paragraph("Margin "));
GridContainer gridcontainer0 = CreateGridBoxWithText();
gridcontainer0.SetMarginTop(50);
gridcontainer0.SetMarginBottom(100);
gridcontainer0.SetMarginLeft(10);
gridcontainer0.SetMarginRight(10);
document.Add(gridcontainer0);
document.Add(new Paragraph("Margin "));
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, SOURCE_FOLDER + "cmp_margin.pdf"
, DESTINATION_FOLDER, "diff"));
}

[NUnit.Framework.Test]
public virtual void SimplePaddingTest() {
String fileName = DESTINATION_FOLDER + "padding.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fileName));
Document document = new Document(pdfDocument);
document.Add(new Paragraph("Padding "));
GridContainer gridcontainer0 = CreateGridBoxWithText();
gridcontainer0.SetPaddingTop(50);
gridcontainer0.SetPaddingBottom(100);
gridcontainer0.SetPaddingLeft(10);
gridcontainer0.SetPaddingRight(10);
document.Add(gridcontainer0);
document.Add(new Paragraph("Padding "));
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, SOURCE_FOLDER + "cmp_padding.pdf"
, DESTINATION_FOLDER, "diff"));
}

[NUnit.Framework.Test]
public virtual void SimpleBackGroundTest() {
String fileName = DESTINATION_FOLDER + "background.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fileName));
Document document = new Document(pdfDocument);
document.Add(new Paragraph("Background "));
GridContainer gridcontainer0 = CreateGridBoxWithText();
gridcontainer0.SetBackgroundColor(ColorConstants.RED);
document.Add(gridcontainer0);
document.Add(new Paragraph("Background "));
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, SOURCE_FOLDER + "cmp_background.pdf"
, DESTINATION_FOLDER, "diff"));
}

[NUnit.Framework.Test]
public virtual void BackgroundWithImageTest() {
String fileName = DESTINATION_FOLDER + "backgroundWithImage.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fileName));
Document document = new Document(pdfDocument);
document.Add(new Paragraph("Background with image "));
GridContainer gridcontainer0 = CreateGridBoxWithText();
PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.Create(SOURCE_FOLDER + "rock_texture.jpg"))
.Put(PdfName.BBox, new PdfArray(new Rectangle(70, -15, 500, 750)));
BackgroundImage image = new BackgroundImage.Builder().SetImage(xObject).SetBackgroundRepeat(new BackgroundRepeat
(BackgroundRepeat.BackgroundRepeatValue.REPEAT)).Build();
gridcontainer0.SetBackgroundImage(image);
document.Add(gridcontainer0);
document.Add(new Paragraph("Background with image "));
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, SOURCE_FOLDER + "cmp_backgroundWithImage.pdf"
, DESTINATION_FOLDER, "diff"));
}

[NUnit.Framework.Test]
public virtual void EmptyGridContainerTest() {
String fileName = DESTINATION_FOLDER + "emptyGridContainer.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fileName));
Document document = new Document(pdfDocument);
GridContainer gridcontainer0 = new GridContainer();
gridcontainer0.SetProperty(Property.COLUMN_GAP_BORDER, null);
gridcontainer0.SetBackgroundColor(ColorConstants.RED);
gridcontainer0.SetProperty(Property.GRID_TEMPLATE_COLUMNS, JavaUtil.ArraysAsList(GridValue.CreateUnitValue
(new UnitValue(1, 150.0f)), GridValue.CreateUnitValue(new UnitValue(1, 150.0f)), GridValue.CreateUnitValue
(new UnitValue(1, 150.0f))));
gridcontainer0.SetProperty(Property.COLUMN_GAP, 12.0f);
document.Add(gridcontainer0);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, SOURCE_FOLDER + "cmp_emptyGridContainer.pdf"
, 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;
}

private GridContainer CreateGridBoxWithText() {
GridContainer gridcontainer0 = new GridContainer();
gridcontainer0.SetProperty(Property.COLUMN_GAP_BORDER, null);
gridcontainer0.SetProperty(Property.GRID_TEMPLATE_COLUMNS, JavaUtil.ArraysAsList(GridValue.CreateUnitValue
(new UnitValue(1, 150.0f)), GridValue.CreateUnitValue(new UnitValue(1, 150.0f)), GridValue.CreateUnitValue
(new UnitValue(1, 150.0f))));
gridcontainer0.SetProperty(Property.COLUMN_GAP, 12.0f);
Div div1 = new Div();
div1.SetBackgroundColor(ColorConstants.YELLOW);
div1.SetProperty(Property.COLUMN_GAP_BORDER, null);
div1.SetProperty(Property.COLUMN_GAP, 12.0f);
Paragraph paragraph2 = new Paragraph();
Text text3 = new Text("One");
paragraph2.Add(text3);
div1.Add(paragraph2);
gridcontainer0.Add(div1);
Div div4 = new Div();
div4.SetProperty(Property.COLUMN_GAP_BORDER, null);
div4.SetProperty(Property.COLUMN_GAP, 12.0f);
Paragraph paragraph5 = new Paragraph();
Text text6 = new Text("Two");
paragraph5.Add(text6);
div4.Add(paragraph5);
gridcontainer0.Add(div4);
Div div7 = new Div();
div7.SetBackgroundColor(ColorConstants.GREEN);
div7.SetProperty(Property.COLUMN_GAP_BORDER, null);
div7.SetProperty(Property.COLUMN_GAP, 12.0f);
Paragraph paragraph8 = new Paragraph();
Text text9 = new Text("Three");
paragraph8.Add(text9);
div7.Add(paragraph8);
gridcontainer0.Add(div7);
Div div10 = new Div();
div10.SetBackgroundColor(ColorConstants.CYAN);
div10.SetProperty(Property.COLUMN_GAP_BORDER, null);
div10.SetProperty(Property.COLUMN_GAP, 12.0f);
Paragraph paragraph11 = new Paragraph();
Text text12 = new Text("Four");
paragraph11.Add(text12);
div10.Add(paragraph11);
gridcontainer0.Add(div10);
Div div13 = new Div();
div13.SetProperty(Property.COLUMN_GAP_BORDER, null);
div13.SetProperty(Property.COLUMN_GAP, 12.0f);
Paragraph paragraph14 = new Paragraph();
Text text15 = new Text("Five");
paragraph14.Add(text15);
div13.Add(paragraph14);
gridcontainer0.Add(div13);
return gridcontainer0;
}
}
}
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 28 additions & 22 deletions itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,39 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
GridContainerRenderer.GridLayoutResult layoutResult = LayoutGrid(layoutContext, actualBBox, grid);
//TODO DEVSIX-8329 improve nothing processing, consider checking for cause of nothing here?
//TODO DEVSIX-8329 improve forced placement logic
if (layoutResult.GetSplitRenderers().IsEmpty()) {
if (true.Equals(this.GetProperty<bool?>(Property.FORCED_PLACEMENT))) {
this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, grid, true);
return new LayoutResult(LayoutResult.FULL, this.occupiedArea, this, null);
}
IRenderer cause = this;
if (!layoutResult.GetCauseOfNothing().IsEmpty()) {
cause = layoutResult.GetCauseOfNothing()[0];
}
return new LayoutResult(LayoutResult.NOTHING, null, null, this, cause);
if (layoutResult.GetOverflowRenderers().IsEmpty() && layoutResult.GetSplitRenderers().IsEmpty()) {
this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, grid, true);
return new LayoutResult(LayoutResult.FULL, this.occupiedArea, null, null);
}
else {
if (layoutResult.GetOverflowRenderers().IsEmpty()) {
ContinuousContainer continuousContainer = this.GetProperty<ContinuousContainer>(Property.TREAT_AS_CONTINUOUS_CONTAINER_RESULT
);
if (continuousContainer != null) {
continuousContainer.ReApplyProperties(this);
if (layoutResult.GetSplitRenderers().IsEmpty()) {
if (true.Equals(this.GetProperty<bool?>(Property.FORCED_PLACEMENT))) {
this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, grid, true);
return new LayoutResult(LayoutResult.FULL, this.occupiedArea, this, null);
}
IRenderer cause = this;
if (!layoutResult.GetCauseOfNothing().IsEmpty()) {
cause = layoutResult.GetCauseOfNothing()[0];
}
this.childRenderers.Clear();
this.AddAllChildRenderers(layoutResult.GetSplitRenderers());
this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, grid, true);
return new LayoutResult(LayoutResult.FULL, this.occupiedArea, this, null);
return new LayoutResult(LayoutResult.NOTHING, null, null, this, cause);
}
else {
this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, grid, false);
return new LayoutResult(LayoutResult.PARTIAL, this.occupiedArea, CreateSplitRenderer(layoutResult.GetSplitRenderers
()), CreateOverflowRenderer(layoutResult.GetOverflowRenderers()));
if (layoutResult.GetOverflowRenderers().IsEmpty()) {
ContinuousContainer continuousContainer = this.GetProperty<ContinuousContainer>(Property.TREAT_AS_CONTINUOUS_CONTAINER_RESULT
);
if (continuousContainer != null) {
continuousContainer.ReApplyProperties(this);
}
this.childRenderers.Clear();
this.AddAllChildRenderers(layoutResult.GetSplitRenderers());
this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, grid, true);
return new LayoutResult(LayoutResult.FULL, this.occupiedArea, this, null);
}
else {
this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, grid, false);
return new LayoutResult(LayoutResult.PARTIAL, this.occupiedArea, CreateSplitRenderer(layoutResult.GetSplitRenderers
()), CreateOverflowRenderer(layoutResult.GetOverflowRenderers()));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
db84b32c9fb62f2ad1936298f4c50beaa0b3f0d8
570c5a12b407294f946f797e91d927b8695df1d4

0 comments on commit 3f8cd18

Please sign in to comment.