diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Layer.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Layer.java index f27226972..8192c8f00 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Layer.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Layer.java @@ -89,6 +89,8 @@ public class Layer { private int _selectionEndX; private int _selectionEndY; + private boolean _forDeletion; + /** * @see {@link #getCurrentTransformMatrix()} */ @@ -149,6 +151,14 @@ public boolean hasLocalTransform() { return _hasLocalTransform; } + public void setForDeletion(boolean forDeletion) { + this._forDeletion = forDeletion; + } + + public boolean isForDeletion() { + return this._forDeletion; + } + public Layer getParent() { return _parent; } @@ -259,7 +269,9 @@ public List collectLayers(int which) { for (Layer child : children) { if (! child.isStackingContext()) { - if (which == AUTO && child.isZIndexAuto()) { + if (child.isForDeletion()) { + // Do nothing... + } else if (which == AUTO && child.isZIndexAuto()) { result.add(child); } else if (which == NEGATIVE && child.getZIndex() < 0) { result.add(child); @@ -280,7 +292,9 @@ private List getStackingContextLayers(int which) { List children = getChildren(); for (Layer target : children) { - if (target.isStackingContext()) { + if (target.isForDeletion()) { + // Do nothing... + } else if (target.isStackingContext()) { if (!target.isZIndexAuto()) { int zIndex = target.getZIndex(); if (which == NEGATIVE && zIndex < 0) { @@ -894,6 +908,7 @@ public void detach() { if (getParent() != null) { getParent().remove(this); } + setForDeletion(true); } public boolean isInline() { diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java index 9a0a363e5..2b614633c 100755 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java @@ -845,8 +845,12 @@ public void layout(LayoutContext c, int contentStart) { pushedLayer = true; c.pushLayer(this); } else if (style.requiresLayer()) { + // FIXME: HACK. Some boxes can be layed out many times (to satisfy page constraints for example). + // If this happens we just mark our old layer for deletion and create a new layer. + // Not sure this is right, but doesn't break any correct tests. + this.getLayer().setForDeletion(true); pushedLayer = true; - c.pushLayer(this.getLayer()); + c.pushLayer(this); } if (style.isFixedBackground()) { diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/fixed-nested-float.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/fixed-nested-float.pdf new file mode 100644 index 000000000..e9d04a93c Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/fixed-nested-float.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/text/fixed-nested-float.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/text/fixed-nested-float.html index bc7dbc1c5..42632888b 100644 --- a/openhtmltopdf-examples/src/main/resources/visualtest/html/text/fixed-nested-float.html +++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/text/fixed-nested-float.html @@ -46,8 +46,8 @@
abcd
-
PAGE 1
+
PAGE 1
-
PAGE 2
+
PAGE 2
diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/text/positioning-absolute.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/text/positioning-absolute.html index 9f803d97b..404811e85 100644 --- a/openhtmltopdf-examples/src/main/resources/visualtest/html/text/positioning-absolute.html +++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/text/positioning-absolute.html @@ -47,7 +47,6 @@
DEF
GHI
JKL
-
MNO
diff --git a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/TextVisualRegressionTest.java b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/TextVisualRegressionTest.java index 2489b2860..39d6154a3 100644 --- a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/TextVisualRegressionTest.java +++ b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/TextVisualRegressionTest.java @@ -436,9 +436,6 @@ public void testFixedOnOverflowPages() throws IOException { * Tests that a nested float in a fixed element renders correctly. */ @Test - @Ignore // SERIOUS FAILURE - The footer element is not rendering. - // Appears to be an ordering issue of the layers as if header and footer swap element order - // everything works! public void testFixedNestedFloat() throws IOException { assertTrue(run("fixed-nested-float")); }