Skip to content

Commit f82c54b

Browse files
authored
Merge pull request #483 from rototor/testcase-for-#482
Fixes #482: Testcase And fix for the endless loop because of soft hyphen on empty line.
2 parents 9034e37 + a486953 commit f82c54b

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ public static LineBreakResult breakText(LayoutContext c,
173173
context.setEnd(savedEnd);
174174
continue LOOP;
175175
} else {
176+
if (context.getWidth() == 0) {
177+
String calculatedSubstring = context.getCalculatedSubstring();
178+
if (calculatedSubstring.chars().allMatch(ch -> ch == SOFT_HYPHEN)) {
179+
// Consists only of soft hypen, we have to break here and skip all togheter. We do not
180+
// need to try breaking on the charater level, this will not work.
181+
tryToBreakAnywhere = true;
182+
}
183+
}
176184
// Else, retry it on a new line.
177185
context.setEnd(savedEnd);
178186
break LOOP;

openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlineBoxing.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ private static void startNewInlineLine(LayoutContext c, BlockBox box, int breakA
373373
* layout box.
374374
* Otherwise, if there are floats and the current line is otherwise empty, moves below float and trys again.
375375
* Otherwise, trys again on a new line.
376+
* @return true if the line is finished, false if we must continue
376377
*/
377378
private static boolean startInlineText(
378379
LayoutContext c, LineBreakContext lbContext, InlineBox inlineBox,

openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/TestcaseRunner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class TestcaseRunner {
5151
*/
5252
public static void main(String[] args) throws Exception {
5353

54+
runTestCase("soft-hypen-oom");
55+
5456
/*
5557
* Note: The RepeatedTableSample optionally requires the font file
5658
* NotoSans-Regular.ttf to be placed in the resources directory.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html>
3+
<head>
4+
<style>
5+
* {
6+
margin: 0;
7+
padding: 0;
8+
}
9+
10+
.content {
11+
word-wrap: break-word;
12+
white-space:pre-wrap;
13+
}
14+
</style>
15+
</head>
16+
<body>
17+
<table class="content">
18+
<tr>
19+
<td>­</td>
20+
</tr>
21+
<tr>
22+
<td>­­</td>
23+
</tr>
24+
<tr>
25+
<td>­­­</td>
26+
</tr>
27+
</table>
28+
<table class="content">
29+
<tr>
30+
<td> ­</td>
31+
</tr>
32+
<tr>
33+
<td>­ ­</td>
34+
</tr>
35+
<tr>
36+
<td>­ ­ ­</td>
37+
</tr>
38+
</table>
39+
</body>
40+
</html>

0 commit comments

Comments
 (0)