Skip to content

Commit

Permalink
#429 Tests/fixes break-word behavior with unbreakably large chars.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfickle committed Feb 1, 2020
1 parent 913c196 commit f4d8eec
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,24 @@ static LineBreakResult doBreakCharacters(
} else {
return LineBreakResult.CHAR_BREAKING_NEED_NEW_LINE;
}
} else {
// One character word, so we didn't find a wrap point.
float extraSpacing = nextWordBreak * letterSpacing;
int splitWidth = (int) (measurer.applyAsInt(currentString.substring(0, nextWordBreak)) + extraSpacing);
} else if (!currentString.isEmpty()) {
// Not even one character fit!
int end = 1;
float extraSpacing = letterSpacing;
int splitWidth = (int) (measurer.applyAsInt(currentString.substring(0, end)) + extraSpacing);

context.setUnbreakable(true);
context.setEnd(nextWordBreak + context.getStart());
context.setEndsOnWordBreak(true);
context.setEnd(end + context.getStart());
context.setEndsOnWordBreak(end == nextWordBreak);
context.setWidth(splitWidth);

return LineBreakResult.CHAR_BREAKING_UNBREAKABLE;
} else {
// Empty string.
context.setEnd(context.getStart());
context.setWidth(0);

return LineBreakResult.CHAR_BREAKING_FINISHED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,12 @@ public void testCharacterBreakerNoFit2() {

Breaker.doBreakCharacters(whole, createLine(whole), createChar(whole), context, avail, letterSpacing, MEASURER3);

// Breaks off minimum of one character.
assertTrue(context.isUnbreakable());
assertTrue(context.isNeedsNewLine());
assertThat(context.getWidth(), equalTo(18));
assertThat(context.getEnd(), equalTo(6));
assertThat(whole.substring(context.getEnd()), equalTo(""));
assertThat(context.getWidth(), equalTo(3));
assertThat(context.getEnd(), equalTo(1));
assertThat(whole.substring(context.getEnd()), equalTo("BCDEF"));
}

@Test
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<html>
<head>
<style>
@page {
size: 40mm 300mm;
margin: 5mm;
}
body {
word-wrap: break-word;
margin: 5mm;
border: 1px solid black;
width: 18mm;
}
</style>
</head>
<body>
<div style="font-size: 36mm;">ABC DEF</div>
<div style="font-size: 9mm;">ABC</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,14 @@ public void testIssue429BreakWordExtra() throws IOException {
public void testIssue429BreakWordExtraCentered() throws IOException {
assertTrue(vt.runTest("issue-429-break-word-extra-centered"));
}

/**
* Tests the behavior of very large unbreakable characters with break-word enabled.
*/
@Test
public void testIssue429BreakWordLargeChars() throws IOException {
assertTrue(vt.runTest("issue-429-break-word-large-chars"));
}

/**
* Tests break-word in the presence of floats.
Expand Down

0 comments on commit f4d8eec

Please sign in to comment.