Skip to content

Commit a4ba6c2

Browse files
committed
Move clippedHeight to LayoutContext. Deprecate emptyArea. Minor refactoring. Fix merge issues.
DEVSIX-992
1 parent 60234f2 commit a4ba6c2

File tree

9 files changed

+65
-68
lines changed

9 files changed

+65
-68
lines changed

layout/src/main/java/com/itextpdf/layout/layout/LayoutArea.java

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ This file is part of the iText (R) project.
4545

4646
import com.itextpdf.io.util.HashCode;
4747
import com.itextpdf.kernel.geom.Rectangle;
48+
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
49+
import com.itextpdf.layout.border.Border;
4850
import com.itextpdf.layout.renderer.AbstractRenderer;
4951

5052
import com.itextpdf.io.util.MessageFormatUtil;
@@ -64,34 +66,20 @@ public class LayoutArea {
6466
protected Rectangle bBox;
6567
/**
6668
* Indicates whether the area already has some placed content or not.
69+
* @deprecated Will be removed in 7.1.0.
6770
*/
71+
@Deprecated
6872
protected boolean emptyArea = true;
6973

70-
/**
71-
* Indicates whether the height is clipped or not.
72-
*/
73-
protected boolean clippedHeight = false;
74-
7574
/**
7675
* Creates the area for content {@link com.itextpdf.layout.renderer.IRenderer#layout(LayoutContext) layouting}.
7776
*
7877
* @param pageNumber the number of page on which the area is located.
7978
* @param bBox the area's bounding box
8079
*/
8180
public LayoutArea(int pageNumber, Rectangle bBox) {
82-
this(pageNumber, bBox, false);
83-
}
84-
85-
/**
86-
* Creates the area for content {@link com.itextpdf.layout.renderer.IRenderer#layout(LayoutContext) layouting}.
87-
*
88-
* @param pageNumber the number of page on which the area is located.
89-
* @param bBox the area's bounding box
90-
*/
91-
public LayoutArea(int pageNumber, Rectangle bBox, boolean isClippedHeight) {
9281
this.pageNumber = pageNumber;
9382
this.bBox = bBox;
94-
this.clippedHeight = isClippedHeight;
9583
}
9684

9785
/**
@@ -123,35 +111,22 @@ public void setBBox(Rectangle bbox) {
123111
* Indicates whether the area already has some placed content or not.
124112
*
125113
* @return whether the area is empty or not
114+
* @deprecated Will be removed in 7.1.0.
126115
*/
116+
@Deprecated
127117
public boolean isEmptyArea() {
128118
return emptyArea;
129119
}
130120

131121
/**
132122
* Defines whether the area already has some placed content or not.
123+
* @deprecated Will be removed in 7.1.0.
133124
*/
125+
@Deprecated
134126
public void setEmptyArea(boolean emptyArea) {
135127
this.emptyArea = emptyArea;
136128
}
137129

138-
/**
139-
* Indicates whether the height is clipped or not.
140-
*
141-
* @return whether the area is empty or not
142-
*/
143-
public boolean isClippedHeight() {
144-
return clippedHeight;
145-
}
146-
147-
/**
148-
* Defines whether the height is clipped or not.
149-
*/
150-
public void setClippedHeight(boolean clippedHeight) {
151-
this.clippedHeight = clippedHeight;
152-
}
153-
154-
155130
/**
156131
* {@inheritDoc}
157132
*/

layout/src/main/java/com/itextpdf/layout/layout/LayoutContext.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public class LayoutContext {
6363

6464
protected List<Rectangle> floatRendererAreas = new ArrayList<>();
6565

66+
/**
67+
* Indicates whether the height is clipped or not.
68+
*/
69+
protected boolean clippedHeight = false;
70+
6671
public LayoutContext(LayoutArea area) {
6772
this.area = area;
6873
}
@@ -79,6 +84,19 @@ public LayoutContext(LayoutArea area, MarginsCollapseInfo marginsCollapseInfo, L
7984
}
8085
}
8186

87+
public LayoutContext(LayoutArea area, boolean clippedHeight) {
88+
this(area);
89+
this.clippedHeight = clippedHeight;
90+
}
91+
92+
public LayoutContext(LayoutArea area, MarginsCollapseInfo marginsCollapseInfo, List<Rectangle> floatedRendererAreas, boolean clippedHeight) {
93+
this(area, marginsCollapseInfo);
94+
if (floatedRendererAreas != null) {
95+
this.floatRendererAreas = floatedRendererAreas;
96+
}
97+
this.clippedHeight = clippedHeight;
98+
}
99+
82100
/**
83101
* Gets the {@link LayoutArea area} the content to be placed on.
84102
*
@@ -96,6 +114,23 @@ public List<Rectangle> getFloatRendererAreas() {
96114
return floatRendererAreas;
97115
}
98116

117+
/**
118+
* Indicates whether the layout area's height is clipped or not.
119+
*
120+
* @return whether the layout area's height is clipped or not.
121+
*/
122+
public boolean isClippedHeight() {
123+
return clippedHeight;
124+
}
125+
126+
/**
127+
* Defines whether the layout area's height is clipped or not.
128+
*/
129+
public void setClippedHeight(boolean clippedHeight) {
130+
this.clippedHeight = clippedHeight;
131+
}
132+
133+
99134
/**
100135
* {@inheritDoc}
101136
*/

layout/src/main/java/com/itextpdf/layout/renderer/BlockRenderer.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected BlockRenderer(IElement modelElement) {
9090
public LayoutResult layout(LayoutContext layoutContext) {
9191
overrideHeightProperties();
9292
boolean wasHeightClipped = false;
93-
boolean wasParentsHeightClipped = layoutContext.getArea().isClippedHeight();
93+
boolean wasParentsHeightClipped = layoutContext.isClippedHeight();
9494
int pageNumber = layoutContext.getArea().getPageNumber();
9595

9696
boolean isPositioned = isPositioned();
@@ -181,7 +181,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
181181
if (marginsCollapsingEnabled) {
182182
childMarginsInfo = marginsCollapseHandler.startChildMarginsHandling(childRenderer, layoutBox);
183183
}
184-
while ((result = childRenderer.setParent(this).layout(new LayoutContext(new LayoutArea(pageNumber, layoutBox, wasHeightClipped || wasParentsHeightClipped), childMarginsInfo, floatRendererAreas)))
184+
while ((result = childRenderer.setParent(this).layout(new LayoutContext(new LayoutArea(pageNumber, layoutBox), childMarginsInfo, floatRendererAreas, wasHeightClipped || wasParentsHeightClipped)))
185185
.getStatus() != LayoutResult.FULL) {
186186
if (marginsCollapsingEnabled) {
187187
if (result.getStatus() != LayoutResult.NOTHING) {
@@ -445,14 +445,6 @@ public LayoutResult layout(LayoutContext layoutContext) {
445445

446446
applyPaddings(occupiedArea.getBBox(), paddings, true);
447447
applyBorderBox(occupiedArea.getBBox(), borders, true);
448-
if (positionedRenderers.size() > 0) {
449-
LayoutArea area = new LayoutArea(occupiedArea.getPageNumber(), occupiedArea.getBBox().clone(), wasHeightClipped || wasParentsHeightClipped);
450-
applyBorderBox(area.getBBox(), false);
451-
for (IRenderer childPositionedRenderer : positionedRenderers) {
452-
childPositionedRenderer.setParent(this).layout(new LayoutContext(area));
453-
}
454-
applyBorderBox(area.getBBox(), true);
455-
}
456448
applyMargins(occupiedArea.getBBox(), true);
457449

458450
applyAbsolutePositionIfNeeded(layoutContext);
@@ -785,7 +777,7 @@ protected void correctPositionedLayout(Rectangle layoutBox) {
785777
}
786778
}
787779

788-
protected float getOverflowPartHeight(OverflowPropertyValue overflowY, Rectangle parentBox) {
780+
float getOverflowPartHeight(OverflowPropertyValue overflowY, Rectangle parentBox) {
789781
float difference = 0;
790782
if (null != overflowY && OverflowPropertyValue.FIT != overflowY) {
791783
if (occupiedArea.getBBox().getBottom() < parentBox.getBottom()) {

layout/src/main/java/com/itextpdf/layout/renderer/ImageRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
123123
applyBorderBox(layoutBox, borders, false);
124124

125125
OverflowPropertyValue overflowX = this.parent.<OverflowPropertyValue>getProperty(Property.OVERFLOW_X);
126-
OverflowPropertyValue overflowY = (null == retrieveMaxHeight() || retrieveMaxHeight() > layoutBox.getHeight()) && !layoutContext.getArea().isClippedHeight() ? OverflowPropertyValue.FIT : this.parent.<OverflowPropertyValue>getProperty(Property.OVERFLOW_Y);
126+
OverflowPropertyValue overflowY = (null == retrieveMaxHeight() || retrieveMaxHeight() > layoutBox.getHeight()) && !layoutContext.isClippedHeight() ? OverflowPropertyValue.FIT : this.parent.<OverflowPropertyValue>getProperty(Property.OVERFLOW_Y);
127127
boolean processOverflowX = (null != overflowX && !OverflowPropertyValue.FIT.equals(overflowX));
128128
boolean processOverflowY = (null != overflowY && !OverflowPropertyValue.FIT.equals(overflowY));
129129
if (isAbsolutePosition()) {

layout/src/main/java/com/itextpdf/layout/renderer/LineRenderer.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public class LineRenderer extends AbstractRenderer {
9393
@Override
9494
public LineLayoutResult layout(LayoutContext layoutContext) {
9595
Rectangle layoutBox = layoutContext.getArea().getBBox().clone();
96-
boolean wasParentsHeightClipped = layoutContext.getArea().isClippedHeight();
96+
boolean wasParentsHeightClipped = layoutContext.isClippedHeight();
9797
List<Rectangle> floatRendererAreas = layoutContext.getFloatRendererAreas();
9898

9999
OverflowPropertyValue oldXOverflow = null;
@@ -153,7 +153,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
153153
} else if (childRenderer instanceof TabRenderer) {
154154
if (hangingTabStop != null) {
155155
IRenderer tabRenderer = childRenderers.get(childPos - 1);
156-
tabRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), bbox, wasParentsHeightClipped)));
156+
tabRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), bbox), wasParentsHeightClipped));
157157
curWidth += tabRenderer.getOccupiedArea().getBBox().getWidth();
158158
widthHandler.updateMaxChildWidth(tabRenderer.getOccupiedArea().getBBox().getWidth());
159159
}
@@ -210,7 +210,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
210210
setProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
211211
}
212212
if (overflowFloats.isEmpty() && (!anythingPlaced || floatingBoxFullWidth <= bbox.getWidth())) {
213-
childResult = childRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), layoutContext.getArea().getBBox().clone(), wasParentsHeightClipped), null, floatRendererAreas));
213+
childResult = childRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), layoutContext.getArea().getBBox().clone()), null, floatRendererAreas, wasParentsHeightClipped));
214214
}
215215
// Get back child width so that it's not lost
216216
if (childWidthWasReplaced) {
@@ -291,16 +291,13 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
291291
}
292292
}
293293

294-
if (childPos > 0) {
295-
setProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
296-
}
297294
if (childResult == null) {
298295
if (!wasXOverflowChanged && childPos > 0) {
299296
oldXOverflow = this.<OverflowPropertyValue>getProperty(Property.OVERFLOW_X);
300297
wasXOverflowChanged = true;
301298
setProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
302299
}
303-
childResult = childRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), bbox, wasParentsHeightClipped)));
300+
childResult = childRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), bbox), wasParentsHeightClipped));
304301
}
305302

306303
// Get back child width so that it's not lost
@@ -367,7 +364,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
367364
affectedRenderers.addAll(childRenderers.subList(lastTabIndex + 1, childPos + 1));
368365
float tabWidth = calculateTab(layoutBox, curWidth, hangingTabStop, affectedRenderers, tabRenderer);
369366

370-
tabRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), bbox, wasParentsHeightClipped)));
367+
tabRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), bbox), wasParentsHeightClipped));
371368
float sumOfAffectedRendererWidths = 0;
372369
for (IRenderer renderer : affectedRenderers) {
373370
renderer.getOccupiedArea().getBBox().moveRight(tabWidth + sumOfAffectedRendererWidths);
@@ -405,7 +402,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
405402
if (wasXOverflowChanged) {
406403
setProperty(Property.OVERFLOW_X, oldXOverflow);
407404
}
408-
LayoutResult newLayoutResult = childRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), layoutBox, wasParentsHeightClipped)));
405+
LayoutResult newLayoutResult = childRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), layoutBox), wasParentsHeightClipped));
409406
if (wasXOverflowChanged) {
410407
setProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
411408
}

layout/src/main/java/com/itextpdf/layout/renderer/ParagraphRenderer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public ParagraphRenderer(Paragraph modelElement) {
8585
public LayoutResult layout(LayoutContext layoutContext) {
8686
overrideHeightProperties();
8787
boolean wasHeightClipped = false;
88-
boolean wasParentsHeightClipped = layoutContext.getArea().isClippedHeight();
88+
boolean wasParentsHeightClipped = layoutContext.isClippedHeight();
8989
int pageNumber = layoutContext.getArea().getPageNumber();
9090
boolean anythingPlaced = false;
9191
boolean firstLineInBox = true;
@@ -192,8 +192,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
192192
currentRenderer.setProperty(Property.OVERFLOW_X, overflowX);
193193
currentRenderer.setProperty(Property.OVERFLOW_Y, overflowY);
194194
LineLayoutResult result = ((LineRenderer) currentRenderer.setParent(this)).layout(new LayoutContext(
195-
new LayoutArea(pageNumber, childLayoutBox, wasHeightClipped || wasParentsHeightClipped), null,
196-
floatRendererAreas));
195+
new LayoutArea(pageNumber, childLayoutBox), null, floatRendererAreas, wasHeightClipped || wasParentsHeightClipped));
197196

198197
if (result.getStatus() == LayoutResult.NOTHING) {
199198
Float lineShiftUnderFloats = FloatingHelper.calculateLineShiftUnderFloats(floatRendererAreas, layoutBox);

layout/src/main/java/com/itextpdf/layout/renderer/RootRenderer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ protected void flushWaitingDrawingElements() {
301301

302302
protected void shrinkCurrentAreaAndProcessRenderer(IRenderer renderer, List<IRenderer> resultRenderers, LayoutResult result) {
303303
if (currentArea != null) {
304-
OverflowPropertyValue overflowY = renderer.<OverflowPropertyValue>getProperty(Property.OVERFLOW_Y);
305304
float resultRendererHeight = result.getOccupiedArea().getBBox().getHeight();
306305
currentArea.getBBox().setHeight(currentArea.getBBox().getHeight() - resultRendererHeight);
307306
if (currentArea.isEmptyArea() && resultRendererHeight > 0) {

0 commit comments

Comments
 (0)