Skip to content

Commit 68055cb

Browse files
author
Vitali Prudnikovich
committed
Wrap inline block with relative width to new line if there is not enough space on current line
DEVSIX-5796, DEVSIX-1823, DEVSIX-6143
1 parent df66dc9 commit 68055cb

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,20 @@ && hasChildRendererInHtmlMode()) {
352352

353353
MinMaxWidth childBlockMinMaxWidth = null;
354354
boolean isInlineBlockChild = isInlineBlockChild(childRenderer);
355-
if (!childWidthWasReplaced) {
356-
if (isInlineBlockChild && childRenderer instanceof AbstractRenderer) {
357-
childBlockMinMaxWidth = ((AbstractRenderer) childRenderer).getMinMaxWidth();
358-
float childMaxWidth = childBlockMinMaxWidth.getMaxWidth();
359-
float lineFullAvailableWidth = layoutContext.getArea().getBBox().getWidth() - lineLayoutContext.getTextIndent();
360-
if (!noSoftWrap && childMaxWidth > bbox.getWidth() + MIN_MAX_WIDTH_CORRECTION_EPS && bbox.getWidth() != lineFullAvailableWidth) {
361-
childResult = new LineLayoutResult(LayoutResult.NOTHING, null, null, childRenderer, childRenderer);
362-
} else {
355+
if (isInlineBlockChild && childRenderer instanceof AbstractRenderer) {
356+
final MinMaxWidth childBlockMinMaxWidthLocal = ((AbstractRenderer) childRenderer).getMinMaxWidth();
357+
// Don't calculate childBlockMinMaxWidth in case of relative width here
358+
// and further (childBlockMinMaxWidth != null)
359+
if (!childWidthWasReplaced) {
360+
childBlockMinMaxWidth = childBlockMinMaxWidthLocal;
361+
}
362+
363+
float childMaxWidth = childBlockMinMaxWidthLocal.getMaxWidth();
364+
float lineFullAvailableWidth = layoutContext.getArea().getBBox().getWidth() - lineLayoutContext.getTextIndent();
365+
if (!noSoftWrap && childMaxWidth > bbox.getWidth() + MIN_MAX_WIDTH_CORRECTION_EPS && bbox.getWidth() != lineFullAvailableWidth) {
366+
childResult = new LineLayoutResult(LayoutResult.NOTHING, null, null, childRenderer, childRenderer);
367+
} else {
368+
if (childBlockMinMaxWidth != null) {
363369
childMaxWidth += MIN_MAX_WIDTH_CORRECTION_EPS;
364370
float inlineBlockWidth = Math.min(childMaxWidth, lineFullAvailableWidth);
365371

@@ -376,8 +382,13 @@ && hasChildRendererInHtmlMode()) {
376382
childRenderer.setProperty(Property.FORCED_PLACEMENT, true);
377383
}
378384
}
379-
childBlockMinMaxWidth.setChildrenMaxWidth(childBlockMinMaxWidth.getChildrenMaxWidth() + MIN_MAX_WIDTH_CORRECTION_EPS);
380-
childBlockMinMaxWidth.setChildrenMinWidth(childBlockMinMaxWidth.getChildrenMinWidth() + MIN_MAX_WIDTH_CORRECTION_EPS);
385+
}
386+
387+
if (childBlockMinMaxWidth != null) {
388+
childBlockMinMaxWidth.setChildrenMaxWidth(
389+
childBlockMinMaxWidth.getChildrenMaxWidth() + MIN_MAX_WIDTH_CORRECTION_EPS);
390+
childBlockMinMaxWidth.setChildrenMinWidth(
391+
childBlockMinMaxWidth.getChildrenMinWidth() + MIN_MAX_WIDTH_CORRECTION_EPS);
381392
}
382393
}
383394

layout/src/test/java/com/itextpdf/layout/InlineBlockTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ public void wrappingAfter100PercentWidthFloatTest() throws IOException, Interrup
193193
);
194194
}
195195

196-
// TODO DEVSIX-5796 inline-block should be wrapped to the next line
197196
Assert.assertNull(new CompareTool().compareByContent(output, cmp, destinationFolder));
198197
}
199198
}

0 commit comments

Comments
 (0)