From: arved Date: Sun, 20 May 2001 23:56:49 +0000 (+0000) Subject: AHS: support for XMLRenderer X-Git-Tag: PRE_CODEFORMATTING~121 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f02432115d660c65671a2062d5202e8352a86d0c;p=xmlgraphics-fop.git AHS: support for XMLRenderer git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194258 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/apps/CommandLineOptions.java b/src/org/apache/fop/apps/CommandLineOptions.java index a05c0ffdc..435810957 100644 --- a/src/org/apache/fop/apps/CommandLineOptions.java +++ b/src/org/apache/fop/apps/CommandLineOptions.java @@ -45,12 +45,17 @@ public class CommandLineOptions { /* System buffers */ private static final int BUFFER_FILE = 7; + /* System buffers */ + private static final int AREA_OUTPUT = 8; + /* use debug mode*/ Boolean errorDump = new Boolean(false); /* show configuration information */ Boolean dumpConfiguration = new Boolean(false); /*suppress any progress information */ Boolean quiet = new Boolean(false); + /* for area tree XML output, only down to block area level */ + Boolean suppressLowLevelAreas = new Boolean(false); /* name of user configuration file*/ File userConfigFile = null; /* name of input fo file */ @@ -72,11 +77,13 @@ public class CommandLineOptions { /* language for user information */ String language = null; - + private java.util.Hashtable rendererOptions; + public CommandLineOptions (String [] args) throws FOPException, FileNotFoundException { boolean optionsParsed = true; + rendererOptions = new java.util.Hashtable(); try { optionsParsed = parseOptions(args); if (optionsParsed) { @@ -129,7 +136,9 @@ public class CommandLineOptions { language = args[i + 1]; i++; } - } else if (args[i].equals("-fo")) { + } else if (args[i].equals("-s")) { + suppressLowLevelAreas = new Boolean(true); + } else if (args[i].equals("-fo")) { inputmode = FO_INPUT; if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { @@ -228,6 +237,15 @@ public class CommandLineOptions { bufferFile = new File (args[i + 1]); i++; } + } else if (args[i].equals("-at")) { + setOutputMode(AREA_OUTPUT); + if ((i + 1 == args.length) || + (args[i + 1].charAt(0) == '-')) { + throw new FOPException("you must specify the area-tree output file"); + } else { + outfile = new File (args[i + 1]); + i++; + } } else { printUsage(); return false; @@ -322,6 +340,9 @@ public class CommandLineOptions { return Driver.RENDER_PCL; case TXT_OUTPUT: return Driver.RENDER_TXT; + case AREA_OUTPUT: + rendererOptions.put("fineDetail", isCoarseAreaXml()); + return Driver.RENDER_XML; default: throw new FOPException("Invalid Renderer setting!"); } @@ -341,7 +362,10 @@ public class CommandLineOptions { } } - + public java.util.Hashtable getRendererOptions() { + return rendererOptions; + } + public Starter getStarter() throws FOPException { @@ -377,6 +401,8 @@ public class CommandLineOptions { throw new FOPException("PrintStarter could not be loaded.",e); } + case AREA_OUTPUT: + return new CommandLineStarter(this); default: return new CommandLineStarter(this); } @@ -430,7 +456,10 @@ public class CommandLineOptions { return errorDump; } - + public Boolean isCoarseAreaXml() { + return suppressLowLevelAreas; + } + /** * return either the fofile or the xmlfile */ @@ -451,12 +480,13 @@ public class CommandLineOptions { */ public static void printUsage() { MessageHandler.errorln( - "\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-pcl|-txt|-print] \n" + + "\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-pcl|-txt|-at|-print] \n" + " [OPTIONS] \n" + " -d debug mode \n" + " -x dump configuration settings \n" + " -q quiet mode \n" + " -c cfg.xml use additional configuration file cfg.xml\n" + - " -l lang the language to use for user information \n\n" + + " -l lang the language to use for user information \n" + + " -s for area tree XML, down to block areas only\n\n" + " [INPUT] \n" + " infile xsl:fo input file (the same as the next) \n" + " -fo infile xsl:fo input file \n" + @@ -469,6 +499,7 @@ public class CommandLineOptions { " -mif outfile input will be rendered as mif file (outfile req'd)\n" + " -pcl outfile input will be rendered as pcl file (outfile req'd) \n" + " -txt outfile input will be rendered as text 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" + " [Examples]\n" + " Fop foo.fo foo.pdf \n" + diff --git a/src/org/apache/fop/apps/CommandLineStarter.java b/src/org/apache/fop/apps/CommandLineStarter.java index bf25dd07d..72f4804cf 100644 --- a/src/org/apache/fop/apps/CommandLineStarter.java +++ b/src/org/apache/fop/apps/CommandLineStarter.java @@ -55,7 +55,7 @@ public class CommandLineStarter extends Starter { try { driver.setRenderer(commandLineOptions.getRenderer()); - + driver.getRenderer().setOptions(commandLineOptions.getRendererOptions()); driver.buildFOTree(parser, inputHandler.getInputSource()); driver.format(); driver.setOutputStream(new FileOutputStream(commandLineOptions.getOutputFile())); diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java index 0880dc1d4..c9a48a242 100644 --- a/src/org/apache/fop/apps/Driver.java +++ b/src/org/apache/fop/apps/Driver.java @@ -269,6 +269,10 @@ public class Driver { _renderer = renderer; } + public Renderer getRenderer() { + return _renderer; + } + /** * @deprecated use renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(renderer_type) which will use the default producer string. * @see #setRenderer(int) diff --git a/src/org/apache/fop/render/Renderer.java b/src/org/apache/fop/render/Renderer.java index adc268a9a..fc1c354b4 100644 --- a/src/org/apache/fop/render/Renderer.java +++ b/src/org/apache/fop/render/Renderer.java @@ -72,6 +72,9 @@ public interface Renderer { /** set up the given FontInfo */ public void setupFontInfo(FontInfo fontInfo); + /** set up renderer options */ + public void setOptions(java.util.Hashtable options); + /** set the producer of the rendering */ public void setProducer(String producer); diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java index f17e4db4f..f4739e10f 100644 --- a/src/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -110,7 +110,14 @@ public class AWTRenderer implements Renderer, Printable, Pageable { */ private int currentAreaContainerXPosition = 0; - + /** options */ + protected Hashtable options; + + /** set up renderer options */ + public void setOptions(Hashtable options) { + this.options = options; + } + public AWTRenderer(Translator aRes) { res = aRes; } diff --git a/src/org/apache/fop/render/mif/MIFRenderer.java b/src/org/apache/fop/render/mif/MIFRenderer.java index 07fa3e12a..c871a9bcc 100644 --- a/src/org/apache/fop/render/mif/MIFRenderer.java +++ b/src/org/apache/fop/render/mif/MIFRenderer.java @@ -111,16 +111,21 @@ public class MIFRenderer implements Renderer { /* is a table currently open? */ private boolean inTable=false; - - + /** options */ + protected Hashtable options; + /** * create the MIF renderer */ public MIFRenderer() { - this.mifDoc = new MIFDocument(); + this.mifDoc = new MIFDocument(); } - + /** set up renderer options */ + public void setOptions(Hashtable options) { + this.options = options; + } + /** * render the areas into MIF * diff --git a/src/org/apache/fop/render/pcl/PCLRenderer.java b/src/org/apache/fop/render/pcl/PCLRenderer.java index 59edf404c..88d45c05f 100755 --- a/src/org/apache/fop/render/pcl/PCLRenderer.java +++ b/src/org/apache/fop/render/pcl/PCLRenderer.java @@ -56,6 +56,8 @@ public class PCLRenderer extends PrintRenderer private int xoffset = -180; // X Offset to allow for PCL implicit 1/4" left margin. + private java.util.Hashtable options; + /** * Create the PCL renderer */ @@ -63,6 +65,11 @@ public class PCLRenderer extends PrintRenderer { } + /** set up renderer options */ + public void setOptions(java.util.Hashtable options) { + this.options = options; + } + /** * set the PCL document's producer * diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 5087bbc84..cf808b8e4 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -89,6 +89,9 @@ public class PDFRenderer extends PrintRenderer { /** reusable word area string buffer to reduce memory usage */ private StringBuffer _wordAreaPDF = new StringBuffer(); + /** options */ + protected Hashtable options; + /** * create the PDF renderer */ @@ -96,6 +99,11 @@ public class PDFRenderer extends PrintRenderer { this.pdfDoc = new PDFDocument(); } + /** set up renderer options */ + public void setOptions(Hashtable options) { + this.options = options; + } + /** * set the PDF document's producer * diff --git a/src/org/apache/fop/render/txt/TXTRenderer.java b/src/org/apache/fop/render/txt/TXTRenderer.java index 61d2b4a4c..f971800d0 100755 --- a/src/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/org/apache/fop/render/txt/TXTRenderer.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Enumeration; import java.util.Vector; +import java.util.Hashtable; /** * Renderer that renders areas to plain text @@ -64,13 +65,17 @@ public class TXTRenderer extends PrintRenderer public String pageEnding = "\f"; // Every page except the last one will end with this string. public boolean suppressGraphics = false; // If true then graphics/decorations will not be rendered - text only. - /** - * create the TXT renderer - */ - public TXTRenderer() - { - } + /** options */ + protected Hashtable options; + + public TXTRenderer() { + } + /** set up renderer options */ + public void setOptions(Hashtable options) { + this.options = options; + } + /** * set the TXT document's producer * diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java index d0044ebf1..9a06c2d2e 100644 --- a/src/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/org/apache/fop/render/xml/XMLRenderer.java @@ -65,6 +65,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.OutputStream; import java.util.Enumeration; +import java.util.Hashtable; /** * Renderer that renders areas to XML for debugging purposes. @@ -80,6 +81,17 @@ public class XMLRenderer implements Renderer { /** the writer used to output the XML */ protected PrintWriter writer; + /** options */ + protected Hashtable options; + + public XMLRenderer() { + } + + /** set up renderer options */ + public void setOptions(Hashtable options) { + this.options = options; + } + /** * set the document's producer * @@ -244,7 +256,8 @@ public class XMLRenderer implements Renderer { * @param space the space to render */ public void renderDisplaySpace(DisplaySpace space) { - writeEmptyElementTag(""); } @@ -290,13 +303,17 @@ public class XMLRenderer implements Renderer { else sb = sb.append(ch); } - writeElement("" + sb.toString() - + ""); + + ""); + } else { + this.writer.write(sb.toString()); + } } /** @@ -305,8 +322,11 @@ public class XMLRenderer implements Renderer { * @param space the space to render */ public void renderInlineSpace(InlineSpace space) { - writeEmptyElementTag(""); + else + this.writer.write(" "); } /** @@ -315,15 +335,20 @@ public class XMLRenderer implements Renderer { * @param area the area to render */ public void renderLineArea(LineArea area) { - String fontWeight = area.getFontState().getFontWeight(); - writeStartTag(""); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - writeEndTag(""); + } + Enumeration e = area.getChildren().elements(); + while (e.hasMoreElements()) { + Box b = (Box)e.nextElement(); + b.render(this); + } + if (!isCoarseXml()) + writeEndTag(""); + else + this.writer.write("\n"); } /** @@ -334,7 +359,7 @@ public class XMLRenderer implements Renderer { public void renderPage(Page page) { BodyAreaContainer body; AreaContainer before, after; - writeStartTag(""); + writeStartTag(""); body = page.getBody(); before = page.getBefore(); after = page.getAfter(); @@ -354,6 +379,7 @@ public class XMLRenderer implements Renderer { * @param area the area to render */ public void renderLeaderArea(LeaderArea area) { + if (isCoarseXml()) return; String leaderPattern = ""; switch (area.getLeaderPattern()) { case LeaderPattern.SPACE: @@ -377,4 +403,8 @@ public class XMLRenderer implements Renderer { "\" red=\"" + area.getRed() + "\" green=\"" + area.getGreen() + "\" blue = \"" + area.getBlue() + "\"/>"); } + + private boolean isCoarseXml() { + return ((Boolean)options.get("fineDetail")).booleanValue(); + } }