diff options
author | Bertrand Delacretaz <bdelacretaz@apache.org> | 2002-11-01 06:44:15 +0000 |
---|---|---|
committer | Bertrand Delacretaz <bdelacretaz@apache.org> | 2002-11-01 06:44:15 +0000 |
commit | 6a962c8283f5e24dfdee46a245d34751c788c1a3 (patch) | |
tree | be6a76b3a64c7affd59af8d1d1a2a77759b23d42 /src/org/apache | |
parent | 6484f92ba1b2420dbbf0533c55ead08acd32e6eb (diff) | |
download | xmlgraphics-fop-6a962c8283f5e24dfdee46a245d34751c788c1a3.tar.gz xmlgraphics-fop-6a962c8283f5e24dfdee46a245d34751c788c1a3.zip |
first shot at RTFHandler using jfor RTF library
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195397 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache')
-rw-r--r-- | src/org/apache/fop/apps/Driver.java | 20 | ||||
-rw-r--r-- | src/org/apache/fop/rtf/renderer/RTFHandler.java | 120 |
2 files changed, 135 insertions, 5 deletions
diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java index d885c9ab2..010f63a7f 100644 --- a/src/org/apache/fop/apps/Driver.java +++ b/src/org/apache/fop/apps/Driver.java @@ -145,6 +145,11 @@ public class Driver implements LogEnabled { private FOTreeBuilder _treeBuilder; /** + * the renderer type code given by setRenderer + */ + private int _rendererType; + + /** * the renderer to use to output the area tree */ private Renderer _renderer; @@ -318,6 +323,7 @@ public class Driver implements LogEnabled { * @param renderer the type of renderer to use */ public void setRenderer(int renderer) throws IllegalArgumentException { + _rendererType = renderer; switch (renderer) { case RENDER_PDF: setRenderer("org.apache.fop.render.pdf.PDFRenderer"); @@ -336,7 +342,7 @@ public class Driver implements LogEnabled { setRenderer("org.apache.fop.render.txt.TXTRenderer()"); break; case RENDER_MIF: - //structHandler = new org.apache.fop.mif.MIFHandler(_stream); + //structHandler will be set later break; case RENDER_XML: setRenderer("org.apache.fop.render.xml.XMLRenderer"); @@ -345,7 +351,7 @@ public class Driver implements LogEnabled { setRenderer("org.apache.fop.render.svg.SVGRenderer"); break; case RENDER_RTF: - if(true) throw new IllegalArgumentException("-rtf option recognized but RTF output is not implemented yet"); + //structHandler will be set later break; default: throw new IllegalArgumentException("Unknown renderer type"); @@ -456,11 +462,15 @@ public class Driver implements LogEnabled { */ public ContentHandler getContentHandler() { // TODO - do this stuff in a better way - if (_renderer != null) { - structHandler = new LayoutHandler(_stream, _renderer, true); - } else { + if(_rendererType == RENDER_MIF) { structHandler = new org.apache.fop.mif.MIFHandler(_stream); + } else if(_rendererType == RENDER_RTF) { + structHandler = new org.apache.fop.rtf.renderer.RTFHandler(_stream); + } else { + if (_renderer == null) throw new Error("_renderer not set when using standard structHandler"); + structHandler = new LayoutHandler(_stream, _renderer, true); } + structHandler.enableLogging(getLogger()); _treeBuilder.setUserAgent(getUserAgent()); diff --git a/src/org/apache/fop/rtf/renderer/RTFHandler.java b/src/org/apache/fop/rtf/renderer/RTFHandler.java new file mode 100644 index 000000000..bfd04f09c --- /dev/null +++ b/src/org/apache/fop/rtf/renderer/RTFHandler.java @@ -0,0 +1,120 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + +package org.apache.fop.rtf.renderer; + +import org.apache.fop.apps.StructureHandler; +import org.apache.fop.layout.FontInfo; +import org.apache.fop.apps.FOPException; + +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.fo.pagination.LayoutMasterSet; +import org.apache.fop.fo.pagination.SimplePageMaster; +import org.apache.fop.fo.Title; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.Flow; + +import org.jfor.jfor.rtflib.rtfdoc.RtfFile; +import org.jfor.jfor.rtflib.rtfdoc.RtfSection; +import org.jfor.jfor.rtflib.rtfdoc.RtfParagraph; +import org.jfor.jfor.rtflib.rtfdoc.RtfDocumentArea; + +import org.xml.sax.SAXException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.IOException; + +/** + * RTF Handler: generates RTF output using the structure events from + * the FO Tree sent to this structure handler. + * + * @author bdelacretaz@apache.org + */ + + public class RTFHandler extends StructureHandler { + private FontInfo _fontInfo = new FontInfo(); + private RtfFile _rtfFile; + private RtfSection _sect; + private RtfDocumentArea _docArea; + private RtfParagraph _para; + private boolean _warned = false; + + private static final String ALPHA_WARNING = "WARNING: RTF renderer is veryveryalpha at this time, see class org.apache.fop.rtf.renderer.RTFHandler"; + + public RTFHandler(OutputStream os) throws IOException { + _rtfFile = new RtfFile(new OutputStreamWriter(os)); + // use pdf fonts for now, this is only for resolving names + org.apache.fop.render.pdf.FontSetup.setup(_fontInfo, null); + System.err.println(ALPHA_WARNING); + } + + public FontInfo getFontInfo() { + return _fontInfo; + } + + public void startDocument() throws SAXException { + // FIXME sections should be created + try { + _docArea = _rtfFile.startDocumentArea(); + } catch(IOException ioe) { + // FIXME could we throw Exception in all StructureHandler events? + throw new SAXException("IOException: " + ioe); + } + } + + public void endDocument() throws SAXException { + try { + _rtfFile.flush(); + } catch(IOException ioe) { + // FIXME could we throw Exception in all StructureHandler events? + throw new SAXException("IOException: " + ioe); + } + } + + public void startPageSequence(PageSequence pageSeq, Title seqTitle, LayoutMasterSet lms) { + try { + _sect = _docArea.newSection(); + if(!_warned) { + _sect.newParagraph().newText(ALPHA_WARNING); + _warned = true; + } + } catch(IOException ioe) { + // FIXME could we throw Exception in all StructureHandler events? + throw new Error("IOException: " + ioe); + } + } + + public void endPageSequence(PageSequence pageSeq) throws FOPException { + } + + public void startFlow(Flow fl) { + } + + public void endFlow(Flow fl) { + } + + public void startBlock(Block bl) { + try { + _para = _sect.newParagraph(); + } catch(IOException ioe) { + // FIXME could we throw Exception in all StructureHandler events? + throw new Error("IOException: " + ioe); + } + } + + public void endBlock(Block bl) { + } + + public void characters(char data[], int start, int length) { + try { + _para.newText(new String(data,start,length)); + } catch(IOException ioe) { + // FIXME could we throw Exception in all StructureHandler events? + throw new Error("IOException: " + ioe); + } + } +} |