1 17 18 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 ; 27 import org.w3c.dom.Document ; 28 29 import java.util.HashMap ; 30 31 import net.sourceforge.jeuclid.MathBase; 32 import net.sourceforge.jeuclid.DOMMathBuilder; 33 34 37 public class MathMLElementMapping extends ElementMapping { 38 39 40 public static final String NAMESPACE = "http://www.w3.org/1998/Math/MathML"; 41 42 43 public MathMLElementMapping() { 44 this.namespaceURI = NAMESPACE; 45 } 46 47 48 public DOMImplementation getDOMImplementation() { 49 return getDefaultDOMImplementation(); 50 } 51 52 53 protected void initialize() { 54 if (foObjs == null) { 55 foObjs = new HashMap (); 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 doc) { 77 try { 78 FopImage.ImageInfo info = new FopImage.ImageInfo(); 79 String 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 t) { 102 103 } 104 return null; 105 106 } 107 } 108 109 } 110 | Popular Tags |