Skip to content

Commit e4319b1

Browse files
Implement float elements splitting
DEVSIX-1267 Autoported commit. Original commit hash: [90f44ffeb]
1 parent 9127760 commit e4319b1

File tree

10 files changed

+241
-49
lines changed

10 files changed

+241
-49
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ public virtual void FloatDivTest02() {
202202
[NUnit.Framework.Test]
203203
[NUnit.Framework.Ignore("block level floating elements page-overflow and splitting not supported yet")]
204204
public virtual void FloatDivTest03() {
205+
//
206+
// TODO probably we shouldn't review forced placement applying on floated elements
207+
// May be check if there are any floated elements already on page
208+
//
205209
String cmpFileName = sourceFolder + "cmp_floatDivTest03.pdf";
206210
String outFile = destinationFolder + "floatDivTest03.pdf";
207211
PdfWriter writer = new PdfWriter(outFile);

itext/itext.layout/itext/layout/margincollapse/MarginsCollapseHandler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ public virtual void EndMarginsCollapse(Rectangle layoutBox) {
221221
() && !lastKidCollapsedAfterHasClearanceApplied;
222222
if (lastChildMarginJoinedToParent) {
223223
ownCollapseAfter = prevChildMarginInfo.GetOwnCollapseAfter();
224+
if (ownCollapseAfter == null) {
225+
ownCollapseAfter = new MarginsCollapse();
226+
}
224227
}
225228
else {
226229
ownCollapseAfter = new MarginsCollapse();

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

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ source product.
4444
using System;
4545
using System.Collections.Generic;
4646
using System.Text;
47+
using Java.Lang;
4748
using iText.IO.Log;
4849
using iText.IO.Util;
4950
using iText.Kernel.Colors;
@@ -335,6 +336,35 @@ public virtual TransparentColor GetPropertyAsTransparentColor(int property) {
335336
return this.GetProperty<TransparentColor>(property);
336337
}
337338

339+
/// <summary>Returns a property with a certain key, as a floating point value.</summary>
340+
/// <param name="property">
341+
/// an
342+
/// <see cref="iText.Layout.Properties.Property">enum value</see>
343+
/// </param>
344+
/// <returns>
345+
/// a
346+
/// <see cref="float?"/>
347+
/// </returns>
348+
public virtual float? GetPropertyAsFloat(int property) {
349+
Number value = this.GetProperty<Number>(property);
350+
return value != null ? value : null;
351+
}
352+
353+
/// <summary>Returns a property with a certain key, as a floating point value.</summary>
354+
/// <param name="property">
355+
/// an
356+
/// <see cref="iText.Layout.Properties.Property">enum value</see>
357+
/// </param>
358+
/// <param name="defaultValue">default value to be returned if property is not found</param>
359+
/// <returns>
360+
/// a
361+
/// <see cref="float?"/>
362+
/// </returns>
363+
public virtual float? GetPropertyAsFloat(int property, float? defaultValue) {
364+
Number value = this.GetProperty<Number>(property, defaultValue);
365+
return value != null ? value : null;
366+
}
367+
338368
/// <summary>Returns a property with a certain key, as a boolean value.</summary>
339369
/// <param name="property">
340370
/// an
@@ -348,6 +378,20 @@ public virtual TransparentColor GetPropertyAsTransparentColor(int property) {
348378
return this.GetProperty<bool?>(property);
349379
}
350380

381+
/// <summary>Returns a property with a certain key, as an integer value.</summary>
382+
/// <param name="property">
383+
/// an
384+
/// <see cref="iText.Layout.Properties.Property">enum value</see>
385+
/// </param>
386+
/// <returns>
387+
/// a
388+
/// <see cref="int?"/>
389+
/// </returns>
390+
public virtual int? GetPropertyAsInteger(int property) {
391+
Number value = GetProperty(property);
392+
return value != null ? value : null;
393+
}
394+
351395
/// <summary>Returns a string representation of the renderer.</summary>
352396
/// <returns>
353397
/// a
@@ -476,25 +520,18 @@ public virtual void DrawBackground(DrawContext drawContext) {
476520
/// </summary>
477521
/// <param name="drawContext">the context (canvas, document, etc) of this drawing operation.</param>
478522
public virtual void DrawChildren(DrawContext drawContext) {
479-
IList<IRenderer> waitingRenderers = new List<IRenderer>();
480523
foreach (IRenderer child in childRenderers) {
481524
if (FloatingHelper.IsRendererFloating(child)) {
482525
RootRenderer rootRenderer = GetRootRenderer();
483526
if (rootRenderer != null) {
484527
rootRenderer.waitingDrawingElements.Add(child);
485528
child.SetProperty(Property.FLOAT, null);
486529
}
487-
else {
488-
waitingRenderers.Add(child);
489-
}
490530
}
491531
else {
492532
child.Draw(drawContext);
493533
}
494534
}
495-
foreach (IRenderer waitingRenderer in waitingRenderers) {
496-
waitingRenderer.Draw(drawContext);
497-
}
498535
}
499536

500537
/// <summary>
@@ -1211,9 +1248,9 @@ protected internal virtual float[] CalculateShiftToPositionBBoxOfPointsAt(float
12111248
}
12121249

12131250
protected internal virtual void OverrideHeightProperties() {
1214-
float? height = this.GetPropertyAsFloat(Property.HEIGHT);
1215-
float? maxHeight = this.GetPropertyAsFloat(Property.MAX_HEIGHT);
1216-
float? minHeight = this.GetPropertyAsFloat(Property.MIN_HEIGHT);
1251+
float? height = this.GetPropertyAsFloat<float>(Property.HEIGHT);
1252+
float? maxHeight = this.GetPropertyAsFloat<float>(Property.MAX_HEIGHT);
1253+
float? minHeight = this.GetPropertyAsFloat<float>(Property.MIN_HEIGHT);
12171254
if (null != height) {
12181255
if (null == maxHeight || height < maxHeight) {
12191256
maxHeight = height;

0 commit comments

Comments
 (0)