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 @@
-PAGE 1
+PAGE 1
-PAGE 2
+PAGE 2