001 /*
002 * Copyright 2007 - 2008 JEuclid, http://jeuclid.sf.net
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 /* $Id: ConverterPlugin.java,v 70597ba9d706 2008/02/18 19:42:05 maxberger $ */
018
019 package net.sourceforge.jeuclid.converter;
020
021 import java.awt.Dimension;
022 import java.io.IOException;
023 import java.io.OutputStream;
024
025 import net.sourceforge.jeuclid.LayoutContext;
026
027 import org.w3c.dom.Document;
028 import org.w3c.dom.Node;
029
030 /**
031 * Describes an Image converter.
032 *
033 * @version $Revision: 70597ba9d706 $
034 */
035 public interface ConverterPlugin {
036 /**
037 * Write the given MathBase object with its rendering parameters into the
038 * given output stream.
039 *
040 * @param doc
041 * A JEuclid DocumentElement
042 * @param outStream
043 * Target output stream.
044 * @param context
045 * LayoutContext to use.
046 * @return Rendering's dimension based on the spefic plugin's Graphics2D
047 * implementation.
048 * @throws IOException
049 * if an I/O error occurred during write.
050 */
051 Dimension convert(Node doc, LayoutContext context, OutputStream outStream)
052 throws IOException;
053
054 /**
055 * Internal class describing an XML document and the dimensions of its
056 * default view.
057 */
058 class DocumentWithDimension {
059 private final Document document;
060
061 private final Dimension dimension;
062
063 private final float baseline;
064
065 public DocumentWithDimension(final Document doc, final Dimension dim,
066 final float bline) {
067 super();
068 this.document = doc;
069 this.dimension = dim;
070 this.baseline = bline;
071 }
072
073 /**
074 * @return the document resulting from this conversion, a suptype of
075 * Document (e.g. SVGDocument) if possible.
076 */
077 public Document getDocument() {
078 return this.document;
079 }
080
081 /**
082 * @return The dimensions from this conversion
083 */
084 public Dimension getDimension() {
085 return this.dimension;
086 }
087
088 /**
089 * @return the position of the baseline in pixels from the bottom.
090 */
091 public float getBaseline() {
092 return this.baseline;
093 }
094
095 }
096
097 /**
098 * Convert from the given Math Object to an XML DOM Document.
099 *
100 * @param doc
101 * A JEuclid DocumentElement
102 * @param context
103 * LayoutContext to use.
104 * @return an instance of DocumentWithDimension, containing a Document of
105 * the appropriate subtype for this format (e.g. SVGDocument), if
106 * available. If conversion is not supported by this plugin, it
107 * may return null.
108 */
109 DocumentWithDimension convert(final Node doc, final LayoutContext context);
110
111 }