View Javadoc

1   /*
2    * Copyright 2002 - 2009 JEuclid, http://jeuclid.sf.net
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: ImageConverterMathML2G2D.java,v 7398e6c12c80 2010/02/17 13:26:07 max $ */
18  
19  package net.sourceforge.jeuclid.xmlgraphics;
20  
21  import java.util.Map;
22  
23  import org.apache.xmlgraphics.image.loader.Image;
24  import org.apache.xmlgraphics.image.loader.ImageException;
25  import org.apache.xmlgraphics.image.loader.ImageFlavor;
26  import org.apache.xmlgraphics.image.loader.impl.AbstractImageConverter;
27  import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
28  import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
29  import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
30  
31  /**
32   * Convert a MathML Image given as DOM to a Graphics2d Painter.
33   * 
34   * @version $Revision: 7398e6c12c80 $
35   */
36  public class ImageConverterMathML2G2D extends AbstractImageConverter {
37      /**
38       * Default Constructor.
39       */
40      public ImageConverterMathML2G2D() {
41          // Empty on purpose
42      }
43  
44      /** {@inheritDoc} */
45      @SuppressWarnings("unchecked")
46      // Interface is not generic
47      public Image convert(final Image src, final Map hints)
48              throws ImageException {
49          // TODO: Should be checked
50          // this.checkSourceFlavor(src);
51          final ImageXMLDOM xmlDom = (ImageXMLDOM) src;
52          final Graphics2DImagePainter painter = Graphics2DImagePainterMathML
53                  .createGraphics2DImagePainter(xmlDom.getDocument());
54  
55          final ImageGraphics2D g2dImage = new ImageGraphics2D(src.getInfo(),
56                  painter);
57          return g2dImage;
58      }
59  
60      /** {@inheritDoc} */
61      public ImageFlavor getSourceFlavor() {
62          return ImageFlavor.XML_DOM;
63          // TODO: Use new namespace
64          // return new ImageFlavor(
65          // "text/xml;DOM;namespace=http://www.w3.org/1998/Math/MathML");
66      }
67  
68      /** {@inheritDoc} */
69      public ImageFlavor getTargetFlavor() {
70          return ImageFlavor.GRAPHICS2D;
71      }
72  
73  }