Skip to content

Commit a009bcd

Browse files
yulian-gaponenkoUbuntu
authored andcommitted
Fix margin-border-padding widths for floating Text min-max-width calculation
DEVSIX-3958
1 parent d3b3998 commit a009bcd

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
196196
FloatingHelper.adjustFloatedBlockLayoutBox(this, layoutBox, null, floatRendererAreas, floatPropertyValue, overflowX);
197197
}
198198

199+
float preMarginBorderPaddingWidth = layoutBox.getWidth();
199200
UnitValue[] margins = getMargins();
200201
applyMargins(layoutBox, margins, false);
201202
Border[] borders = getBorders();
@@ -204,7 +205,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
204205
UnitValue[] paddings = getPaddings();
205206
applyPaddings(layoutBox, paddings, false);
206207

207-
MinMaxWidth countedMinMaxWidth = new MinMaxWidth(area.getBBox().getWidth() - layoutBox.getWidth());
208+
MinMaxWidth countedMinMaxWidth = new MinMaxWidth(preMarginBorderPaddingWidth - layoutBox.getWidth());
208209
AbstractWidthHandler widthHandler;
209210
if (noSoftWrap) {
210211
widthHandler = new SumSumWidthHandler(countedMinMaxWidth);

layout/src/test/java/com/itextpdf/layout/renderer/TextRendererTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,26 @@ public void overflowWrapAnywhereItalicSimulationMinWidth() {
385385

386386
Assert.assertTrue(minWidthAndItalicSimulation > minWidthNoItalicSimulation);
387387
}
388+
389+
@Test
390+
public void floatingRightMinMaxWidth() throws IOException {
391+
String longestWord = "float:right";
392+
String wholeText = "text with " + longestWord;
393+
TextRenderer textRenderer = new TextRenderer(new Text(wholeText));
394+
textRenderer.setProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
395+
396+
textRenderer.setParent(createDummyDocument().getRenderer());
397+
398+
PdfFont font = PdfFontFactory.createFont();
399+
int fontSize = 12;
400+
textRenderer.setProperty(Property.FONT, font);
401+
textRenderer.setProperty(Property.FONT_SIZE, UnitValue.createPointValue(fontSize));
402+
403+
float expectedMaxWidth = font.getWidth(wholeText, fontSize);
404+
float expectedMinWidth = font.getWidth(longestWord, fontSize);
405+
406+
MinMaxWidth minMaxWidth = textRenderer.getMinMaxWidth();
407+
Assert.assertEquals(expectedMinWidth, minMaxWidth.getMinWidth(), 0.01f);
408+
Assert.assertEquals(expectedMaxWidth, minMaxWidth.getMaxWidth(), 0.01f);
409+
}
388410
}

0 commit comments

Comments
 (0)