Skip to content

Commit 783ec13

Browse files
committed
Fixes in overflow. Process long words correctly.
Distinguish x and y image overflow. Skip x overflow if there is already float in a line. Change long word's occupied area if it has x-overflow Distinguish whether area was clipped or not by setting clippedHeight value of LayoutArea. Apply overflow if area was clipped. DEVSIX-922 Autoported commit. Original commit hash: [8bfe573]
1 parent 79b8115 commit 783ec13

File tree

9 files changed

+137
-43
lines changed

9 files changed

+137
-43
lines changed

itext/itext.layout/itext/layout/layout/LayoutArea.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,31 @@ public class LayoutArea {
6262
/// <summary>Indicates whether the area already has some placed content or not.</summary>
6363
protected internal bool emptyArea = true;
6464

65+
/// <summary>Indicates whether the height is clipped or not.</summary>
66+
protected internal bool clippedHeight = false;
67+
6568
/// <summary>
6669
/// Creates the area for content
6770
/// <see cref="iText.Layout.Renderer.IRenderer.Layout(LayoutContext)">layouting</see>
6871
/// .
6972
/// </summary>
7073
/// <param name="pageNumber">the number of page on which the area is located.</param>
7174
/// <param name="bBox">the area's bounding box</param>
72-
public LayoutArea(int pageNumber, Rectangle bBox) {
75+
public LayoutArea(int pageNumber, Rectangle bBox)
76+
: this(pageNumber, bBox, false) {
77+
}
78+
79+
/// <summary>
80+
/// Creates the area for content
81+
/// <see cref="iText.Layout.Renderer.IRenderer.Layout(LayoutContext)">layouting</see>
82+
/// .
83+
/// </summary>
84+
/// <param name="pageNumber">the number of page on which the area is located.</param>
85+
/// <param name="bBox">the area's bounding box</param>
86+
public LayoutArea(int pageNumber, Rectangle bBox, bool isClippedHeight) {
7387
this.pageNumber = pageNumber;
7488
this.bBox = bBox;
89+
this.clippedHeight = isClippedHeight;
7590
}
7691

7792
/// <summary>Gets the number of page on which the area is located.</summary>
@@ -110,6 +125,17 @@ public virtual void SetEmptyArea(bool emptyArea) {
110125
this.emptyArea = emptyArea;
111126
}
112127

128+
/// <summary>Indicates whether the height is clipped or not.</summary>
129+
/// <returns>whether the area is empty or not</returns>
130+
public virtual bool IsClippedHeight() {
131+
return clippedHeight;
132+
}
133+
134+
/// <summary>Defines whether the height is clipped or not.</summary>
135+
public virtual void SetClippedHeight(bool clippedHeight) {
136+
this.clippedHeight = clippedHeight;
137+
}
138+
113139
/// <summary><inheritDoc/></summary>
114140
public virtual iText.Layout.Layout.LayoutArea Clone() {
115141
iText.Layout.Layout.LayoutArea area = new iText.Layout.Layout.LayoutArea(pageNumber, bBox.Clone());

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

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ protected internal BlockRenderer(IElement modelElement)
6666
public override LayoutResult Layout(LayoutContext layoutContext) {
6767
OverrideHeightProperties();
6868
bool wasHeightClipped = false;
69+
bool wasParentsHeightClipped = layoutContext.GetArea().IsClippedHeight();
6970
int pageNumber = layoutContext.GetArea().GetPageNumber();
7071
bool isPositioned = IsPositioned();
7172
Rectangle parentBBox = layoutContext.GetArea().GetBBox().Clone();
@@ -103,19 +104,20 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
103104
float[] paddings = GetPaddings();
104105
ApplyBordersPaddingsMargins(parentBBox, borders, paddings);
105106
OverflowPropertyValue? overflowX = this.GetProperty<OverflowPropertyValue?>(Property.OVERFLOW_X);
106-
OverflowPropertyValue? overflowY = this.GetProperty<OverflowPropertyValue?>(Property.OVERFLOW_Y);
107+
float? blockMaxHeight = RetrieveMaxHeight();
108+
OverflowPropertyValue? overflowY = (null == blockMaxHeight || blockMaxHeight > parentBBox.GetHeight()) &&
109+
!wasParentsHeightClipped ? OverflowPropertyValue.FIT : this.GetProperty<OverflowPropertyValue?>(Property
110+
.OVERFLOW_Y);
107111
if (blockWidth != null && (blockWidth < parentBBox.GetWidth() || isPositioned || rotation != null || (null
108112
!= overflowX && !OverflowPropertyValue.FIT.Equals(overflowX)))) {
109113
// TODO DEVSIX-1174
110114
UnitValue widthVal = this.GetProperty<UnitValue>(Property.WIDTH);
111-
if (widthVal != null && widthVal.IsPercentValue() && widthVal.GetValue() == 100 && (null == overflowX || OverflowPropertyValue
112-
.FIT.Equals(overflowX))) {
115+
if (widthVal != null && widthVal.IsPercentValue() && widthVal.GetValue() == 100) {
113116
}
114117
else {
115118
parentBBox.SetWidth((float)blockWidth);
116119
}
117120
}
118-
float? blockMaxHeight = RetrieveMaxHeight();
119121
if (!IsFixedLayout() && null != blockMaxHeight && (blockMaxHeight < parentBBox.GetHeight() || (null != overflowY
120122
&& !OverflowPropertyValue.FIT.Equals(overflowY))) && !true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT
121123
))) {
@@ -128,7 +130,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
128130
}
129131
parentBBox.MoveUp(heightDelta).SetHeight((float)blockMaxHeight);
130132
}
131-
Rectangle contentBoxToFit = parentBBox.Clone();
132133
IList<Rectangle> areas;
133134
if (isPositioned) {
134135
areas = JavaCollectionsUtil.SingletonList(parentBBox);
@@ -153,7 +154,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
153154
childMarginsInfo = marginsCollapseHandler.StartChildMarginsHandling(childRenderer, layoutBox);
154155
}
155156
while ((result = childRenderer.SetParent(this).Layout(new LayoutContext(new LayoutArea(pageNumber, layoutBox
156-
), childMarginsInfo, floatRendererAreas))).GetStatus() != LayoutResult.FULL) {
157+
, wasHeightClipped || wasParentsHeightClipped), childMarginsInfo, floatRendererAreas))).GetStatus() !=
158+
LayoutResult.FULL) {
157159
if (marginsCollapsingEnabled) {
158160
if (result.GetStatus() != LayoutResult.NOTHING) {
159161
marginsCollapseHandler.EndChildMarginsHandling(layoutBox);
@@ -169,7 +171,10 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
169171
else {
170172
if (result.GetOccupiedArea() != null && result.GetStatus() != LayoutResult.NOTHING) {
171173
occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), result.GetOccupiedArea().GetBBox
172-
()).SetWidth(occupiedArea.GetBBox().GetWidth()));
174+
()));
175+
if (occupiedArea.GetBBox().GetWidth() > layoutBox.GetWidth()) {
176+
occupiedArea.GetBBox().SetWidth(layoutBox.GetWidth());
177+
}
173178
}
174179
}
175180
if (FloatingHelper.IsRendererFloating(this) || isCellRenderer) {
@@ -329,7 +334,10 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
329334
if (!FloatingHelper.IsRendererFloating(childRenderer)) {
330335
// this check is needed only if margins collapsing is enabled
331336
occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), result.GetOccupiedArea().GetBBox
332-
()).SetWidth(occupiedArea.GetBBox().GetWidth()));
337+
()));
338+
if (occupiedArea.GetBBox().GetWidth() > layoutBox.GetWidth()) {
339+
occupiedArea.GetBBox().SetWidth(layoutBox.GetWidth());
340+
}
333341
}
334342
}
335343
if (marginsCollapsingEnabled) {
@@ -405,9 +413,18 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
405413
if (isPositioned) {
406414
CorrectPositionedLayout(layoutBox);
407415
}
408-
float overflowPartHeight = GetOverflowPartHeight(overflowY, contentBoxToFit);
416+
float overflowPartHeight = GetOverflowPartHeight(overflowY, layoutBox);
409417
ApplyPaddings(occupiedArea.GetBBox(), paddings, true);
410418
ApplyBorderBox(occupiedArea.GetBBox(), borders, true);
419+
if (positionedRenderers.Count > 0) {
420+
LayoutArea area = new LayoutArea(occupiedArea.GetPageNumber(), occupiedArea.GetBBox().Clone(), wasHeightClipped
421+
|| wasParentsHeightClipped);
422+
ApplyBorderBox(area.GetBBox(), false);
423+
foreach (IRenderer childPositionedRenderer in positionedRenderers) {
424+
childPositionedRenderer.SetParent(this).Layout(new LayoutContext(area));
425+
}
426+
ApplyBorderBox(area.GetBBox(), true);
427+
}
411428
ApplyMargins(occupiedArea.GetBBox(), true);
412429
ApplyAbsolutePositionIfNeeded(layoutContext);
413430
if (rotation != null) {
@@ -441,6 +458,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
441458
}
442459
}
443460
if (wasHeightClipped) {
461+
editedArea_1.GetBBox().MoveUp(overflowPartHeight).DecreaseHeight(overflowPartHeight);
444462
occupiedArea.GetBBox().MoveUp(overflowPartHeight).DecreaseHeight(overflowPartHeight);
445463
}
446464
if (null == overflowRenderer_1) {
@@ -779,7 +797,9 @@ protected internal override MinMaxWidth GetMinMaxWidth(float availableWidth) {
779797

780798
internal virtual MinMaxWidth CorrectMinMaxWidth(MinMaxWidth minMaxWidth) {
781799
float? width = RetrieveWidth(-1);
782-
if (width != null && width >= 0 && width >= minMaxWidth.GetChildrenMinWidth()) {
800+
OverflowPropertyValue? overflowX = this.GetProperty<OverflowPropertyValue?>(Property.OVERFLOW_X);
801+
if (width != null && width >= 0 && (width >= minMaxWidth.GetChildrenMinWidth() || !OverflowPropertyValue.FIT
802+
.Equals(overflowX))) {
783803
minMaxWidth.SetChildrenMaxWidth((float)width);
784804
minMaxWidth.SetChildrenMinWidth((float)width);
785805
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
119119
Border[] borders = GetBorders();
120120
ApplyBorderBox(layoutBox, borders, false);
121121
OverflowPropertyValue? overflowX = this.parent.GetProperty<OverflowPropertyValue?>(Property.OVERFLOW_X);
122-
OverflowPropertyValue? overflowY = this.parent.GetProperty<OverflowPropertyValue?>(Property.OVERFLOW_Y);
123-
bool processOverflow = (null != overflowX && !OverflowPropertyValue.FIT.Equals(overflowX)) || (null != overflowY
124-
&& !OverflowPropertyValue.FIT.Equals(overflowY));
122+
OverflowPropertyValue? overflowY = (null == RetrieveMaxHeight() || RetrieveMaxHeight() > layoutBox.GetHeight
123+
()) && !layoutContext.GetArea().IsClippedHeight() ? OverflowPropertyValue.FIT : this.parent.GetProperty
124+
<OverflowPropertyValue?>(Property.OVERFLOW_Y);
125+
bool processOverflowX = (null != overflowX && !OverflowPropertyValue.FIT.Equals(overflowX));
126+
bool processOverflowY = (null != overflowY && !OverflowPropertyValue.FIT.Equals(overflowY));
125127
if (IsAbsolutePosition()) {
126128
ApplyAbsolutePosition(layoutBox);
127129
}
@@ -210,7 +212,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
210212
// indicates whether the placement is forced
211213
bool isPlacingForced = false;
212214
if (width > layoutBox.GetWidth() || height > layoutBox.GetHeight()) {
213-
if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT)) || processOverflow) {
215+
if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT)) || (width > layoutBox.GetWidth() && processOverflowX
216+
) || (height > layoutBox.GetHeight() && processOverflowY)) {
214217
isPlacingForced = true;
215218
}
216219
else {

itext/itext.layout/itext/layout/renderer/LineRenderer.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,15 @@ public class LineRenderer : AbstractRenderer {
7575
// AbstractRenderer.EPS is not enough here
7676
public override LayoutResult Layout(LayoutContext layoutContext) {
7777
Rectangle layoutBox = layoutContext.GetArea().GetBBox().Clone();
78+
bool wasParentsHeightClipped = layoutContext.GetArea().IsClippedHeight();
7879
IList<Rectangle> floatRendererAreas = layoutContext.GetFloatRendererAreas();
7980
if (floatRendererAreas != null) {
8081
FloatingHelper.AdjustLineAreaAccordingToFloats(floatRendererAreas, layoutBox);
82+
if (0 != floatRendererAreas.Count) {
83+
SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
84+
}
8185
}
86+
// TODO
8287
occupiedArea = new LayoutArea(layoutContext.GetArea().GetPageNumber(), layoutBox.Clone().MoveUp(layoutBox.
8388
GetHeight()).SetHeight(0).SetWidth(0));
8489
float curWidth = 0;
@@ -116,7 +121,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
116121
if (childRenderer is TabRenderer) {
117122
if (hangingTabStop != null) {
118123
IRenderer tabRenderer = childRenderers[childPos - 1];
119-
tabRenderer.Layout(new LayoutContext(new LayoutArea(layoutContext.GetArea().GetPageNumber(), bbox)));
124+
tabRenderer.Layout(new LayoutContext(new LayoutArea(layoutContext.GetArea().GetPageNumber(), bbox, wasParentsHeightClipped
125+
)));
120126
curWidth += tabRenderer.GetOccupiedArea().GetBBox().GetWidth();
121127
widthHandler.UpdateMaxChildWidth(tabRenderer.GetOccupiedArea().GetBBox().GetWidth());
122128
}
@@ -168,9 +174,15 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
168174
// also not taking it into account (i.e. not setting it on child renderer) results in differences with html
169175
// when floating span is split on other line;
170176
// TODO may be process floating spans as inline blocks always?
177+
if (childPos > 0) {
178+
SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
179+
}
171180
if (overflowFloats.IsEmpty() && (!anythingPlaced || floatingBoxFullWidth <= bbox.GetWidth())) {
172181
childResult = childRenderer.Layout(new LayoutContext(new LayoutArea(layoutContext.GetArea().GetPageNumber(
173-
), layoutContext.GetArea().GetBBox().Clone()), null, floatRendererAreas));
182+
), layoutContext.GetArea().GetBBox().Clone(), wasParentsHeightClipped), null, floatRendererAreas));
183+
}
184+
if (childPos > 0) {
185+
DeleteOwnProperty(Property.OVERFLOW_X);
174186
}
175187
// Get back child width so that it's not lost
176188
if (childWidthWasReplaced) {
@@ -255,10 +267,16 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
255267
}
256268
}
257269
}
270+
if (childPos > 0) {
271+
SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
272+
}
258273
if (childResult == null) {
259274
childResult = childRenderer.Layout(new LayoutContext(new LayoutArea(layoutContext.GetArea().GetPageNumber(
260275
), bbox)));
261276
}
277+
if (childPos > 0) {
278+
DeleteOwnProperty(Property.OVERFLOW_X);
279+
}
262280
// Get back child width so that it's not lost
263281
if (childWidthWasReplaced) {
264282
if (childRendererHasOwnWidthProperty) {
@@ -335,7 +353,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
335353
IList<IRenderer> affectedRenderers = new List<IRenderer>();
336354
affectedRenderers.AddAll(childRenderers.SubList(lastTabIndex + 1, childPos + 1));
337355
float tabWidth = CalculateTab(layoutBox, curWidth, hangingTabStop, affectedRenderers, tabRenderer);
338-
tabRenderer.Layout(new LayoutContext(new LayoutArea(layoutContext.GetArea().GetPageNumber(), bbox)));
356+
tabRenderer.Layout(new LayoutContext(new LayoutArea(layoutContext.GetArea().GetPageNumber(), bbox, wasParentsHeightClipped
357+
)));
339358
float sumOfAffectedRendererWidths = 0;
340359
foreach (IRenderer renderer in affectedRenderers) {
341360
renderer.GetOccupiedArea().GetBBox().MoveRight(tabWidth + sumOfAffectedRendererWidths);
@@ -374,7 +393,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
374393
bool wordWasSplitAndItWillFitOntoNextLine = false;
375394
if (childResult is TextLayoutResult && ((TextLayoutResult)childResult).IsWordHasBeenSplit()) {
376395
LayoutResult newLayoutResult = childRenderer.Layout(new LayoutContext(new LayoutArea(layoutContext.GetArea
377-
().GetPageNumber(), layoutBox)));
396+
().GetPageNumber(), layoutBox, wasParentsHeightClipped)));
378397
if (newLayoutResult is TextLayoutResult && !((TextLayoutResult)newLayoutResult).IsWordHasBeenSplit()) {
379398
wordWasSplitAndItWillFitOntoNextLine = true;
380399
}
@@ -599,6 +618,18 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
599618
processed.AdjustChildrenYLine().TrimLast();
600619
result.SetMinMaxWidth(minMaxWidth);
601620
}
621+
if (floatRendererAreas != null) {
622+
if (0 != floatRendererAreas.Count) {
623+
DeleteOwnProperty(Property.OVERFLOW_X);
624+
// TODO
625+
if (null != result.GetSplitRenderer()) {
626+
result.GetSplitRenderer().DeleteOwnProperty(Property.OVERFLOW_X);
627+
}
628+
if (null != result.GetOverflowRenderer()) {
629+
result.GetOverflowRenderer().DeleteOwnProperty(Property.OVERFLOW_X);
630+
}
631+
}
632+
}
602633
return result;
603634
}
604635

0 commit comments

Comments
 (0)