001    /*
002     * Copyright 2002 - 2009 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: ImageConverterMathML2G2D.java,v 7398e6c12c80 2010/02/17 13:26:07 max $ */
018    
019    package net.sourceforge.jeuclid.xmlgraphics;
020    
021    import java.util.Map;
022    
023    import org.apache.xmlgraphics.image.loader.Image;
024    import org.apache.xmlgraphics.image.loader.ImageException;
025    import org.apache.xmlgraphics.image.loader.ImageFlavor;
026    import org.apache.xmlgraphics.image.loader.impl.AbstractImageConverter;
027    import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
028    import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
029    import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
030    
031    /**
032     * Convert a MathML Image given as DOM to a Graphics2d Painter.
033     * 
034     * @version $Revision: 7398e6c12c80 $
035     */
036    public class ImageConverterMathML2G2D extends AbstractImageConverter {
037        /**
038         * Default Constructor.
039         */
040        public ImageConverterMathML2G2D() {
041            // Empty on purpose
042        }
043    
044        /** {@inheritDoc} */
045        @SuppressWarnings("unchecked")
046        // Interface is not generic
047        public Image convert(final Image src, final Map hints)
048                throws ImageException {
049            // TODO: Should be checked
050            // this.checkSourceFlavor(src);
051            final ImageXMLDOM xmlDom = (ImageXMLDOM) src;
052            final Graphics2DImagePainter painter = Graphics2DImagePainterMathML
053                    .createGraphics2DImagePainter(xmlDom.getDocument());
054    
055            final ImageGraphics2D g2dImage = new ImageGraphics2D(src.getInfo(),
056                    painter);
057            return g2dImage;
058        }
059    
060        /** {@inheritDoc} */
061        public ImageFlavor getSourceFlavor() {
062            return ImageFlavor.XML_DOM;
063            // TODO: Use new namespace
064            // return new ImageFlavor(
065            // "text/xml;DOM;namespace=http://www.w3.org/1998/Math/MathML");
066        }
067    
068        /** {@inheritDoc} */
069        public ImageFlavor getTargetFlavor() {
070            return ImageFlavor.GRAPHICS2D;
071        }
072    
073    }