From: Glen Mazza Date: Sat, 26 Jun 2004 19:37:13 +0000 (+0000) Subject: 1. Output constant types (RENDER_PDF, RENDER_PS, etc.) made common between X-Git-Tag: Root_Temp_KnuthStylePageBreaking~694 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b0449877f620ca620d7061e17fff267b27af87e8;p=xmlgraphics-fop.git 1. Output constant types (RENDER_PDF, RENDER_PS, etc.) made common between CommandLineOptions and Driver, and factored into fo.Constants interface. 2. New Driver(AWTRenderer renderer) constructor added in apps.Driver for the AWTRenderer (which does reloading, unique among the output types.) Note reloading currently doesn't work--AWTRenderer not yet functional. 3. Driver.hasData() method removed from API--a search on when it was implemented dates it to 2001, when reset() was coded. Unsure of its need, and so removed until we have user requests for it. 4. Renderers abstracted away from API in favor of just calling .setRenderer(int Rendertype), and configuring user-configurable options in FOUserAgent. 5. Driver.setRenderer(String ) also dropped. If external user need for it, can be re-implemented fairly easily via a "renderer override" string in FOUserAgent, for which FOTreeHandler can read and use instead. 6. Validity checking added to fo:flow, and convenience functions defining the "%block;" parameter entity and neutral containers as defined in 6.2 of spec [1] added to FObj. [1] http://www.w3.org/TR/2001/REC-xsl-20011015/slice6.html#section-N9447-Formatting-Object-Content git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197745 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/apps/CommandLineOptions.java b/src/java/org/apache/fop/apps/CommandLineOptions.java index 2497131cb..0689702b3 100644 --- a/src/java/org/apache/fop/apps/CommandLineOptions.java +++ b/src/java/org/apache/fop/apps/CommandLineOptions.java @@ -23,6 +23,8 @@ import java.io.FileNotFoundException; import java.util.Locale; import java.util.Vector; +import org.apache.fop.fo.Constants; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.impl.SimpleLog; @@ -30,34 +32,7 @@ import org.apache.commons.logging.impl.SimpleLog; /** * Options parses the commandline arguments */ -public class CommandLineOptions { - - /** input / output not set */ - public static final int NOT_SET = 0; - /** input: fo file */ - public static final int FO_INPUT = 1; - /** input: xml+xsl file */ - public static final int XSLT_INPUT = 2; - /** output: pdf file */ - public static final int PDF_OUTPUT = 1; - /** output: screen using swing */ - public static final int AWT_OUTPUT = 2; - /** output: mif file */ - public static final int MIF_OUTPUT = 3; - /** output: sent swing rendered file to printer */ - public static final int PRINT_OUTPUT = 4; - /** output: pcl file */ - public static final int PCL_OUTPUT = 5; - /** output: postscript file */ - public static final int PS_OUTPUT = 6; - /** output: text file */ - public static final int TXT_OUTPUT = 7; - /** output: svg file */ - public static final int SVG_OUTPUT = 8; - /** output: XML area tree */ - public static final int AREA_OUTPUT = 9; - /** output: RTF file */ - public static final int RTF_OUTPUT = 10; +public class CommandLineOptions implements Constants { /* show configuration information */ private Boolean showConfiguration = Boolean.FALSE; @@ -257,12 +232,12 @@ public class CommandLineOptions { } private int parseAWTOutputOption(String[] args, int i) throws FOPException { - setOutputMode(AWT_OUTPUT); + setOutputMode(RENDER_AWT); return 0; } private int parsePDFOutputOption(String[] args, int i) throws FOPException { - setOutputMode(PDF_OUTPUT); + setOutputMode(RENDER_PDF); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the pdf output file"); @@ -273,7 +248,7 @@ public class CommandLineOptions { } private int parseMIFOutputOption(String[] args, int i) throws FOPException { - setOutputMode(MIF_OUTPUT); + setOutputMode(RENDER_MIF); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the mif output file"); @@ -284,7 +259,7 @@ public class CommandLineOptions { } private int parseRTFOutputOption(String[] args, int i) throws FOPException { - setOutputMode(RTF_OUTPUT); + setOutputMode(RENDER_RTF); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the rtf output file"); @@ -295,12 +270,12 @@ public class CommandLineOptions { } private int parsePrintOutputOption(String[] args, int i) throws FOPException { - setOutputMode(PRINT_OUTPUT); + setOutputMode(RENDER_PRINT); return 0; } private int parsePCLOutputOption(String[] args, int i) throws FOPException { - setOutputMode(PCL_OUTPUT); + setOutputMode(RENDER_PCL); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the pdf output file"); @@ -311,7 +286,7 @@ public class CommandLineOptions { } private int parsePostscriptOutputOption(String[] args, int i) throws FOPException { - setOutputMode(PS_OUTPUT); + setOutputMode(RENDER_PS); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the PostScript output file"); @@ -322,7 +297,7 @@ public class CommandLineOptions { } private int parseTextOutputOption(String[] args, int i) throws FOPException { - setOutputMode(TXT_OUTPUT); + setOutputMode(RENDER_TXT); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the text output file"); @@ -333,7 +308,7 @@ public class CommandLineOptions { } private int parseSVGOutputOption(String[] args, int i) throws FOPException { - setOutputMode(SVG_OUTPUT); + setOutputMode(RENDER_SVG); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the svg output file"); @@ -348,7 +323,7 @@ public class CommandLineOptions { inputmode = FO_INPUT; fofile = new File(args[i]); } else if (outputmode == NOT_SET) { - outputmode = PDF_OUTPUT; + outputmode = RENDER_PDF; outfile = new File(args[i]); } else { throw new FOPException("Don't know what to do with " @@ -358,7 +333,7 @@ public class CommandLineOptions { } private int parseAreaTreeOption(String[] args, int i) throws FOPException { - setOutputMode(AREA_OUTPUT); + setOutputMode(RENDER_XML); if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the area-tree output file"); @@ -388,7 +363,7 @@ public class CommandLineOptions { throw new FOPException("No output file specified"); } - if ((outputmode == AWT_OUTPUT || outputmode == PRINT_OUTPUT) && outfile != null) { + if ((outputmode == RENDER_AWT || outputmode == RENDER_PRINT) && outfile != null) { throw new FOPException("Output file may not be specified " + "for AWT or PRINT output"); } @@ -446,26 +421,26 @@ public class CommandLineOptions { switch (outputmode) { case NOT_SET: throw new FOPException("Renderer has not been set!"); - case PDF_OUTPUT: + case RENDER_PDF: return Driver.RENDER_PDF; - case AWT_OUTPUT: + case RENDER_AWT: return Driver.RENDER_AWT; - case MIF_OUTPUT: + case RENDER_MIF: return Driver.RENDER_MIF; - case PRINT_OUTPUT: + case RENDER_PRINT: return Driver.RENDER_PRINT; - case PCL_OUTPUT: + case RENDER_PCL: return Driver.RENDER_PCL; - case PS_OUTPUT: + case RENDER_PS: return Driver.RENDER_PS; - case TXT_OUTPUT: + case RENDER_TXT: return Driver.RENDER_TXT; - case SVG_OUTPUT: + case RENDER_SVG: return Driver.RENDER_SVG; - case AREA_OUTPUT: + case RENDER_XML: foUserAgent.getRendererOptions().put("fineDetail", isCoarseAreaXml()); return Driver.RENDER_XML; - case RTF_OUTPUT: + case RENDER_RTF: return Driver.RENDER_RTF; default: throw new FOPException("Invalid Renderer setting!"); @@ -505,7 +480,7 @@ public class CommandLineOptions { } /** - * Returns the output mode (output format, ex. NOT_SET or PDF_OUTPUT) + * Returns the output mode (output format, ex. NOT_SET or RENDER_PDF) * @return the output mode */ public int getOutputMode() { @@ -653,45 +628,45 @@ public class CommandLineOptions { case NOT_SET: log.info("not set"); break; - case PDF_OUTPUT: + case RENDER_PDF: log.info("pdf"); log.info("output file: " + outfile.toString()); break; - case AWT_OUTPUT: + case RENDER_AWT: log.info("awt on screen"); if (outfile != null) { log.error("awt mode, but outfile is set:"); log.info("out file: " + outfile.toString()); } break; - case MIF_OUTPUT: + case RENDER_MIF: log.info("mif"); log.info("output file: " + outfile.toString()); break; - case RTF_OUTPUT: + case RENDER_RTF: log.info("rtf"); log.info("output file: " + outfile.toString()); break; - case PRINT_OUTPUT: + case RENDER_PRINT: log.info("print directly"); if (outfile != null) { log.error("print mode, but outfile is set:"); log.error("out file: " + outfile.toString()); } break; - case PCL_OUTPUT: + case RENDER_PCL: log.info("pcl"); log.info("output file: " + outfile.toString()); break; - case PS_OUTPUT: + case RENDER_PS: log.info("PostScript"); log.info("output file: " + outfile.toString()); break; - case TXT_OUTPUT: + case RENDER_TXT: log.info("txt"); log.info("output file: " + outfile.toString()); break; - case SVG_OUTPUT: + case RENDER_SVG: log.info("svg"); log.info("output file: " + outfile.toString()); break; diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index 2a96d8039..e1287740e 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -30,6 +30,7 @@ import org.xml.sax.XMLReader; import org.w3c.dom.Document; // FOP +import org.apache.fop.fo.Constants; import org.apache.fop.fo.ElementMapping; import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.fo.FOInputHandler; @@ -86,62 +87,7 @@ import org.apache.fop.tools.DocumentReader; * driver.render(parser, fileInputSource(args[0])); * */ -public class Driver { - - /** - * private constant to indicate renderer was not defined. - */ - private static final int NOT_SET = 0; - - /** - * Render to PDF. OutputStream must be set - */ - public static final int RENDER_PDF = 1; - - /** - * Render to a GUI window. No OutputStream neccessary - */ - public static final int RENDER_AWT = 2; - - /** - * Render to MIF. OutputStream must be set - */ - public static final int RENDER_MIF = 3; - - /** - * Render to XML. OutputStream must be set - */ - public static final int RENDER_XML = 4; - - /** - * Render to PRINT. No OutputStream neccessary - */ - public static final int RENDER_PRINT = 5; - - /** - * Render to PCL. OutputStream must be set - */ - public static final int RENDER_PCL = 6; - - /** - * Render to Postscript. OutputStream must be set - */ - public static final int RENDER_PS = 7; - - /** - * Render to Text. OutputStream must be set - */ - public static final int RENDER_TXT = 8; - - /** - * Render to SVG. OutputStream must be set - */ - public static final int RENDER_SVG = 9; - - /** - * Render to RTF. OutputStream must be set - */ - public static final int RENDER_RTF = 10; +public class Driver implements Constants { /** * the FO tree builder @@ -190,6 +136,15 @@ public class Driver { stream = null; } + /** + * Constructor for AWTRenderer, which reuses the + * same renderer instance for document reloading + */ + public Driver(AWTRenderer renderer) { + this(); + setRenderer(renderer); + } + /** * Convenience constructor for directly setting input and output. * @param source InputSource to take the XSL-FO input from @@ -222,8 +177,15 @@ public class Driver { */ public void setUserAgent(FOUserAgent agent) { userAgent = agent; + if (renderer != null) { + renderer.setUserAgent(userAgent); + } } + /** + * Get the FOUserAgent instance for this process + * @return the user agent + */ public FOUserAgent getUserAgent() { if (userAgent == null) { userAgent = new FOUserAgent(); @@ -245,14 +207,6 @@ public class Driver { } } - /** - * Indicates whether FOP has already received input data. - * @return true, if input data was received - */ - public boolean hasData() { - return (treeBuilder.hasData()); - } - /** * Set the OutputStream to use to output the result of the Renderer * (if applicable) @@ -287,7 +241,7 @@ public class Driver { } /** - * Shortcut to set the rendering type to use. Must be one of + * Method to set the rendering type to use. Must be one of *