Skip to content

Commit 64daec8

Browse files
Dmitry RadchukiText-CI
authored andcommitted
Add negative indexes support in grid layout
DEVSIX-8423 Autoported commit. Original commit hash: [7a057c9d6]
1 parent 7b647d2 commit 64daec8

File tree

14 files changed

+383
-306
lines changed

14 files changed

+383
-306
lines changed

itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,51 @@ public virtual void BasicThreeColumnsTest() {
6767
));
6868
}
6969

70+
[NUnit.Framework.Test]
71+
public virtual void BasicTwoColumnsTest() {
72+
String filename = DESTINATION_FOLDER + "basicTwoColumnsTest.pdf";
73+
String cmpName = SOURCE_FOLDER + "cmp_basicTwoColumnsTest.pdf";
74+
IList<TemplateValue> templateColumns = new List<TemplateValue>();
75+
templateColumns.Add(new PointValue(150.0f));
76+
templateColumns.Add(new PointValue(150.0f));
77+
SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1);
78+
using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) {
79+
GridContainer grid = new GridContainer();
80+
grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, templateColumns);
81+
grid.Add(new Paragraph("One").SetBorder(border));
82+
grid.Add(new Paragraph("Two").SetBorder(border));
83+
Paragraph paragraph3 = new Paragraph("One").SetBorder(border);
84+
paragraph3.SetProperty(Property.GRID_COLUMN_SPAN, 2);
85+
grid.Add(paragraph3);
86+
document.Add(grid);
87+
}
88+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_"
89+
));
90+
}
91+
92+
[NUnit.Framework.Test]
93+
public virtual void BasicTwoRowsTest() {
94+
String filename = DESTINATION_FOLDER + "basicTwoRowsTest.pdf";
95+
String cmpName = SOURCE_FOLDER + "cmp_basicTwoRowsTest.pdf";
96+
IList<TemplateValue> templateRows = new List<TemplateValue>();
97+
templateRows.Add(new PointValue(150.0f));
98+
templateRows.Add(new PointValue(150.0f));
99+
SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1);
100+
using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) {
101+
GridContainer grid = new GridContainer();
102+
grid.SetProperty(Property.GRID_TEMPLATE_ROWS, templateRows);
103+
grid.SetProperty(Property.GRID_FLOW, GridFlow.COLUMN);
104+
grid.Add(new Paragraph("One").SetBorder(border));
105+
grid.Add(new Paragraph("Two").SetBorder(border));
106+
Paragraph paragraph3 = new Paragraph("One").SetBorder(border);
107+
paragraph3.SetProperty(Property.GRID_ROW_SPAN, 2);
108+
grid.Add(paragraph3);
109+
document.Add(grid);
110+
}
111+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_"
112+
));
113+
}
114+
70115
[NUnit.Framework.Test]
71116
public virtual void BasicAutoColumnsTest() {
72117
String filename = DESTINATION_FOLDER + "basicAutoColumnsTest.pdf";
@@ -131,6 +176,66 @@ public virtual void BasicThreeColumnsWithCustomColumnIndexesTest() {
131176
));
132177
}
133178

179+
[NUnit.Framework.Test]
180+
public virtual void BasicThreeColumnsOutOfBoundsWithNoCellsTest() {
181+
String filename = DESTINATION_FOLDER + "basicThreeColumnsOutOfBoundsWithNoCellsTest.pdf";
182+
String cmpName = SOURCE_FOLDER + "cmp_basicThreeColumnsOutOfBoundsWithNoCellsTest.pdf";
183+
IList<TemplateValue> templateColumns = new List<TemplateValue>();
184+
templateColumns.Add(new PointValue(100.0f));
185+
templateColumns.Add(new PointValue(100.0f));
186+
templateColumns.Add(new PointValue(100.0f));
187+
SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1);
188+
using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) {
189+
GridContainer grid = new GridContainer();
190+
grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, templateColumns);
191+
Paragraph paragraph1 = new Paragraph("One").SetBorder(border);
192+
paragraph1.SetProperty(Property.GRID_COLUMN_START, -2);
193+
paragraph1.SetProperty(Property.GRID_COLUMN_END, -1);
194+
grid.Add(paragraph1);
195+
grid.Add(new Paragraph("Two").SetBorder(border));
196+
Paragraph paragraph3 = new Paragraph("Three").SetBorder(border);
197+
paragraph3.SetProperty(Property.GRID_COLUMN_START, -4);
198+
paragraph3.SetProperty(Property.GRID_COLUMN_END, 3);
199+
grid.Add(paragraph3);
200+
grid.Add(new Paragraph("Four").SetBorder(border));
201+
document.Add(grid);
202+
}
203+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_"
204+
));
205+
}
206+
207+
[NUnit.Framework.Test]
208+
public virtual void BasicThreeColumnsWithNegativeCustomColumnIndexesTest() {
209+
String filename = DESTINATION_FOLDER + "basicThreeColumnsWithNegativeCustomColumnIndexesTest.pdf";
210+
String cmpName = SOURCE_FOLDER + "cmp_basicThreeColumnsWithNegativeCustomColumnIndexesTest.pdf";
211+
IList<TemplateValue> templateColumns = new List<TemplateValue>();
212+
templateColumns.Add(new PointValue(100.0f));
213+
templateColumns.Add(new PointValue(100.0f));
214+
templateColumns.Add(new PointValue(100.0f));
215+
SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1);
216+
using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) {
217+
GridContainer grid = new GridContainer();
218+
grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, templateColumns);
219+
Paragraph paragraph1 = new Paragraph("One").SetBorder(border);
220+
paragraph1.SetProperty(Property.GRID_COLUMN_START, -2);
221+
paragraph1.SetProperty(Property.GRID_COLUMN_END, -1);
222+
grid.Add(paragraph1);
223+
grid.Add(new Paragraph("Two").SetBorder(border));
224+
Paragraph paragraph3 = new Paragraph("Three").SetBorder(border);
225+
paragraph3.SetProperty(Property.GRID_COLUMN_START, -7);
226+
paragraph3.SetProperty(Property.GRID_COLUMN_END, 3);
227+
grid.Add(paragraph3);
228+
grid.Add(new Paragraph("Four").SetBorder(border));
229+
grid.Add(new Paragraph("Five").SetBorder(border));
230+
grid.Add(new Paragraph("Six").SetBorder(border));
231+
grid.Add(new Paragraph("Seven").SetBorder(border));
232+
grid.Add(new Paragraph("Eight").SetBorder(border));
233+
document.Add(grid);
234+
}
235+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_"
236+
));
237+
}
238+
134239
[NUnit.Framework.Test]
135240
public virtual void ThreeColumnsWithAdjacentWideCellsTest() {
136241
String filename = DESTINATION_FOLDER + "threeColumnsWithAdjacentWideCellsTest.pdf";

itext.tests/itext.layout.tests/itext/layout/renderer/GridCellUnitTest.cs

Lines changed: 0 additions & 106 deletions
This file was deleted.

itext.tests/itext.layout.tests/itext/layout/renderer/GridUnitTest.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2020
You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
23-
using System;
2423
using iText.Commons.Utils;
2524
using iText.Layout.Element;
2625
using iText.Layout.Properties;
@@ -41,38 +40,6 @@ public virtual void GetUniqueCellsTest() {
4140
NUnit.Framework.Assert.AreEqual(4, grid.GetUniqueGridCells(Grid.GridOrder.ROW).Count);
4241
}
4342

44-
[NUnit.Framework.Test]
45-
public virtual void GetUniqueCellsInColumnAndRowTest() {
46-
IRenderer twoRenderer = new TextRenderer(new Text("Two"));
47-
twoRenderer.SetProperty(Property.GRID_ROW_START, 2);
48-
twoRenderer.SetProperty(Property.GRID_ROW_END, 4);
49-
iText.Layout.Renderer.Grid grid = Grid.Builder.ForItems(JavaUtil.ArraysAsList(new TextRenderer(new Text("One"
50-
)), twoRenderer, new TextRenderer(new Text("Three")), new TextRenderer(new Text("Four")))).Columns(3).
51-
Rows(3).Flow(GridFlow.ROW).Build();
52-
NUnit.Framework.Assert.AreEqual(1, grid.GetUniqueCellsInTrack(Grid.GridOrder.COLUMN, 1).Count);
53-
NUnit.Framework.Assert.AreEqual(3, grid.GetUniqueCellsInTrack(Grid.GridOrder.ROW, 0).Count);
54-
}
55-
56-
[NUnit.Framework.Test]
57-
public virtual void InvalidColumnForGetColCellsTest() {
58-
iText.Layout.Renderer.Grid grid = new iText.Layout.Renderer.Grid(3, 3);
59-
NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => grid.GetUniqueCellsInTrack(Grid.GridOrder
60-
.COLUMN, 4));
61-
NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => grid.GetUniqueCellsInTrack(Grid.GridOrder
62-
.COLUMN, -1));
63-
NUnit.Framework.Assert.DoesNotThrow(() => grid.GetUniqueCellsInTrack(Grid.GridOrder.COLUMN, 2));
64-
}
65-
66-
[NUnit.Framework.Test]
67-
public virtual void InvalidRowForGetRowCellsTest() {
68-
iText.Layout.Renderer.Grid grid = new iText.Layout.Renderer.Grid(3, 3);
69-
NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => grid.GetUniqueCellsInTrack(Grid.GridOrder
70-
.ROW, 4));
71-
NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => grid.GetUniqueCellsInTrack(Grid.GridOrder
72-
.ROW, -1));
73-
NUnit.Framework.Assert.DoesNotThrow(() => grid.GetUniqueCellsInTrack(Grid.GridOrder.ROW, 2));
74-
}
75-
7643
[NUnit.Framework.Test]
7744
public virtual void SparsePackingTest() {
7845
IRenderer cell1 = new TextRenderer(new Text("One"));
Binary file not shown.

itext/itext.layout/itext/layout/renderer/AbstractRenderer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,7 @@ private void UpdateMinHeightForAbsolutelyPositionedRenderer(IRenderer renderer,
26902690
resolvedMinHeight = Math.Min(resolvedMinHeight, currentMaxHeight.GetValue());
26912691
}
26922692
renderer.SetProperty(Property.MIN_HEIGHT, UnitValue.CreatePointValue((float)resolvedMinHeight));
2693+
renderer.SetProperty(Property.HEIGHT, UnitValue.CreatePointValue((float)resolvedMinHeight));
26932694
}
26942695
}
26952696

0 commit comments

Comments
 (0)