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 19, 2024
2 parents c180a64 + 70802d5 commit 271cb32
Show file tree
Hide file tree
Showing 29 changed files with 2,145 additions and 2 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
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.Layout.Element;
using iText.Layout.Properties;
using iText.Test;

namespace iText.Layout.Renderer {
[NUnit.Framework.Category("UnitTest")]
public class GridCellUnitTest : ExtendedITextTest {
[NUnit.Framework.Test]
public virtual void CellWithOnlyGridRowStartTest() {
IRenderer renderer = new TextRenderer(new Text("test"));
renderer.SetProperty(Property.GRID_ROW_START, 3);
GridCell cell = new GridCell(renderer);
NUnit.Framework.Assert.AreEqual(2, cell.GetRowStart());
NUnit.Framework.Assert.AreEqual(3, cell.GetRowEnd());
}

[NUnit.Framework.Test]
public virtual void CellWithOnlyGridRowEndTest() {
IRenderer renderer = new TextRenderer(new Text("test"));
renderer.SetProperty(Property.GRID_ROW_END, 5);
GridCell cell = new GridCell(renderer);
NUnit.Framework.Assert.AreEqual(3, cell.GetRowStart());
NUnit.Framework.Assert.AreEqual(4, cell.GetRowEnd());
}

[NUnit.Framework.Test]
public virtual void CellWithGridRowStartAndEndTest() {
IRenderer renderer = new TextRenderer(new Text("test"));
renderer.SetProperty(Property.GRID_ROW_START, 2);
renderer.SetProperty(Property.GRID_ROW_END, 4);
GridCell cell = new GridCell(renderer);
NUnit.Framework.Assert.AreEqual(1, cell.GetRowStart());
NUnit.Framework.Assert.AreEqual(3, cell.GetRowEnd());
}

[NUnit.Framework.Test]
public virtual void CellWithOnlyGridColumnStartTest() {
IRenderer renderer = new TextRenderer(new Text("test"));
renderer.SetProperty(Property.GRID_COLUMN_START, 3);
GridCell cell = new GridCell(renderer);
NUnit.Framework.Assert.AreEqual(2, cell.GetColumnStart());
NUnit.Framework.Assert.AreEqual(3, cell.GetColumnEnd());
}

[NUnit.Framework.Test]
public virtual void CellWithOnlyGridColumnEndTest() {
IRenderer renderer = new TextRenderer(new Text("test"));
renderer.SetProperty(Property.GRID_COLUMN_END, 8);
GridCell cell = new GridCell(renderer);
NUnit.Framework.Assert.AreEqual(6, cell.GetColumnStart());
NUnit.Framework.Assert.AreEqual(7, cell.GetColumnEnd());
}

[NUnit.Framework.Test]
public virtual void CellWithGridColumnStartAndEndTest() {
IRenderer renderer = new TextRenderer(new Text("test"));
renderer.SetProperty(Property.GRID_COLUMN_START, 4);
renderer.SetProperty(Property.GRID_COLUMN_END, 7);
GridCell cell = new GridCell(renderer);
NUnit.Framework.Assert.AreEqual(3, cell.GetColumnStart());
NUnit.Framework.Assert.AreEqual(6, cell.GetColumnEnd());
}

[NUnit.Framework.Test]
public virtual void CellWithReversedColumnStartAndEndTest() {
IRenderer renderer = new TextRenderer(new Text("test"));
renderer.SetProperty(Property.GRID_COLUMN_START, 7);
renderer.SetProperty(Property.GRID_COLUMN_END, 4);
GridCell cell = new GridCell(renderer);
NUnit.Framework.Assert.AreEqual(3, cell.GetColumnStart());
NUnit.Framework.Assert.AreEqual(6, cell.GetColumnEnd());
}

[NUnit.Framework.Test]
public virtual void CellWithReversedRowStartAndEndTest() {
IRenderer renderer = new TextRenderer(new Text("test"));
renderer.SetProperty(Property.GRID_ROW_START, 4);
renderer.SetProperty(Property.GRID_ROW_END, 2);
GridCell cell = new GridCell(renderer);
NUnit.Framework.Assert.AreEqual(1, cell.GetRowStart());
NUnit.Framework.Assert.AreEqual(3, cell.GetRowEnd());
}
}
}
165 changes: 165 additions & 0 deletions itext.tests/itext.layout.tests/itext/layout/renderer/GridUnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
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.Geom;
using iText.Layout.Element;
using iText.Layout.Properties;
using iText.Test;

namespace iText.Layout.Renderer {
[NUnit.Framework.Category("UnitTest")]
public class GridUnitTest : ExtendedITextTest {
[NUnit.Framework.Test]
public virtual void GetClosestTopNeighborTest() {
Grid grid = new Grid(3, 3, false);
grid.AddCell(new GridCell(new TextRenderer(new Text("One"))));
grid.AddCell(new GridCell(new TextRenderer(new Text("Three"))));
IRenderer value = new TextRenderer(new Text("Two"));
value.SetProperty(Property.GRID_COLUMN_START, 2);
value.SetProperty(Property.GRID_ROW_START, 2);
GridCell cell = new GridCell(value);
grid.AddCell(cell);
NUnit.Framework.Assert.AreEqual(grid.GetRows()[0][0], grid.GetClosestTopNeighbor(cell));
}

[NUnit.Framework.Test]
public virtual void GetClosestLeftNeighborTest() {
Grid grid = new Grid(3, 3, false);
grid.AddCell(new GridCell(new TextRenderer(new Text("One"))));
IRenderer value = new TextRenderer(new Text("Two"));
value.SetProperty(Property.GRID_COLUMN_START, 2);
value.SetProperty(Property.GRID_ROW_START, 2);
GridCell cell = new GridCell(value);
grid.AddCell(cell);
NUnit.Framework.Assert.AreEqual(grid.GetRows()[0][0], grid.GetClosestLeftNeighbor(cell));
}

[NUnit.Framework.Test]
public virtual void GetUniqueCellsTest() {
Grid grid = new Grid(3, 3, false);
grid.AddCell(new GridCell(new TextRenderer(new Text("One"))));
IRenderer twoRenderer = new TextRenderer(new Text("Two"));
twoRenderer.SetProperty(Property.GRID_COLUMN_START, 2);
twoRenderer.SetProperty(Property.GRID_COLUMN_END, 4);
GridCell cell = new GridCell(twoRenderer);
grid.AddCell(cell);
grid.AddCell(new GridCell(new TextRenderer(new Text("Three"))));
grid.AddCell(new GridCell(new TextRenderer(new Text("Four"))));
NUnit.Framework.Assert.AreEqual(4, grid.GetUniqueGridCells(Grid.ROW_ORDER).Count);
}

[NUnit.Framework.Test]
public virtual void IncreaseRowHeightTest() {
Grid grid = new Grid(3, 3, false);
GridCell cell1 = new GridCell(new TextRenderer(new Text("One")));
cell1.SetLayoutArea(new Rectangle(50.0f, 50.0f));
GridCell cell2 = new GridCell(new TextRenderer(new Text("Two")));
cell2.SetLayoutArea(new Rectangle(50.0f, 50.0f));
GridCell cell3 = new GridCell(new TextRenderer(new Text("Three")));
cell3.SetLayoutArea(new Rectangle(50.0f, 50.0f));
grid.AddCell(cell1);
grid.AddCell(cell2);
grid.AddCell(cell3);
grid.AlignRow(0, 100.0f);
NUnit.Framework.Assert.AreEqual(100.0f, grid.GetRows()[0][0].GetLayoutArea().GetHeight(), 0.00001f);
NUnit.Framework.Assert.AreEqual(100.0f, grid.GetRows()[0][1].GetLayoutArea().GetHeight(), 0.00001f);
NUnit.Framework.Assert.AreEqual(100.0f, grid.GetRows()[0][2].GetLayoutArea().GetHeight(), 0.00001f);
}

[NUnit.Framework.Test]
public virtual void IncreaseColumnWidthTest() {
Grid grid = new Grid(3, 3, false);
GridCell cell1 = new GridCell(new TextRenderer(new Text("One")));
cell1.SetLayoutArea(new Rectangle(100.0f, 50.0f));
GridCell cell2 = new GridCell(new TextRenderer(new Text("Two")));
cell2.SetLayoutArea(new Rectangle(30.0f, 50.0f));
GridCell cell3 = new GridCell(new TextRenderer(new Text("Three")));
cell3.SetLayoutArea(new Rectangle(50.0f, 50.0f));
GridCell cell4 = new GridCell(new TextRenderer(new Text("Three")));
cell4.SetLayoutArea(new Rectangle(100.0f, 50.0f));
GridCell cell5 = new GridCell(new TextRenderer(new Text("Three")));
cell5.SetLayoutArea(new Rectangle(50.0f, 50.0f));
grid.AddCell(cell1);
grid.AddCell(cell2);
grid.AddCell(cell3);
grid.AddCell(cell4);
grid.AddCell(cell5);
grid.AlignColumn(1, 150.0f);
NUnit.Framework.Assert.AreEqual(100.0f, grid.GetRows()[0][0].GetLayoutArea().GetWidth(), 0.00001f);
NUnit.Framework.Assert.AreEqual(150.0f, grid.GetRows()[0][1].GetLayoutArea().GetWidth(), 0.00001f);
NUnit.Framework.Assert.AreEqual(150.0f, grid.GetRows()[1][1].GetLayoutArea().GetWidth(), 0.00001f);
NUnit.Framework.Assert.AreEqual(50.0f, grid.GetRows()[0][2].GetLayoutArea().GetWidth(), 0.00001f);
}

[NUnit.Framework.Test]
public virtual void SparsePackingTest() {
Grid grid = new Grid(3, 3, false);
GridCell cell1 = new GridCell(new TextRenderer(new Text("One")));
grid.AddCell(cell1);
IRenderer renderer = new TextRenderer(new Text("Two"));
renderer.SetProperty(Property.GRID_COLUMN_START, 1);
renderer.SetProperty(Property.GRID_COLUMN_END, 6);
GridCell wideCell = new GridCell(renderer);
grid.AddCell(wideCell);
GridCell cell3 = new GridCell(new TextRenderer(new Text("Three")));
GridCell cell4 = new GridCell(new TextRenderer(new Text("Four")));
GridCell cell5 = new GridCell(new TextRenderer(new Text("Five")));
GridCell cell6 = new GridCell(new TextRenderer(new Text("Six")));
grid.AddCell(cell3);
grid.AddCell(cell4);
grid.AddCell(cell5);
grid.AddCell(cell6);
NUnit.Framework.Assert.AreEqual(cell1, grid.GetRows()[0][0]);
NUnit.Framework.Assert.AreEqual(wideCell, grid.GetRows()[1][0]);
NUnit.Framework.Assert.AreEqual(cell3, grid.GetRows()[2][0]);
NUnit.Framework.Assert.AreEqual(cell4, grid.GetRows()[2][1]);
NUnit.Framework.Assert.AreEqual(cell5, grid.GetRows()[2][2]);
NUnit.Framework.Assert.AreEqual(cell6, grid.GetRows()[2][3]);
}

[NUnit.Framework.Test]
public virtual void DensePackingTest() {
Grid grid = new Grid(3, 3, true);
GridCell cell1 = new GridCell(new TextRenderer(new Text("One")));
grid.AddCell(cell1);
IRenderer renderer = new TextRenderer(new Text("Two"));
renderer.SetProperty(Property.GRID_COLUMN_START, 1);
renderer.SetProperty(Property.GRID_COLUMN_END, 6);
GridCell wideCell = new GridCell(renderer);
grid.AddCell(wideCell);
GridCell cell3 = new GridCell(new TextRenderer(new Text("Three")));
GridCell cell4 = new GridCell(new TextRenderer(new Text("Four")));
GridCell cell5 = new GridCell(new TextRenderer(new Text("Five")));
GridCell cell6 = new GridCell(new TextRenderer(new Text("Six")));
grid.AddCell(cell3);
grid.AddCell(cell4);
grid.AddCell(cell5);
grid.AddCell(cell6);
NUnit.Framework.Assert.AreEqual(cell1, grid.GetRows()[0][0]);
NUnit.Framework.Assert.AreEqual(cell3, grid.GetRows()[0][1]);
NUnit.Framework.Assert.AreEqual(cell4, grid.GetRows()[0][2]);
NUnit.Framework.Assert.AreEqual(cell5, grid.GetRows()[0][3]);
NUnit.Framework.Assert.AreEqual(cell6, grid.GetRows()[0][4]);
NUnit.Framework.Assert.AreEqual(wideCell, grid.GetRows()[1][0]);
}
}
}
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
45 changes: 45 additions & 0 deletions itext/itext.layout/itext/layout/element/GridContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
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.Layout.Renderer;

namespace iText.Layout.Element {
/// <summary>
/// A
/// <see cref="GridContainer"/>
/// represents a container of the css grid object.
/// </summary>
public class GridContainer : Div {
/// <summary>
/// Creates a new
/// <see cref="GridContainer"/>
/// instance.
/// </summary>
public GridContainer()
: base() {
}

protected internal override IRenderer MakeNewRenderer() {
return new GridContainerRenderer(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public sealed class LayoutExceptionMessageConstant {

public const String INVALID_COLUMN_PROPERTIES = "Invalid column-count/column-width/column-gap properties, they're absent or have negative value";

public const String INVALID_CELL_INDEXES = "Invalid grid-column/grid-row properties, cells overlapping";

public const String INVALID_FONT_PROPERTY_VALUE = "Invalid FONT property value type.";

public const String TAGGING_HINTKEY_SHOULD_HAVE_ACCES = "TaggingHintKey should have accessibility properties";
Expand Down
18 changes: 17 additions & 1 deletion itext/itext.layout/itext/layout/properties/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ public sealed class Property {

public const int FULL = 25;

public const int GRID_COLUMN_END = 147;

public const int GRID_COLUMN_START = 148;

public const int GRID_ROW_END = 149;

public const int GRID_ROW_START = 150;

public const int GRID_TEMPLATE_COLUMNS = 145;

public const int GRID_TEMPLATE_ROWS = 146;

public const int GRID_AUTO_ROWS = 151;

public const int GRID_AUTO_COLUMNS = 152;

public const int HEIGHT = 27;

public const int HORIZONTAL_ALIGNMENT = 28;
Expand Down Expand Up @@ -382,7 +398,7 @@ public sealed class Property {
/// </remarks>
private static readonly bool[] INHERITED_PROPERTIES;

private const int MAX_INHERITED_PROPERTY_ID = 144;
private const int MAX_INHERITED_PROPERTY_ID = 152;

static Property() {
INHERITED_PROPERTIES = new bool[MAX_INHERITED_PROPERTY_ID + 1];
Expand Down
Loading

0 comments on commit 271cb32

Please sign in to comment.