diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/BoxBuilder.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/BoxBuilder.java
index 60375bc8f..d62ba5ac6 100644
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/BoxBuilder.java
+++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/BoxBuilder.java
@@ -125,12 +125,12 @@ public static BlockBox createRootBox(LayoutContext c, Document document) {
}
public static void createChildren(LayoutContext c, BlockBox parent) {
-
- if (parent.isReplaced()) {
+
+ if (parent.shouldBeReplaced()) {
return;
}
- List children = new ArrayList();
+ List children = new ArrayList();
ChildBoxInfo info = new ChildBoxInfo();
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 bff0ef198..cbc8f2f86 100755
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java
+++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java
@@ -417,8 +417,12 @@ public void setStaticEquivalent(Box staticEquivalent) {
_staticEquivalent = staticEquivalent;
}
+ public boolean shouldBeReplaced() {
+ return _isReplaced;
+ }
+
public boolean isReplaced() {
- return _replacedElement != null || _isReplaced;
+ return _replacedElement != null;
}
public void calcCanvasLocation() {
@@ -449,7 +453,7 @@ public void calcCanvasLocation() {
setAbsY(lineBox.getAbsY() + getY());
}
- if (isReplaced() && getReplacedElement() != null) {
+ if (isReplaced()) {
Point location = getReplacedElement().getLocation();
if (location.x != getAbsX() || location.y != getAbsY()) {
getReplacedElement().setLocation(getAbsX(), getAbsY());
@@ -811,7 +815,6 @@ public void layout(LayoutContext c) {
public void layout(LayoutContext c, int contentStart) {
CalculatedStyle style = getStyle();
-
boolean pushedLayer = false;
if (isRoot() || style.requiresLayer()) {
pushedLayer = true;
@@ -1522,7 +1525,7 @@ public void calcMinMaxWidth(LayoutContext c) {
int width = getCSSWidth(c, true);
if (width == -1) {
- if (isReplaced() && getReplacedElement() != null) {
+ if (getReplacedElement() != null) {
width = getReplacedElement().getIntrinsicWidth();
} else {
int height = getCSSHeight(c);
diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/displaylist/DisplayListCollector.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/displaylist/DisplayListCollector.java
index eb879f60f..cfab1ccf4 100644
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/displaylist/DisplayListCollector.java
+++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/displaylist/DisplayListCollector.java
@@ -68,6 +68,11 @@ private void collect(RenderingContext c, Layer layer, DisplayListContainer dlPag
}
if (!layer.isInline() && ((BlockBox) layer.getMaster()).isReplaced()) {
+ if (((BlockBox) layer.getMaster()).getReplacedElement() == null) {
+ System.out.println(layer.getMaster().getElement().getAttribute("style"));
+ } else
+
+
collectReplacedElementLayer(c, layer, dlPages, pages);
} else {
@@ -175,17 +180,13 @@ private void collectLayerBackgroundAndBorder(RenderingContext c, Layer layer,
private void collectReplacedElementLayer(RenderingContext c, Layer layer,
DisplayListContainer dlPages, List pages) {
- if (layer.getMaster() instanceof BlockBox) {
- DisplayListOperation dlo = new PaintLayerBackgroundAndBorder(layer.getMaster());
- int pgStart = PagedBoxCollector.findStartPage(c, layer.getMaster(), pages);
- int pgEnd = PagedBoxCollector.findEndPage(c, layer.getMaster(), pages);
- addItem(dlo, pgStart, pgEnd, dlPages);
- }
-
- DisplayListOperation dlo = new PaintReplacedElement((BlockBox) layer.getMaster());
+ DisplayListOperation dlo = new PaintLayerBackgroundAndBorder(layer.getMaster());
int pgStart = PagedBoxCollector.findStartPage(c, layer.getMaster(), pages);
int pgEnd = PagedBoxCollector.findEndPage(c, layer.getMaster(), pages);
addItem(dlo, pgStart, pgEnd, dlPages);
+
+ DisplayListOperation dlo2 = new PaintReplacedElement((BlockBox) layer.getMaster());
+ addItem(dlo2, pgStart, pgEnd, dlPages);
}
// Bit of a kludge here. We need to paint collapsed table borders according
diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/displaylist/DisplayListPainter.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/displaylist/DisplayListPainter.java
index 0719db1b3..aaf777d87 100644
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/displaylist/DisplayListPainter.java
+++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/displaylist/DisplayListPainter.java
@@ -1,5 +1,7 @@
package com.openhtmltopdf.render.displaylist;
+import java.awt.Point;
+import java.awt.Rectangle;
import java.util.List;
import java.util.Map;
@@ -86,10 +88,25 @@ private void paintReplacedElements(RenderingContext c, List rep
c.getOutputDevice().setClip(setClip.getSetClipShape());
} else {
BlockBox box = (BlockBox) dli;
- c.getOutputDevice().paintReplacedElement(c, box);
+ paintReplacedElement(c, box);
}
}
}
+
+ private void paintReplacedElement(RenderingContext c, BlockBox replaced) {
+
+ Rectangle contentBounds = replaced.getContentAreaEdge(
+ replaced.getAbsX(), replaced.getAbsY(), c);
+
+ // Minor hack: It's inconvenient to adjust for margins, border, padding during
+ // layout so just do it here.
+ Point loc = replaced.getReplacedElement().getLocation();
+ if (contentBounds.x != loc.x || contentBounds.y != loc.y) {
+ replaced.getReplacedElement().setLocation(contentBounds.x, contentBounds.y);
+ }
+
+ c.getOutputDevice().paintReplacedElement(c, replaced);
+ }
public void paint(RenderingContext c, DisplayListPageContainer pageOperations) {
for (DisplayListOperation op : pageOperations.getOperations()) {
@@ -108,7 +125,7 @@ public void paint(RenderingContext c, DisplayListPageContainer pageOperations) {
} else if (op instanceof PaintReplacedElement) {
PaintReplacedElement dlo = (PaintReplacedElement) op;
- c.getOutputDevice().paintReplacedElement(c, dlo.getMaster());
+ paintReplacedElement(c, dlo.getMaster());
} else if (op instanceof PaintBackgroundAndBorders) {
diff --git a/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxRenderer.java b/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxRenderer.java
index e5aaa00cd..8ce67ac42 100644
--- a/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxRenderer.java
+++ b/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxRenderer.java
@@ -41,7 +41,6 @@
import com.openhtmltopdf.render.ViewportBox;
import com.openhtmltopdf.render.displaylist.DisplayListCollector;
import com.openhtmltopdf.render.displaylist.DisplayListContainer;
-import com.openhtmltopdf.render.displaylist.DisplayListOperation;
import com.openhtmltopdf.render.displaylist.DisplayListPainter;
import com.openhtmltopdf.render.displaylist.DisplayListContainer.DisplayListPageContainer;
import com.openhtmltopdf.resource.XMLResource;
@@ -491,7 +490,6 @@ public void createPDF(OutputStream os, boolean finish, int initialPageNo) throws
* - inline-blocks
* - hidden overflow
* - transforms
- * - fine positioning of replaced elements.
* - debugging everything
*/
public void createPdfFast(boolean finish) throws IOException {