aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/render')
-rw-r--r--src/java/org/apache/fop/render/AbstractFOEventHandlerMaker.java68
-rw-r--r--src/java/org/apache/fop/render/AbstractRenderer.java5
-rw-r--r--src/java/org/apache/fop/render/AbstractRendererMaker.java61
-rw-r--r--src/java/org/apache/fop/render/Graphics2DAdapter.java49
-rw-r--r--src/java/org/apache/fop/render/Graphics2DImagePainter.java44
-rw-r--r--src/java/org/apache/fop/render/Renderer.java7
-rw-r--r--src/java/org/apache/fop/render/RendererFactory.java302
-rw-r--r--src/java/org/apache/fop/render/XMLHandlerRegistry.java3
-rw-r--r--src/java/org/apache/fop/render/awt/AWTRenderer.java3
-rw-r--r--src/java/org/apache/fop/render/awt/AWTRendererMaker.java49
-rw-r--r--src/java/org/apache/fop/render/bitmap/PNGRenderer.java3
-rw-r--r--src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java49
-rw-r--r--src/java/org/apache/fop/render/bitmap/TIFFRenderer.java3
-rw-r--r--src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java49
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DGraphics2DAdapter.java86
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DRenderer.java19
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java10
-rw-r--r--src/java/org/apache/fop/render/mif/MIFFOEventHandlerMaker.java51
-rw-r--r--src/java/org/apache/fop/render/mif/MIFHandler.java8
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLRenderer.java4
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLRendererMaker.java51
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java106
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderer.java9
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRendererMaker.java49
-rw-r--r--src/java/org/apache/fop/render/print/PrintRendererMaker.java49
-rw-r--r--src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java90
-rw-r--r--src/java/org/apache/fop/render/ps/PSRenderer.java6
-rw-r--r--src/java/org/apache/fop/render/ps/PSRendererMaker.java49
-rw-r--r--src/java/org/apache/fop/render/ps/PSSVGHandler.java3
-rw-r--r--src/java/org/apache/fop/render/rtf/RTFFOEventHandlerMaker.java54
-rw-r--r--src/java/org/apache/fop/render/svg/SVGRendererMaker.java49
-rw-r--r--src/java/org/apache/fop/render/txt/TXTFOEventHandlerMaker.java52
-rw-r--r--src/java/org/apache/fop/render/txt/TXTHandler.java3
-rw-r--r--src/java/org/apache/fop/render/txt/TXTRendererMaker.java49
-rw-r--r--src/java/org/apache/fop/render/xml/XMLRenderer.java3
-rw-r--r--src/java/org/apache/fop/render/xml/XMLRendererMaker.java49
36 files changed, 1459 insertions, 85 deletions
diff --git a/src/java/org/apache/fop/render/AbstractFOEventHandlerMaker.java b/src/java/org/apache/fop/render/AbstractFOEventHandlerMaker.java
new file mode 100644
index 000000000..f18be7dfa
--- /dev/null
+++ b/src/java/org/apache/fop/render/AbstractFOEventHandlerMaker.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render;
+
+import java.io.OutputStream;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fo.FOEventHandler;
+
+/**
+ * Base class for factory classes which instantiate FOEventHandlers and provide information
+ * about them.
+ */
+public abstract class AbstractFOEventHandlerMaker {
+
+ /**
+ * Instantiates a new FOEventHandler.
+ * @param ua the user agent
+ * @param out OutputStream for the FOEventHandler to use
+ * @return the newly instantiated FOEventHandler
+ * @throws FOPException if a problem occurs while creating the event handler
+ */
+ public abstract FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out)
+ throws FOPException;
+
+ /**
+ * @return Indicates whether this renderer requires an OutputStream to work with.
+ */
+ public abstract boolean needsOutputStream();
+
+ /**
+ * @return an array of MIME types the renderer supports.
+ */
+ public abstract String[] getSupportedMimeTypes();
+
+ /**
+ * Indicates whether a specific MIME type is supported by this renderer.
+ * @param mimeType the MIME type (ex. "application/rtf")
+ * @return true if the MIME type is supported
+ */
+ public boolean isMimeTypeSupported(String mimeType) {
+ String[] mimes = getSupportedMimeTypes();
+ for (int i = 0; i < mimes.length; i++) {
+ if (mimes[i].equals(mimeType)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java
index 6dd4c7510..dc793611b 100644
--- a/src/java/org/apache/fop/render/AbstractRenderer.java
+++ b/src/java/org/apache/fop/render/AbstractRenderer.java
@@ -155,6 +155,11 @@ public abstract class AbstractRenderer
*/
public void processOffDocumentItem(OffDocumentItem oDI) { }
+ /** @see org.apache.fop.render.Renderer#getGraphics2DAdapter() */
+ public Graphics2DAdapter getGraphics2DAdapter() {
+ return null;
+ }
+
/**
* Prepare a page for rendering. This is called if the renderer supports
* out of order rendering. The renderer should prepare the page so that a
diff --git a/src/java/org/apache/fop/render/AbstractRendererMaker.java b/src/java/org/apache/fop/render/AbstractRendererMaker.java
new file mode 100644
index 000000000..3aa63b48c
--- /dev/null
+++ b/src/java/org/apache/fop/render/AbstractRendererMaker.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render;
+
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * Base class for factory classes which instantiate Renderers and provide information
+ * about them.
+ */
+public abstract class AbstractRendererMaker {
+
+ /**
+ * Instantiates a new renderer.
+ * @param ua the user agent
+ * @return the newly instantiated renderer
+ */
+ public abstract Renderer makeRenderer(FOUserAgent ua);
+
+ /**
+ * @return Indicates whether this renderer requires an OutputStream to work with.
+ */
+ public abstract boolean needsOutputStream();
+
+ /**
+ * @return an array of MIME types the renderer supports.
+ */
+ public abstract String[] getSupportedMimeTypes();
+
+ /**
+ * Indicates whether a specific MIME type is supported by this renderer.
+ * @param mimeType the MIME type (ex. "application/pdf")
+ * @return true if the MIME type is supported
+ */
+ public boolean isMimeTypeSupported(String mimeType) {
+ String[] mimes = getSupportedMimeTypes();
+ for (int i = 0; i < mimes.length; i++) {
+ if (mimes[i].equals(mimeType)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/Graphics2DAdapter.java b/src/java/org/apache/fop/render/Graphics2DAdapter.java
new file mode 100644
index 000000000..e5b98e21c
--- /dev/null
+++ b/src/java/org/apache/fop/render/Graphics2DAdapter.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render;
+
+import java.io.IOException;
+
+/**
+ * This interface represents an optional feature that can be provided by
+ * a renderer. It is exposed by calling the getGraphics2DAdapter() method
+ * on the renderer. Renderers that support this feature allow painting
+ * of arbitrary images through a Graphics2D instance.
+ */
+public interface Graphics2DAdapter {
+
+ /**
+ * Paints an arbitrary images on a given Graphics2D instance. The renderer
+ * providing this functionality must set up a Graphics2D instance so that
+ * the image with the given extents (in mpt) can be painted by the painter
+ * passed to this method. The Graphics2DImagePainter is then passed this
+ * Graphics2D instance so the image can be painted.
+ * @param painter the painter which will paint the actual image
+ * @param context the renderer context for the current renderer
+ * @param x X position of the image
+ * @param y Y position of the image
+ * @param width width of the image
+ * @param height height of the image
+ * @throws IOException In case of an I/O error while writing the output format
+ */
+ void paintImage(Graphics2DImagePainter painter,
+ RendererContext context,
+ int x, int y, int width, int height) throws IOException;
+
+}
diff --git a/src/java/org/apache/fop/render/Graphics2DImagePainter.java b/src/java/org/apache/fop/render/Graphics2DImagePainter.java
new file mode 100644
index 000000000..3d946b624
--- /dev/null
+++ b/src/java/org/apache/fop/render/Graphics2DImagePainter.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * This interface is used by the Graphics2DAdapter. Components that can paint using
+ * a Graphics2D instance can implement this interface to paint themselves.
+ */
+public interface Graphics2DImagePainter {
+
+ /**
+ * Called to paint the image. Implementations should scale so the image is
+ * painted fully inside the given area indicated by then Rectangle2D object.
+ * @param g2d the Graphics2D instance to paint on
+ * @param area the target area for the image
+ */
+ void paint(Graphics2D g2d, Rectangle2D area);
+
+ /**
+ * @return the dimensions of the image to be painted in millipoints
+ */
+ Dimension getImageSize();
+
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/Renderer.java b/src/java/org/apache/fop/render/Renderer.java
index ebe2215f1..da347e0e6 100644
--- a/src/java/org/apache/fop/render/Renderer.java
+++ b/src/java/org/apache/fop/render/Renderer.java
@@ -114,9 +114,14 @@ public interface Renderer {
*
* @param ext The extension element to be rendered
*/
- public void processOffDocumentItem(OffDocumentItem ext);
+ void processOffDocumentItem(OffDocumentItem ext);
/**
+ * @return the adapter for painting Java2D images (or null if not supported)
+ */
+ Graphics2DAdapter getGraphics2DAdapter();
+
+ /**
* This is called if the renderer supports out of order rendering. The
* renderer should prepare the page so that a page further on in the set of
* pages can be rendered. The body of the page should not be rendered. The
diff --git a/src/java/org/apache/fop/render/RendererFactory.java b/src/java/org/apache/fop/render/RendererFactory.java
index d4d1460bd..cb677a4a9 100644
--- a/src/java/org/apache/fop/render/RendererFactory.java
+++ b/src/java/org/apache/fop/render/RendererFactory.java
@@ -19,77 +19,195 @@
package org.apache.fop.render;
import java.io.OutputStream;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
//Avalon
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
//FOP
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.AreaTreeHandler;
-import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FOEventHandler;
-import org.apache.fop.render.mif.MIFHandler;
-import org.apache.fop.render.rtf.RTFHandler;
-import org.apache.fop.render.txt.TXTHandler;
+import org.apache.fop.util.Service;
/**
* Factory for FOEventHandlers and Renderers.
*/
public class RendererFactory {
+ /** the logger */
+ private static Log log = LogFactory.getLog(RendererFactory.class);
+
+ private Map rendererMakerMapping = new java.util.HashMap();
+ private Map eventHandlerMakerMapping = new java.util.HashMap();
+
+
/**
- * Creates a Renderer object based on render-type desired
- * @param renderType the type of renderer to use
- * @return the new Renderer instance
- * @throws IllegalArgumentException if an unsupported renderer type was requested
+ * Main constructor.
*/
- private static Renderer newInstance(int renderType) throws IllegalArgumentException {
-
- switch (renderType) {
- case Constants.RENDER_PDF:
- return new org.apache.fop.render.pdf.PDFRenderer();
- case Constants.RENDER_AWT:
- return new org.apache.fop.render.awt.AWTRenderer();
- case Constants.RENDER_PRINT:
- return new org.apache.fop.render.print.PrintRenderer();
- case Constants.RENDER_PCL:
- return new org.apache.fop.render.pcl.PCLRenderer();
- case Constants.RENDER_TIFF:
- return new org.apache.fop.render.bitmap.TIFFRenderer();
- case Constants.RENDER_PNG:
- return new org.apache.fop.render.bitmap.PNGRenderer();
- case Constants.RENDER_PS:
- return new org.apache.fop.render.ps.PSRenderer();
- case Constants.RENDER_TXT:
- return new org.apache.fop.render.txt.TXTRenderer();
- case Constants.RENDER_XML:
- return new org.apache.fop.render.xml.XMLRenderer();
- case Constants.RENDER_SVG:
- return new org.apache.fop.render.svg.SVGRenderer();
- default:
- throw new IllegalArgumentException("Invalid renderer type "
- + renderType);
+ public RendererFactory() {
+ registerStandardRenderers();
+ discoverRenderers();
+
+ registerStandardEventHandlers();
+ discoverFOEventHandlers();
+ }
+
+ private void registerStandardRenderers() {
+ addRendererMaker(new org.apache.fop.render.pdf.PDFRendererMaker());
+ addRendererMaker(new org.apache.fop.render.ps.PSRendererMaker());
+ addRendererMaker(new org.apache.fop.render.pcl.PCLRendererMaker());
+ addRendererMaker(new org.apache.fop.render.svg.SVGRendererMaker());
+ addRendererMaker(new org.apache.fop.render.txt.TXTRendererMaker());
+ addRendererMaker(new org.apache.fop.render.bitmap.PNGRendererMaker());
+ addRendererMaker(new org.apache.fop.render.bitmap.TIFFRendererMaker());
+ addRendererMaker(new org.apache.fop.render.bitmap.TIFFRendererMaker());
+ addRendererMaker(new org.apache.fop.render.xml.XMLRendererMaker());
+ addRendererMaker(new org.apache.fop.render.awt.AWTRendererMaker());
+ addRendererMaker(new org.apache.fop.render.print.PrintRendererMaker());
+ }
+
+ private void registerStandardEventHandlers() {
+ addFOEventHandlerMaker(new org.apache.fop.render.rtf.RTFFOEventHandlerMaker());
+ addFOEventHandlerMaker(new org.apache.fop.render.mif.MIFFOEventHandlerMaker());
+ }
+
+ /**
+ * Add a new RendererMaker. If another maker has already been registered for a
+ * particular MIME type, this call overwrites the existing one.
+ * @param maker the RendererMaker
+ */
+ public void addRendererMaker(AbstractRendererMaker maker) {
+ String[] mimes = maker.getSupportedMimeTypes();
+ for (int i = 0; i < mimes.length; i++) {
+ //This overrides any renderer previously set for a MIME type
+ if (rendererMakerMapping.get(mimes[i]) != null) {
+ log.trace("Overriding renderer for " + mimes[i]
+ + " with " + maker.getClass().getName());
+ }
+ rendererMakerMapping.put(mimes[i], maker);
}
}
-
+
+ /**
+ * Add a new FOEventHandlerMaker. If another maker has already been registered for a
+ * particular MIME type, this call overwrites the existing one.
+ * @param maker the FOEventHandlerMaker
+ */
+ public void addFOEventHandlerMaker(AbstractFOEventHandlerMaker maker) {
+ String[] mimes = maker.getSupportedMimeTypes();
+ for (int i = 0; i < mimes.length; i++) {
+ //This overrides any event handler previously set for a MIME type
+ if (eventHandlerMakerMapping.get(mimes[i]) != null) {
+ log.trace("Overriding FOEventHandler for " + mimes[i]
+ + " with " + maker.getClass().getName());
+ }
+ eventHandlerMakerMapping.put(mimes[i], maker);
+ }
+ }
+
+ /**
+ * Add a new RendererMaker. If another maker has already been registered for a
+ * particular MIME type, this call overwrites the existing one.
+ * @param className the fully qualified class name of the RendererMaker
+ */
+ public void addRendererMaker(String className) {
+ try {
+ AbstractRendererMaker makerInstance
+ = (AbstractRendererMaker)Class.forName(className).newInstance();
+ addRendererMaker(makerInstance);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("Could not find "
+ + className);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException("Could not instantiate "
+ + className);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException("Could not access "
+ + className);
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException(className
+ + " is not an "
+ + AbstractRendererMaker.class.getName());
+ }
+ }
+
+ /**
+ * Add a new FOEventHandlerMaker. If another maker has already been registered for a
+ * particular MIME type, this call overwrites the existing one.
+ * @param className the fully qualified class name of the FOEventHandlerMaker
+ */
+ public void addFOEventHandlerMaker(String className) {
+ try {
+ AbstractFOEventHandlerMaker makerInstance
+ = (AbstractFOEventHandlerMaker)Class.forName(className).newInstance();
+ addFOEventHandlerMaker(makerInstance);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("Could not find "
+ + className);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException("Could not instantiate "
+ + className);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException("Could not access "
+ + className);
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException(className
+ + " is not an "
+ + AbstractFOEventHandlerMaker.class.getName());
+ }
+ }
+
+ /**
+ * Returns a RendererMaker which handles the given MIME type.
+ * @param mime the requested output format
+ * @return the requested RendererMaker or null if none is available
+ */
+ public AbstractRendererMaker getRendererMaker(String mime) {
+ AbstractRendererMaker maker
+ = (AbstractRendererMaker)rendererMakerMapping.get(mime);
+ return maker;
+ }
+
+ /**
+ * Returns a FOEventHandlerMaker which handles the given MIME type.
+ * @param mime the requested output format
+ * @return the requested FOEventHandlerMaker or null if none is available
+ */
+ public AbstractFOEventHandlerMaker getFOEventHandlerMaker(String mime) {
+ AbstractFOEventHandlerMaker maker
+ = (AbstractFOEventHandlerMaker)eventHandlerMakerMapping.get(mime);
+ return maker;
+ }
+
/**
* Creates a Renderer object based on render-type desired
* @param userAgent the user agent for access to configuration
- * @param renderType the type of renderer to use
+ * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
* @return the new Renderer instance
* @throws FOPException if the renderer cannot be properly constructed
*/
- public static Renderer createRenderer(FOUserAgent userAgent, int renderType)
+ public Renderer createRenderer(FOUserAgent userAgent, String outputFormat)
throws FOPException {
if (userAgent.getRendererOverride() != null) {
return userAgent.getRendererOverride();
} else {
- Renderer rend = newInstance(renderType);
+ AbstractRendererMaker maker = getRendererMaker(outputFormat);
+ if (maker == null) {
+ throw new UnsupportedOperationException(
+ "No renderer for the requested format available: " + outputFormat);
+ }
+ Renderer rend = maker.makeRenderer(userAgent);
rend.setUserAgent(userAgent);
- String mimeType = rend.getMimeType();
+ String mimeType = rend.getMimeType(); //Always use main MIME type for this
Configuration userRendererConfig = null;
if (mimeType != null) {
userRendererConfig
@@ -110,40 +228,104 @@ public class RendererFactory {
/**
* Creates FOEventHandler instances based on the desired output.
* @param userAgent the user agent for access to configuration
- * @param renderType the type of renderer to use
+ * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
* @param out the OutputStream where the output is written to (if applicable)
* @return the newly constructed FOEventHandler
* @throws FOPException if the FOEventHandler cannot be properly constructed
*/
- public static FOEventHandler createFOEventHandler(FOUserAgent userAgent,
- int renderType, OutputStream out) throws FOPException {
+ public FOEventHandler createFOEventHandler(FOUserAgent userAgent,
+ String outputFormat, OutputStream out) throws FOPException {
if (userAgent.getFOEventHandlerOverride() != null) {
return userAgent.getFOEventHandlerOverride();
} else {
- if (renderType != Constants.RENDER_PRINT
- && renderType != Constants.RENDER_AWT) {
- if (out == null && userAgent.getRendererOverride() == null) {
- throw new IllegalStateException(
- "OutputStream has not been set");
+ AbstractFOEventHandlerMaker maker = getFOEventHandlerMaker(outputFormat);
+ if (maker == null) {
+ AbstractRendererMaker rendMaker = getRendererMaker(outputFormat);
+ if (rendMaker == null && userAgent.getRendererOverride() == null) {
+ throw new UnsupportedOperationException(
+ "Don't know how to handle \"" + outputFormat + "\" as an output format."
+ + " Neither an FOEventHandler, nor a Renderer could be found"
+ + " for this output format.");
+ } else {
+ if (out == null
+ && userAgent.getRendererOverride() == null
+ && rendMaker.needsOutputStream()) {
+ throw new IllegalStateException(
+ "OutputStream has not been set");
+ }
+ //Found a Renderer so we need to construct an AreaTreeHandler.
+ return new AreaTreeHandler(userAgent, outputFormat, out);
}
- }
-
- if (renderType == Constants.RENDER_MIF) {
- return new MIFHandler(userAgent, out);
- } else if (renderType == Constants.RENDER_RTF) {
- return new RTFHandler(userAgent, out);
- } else if (renderType == Constants.RENDER_TXT) {
- return new TXTHandler(userAgent, out);
} else {
- if (renderType < Constants.RENDER_MIN_CONST
- || renderType > Constants.RENDER_MAX_CONST) {
- throw new IllegalArgumentException(
- "Invalid render ID#" + renderType);
+ return maker.makeFOEventHandler(userAgent, out);
+ }
+ }
+ }
+
+ /**
+ * @return an array of all supported MIME types
+ */
+ public String[] listSupportedMimeTypes() {
+ List lst = new java.util.ArrayList();
+ Iterator iter = this.rendererMakerMapping.keySet().iterator();
+ while (iter.hasNext()) {
+ lst.add(((String)iter.next()));
+ }
+ iter = this.eventHandlerMakerMapping.keySet().iterator();
+ while (iter.hasNext()) {
+ lst.add(((String)iter.next()));
+ }
+ Collections.sort(lst);
+ return (String[])lst.toArray(new String[lst.size()]);
+ }
+
+ /**
+ * Discovers Renderer implementations through the classpath and dynamically
+ * registers them.
+ */
+ private void discoverRenderers() {
+ // add mappings from available services
+ Iterator providers
+ = Service.providers(Renderer.class);
+ if (providers != null) {
+ while (providers.hasNext()) {
+ String str = (String)providers.next();
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Dynamically adding maker for Renderer: " + str);
+ }
+ addRendererMaker(str);
+ } catch (IllegalArgumentException e) {
+ log.error("Error while adding maker for Renderer", e);
}
+
+ }
+ }
+ }
- return new AreaTreeHandler(userAgent, renderType, out);
+ /**
+ * Discovers FOEventHandler implementations through the classpath and dynamically
+ * registers them.
+ */
+ private void discoverFOEventHandlers() {
+ // add mappings from available services
+ Iterator providers
+ = Service.providers(FOEventHandler.class);
+ if (providers != null) {
+ while (providers.hasNext()) {
+ String str = (String)providers.next();
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Dynamically adding maker for FOEventHandler: " + str);
+ }
+ addFOEventHandlerMaker(str);
+ } catch (IllegalArgumentException e) {
+ log.error("Error while adding maker for FOEventHandler", e);
+ }
+
}
}
}
+
}
diff --git a/src/java/org/apache/fop/render/XMLHandlerRegistry.java b/src/java/org/apache/fop/render/XMLHandlerRegistry.java
index 11a9470a1..5712ca3fa 100644
--- a/src/java/org/apache/fop/render/XMLHandlerRegistry.java
+++ b/src/java/org/apache/fop/render/XMLHandlerRegistry.java
@@ -76,7 +76,8 @@ public class XMLHandlerRegistry {
+ classname);
} catch (ClassCastException e) {
throw new IllegalArgumentException(classname
- + " is not an ElementMapping");
+ + " is not an "
+ + XMLHandler.class.getName());
}
}
diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java
index 5287bd15d..37169d7e2 100644
--- a/src/java/org/apache/fop/render/awt/AWTRenderer.java
+++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java
@@ -39,6 +39,7 @@ import java.io.IOException;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.Area;
import org.apache.fop.area.PageViewport;
import org.apache.fop.datatypes.ColorType;
@@ -56,7 +57,7 @@ import org.apache.fop.render.java2d.Java2DRenderer;
public class AWTRenderer extends Java2DRenderer implements Pageable {
/** The MIME type for AWT-Rendering */
- public static final String MIME_TYPE = "application/X-awt";
+ public static final String MIME_TYPE = MimeConstants.MIME_FOP_AWT_PREVIEW;
/** The resource bundle used for AWT messages. */
protected Translator translator = null;
diff --git a/src/java/org/apache/fop/render/awt/AWTRendererMaker.java b/src/java/org/apache/fop/render/awt/AWTRendererMaker.java
new file mode 100644
index 000000000..c094d32ed
--- /dev/null
+++ b/src/java/org/apache/fop/render/awt/AWTRendererMaker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.awt;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the AWT Preview Renderer.
+ */
+public class AWTRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_AWT_PREVIEW};
+
+
+ /** @see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new AWTRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return false;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/bitmap/PNGRenderer.java b/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
index 3c24bf39f..143436d5d 100644
--- a/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
+++ b/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
@@ -11,6 +11,7 @@ import java.io.OutputStream;
import org.apache.batik.ext.awt.image.codec.PNGEncodeParam;
import org.apache.batik.ext.awt.image.codec.PNGImageEncoder;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.PageViewport;
import org.apache.fop.render.java2d.Java2DRenderer;
@@ -22,7 +23,7 @@ import org.apache.fop.render.java2d.Java2DRenderer;
public class PNGRenderer extends Java2DRenderer {
/** The MIME type for png-Rendering */
- public static final String MIME_TYPE = "image/png";
+ public static final String MIME_TYPE = MimeConstants.MIME_PNG;
/** The file syntax prefix, eg. "page" will output "page1.png" etc */
private String filePrefix;
diff --git a/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java b/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java
new file mode 100644
index 000000000..bb21c496c
--- /dev/null
+++ b/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.bitmap;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the PNG Renderer.
+ */
+public class PNGRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_PNG};
+
+
+ /** @see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new PNGRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
index 0cc4c1798..264c7b6f6 100644
--- a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
+++ b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
@@ -41,6 +41,7 @@ import org.apache.batik.ext.awt.image.codec.tiff.TIFFImageEncoder;
import org.apache.batik.ext.awt.image.rendered.FormatRed;
import org.apache.commons.logging.Log;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.java2d.Java2DRenderer;
/**
@@ -67,7 +68,7 @@ import org.apache.fop.render.java2d.Java2DRenderer;
public class TIFFRenderer extends Java2DRenderer {
/** The MIME type for tiff-Rendering */
- public static final String MIME_TYPE = "image/tiff";
+ public static final String MIME_TYPE = MimeConstants.MIME_TIFF;
/** */
private TIFFEncodeParam renderParams;
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java b/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java
new file mode 100644
index 000000000..3aaa01414
--- /dev/null
+++ b/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.bitmap;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the TIFF Renderer.
+ */
+public class TIFFRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_TIFF};
+
+
+ /** @see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new TIFFRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/java2d/Java2DGraphics2DAdapter.java b/src/java/org/apache/fop/render/java2d/Java2DGraphics2DAdapter.java
new file mode 100644
index 000000000..d2982e3c0
--- /dev/null
+++ b/src/java/org/apache/fop/render/java2d/Java2DGraphics2DAdapter.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.java2d;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+
+import org.apache.fop.render.Graphics2DAdapter;
+import org.apache.fop.render.Graphics2DImagePainter;
+import org.apache.fop.render.RendererContext;
+
+/**
+ * Graphics2DAdapter implementation for Java2D.
+ */
+public class Java2DGraphics2DAdapter implements Graphics2DAdapter {
+
+ private Java2DGraphicsState state;
+
+ /**
+ * Main constructor
+ * @param renderer the Renderer instance to which this instance belongs
+ */
+ public Java2DGraphics2DAdapter(Java2DGraphicsState state) {
+ this.state = state;
+ }
+
+ /** @see org.apache.fop.render.Graphics2DAdapter */
+ public void paintImage(Graphics2DImagePainter painter,
+ RendererContext context,
+ int x, int y, int width, int height) throws IOException {
+
+ float fwidth = width / 1000f;
+ float fheight = height / 1000f;
+ float fx = x / 1000f;
+ float fy = y / 1000f;
+
+ // get the 'width' and 'height' attributes of the SVG document
+ Dimension dim = painter.getImageSize();
+ float imw = (float)dim.getWidth() / 1000f;
+ float imh = (float)dim.getHeight() / 1000f;
+
+ float sx = fwidth / (float)imw;
+ float sy = fheight / (float)imh;
+
+ state.push();
+ state.getGraph().setColor(Color.black);
+ state.getGraph().setBackground(Color.black);
+
+ //TODO Clip to the image area.
+
+ // transform so that the coordinates (0,0) is from the top left
+ // and positive is down and to the right. (0,0) is where the
+ // viewBox puts it.
+ state.getGraph().translate(fx, fy);
+ AffineTransform at = AffineTransform.getScaleInstance(sx, sy);
+ if (!at.isIdentity()) {
+ state.getGraph().transform(at);
+ }
+
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+ painter.paint(state.getGraph(), area);
+
+ state.pop();
+
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
index 4661eb49d..4e288f4e4 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
@@ -26,7 +26,6 @@ import java.awt.RenderingHints;
import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
-import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
@@ -69,6 +68,7 @@ import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.image.XMLImage;
import org.apache.fop.render.AbstractRenderer;
+import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.RendererContext;
import org.apache.fop.render.pdf.CTMHelper;
import org.apache.fop.traits.BorderProps;
@@ -100,9 +100,6 @@ import org.w3c.dom.Document;
*/
public abstract class Java2DRenderer extends AbstractRenderer implements Printable {
- /** The MIME type for Java2D-Rendering */
- public static final String MIME_TYPE = "application/X-Java2D";
-
/** The scale factor for the image size, values: ]0 ; 1] */
protected double scaleFactor = 1;
@@ -152,7 +149,7 @@ public abstract class Java2DRenderer extends AbstractRenderer implements Printab
*/
public void setUserAgent(FOUserAgent foUserAgent) {
super.setUserAgent(foUserAgent);
- Java2DSVGHandler xmlHandler = new Java2DSVGHandler();
+ Java2DSVGHandler xmlHandler = new Java2DSVGHandler(getMimeType());
userAgent.getXMLHandlerRegistry().addXMLHandler(xmlHandler);
userAgent.setRendererOverride(this); // for document regeneration
}
@@ -162,11 +159,6 @@ public abstract class Java2DRenderer extends AbstractRenderer implements Printab
return userAgent;
}
- /** @see org.apache.fop.render.AbstractRenderer */
- public String getMimeType() {
- return MIME_TYPE;
- }
-
/**
* @see org.apache.fop.render.Renderer#setupFontInfo(org.apache.fop.fonts.FontInfo)
*/
@@ -178,6 +170,11 @@ public abstract class Java2DRenderer extends AbstractRenderer implements Printab
FontSetup.setup(fontInfo, fontImage.createGraphics());
}
+ /** @see org.apache.fop.render.Renderer#getGraphics2DAdapter() */
+ public Graphics2DAdapter getGraphics2DAdapter() {
+ return new Java2DGraphics2DAdapter(state);
+ }
+
/**
* Sets the new scale factor.
* @param newScaleFactor ]0 ; 1]
@@ -1046,7 +1043,7 @@ public abstract class Java2DRenderer extends AbstractRenderer implements Printab
*/
public void renderDocument(Document doc, String ns, Rectangle2D pos) {
RendererContext context;
- context = new RendererContext(this, MIME_TYPE);
+ context = new RendererContext(this, getMimeType());
context.setUserAgent(userAgent);
context.setProperty(Java2DSVGHandler.JAVA2D_STATE, state);
diff --git a/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java b/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java
index d89adf63d..575967f03 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java
@@ -73,10 +73,14 @@ public class Java2DSVGHandler implements XMLHandler {
*/
public static final String JAVA2D_YPOS = "ypos";
+ private String mimeType;
+
/**
* Create a new Java2D XML handler for use by the Java2D renderer.
+ * @param MIME type that this handler is used for
*/
- public Java2DSVGHandler() {
+ public Java2DSVGHandler(String mime) {
+ this.mimeType = mime;
}
/** @see org.apache.fop.render.XMLHandler */
@@ -178,7 +182,7 @@ public class Java2DSVGHandler implements XMLHandler {
AffineTransform origTransform = info.state.getGraph().getTransform();
// correct integer roundoff
- info.state.getGraph().translate(x / 1000, y / 1000);
+ info.state.getGraph().translate(x / 1000f, y / 1000f);
//SVGSVGElement svg = ((SVGDocument) doc).getRootElement();
// Aspect ratio preserved by layout engine, not here
@@ -199,7 +203,7 @@ public class Java2DSVGHandler implements XMLHandler {
/** @see org.apache.fop.render.XMLHandler#getMimeType() */
public String getMimeType() {
- return Java2DRenderer.MIME_TYPE;
+ return this.mimeType;
}
/** @see org.apache.fop.render.XMLHandler#getNamespace() */
diff --git a/src/java/org/apache/fop/render/mif/MIFFOEventHandlerMaker.java b/src/java/org/apache/fop/render/mif/MIFFOEventHandlerMaker.java
new file mode 100644
index 000000000..96bde2600
--- /dev/null
+++ b/src/java/org/apache/fop/render/mif/MIFFOEventHandlerMaker.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.mif;
+
+import java.io.OutputStream;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.fo.FOEventHandler;
+import org.apache.fop.render.AbstractFOEventHandlerMaker;
+
+/**
+ * Maker class for MIF support.
+ */
+public class MIFFOEventHandlerMaker extends AbstractFOEventHandlerMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_MIF};
+
+
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker */
+ public FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out) {
+ return new MIFHandler(ua, out);
+ }
+
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/mif/MIFHandler.java b/src/java/org/apache/fop/render/mif/MIFHandler.java
index 78f108f82..c9ef2a53e 100644
--- a/src/java/org/apache/fop/render/mif/MIFHandler.java
+++ b/src/java/org/apache/fop/render/mif/MIFHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@ package org.apache.fop.render.mif;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.FOEventHandler;
import org.apache.fop.fo.flow.BasicLink;
@@ -57,6 +59,9 @@ import org.xml.sax.SAXException;
*/
public class MIFHandler extends FOEventHandler {
+ /** Logger */
+ private static Log log = LogFactory.getLog(MIFHandler.class);
+
/** the MIFFile instance */
protected MIFFile mifFile;
@@ -82,6 +87,7 @@ public class MIFHandler extends FOEventHandler {
* @see org.apache.fop.fo.FOEventHandler#startDocument()
*/
public void startDocument() throws SAXException {
+ log.fatal("The MIF Handler is non-functional at this time. Please help resurrect it!");
mifFile = new MIFFile();
try {
mifFile.output(outStream);
diff --git a/src/java/org/apache/fop/render/pcl/PCLRenderer.java b/src/java/org/apache/fop/render/pcl/PCLRenderer.java
index a7283c7bb..f322d2679 100644
--- a/src/java/org/apache/fop/render/pcl/PCLRenderer.java
+++ b/src/java/org/apache/fop/render/pcl/PCLRenderer.java
@@ -19,6 +19,7 @@
package org.apache.fop.render.pcl;
// FOP
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.PrintRenderer;
// Java
@@ -33,7 +34,7 @@ import java.io.OutputStream;
public class PCLRenderer extends PrintRenderer {
/** The MIME type for PCL */
- public static final String MIME_TYPE = "application/vnd.hp-PCL";
+ public static final String MIME_TYPE = MimeConstants.MIME_PCL_ALT;
/**
* the current stream to add PCL commands to
@@ -156,6 +157,7 @@ public class PCLRenderer extends PrintRenderer {
public void startRenderer(OutputStream outputStream) throws IOException {
log.info("rendering areas to PCL");
+ log.fatal("The PCL Renderer is non-functional at this time. Please help resurrect it!");
currentStream = new PCLStream(outputStream);
// Set orientation.
diff --git a/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java b/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java
new file mode 100644
index 000000000..2e39d355a
--- /dev/null
+++ b/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pcl;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the PCL Renderer.
+ */
+public class PCLRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {
+ MimeConstants.MIME_PCL,
+ MimeConstants.MIME_PCL_ALT};
+
+
+ /**@see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new PCLRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java b/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
new file mode 100644
index 000000000..8a72fc4b9
--- /dev/null
+++ b/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pdf;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+
+import org.apache.batik.bridge.ViewBox;
+import org.apache.fop.render.Graphics2DAdapter;
+import org.apache.fop.render.Graphics2DImagePainter;
+import org.apache.fop.render.RendererContext;
+import org.apache.fop.svg.PDFGraphics2D;
+import org.w3c.dom.svg.SVGDocument;
+import org.w3c.dom.svg.SVGSVGElement;
+
+/**
+ * Graphics2DAdapter implementation for PDF.
+ */
+public class PDFGraphics2DAdapter implements Graphics2DAdapter {
+
+ private PDFRenderer renderer;
+
+ /**
+ * Main constructor
+ * @param renderer the Renderer instance to which this instance belongs
+ */
+ public PDFGraphics2DAdapter(PDFRenderer renderer) {
+ this.renderer = renderer;
+ }
+
+ /** @see org.apache.fop.render.Graphics2DAdapter */
+ public void paintImage(Graphics2DImagePainter painter,
+ RendererContext context,
+ int x, int y, int width, int height) throws IOException {
+
+ PDFSVGHandler.PDFInfo pdfInfo = PDFSVGHandler.getPDFInfo(context);
+
+ float fwidth = width / 1000f;
+ float fheight = height / 1000f;
+ float fx = x / 1000f;
+ float fy = y / 1000f;
+
+ // get the 'width' and 'height' attributes of the SVG document
+ Dimension dim = painter.getImageSize();
+ float imw = (float)dim.getWidth() / 1000f;
+ float imh = (float)dim.getHeight() / 1000f;
+
+ float sx = fwidth / (float)imw;
+ float sy = fheight / (float)imh;
+
+ renderer.saveGraphicsState();
+ renderer.setColor(Color.black, false, null);
+ renderer.setColor(Color.black, true, null);
+
+ //TODO Clip to the image area.
+
+ // transform so that the coordinates (0,0) is from the top left
+ // and positive is down and to the right. (0,0) is where the
+ // viewBox puts it.
+ renderer.currentStream.add(sx + " 0 0 " + sy + " " + fx + " "
+ + fy + " cm\n");
+
+
+ final boolean textAsShapes = false;
+ PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes,
+ pdfInfo.fi, pdfInfo.pdfDoc,
+ pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(),
+ renderer.currentFontName,
+ renderer.currentFontSize);
+ graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
+
+ AffineTransform transform = new AffineTransform();
+ transform.translate(fx, fy);
+ pdfInfo.pdfState.setTransform(transform);
+ graphics.setPDFState(pdfInfo.pdfState);
+ graphics.setOutputStream(pdfInfo.outputStream);
+
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+ painter.paint(graphics, area);
+
+ pdfInfo.currentStream.add(graphics.getString());
+ renderer.restoreGraphicsState();
+ pdfInfo.pdfState.pop();
+
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index f30b0e0d0..7006cb8b9 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -38,6 +38,7 @@ import org.apache.avalon.framework.configuration.ConfigurationException;
// FOP
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.CTM;
import org.apache.fop.area.LineArea;
import org.apache.fop.area.Page;
@@ -78,6 +79,7 @@ import org.apache.fop.pdf.PDFStream;
import org.apache.fop.pdf.PDFText;
import org.apache.fop.pdf.PDFXObject;
import org.apache.fop.render.AbstractPathOrientedRenderer;
+import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.RendererContext;
import org.apache.fop.fo.Constants;
@@ -102,7 +104,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
/**
* The mime type for pdf
*/
- public static final String MIME_TYPE = "application/pdf";
+ public static final String MIME_TYPE = MimeConstants.MIME_PDF;
/** Controls whether comments are written to the PDF stream. */
protected static final boolean WRITE_COMMENTS = true;
@@ -338,6 +340,11 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
}
}
+ /** @see org.apache.fop.render.Renderer#getGraphics2DAdapter() */
+ public Graphics2DAdapter getGraphics2DAdapter() {
+ return new PDFGraphics2DAdapter(this);
+ }
+
/**
* writes out a comment.
* @param text text for the comment
diff --git a/src/java/org/apache/fop/render/pdf/PDFRendererMaker.java b/src/java/org/apache/fop/render/pdf/PDFRendererMaker.java
new file mode 100644
index 000000000..cbab95260
--- /dev/null
+++ b/src/java/org/apache/fop/render/pdf/PDFRendererMaker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pdf;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the PDF Renderer.
+ */
+public class PDFRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_PDF};
+
+
+ /**@see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new PDFRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/print/PrintRendererMaker.java b/src/java/org/apache/fop/render/print/PrintRendererMaker.java
new file mode 100644
index 000000000..39e7fa921
--- /dev/null
+++ b/src/java/org/apache/fop/render/print/PrintRendererMaker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.print;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the Print Renderer.
+ */
+public class PrintRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_PRINT};
+
+
+ /**@see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new PrintRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return false;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java b/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
new file mode 100644
index 000000000..d54c87b8c
--- /dev/null
+++ b/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import java.awt.Dimension;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+
+import org.apache.fop.render.Graphics2DAdapter;
+import org.apache.fop.render.Graphics2DImagePainter;
+import org.apache.fop.render.RendererContext;
+
+/**
+ * Graphics2DAdapter implementation for PostScript.
+ */
+public class PSGraphics2DAdapter implements Graphics2DAdapter {
+
+ private PSRenderer renderer;
+
+ /**
+ * Main constructor
+ * @param renderer the Renderer instance to which this instance belongs
+ */
+ public PSGraphics2DAdapter(PSRenderer renderer) {
+ this.renderer = renderer;
+ }
+
+ /** @see org.apache.fop.render.Graphics2DAdapter */
+ public void paintImage(Graphics2DImagePainter painter,
+ RendererContext context,
+ int x, int y, int width, int height) throws IOException {
+ PSGenerator gen = renderer.gen;
+
+ float fwidth = width / 1000f;
+ float fheight = height / 1000f;
+ float fx = x / 1000f;
+ float fy = y / 1000f;
+
+ // get the 'width' and 'height' attributes of the SVG document
+ Dimension dim = painter.getImageSize();
+ float imw = (float)dim.getWidth() / 1000f;
+ float imh = (float)dim.getHeight() / 1000f;
+
+ float sx = fwidth / (float)imw;
+ float sy = fheight / (float)imh;
+
+ gen.commentln("%FOPBeginGraphics2D");
+ gen.saveGraphicsState();
+ // Clip to the image area.
+ gen.writeln("newpath");
+ gen.defineRect(fx, fy, fwidth, fheight);
+ gen.writeln("clip");
+
+ // transform so that the coordinates (0,0) is from the top left
+ // and positive is down and to the right. (0,0) is where the
+ // viewBox puts it.
+ gen.concatMatrix(sx, 0, 0, sy, fx, fy);
+
+ final boolean textAsShapes = false;
+ PSGraphics2D graphics = new PSGraphics2D(textAsShapes, gen);
+ graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
+ AffineTransform transform = new AffineTransform();
+ // scale to viewbox
+ transform.translate(fx, fy);
+ gen.getCurrentState().concatMatrix(transform);
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+ painter.paint(graphics, area);
+
+ gen.restoreGraphicsState();
+ gen.commentln("%FOPEndGraphics2D");
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java
index 1902df16e..5c43050d0 100644
--- a/src/java/org/apache/fop/render/ps/PSRenderer.java
+++ b/src/java/org/apache/fop/render/ps/PSRenderer.java
@@ -59,6 +59,7 @@ import org.apache.fop.image.EPSImage;
import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.image.XMLImage;
+import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.AbstractPathOrientedRenderer;
import org.apache.fop.render.RendererContext;
import org.apache.fop.render.ps.extensions.PSSetupCode;
@@ -134,6 +135,11 @@ public class PSRenderer extends AbstractPathOrientedRenderer {
userAgent.getXMLHandlerRegistry().addXMLHandler(xmlHandler);
}
+ /** @see org.apache.fop.render.Renderer#getGraphics2DAdapter() */
+ public Graphics2DAdapter getGraphics2DAdapter() {
+ return new PSGraphics2DAdapter(this);
+ }
+
/**
* Write out a command
* @param cmd PostScript command
diff --git a/src/java/org/apache/fop/render/ps/PSRendererMaker.java b/src/java/org/apache/fop/render/ps/PSRendererMaker.java
new file mode 100644
index 000000000..077e45d72
--- /dev/null
+++ b/src/java/org/apache/fop/render/ps/PSRendererMaker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the PostScript Renderer.
+ */
+public class PSRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_POSTSCRIPT};
+
+
+ /** @see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new PSRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/ps/PSSVGHandler.java b/src/java/org/apache/fop/render/ps/PSSVGHandler.java
index 5d829c443..7768cb91a 100644
--- a/src/java/org/apache/fop/render/ps/PSSVGHandler.java
+++ b/src/java/org/apache/fop/render/ps/PSSVGHandler.java
@@ -307,6 +307,7 @@ public class PSSVGHandler implements XMLHandler {
gen.writeln("newpath");
gen.defineRect(xOffset / 1000f, yOffset / 1000f,
psInfo.getWidth() / 1000f, psInfo.getWidth() / 1000f);
+ //TODO Is the above correct? Twice getWidth??????????????
gen.writeln("clip");
// transform so that the coordinates (0,0) is from the top left
@@ -337,7 +338,7 @@ public class PSSVGHandler implements XMLHandler {
+ e.getMessage(), e);
}
- psInfo.psGenerator.restoreGraphicsState();
+ gen.restoreGraphicsState();
gen.commentln("%FOPEndSVG");
} catch (IOException ioe) {
log.error("SVG graphic could not be rendered: "
diff --git a/src/java/org/apache/fop/render/rtf/RTFFOEventHandlerMaker.java b/src/java/org/apache/fop/render/rtf/RTFFOEventHandlerMaker.java
new file mode 100644
index 000000000..2ad238b2e
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/RTFFOEventHandlerMaker.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.rtf;
+
+import java.io.OutputStream;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.fo.FOEventHandler;
+import org.apache.fop.render.AbstractFOEventHandlerMaker;
+
+/**
+ * Maker class for RTF support.
+ */
+public class RTFFOEventHandlerMaker extends AbstractFOEventHandlerMaker {
+
+ private static final String[] MIMES = new String[] {
+ MimeConstants.MIME_RTF,
+ MimeConstants.MIME_RTF_ALT1,
+ MimeConstants.MIME_RTF_ALT2};
+
+
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker */
+ public FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out) {
+ return new RTFHandler(ua, out);
+ }
+
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/svg/SVGRendererMaker.java b/src/java/org/apache/fop/render/svg/SVGRendererMaker.java
new file mode 100644
index 000000000..5dfcd3d03
--- /dev/null
+++ b/src/java/org/apache/fop/render/svg/SVGRendererMaker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.svg;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the SVG Renderer.
+ */
+public class SVGRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_SVG};
+
+
+ /**@see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new SVGRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/txt/TXTFOEventHandlerMaker.java b/src/java/org/apache/fop/render/txt/TXTFOEventHandlerMaker.java
new file mode 100644
index 000000000..ddc981a40
--- /dev/null
+++ b/src/java/org/apache/fop/render/txt/TXTFOEventHandlerMaker.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.txt;
+
+import java.io.OutputStream;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.fo.FOEventHandler;
+import org.apache.fop.render.AbstractFOEventHandlerMaker;
+
+/**
+ * Maker class for the special FOEventHandler for TXT support.
+ */
+public class TXTFOEventHandlerMaker extends AbstractFOEventHandlerMaker {
+
+ private static final String[] MIMES = new String[] {
+ MimeConstants.MIME_PLAIN_TEXT};
+
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker */
+ public FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out) throws FOPException {
+ return new TXTHandler(ua, out);
+ }
+
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/txt/TXTHandler.java b/src/java/org/apache/fop/render/txt/TXTHandler.java
index d75e65f50..87e6defee 100644
--- a/src/java/org/apache/fop/render/txt/TXTHandler.java
+++ b/src/java/org/apache/fop/render/txt/TXTHandler.java
@@ -25,6 +25,7 @@ import java.util.List;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.AreaTreeHandler;
import org.apache.fop.datatypes.CompoundDatatype;
import org.apache.fop.datatypes.Length;
@@ -94,7 +95,7 @@ public class TXTHandler extends AreaTreeHandler {
*/
public TXTHandler(FOUserAgent userAgent, OutputStream stream)
throws FOPException {
- super(userAgent, Constants.RENDER_TXT, stream);
+ super(userAgent, MimeConstants.MIME_PLAIN_TEXT, stream);
}
/**
diff --git a/src/java/org/apache/fop/render/txt/TXTRendererMaker.java b/src/java/org/apache/fop/render/txt/TXTRendererMaker.java
new file mode 100644
index 000000000..026c7996c
--- /dev/null
+++ b/src/java/org/apache/fop/render/txt/TXTRendererMaker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.txt;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the Plain Text Renderer.
+ */
+public class TXTRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_PLAIN_TEXT};
+
+
+ /**@see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new TXTRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java
index ad6c9331a..e02b07f2f 100644
--- a/src/java/org/apache/fop/render/xml/XMLRenderer.java
+++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java
@@ -42,6 +42,7 @@ import org.apache.fop.render.RendererContext;
import org.apache.fop.render.XMLHandler;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.Area;
import org.apache.fop.area.BeforeFloat;
import org.apache.fop.area.Block;
@@ -79,7 +80,7 @@ import org.apache.fop.area.inline.WordArea;
public class XMLRenderer extends PrintRenderer {
/** XML MIME type */
- public static final String XML_MIME_TYPE = "application/x-fop-areatree";
+ public static final String XML_MIME_TYPE = MimeConstants.MIME_FOP_AREA_TREE;
/** Main namespace in use. */
public static final String NS = "";
diff --git a/src/java/org/apache/fop/render/xml/XMLRendererMaker.java b/src/java/org/apache/fop/render/xml/XMLRendererMaker.java
new file mode 100644
index 000000000..639a63993
--- /dev/null
+++ b/src/java/org/apache/fop/render/xml/XMLRendererMaker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.xml;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the Area Tree XML Renderer.
+ */
+public class XMLRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_AREA_TREE};
+
+
+ /**@see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new XMLRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}