aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/java2d
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/render/java2d')
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DRenderer.java80
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java37
2 files changed, 56 insertions, 61 deletions
diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
index 65e6ac0fe..933398125 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
@@ -135,7 +135,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
/** The current state, holds a Graphics2D and its context */
protected Java2DGraphicsState state;
- private Stack stateStack = new Stack();
+ private final Stack stateStack = new Stack();
/** true if the renderer has finished rendering all the pages */
private boolean renderingDone;
@@ -146,9 +146,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
public Java2DRenderer() {
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void setUserAgent(FOUserAgent foUserAgent) {
super.setUserAgent(foUserAgent);
userAgent.setRendererOverride(this); // for document regeneration
@@ -164,9 +162,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
return userAgent;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void setupFontInfo(FontInfo inFontInfo) {
//Don't call super.setupFontInfo() here! Java2D needs a special font setup
// create a temp Image to test font metrics on
@@ -437,16 +433,12 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
state.transform(new AffineTransform(CTMHelper.toPDFArray(ctm)));
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void endVParea() {
restoreGraphicsState();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected List breakOutOfStateStack() {
log.debug("Block.FIXED --> break out");
List breakOutList;
@@ -459,10 +451,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
return breakOutList;
}
- /**
- * {@inheritDoc}
- * java.util.List)
- */
+ /** {@inheritDoc} */
protected void restoreStateStackAfterBreakOut(List breakOutList) {
log.debug("Block.FIXED --> restoring context after break-out");
@@ -474,16 +463,12 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void updateColor(Color col, boolean fill) {
state.updateColor(col);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void clip() {
if (currentPath == null) {
throw new IllegalStateException("No current path available!");
@@ -492,16 +477,12 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
currentPath = null;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void closePath() {
currentPath.closePath();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void lineTo(float x, float y) {
if (currentPath == null) {
currentPath = new GeneralPath();
@@ -509,9 +490,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
currentPath.lineTo(x, y);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void moveTo(float x, float y) {
if (currentPath == null) {
currentPath = new GeneralPath();
@@ -519,23 +498,17 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
currentPath.moveTo(x, y);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void clipRect(float x, float y, float width, float height) {
state.updateClip(new Rectangle2D.Float(x, y, width, height));
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void fillRect(float x, float y, float width, float height) {
state.getGraph().fill(new Rectangle2D.Float(x, y, width, height));
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void drawBorderLine(float x1, float y1, float x2, float y2,
boolean horz, boolean startOrBefore, int style, Color col) {
Graphics2D g2d = state.getGraph();
@@ -706,9 +679,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void renderText(TextArea text) {
renderInlineAreaBackAndBorders(text);
@@ -890,18 +861,20 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
super.renderLeader(area);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void renderImage(Image image, Rectangle2D pos) {
// endTextObject();
String url = image.getURL();
drawImage(url, pos);
}
- /**
- * {@inheritDoc}
- */
+ private static final ImageFlavor[] FLAVOURS = new ImageFlavor[]
+ {ImageFlavor.GRAPHICS2D,
+ ImageFlavor.BUFFERED_IMAGE,
+ ImageFlavor.RENDERED_IMAGE,
+ ImageFlavor.XML_DOM};
+
+ /** {@inheritDoc} */
protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
int x = currentIPPosition + (int)Math.round(pos.getX());
@@ -913,14 +886,9 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
try {
ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
info = manager.getImageInfo(uri, sessionContext);
- final ImageFlavor[] flavors = new ImageFlavor[]
- {ImageFlavor.GRAPHICS2D,
- ImageFlavor.BUFFERED_IMAGE,
- ImageFlavor.RENDERED_IMAGE,
- ImageFlavor.XML_DOM};
Map hints = ImageUtil.getDefaultHints(sessionContext);
org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
- info, flavors, hints, sessionContext);
+ info, FLAVOURS, hints, sessionContext);
if (img instanceof ImageGraphics2D) {
ImageGraphics2D imageG2D = (ImageGraphics2D)img;
int width = (int)pos.getWidth();
diff --git a/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java b/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java
index 12b269a44..99502096c 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java
@@ -20,6 +20,8 @@
package org.apache.fop.render.java2d;
import java.awt.geom.AffineTransform;
+import java.io.IOException;
+import java.util.Map;
import org.w3c.dom.Document;
@@ -29,9 +31,11 @@ import org.apache.batik.gvt.GraphicsNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.image.loader.batik.BatikUtil;
import org.apache.fop.render.AbstractGenericSVGHandler;
import org.apache.fop.render.Renderer;
import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RendererContextConstants;
import org.apache.fop.svg.SVGEventProducer;
import org.apache.fop.svg.SVGUserAgent;
@@ -66,6 +70,11 @@ public class Java2DSVGHandler extends AbstractGenericSVGHandler
pdfi.height = ((Integer)context.getProperty(HEIGHT)).intValue();
pdfi.currentXPosition = ((Integer)context.getProperty(XPOS)).intValue();
pdfi.currentYPosition = ((Integer)context.getProperty(YPOS)).intValue();
+ Map foreign = (Map)context.getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES);
+ if (foreign != null
+ && BITMAP.equalsIgnoreCase((String)foreign.get(CONVERSION_MODE))) {
+ pdfi.paintAsBitmap = true;
+ }
return pdfi;
}
@@ -83,6 +92,7 @@ public class Java2DSVGHandler extends AbstractGenericSVGHandler
public int currentXPosition;
/** see Java2D_YPOS */
public int currentYPosition;
+ public boolean paintAsBitmap;
/** {@inheritDoc} */
public String toString() {
@@ -91,7 +101,8 @@ public class Java2DSVGHandler extends AbstractGenericSVGHandler
+ "width = " + width + ", "
+ "height = " + height + ", "
+ "currentXPosition = " + currentXPosition + ", "
- + "currentYPosition = " + currentYPosition + "}";
+ + "currentYPosition = " + currentYPosition + ", "
+ + "paintAsBitmap = " + paintAsBitmap + "}";
}
}
@@ -103,17 +114,33 @@ public class Java2DSVGHandler extends AbstractGenericSVGHandler
log.debug("renderSVGDocument(" + context + ", " + doc + ", " + info + ")");
}
+ // fallback paint as bitmap
+ if (info.paintAsBitmap) {
+ try {
+ super.renderSVGDocument(context, doc);
+ } catch (IOException ioe) {
+ SVGEventProducer eventProducer = SVGEventProducer.Provider.get(
+ context.getUserAgent().getEventBroadcaster());
+ eventProducer.svgRenderingError(this, ioe, getDocumentURI(doc));
+ }
+ return;
+ }
+
int x = info.currentXPosition;
int y = info.currentYPosition;
SVGUserAgent ua = new SVGUserAgent(context.getUserAgent(), new AffineTransform());
- GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(ua);
+ //Cloning SVG DOM as Batik attaches non-thread-safe facilities (like the CSS engine)
+ //to it.
+ Document clonedDoc = BatikUtil.cloneSVGDocument(doc);
+
GraphicsNode root;
try {
- root = builder.build(ctx, doc);
+ GVTBuilder builder = new GVTBuilder();
+ root = builder.build(ctx, clonedDoc);
} catch (Exception e) {
SVGEventProducer eventProducer = SVGEventProducer.Provider.get(
context.getUserAgent().getEventBroadcaster());
@@ -126,8 +153,8 @@ public class Java2DSVGHandler extends AbstractGenericSVGHandler
float iw = (float) ctx.getDocumentSize().getWidth() * 1000f;
float ih = (float) ctx.getDocumentSize().getHeight() * 1000f;
- float w = (float) info.width;
- float h = (float) info.height;
+ float w = info.width;
+ float h = info.height;
AffineTransform origTransform = info.state.getGraph().getTransform();