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;
/**
/** 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();
* 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;
}
/**
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;
// FOTreeBuilder object to maintain reference for access to results
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
* @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);
}
/**
* @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
*/
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;
}
--- /dev/null
+/*\r
+ * Copyright 2005 Jeremias Maerki\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.apache.fop.apps;\r
+\r
+/**\r
+ * Frequently used MIME types for various file formats used when working with Apache FOP.\r
+ */\r
+public interface MimeConstants {\r
+\r
+ /** Portable Document Format */\r
+ String MIME_PDF = "application/pdf";\r
+ \r
+ /** PostScript */\r
+ String MIME_POSTSCRIPT = "application/postscript";\r
+ /** Encapsulated PostScript (same MIME type as PostScript) */\r
+ String MIME_EPS = MIME_POSTSCRIPT;\r
+ \r
+ /** HP's PCL */\r
+ String MIME_PCL = "application/x-pcl";\r
+ /** HP's PCL (alternative MIME type) */\r
+ String MIME_PCL_ALT = "application/vnd.hp-PCL";\r
+ \r
+ /** Plain text */\r
+ String MIME_PLAIN_TEXT = "text/plain";\r
+ \r
+ /** Rich text format */\r
+ String MIME_RTF = "application/rtf";\r
+ /** Rich text format (alternative 1) */\r
+ String MIME_RTF_ALT1 = "text/richtext";\r
+ /** Rich text format (alternative 2) */\r
+ String MIME_RTF_ALT2 = "text/rtf";\r
+ \r
+ /** FrameMaker's MIF */\r
+ String MIME_MIF = "application/mif";\r
+ \r
+ /** Structured Vector Graphics */\r
+ String MIME_SVG = "image/svg+xml";\r
+ \r
+ /** PNG images */\r
+ String MIME_PNG = "image/png";\r
+ /** JPEG images */\r
+ String MIME_JPEG = "image/jpeg";\r
+ /** TIFF images */\r
+ String MIME_TIFF = "image/tiff";\r
+ \r
+ /** Apache FOP's AWT preview (non-standard MIME type) */\r
+ String MIME_FOP_AWT_PREVIEW = "application/X-fop-awt-preview";\r
+ /** Apache FOP's Direct Printing (non-standard MIME type) */\r
+ String MIME_FOP_PRINT = "application/X-fop-print";\r
+ /** Apache FOP's area tree XML */\r
+ String MIME_FOP_AREA_TREE = "application/X-fop-areatree";\r
+\r
+ /** Proposed but non-registered MIME type for XSL-FO */\r
+ String MIME_XSL_FO = "text/xsl";\r
+ \r
+}\r
/**
* 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();
/**
* 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);
}
/**
/**
* 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);
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;
/* input mode */
private int inputmode = NOT_SET;
/* output mode */
- private int outputmode = NOT_SET;
+ private String outputmode = null;
private FOUserAgent foUserAgent;
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);
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")) {
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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");
}
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");
}
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;
}
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");
}
}
+ 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 "
}
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");
}
}
- 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");
}
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");
}
}
} 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");
}
}
/**
- * @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;
}
/**
return foUserAgent;
}
- /**
- * 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
+ " -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"
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");
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.
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 {
// 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) {
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;
/**
* 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);
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();
}
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render;\r
+\r
+import java.io.OutputStream;\r
+\r
+import org.apache.fop.apps.FOPException;\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.fo.FOEventHandler;\r
+\r
+/**\r
+ * Base class for factory classes which instantiate FOEventHandlers and provide information\r
+ * about them.\r
+ */\r
+public abstract class AbstractFOEventHandlerMaker {\r
+ \r
+ /**\r
+ * Instantiates a new FOEventHandler.\r
+ * @param ua the user agent\r
+ * @param out OutputStream for the FOEventHandler to use\r
+ * @return the newly instantiated FOEventHandler\r
+ * @throws FOPException if a problem occurs while creating the event handler\r
+ */\r
+ public abstract FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out)\r
+ throws FOPException;\r
+\r
+ /**\r
+ * @return Indicates whether this renderer requires an OutputStream to work with.\r
+ */\r
+ public abstract boolean needsOutputStream();\r
+ \r
+ /**\r
+ * @return an array of MIME types the renderer supports.\r
+ */\r
+ public abstract String[] getSupportedMimeTypes();\r
+\r
+ /**\r
+ * Indicates whether a specific MIME type is supported by this renderer.\r
+ * @param mimeType the MIME type (ex. "application/rtf")\r
+ * @return true if the MIME type is supported\r
+ */\r
+ public boolean isMimeTypeSupported(String mimeType) {\r
+ String[] mimes = getSupportedMimeTypes();\r
+ for (int i = 0; i < mimes.length; i++) {\r
+ if (mimes[i].equals(mimeType)) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+ \r
+}\r
*/
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
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+\r
+/**\r
+ * Base class for factory classes which instantiate Renderers and provide information\r
+ * about them.\r
+ */\r
+public abstract class AbstractRendererMaker {\r
+ \r
+ /**\r
+ * Instantiates a new renderer.\r
+ * @param ua the user agent\r
+ * @return the newly instantiated renderer\r
+ */\r
+ public abstract Renderer makeRenderer(FOUserAgent ua);\r
+\r
+ /**\r
+ * @return Indicates whether this renderer requires an OutputStream to work with.\r
+ */\r
+ public abstract boolean needsOutputStream();\r
+ \r
+ /**\r
+ * @return an array of MIME types the renderer supports.\r
+ */\r
+ public abstract String[] getSupportedMimeTypes();\r
+\r
+ /**\r
+ * Indicates whether a specific MIME type is supported by this renderer.\r
+ * @param mimeType the MIME type (ex. "application/pdf")\r
+ * @return true if the MIME type is supported\r
+ */\r
+ public boolean isMimeTypeSupported(String mimeType) {\r
+ String[] mimes = getSupportedMimeTypes();\r
+ for (int i = 0; i < mimes.length; i++) {\r
+ if (mimes[i].equals(mimeType)) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+ \r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+ \r
+package org.apache.fop.render;\r
+\r
+import java.io.IOException;\r
+\r
+/**\r
+ * This interface represents an optional feature that can be provided by\r
+ * a renderer. It is exposed by calling the getGraphics2DAdapter() method\r
+ * on the renderer. Renderers that support this feature allow painting\r
+ * of arbitrary images through a Graphics2D instance.\r
+ */\r
+public interface Graphics2DAdapter {\r
+\r
+ /**\r
+ * Paints an arbitrary images on a given Graphics2D instance. The renderer\r
+ * providing this functionality must set up a Graphics2D instance so that\r
+ * the image with the given extents (in mpt) can be painted by the painter\r
+ * passed to this method. The Graphics2DImagePainter is then passed this\r
+ * Graphics2D instance so the image can be painted.\r
+ * @param painter the painter which will paint the actual image\r
+ * @param context the renderer context for the current renderer\r
+ * @param x X position of the image\r
+ * @param y Y position of the image\r
+ * @param width width of the image\r
+ * @param height height of the image\r
+ * @throws IOException In case of an I/O error while writing the output format\r
+ */\r
+ void paintImage(Graphics2DImagePainter painter, \r
+ RendererContext context,\r
+ int x, int y, int width, int height) throws IOException;\r
+ \r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+ \r
+package org.apache.fop.render;\r
+\r
+import java.awt.Dimension;\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+/**\r
+ * This interface is used by the Graphics2DAdapter. Components that can paint using\r
+ * a Graphics2D instance can implement this interface to paint themselves.\r
+ */\r
+public interface Graphics2DImagePainter {\r
+\r
+ /**\r
+ * Called to paint the image. Implementations should scale so the image is\r
+ * painted fully inside the given area indicated by then Rectangle2D object.\r
+ * @param g2d the Graphics2D instance to paint on\r
+ * @param area the target area for the image\r
+ */\r
+ void paint(Graphics2D g2d, Rectangle2D area);\r
+\r
+ /**\r
+ * @return the dimensions of the image to be painted in millipoints\r
+ */\r
+ Dimension getImageSize();\r
+ \r
+}
\ No newline at end of file
*
* @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
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
/**
* 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);
+ }
+
}
}
}
+
}
+ classname);\r
} catch (ClassCastException e) {\r
throw new IllegalArgumentException(classname\r
- + " is not an ElementMapping");\r
+ + " is not an " \r
+ + XMLHandler.class.getName());\r
}\r
}\r
\r
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;
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;
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.awt;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the AWT Preview Renderer.\r
+ */\r
+public class AWTRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_AWT_PREVIEW};\r
+ \r
+ \r
+ /** @see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new AWTRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return false;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
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;
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;
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.bitmap;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the PNG Renderer.\r
+ */\r
+public class PNGRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_PNG};\r
+ \r
+ \r
+ /** @see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new PNGRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
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;
/**
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;
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.bitmap;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the TIFF Renderer.\r
+ */\r
+public class TIFFRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_TIFF};\r
+ \r
+ \r
+ /** @see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new TIFFRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+ \r
+package org.apache.fop.render.java2d;\r
+\r
+import java.awt.Color;\r
+import java.awt.Dimension;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Rectangle2D;\r
+import java.io.IOException;\r
+\r
+import org.apache.fop.render.Graphics2DAdapter;\r
+import org.apache.fop.render.Graphics2DImagePainter;\r
+import org.apache.fop.render.RendererContext;\r
+\r
+/**\r
+ * Graphics2DAdapter implementation for Java2D.\r
+ */\r
+public class Java2DGraphics2DAdapter implements Graphics2DAdapter {\r
+\r
+ private Java2DGraphicsState state;\r
+\r
+ /**\r
+ * Main constructor\r
+ * @param renderer the Renderer instance to which this instance belongs\r
+ */\r
+ public Java2DGraphics2DAdapter(Java2DGraphicsState state) {\r
+ this.state = state;\r
+ }\r
+ \r
+ /** @see org.apache.fop.render.Graphics2DAdapter */\r
+ public void paintImage(Graphics2DImagePainter painter,\r
+ RendererContext context,\r
+ int x, int y, int width, int height) throws IOException {\r
+ \r
+ float fwidth = width / 1000f;\r
+ float fheight = height / 1000f;\r
+ float fx = x / 1000f;\r
+ float fy = y / 1000f;\r
+ \r
+ // get the 'width' and 'height' attributes of the SVG document\r
+ Dimension dim = painter.getImageSize();\r
+ float imw = (float)dim.getWidth() / 1000f;\r
+ float imh = (float)dim.getHeight() / 1000f;\r
+\r
+ float sx = fwidth / (float)imw;\r
+ float sy = fheight / (float)imh;\r
+\r
+ state.push();\r
+ state.getGraph().setColor(Color.black);\r
+ state.getGraph().setBackground(Color.black);\r
+ \r
+ //TODO Clip to the image area.\r
+\r
+ // transform so that the coordinates (0,0) is from the top left\r
+ // and positive is down and to the right. (0,0) is where the\r
+ // viewBox puts it.\r
+ state.getGraph().translate(fx, fy);\r
+ AffineTransform at = AffineTransform.getScaleInstance(sx, sy);\r
+ if (!at.isIdentity()) {\r
+ state.getGraph().transform(at);\r
+ }\r
+\r
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);\r
+ painter.paint(state.getGraph(), area);\r
+\r
+ state.pop();\r
+ \r
+ }\r
+\r
+}\r
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;
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;
*/
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;
*/
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
}
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)
*/
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]
*/
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);
*/
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 */
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
/** @see org.apache.fop.render.XMLHandler#getMimeType() */
public String getMimeType() {
- return Java2DRenderer.MIME_TYPE;
+ return this.mimeType;
}
/** @see org.apache.fop.render.XMLHandler#getNamespace() */
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.mif;\r
+\r
+import java.io.OutputStream;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.fo.FOEventHandler;\r
+import org.apache.fop.render.AbstractFOEventHandlerMaker;\r
+\r
+/**\r
+ * Maker class for MIF support.\r
+ */\r
+public class MIFFOEventHandlerMaker extends AbstractFOEventHandlerMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_MIF};\r
+ \r
+ \r
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker */\r
+ public FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out) {\r
+ return new MIFHandler(ua, out);\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
/*
- * 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.
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;
*/
public class MIFHandler extends FOEventHandler {
+ /** Logger */
+ private static Log log = LogFactory.getLog(MIFHandler.class);
+
/** the MIFFile instance */
protected MIFFile mifFile;
* @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);
package org.apache.fop.render.pcl;
// FOP
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.PrintRenderer;
// Java
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
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.
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.pcl;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the PCL Renderer.\r
+ */\r
+public class PCLRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {\r
+ MimeConstants.MIME_PCL,\r
+ MimeConstants.MIME_PCL_ALT};\r
+ \r
+ \r
+ /**@see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new PCLRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+ \r
+package org.apache.fop.render.pdf;\r
+\r
+import java.awt.Color;\r
+import java.awt.Dimension;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Rectangle2D;\r
+import java.io.IOException;\r
+\r
+import org.apache.batik.bridge.ViewBox;\r
+import org.apache.fop.render.Graphics2DAdapter;\r
+import org.apache.fop.render.Graphics2DImagePainter;\r
+import org.apache.fop.render.RendererContext;\r
+import org.apache.fop.svg.PDFGraphics2D;\r
+import org.w3c.dom.svg.SVGDocument;\r
+import org.w3c.dom.svg.SVGSVGElement;\r
+\r
+/**\r
+ * Graphics2DAdapter implementation for PDF.\r
+ */\r
+public class PDFGraphics2DAdapter implements Graphics2DAdapter {\r
+\r
+ private PDFRenderer renderer;\r
+\r
+ /**\r
+ * Main constructor\r
+ * @param renderer the Renderer instance to which this instance belongs\r
+ */\r
+ public PDFGraphics2DAdapter(PDFRenderer renderer) {\r
+ this.renderer = renderer;\r
+ }\r
+ \r
+ /** @see org.apache.fop.render.Graphics2DAdapter */\r
+ public void paintImage(Graphics2DImagePainter painter,\r
+ RendererContext context,\r
+ int x, int y, int width, int height) throws IOException {\r
+ \r
+ PDFSVGHandler.PDFInfo pdfInfo = PDFSVGHandler.getPDFInfo(context);\r
+ \r
+ float fwidth = width / 1000f;\r
+ float fheight = height / 1000f;\r
+ float fx = x / 1000f;\r
+ float fy = y / 1000f;\r
+ \r
+ // get the 'width' and 'height' attributes of the SVG document\r
+ Dimension dim = painter.getImageSize();\r
+ float imw = (float)dim.getWidth() / 1000f;\r
+ float imh = (float)dim.getHeight() / 1000f;\r
+\r
+ float sx = fwidth / (float)imw;\r
+ float sy = fheight / (float)imh;\r
+\r
+ renderer.saveGraphicsState();\r
+ renderer.setColor(Color.black, false, null);\r
+ renderer.setColor(Color.black, true, null);\r
+ \r
+ //TODO Clip to the image area.\r
+\r
+ // transform so that the coordinates (0,0) is from the top left\r
+ // and positive is down and to the right. (0,0) is where the\r
+ // viewBox puts it.\r
+ renderer.currentStream.add(sx + " 0 0 " + sy + " " + fx + " "\r
+ + fy + " cm\n");\r
+\r
+\r
+ final boolean textAsShapes = false;\r
+ PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes, \r
+ pdfInfo.fi, pdfInfo.pdfDoc,\r
+ pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(),\r
+ renderer.currentFontName,\r
+ renderer.currentFontSize);\r
+ graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());\r
+ \r
+ AffineTransform transform = new AffineTransform();\r
+ transform.translate(fx, fy);\r
+ pdfInfo.pdfState.setTransform(transform);\r
+ graphics.setPDFState(pdfInfo.pdfState);\r
+ graphics.setOutputStream(pdfInfo.outputStream);\r
+\r
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);\r
+ painter.paint(graphics, area);\r
+\r
+ pdfInfo.currentStream.add(graphics.getString());\r
+ renderer.restoreGraphicsState();\r
+ pdfInfo.pdfState.pop();\r
+ \r
+ }\r
+\r
+}\r
// 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;
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;
/**
* 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;
}
}
+ /** @see org.apache.fop.render.Renderer#getGraphics2DAdapter() */
+ public Graphics2DAdapter getGraphics2DAdapter() {
+ return new PDFGraphics2DAdapter(this);
+ }
+
/**
* writes out a comment.
* @param text text for the comment
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.pdf;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the PDF Renderer.\r
+ */\r
+public class PDFRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_PDF};\r
+ \r
+ \r
+ /**@see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new PDFRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.print;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the Print Renderer.\r
+ */\r
+public class PrintRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_PRINT};\r
+ \r
+ \r
+ /**@see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new PrintRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return false;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+ \r
+package org.apache.fop.render.ps;\r
+\r
+import java.awt.Dimension;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Rectangle2D;\r
+import java.io.IOException;\r
+\r
+import org.apache.fop.render.Graphics2DAdapter;\r
+import org.apache.fop.render.Graphics2DImagePainter;\r
+import org.apache.fop.render.RendererContext;\r
+\r
+/**\r
+ * Graphics2DAdapter implementation for PostScript.\r
+ */\r
+public class PSGraphics2DAdapter implements Graphics2DAdapter {\r
+\r
+ private PSRenderer renderer;\r
+\r
+ /**\r
+ * Main constructor\r
+ * @param renderer the Renderer instance to which this instance belongs\r
+ */\r
+ public PSGraphics2DAdapter(PSRenderer renderer) {\r
+ this.renderer = renderer;\r
+ }\r
+ \r
+ /** @see org.apache.fop.render.Graphics2DAdapter */\r
+ public void paintImage(Graphics2DImagePainter painter, \r
+ RendererContext context,\r
+ int x, int y, int width, int height) throws IOException {\r
+ PSGenerator gen = renderer.gen;\r
+ \r
+ float fwidth = width / 1000f;\r
+ float fheight = height / 1000f;\r
+ float fx = x / 1000f;\r
+ float fy = y / 1000f;\r
+ \r
+ // get the 'width' and 'height' attributes of the SVG document\r
+ Dimension dim = painter.getImageSize();\r
+ float imw = (float)dim.getWidth() / 1000f;\r
+ float imh = (float)dim.getHeight() / 1000f;\r
+\r
+ float sx = fwidth / (float)imw;\r
+ float sy = fheight / (float)imh;\r
+\r
+ gen.commentln("%FOPBeginGraphics2D");\r
+ gen.saveGraphicsState();\r
+ // Clip to the image area.\r
+ gen.writeln("newpath");\r
+ gen.defineRect(fx, fy, fwidth, fheight);\r
+ gen.writeln("clip");\r
+ \r
+ // transform so that the coordinates (0,0) is from the top left\r
+ // and positive is down and to the right. (0,0) is where the\r
+ // viewBox puts it.\r
+ gen.concatMatrix(sx, 0, 0, sy, fx, fy);\r
+\r
+ final boolean textAsShapes = false;\r
+ PSGraphics2D graphics = new PSGraphics2D(textAsShapes, gen);\r
+ graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());\r
+ AffineTransform transform = new AffineTransform();\r
+ // scale to viewbox\r
+ transform.translate(fx, fy);\r
+ gen.getCurrentState().concatMatrix(transform);\r
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);\r
+ painter.paint(graphics, area);\r
+\r
+ gen.restoreGraphicsState();\r
+ gen.commentln("%FOPEndGraphics2D");\r
+ }\r
+\r
+}\r
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;
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
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.ps;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the PostScript Renderer.\r
+ */\r
+public class PSRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_POSTSCRIPT};\r
+ \r
+ \r
+ /** @see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new PSRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
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
+ e.getMessage(), e);
}
- psInfo.psGenerator.restoreGraphicsState();
+ gen.restoreGraphicsState();
gen.commentln("%FOPEndSVG");
} catch (IOException ioe) {
log.error("SVG graphic could not be rendered: "
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.rtf;\r
+\r
+import java.io.OutputStream;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.fo.FOEventHandler;\r
+import org.apache.fop.render.AbstractFOEventHandlerMaker;\r
+\r
+/**\r
+ * Maker class for RTF support.\r
+ */\r
+public class RTFFOEventHandlerMaker extends AbstractFOEventHandlerMaker {\r
+\r
+ private static final String[] MIMES = new String[] {\r
+ MimeConstants.MIME_RTF,\r
+ MimeConstants.MIME_RTF_ALT1,\r
+ MimeConstants.MIME_RTF_ALT2};\r
+ \r
+ \r
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker */\r
+ public FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out) {\r
+ return new RTFHandler(ua, out);\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.svg;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the SVG Renderer.\r
+ */\r
+public class SVGRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_SVG};\r
+ \r
+ \r
+ /**@see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new SVGRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.txt;\r
+\r
+import java.io.OutputStream;\r
+\r
+import org.apache.fop.apps.FOPException;\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.fo.FOEventHandler;\r
+import org.apache.fop.render.AbstractFOEventHandlerMaker;\r
+\r
+/**\r
+ * Maker class for the special FOEventHandler for TXT support.\r
+ */\r
+public class TXTFOEventHandlerMaker extends AbstractFOEventHandlerMaker {\r
+\r
+ private static final String[] MIMES = new String[] {\r
+ MimeConstants.MIME_PLAIN_TEXT};\r
+ \r
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker */\r
+ public FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out) throws FOPException {\r
+ return new TXTHandler(ua, out);\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractFOEventHandlerMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
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;
*/
public TXTHandler(FOUserAgent userAgent, OutputStream stream)
throws FOPException {
- super(userAgent, Constants.RENDER_TXT, stream);
+ super(userAgent, MimeConstants.MIME_PLAIN_TEXT, stream);
}
/**
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.txt;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the Plain Text Renderer.\r
+ */\r
+public class TXTRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_PLAIN_TEXT};\r
+ \r
+ \r
+ /**@see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new TXTRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r
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;
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 = "";
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render.xml;\r
+\r
+import org.apache.fop.apps.FOUserAgent;\r
+import org.apache.fop.apps.MimeConstants;\r
+import org.apache.fop.render.AbstractRendererMaker;\r
+import org.apache.fop.render.Renderer;\r
+\r
+/**\r
+ * RendererMaker for the Area Tree XML Renderer.\r
+ */\r
+public class XMLRendererMaker extends AbstractRendererMaker {\r
+\r
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_AREA_TREE};\r
+ \r
+ \r
+ /**@see org.apache.fop.render.AbstractRendererMaker */\r
+ public Renderer makeRenderer(FOUserAgent ua) {\r
+ return new XMLRenderer();\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */\r
+ public boolean needsOutputStream() {\r
+ return true;\r
+ }\r
+\r
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */\r
+ public String[] getSupportedMimeTypes() {\r
+ return MIMES;\r
+ }\r
+\r
+}\r