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 @@ -
­
+
­
- \ No newline at end of file + diff --git a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java index 53b921943..c991a0046 100644 --- a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java +++ b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java @@ -1154,8 +1154,12 @@ public Reader getReader() { }))); } + /** + * Tests another endless loop bug when the font reports a non-zero width + * for soft hyphen and this overflows the width of the box in break-word + * mode. + */ @Test - @Ignore public void testIssue482InfiniteLoopTable() throws IOException { assertTrue(vt.runTest("issue-482-infinite-loop-table", builder -> { builder.useFont(() -> VisualRegressionTest.class.getClassLoader().getResourceAsStream("org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf"),