2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - Calixte DENIZET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 package org.scilab.modules.helptools.external;
16 import java.util.HashMap;
19 import org.xml.sax.Attributes;
21 import org.scilab.modules.helptools.image.ImageConverter;
24 * Handle the included SVG code
25 * @author Calixte DENIZET
27 public class HTMLMathMLHandler extends ExternalXMLHandler {
29 private static final String MATH = "math";
30 private static final String BASENAME = "Equation_MathML_";
32 private static HTMLMathMLHandler instance;
35 private StringBuilder buffer = new StringBuilder(8192);
36 private String baseDir;
37 private String outputDir;
41 * @param baseDir the base directory where to put the generated images
43 private HTMLMathMLHandler(String outputDir, String baseDir) {
44 this.outputDir = outputDir + File.separator + baseDir;
45 this.baseDir = baseDir + "/";
48 public static HTMLMathMLHandler getInstance(String outputDir, String baseDir) {
49 if (instance == null) {
50 instance = new HTMLMathMLHandler(outputDir, baseDir);
59 public String getURI() {
60 return "http://www.w3.org/1998/Math/MathML";
66 public StringBuilder startExternalXML(String localName, Attributes attributes) {
67 recreateTag(buffer, localName, attributes);
68 if (MATH.equals(localName)) {
78 public String endExternalXML(String localName) {
79 if (MATH.equals(localName)) {
80 recreateTag(buffer, localName, null);
81 File f = new File(outputDir, BASENAME + (compt++) + ".png");
82 Map<String, String> attributes = new HashMap();
83 attributes.put("fontsize", "16");
85 String ret = ImageConverter.getImageByCode(getConverter().getCurrentFileName(), buffer.toString(), attributes, "image/mathml", f, baseDir + f.getName());
91 recreateTag(buffer, localName, null);