From: Glen Mazza Date: Sat, 1 Nov 2003 23:08:51 +0000 (+0000) Subject: Moved mif package (including structural renderer MIFHandler.java) to X-Git-Tag: Root_Temp_KnuthStylePageBreaking~1038 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2a39d3fdaab42b43563cc622094269006c669272;p=xmlgraphics-fop.git Moved mif package (including structural renderer MIFHandler.java) to render.mif. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196978 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/build.xml b/build.xml index a2ff79622..e9b1e3230 100644 --- a/build.xml +++ b/build.xml @@ -768,10 +768,10 @@ list of possible build targets. + - diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index 3ed6d47fb..dd07514ba 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -59,7 +59,7 @@ import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.fo.FOInputHandler; import org.apache.fop.fo.FOTreeHandler; -import org.apache.fop.mif.MIFHandler; +import org.apache.fop.render.mif.MIFHandler; import org.apache.fop.render.Renderer; import org.apache.fop.render.awt.AWTRenderer; import org.apache.fop.rtf.renderer.RTFHandler; diff --git a/src/java/org/apache/fop/mif/MIFElement.java b/src/java/org/apache/fop/mif/MIFElement.java deleted file mode 100644 index 76b4173dd..000000000 --- a/src/java/org/apache/fop/mif/MIFElement.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * $Id: MIFElement.java,v 1.3 2003/03/07 08:09:26 jeremias Exp $ - * ============================================================================ - * 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.mif; - -// Java -import java.io.IOException; -import java.io.OutputStream; -import java.util.Iterator; -import java.util.List; - -/** - * The is the basis for MIF document elements. - * This enables the creation of the element and to write it - * to an output stream including sub-elements or a single value. - */ -public class MIFElement { - protected String name; - protected String valueStr = null; - protected List valueElements = null; - - protected boolean started = false; - protected boolean finish = false; - protected boolean finished = false; - - /** - */ - public MIFElement(String n) { - name = n; - } - - public void setValue(String str) { - valueStr = str; - } - - public void addElement(MIFElement el) { - if (valueElements == null) { - valueElements = new java.util.ArrayList(); - } - valueElements.add(el); - } - - /** - * Output this element to an output stream. - * This will output only so far as the fisrt unfinished child element. - * This method can be called again to continue from the previous point. - * An element that contains child elements will only be finished when - * the finish method is called. - */ - public boolean output(OutputStream os, int indent) throws IOException { - if (finished) { - return true; - } - if (valueElements == null && valueStr == null) { - return false; - } - - String indentStr = ""; - for (int c = 0; c < indent; c++) { - indentStr += " "; - } - if (!started) { - os.write((indentStr + "<" + name).getBytes()); - if (valueElements != null) { - os.write(("\n").getBytes()); - } - started = true; - } - if (valueElements != null) { - boolean done = true; - for (Iterator iter = valueElements.iterator(); iter.hasNext();) { - MIFElement el = (MIFElement)iter.next(); - boolean d = el.output(os, indent + 1); - if (d) { - iter.remove(); - } else { - done = false; - break; - } - } - if (!finish || !done) { - return false; - } - os.write((indentStr + "> # end of " + name + "\n").getBytes()); - } else { - os.write((" " + valueStr + ">\n").getBytes()); - } - finished = true; - return true; - } - - public void finish(boolean deep) { - finish = true; - if (deep && valueElements != null) { - for (Iterator iter = valueElements.iterator(); iter.hasNext();) { - MIFElement el = (MIFElement)iter.next(); - el.finish(deep); - } - } - } -} - diff --git a/src/java/org/apache/fop/mif/MIFFile.java b/src/java/org/apache/fop/mif/MIFFile.java deleted file mode 100644 index e467af1af..000000000 --- a/src/java/org/apache/fop/mif/MIFFile.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * $Id: MIFFile.java,v 1.2 2003/03/07 08:09:26 jeremias Exp $ - * ============================================================================ - * 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.mif; - -// Java -import java.io.IOException; -import java.io.OutputStream; -import java.util.Iterator; -import java.util.List; - -/** - * The MIF File. - * This organises the MIF File and the corresponding elements. - * The catalog elements are used to setup the resources that - * are referenced. - */ -public class MIFFile extends MIFElement { - - protected MIFElement colorCatalog = null; - protected PGFElement pgfCatalog = null; - protected MIFElement fontCatalog = null; - protected RulingElement rulingCatalog = null; - protected MIFElement tblCatalog = null; - protected MIFElement views = null; - protected MIFElement variableFormats = null; - protected MIFElement xRefFormats = null; - protected MIFElement document = null; - protected MIFElement bookComponent = null; - protected MIFElement initialAutoNums = null; - protected MIFElement aFrames = null; - protected MIFElement tbls = null; - protected List pages = new java.util.ArrayList(); - protected List textFlows = null; - - - public MIFFile() { - super(""); - valueElements = new java.util.ArrayList(); - setup(); - } - - /** - * Do some setup. - * Currently adds some dummy values to the resources. - */ - protected void setup() { - MIFElement unit = new MIFElement("Units"); - unit.setValue("Ucm"); - addElement(unit); - - colorCatalog = new MIFElement("ColorCatalog"); - MIFElement color = new MIFElement("Color"); - MIFElement prop = new MIFElement("ColorTag"); - prop.setValue("`Black'"); - color.addElement(prop); - prop = new MIFElement("ColorCyan"); - prop.setValue("0.000000"); - color.addElement(prop); - - prop = new MIFElement("ColorMagenta"); - prop.setValue("0.000000"); - color.addElement(prop); - prop = new MIFElement("ColorYellow"); - prop.setValue("0.000000"); - color.addElement(prop); - prop = new MIFElement("ColorBlack"); - prop.setValue("100.000000"); - color.addElement(prop); - prop = new MIFElement("ColorAttribute"); - prop.setValue("ColorIsBlack"); - color.addElement(prop); - prop = new MIFElement("ColorAttribute"); - prop.setValue("ColorIsReserved"); - color.addElement(prop); - color.finish(true); - - colorCatalog.addElement(color); - addElement(colorCatalog); - - pgfCatalog = new PGFElement(); - pgfCatalog.lookupElement(null); - addElement(pgfCatalog); - - rulingCatalog = new RulingElement(); - rulingCatalog.lookupElement(null); - addElement(rulingCatalog); - - } - - public void output(OutputStream os) throws IOException { - if (finished) { - return; - } - - if (!started) { - os.write((" # Generated by FOP\n"/* + getVersion()*/).getBytes()); - started = true; - } - boolean done = true; - - for (Iterator iter = valueElements.iterator(); iter.hasNext();) { - MIFElement el = (MIFElement)iter.next(); - boolean d = el.output(os, 0); - if (d) { - iter.remove(); - } else { - done = false; - break; - } - } - if (done && finish) { - os.write(("# end of MIFFile").getBytes()); - } - } - - public void addPage(MIFElement p) { - pages.add(p); - addElement(p); - } -} - diff --git a/src/java/org/apache/fop/mif/MIFHandler.java b/src/java/org/apache/fop/mif/MIFHandler.java deleted file mode 100644 index 902ed9750..000000000 --- a/src/java/org/apache/fop/mif/MIFHandler.java +++ /dev/null @@ -1,480 +0,0 @@ -/* - * $Id: MIFHandler.java,v 1.6 2003/03/07 08:09:26 jeremias Exp $ - * ============================================================================ - * 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.mif; - -// Java -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.apps.Document; -import org.apache.fop.apps.FOPException; -import org.apache.fop.fo.FOInputHandler; -import org.apache.fop.fo.flow.Block; -import org.apache.fop.fo.flow.ExternalGraphic; -import org.apache.fop.fo.flow.InstreamForeignObject; -import org.apache.fop.fo.flow.Inline; -import org.apache.fop.fo.flow.Leader; -import org.apache.fop.fo.flow.ListBlock; -import org.apache.fop.fo.flow.ListItem; -import org.apache.fop.fo.flow.PageNumber; -import org.apache.fop.fo.flow.Table; -import org.apache.fop.fo.flow.TableBody; -import org.apache.fop.fo.flow.TableCell; -import org.apache.fop.fo.flow.TableColumn; -import org.apache.fop.fo.flow.TableRow; -import org.apache.fop.fo.pagination.Flow; -import org.apache.fop.fo.pagination.PageSequence; -import org.apache.fop.fo.pagination.PageSequenceMaster; -import org.apache.fop.fo.pagination.SimplePageMaster; -import org.xml.sax.SAXException; - -// TODO: do we really want every method throwing a SAXException - -/** - * The MIF Handler. - * This generates MIF output using the structure events from - * the FO Tree sent to this structure handler. - * This builds an MIF file and writes it to the output. - */ -public class MIFHandler extends FOInputHandler { - - /** the MIFFile instance */ - protected MIFFile mifFile; - /** the OutputStream to write to */ - protected OutputStream outStream; - - // current state elements - private MIFElement textFlow; - private MIFElement para; - - /** - * Creates a new MIF handler on a given OutputStream. - * @param os OutputStream to write to - */ - public MIFHandler(Document doc, OutputStream os) { - super(doc); - outStream = os; - // use pdf fonts for now, this is only for resolving names - org.apache.fop.render.pdf.FontSetup.setup(doc, null); - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startDocument() - */ - public void startDocument() throws SAXException { - mifFile = new MIFFile(); - try { - mifFile.output(outStream); - } catch (IOException ioe) { - throw new SAXException(ioe); - } - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endDocument() - */ - public void endDocument() throws SAXException { - // finish all open elements - mifFile.finish(true); - try { - mifFile.output(outStream); - outStream.flush(); - } catch (IOException ioe) { - throw new SAXException(ioe); - } - } - - /** - * Start the page sequence. - * This creates the pages in the MIF document that will be used - * by the following flows and static areas. - * @see org.apache.fop.fo.FOInputHandler - */ - public void startPageSequence(PageSequence pageSeq) { - // get the layout master set - // setup the pages for this sequence - String name = pageSeq.getProperty("master-reference").getString(); - SimplePageMaster spm = pageSeq.getLayoutMasterSet().getSimplePageMaster(name); - if (spm == null) { - PageSequenceMaster psm = pageSeq.getLayoutMasterSet().getPageSequenceMaster(name); - } else { - // create simple master with regions - MIFElement prop = new MIFElement("PageType"); - prop.setValue("BodyPage"); - - MIFElement page = new MIFElement("Page"); - page.addElement(prop); - - prop = new MIFElement("PageBackground"); - prop.setValue("'Default'"); - page.addElement(prop); - - // build regions - MIFElement textRect = new MIFElement("TextRect"); - prop = new MIFElement("ID"); - prop.setValue("1"); - textRect.addElement(prop); - prop = new MIFElement("ShapeRect"); - prop.setValue("0.0 841.889 453.543 0.0"); - textRect.addElement(prop); - page.addElement(textRect); - - textRect = new MIFElement("TextRect"); - prop = new MIFElement("ID"); - prop.setValue("2"); - textRect.addElement(prop); - prop = new MIFElement("ShapeRect"); - prop.setValue("0.0 841.889 453.543 187.65"); - textRect.addElement(prop); - page.addElement(textRect); - - - - mifFile.addPage(page); - } - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endPageSequence(PageSequence) - */ - public void endPageSequence(PageSequence pageSeq) throws FOPException { - - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startFlow(Flow) - */ - public void startFlow(Flow fl) { - // start text flow in body region - textFlow = new MIFElement("TextFlow"); - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endFlow(Flow) - */ - public void endFlow(Flow fl) { - textFlow.finish(true); - mifFile.addElement(textFlow); - textFlow = null; - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startBlock(Block) - */ - public void startBlock(Block bl) { - para = new MIFElement("Para"); - // get font - textFlow.addElement(para); - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endBlock(Block) - */ - public void endBlock(Block bl) { - para.finish(true); - para = null; - } - - /** - * - * @param inl Inline that is starting. - */ - public void startInline(Inline inl){ - } - - /** - * - * @param inl Inline that is ending. - */ - public void endInline(Inline inl){ - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startTable(Table) - */ - public void startTable(Table tbl) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endTable(Table) - */ - public void endTable(Table tbl) { - } - - /** - * - * @param tc TableColumn that is starting; - */ - public void startColumn(TableColumn tc) { - } - - /** - * - * @param tc TableColumn that is ending; - */ - public void endColumn(TableColumn tc) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startHeader(TableBody) - */ - public void startHeader(TableBody th) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endHeader(TableBody) - */ - public void endHeader(TableBody th) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startFooter(TableBody) - */ - public void startFooter(TableBody tf) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endFooter(TableBody) - */ - public void endFooter(TableBody tf) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startBody(TableBody) - */ - public void startBody(TableBody tb) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endBody(TableBody) - */ - public void endBody(TableBody tb) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startRow(TableRow) - */ - public void startRow(TableRow tr) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endRow(TableRow) - */ - public void endRow(TableRow tr) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startCell(TableCell) - */ - public void startCell(TableCell tc) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endCell(TableCell) - */ - public void endCell(TableCell tc) { - } - - // Lists - /** - * @see org.apache.fop.fo.FOInputHandler#startList(ListBlock) - */ - public void startList(ListBlock lb) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endList(ListBlock) - */ - public void endList(ListBlock lb) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startListItem(ListItem) - */ - public void startListItem(ListItem li) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endListItem(ListItem) - */ - public void endListItem(ListItem li) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startListLabel() - */ - public void startListLabel() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endListLabel() - */ - public void endListLabel() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startListBody() - */ - public void startListBody() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endListBody() - */ - public void endListBody() { - } - - // Static Regions - /** - * @see org.apache.fop.fo.FOInputHandler#startStatic() - */ - public void startStatic() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endStatic() - */ - public void endStatic() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startMarkup() - */ - public void startMarkup() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endMarkup() - */ - public void endMarkup() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startLink() - */ - public void startLink() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endLink() - */ - public void endLink() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#image(ExternalGraphic) - */ - public void image(ExternalGraphic eg) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#pageRef() - */ - public void pageRef() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#foreignObject(InstreamForeignObject) - */ - public void foreignObject(InstreamForeignObject ifo) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#footnote() - */ - public void footnote() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#leader(Leader) - */ - public void leader(Leader l) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#characters(char[], int, int) - */ - public void characters(char data[], int start, int length) { - if (para != null) { - String str = new String(data, start, length); - str = str.trim(); - // break into nice length chunks - if (str.length() == 0) { - return; - } - - MIFElement line = new MIFElement("ParaLine"); - MIFElement prop = new MIFElement("TextRectID"); - prop.setValue("2"); - line.addElement(prop); - prop = new MIFElement("String"); - prop.setValue("\"" + str + "\""); - line.addElement(prop); - - para.addElement(line); - } - } - - /** - * - * @param pagenum PageNumber that is starting. - */ - public void startPageNumber(PageNumber pagenum) { - } - - /** - * - * @param pagenum PageNumber that is ending. - */ - public void endPageNumber(PageNumber pagenum) { - } -} - diff --git a/src/java/org/apache/fop/mif/PGFElement.java b/src/java/org/apache/fop/mif/PGFElement.java deleted file mode 100644 index 3677c77b8..000000000 --- a/src/java/org/apache/fop/mif/PGFElement.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * $Id: PGFElement.java,v 1.2 2003/03/07 08:09:26 jeremias Exp $ - * ============================================================================ - * 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.mif; - -/** - * Font Catalog element. - * This is the reference lookup element for fonts in - * the MIF document. - */ -public class PGFElement extends RefElement { - - /** - * Creates a new font catalog element. - */ - public PGFElement() { - super("PgfCatalog"); - } - - public MIFElement lookupElement(Object key) { - if (key == null) { - MIFElement pgf = new MIFElement("Pgf"); - MIFElement prop = new MIFElement("PgfTag"); - prop.setValue("`Body'"); - pgf.addElement(prop); - addElement(pgf); - pgf.finish(true); - return pgf; - } - return null; - } -} - diff --git a/src/java/org/apache/fop/mif/RefElement.java b/src/java/org/apache/fop/mif/RefElement.java deleted file mode 100644 index c1dafcf08..000000000 --- a/src/java/org/apache/fop/mif/RefElement.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * $Id: RefElement.java,v 1.2 2003/03/07 08:09:26 jeremias Exp $ - * ============================================================================ - * 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.mif; - -/** - * Reference MIF Element. - * This element is a lookup reference set that contains - * a list of resources used in the MIF Document. - * When a lookup is performed it will either create a new - * element or return an existing element that is valid. - * THe key depends on the type of reference, it should be able - * to uniquely identify the element. - */ -public class RefElement extends MIFElement { - - /** - * @see org.apache.fop.mif.MIFElement#MIFElement(String) - */ - public RefElement(String n) { - super(n); - } - - public MIFElement lookupElement(Object key) { - return null; - } -} - diff --git a/src/java/org/apache/fop/mif/RulingElement.java b/src/java/org/apache/fop/mif/RulingElement.java deleted file mode 100644 index ba9e32b77..000000000 --- a/src/java/org/apache/fop/mif/RulingElement.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * $Id: RulingElement.java,v 1.2 2003/03/07 08:09:26 jeremias Exp $ - * ============================================================================ - * 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.mif; - -public class RulingElement extends RefElement { - - public RulingElement() { - super("RulingCatalog"); - } - - public MIFElement lookupElement(Object key) { - if (key == null) { - MIFElement rul = new MIFElement("Ruling"); - MIFElement prop = new MIFElement("RulingTag"); - prop.setValue("`Default'"); - rul.addElement(prop); - prop = new MIFElement("RulingPenWidth"); - prop.setValue("1"); - rul.addElement(prop); - prop = new MIFElement("RulingPen"); - prop.setValue("0"); - rul.addElement(prop); - prop = new MIFElement("RulingLines"); - prop.setValue("1"); - rul.addElement(prop); - - addElement(rul); - rul.finish(true); - return rul; - } - return null; - } -} - diff --git a/src/java/org/apache/fop/render/mif/MIFElement.java b/src/java/org/apache/fop/render/mif/MIFElement.java new file mode 100644 index 000000000..cc2e1b6e9 --- /dev/null +++ b/src/java/org/apache/fop/render/mif/MIFElement.java @@ -0,0 +1,149 @@ +/* + * $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.mif; + +// Java +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.List; + +/** + * The is the basis for MIF document elements. + * This enables the creation of the element and to write it + * to an output stream including sub-elements or a single value. + */ +public class MIFElement { + protected String name; + protected String valueStr = null; + protected List valueElements = null; + + protected boolean started = false; + protected boolean finish = false; + protected boolean finished = false; + + /** + */ + public MIFElement(String n) { + name = n; + } + + public void setValue(String str) { + valueStr = str; + } + + public void addElement(MIFElement el) { + if (valueElements == null) { + valueElements = new java.util.ArrayList(); + } + valueElements.add(el); + } + + /** + * Output this element to an output stream. + * This will output only so far as the fisrt unfinished child element. + * This method can be called again to continue from the previous point. + * An element that contains child elements will only be finished when + * the finish method is called. + */ + public boolean output(OutputStream os, int indent) throws IOException { + if (finished) { + return true; + } + if (valueElements == null && valueStr == null) { + return false; + } + + String indentStr = ""; + for (int c = 0; c < indent; c++) { + indentStr += " "; + } + if (!started) { + os.write((indentStr + "<" + name).getBytes()); + if (valueElements != null) { + os.write(("\n").getBytes()); + } + started = true; + } + if (valueElements != null) { + boolean done = true; + for (Iterator iter = valueElements.iterator(); iter.hasNext();) { + MIFElement el = (MIFElement)iter.next(); + boolean d = el.output(os, indent + 1); + if (d) { + iter.remove(); + } else { + done = false; + break; + } + } + if (!finish || !done) { + return false; + } + os.write((indentStr + "> # end of " + name + "\n").getBytes()); + } else { + os.write((" " + valueStr + ">\n").getBytes()); + } + finished = true; + return true; + } + + public void finish(boolean deep) { + finish = true; + if (deep && valueElements != null) { + for (Iterator iter = valueElements.iterator(); iter.hasNext();) { + MIFElement el = (MIFElement)iter.next(); + el.finish(deep); + } + } + } +} + diff --git a/src/java/org/apache/fop/render/mif/MIFFile.java b/src/java/org/apache/fop/render/mif/MIFFile.java new file mode 100644 index 000000000..2901daf49 --- /dev/null +++ b/src/java/org/apache/fop/render/mif/MIFFile.java @@ -0,0 +1,169 @@ +/* + * $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.mif; + +// Java +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.List; + +/** + * The MIF File. + * This organises the MIF File and the corresponding elements. + * The catalog elements are used to setup the resources that + * are referenced. + */ +public class MIFFile extends MIFElement { + + protected MIFElement colorCatalog = null; + protected PGFElement pgfCatalog = null; + protected MIFElement fontCatalog = null; + protected RulingElement rulingCatalog = null; + protected MIFElement tblCatalog = null; + protected MIFElement views = null; + protected MIFElement variableFormats = null; + protected MIFElement xRefFormats = null; + protected MIFElement document = null; + protected MIFElement bookComponent = null; + protected MIFElement initialAutoNums = null; + protected MIFElement aFrames = null; + protected MIFElement tbls = null; + protected List pages = new java.util.ArrayList(); + protected List textFlows = null; + + + public MIFFile() { + super(""); + valueElements = new java.util.ArrayList(); + setup(); + } + + /** + * Do some setup. + * Currently adds some dummy values to the resources. + */ + protected void setup() { + MIFElement unit = new MIFElement("Units"); + unit.setValue("Ucm"); + addElement(unit); + + colorCatalog = new MIFElement("ColorCatalog"); + MIFElement color = new MIFElement("Color"); + MIFElement prop = new MIFElement("ColorTag"); + prop.setValue("`Black'"); + color.addElement(prop); + prop = new MIFElement("ColorCyan"); + prop.setValue("0.000000"); + color.addElement(prop); + + prop = new MIFElement("ColorMagenta"); + prop.setValue("0.000000"); + color.addElement(prop); + prop = new MIFElement("ColorYellow"); + prop.setValue("0.000000"); + color.addElement(prop); + prop = new MIFElement("ColorBlack"); + prop.setValue("100.000000"); + color.addElement(prop); + prop = new MIFElement("ColorAttribute"); + prop.setValue("ColorIsBlack"); + color.addElement(prop); + prop = new MIFElement("ColorAttribute"); + prop.setValue("ColorIsReserved"); + color.addElement(prop); + color.finish(true); + + colorCatalog.addElement(color); + addElement(colorCatalog); + + pgfCatalog = new PGFElement(); + pgfCatalog.lookupElement(null); + addElement(pgfCatalog); + + rulingCatalog = new RulingElement(); + rulingCatalog.lookupElement(null); + addElement(rulingCatalog); + + } + + public void output(OutputStream os) throws IOException { + if (finished) { + return; + } + + if (!started) { + os.write((" # Generated by FOP\n"/* + getVersion()*/).getBytes()); + started = true; + } + boolean done = true; + + for (Iterator iter = valueElements.iterator(); iter.hasNext();) { + MIFElement el = (MIFElement)iter.next(); + boolean d = el.output(os, 0); + if (d) { + iter.remove(); + } else { + done = false; + break; + } + } + if (done && finish) { + os.write(("# end of MIFFile").getBytes()); + } + } + + public void addPage(MIFElement p) { + pages.add(p); + addElement(p); + } +} + diff --git a/src/java/org/apache/fop/render/mif/MIFHandler.java b/src/java/org/apache/fop/render/mif/MIFHandler.java new file mode 100644 index 000000000..0f7cf75f8 --- /dev/null +++ b/src/java/org/apache/fop/render/mif/MIFHandler.java @@ -0,0 +1,480 @@ +/* + * $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.mif; + +// Java +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.apps.Document; +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.FOInputHandler; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Inline; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.PageNumber; +import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableCell; +import org.apache.fop.fo.flow.TableColumn; +import org.apache.fop.fo.flow.TableRow; +import org.apache.fop.fo.pagination.Flow; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.fo.pagination.PageSequenceMaster; +import org.apache.fop.fo.pagination.SimplePageMaster; +import org.xml.sax.SAXException; + +// TODO: do we really want every method throwing a SAXException + +/** + * The MIF Handler. + * This generates MIF output using the structure events from + * the FO Tree sent to this structure handler. + * This builds an MIF file and writes it to the output. + */ +public class MIFHandler extends FOInputHandler { + + /** the MIFFile instance */ + protected MIFFile mifFile; + /** the OutputStream to write to */ + protected OutputStream outStream; + + // current state elements + private MIFElement textFlow; + private MIFElement para; + + /** + * Creates a new MIF handler on a given OutputStream. + * @param os OutputStream to write to + */ + public MIFHandler(Document doc, OutputStream os) { + super(doc); + outStream = os; + // use pdf fonts for now, this is only for resolving names + org.apache.fop.render.pdf.FontSetup.setup(doc, null); + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startDocument() + */ + public void startDocument() throws SAXException { + mifFile = new MIFFile(); + try { + mifFile.output(outStream); + } catch (IOException ioe) { + throw new SAXException(ioe); + } + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endDocument() + */ + public void endDocument() throws SAXException { + // finish all open elements + mifFile.finish(true); + try { + mifFile.output(outStream); + outStream.flush(); + } catch (IOException ioe) { + throw new SAXException(ioe); + } + } + + /** + * Start the page sequence. + * This creates the pages in the MIF document that will be used + * by the following flows and static areas. + * @see org.apache.fop.fo.FOInputHandler + */ + public void startPageSequence(PageSequence pageSeq) { + // get the layout master set + // setup the pages for this sequence + String name = pageSeq.getProperty("master-reference").getString(); + SimplePageMaster spm = pageSeq.getLayoutMasterSet().getSimplePageMaster(name); + if (spm == null) { + PageSequenceMaster psm = pageSeq.getLayoutMasterSet().getPageSequenceMaster(name); + } else { + // create simple master with regions + MIFElement prop = new MIFElement("PageType"); + prop.setValue("BodyPage"); + + MIFElement page = new MIFElement("Page"); + page.addElement(prop); + + prop = new MIFElement("PageBackground"); + prop.setValue("'Default'"); + page.addElement(prop); + + // build regions + MIFElement textRect = new MIFElement("TextRect"); + prop = new MIFElement("ID"); + prop.setValue("1"); + textRect.addElement(prop); + prop = new MIFElement("ShapeRect"); + prop.setValue("0.0 841.889 453.543 0.0"); + textRect.addElement(prop); + page.addElement(textRect); + + textRect = new MIFElement("TextRect"); + prop = new MIFElement("ID"); + prop.setValue("2"); + textRect.addElement(prop); + prop = new MIFElement("ShapeRect"); + prop.setValue("0.0 841.889 453.543 187.65"); + textRect.addElement(prop); + page.addElement(textRect); + + + + mifFile.addPage(page); + } + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endPageSequence(PageSequence) + */ + public void endPageSequence(PageSequence pageSeq) throws FOPException { + + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startFlow(Flow) + */ + public void startFlow(Flow fl) { + // start text flow in body region + textFlow = new MIFElement("TextFlow"); + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endFlow(Flow) + */ + public void endFlow(Flow fl) { + textFlow.finish(true); + mifFile.addElement(textFlow); + textFlow = null; + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startBlock(Block) + */ + public void startBlock(Block bl) { + para = new MIFElement("Para"); + // get font + textFlow.addElement(para); + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endBlock(Block) + */ + public void endBlock(Block bl) { + para.finish(true); + para = null; + } + + /** + * + * @param inl Inline that is starting. + */ + public void startInline(Inline inl){ + } + + /** + * + * @param inl Inline that is ending. + */ + public void endInline(Inline inl){ + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startTable(Table) + */ + public void startTable(Table tbl) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endTable(Table) + */ + public void endTable(Table tbl) { + } + + /** + * + * @param tc TableColumn that is starting; + */ + public void startColumn(TableColumn tc) { + } + + /** + * + * @param tc TableColumn that is ending; + */ + public void endColumn(TableColumn tc) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startHeader(TableBody) + */ + public void startHeader(TableBody th) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endHeader(TableBody) + */ + public void endHeader(TableBody th) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startFooter(TableBody) + */ + public void startFooter(TableBody tf) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endFooter(TableBody) + */ + public void endFooter(TableBody tf) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startBody(TableBody) + */ + public void startBody(TableBody tb) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endBody(TableBody) + */ + public void endBody(TableBody tb) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startRow(TableRow) + */ + public void startRow(TableRow tr) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endRow(TableRow) + */ + public void endRow(TableRow tr) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startCell(TableCell) + */ + public void startCell(TableCell tc) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endCell(TableCell) + */ + public void endCell(TableCell tc) { + } + + // Lists + /** + * @see org.apache.fop.fo.FOInputHandler#startList(ListBlock) + */ + public void startList(ListBlock lb) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endList(ListBlock) + */ + public void endList(ListBlock lb) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startListItem(ListItem) + */ + public void startListItem(ListItem li) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endListItem(ListItem) + */ + public void endListItem(ListItem li) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startListLabel() + */ + public void startListLabel() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endListLabel() + */ + public void endListLabel() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startListBody() + */ + public void startListBody() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endListBody() + */ + public void endListBody() { + } + + // Static Regions + /** + * @see org.apache.fop.fo.FOInputHandler#startStatic() + */ + public void startStatic() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endStatic() + */ + public void endStatic() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startMarkup() + */ + public void startMarkup() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endMarkup() + */ + public void endMarkup() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#startLink() + */ + public void startLink() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#endLink() + */ + public void endLink() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#image(ExternalGraphic) + */ + public void image(ExternalGraphic eg) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#pageRef() + */ + public void pageRef() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#foreignObject(InstreamForeignObject) + */ + public void foreignObject(InstreamForeignObject ifo) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#footnote() + */ + public void footnote() { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#leader(Leader) + */ + public void leader(Leader l) { + } + + /** + * @see org.apache.fop.fo.FOInputHandler#characters(char[], int, int) + */ + public void characters(char data[], int start, int length) { + if (para != null) { + String str = new String(data, start, length); + str = str.trim(); + // break into nice length chunks + if (str.length() == 0) { + return; + } + + MIFElement line = new MIFElement("ParaLine"); + MIFElement prop = new MIFElement("TextRectID"); + prop.setValue("2"); + line.addElement(prop); + prop = new MIFElement("String"); + prop.setValue("\"" + str + "\""); + line.addElement(prop); + + para.addElement(line); + } + } + + /** + * + * @param pagenum PageNumber that is starting. + */ + public void startPageNumber(PageNumber pagenum) { + } + + /** + * + * @param pagenum PageNumber that is ending. + */ + public void endPageNumber(PageNumber pagenum) { + } +} + diff --git a/src/java/org/apache/fop/render/mif/PGFElement.java b/src/java/org/apache/fop/render/mif/PGFElement.java new file mode 100644 index 000000000..4e17a4e41 --- /dev/null +++ b/src/java/org/apache/fop/render/mif/PGFElement.java @@ -0,0 +1,80 @@ +/* + * $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.mif; + +/** + * Font Catalog element. + * This is the reference lookup element for fonts in + * the MIF document. + */ +public class PGFElement extends RefElement { + + /** + * Creates a new font catalog element. + */ + public PGFElement() { + super("PgfCatalog"); + } + + public MIFElement lookupElement(Object key) { + if (key == null) { + MIFElement pgf = new MIFElement("Pgf"); + MIFElement prop = new MIFElement("PgfTag"); + prop.setValue("`Body'"); + pgf.addElement(prop); + addElement(pgf); + pgf.finish(true); + return pgf; + } + return null; + } +} + diff --git a/src/java/org/apache/fop/render/mif/RefElement.java b/src/java/org/apache/fop/render/mif/RefElement.java new file mode 100644 index 000000000..c35009d15 --- /dev/null +++ b/src/java/org/apache/fop/render/mif/RefElement.java @@ -0,0 +1,75 @@ +/* + * $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.mif; + +/** + * Reference MIF Element. + * This element is a lookup reference set that contains + * a list of resources used in the MIF Document. + * When a lookup is performed it will either create a new + * element or return an existing element that is valid. + * THe key depends on the type of reference, it should be able + * to uniquely identify the element. + */ +public class RefElement extends MIFElement { + + /** + * @see org.apache.fop.mif.MIFElement#MIFElement(String) + */ + public RefElement(String n) { + super(n); + } + + public MIFElement lookupElement(Object key) { + return null; + } +} + diff --git a/src/java/org/apache/fop/render/mif/RulingElement.java b/src/java/org/apache/fop/render/mif/RulingElement.java new file mode 100644 index 000000000..c205a72f4 --- /dev/null +++ b/src/java/org/apache/fop/render/mif/RulingElement.java @@ -0,0 +1,82 @@ +/* + * $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.mif; + +public class RulingElement extends RefElement { + + public RulingElement() { + super("RulingCatalog"); + } + + public MIFElement lookupElement(Object key) { + if (key == null) { + MIFElement rul = new MIFElement("Ruling"); + MIFElement prop = new MIFElement("RulingTag"); + prop.setValue("`Default'"); + rul.addElement(prop); + prop = new MIFElement("RulingPenWidth"); + prop.setValue("1"); + rul.addElement(prop); + prop = new MIFElement("RulingPen"); + prop.setValue("0"); + rul.addElement(prop); + prop = new MIFElement("RulingLines"); + prop.setValue("1"); + rul.addElement(prop); + + addElement(rul); + rul.finish(true); + return rul; + } + return null; + } +} +