Skip to content

Commit 17a37ee

Browse files
ars18wrwiText-CI
authored andcommitted
Preserve cell's percent width between relayouts
DEVSIX-5158 Autoported commit. Original commit hash: [504a9a8cf]
1 parent e23fed1 commit 17a37ee

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,26 @@ public virtual void SimpleTableTest23() {
631631
, testName + "_diff"));
632632
}
633633

634+
[NUnit.Framework.Test]
635+
public virtual void WidthInPercentShouldBeResetAfterOverflow() {
636+
String testName = "widthInPercentShouldBeResetAfterOverflow.pdf";
637+
String outFileName = destinationFolder + testName;
638+
String cmpFileName = sourceFolder + "cmp_" + testName;
639+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
640+
Document doc = new Document(pdfDoc);
641+
doc.Add(new Div().SetHeight(730).SetWidth(523));
642+
Table table = new Table(2).UseAllAvailableWidth().SetFixedLayout().AddCell(new Cell().Add(new Paragraph("Hello"
643+
)).SetWidth(UnitValue.CreatePercentValue(20))).AddCell(new Cell().Add(new Paragraph("World")).SetWidth
644+
(UnitValue.CreatePercentValue(80)));
645+
// will be added on the first page
646+
doc.Add(table);
647+
// will be added on the second page
648+
doc.Add(table);
649+
doc.Close();
650+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
651+
, testName + "_diff"));
652+
}
653+
634654
[NUnit.Framework.Test]
635655
public virtual void BigRowspanTest01() {
636656
String testName = "bigRowspanTest01.pdf";

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
545545
}
546546
LayoutResult cellResult = cell.SetParent(this).Layout(new LayoutContext(cellArea, null, childFloatRendererAreas
547547
, wasHeightClipped || wasParentsHeightClipped));
548+
if (cellWidthProperty != null && cellWidthProperty.IsPercentValue()) {
549+
cell.SetProperty(Property.WIDTH, cellWidthProperty);
550+
if (null != cellResult.GetOverflowRenderer()) {
551+
cellResult.GetOverflowRenderer().SetProperty(Property.WIDTH, cellWidthProperty);
552+
}
553+
}
548554
cell.SetProperty(Property.VERTICAL_ALIGNMENT, verticalAlignment);
549555
// width of BlockRenderer depends on child areas, while in cell case it is hardly define.
550556
if (cellResult.GetStatus() != LayoutResult.NOTHING) {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e5a5dfd2662b8205bfb22eed87f6720ea319d1a9
1+
504a9a8cf451797fa1aa8ff775cf7ecb09012c41

0 commit comments

Comments
 (0)