123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- /*
- * $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 <jtauber@jtauber.com>. For more information on the Apache
- * Software Foundation, please see <http://www.apache.org/>.
- */
- 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) {
- }
- }
|