diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java index 6b9efa9ae..79d20e02c 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java @@ -173,15 +173,9 @@ public static LineBreakResult breakText(LayoutContext c, context.setEnd(savedEnd); continue LOOP; } else { - if (context.getWidth() == 0) { - String calculatedSubstring = context.getCalculatedSubstring(); - if (calculatedSubstring.chars().allMatch(ch -> ch == SOFT_HYPHEN)) { - // Consists only of soft hypen, we have to break here and skip all togheter. We do not - // need to try breaking on the charater level, this will not work. - tryToBreakAnywhere = true; - } - } // Else, retry it on a new line. + // FIXME: This is very dangerous and has led to infinite + // loops. Needs review. context.setEnd(savedEnd); break LOOP; } @@ -501,7 +495,9 @@ public static LineBreakResult doBreakText( context.setEnd(context.getStart() + current.left); context.setUnbreakable(true); - if (current.left == currentString.length()) { + if (current.isSoftHyphenBreak) { + context.setWidth(current.withHyphenGraphicsLength); + } else if (current.left == currentString.length()) { String text = context.getCalculatedSubstring(); float extraSpacing = text.length() * letterSpacing; context.setWidth((int) (c.getTextRenderer().getWidth( @@ -509,7 +505,6 @@ public static LineBreakResult doBreakText( } else { context.setWidth(current.graphicsLength); } - return LineBreakResult.WORD_BREAKING_UNBREAKABLE; } } diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-482-infinite-loop-table.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-482-infinite-loop-table.pdf new file mode 100644 index 000000000..664c98497 Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-482-infinite-loop-table.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-482-infinite-loop-table.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-482-infinite-loop-table.html index f421bc445..c72b84e6b 100644 --- a/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-482-infinite-loop-table.html +++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-482-infinite-loop-table.html @@ -1,19 +1,19 @@
- |