Skip to content

Commit 4544a37

Browse files
ars18wrwiText-CI
authored andcommitted
Do not recalculate table's minmax width once the table has been split.
DEVSIX-3008 Autoported commit. Original commit hash: [2ec5ebc58]
1 parent 91eb32c commit 4544a37

File tree

5 files changed

+75
-16
lines changed

5 files changed

+75
-16
lines changed

itext.tests/itext.layout.tests/itext/layout/FloatTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,5 +2626,32 @@ public virtual void FloatOverflowAlongWithNewContent02() {
26262626
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
26272627
"diff_overflowNewContent02_"));
26282628
}
2629+
2630+
/// <exception cref="System.IO.IOException"/>
2631+
/// <exception cref="System.Exception"/>
2632+
[NUnit.Framework.Test]
2633+
[LogMessage(iText.IO.LogMessageConstant.TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH)]
2634+
public virtual void FloatTableTest01() {
2635+
String cmpFileName = sourceFolder + "cmp_floatTableTest01.pdf";
2636+
String outFile = destinationFolder + "floatTableTest01.pdf";
2637+
PdfWriter writer = new PdfWriter(outFile);
2638+
PdfDocument pdfDoc = new PdfDocument(writer);
2639+
Document doc = new Document(pdfDoc);
2640+
Div div = new Div();
2641+
div.SetWidth(38);
2642+
Div floatDiv = new Div();
2643+
floatDiv.SetProperty(Property.FLOAT, FloatPropertyValue.LEFT);
2644+
Table table = new Table(2);
2645+
for (int i = 0; i < 26; i++) {
2646+
table.AddCell(new Cell().Add(new Paragraph("abba a")));
2647+
table.AddCell(new Cell().Add(new Paragraph("ab ab ab")));
2648+
}
2649+
floatDiv.Add(table);
2650+
div.Add(floatDiv);
2651+
doc.Add(div);
2652+
doc.Close();
2653+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
2654+
"diff03_"));
2655+
}
26292656
}
26302657
}

itext.tests/itext.layout.tests/itext/layout/TableTest.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ source product.
4141
4242
*/
4343
using System;
44+
using System.IO;
4445
using iText.IO.Image;
4546
using iText.IO.Util;
4647
using iText.Kernel.Colors;
@@ -50,6 +51,8 @@ source product.
5051
using iText.Kernel.Utils;
5152
using iText.Layout.Borders;
5253
using iText.Layout.Element;
54+
using iText.Layout.Layout;
55+
using iText.Layout.Minmaxwidth;
5356
using iText.Layout.Properties;
5457
using iText.Layout.Renderer;
5558
using iText.Test;
@@ -2193,6 +2196,45 @@ public virtual void TableMinMaxWidthTest06() {
21932196
, testName + "_diff"));
21942197
}
21952198

2199+
[NUnit.Framework.Test]
2200+
[LogMessage(iText.IO.LogMessageConstant.TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH)]
2201+
public virtual void SplitTableMinMaxWidthTest01() {
2202+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
2203+
Document doc = new Document(pdfDoc);
2204+
Table table = new Table(2);
2205+
for (int i = 0; i < 26; i++) {
2206+
table.AddCell(new Cell().Add(new Paragraph("abba a")));
2207+
table.AddCell(new Cell().Add(new Paragraph("ab ab ab")));
2208+
}
2209+
// not enough to place even if min-width approach is used
2210+
float areaWidth = 20;
2211+
LayoutResult result = table.CreateRendererSubTree().SetParent(doc.GetRenderer()).Layout(new LayoutContext(
2212+
new LayoutArea(1, new Rectangle(areaWidth, 100))));
2213+
TableRenderer overflowRenderer = (TableRenderer)result.GetOverflowRenderer();
2214+
MinMaxWidth minMaxWidth = overflowRenderer.GetMinMaxWidth();
2215+
NUnit.Framework.Assert.AreEqual(result.GetOccupiedArea().GetBBox().GetWidth(), minMaxWidth.GetMaxWidth(),
2216+
0.0001);
2217+
NUnit.Framework.Assert.AreEqual(minMaxWidth.GetMaxWidth(), minMaxWidth.GetMinWidth(), 0.0001);
2218+
// not enough to place using max-width approach, but more than required for min-width approach
2219+
areaWidth = 70;
2220+
result = table.CreateRendererSubTree().SetParent(doc.GetRenderer()).Layout(new LayoutContext(new LayoutArea
2221+
(1, new Rectangle(areaWidth, 100))));
2222+
overflowRenderer = (TableRenderer)result.GetOverflowRenderer();
2223+
minMaxWidth = overflowRenderer.GetMinMaxWidth();
2224+
NUnit.Framework.Assert.AreEqual(result.GetOccupiedArea().GetBBox().GetWidth(), minMaxWidth.GetMaxWidth(),
2225+
0.0001);
2226+
NUnit.Framework.Assert.AreEqual(minMaxWidth.GetMaxWidth(), minMaxWidth.GetMinWidth(), 0.0001);
2227+
// enough to place using max-width approach
2228+
areaWidth = 400f;
2229+
result = table.CreateRendererSubTree().SetParent(doc.GetRenderer()).Layout(new LayoutContext(new LayoutArea
2230+
(1, new Rectangle(areaWidth, 100))));
2231+
overflowRenderer = (TableRenderer)result.GetOverflowRenderer();
2232+
minMaxWidth = overflowRenderer.GetMinMaxWidth();
2233+
NUnit.Framework.Assert.AreEqual(result.GetOccupiedArea().GetBBox().GetWidth(), minMaxWidth.GetMaxWidth(),
2234+
0.0001);
2235+
NUnit.Framework.Assert.AreEqual(minMaxWidth.GetMaxWidth(), minMaxWidth.GetMinWidth(), 0.0001);
2236+
}
2237+
21962238
/// <exception cref="System.IO.IOException"/>
21972239
/// <exception cref="System.Exception"/>
21982240
[NUnit.Framework.Test]

itext/itext.layout/itext/layout/renderer/TableRenderer.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,18 +1344,19 @@ protected internal virtual iText.Layout.Renderer.TableRenderer CreateOverflowRen
13441344
}
13451345

13461346
public override MinMaxWidth GetMinMaxWidth() {
1347-
InitializeTableLayoutBorders();
1347+
if (isOriginalNonSplitRenderer) {
1348+
InitializeTableLayoutBorders();
1349+
}
13481350
float rightMaxBorder = bordersHandler.GetRightBorderMaxWidth();
13491351
float leftMaxBorder = bordersHandler.GetLeftBorderMaxWidth();
13501352
TableWidths tableWidths = new TableWidths(this, MinMaxWidthUtils.GetInfWidth(), true, rightMaxBorder, leftMaxBorder
13511353
);
1352-
float[] columns = tableWidths.Layout();
1353-
float minWidth = tableWidths.GetMinWidth();
1354-
CleanTableLayoutBorders();
13551354
float maxColTotalWidth = 0;
1355+
float[] columns = isOriginalNonSplitRenderer ? tableWidths.Layout() : countedColumnWidth;
13561356
foreach (float column in columns) {
13571357
maxColTotalWidth += column;
13581358
}
1359+
float minWidth = isOriginalNonSplitRenderer ? tableWidths.GetMinWidth() : maxColTotalWidth;
13591360
UnitValue marginRightUV = this.GetPropertyAsUnitValue(Property.MARGIN_RIGHT);
13601361
if (!marginRightUV.IsPointValue()) {
13611362
ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.TableRenderer));
@@ -1398,17 +1399,6 @@ private void InitializeTableLayoutBorders() {
13981399
CorrectRowRange();
13991400
}
14001401

1401-
private void CleanTableLayoutBorders() {
1402-
footerRenderer = null;
1403-
headerRenderer = null;
1404-
// we may have deleted empty rows and now need to update table's rowrange
1405-
this.rowRange = new Table.RowRange(rowRange.GetStartRow(), bordersHandler.GetFinishRow());
1406-
//TODO do we need it?
1407-
// delete set properties
1408-
DeleteOwnProperty(Property.BORDER_BOTTOM);
1409-
DeleteOwnProperty(Property.BORDER_TOP);
1410-
}
1411-
14121402
private void CorrectRowRange() {
14131403
if (rows.Count < rowRange.GetFinishRow() - rowRange.GetStartRow() + 1) {
14141404
rowRange = new Table.RowRange(rowRange.GetStartRow(), rowRange.GetStartRow() + rows.Count - 1);

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8f794faaa53e0a9947e9789e4a7769c56651238c
1+
2ec5ebc58553d147be174a03bf5305f53acc9659

0 commit comments

Comments
 (0)