aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorGlen Mazza <gmazza@apache.org>2003-10-11 14:48:49 +0000
committerGlen Mazza <gmazza@apache.org>2003-10-11 14:48:49 +0000
commita43647226be1b1ada209d5b4c51f3f866a501fbd (patch)
treea057b5d94de370144cd2f7bba4a1c42f89723e3b /src/java
parent11b030a2ae8561afeda28e199b42abab6e4ec567 (diff)
downloadxmlgraphics-fop-a43647226be1b1ada209d5b4c51f3f866a501fbd.tar.gz
xmlgraphics-fop-a43647226be1b1ada209d5b4c51f3f866a501fbd.zip
Applied Tom DeWeese/Batik Team's SVG patches. New Batik.jar created from latest CVS build, using Batik's "all-jar" target.
PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196955 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/fop/render/ps/PSTranscoder.java138
-rw-r--r--src/java/org/apache/fop/svg/AbstractFOPTranscoder.java4
-rw-r--r--src/java/org/apache/fop/svg/PDFImageElementBridge.java49
-rw-r--r--src/java/org/apache/fop/svg/PDFTranscoder.java161
4 files changed, 106 insertions, 246 deletions
diff --git a/src/java/org/apache/fop/render/ps/PSTranscoder.java b/src/java/org/apache/fop/render/ps/PSTranscoder.java
index d5be860d3..76f2771c9 100644
--- a/src/java/org/apache/fop/render/ps/PSTranscoder.java
+++ b/src/java/org/apache/fop/render/ps/PSTranscoder.java
@@ -116,6 +116,8 @@ import org.w3c.dom.svg.SVGSVGElement;
*/
public class PSTranscoder extends AbstractFOPTranscoder {
+ protected PSDocumentGraphics2D graphics = null;
+
/**
* Constructs a new <tt>PSTranscoder</tt>.
*/
@@ -132,21 +134,38 @@ public class PSTranscoder extends AbstractFOPTranscoder {
* @exception TranscoderException if an error occured while transcoding
*/
protected void transcode(Document document, String uri,
- TranscoderOutput output) throws TranscoderException {
+ TranscoderOutput output)
+ throws TranscoderException {
+
+ graphics = new PSDocumentGraphics2D(false);
+
+ super.transcode(document, uri, output);
- if (!(document instanceof SVGOMDocument)) {
- throw new TranscoderException(Messages.formatMessage("notsvg",
- null));
+ // prepare the image to be painted
+ int w = (int)(width+.5);
+ int h = (int)(height+.5);
+
+ try {
+ graphics.setupDocument(output.getOutputStream(), w, h);
+ graphics.setSVGDimension(width, height);
+
+ if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
+ graphics.setBackgroundColor
+ ((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
}
- SVGDocument svgDoc = (SVGDocument)document;
- SVGSVGElement root = svgDoc.getRootElement();
- // initialize the SVG document with the appropriate context
- String parserClassname = (String)hints.get(KEY_XML_PARSER_CLASSNAME);
+ graphics.setGraphicContext
+ (new org.apache.batik.ext.awt.g2d.GraphicContext());
+ graphics.setTransform(curTxf);
- PSDocumentGraphics2D graphics = new PSDocumentGraphics2D(false);
+ this.root.paint(graphics);
+
+ graphics.finish();
+ } catch (IOException ex) {
+ throw new TranscoderException(ex);
+ }
+ }
- // build the GVT tree
- GVTBuilder builder = new GVTBuilder();
+ protected BridgeContext createBridgeContext() {
BridgeContext ctx = new BridgeContext(userAgent);
TextPainter textPainter = null;
textPainter = new StrokingTextPainter();
@@ -162,102 +181,7 @@ public class PSTranscoder extends AbstractFOPTranscoder {
//ctx.putBridge(pdfAElementBridge);
//ctx.putBridge(new PSImageElementBridge());
- GraphicsNode gvtRoot;
- try {
- gvtRoot = builder.build(ctx, svgDoc);
- } catch (BridgeException ex) {
- throw new TranscoderException(ex);
- }
- // get the 'width' and 'height' attributes of the SVG document
- float docWidth = (float)ctx.getDocumentSize().getWidth();
- float docHeight = (float)ctx.getDocumentSize().getHeight();
- ctx = null;
- builder = null;
-
- // compute the image's width and height according the hints
- float imgWidth = -1;
- if (hints.containsKey(ImageTranscoder.KEY_WIDTH)) {
- imgWidth =
- ((Float)hints.get(ImageTranscoder.KEY_WIDTH)).floatValue();
- }
- float imgHeight = -1;
- if (hints.containsKey(ImageTranscoder.KEY_HEIGHT)) {
- imgHeight =
- ((Float)hints.get(ImageTranscoder.KEY_HEIGHT)).floatValue();
- }
- float width, height;
- if (imgWidth > 0 && imgHeight > 0) {
- width = imgWidth;
- height = imgHeight;
- } else if (imgHeight > 0) {
- width = (docWidth * imgHeight) / docHeight;
- height = imgHeight;
- } else if (imgWidth > 0) {
- width = imgWidth;
- height = (docHeight * imgWidth) / docWidth;
- } else {
- width = docWidth;
- height = docHeight;
- }
- // compute the preserveAspectRatio matrix
- AffineTransform px;
- String ref = null;
- try {
- ref = new URL(uri).getRef();
- } catch (MalformedURLException ex) {
- // nothing to do, catched previously
- }
-
- try {
- px = ViewBox.getViewTransform(ref, root, width, height);
- } catch (BridgeException ex) {
- throw new TranscoderException(ex);
- }
-
- if (px.isIdentity() && (width != docWidth || height != docHeight)) {
- // The document has no viewBox, we need to resize it by hand.
- // we want to keep the document size ratio
- float d = Math.max(docWidth, docHeight);
- float dd = Math.max(width, height);
- float scale = dd / d;
- px = AffineTransform.getScaleInstance(scale, scale);
- }
- // take the AOI into account if any
- if (hints.containsKey(ImageTranscoder.KEY_AOI)) {
- Rectangle2D aoi = (Rectangle2D)hints.get(ImageTranscoder.KEY_AOI);
- // transform the AOI into the image's coordinate system
- aoi = px.createTransformedShape(aoi).getBounds2D();
- AffineTransform mx = new AffineTransform();
- double sx = width / aoi.getWidth();
- double sy = height / aoi.getHeight();
- mx.scale(sx, sy);
- double tx = -aoi.getX();
- double ty = -aoi.getY();
- mx.translate(tx, ty);
- // take the AOI transformation matrix into account
- // we apply first the preserveAspectRatio matrix
- px.preConcatenate(mx);
- }
- // prepare the image to be painted
- int w = (int)width;
- int h = (int)height;
-
- try {
- graphics.setupDocument(output.getOutputStream(), w, h);
- graphics.setSVGDimension(docWidth, docHeight);
-
- if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
- graphics.setBackgroundColor((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
- }
- graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
- graphics.setTransform(px);
-
- gvtRoot.paint(graphics);
-
- graphics.finish();
- } catch (IOException ex) {
- throw new TranscoderException(ex);
- }
+ return ctx;
}
}
diff --git a/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java b/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java
index bb93e52d9..e4f17c6d4 100644
--- a/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java
+++ b/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java
@@ -65,7 +65,7 @@ import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.dom.util.DocumentFactory;
import org.apache.batik.transcoder.ErrorHandler;
import org.apache.batik.transcoder.TranscoderException;
-import org.apache.batik.transcoder.XMLAbstractTranscoder;
+import org.apache.batik.transcoder.SVGAbstractTranscoder;
import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.batik.util.SVGConstants;
import org.apache.batik.util.XMLResourceDescriptor;
@@ -74,7 +74,7 @@ import org.w3c.dom.DOMImplementation;
/**
* This is the common base class of all of FOP's transcoders.
*/
-public abstract class AbstractFOPTranscoder extends XMLAbstractTranscoder
+public abstract class AbstractFOPTranscoder extends SVGAbstractTranscoder
implements LogEnabled {
/**
diff --git a/src/java/org/apache/fop/svg/PDFImageElementBridge.java b/src/java/org/apache/fop/svg/PDFImageElementBridge.java
index 5507dbe22..3c6292761 100644
--- a/src/java/org/apache/fop/svg/PDFImageElementBridge.java
+++ b/src/java/org/apache/fop/svg/PDFImageElementBridge.java
@@ -53,12 +53,20 @@ package org.apache.fop.svg;
import org.apache.batik.bridge.SVGImageElementBridge;
import org.apache.fop.image.JpegImage;
+import org.apache.fop.image.FopImage;
+import org.apache.fop.image.analyser.ImageReaderFactory;
import java.awt.Shape;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
+import java.net.URL;
+import org.w3c.dom.Element;
+
+import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.gvt.AbstractGraphicsNode;
+import org.apache.batik.gvt.GraphicsNode;
+import org.apache.batik.util.ParsedURL;
/**
* Bridge class for the &lt;image> element when jpeg images.
@@ -72,7 +80,6 @@ public class PDFImageElementBridge extends SVGImageElementBridge {
*/
public PDFImageElementBridge() { }
-/*
/**
* Create the raster image node.
* THis checks if it is a jpeg file and creates a jpeg node
@@ -81,14 +88,19 @@ public class PDFImageElementBridge extends SVGImageElementBridge {
* @param e the svg element for the image
* @param purl the parsed url for the image resource
* @return a new graphics node
- *
- protected GraphicsNode createRasterImageNode(BridgeContext ctx,
- Element e, ParsedURL purl) {
-
+ */
+ protected GraphicsNode createImageGraphicsNode
+ (BridgeContext ctx, Element e, ParsedURL purl) {
+ GraphicsNode origGN = super.createImageGraphicsNode
+ (ctx, e, purl);
try {
- JpegImage jpeg = new JpegImage(new URL(purl.toString()));
- PDFFilter filter = jpeg.getPDFFilter();
- PDFJpegNode node = new PDFJpegNode(jpeg);
+ FopImage.ImageInfo ii = ImageReaderFactory.make
+ (purl.toString(), purl.openStream(), null);
+ if (ii.mimeType.toLowerCase() == "image/jpeg") {
+ JpegImage jpeg = new JpegImage(ii);
+ PDFJpegNode node = new PDFJpegNode(jpeg, origGN);
+
+ Rectangle2D imgBounds = getImageBounds(ctx, e);
Rectangle2D bounds = node.getPrimitiveBounds();
float [] vb = new float[4];
vb[0] = 0; // x
@@ -96,17 +108,16 @@ public class PDFImageElementBridge extends SVGImageElementBridge {
vb[2] = (float) bounds.getWidth(); // width
vb[3] = (float) bounds.getHeight(); // height
- // handles the 'preserveAspectRatio', 'overflow' and 'clip' and sets the
- // appropriate AffineTransform to the image node
- initializeViewport(ctx, e, node, vb, bounds);
-
+ // handles the 'preserveAspectRatio', 'overflow' and 'clip'
+ // and sets the appropriate AffineTransform to the image node
+ initializeViewport(ctx, e, node, vb, imgBounds);
return node;
+ }
} catch (Exception ex) {
}
- return super.createRasterImageNode(ctx, e, purl);
+ return origGN;
}
-*/
/**
* A PDF jpeg node.
@@ -115,14 +126,16 @@ public class PDFImageElementBridge extends SVGImageElementBridge {
*/
public static class PDFJpegNode extends AbstractGraphicsNode {
private JpegImage jpeg;
-
+ private GraphicsNode origGraphicsNode ;
/**
* Create a new pdf jpeg node for drawing jpeg images
* into pdf graphics.
* @param j the jpeg image
*/
- public PDFJpegNode(JpegImage j) {
+ public PDFJpegNode(JpegImage j,
+ GraphicsNode origGraphicsNode) {
jpeg = j;
+ this.origGraphicsNode = origGraphicsNode;
}
/**
@@ -152,6 +165,10 @@ public class PDFImageElementBridge extends SVGImageElementBridge {
} catch (Exception e) {
e.printStackTrace();
}
+ } else {
+ // Not going directly into PDF so use
+ // original implemtation so filters etc work.
+ origGraphicsNode.primitivePaint(g2d);
}
}
diff --git a/src/java/org/apache/fop/svg/PDFTranscoder.java b/src/java/org/apache/fop/svg/PDFTranscoder.java
index 6b69c659b..000312c2c 100644
--- a/src/java/org/apache/fop/svg/PDFTranscoder.java
+++ b/src/java/org/apache/fop/svg/PDFTranscoder.java
@@ -107,7 +107,8 @@ import org.w3c.dom.svg.SVGSVGElement;
public class PDFTranscoder extends AbstractFOPTranscoder
implements Configurable {
- private Configuration cfg;
+ private Configuration cfg = null;
+ protected PDFDocumentGraphics2D graphics = null;
/**
* Constructs a new <tt>ImageTranscoder</tt>.
@@ -134,22 +135,10 @@ public class PDFTranscoder extends AbstractFOPTranscoder
* @exception TranscoderException if an error occured while transcoding
*/
protected void transcode(Document document, String uri,
- TranscoderOutput output) throws TranscoderException {
+ TranscoderOutput output)
+ throws TranscoderException {
- if (!(document instanceof SVGOMDocument)) {
- throw new TranscoderException(Messages.formatMessage("notsvg",
- null));
- }
- SVGDocument svgDoc = (SVGDocument)document;
- SVGSVGElement root = svgDoc.getRootElement();
- // initialize the SVG document with the appropriate context
- String parserClassname = (String)hints.get(KEY_XML_PARSER_CLASSNAME);
-
- /*boolean stroke = true;
- if (hints.containsKey(KEY_STROKE_TEXT)) {
- stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue();
- }*/
- PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D();
+ graphics = new PDFDocumentGraphics2D();
ContainerUtil.enableLogging(graphics, getLogger());
try {
if (this.cfg != null) {
@@ -161,127 +150,57 @@ public class PDFTranscoder extends AbstractFOPTranscoder
"Error while setting up PDFDocumentGraphics2D", e);
}
- // build the GVT tree
- GVTBuilder builder = new GVTBuilder();
- BridgeContext ctx = new BridgeContext(userAgent);
- TextPainter textPainter = null;
- textPainter = new StrokingTextPainter();
- ctx.setTextPainter(textPainter);
-
- PDFTextElementBridge pdfTextElementBridge;
- pdfTextElementBridge = new PDFTextElementBridge(graphics.getFontInfo());
- ctx.putBridge(pdfTextElementBridge);
+ super.transcode(document, uri, output);
- PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
- AffineTransform currentTransform = new AffineTransform(1, 0, 0, 1, 0, 0);
- pdfAElementBridge.setCurrentTransform(currentTransform);
- ctx.putBridge(pdfAElementBridge);
- ctx.putBridge(new PDFImageElementBridge());
- GraphicsNode gvtRoot;
- try {
- gvtRoot = builder.build(ctx, svgDoc);
- } catch (BridgeException ex) {
- throw new TranscoderException(ex);
- }
- // get the 'width' and 'height' attributes of the SVG document
- float docWidth = (float)ctx.getDocumentSize().getWidth();
- float docHeight = (float)ctx.getDocumentSize().getHeight();
- ctx = null;
- builder = null;
+ // prepare the image to be painted
+ int w = (int)(width+.5);
+ int h = (int)(height+.5);
- // compute the image's width and height according the hints
- float imgWidth = -1;
- if (hints.containsKey(ImageTranscoder.KEY_WIDTH)) {
- imgWidth =
- ((Float)hints.get(ImageTranscoder.KEY_WIDTH)).floatValue();
- }
- float imgHeight = -1;
- if (hints.containsKey(ImageTranscoder.KEY_HEIGHT)) {
- imgHeight =
- ((Float)hints.get(ImageTranscoder.KEY_HEIGHT)).floatValue();
- }
- float width, height;
- if (imgWidth > 0 && imgHeight > 0) {
- width = imgWidth;
- height = imgHeight;
- } else if (imgHeight > 0) {
- width = (docWidth * imgHeight) / docHeight;
- height = imgHeight;
- } else if (imgWidth > 0) {
- width = imgWidth;
- height = (docHeight * imgWidth) / docWidth;
- } else {
- width = docWidth;
- height = docHeight;
- }
- // compute the preserveAspectRatio matrix
- AffineTransform px;
- String ref = null;
try {
- ref = new URL(uri).getRef();
- } catch (MalformedURLException ex) {
- // nothing to do, catched previously
- }
+ graphics.setupDocument(output.getOutputStream(), w, h);
+ graphics.setSVGDimension(width, height);
- try {
- px = ViewBox.getViewTransform(ref, root, width, height);
- } catch (BridgeException ex) {
- throw new TranscoderException(ex);
+ if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
+ graphics.setBackgroundColor
+ ((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
}
+ graphics.setGraphicContext
+ (new org.apache.batik.ext.awt.g2d.GraphicContext());
+ graphics.setTransform(curTxf);
- if (px.isIdentity() && (width != docWidth || height != docHeight)) {
- // The document has no viewBox, we need to resize it by hand.
- // we want to keep the document size ratio
- float d = Math.max(docWidth, docHeight);
- float dd = Math.max(width, height);
- float scale = dd / d;
- px = AffineTransform.getScaleInstance(scale, scale);
- }
- // take the AOI into account if any
- if (hints.containsKey(ImageTranscoder.KEY_AOI)) {
- Rectangle2D aoi = (Rectangle2D)hints.get(ImageTranscoder.KEY_AOI);
- // transform the AOI into the image's coordinate system
- aoi = px.createTransformedShape(aoi).getBounds2D();
- AffineTransform mx = new AffineTransform();
- double sx = width / aoi.getWidth();
- double sy = height / aoi.getHeight();
- mx.scale(sx, sy);
- double tx = -aoi.getX();
- double ty = -aoi.getY();
- mx.translate(tx, ty);
- // take the AOI transformation matrix into account
- // we apply first the preserveAspectRatio matrix
- px.preConcatenate(mx);
- }
- // prepare the image to be painted
- int w = (int)width;
- int h = (int)height;
+ this.root.paint(graphics);
- try {
- graphics.setupDocument(output.getOutputStream(), w, h);
+ graphics.finish();
} catch (IOException ex) {
throw new TranscoderException(ex);
}
- graphics.setSVGDimension(docWidth, docHeight);
- currentTransform.setTransform(1, 0, 0, -1, 0, height);
+ }
+
+ protected BridgeContext createBridgeContext() {
+ /*boolean stroke = true;
+ if (hints.containsKey(KEY_STROKE_TEXT)) {
+ stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue();
+ }*/
+
+ BridgeContext ctx = new BridgeContext(userAgent);
+ TextPainter textPainter = null;
+ textPainter = new StrokingTextPainter();
+ ctx.setTextPainter(textPainter);
/*if (!stroke) {
textPainter = new PDFTextPainter(graphics.getFontInfo());
ctx.setTextPainter(textPainter);
}*/
- if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
- graphics.setBackgroundColor((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
- }
- graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
- graphics.setTransform(px);
-
- gvtRoot.paint(graphics);
+ PDFTextElementBridge pdfTextElementBridge;
+ pdfTextElementBridge = new PDFTextElementBridge(graphics.getFontInfo());
+ ctx.putBridge(pdfTextElementBridge);
- try {
- graphics.finish();
- } catch (IOException ex) {
- throw new TranscoderException(ex);
- }
+ PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
+ AffineTransform currentTransform = new AffineTransform(1, 0, 0, 1, 0, 0);
+ pdfAElementBridge.setCurrentTransform(currentTransform);
+ ctx.putBridge(pdfAElementBridge);
+ ctx.putBridge(new PDFImageElementBridge());
+ return ctx;
}
}