You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MathMLElementMapping.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  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. /* $Id$ */
  17. package org.apache.fop.mathml;
  18. import org.apache.fop.fo.FONode;
  19. import org.apache.fop.fo.ElementMapping;
  20. import org.apache.fop.image.analyser.XMLReader;
  21. import org.apache.fop.image.FopImage;
  22. import org.w3c.dom.Document;
  23. import java.util.HashMap;
  24. import net.sourceforge.jeuclid.MathBase;
  25. import net.sourceforge.jeuclid.DOMMathBuilder;
  26. /**
  27. * This class provides the element mapping for FOP.
  28. */
  29. public class MathMLElementMapping extends ElementMapping {
  30. /** MathML Namespace */
  31. public static final String NAMESPACE = "http://www.w3.org/1998/Math/MathML";
  32. public MathMLElementMapping() {
  33. this.namespaceURI = NAMESPACE;
  34. }
  35. protected void initialize() {
  36. if (foObjs == null) {
  37. foObjs = new HashMap();
  38. foObjs.put("math", new ME());
  39. foObjs.put(DEFAULT, new MathMLMaker());
  40. XMLReader.setConverter(this.namespaceURI, new MathMLConverter());
  41. }
  42. }
  43. static class MathMLMaker extends ElementMapping.Maker {
  44. public FONode make(FONode parent) {
  45. return new MathMLObj(parent);
  46. }
  47. }
  48. static class ME extends ElementMapping.Maker {
  49. public FONode make(FONode parent) {
  50. return new MathMLElement(parent);
  51. }
  52. }
  53. static class MathMLConverter implements XMLReader.Converter {
  54. public FopImage.ImageInfo convert(Document doc) {
  55. try {
  56. FopImage.ImageInfo info = new FopImage.ImageInfo();
  57. String fontname = "Helvetica";
  58. int fontstyle = 0;
  59. int inlinefontstyle = 0;
  60. int inlinefontsize = 12;
  61. int displayfontsize = 12;
  62. MathBase base = new MathBase(
  63. (new DOMMathBuilder(doc)).getMathRootElement(),
  64. fontname, fontstyle, inlinefontsize,
  65. displayfontsize);
  66. base.setDebug(false);
  67. info.data = MathMLElement.createSVG(base);
  68. info.width = base.getWidth();
  69. info.height = base.getHeight();
  70. info.mimeType = "image/svg+xml";
  71. info.str = "http://www.w3.org/2000/svg";
  72. return info;
  73. } catch (Throwable t) {
  74. /**@todo log that properly */
  75. }
  76. return null;
  77. }
  78. }
  79. }