Skip to content

Commit d6aedef

Browse files
author
Samuel Huylebroeck
committed
Relative height support
Refactor layout-methods to not use overrideHeight Adapt retrieve[Min/Max-]Height methods to take priority and relative height into account Methods for getting the declared (and resolved) height property of a direct parent Refactor updateHeightsOnSplit to take relative heights into account Add additional tests DEVSIX-1389
1 parent e6dec40 commit d6aedef

18 files changed

+568
-130
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,22 @@ public T setWidth(UnitValue width) {
169169
/**
170170
* Gets the height property of the Element.
171171
*
172-
* @return the height of the element, as a floating point value.
172+
* @return the height of the element, as a floating point value. Null if the property is not present
173173
*/
174174
public Float getHeight() {
175-
return this.<Float>getProperty(Property.HEIGHT);
175+
return this.<UnitValue>getProperty(Property.HEIGHT).getValue();
176+
176177
}
177178

178179
/**
179-
* Sets the height property of the Element.
180+
* Sets the height property of the Element as a point-value.
180181
*
181182
* @param height a floating point value for the new height
182183
* @return this Element.
183184
*/
184185
public T setHeight(float height) {
185-
setProperty(Property.HEIGHT, height);
186+
UnitValue heightAsUV = UnitValue.createPointValue(height);
187+
setProperty(Property.HEIGHT, heightAsUV);
186188
return (T) (Object) this;
187189
}
188190

layout/src/main/java/com/itextpdf/layout/element/BlockElement.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,36 @@ public T setRotationAngle(double angleInRadians) {
386386
return (T) (Object) this;
387387
}
388388

389+
/**
390+
* Sets the height of a block element as point-unit value
391+
* @param height a floating point value for the new height
392+
* @return the block element itself
393+
*/
389394
@Override
390395
public T setHeight(float height) {
391396
super.setHeight(height);
392397
return (T) (Object) this;
393398
}
394399

400+
/**
401+
* Sets the max-height of a block element as point-unit value.
402+
* @param maxHeight a floating point value for the new max-height
403+
* @return the block element itself
404+
*/
395405
public T setMaxHeight(float maxHeight) {
396-
setProperty(Property.MAX_HEIGHT, maxHeight);
406+
UnitValue maxHeightAsUV = UnitValue.createPointValue(maxHeight);
407+
setProperty(Property.MAX_HEIGHT, maxHeightAsUV);
397408
return (T) (Object) this;
398409
}
399410

411+
/**
412+
* Sets the min-height of a block element as point-unit value.
413+
* @param minHeight a floating point value for the new min-height
414+
* @return the block element itself
415+
*/
400416
public T setMinHeight(float minHeight) {
401-
setProperty(Property.MIN_HEIGHT, minHeight);
417+
UnitValue minHeightAsUV = UnitValue.createPointValue(minHeight);
418+
setProperty(Property.MIN_HEIGHT, minHeightAsUV);
402419
return (T) (Object) this;
403420
}
404421

layout/src/main/java/com/itextpdf/layout/element/Image.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This file is part of the iText (R) project.
5555
import com.itextpdf.kernel.pdf.xobject.PdfXObject;
5656
import com.itextpdf.layout.property.Property;
5757
import com.itextpdf.layout.layout.LayoutPosition;
58+
import com.itextpdf.layout.property.UnitValue;
5859
import com.itextpdf.layout.renderer.IRenderer;
5960
import com.itextpdf.layout.renderer.ImageRenderer;
6061

@@ -421,12 +422,14 @@ public float getImageHeight() {
421422
}
422423

423424
public Image setMaxHeight(float maxHeight) {
424-
setProperty(Property.MAX_HEIGHT, maxHeight);
425+
UnitValue maxHeightAsUv = UnitValue.createPointValue(maxHeight);
426+
setProperty(Property.MAX_HEIGHT, maxHeightAsUv);
425427
return (Image) (Object) this;
426428
}
427429

428430
public Image setMinHeight(float minHeight) {
429-
setProperty(Property.MIN_HEIGHT, minHeight);
431+
UnitValue minHeightAsUv = UnitValue.createPointValue(minHeight);
432+
setProperty(Property.MIN_HEIGHT, minHeightAsUv);
430433
return (Image) (Object) this;
431434
}
432435

layout/src/main/java/com/itextpdf/layout/margincollapse/MarginsCollapseHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ This file is part of the iText (R) project.
4646
import com.itextpdf.layout.IPropertyContainer;
4747
import com.itextpdf.layout.property.FloatPropertyValue;
4848
import com.itextpdf.layout.property.Property;
49+
import com.itextpdf.layout.property.UnitValue;
4950
import com.itextpdf.layout.renderer.AbstractRenderer;
5051
import com.itextpdf.layout.renderer.BlockRenderer;
5152
import com.itextpdf.layout.renderer.CellRenderer;
@@ -519,11 +520,11 @@ private static boolean hasPositiveHeight(IRenderer renderer) {
519520
float height = renderer.getOccupiedArea().getBBox().getHeight();
520521

521522
if (height == 0) {
522-
Float heightPropVal = renderer.<Float>getProperty(Property.HEIGHT);
523-
Float minHeightPropVal = renderer.<Float>getProperty(Property.MIN_HEIGHT);
523+
UnitValue heightPropVal = renderer.<UnitValue>getProperty(Property.HEIGHT);
524+
UnitValue minHeightPropVal = renderer.<UnitValue>getProperty(Property.MIN_HEIGHT);
524525
height = minHeightPropVal != null
525-
? (float) minHeightPropVal
526-
: heightPropVal != null ? (float) heightPropVal : 0;
526+
? (float) minHeightPropVal.getValue()
527+
: heightPropVal != null ? (float) heightPropVal.getValue() : 0;
527528
}
528529
return height > 0;
529530
}

0 commit comments

Comments
 (0)