Skip to content

Commit 7e802cc

Browse files
ars18wrwiText-CI
authored andcommitted
Take epsilon into account while deciding whether a cell of a fixed height sgould be split.
Float are compared there without any epsilon value, which may cause issues because of float precision inaccuracy. DEVSIX-3848 Autoported commit. Original commit hash: [1dc93c774]
1 parent c048abe commit 7e802cc

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using iText.Kernel.Geom;
2+
using iText.Layout.Element;
3+
using iText.Layout.Layout;
4+
using iText.Layout.Properties;
5+
using iText.Test;
6+
7+
namespace iText.Layout.Renderer {
8+
public class BlockRendererTest : ExtendedITextTest {
9+
[NUnit.Framework.Test]
10+
public virtual void ApplyMinHeightForSpecificDimensionsCausingFloatPrecisionError() {
11+
float divHeight = 42.55f;
12+
Div div = new Div();
13+
div.SetHeight(UnitValue.CreatePointValue(divHeight));
14+
float occupiedHeight = 17.981995f;
15+
float leftHeight = 24.567993f;
16+
NUnit.Framework.Assert.IsTrue(occupiedHeight + leftHeight < divHeight);
17+
BlockRenderer blockRenderer = (BlockRenderer)div.CreateRendererSubTree();
18+
blockRenderer.occupiedArea = new LayoutArea(1, new Rectangle(0, 267.9681f, 0, occupiedHeight));
19+
AbstractRenderer renderer = blockRenderer.ApplyMinHeight(OverflowPropertyValue.FIT, new Rectangle(0, 243.40012f
20+
, 0, leftHeight));
21+
NUnit.Framework.Assert.IsNull(renderer);
22+
}
23+
}
24+
}

itext/itext.layout/itext/layout/renderer/BlockRenderer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,10 @@ internal virtual AbstractRenderer ApplyMinHeight(OverflowPropertyValue? overflow
769769
occupiedArea.GetBBox().SetY(blockBottom).SetHeight((float)blockMinHeight);
770770
}
771771
else {
772-
if (IsOverflowFit(overflowY) && blockBottom < layoutBox.GetBottom()) {
772+
// Because of float precision inaccuracy, iText can incorrectly calculate that the block of fixed height
773+
// needs to be split. As a result, an empty block with a height equal to sum of paddings
774+
// may appear on the next area. To prevent such situations epsilon is used.
775+
if (IsOverflowFit(overflowY) && blockBottom + EPS < layoutBox.GetBottom()) {
773776
float hDelta = occupiedArea.GetBBox().GetBottom() - layoutBox.GetBottom();
774777
occupiedArea.GetBBox().IncreaseHeight(hDelta).SetY(layoutBox.GetBottom());
775778
if (occupiedArea.GetBBox().GetHeight() < 0) {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
42962d3e7cb76c51101448397741cc467b1d4d2f
1+
1dc93c7744f3da3155837f052a503edaca6265f7

0 commit comments

Comments
 (0)