Skip to content

Commit

Permalink
Merge pull request danfickle#587 from vipcxj/open-dev-v1
Browse files Browse the repository at this point in the history
Fixes danfickle#302 nowrap text inside wrap text breaking.
  • Loading branch information
danfickle authored Oct 28, 2020
2 parents f14e3b8 + cf3ccc8 commit ed2bd9c
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,24 @@ public static LineBreakResult breakText(LayoutContext c,

// ====== handle nowrap
if (whitespace == IdentValue.NOWRAP) {
context.setEnd(context.getLast());
context.setWidth(Breaker.getTextWidthWithLetterSpacing(c, font, context.getCalculatedSubstring(), letterSpacing));
return LineBreakResult.WORD_BREAKING_FINISHED;
int width = Breaker.getTextWidthWithLetterSpacing(c, font, context.getMaster(), letterSpacing);
if (width <= avail) {
c.setLineBreakedBecauseOfNoWrap(false);
context.setEnd(context.getLast());
context.setWidth(width);
return LineBreakResult.WORD_BREAKING_FINISHED;
} else if (!c.isLineBreakedBecauseOfNoWrap()) {
c.setLineBreakedBecauseOfNoWrap(true);
context.setEnd(context.getStart());
context.setWidth(0);
context.setNeedsNewLine(true);
return LineBreakResult.WORD_BREAKING_NEED_NEW_LINE;
} else {
c.setLineBreakedBecauseOfNoWrap(false);
context.setEnd(context.getLast());
context.setWidth(width);
return LineBreakResult.WORD_BREAKING_FINISHED;
}
}

//check if we should break on the next newline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public class LayoutContext implements CssContext {

private boolean _mayCheckKeepTogether = true;

private boolean _lineBreakedBecauseOfNoWrap = false;

private BreakAtLineContext _breakAtLineContext;

private Boolean isPrintOverride = null; // True, false, or null for no override.
Expand Down Expand Up @@ -600,6 +602,14 @@ public void setMayCheckKeepTogether(boolean mayKeepTogether) {
_mayCheckKeepTogether = mayKeepTogether;
}

public boolean isLineBreakedBecauseOfNoWrap() {
return _lineBreakedBecauseOfNoWrap;
}

public void setLineBreakedBecauseOfNoWrap(boolean value) {
_lineBreakedBecauseOfNoWrap = value;
}

public BreakAtLineContext getBreakAtLineContext() {
return _breakAtLineContext;
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<head>
<style>
@page {
size: 300px 350px;
margin: 10px;
}
body {
margin: 20px;
max-width: 280px;
color: red;
border: 1px solid pink;
}
.nowrap {
white-space: nowrap;
color: blue;
}
.wrap {
white-space: normal;
color: red;
}
</style>
</head>
<body style="font-family: 'TestFont'; font-size: 20px;">
Text should wrap before <span class="nowrap">a very long <span class="wrap">unwrappable wrap</span> span some more very long</span>

Text should wrap before <span class="nowrap">a very long <span class="wrap">unwrappable</span> nowrap span some more very long</span>

Text should wrap before <span class="nowrap">a very long <span class="wrap">unwrappable <span class="nowrap">wrap some more content testing 123</span></span> nowrap span some more very long</span>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<html>
<head>
<style>
@page {
size: 21cm 9cm;
}
/* Unrelated workaround for bug where top/bottom margin
* on page does not collapse correctly. */
p:first-child {
margin-top: 0;
}
p:last-child {
margin-bottom: 0;
}
</style>
</head>
<body style="border: 1px solid black;">
<div style="width:90%; line-height: 1.3;">
<p>
Some text.Some text.Some text.Some text.Some text.Some text.Some text.Some text.
<span style="white-space: nowrap; border-bottom: 1px solid red;">This text should be at next line.</span>
Other text. Other text. Other text. Other text. Other text. Other text. Other text.
</p>
<p>
Some text.Some text.
<span style="white-space: nowrap; border-bottom: 1px solid red;">This text should not be at next line.</span>
Other text. Other text. Other text. Other text. Other text. Other text. Other text.
</p>
<p>
Some text.Some text.Some text.Some text.Some text.Some text.Some text.Some text.
<span style="white-space: nowrap; border-bottom: 1px solid red;">This is a very very very very very very very very very very very very very very very very very very very very very very long nowrap text.</span>
Other text. Other text. Other text. Other text. Other text. Other text. Other text.
</p>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,26 @@ public void testHorizPageOverflowTransform3() throws IOException {
* Tests that a nowrap span inside a line wraps to a new line if needed. Issue 302.
*/
@Test
@Ignore // Greedily puts nowrap span on same line even though it does not fit.
public void testLineWrapNoWrapSpan() throws IOException {
assertTrue(run("line-wrap-nowrap-span"));
}

/**
* Tests that various nested nowrap spans inside normal wrap works.
*/
@Test
public void testPr587LineWrapNoWrapSpanNested() throws IOException {
assertTrue(run("line-wrap-nowrap-span-nested"));
}

/**
* Test provided with pr#587, fix for break before nowrap span.
*/
@Test
public void testPr587FixForBreakBeforeNoWrap() throws IOException {
assertTrue(run("nowrap"));
}

/**
* Tests that an element boundary is NOT seen as a line break opportunity by itself (eg. mid word). Issue 39.
*/
Expand Down

0 comments on commit ed2bd9c

Please sign in to comment.