KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > mathml > MathMLElementMapping


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: MathMLElementMapping.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.mathml;
21
22 import org.apache.fop.fo.FONode;
23 import org.apache.fop.fo.ElementMapping;
24 import org.apache.fop.image.analyser.XMLReader;
25 import org.apache.fop.image.FopImage;
26 import org.w3c.dom.DOMImplementation JavaDoc;
27 import org.w3c.dom.Document JavaDoc;
28
29 import java.util.HashMap JavaDoc;
30
31 import net.sourceforge.jeuclid.MathBase;
32 import net.sourceforge.jeuclid.DOMMathBuilder;
33
34 /**
35  * This class provides the element mapping for FOP.
36  */

37 public class MathMLElementMapping extends ElementMapping {
38
39     /** MathML Namespace */
40     public static final String JavaDoc NAMESPACE = "http://www.w3.org/1998/Math/MathML";
41
42     /** Main constructor. */
43     public MathMLElementMapping() {
44         this.namespaceURI = NAMESPACE;
45     }
46
47     /** @see org.apache.fop.fo.ElementMapping#getDOMImplementation() */
48     public DOMImplementation JavaDoc getDOMImplementation() {
49         return getDefaultDOMImplementation();
50     }
51
52     /** @see org.apache.fop.fo.ElementMapping#initialize() */
53     protected void initialize() {
54         if (foObjs == null) {
55             foObjs = new HashMap JavaDoc();
56             foObjs.put("math", new ME());
57             foObjs.put(DEFAULT, new MathMLMaker());
58
59             XMLReader.setConverter(this.namespaceURI, new MathMLConverter());
60         }
61     }
62
63     static class MathMLMaker extends ElementMapping.Maker {
64         public FONode make(FONode parent) {
65             return new MathMLObj(parent);
66         }
67     }
68
69     static class ME extends ElementMapping.Maker {
70         public FONode make(FONode parent) {
71             return new MathMLElement(parent);
72         }
73     }
74
75     static class MathMLConverter implements XMLReader.Converter {
76         public FopImage.ImageInfo convert(Document JavaDoc doc) {
77             try {
78                 FopImage.ImageInfo info = new FopImage.ImageInfo();
79                 String JavaDoc fontname = "Helvetica";
80                 int fontstyle = 0;
81                 int inlinefontstyle = 0;
82                 int inlinefontsize = 12;
83                 int displayfontsize = 12;
84
85                 MathBase base = new MathBase(
86                                   (new DOMMathBuilder(doc)).getMathRootElement(),
87                                   fontname, fontstyle, inlinefontsize,
88                                   displayfontsize);
89
90                 base.setDebug(false);
91
92                 info.data = MathMLElement.createSVG(base);
93
94                 info.width = base.getWidth();
95                 info.height = base.getHeight();
96
97                 info.mimeType = "image/svg+xml";
98                 info.str = "http://www.w3.org/2000/svg";
99
100                 return info;
101             } catch (Throwable JavaDoc t) {
102                 /**@todo log that properly */
103             }
104             return null;
105
106         }
107     }
108
109 }
110
Popular Tags