View Javadoc

1   /*
2    * Copyright 2007 - 2008 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: JEuclidXMLHandler.java,v 32023847f457 2009/03/20 14:20:15 maxberger $ */
18  
19  /* 
20   * Parts of the contents are heavily inspired by work done for Barcode4J by
21   * Jeremias Maerki, available at http://barcode4j.sf.net/
22   */
23  package net.sourceforge.jeuclid.fop;
24  
25  import net.sourceforge.jeuclid.elements.AbstractJEuclidElement;
26  import net.sourceforge.jeuclid.xmlgraphics.Graphics2DImagePainterMathML;
27  
28  import org.apache.fop.render.Graphics2DAdapter;
29  import org.apache.fop.render.Renderer;
30  import org.apache.fop.render.RendererContext;
31  import org.apache.fop.render.XMLHandler;
32  import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
33  import org.w3c.dom.Document;
34  
35  /**
36   * XMLHandler which draws MathML through a fop G2DAdapter.
37   * 
38   * @version $Revision: 32023847f457 $
39   */
40  public class JEuclidXMLHandler implements XMLHandler {
41  
42      /** Creates a new instance of JEuclidXMLHandler. */
43      public JEuclidXMLHandler() {
44      }
45  
46      /** {@inheritDoc} */
47      public void handleXML(final RendererContext rendererContext,
48              final Document document, final String ns) throws Exception {
49          final Graphics2DAdapter g2dAdapter = rendererContext.getRenderer()
50                  .getGraphics2DAdapter();
51  
52          if (g2dAdapter != null) {
53              final Graphics2DImagePainter painter = Graphics2DImagePainterMathML
54                      .createGraphics2DImagePainter(document);
55              g2dAdapter.paintImage(painter, rendererContext,
56                      ((Integer) rendererContext.getProperty("xpos"))
57                              .intValue(), ((Integer) rendererContext
58                              .getProperty("ypos")).intValue(),
59                      ((Integer) rendererContext.getProperty("width"))
60                              .intValue(), ((Integer) rendererContext
61                              .getProperty("height")).intValue());
62  
63          }
64      }
65  
66      /** {@inheritDoc} */
67      public boolean supportsRenderer(final Renderer renderer) {
68          return renderer.getGraphics2DAdapter() != null;
69      }
70  
71      /** {@inheritDoc} */
72      public String getNamespace() {
73          return AbstractJEuclidElement.URI;
74      }
75  
76  }