Przeglądaj źródła

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
pull/30/head
Bertrand Delacretaz 21 lat temu
rodzic
commit
1da884d0a4

+ 1
- 0
build.xml Wyświetl plik

@@ -64,6 +64,7 @@ list of possible build targets.
<include name="lib/batik.jar"/>
<include name="lib/avalon-framework*.jar"/>
<include name="lib/jimi*"/>
<include name="lib/jfor*.jar"/>
</fileset>
<fileset dir="${basedir}" id="dist.src">

BIN
lib/jfor-0.7.1.jar Wyświetl plik


+ 43
- 0
lib/jfor.LICENSE.txt Wyświetl plik

@@ -0,0 +1,43 @@
* ====================================================================
* jfor Apache-Style Software License.
* Copyright (c) 2002 by the jfor project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed
* by the jfor project (http://www.jfor.org)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The name "jfor" must not be used to endorse
* or promote products derived from this software without prior written
* permission. For written permission, please contact info@jfor.org.
*
* 5. Products derived from this software may not be called "jfor",
* nor may "jfor" appear in their name, without prior written
* permission of info@jfor.org.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE JFOR PROJECT OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================

+ 15
- 5
src/org/apache/fop/apps/Driver.java Wyświetl plik

@@ -144,6 +144,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
*/
@@ -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());

+ 120
- 0
src/org/apache/fop/rtf/renderer/RTFHandler.java Wyświetl plik

@@ -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);
}
}
}

Ładowanie…
Anuluj
Zapisz