diff options
Diffstat (limited to 'src/java/org/apache/fop')
45 files changed, 1708 insertions, 230 deletions
diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java index 71a645c63..5d2686920 100644 --- a/src/java/org/apache/fop/apps/FOUserAgent.java +++ b/src/java/org/apache/fop/apps/FOUserAgent.java @@ -44,6 +44,7 @@ import org.apache.fop.fo.FOEventHandler; import org.apache.fop.layoutmgr.LayoutManagerMaker; import org.apache.fop.pdf.PDFEncryptionParams; import org.apache.fop.render.Renderer; +import org.apache.fop.render.RendererFactory; import org.apache.fop.render.XMLHandlerRegistry; /** @@ -77,6 +78,9 @@ public class FOUserAgent { /** Defines the default page-width */ public static final String DEFAULT_PAGE_WIDTH = "8.26in"; + /** Factory for Renderers and FOEventHandlers */ + private RendererFactory rendererFactory = new RendererFactory(); + /** Registry for XML handlers */ private XMLHandlerRegistry xmlHandlers = new XMLHandlerRegistry(); @@ -592,8 +596,16 @@ public class FOUserAgent { * If to create hot links to footnotes and before floats. * @return True if hot links should be created */ + /* TODO This method is never referenced! public boolean linkToFootnotes() { return true; + }*/ + + /** + * @return the RendererFactory + */ + public RendererFactory getRendererFactory() { + return this.rendererFactory; } /** diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java index 6c972185d..912e1a402 100644 --- a/src/java/org/apache/fop/apps/Fop.java +++ b/src/java/org/apache/fop/apps/Fop.java @@ -44,7 +44,10 @@ import org.apache.fop.fo.FOTreeBuilder; public class Fop implements Constants { // desired output type: RENDER_PDF, RENDER_PS, etc. - private int renderType = NOT_SET; + //private int renderType = NOT_SET; + + // desired output format: MIME type such as "application/pdf", "application/postscript" etc. + private String outputFormat = null; // output stream to send results to private OutputStream stream = null; @@ -56,6 +59,32 @@ public class Fop implements Constants { private FOTreeBuilder foTreeBuilder = null; /** + * Constructor for use with already-created FOUserAgents. It uses MIME types to select the + * output format (ex. "application/pdf" for PDF). + * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). + * @param ua FOUserAgent object + * @throws IllegalArgumentException if an unsupported renderer type was requested. + */ + public Fop(String outputFormat, FOUserAgent ua) { + this.outputFormat = outputFormat; + + foUserAgent = ua; + if (foUserAgent == null) { + foUserAgent = new FOUserAgent(); + } + } + + /** + * Constructor for FOP with a default FOUserAgent. It uses MIME types to select the + * output format (ex. "application/pdf" for PDF). + * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). + * @throws IllegalArgumentException if an unsupported renderer type was requested. + */ + public Fop(String outputFormat) { + this(outputFormat, null); + } + + /** * Constructor for use with already-created FOUserAgents * @param renderType the type of renderer to use. Must be one of * <ul> @@ -76,18 +105,7 @@ public class Fop implements Constants { * @throws IllegalArgumentException if an unsupported renderer type was requested. */ public Fop(int renderType, FOUserAgent ua) { - if (renderType < Constants.RENDER_MIN_CONST - || renderType > Constants.RENDER_MAX_CONST) { - throw new IllegalArgumentException( - "Invalid render type #" + renderType); - } - - this.renderType = renderType; - - foUserAgent = ua; - if (foUserAgent == null) { - foUserAgent = new FOUserAgent(); - } + this(getMimeTypeForRenderType(renderType), ua); } /** @@ -95,9 +113,34 @@ public class Fop implements Constants { * @see org.apache.fop.apps.Fop#Fop(int, FOUserAgent) */ public Fop(int renderType) { - this(renderType, new FOUserAgent()); + this(renderType, null); } + private static String getMimeTypeForRenderType(int renderType) { + switch(renderType) { + case Constants.RENDER_PDF: return MimeConstants.MIME_PDF; + case Constants.RENDER_PS: return MimeConstants.MIME_POSTSCRIPT; + case Constants.RENDER_PCL: return MimeConstants.MIME_PCL; + case Constants.RENDER_MIF: return MimeConstants.MIME_MIF; + case Constants.RENDER_RTF: return MimeConstants.MIME_RTF; + case Constants.RENDER_SVG: return MimeConstants.MIME_SVG; + case Constants.RENDER_TXT: return MimeConstants.MIME_PLAIN_TEXT; + + //Bitmap formats + case Constants.RENDER_PNG: return MimeConstants.MIME_PNG; + case Constants.RENDER_TIFF: return MimeConstants.MIME_TIFF; + + //Area tree XML: FOP-specific + case Constants.RENDER_XML: return MimeConstants.MIME_FOP_AREA_TREE; + + //Non-standard pseudo MIME types + case Constants.RENDER_AWT: return MimeConstants.MIME_FOP_AWT_PREVIEW; + case Constants.RENDER_PRINT: return MimeConstants.MIME_FOP_PRINT; + default: + throw new IllegalArgumentException("Illegal renderType value: " + renderType); + } + } + /** * Get the FOUserAgent instance for this process * @return the user agent @@ -128,7 +171,7 @@ public class Fop implements Constants { */ public DefaultHandler getDefaultHandler() throws FOPException { if (foTreeBuilder == null) { - this.foTreeBuilder = new FOTreeBuilder(renderType, foUserAgent, stream); + this.foTreeBuilder = new FOTreeBuilder(outputFormat, foUserAgent, stream); } return this.foTreeBuilder; } diff --git a/src/java/org/apache/fop/apps/MimeConstants.java b/src/java/org/apache/fop/apps/MimeConstants.java new file mode 100644 index 000000000..f33ddf70f --- /dev/null +++ b/src/java/org/apache/fop/apps/MimeConstants.java @@ -0,0 +1,69 @@ +/*
+ * Copyright 2005 Jeremias Maerki
+ *
+ * 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.
+ */
+package org.apache.fop.apps;
+
+/**
+ * Frequently used MIME types for various file formats used when working with Apache FOP.
+ */
+public interface MimeConstants {
+
+ /** Portable Document Format */
+ String MIME_PDF = "application/pdf";
+
+ /** PostScript */
+ String MIME_POSTSCRIPT = "application/postscript";
+ /** Encapsulated PostScript (same MIME type as PostScript) */
+ String MIME_EPS = MIME_POSTSCRIPT;
+
+ /** HP's PCL */
+ String MIME_PCL = "application/x-pcl";
+ /** HP's PCL (alternative MIME type) */
+ String MIME_PCL_ALT = "application/vnd.hp-PCL";
+
+ /** Plain text */
+ String MIME_PLAIN_TEXT = "text/plain";
+
+ /** Rich text format */
+ String MIME_RTF = "application/rtf";
+ /** Rich text format (alternative 1) */
+ String MIME_RTF_ALT1 = "text/richtext";
+ /** Rich text format (alternative 2) */
+ String MIME_RTF_ALT2 = "text/rtf";
+
+ /** FrameMaker's MIF */
+ String MIME_MIF = "application/mif";
+
+ /** Structured Vector Graphics */
+ String MIME_SVG = "image/svg+xml";
+
+ /** PNG images */
+ String MIME_PNG = "image/png";
+ /** JPEG images */
+ String MIME_JPEG = "image/jpeg";
+ /** TIFF images */
+ String MIME_TIFF = "image/tiff";
+
+ /** Apache FOP's AWT preview (non-standard MIME type) */
+ String MIME_FOP_AWT_PREVIEW = "application/X-fop-awt-preview";
+ /** Apache FOP's Direct Printing (non-standard MIME type) */
+ String MIME_FOP_PRINT = "application/X-fop-print";
+ /** Apache FOP's area tree XML */
+ String MIME_FOP_AREA_TREE = "application/X-fop-areatree";
+
+ /** Proposed but non-registered MIME type for XSL-FO */
+ String MIME_XSL_FO = "text/xsl";
+
+}
diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java index 183ca8896..df7b74fb3 100644 --- a/src/java/org/apache/fop/area/AreaTreeHandler.java +++ b/src/java/org/apache/fop/area/AreaTreeHandler.java @@ -103,16 +103,15 @@ public class AreaTreeHandler extends FOEventHandler { /** * Constructor. * @param userAgent FOUserAgent object for process - * @param renderType Desired fo.Constants output type (RENDER_PDF, - * RENDER_PS, etc.) + * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). * @param stream OutputStream * @throws FOPException if the RenderPagesModel cannot be created */ - public AreaTreeHandler (FOUserAgent userAgent, int renderType, + public AreaTreeHandler (FOUserAgent userAgent, String outputFormat, OutputStream stream) throws FOPException { super(userAgent); - model = new RenderPagesModel(userAgent, renderType, fontInfo, + model = new RenderPagesModel(userAgent, outputFormat, fontInfo, stream); lmMaker = userAgent.getLayoutManagerMakerOverride(); diff --git a/src/java/org/apache/fop/area/CachedRenderPagesModel.java b/src/java/org/apache/fop/area/CachedRenderPagesModel.java index d86e9913b..6737ccb5a 100644 --- a/src/java/org/apache/fop/area/CachedRenderPagesModel.java +++ b/src/java/org/apache/fop/area/CachedRenderPagesModel.java @@ -46,11 +46,11 @@ public class CachedRenderPagesModel extends RenderPagesModel { /** * Constructor - * @see org.apache.fop.area.RenderPagesModel#RenderPagesModel(FOUserAgent, int, FontInfo, OutputStream) + * @see org.apache.fop.area.RenderPagesModel#RenderPagesModel(FOUserAgent, String, FontInfo, OutputStream) */ - public CachedRenderPagesModel (FOUserAgent userAgent, int renderType, - FontInfo fontInfo, OutputStream stream) throws FOPException { - super(userAgent, renderType, fontInfo, stream); + public CachedRenderPagesModel (FOUserAgent userAgent, String outputFormat, + FontInfo fontInfo, OutputStream stream) throws FOPException { + super(userAgent, outputFormat, fontInfo, stream); } /** diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java index 505902e33..a3c6eda27 100644 --- a/src/java/org/apache/fop/area/RenderPagesModel.java +++ b/src/java/org/apache/fop/area/RenderPagesModel.java @@ -58,17 +58,17 @@ public class RenderPagesModel extends AreaTreeModel { /** * Create a new render pages model with the given renderer. * @param userAgent FOUserAgent object for process - * @param renderType Desired fo.Constants output type (RENDER_PDF, - * RENDER_PS, etc.) + * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). * @param fontInfo FontInfo object * @param stream OutputStream * @throws FOPException if the renderer cannot be properly initialized */ - public RenderPagesModel (FOUserAgent userAgent, int renderType, + public RenderPagesModel (FOUserAgent userAgent, String outputFormat, FontInfo fontInfo, OutputStream stream) throws FOPException { super(); - renderer = RendererFactory.createRenderer(userAgent, renderType); + renderer = userAgent.getRendererFactory().createRenderer( + userAgent, outputFormat); try { renderer.setupFontInfo(fontInfo); diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index b0c1bf4e0..c1d922964 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -28,6 +28,7 @@ import java.util.Vector; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; +import org.apache.fop.apps.MimeConstants; import org.apache.fop.fo.Constants; import org.apache.fop.pdf.PDFEncryptionManager; import org.apache.fop.pdf.PDFEncryptionParams; @@ -73,7 +74,7 @@ public class CommandLineOptions implements Constants { /* input mode */ private int inputmode = NOT_SET; /* output mode */ - private int outputmode = NOT_SET; + private String outputmode = null; private FOUserAgent foUserAgent; @@ -132,7 +133,7 @@ public class CommandLineOptions implements Constants { inputHandler = createInputHandler(); - if (outputmode == RENDER_AWT) { + if (outputmode.equals(MimeConstants.MIME_FOP_AWT_PREVIEW)) { AWTRenderer renderer = new AWTRenderer(); renderer.setRenderable(inputHandler); //set before user agent! renderer.setUserAgent(foUserAgent); @@ -217,6 +218,8 @@ public class CommandLineOptions implements Constants { i = i + parseSVGOutputOption(args, i); } else if (args[i].equals("-foout")) { i = i + parseFOOutputOption(args, i); + } else if (args[i].equals("-out")) { + i = i + parseCustomOutputOption(args, i); } else if (args[i].charAt(0) != '-') { i = i + parseUnknownOption(args, i); } else if (args[i].equals("-at")) { @@ -323,15 +326,15 @@ public class CommandLineOptions implements Constants { } private int parseAWTOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_AWT); + setOutputMode(MimeConstants.MIME_FOP_AWT_PREVIEW); return 0; } private int parsePDFOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_PDF); + setOutputMode(MimeConstants.MIME_PDF); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { - throw new FOPException("you must specify the pdf output file"); + throw new FOPException("you must specify the PDF output file"); } else { outfile = new File(args[i + 1]); return 1; @@ -339,10 +342,10 @@ public class CommandLineOptions implements Constants { } private int parseMIFOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_MIF); + setOutputMode(MimeConstants.MIME_MIF); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { - throw new FOPException("you must specify the mif output file"); + throw new FOPException("you must specify the MIF output file"); } else { outfile = new File(args[i + 1]); return 1; @@ -350,10 +353,10 @@ public class CommandLineOptions implements Constants { } private int parseRTFOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_RTF); + setOutputMode(MimeConstants.MIME_RTF); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { - throw new FOPException("you must specify the rtf output file"); + throw new FOPException("you must specify the RTF output file"); } else { outfile = new File(args[i + 1]); return 1; @@ -361,10 +364,10 @@ public class CommandLineOptions implements Constants { } private int parseTIFFOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_TIFF); + setOutputMode(MimeConstants.MIME_TIFF); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { - throw new FOPException("you must specify the tiff output file"); + throw new FOPException("you must specify the TIFF output file"); } else { outfile = new File(args[i + 1]); return 1; @@ -372,10 +375,10 @@ public class CommandLineOptions implements Constants { } private int parsePNGOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_PNG); + setOutputMode(MimeConstants.MIME_PNG); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { - throw new FOPException("you must specify the png output file"); + throw new FOPException("you must specify the PNG output file"); } else { outfile = new File(args[i + 1]); return 1; @@ -383,15 +386,15 @@ public class CommandLineOptions implements Constants { } private int parsePrintOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_PRINT); + setOutputMode(MimeConstants.MIME_FOP_PRINT); return 0; } private int parsePCLOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_PCL); + setOutputMode(MimeConstants.MIME_PCL); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { - throw new FOPException("you must specify the pdf output file"); + throw new FOPException("you must specify the PDF output file"); } else { outfile = new File(args[i + 1]); return 1; @@ -399,7 +402,7 @@ public class CommandLineOptions implements Constants { } private int parsePostscriptOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_PS); + setOutputMode(MimeConstants.MIME_POSTSCRIPT); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the PostScript output file"); @@ -410,7 +413,7 @@ public class CommandLineOptions implements Constants { } private int parseTextOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_TXT); + setOutputMode(MimeConstants.MIME_PLAIN_TEXT); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the text output file"); @@ -421,10 +424,10 @@ public class CommandLineOptions implements Constants { } private int parseSVGOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_SVG); + setOutputMode(MimeConstants.MIME_SVG); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { - throw new FOPException("you must specify the svg output file"); + throw new FOPException("you must specify the SVG output file"); } else { outfile = new File(args[i + 1]); return 1; @@ -432,7 +435,7 @@ public class CommandLineOptions implements Constants { } private int parseFOOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_NONE); + setOutputMode(MimeConstants.MIME_XSL_FO); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the FO output file"); @@ -442,12 +445,37 @@ public class CommandLineOptions implements Constants { } } + private int parseCustomOutputOption(String[] args, int i) throws FOPException { + String mime = null; + if ((i + 1 < args.length) + || (args[i + 1].charAt(0) != '-')) { + mime = args[i + 1]; + if ("list".equals(mime)) { + String[] mimes = foUserAgent.getRendererFactory().listSupportedMimeTypes(); + System.out.println("Supported MIME types:"); + for (int j = 0; j < mimes.length; j++) { + System.out.println(" " + mimes[j]); + } + System.exit(0); + } + } + if ((i + 2 >= args.length) + || (args[i + 1].charAt(0) == '-') + || (args[i + 2].charAt(0) == '-')) { + throw new FOPException("you must specify the output format and the output file"); + } else { + setOutputMode(mime); + outfile = new File(args[i + 2]); + return 2; + } + } + private int parseUnknownOption(String[] args, int i) throws FOPException { if (inputmode == NOT_SET) { inputmode = FO_INPUT; fofile = new File(args[i]); - } else if (outputmode == NOT_SET) { - outputmode = RENDER_PDF; + } else if (outputmode == null) { + outputmode = MimeConstants.MIME_PDF; outfile = new File(args[i]); } else { throw new FOPException("Don't know what to do with " @@ -457,7 +485,7 @@ public class CommandLineOptions implements Constants { } private int parseAreaTreeOption(String[] args, int i) throws FOPException { - setOutputMode(RENDER_XML); + setOutputMode(MimeConstants.MIME_FOP_AREA_TREE); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the area-tree output file"); @@ -500,9 +528,9 @@ public class CommandLineOptions implements Constants { } } - private void setOutputMode(int mode) throws FOPException { - if (outputmode == NOT_SET) { - outputmode = mode; + private void setOutputMode(String mime) throws FOPException { + if (outputmode == null) { + outputmode = mime; } else { throw new FOPException("you can only set one output method"); } @@ -537,11 +565,13 @@ public class CommandLineOptions implements Constants { throw new FOPException("No input file specified"); } - if (outputmode == NOT_SET) { + if (outputmode == null) { throw new FOPException("No output file specified"); } - if ((outputmode == RENDER_AWT || outputmode == RENDER_PRINT) && outfile != null) { + if ((outputmode.equals(MimeConstants.MIME_FOP_AWT_PREVIEW) + || outputmode.equals(MimeConstants.MIME_FOP_PRINT)) + && outfile != null) { throw new FOPException("Output file may not be specified " + "for AWT or PRINT output"); } @@ -577,7 +607,7 @@ public class CommandLineOptions implements Constants { } } else if (inputmode == FO_INPUT) { - if (outputmode == RENDER_NONE) { + if (outputmode.equals(MimeConstants.MIME_XSL_FO)) { throw new FOPException( "FO output mode is only available if you use -xml and -xsl"); } @@ -619,32 +649,17 @@ public class CommandLineOptions implements Constants { } /** - * @return the type chosen renderer - * @throws FOPException for invalid output modes + * @return the chosen output format (MIME type) + * @throws FOPException for invalid output formats */ - protected int getRenderer() throws FOPException { - switch (outputmode) { - case RENDER_PDF: - case RENDER_AWT: - case RENDER_MIF: - case RENDER_PRINT: - case RENDER_PCL: - case RENDER_PS: - case RENDER_TXT: - case RENDER_SVG: - case RENDER_RTF: - case RENDER_TIFF: - case RENDER_PNG: - case RENDER_NONE: - return outputmode; - case RENDER_XML: - foUserAgent.getRendererOptions().put("fineDetail", isCoarseAreaXml()); - return RENDER_XML; - case NOT_SET: + protected String getOutputFormat() throws FOPException { + if (outputmode == null) { throw new FOPException("Renderer has not been set!"); - default: - throw new FOPException("Invalid Renderer setting!"); } + if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) { + foUserAgent.getRendererOptions().put("fineDetail", isCoarseAreaXml()); + } + return outputmode; } /** @@ -672,14 +687,6 @@ public class CommandLineOptions implements Constants { } /** - * Returns the output mode (output format, ex. NOT_SET or RENDER_PDF) - * @return the output mode - */ - public int getOutputMode() { - return outputmode; - } - - /** * Returns the XSL-FO file if set. * @return the XSL-FO file, null if not set */ @@ -786,7 +793,11 @@ public class CommandLineOptions implements Constants { + " -svg outfile input will be rendered as an svg slides file (outfile req'd) \n" + " -at outfile representation of area tree as XML (outfile req'd) \n" + " -print input file will be rendered and sent to the printer \n" - + " see options with \"-print help\" \n\n" + + " see options with \"-print help\" \n" + + " -out mime outfile input will be rendered using the given MIME type\n" + + " (outfile req'd) Example: \"-out application/pdf D:\\out.pdf\"\n" + + " (Tip: \"-out list\" prints the list of supported MIME types)\n" + + "\n" + " -foout outfile input will only be XSL transformed. The intermediate \n" + " XSL-FO file is saved and no rendering is performed. \n" + " (Only available if you use -xml and -xsl parameters)\n\n" @@ -832,66 +843,26 @@ public class CommandLineOptions implements Constants { log.info("unknown input type"); } log.info("Output mode: "); - switch (outputmode) { - case NOT_SET: + if (outputmode == null) { log.info("not set"); - break; - case RENDER_PDF: - log.info("pdf"); - log.info("output file: " + outfile.toString()); - break; - case RENDER_AWT: + } else if (MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputmode)) { log.info("awt on screen"); if (outfile != null) { log.error("awt mode, but outfile is set:"); log.info("out file: " + outfile.toString()); } - break; - case RENDER_MIF: - log.info("mif"); - log.info("output file: " + outfile.toString()); - break; - case RENDER_RTF: - log.info("rtf"); - log.info("output file: " + outfile.toString()); - break; - case RENDER_TIFF: - log.info("tiff"); - log.info("output file: " + outfile.toString()); - break; - case RENDER_PNG: - log.info("png"); - log.info("output file: " + outfile.toString()); - break; - case RENDER_PRINT: + } else if (MimeConstants.MIME_FOP_PRINT.equals(outputmode)) { log.info("print directly"); if (outfile != null) { log.error("print mode, but outfile is set:"); log.error("out file: " + outfile.toString()); } - break; - case RENDER_PCL: - log.info("pcl"); - log.info("output file: " + outfile.toString()); - break; - case RENDER_PS: - log.info("PostScript"); - log.info("output file: " + outfile.toString()); - break; - case RENDER_TXT: - log.info("txt"); - log.info("output file: " + outfile.toString()); - break; - case RENDER_SVG: - log.info("svg"); - log.info("output file: " + outfile.toString()); - break; - case RENDER_XML: + } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode)) { log.info("area tree"); log.info("output file: " + outfile.toString()); - break; - default: - log.info("unknown input type"); + } else { + log.info(outputmode); + log.info("output file: " + outfile.toString()); } log.info("OPTIONS"); diff --git a/src/java/org/apache/fop/cli/Main.java b/src/java/org/apache/fop/cli/Main.java index 93befd5b1..260559c1e 100644 --- a/src/java/org/apache/fop/cli/Main.java +++ b/src/java/org/apache/fop/cli/Main.java @@ -29,6 +29,7 @@ import java.util.List; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; +import org.apache.fop.apps.MimeConstants; /** * Main command-line class for Apache FOP. @@ -148,8 +149,9 @@ public class Main { foUserAgent = options.getFOUserAgent(); Fop fop = null; - if (options.getOutputMode() != CommandLineOptions.RENDER_NONE) { - fop = new Fop(options.getRenderer(), foUserAgent); + String outputFormat = options.getOutputFormat(); + if (!MimeConstants.MIME_XSL_FO.equals(outputFormat)) { + fop = new Fop(outputFormat, foUserAgent); } try { @@ -175,7 +177,7 @@ public class Main { // System.exit(0) called to close AWT/SVG-created threads, if any. // AWTRenderer closes with window shutdown, so exit() should not // be called here - if (options.getOutputMode() != CommandLineOptions.RENDER_AWT) { + if (!MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputFormat)) { System.exit(0); } } catch (Exception e) { diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index 595dc0566..3cb5d9cb2 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -30,7 +30,6 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FormattingResults; import org.apache.fop.area.AreaTreeHandler; -import org.apache.fop.render.RendererFactory; import org.apache.fop.util.Service; import org.apache.fop.fo.ElementMapping.Maker; import org.apache.fop.fo.pagination.Root; @@ -94,19 +93,20 @@ public class FOTreeBuilder extends DefaultHandler { /** * FOTreeBuilder constructor - * @param renderType output type as defined in Constants class + * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). * @param foUserAgent in effect for this process * @param stream OutputStream to direct results * @throws FOPException if the FOTreeBuilder cannot be properly created */ - public FOTreeBuilder(int renderType, FOUserAgent foUserAgent, + public FOTreeBuilder(String outputFormat, FOUserAgent foUserAgent, OutputStream stream) throws FOPException { this.userAgent = foUserAgent; //This creates either an AreaTreeHandler and ultimately a Renderer, or //one of the RTF-, MIF- etc. Handlers. - foEventHandler = RendererFactory.createFOEventHandler(foUserAgent, renderType, stream); + foEventHandler = foUserAgent.getRendererFactory().createFOEventHandler( + foUserAgent, outputFormat, stream); foEventHandler.setPropertyListMaker(new PropertyListMaker() { public PropertyList make(FObj fobj, PropertyList parentPropertyList) { return new StaticPropertyList(fobj, parentPropertyList); @@ -296,14 +296,22 @@ public class FOTreeBuilder extends DefaultHandler { public void endElement(String uri, String localName, String rawName) throws FOPException { if (currentFObj == null) { - throw new FOPException("No current FO is available. The input document may not be " - + "a valid XSL-FO document."); + throw new IllegalStateException( + "endElement() called for " + rawName + " where there is no current element."); + } else if (!currentFObj.getLocalName().equals(localName) + || !currentFObj.getNamespaceURI().equals(uri)) { + log.warn("Mismatch: " + currentFObj.getLocalName() + + " (" + currentFObj.getNamespaceURI() + + ") vs. " + localName + " (" + uri + ")"); } currentFObj.endOfNode(); if (currentPropertyList.getFObj() == currentFObj) { currentPropertyList = currentPropertyList.getParentPropertyList(); } + if (currentFObj.getParent() == null) { + log.debug("endElement for top-level " + currentFObj.getName()); + } currentFObj = currentFObj.getParent(); } 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;
+ }
+
+}
|