Skip to content

Commit a596674

Browse files
multiple fixes: code review, margin collapse issues during float elements splitting and some other minor issues.
DEVSIX-1267 Autoported commit. Original commit hash: [832c0587e]
1 parent 3540e50 commit a596674

File tree

7 files changed

+154
-132
lines changed

7 files changed

+154
-132
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ public virtual void FloatingImageInCell() {
259259
/// <exception cref="System.IO.IOException"/>
260260
/// <exception cref="System.Exception"/>
261261
[NUnit.Framework.Test]
262-
[LogMessage(iText.IO.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)]
263262
public virtual void FloatingImageToNextPage() {
264263
String cmpFileName = sourceFolder + "cmp_floatingImageToNextPage.pdf";
265264
String outFile = destinationFolder + "floatingImageToNextPage.pdf";
Binary file not shown.

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

Lines changed: 116 additions & 119 deletions
Large diffs are not rendered by default.

itext/itext.layout/itext/layout/renderer/FloatingHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,14 @@ internal static bool IsRendererFloating(IRenderer renderer, FloatPropertyValue?
326326
);
327327
}
328328

329+
internal static bool IsFloatAffectedByClear(FloatPropertyValue? floatPropertyValue, ClearPropertyValue? clearPropertyValue
330+
) {
331+
return !(clearPropertyValue == null || clearPropertyValue.Equals(ClearPropertyValue.NONE)) && (clearPropertyValue
332+
.Equals(ClearPropertyValue.BOTH) || (floatPropertyValue.Equals(FloatPropertyValue.LEFT) && clearPropertyValue
333+
.Equals(ClearPropertyValue.LEFT)) || (floatPropertyValue.Equals(FloatPropertyValue.RIGHT) && clearPropertyValue
334+
.Equals(ClearPropertyValue.RIGHT)));
335+
}
336+
329337
private static void AdjustBoxForFloatRight(Rectangle layoutBox, float blockWidth) {
330338
layoutBox.SetX(layoutBox.GetRight() - blockWidth);
331339
layoutBox.SetWidth(blockWidth);

itext/itext.layout/itext/layout/renderer/ImageRenderer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
210210
isPlacingForced = true;
211211
}
212212
else {
213+
occupiedArea.GetBBox().SetHeight(initialOccupiedAreaBBox.GetHeight());
213214
return new MinMaxWidthLayoutResult(LayoutResult.NOTHING, occupiedArea, null, this, this);
214215
}
215216
}

itext/itext.layout/itext/layout/renderer/RootRenderer.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public override void AddChild(IRenderer renderer) {
7979
int numberOfPositionedChildRenderers = positionedRenderers.Count;
8080
base.AddChild(renderer);
8181
IList<IRenderer> addedRenderers = new List<IRenderer>(1);
82-
if (currentArea != null && currentArea.GetPageNumber() > 1) {
82+
if (currentArea != null && currentArea.IsEmptyArea()) {
8383
addedRenderers.AddAll(waitingRenderers);
8484
waitingRenderers.Clear();
8585
}
@@ -111,13 +111,13 @@ public override void AddChild(IRenderer renderer) {
111111
if (marginsCollapsingEnabled && currentArea != null && renderer != null) {
112112
childMarginsInfo = marginsCollapseHandler.StartChildMarginsHandling(renderer, currentArea.GetBBox());
113113
}
114-
FloatPropertyValue? floatPropertyValue = renderer.GetProperty(Property.FLOAT);
115-
bool rendererIsFloat = floatPropertyValue != null && !floatPropertyValue.Equals(FloatPropertyValue.NONE);
114+
bool rendererIsFloat = FloatingHelper.IsRendererFloating(renderer);
116115
while (currentArea != null && renderer != null && (result = renderer.SetParent(this).Layout(new LayoutContext
117116
(currentArea.Clone(), childMarginsInfo, floatRendererAreas))).GetStatus() != LayoutResult.FULL) {
118117
if (result.GetStatus() == LayoutResult.PARTIAL) {
119118
if (rendererIsFloat) {
120119
waitingRenderers.Add(result.GetOverflowRenderer());
120+
floatRendererAreas.Add(renderer.GetOccupiedArea().GetBBox());
121121
}
122122
else {
123123
if (result.GetOverflowRenderer() is ImageRenderer) {
@@ -139,14 +139,21 @@ public override void AddChild(IRenderer renderer) {
139139
else {
140140
if (result.GetStatus() == LayoutResult.NOTHING) {
141141
if (result.GetOverflowRenderer() is ImageRenderer) {
142-
if (currentArea.GetBBox().GetHeight() < ((ImageRenderer)result.GetOverflowRenderer()).imageHeight && !currentArea
143-
.IsEmptyArea()) {
142+
if (currentArea.GetBBox().GetHeight() < ((ImageRenderer)result.GetOverflowRenderer()).GetOccupiedArea().GetBBox
143+
().GetHeight() && !currentArea.IsEmptyArea() && !rendererIsFloat) {
144144
UpdateCurrentAndInitialArea(result);
145145
}
146-
((ImageRenderer)result.GetOverflowRenderer()).AutoScale(currentArea);
147-
result.GetOverflowRenderer().SetProperty(Property.FORCED_PLACEMENT, true);
148-
ILogger logger = LoggerFactory.GetLogger(typeof(RootRenderer));
149-
logger.Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, ""));
146+
else {
147+
if (rendererIsFloat) {
148+
waitingRenderers.Add(result.GetOverflowRenderer());
149+
}
150+
else {
151+
((ImageRenderer)result.GetOverflowRenderer()).AutoScale(currentArea);
152+
result.GetOverflowRenderer().SetProperty(Property.FORCED_PLACEMENT, true);
153+
ILogger logger = LoggerFactory.GetLogger(typeof(RootRenderer));
154+
logger.Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, ""));
155+
}
156+
}
150157
}
151158
else {
152159
if (currentArea.IsEmptyArea() && result.GetAreaBreak() == null) {
@@ -198,9 +205,9 @@ public override void AddChild(IRenderer renderer) {
198205
}
199206
}
200207
}
201-
if (rendererIsFloat && result.GetStatus() != LayoutResult.NOTHING) {
208+
if (rendererIsFloat && (result.GetStatus() != LayoutResult.NOTHING || renderer is ImageRenderer)) {
202209
renderer = null;
203-
continue;
210+
break;
204211
}
205212
if (!waitingRenderers.IsEmpty()) {
206213
renderer = waitingRenderers.JRemoveAt(0);
@@ -292,6 +299,16 @@ public virtual void Flush() {
292299
/// and when no consequent element has been added. This method addresses such situations.
293300
/// </summary>
294301
public virtual void Close() {
302+
IList<IRenderer> waitingFloatRenderers = new List<IRenderer>(waitingRenderers);
303+
while (!waitingFloatRenderers.IsEmpty()) {
304+
marginsCollapseHandler = new MarginsCollapseHandler(this, null);
305+
waitingRenderers.Clear();
306+
UpdateCurrentAndInitialArea(null);
307+
foreach (IRenderer renderer in waitingFloatRenderers) {
308+
AddChild(renderer);
309+
}
310+
waitingFloatRenderers = new List<IRenderer>(waitingRenderers);
311+
}
295312
if (keepWithNextHangingRenderer != null) {
296313
keepWithNextHangingRenderer.SetProperty(Property.KEEP_WITH_NEXT, false);
297314
IRenderer rendererToBeAdded = keepWithNextHangingRenderer;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
29a58d612b5237ca554268163a60c11a34c82651
1+
832c0587ed1207573c2c22b3898b84bf713101cc

0 commit comments

Comments
 (0)