Debian Codegraph @

jlatexmath-fop/src/main/java/org/scilab/forge/jlatexmath/fop/JLaTeXMathXMLHandler.java

raw
1 /* JLaTeXMathXMLHandler.java
2 * =========================================================================
3 * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath
4 *
5 * Copyright (C) 2010 DENIZET Calixte
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * A copy of the GNU General Public License can be found in the file
18 * LICENSE.txt provided with the source distribution of this program (see
19 * the META-INF directory in the source jar). This license can also be
20 * found on the GNU website at http://www.gnu.org/licenses/gpl.html.
21 *
22 * If you did not receive a copy of the GNU General Public License along
23 * with this program, contact the lead developer, or write to the Free
24 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * 02110-1301, USA.
26 *
27 * Linking this library statically or dynamically with other modules
28 * is making a combined work based on this library. Thus, the terms
29 * and conditions of the GNU General Public License cover the whole
30 * combination.
31 *
32 * As a special exception, the copyright holders of this library give you
33 * permission to link this library with independent modules to produce
34 * an executable, regardless of the license terms of these independent
35 * modules, and to copy and distribute the resulting executable under terms
36 * of your choice, provided that you also meet, for each linked independent
37 * module, the terms and conditions of the license of that module.
38 * An independent module is a module which is not derived from or based
39 * on this library. If you modify this library, you may extend this exception
40 * to your version of the library, but you are not obliged to do so.
41 * If you do not wish to do so, delete this exception statement from your
42 * version.
43 *
44 */
45
46 /* This file is largely inspired by files wrote by Jeremias Maerki,
47 * for the fop plugin of barcode4j available at
48 * http://barcode4j.sourceforge.net/
49 */
50
51 package org.scilab.forge.jlatexmath.fop;
52
53 import org.apache.fop.render.Graphics2DAdapter;
54 import org.apache.fop.render.Renderer;
55 import org.apache.fop.render.RendererContext;
56 import org.apache.fop.render.XMLHandler;
57 import org.scilab.forge.jlatexmath.fop.image.loader.Graphics2DImagePainterJLaTeXMath;
58 import org.w3c.dom.Document;
59
60 /**
61 * XMLHandler which draws LaTeX through a fop G2DAdapter.
62 */
63 public class JLaTeXMathXMLHandler implements XMLHandler {
64
65 public JLaTeXMathXMLHandler() { }
66
67 public void handleXML(RendererContext context, Document document, String ns) throws Exception {
68 Graphics2DAdapter g2dAdapter = context.getRenderer().getGraphics2DAdapter();
69
70 if (g2dAdapter != null) {
71 g2dAdapter.paintImage(new Graphics2DImagePainterJLaTeXMath(document), context,
72 ((Integer) context.getProperty("xpos")).intValue(),
73 ((Integer) context.getProperty("ypos")).intValue(),
74 ((Integer) context.getProperty("width")).intValue(),
75 ((Integer) context.getProperty("height")).intValue());
76 }
77 }
78
79 public boolean supportsRenderer(Renderer renderer) {
80 return renderer.getGraphics2DAdapter() != null;
81 }
82
83 public String getMimeType() {
84 return JLaTeXMathObj.MIME_TYPE;
85 }
86
87 public String getNamespace() {
88 return JLaTeXMathObj.JLATEXMATH_NS;
89 }
90 }