Skip to content

Commit bd3b83b

Browse files
committed
Process margins applied on text renderers.
DEVSIX-1552
1 parent a080e83 commit bd3b83b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ public LayoutResult layout(LayoutContext layoutContext) {
180180
Border[] borders = getBorders();
181181
applyBorderBox(layoutBox, borders, false);
182182

183+
float[] paddings = getPaddings();
184+
applyPaddings(layoutBox, paddings, false);
185+
183186
MinMaxWidth countedMinMaxWidth = new MinMaxWidth(area.getBBox().getWidth() - layoutBox.getWidth(), area.getBBox().getWidth());
184187
AbstractWidthHandler widthHandler = new MaxSumWidthHandler(countedMinMaxWidth);
185188

@@ -347,6 +350,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
347350
} else {
348351
// check if line height exceeds the allowed height
349352
if (Math.max(currentLineHeight, nonBreakablePartMaxHeight) > layoutBox.getHeight() && (null == overflowY || OverflowPropertyValue.FIT.equals(overflowY))) {
353+
applyPaddings(occupiedArea.getBBox(), paddings, true);
350354
applyBorderBox(occupiedArea.getBBox(), borders, true);
351355
applyMargins(occupiedArea.getBBox(), margins, true);
352356
// Force to place what we can
@@ -442,6 +446,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
442446
boolean isPlacingForcedWhileNothing = false;
443447
if (currentLineHeight > layoutBox.getHeight()) {
444448
if (!Boolean.TRUE.equals(getPropertyAsBoolean(Property.FORCED_PLACEMENT)) && (null == overflowY || OverflowPropertyValue.FIT.equals(overflowY))) {
449+
applyPaddings(occupiedArea.getBBox(), paddings, true);
445450
applyBorderBox(occupiedArea.getBBox(), borders, true);
446451
applyMargins(occupiedArea.getBBox(), margins, true);
447452
return new TextLayoutResult(LayoutResult.NOTHING, occupiedArea, null, this, this);
@@ -459,6 +464,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
459464
layoutBox.setHeight(area.getBBox().getHeight() - currentLineHeight);
460465

461466
occupiedArea.getBBox().setWidth(occupiedArea.getBBox().getWidth() + italicSkewAddition + boldSimulationAddition);
467+
applyPaddings(occupiedArea.getBBox(), paddings, true);
462468
applyBorderBox(occupiedArea.getBBox(), borders, true);
463469
applyMargins(occupiedArea.getBBox(), margins, true);
464470

@@ -594,6 +600,7 @@ public void draw(DrawContext drawContext) {
594600

595601
applyMargins(occupiedArea.getBBox(), getMargins(), false);
596602
applyBorderBox(occupiedArea.getBBox(), false);
603+
applyPaddings(occupiedArea.getBBox(), getPaddings(), false);
597604

598605
boolean isRelativePosition = isRelativePosition();
599606
if (isRelativePosition) {
@@ -750,6 +757,7 @@ public boolean accept(Glyph glyph) {
750757
applyRelativePositioningTranslation(false);
751758
}
752759

760+
applyPaddings(occupiedArea.getBBox(), true);
753761
applyBorderBox(occupiedArea.getBBox(), true);
754762
applyMargins(occupiedArea.getBBox(), getMargins(), true);
755763

@@ -1142,7 +1150,7 @@ protected boolean resolveFonts(List<IRenderer> addTo) {
11421150
FontSelectorStrategy strategy = provider.getStrategy(strToBeConverted,
11431151
FontFamilySplitter.splitFontFamily((String) font), fc, fontSet);
11441152
// process empty renderers because they can have borders or paddings with background to be drawn
1145-
if (null != strToBeConverted && strToBeConverted.isEmpty()) {
1153+
if (null == strToBeConverted || strToBeConverted.isEmpty()) {
11461154
addTo.add(this);
11471155
} else {
11481156
while (!strategy.endOfText()) {

0 commit comments

Comments
 (0)