Skip to content

Commit

Permalink
#615 Take account of margins when clearing floats.
Browse files Browse the repository at this point in the history
With test proofs (new and updated for transform float which was also not taking account of margin).
  • Loading branch information
danfickle committed Dec 18, 2020
1 parent 8103c1b commit b15d52b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;

import com.openhtmltopdf.css.style.CssContext;
import com.openhtmltopdf.css.style.derived.RectPropertySet;
import com.openhtmltopdf.render.BlockBox;
import com.openhtmltopdf.render.Box;
import com.openhtmltopdf.render.LineBox;
Expand All @@ -53,7 +53,7 @@ public enum FloatDirection {
public FloatManager(Box master) {
this._master = master;
}

private List<BoxOffset> getAddableFloats(FloatDirection direction) {
if (getFloats(direction).isEmpty()) {
setFloats(direction, new ArrayList<>());
Expand Down Expand Up @@ -342,8 +342,14 @@ public int getNextLineBoxDelta(CssContext cssCtx, BlockFormattingContext bfc,

private int calcDelta(CssContext cssCtx, LineBox line, BoxDistance boxDistance) {
BlockBox floated = boxDistance.getBox();

Rectangle rect = floated.getBorderEdge(floated.getAbsX(), floated.getAbsY(), cssCtx);
int bottom = rect.y + rect.height;
RectPropertySet margin = floated.getMargin(cssCtx);

// NOTE: This was not taking account of margins and thus was not clearing properly.
// See: https://github.com/danfickle/openhtmltopdf/pull/618
int bottom = (int) Math.ceil(rect.y + rect.height + margin.bottom());

return bottom - line.getAbsY();
}

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1326,9 +1326,11 @@ public void testSVGFontFileAddition() throws IOException, FontFormatException {
}));
}

/**
* Tests no infinite loop with this input and that floats
* with a margin are being cleared properly (the root cause)
*/
@Test
@Ignore // No more infinite loop, but being force output at the right
// instead of being pushed below the float.
public void testIssue615InfiniteLoopBreakWord() throws IOException {
assertTrue(vt.runTest("issue-615-infinite-loop-break-word"));
}
Expand Down

0 comments on commit b15d52b

Please sign in to comment.