From: Peter Herweg Date: Sat, 10 Jan 2004 19:43:58 +0000 (+0000) Subject: added support for fo:footnote X-Git-Tag: Root_Temp_KnuthStylePageBreaking~919 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc0944183c69d317c84d0e4f68541e3c0578be7b;p=xmlgraphics-fop.git added support for fo:footnote git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197155 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/FOInputHandler.java b/src/java/org/apache/fop/fo/FOInputHandler.java index 49c99bf06..ea01d73fb 100644 --- a/src/java/org/apache/fop/fo/FOInputHandler.java +++ b/src/java/org/apache/fop/fo/FOInputHandler.java @@ -58,6 +58,8 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.fo.flow.BasicLink; import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.fo.flow.FootnoteBody; import org.apache.fop.fo.flow.Inline; import org.apache.fop.fo.flow.InstreamForeignObject; import org.apache.fop.fo.flow.Leader; @@ -365,9 +367,28 @@ public abstract class FOInputHandler extends AbstractLogEnabled { public abstract void foreignObject(InstreamForeignObject ifo); /** - * Process a footnote. + * Process the start of a footnote. + * @param footnote Footnote that is starting */ - public abstract void footnote(); + public abstract void startFootnote(Footnote footnote); + + /** + * Process the ending of a footnote. + * @param footnote Footnote that is ending + */ + public abstract void endFootnote(Footnote footnote); + + /** + * Process the start of a footnote body. + * @param body FootnoteBody that is starting + */ + public abstract void startFootnoteBody(FootnoteBody body); + + /** + * Process the ending of a footnote body. + * @param body FootnoteBody that is ending + */ + public abstract void endFootnoteBody(FootnoteBody body); /** * Process a Leader. diff --git a/src/java/org/apache/fop/fo/FOTreeHandler.java b/src/java/org/apache/fop/fo/FOTreeHandler.java index 25ddc66a1..ab8fd5add 100644 --- a/src/java/org/apache/fop/fo/FOTreeHandler.java +++ b/src/java/org/apache/fop/fo/FOTreeHandler.java @@ -62,6 +62,8 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.fo.flow.BasicLink; import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.fo.flow.FootnoteBody; import org.apache.fop.fo.flow.InstreamForeignObject; import org.apache.fop.fo.flow.Inline; import org.apache.fop.fo.flow.Leader; @@ -446,11 +448,29 @@ public class FOTreeHandler extends FOInputHandler { } /** - * @see org.apache.fop.fo.FOInputHandler#footnote() + * @see org.apache.fop.fo.FOInputHandler#startFootnote() */ - public void footnote() { + public void startFootnote(Footnote footnote) { } - + + /** + * @see org.apache.fop.fo.FOInputHandler#endFootnote() + */ + public void endFootnote(Footnote footnote) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startFootnoteBody() + */ + public void startFootnoteBody(FootnoteBody body) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endFootnoteBody() + */ + public void endFootnoteBody(FootnoteBody body) { + } + /** * @see org.apache.fop.fo.FOInputHandler#leader(Leader) */ diff --git a/src/java/org/apache/fop/fo/flow/Footnote.java b/src/java/org/apache/fop/fo/flow/Footnote.java index 8c5dd6932..ce9e0d06d 100644 --- a/src/java/org/apache/fop/fo/flow/Footnote.java +++ b/src/java/org/apache/fop/fo/flow/Footnote.java @@ -50,6 +50,11 @@ */ package org.apache.fop.fo.flow; +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FOTreeVisitor; import org.apache.fop.fo.FObj; @@ -95,6 +100,20 @@ public class Footnote extends FObj { public void acceptVisitor(FOTreeVisitor fotv) { fotv.serveFootnote(this); } + + /** + * @see org.apache.fop.fo.FObj#handleAttrs + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + getFOTreeControl().getFOInputHandler().startFootnote(this); + } + protected void end() { + super.end(); + + getFOTreeControl().getFOInputHandler().endFootnote(this); + } } diff --git a/src/java/org/apache/fop/fo/flow/FootnoteBody.java b/src/java/org/apache/fop/fo/flow/FootnoteBody.java index dec8cde43..05596b1c4 100644 --- a/src/java/org/apache/fop/fo/flow/FootnoteBody.java +++ b/src/java/org/apache/fop/fo/flow/FootnoteBody.java @@ -50,7 +50,11 @@ */ package org.apache.fop.fo.flow; +// XML +import org.xml.sax.Attributes; + // FOP +import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.FOTreeVisitor; @@ -79,4 +83,18 @@ public class FootnoteBody extends FObj { fotv.serveFootnoteBody(this); } + /** + * @see org.apache.fop.fo.FObj#handleAttrs + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + getFOTreeControl().getFOInputHandler().startFootnoteBody(this); + } + + protected void end() { + super.end(); + + getFOTreeControl().getFOInputHandler().endFootnoteBody(this); + } } diff --git a/src/java/org/apache/fop/render/mif/MIFHandler.java b/src/java/org/apache/fop/render/mif/MIFHandler.java index 63eab22a0..9b787c8c9 100644 --- a/src/java/org/apache/fop/render/mif/MIFHandler.java +++ b/src/java/org/apache/fop/render/mif/MIFHandler.java @@ -60,6 +60,8 @@ import org.apache.fop.fo.FOInputHandler; import org.apache.fop.fo.flow.BasicLink; import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.fo.flow.FootnoteBody; import org.apache.fop.fo.flow.InstreamForeignObject; import org.apache.fop.fo.flow.Inline; import org.apache.fop.fo.flow.Leader; @@ -429,11 +431,29 @@ public class MIFHandler extends FOInputHandler { } /** - * @see org.apache.fop.fo.FOInputHandler#footnote() + * @see org.apache.fop.fo.FOInputHandler#startFootnote() */ - public void footnote() { + public void startFootnote(Footnote footnote) { } - + + /** + * @see org.apache.fop.fo.FOInputHandler#endFootnote() + */ + public void endFootnote(Footnote footnote) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startFootnoteBody() + */ + public void startFootnoteBody(FootnoteBody body) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endFootnoteBody() + */ + public void endFootnoteBody(FootnoteBody body) { + } + /** * @see org.apache.fop.fo.FOInputHandler#leader(Leader) */ diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index f3122b332..7a1ffe0a6 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -64,6 +64,8 @@ import org.apache.fop.datatypes.FixedLength; import org.apache.fop.fo.flow.BasicLink; import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.fo.flow.FootnoteBody; import org.apache.fop.fo.flow.Inline; import org.apache.fop.fo.flow.InstreamForeignObject; import org.apache.fop.fo.flow.Leader; @@ -96,6 +98,7 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfElement; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfExternalGraphic; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFile; +import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFootnote; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfHyperLink; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfList; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem; @@ -852,9 +855,80 @@ public class RTFHandler extends FOInputHandler { } /** - * @see org.apache.fop.fo.FOInputHandler#footnote() + * @see org.apache.fop.fo.FOInputHandler#startFootnote() */ - public void footnote() { + public void startFootnote(Footnote footnote) { + try { + RtfAttributes rtfAttr + = TextAttributesConverter.convertAttributes(footnote.propertyList, null); + + IRtfTextrunContainer container + = (IRtfTextrunContainer)builderContext.getContainer( + IRtfTextrunContainer.class, + true, this); + + RtfTextrun textrun = container.getTextrun(); + RtfFootnote rtfFootnote = textrun.addFootnote(); + + builderContext.pushContainer(rtfFootnote); + + } catch (IOException ioe) { + // TODO could we throw Exception in all FOInputHandler events? + log.error("startFootnote: " + ioe.getMessage()); + throw new Error("IOException: " + ioe); + } catch (Exception e) { + log.error("startFootnote: " + e.getMessage()); + throw new Error("Exception: " + e); + } + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endFootnote() + */ + public void endFootnote(Footnote footnote) { + builderContext.popContainer(); + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startFootnoteBody() + */ + public void startFootnoteBody(FootnoteBody body) { + try { + RtfFootnote rtfFootnote + = (RtfFootnote)builderContext.getContainer( + RtfFootnote.class, + true, this); + + rtfFootnote.startBody(); + } catch (IOException ioe) { + // TODO could we throw Exception in all FOInputHandler events? + log.error("startFootnoteBody: " + ioe.getMessage()); + throw new Error("IOException: " + ioe); + } catch (Exception e) { + log.error("startFootnoteBody: " + e.getMessage()); + throw new Error("Exception: " + e); + } + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endFootnoteBody() + */ + public void endFootnoteBody(FootnoteBody body) { + try { + RtfFootnote rtfFootnote + = (RtfFootnote)builderContext.getContainer( + RtfFootnote.class, + true, this); + + rtfFootnote.endBody(); + } catch (IOException ioe) { + // TODO could we throw Exception in all FOInputHandler events? + log.error("endFootnoteBody: " + ioe.getMessage()); + throw new Error("IOException: " + ioe); + } catch (Exception e) { + log.error("endFootnoteBody: " + e.getMessage()); + throw new Error("Exception: " + e); + } } /** diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFootnote.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFootnote.java new file mode 100644 index 000000000..3594655c1 --- /dev/null +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFootnote.java @@ -0,0 +1,106 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, 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 Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * 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 + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, 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. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ + +package org.apache.fop.render.rtf.rtflib.rtfdoc; + +//Java +import java.io.Writer; +import java.io.IOException; + +//FOP +import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun; + +/** Model of an RTF footnote + * @author Peter Herweg, pherweg@web.de + */ +public class RtfFootnote extends RtfContainer + implements IRtfTextrunContainer { + RtfTextrun textrunInline = null; + RtfTextrun textrunBody = null; + boolean bBody = false; + + /** Create an RTF list item as a child of given container with default attributes */ + RtfFootnote(RtfContainer parent, Writer w) throws IOException { + super(parent, w); + textrunInline = new RtfTextrun(this, writer, null); + textrunBody = new RtfTextrun(this, writer, null); + } + + public RtfTextrun getTextrun() throws IOException { + if (bBody) { + return textrunBody; + } else { + return textrunInline; + } + } + + /** + * write RTF code of all our children + * @throws IOException for I/O problems + */ + protected void writeRtfContent() throws IOException { + textrunInline.writeRtfContent(); + + writeGroupMark(true); + writeControlWord("footnote"); + writeControlWord("ftnalt"); + textrunBody.writeRtfContent(); + writeGroupMark(false); + } + + public void startBody() { + bBody = true; + } + + public void endBody() { + bBody = false; + } +} diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java index 378b98db2..79f71dcb0 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java @@ -164,6 +164,10 @@ public class RtfTextrun extends RtfContainer { RtfString r = new RtfString(this, writer, s); } + public RtfFootnote addFootnote() throws IOException { + return new RtfFootnote(this, writer); + } + public void addParagraphBreak() throws IOException { RtfParagraphBreak r = new RtfParagraphBreak(this, writer); }