keiron      02/04/23 03:26:47

  Added:       contrib/mathml .cvsignore README build.sh build.xml
               contrib/mathml/docs example.mml mathml.fo
               contrib/mathml/lib readme.txt
               contrib/mathml/resources/META-INF/services
                        org.apache.fop.fo.ElementMapping
               contrib/mathml/src/org/apache/fop/mathml MathMLElement.java
                        MathMLElementMapping.java MathMLObj.java
  Log:
  added an extension for mathml
  uses jeuclid to convert mathml into svg
  
  Revision  Changes    Path
  1.1                  xml-fop/contrib/mathml/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  build
  
  
  
  1.1                  xml-fop/contrib/mathml/README
  
  Index: README
  ===================================================================
  FOP MathML Readme
  
  This directory contains an extension for MathML that can be used with FOP.
  
  This extension works with jeuclid which is available from:
  http://sourceforge.net/projects/jeuclid/
  
  This simply uses jeuclid to convert the mathml xml into svg.
  The svg is then handled as normal.
  
  
  
  
  1.1                  xml-fop/contrib/mathml/build.sh
  
  Index: build.sh
  ===================================================================
  #!/bin/sh
  echo
  echo "MathML Build System"
  echo "----------------"
  echo
  
  if [ "$JAVA_HOME" = "" ] ; then
    echo "ERROR: JAVA_HOME not found in your environment."
    echo
    echo "Please, set the JAVA_HOME variable in your environment to match the"
    echo "location of the Java Virtual Machine you want to use."
    exit 1
  fi
  LIBDIR=../../lib
  
LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:$LIBDIR/ant.jar:$LIBDIR/batik.jar:$LIBDIR/buildtools.jar:$LIBDIR/xerces-1.4.3.jar:$LIBDIR/xalan-2.2D11.jar:../../build/fop.jar:$LIBDIR/avalon-framework-cvs-20020315.jar:lib/jeuclid.jar
  ANT_HOME=$LIBDIR
  
  echo
  CP=$LOCALCLASSPATH
  echo Building with classpath $CP
  
  
  echo Starting Ant...
  echo
  
  $JAVA_HOME/bin/java -Dant.home=$ANT_HOME -classpath "$CP" org.apache.tools.ant.Main 
$*
  
  
  
  1.1                  xml-fop/contrib/mathml/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- ===========================================================================
  
  ============================================================================ -->
  
  <project default="package" basedir=".">
  
    <!-- =================================================================== -->
    <!-- Initialization target                                               -->
    <!-- =================================================================== -->
    <target name="init">
      <tstamp/>
      <property name="Name" value="MathML-FOP"/>
      <property name="name" value="mathml-fop"/>
      <property name="version" value="0.1-CVS"/>
      <filter  token="version" value="${version}"/>
      <property name="year" value="2002"/>
  
      <echo message="------------------- ${Name} ${version} [${year}] 
----------------"/>
  
      <property name="build.compiler" value="classic"/>
      <property name="debug" value="off"/>
      <property name="optimize" value="on"/>
      <property name="deprecation" value="off"/>
  
      <property name="src.dir" value="./src"/>
      <property name="lib.dir" value="./lib"/>
      <property name="packages" value="org.apache.fop.*"/>
  
      <property name="build.dir" value="./build"/>
      <property name="build.src" value="./build/src"/>
      <property name="build.dest" value="./build/classes"/>
  
      <property name="resource.dir" value="resources"/>
      <property name="mathml.dir" value="org/apache/fop/mathml"/>
  
      <property name="xslt" value="org.apache.xalan.xslt.Process"/>
  
    </target>
  
    <!-- =================================================================== -->
    <!-- Help on usage                                                       -->
    <!-- =================================================================== -->
    <target name="usage">
      <echo message=""/>
      <echo message=""/>
      <echo message="${Name} Build file"/>
      <echo message="-------------------------------------------------------------"/>
      <echo message=""/>
      <echo message=" available targets are:"/>
      <echo message=""/>
      <echo message="   package   --> generates the ${name}.jar file (default)"/>
      <echo message="   compile   --> compiles the source code"/>
      <echo message="   clean     --> cleans up the directory"/>
      <echo message="   site      --> generates the ${Name} web site (not yet 
implemented)"/>
      <echo message=""/>
      <echo message=" See the comments inside the build.xml file for more details."/>
      <echo message="-------------------------------------------------------------"/>
      <echo message=""/>
      <echo message=""/>
    </target>
  
    <!-- =================================================================== -->
    <!-- Prepares the build directory                                        -->
    <!-- =================================================================== -->
    <target name="prepare" depends="init">
      <!-- create directories -->
      <echo message="Preparing the build directories"/>
      <mkdir dir="${build.dir}"/>
      <mkdir dir="${build.src}"/>
      <mkdir dir="${build.src}/${mathml.dir}"/>
    </target>
  
    <!-- =================================================================== -->
    <!-- Prepares the source code                                            -->
    <!-- =================================================================== -->
    <target name="prepare-src" depends="prepare">
      <!-- copy src files -->
      <copy todir="${build.src}">
        <fileset dir="${src.dir}" 
           excludes="**/Makefile*, **/package.html"/>
      </copy>
      <copy todir="${build.dest}/">
        <fileset dir="${resource.dir}"/>
      </copy>
    </target>
  
    <!-- =================================================================== -->
    <!-- Compiles the source directory                                       -->
    <!-- =================================================================== -->
    <target name="compile" depends="prepare-src">
      <echo message="Compiling the sources "/>
      <!-- create directories -->
      <mkdir dir="${build.dest}"/>
  
      <javac srcdir="${build.src}"
             destdir="${build.dest}"
             debug="${debug}"
             deprecation="${deprecation}"
             optimize="${optimize}"
             excludes=""/>
    </target>
  
    <!-- =================================================================== -->
    <!-- Creates the class package                                           -->
    <!-- =================================================================== -->
    <target name="package" depends="compile">
      <echo message="Creating the jar file ${build.dir}/${name}.jar"/>
      <tstamp>
        <format property="ts" pattern="yyyyMMdd-HHmmss-z"/>
      </tstamp>
  
      <jar jarfile="${build.dir}/${name}.jar"
           basedir="${build.dest}"
           includes="**">
      <manifest> 
          <attribute name="Implementation-Title" value="${Name}"/>
          <attribute name="Implementation-Version" value="${version}"/>
          <attribute name="Implementation-Vendor" value="Apache Software Foundation 
(http://xml.apache.org/fop/)"/>
          <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} 
${os.version} ${os.arch}])"/>
      </manifest>
      </jar>
    </target>
  
    <!-- =================================================================== -->
    <!-- Clean targets                                                       -->
    <!-- =================================================================== -->
    <target name="clean" depends="init">
      <delete dir="${build.dir}"/>
    </target>
  
  </project>
  
  
  
  
  1.1                  xml-fop/contrib/mathml/docs/example.mml
  
  Index: example.mml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
                <math xmlns="http://www.w3.org/1998/Math/MathML"; mode="display">
                        <mrow>
                                <mo stretchy="false">{</mo>
                                <munder>
                                        <mrow>
                                                <mover>
                                                        <mrow>
                                                                <mpadded width="0"/>
                                                                <!--mpadded 
width="0">(</mpadded-->
                                                                <!-- \mathstrut -ugly 
hack a la TeX -->
                                                                <mi>a</mi>
                                                                <mo>,</mo>
                                                                <mo>...</mo>
                                                                <mo>,</mo>
                                                                <mi>a</mi>
                                                        </mrow>
                                                        <mover>
                                                                <mo>&#x0FE37;</mo>
                                                                <mrow>
                                                                        <mi>k</mi>
                                                                        
<mtext>&#x000A0;</mtext>
                                                                        <mi>a</mi>
                                                                        
<mtext>'s</mtext>
                                                                </mrow>
                                                        </mover>
                                                </mover>
                                                <mo>,</mo>
                                                <mover>
                                                        <mrow>
                                                                <mpadded/>
                                                                <!--mpadded 
width="0">(</mpadded-->
                                                                <!-- \mathstrut -ugly 
hack a la TeX -->
                                                                <mi>b</mi>
                                                                <mo>,</mo>
                                                                <mo>...</mo>
                                                                <mo>,</mo>
                                                                <mi>b</mi>
                                                        </mrow>
                                                        <mover>
                                                                <mo>&#x0FE37;</mo>
                                                                <mrow>
                                                                        
<mi>&#x02113;</mi>
                                                                        
<mtext>&#x000A0;</mtext>
                                                                        <mi>b</mi>
                                                                        
<mtext>'s</mtext>
                                                                </mrow>
                                                        </mover>
                                                </mover>
                                        </mrow>
                                        <munder>
                                                <mo>&#x0FE38;</mo>
                                                <mrow>
                                                        <mi>k</mi>
                                                        <mo>+</mo>
                                                        <mi>&#x02113;</mi>
                                                        
<mtext>&#x000A0;elements</mtext>
                                                </mrow>
                                        </munder>
                                </munder>
                                <mo stretchy="false">}</mo>
                        </mrow>
                </math>
  
  
  
  1.1                  xml-fop/contrib/mathml/docs/mathml.fo
  
  Index: mathml.fo
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
    <fo:layout-master-set>
      <fo:simple-page-master
    margin-right="1.5cm"
    margin-left="1.5cm"
    margin-bottom="2cm"
    margin-top="1cm"
    page-width="21cm"
    page-height="29.7cm"
    master-name="first">
        <fo:region-before extent="1cm"/>
        <fo:region-body margin-top="1cm"/>
        <fo:region-after extent="1.5cm"/>
      </fo:simple-page-master>
    </fo:layout-master-set>
  
    <fo:page-sequence master-reference="first">
      <fo:static-content flow-name="xsl-region-before">
        <fo:block line-height="14pt" font-size="10pt"
      text-align="end">Plan Extension</fo:block>
      </fo:static-content>
      <fo:static-content flow-name="xsl-region-after">
        <fo:block line-height="14pt" font-size="10pt"
      text-align="end">Page <fo:page-number/></fo:block>
      </fo:static-content>
  
      <fo:flow flow-name="xsl-region-body">
  
        <fo:block space-before.optimum="3pt" space-after.optimum="15pt">
        The MathML Extension
        </fo:block>
  
        <fo:block space-before.optimum="3pt" space-after.optimum="15pt">
  The mathml extension is an addition to FOP that can be used to draw mathml
  expressions.
        </fo:block>
  
        <fo:block space-before.optimum="3pt" space-after.optimum="15pt">
        Examples
        </fo:block>
  
        <fo:block space-before.optimum="3pt" space-after.optimum="15pt">
  <fo:block space-after.optimum="5pt">
  <fo:instream-foreign-object>
         <math xmlns="http://www.w3.org/1998/Math/MathML"; mode="inline">
            <mrow>
              <mi>I</mi>
              <mrow>
                <mo>(</mo>
                <mi>x</mi>
                <mo>)</mo>
              </mrow>
              <mo>=</mo>
              <mi>F</mi>
              <mo stretchy="false">(</mo>
              <mi>x</mi>
              <mo stretchy="false">)</mo>
              <mo>+</mo>
              <mi>C</mi>
            </mrow>
          </math>
  </fo:instream-foreign-object>
  </fo:block>
        </fo:block>
  
        <fo:block space-before.optimum="3pt" space-after.optimum="15pt">
  <fo:block space-after.optimum="5pt">
  <fo:instream-foreign-object>
      <math xmlns="http://www.w3.org/1998/Math/MathML"; mode="inline">
        <mrow>
          <mo>(</mo>
          <mtable>
            <mtr>
              <mtd columnalign="center">
                <mrow>
                  <mo>(</mo>
                  <mtable>
                    <mtr>
                      <mtd columnalign="center">
                        <mi>a</mi>
                      </mtd>
                      <mtd columnalign="center">
                        <mi>b</mi>
                      </mtd>
                    </mtr>
                    <mtr>
                      <mtd columnalign="center">
                        <mi>c</mi>
                      </mtd>
                      <mtd columnalign="center">
                        <mi>d</mi>
                      </mtd>
                    </mtr>
                  </mtable>
                  <mo>)</mo>
                </mrow>
              </mtd>
              <mtd columnalign="center">
                <mrow>
                  <mo>(</mo>
                  <mtable>
                    <mtr>
                      <mtd columnalign="center">
                        <mi>e</mi>
                      </mtd>
                      <mtd columnalign="center">
                        <mi>f</mi>
                      </mtd>
                    </mtr>
                    <mtr>
                      <mtd columnalign="center">
                        <mi>g</mi>
                      </mtd>
                      <mtd columnalign="center">
                        <mi>h</mi>
                      </mtd>
                    </mtr>
                  </mtable>
                  <mo>)</mo>
                </mrow>
              </mtd>
            </mtr>
            <mtr>
              <mtd columnalign="center">
                <mn>0</mn>
              </mtd>
              <mtd columnalign="center">
                <mrow>
                  <mo>(</mo>
                  <mtable>
                    <mtr>
                      <mtd columnalign="center">
                        <mi>i</mi>
                      </mtd>
                      <mtd columnalign="center">
                        <mi>j</mi>
                      </mtd>
                    </mtr>
                    <mtr>
                      <mtd columnalign="center">
                        <mi>k</mi>
                      </mtd>
                      <mtd columnalign="center">
                        <mi>l</mi>
                      </mtd>
                    </mtr>
                  </mtable>
                  <mo>)</mo>
                </mrow>
              </mtd>
            </mtr>
          </mtable>
          <mo>)</mo>
        </mrow>
      </math>
  
  </fo:instream-foreign-object>
  </fo:block>
  </fo:block>
  
        <fo:block>
  An external mathml document.
        </fo:block>
  
        <fo:block>
  <fo:external-graphic src="example.mml"/>
        </fo:block>
      </fo:flow>
    </fo:page-sequence>
  </fo:root>
  
  
  
  
  1.1                  xml-fop/contrib/mathml/lib/readme.txt
  
  Index: readme.txt
  ===================================================================
  Put jeuclid.jar in this directory!
  
  
  
  1.1                  
xml-fop/contrib/mathml/resources/META-INF/services/org.apache.fop.fo.ElementMapping
  
  Index: org.apache.fop.fo.ElementMapping
  ===================================================================
  org.apache.fop.mathml.MathMLElementMapping
  
  
  
  
  1.1                  
xml-fop/contrib/mathml/src/org/apache/fop/mathml/MathMLElement.java
  
  Index: MathMLElement.java
  ===================================================================
  /* $Id: MathMLElement.java,v 1.1 2002/04/23 10:26:46 keiron Exp $
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.mathml;
  
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.geom.Point2D;
  
  import org.apache.fop.fo.FONode;
  import org.apache.fop.apps.FOPException;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.*;
  import org.xml.sax.Attributes;
  
  import org.apache.batik.svggen.SVGGraphics2D;
  import org.apache.batik.dom.svg.SVGDOMImplementation;
  
  import net.sourceforge.jeuclid.MathBase;
  import net.sourceforge.jeuclid.DOMMathBuilder;
  
  public class MathMLElement extends MathMLObj {
      Document svgDoc = null;
      float width;
      float height;
      boolean converted = false;
  
      public MathMLElement(FONode parent) {
          super(parent);
      }
  
      public void handleAttrs(Attributes attlist) throws FOPException {
          super.handleAttrs(attlist);
          createBasicDocument();
      }
  
      public void convertToSVG() {
          try {
              if (!converted) {
                  converted = true;
                  String fontname = "Helvetica";
                  int fontstyle = 0;
                  int inlinefontstyle = 0;
                  int displayfontsize = 12;
                  int inlinefontsize = 12;
  
                  MathBase base = new MathBase(
                                    (new DOMMathBuilder(doc)).getMathRootElement(),
                                    fontname, fontstyle, inlinefontsize,
                                    displayfontsize);
  
                  base.setDebug(false);
  
                  svgDoc = createSVG(base);
  
                  width = base.getWidth();
                  height = base.getHeight();
  
                  doc = svgDoc;
              }
          } catch (Throwable t) {
              log.error("Could not convert MathML to SVG", t);
              width = 0;
              height = 0;
          }
  
      }
  
      public static Document createSVG(MathBase base) {
  
          DOMImplementation impl =
            SVGDOMImplementation.getDOMImplementation();
          String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
          Document svgdocument = impl.createDocument(svgNS, "svg", null);
  
          SVGGraphics2D g = new SVGGraphics2D(svgdocument);
  
          g.setSVGCanvasSize(
            new Dimension(base.getWidth(), base.getHeight()));
  
          //g.setColor(Color.white);
          //g.fillRect(0, 0, base.getWidth(), base.getHeight());
          g.setColor(Color.black);
  
          base.paint(g);
  
          //if (antialiasing)
          //element.setAttribute("text-rendering", "optimizeLegibility");
          //else
          //element.setAttribute("text-rendering", "geometricPrecision");
  
          // this should be done in a better way
          Element root = g.getRoot();
          svgdocument = impl.createDocument(svgNS, "svg", null);
          Node node = svgdocument.importNode(root, true);
          ((org.apache.batik.dom.svg.SVGOMDocument) svgdocument).
          getRootElement().appendChild(node);
  
          return svgdocument;
  
      }
  
      public Document getDocument() {
          convertToSVG();
          return doc;
      }
  
      public String getDocumentNamespace() {
          if (svgDoc == null) {
              return MathMLElementMapping.URI;
          }
          return "http://www.w3.org/2000/svg";;
      }
  
      public Point2D getDimension(Point2D view) {
          convertToSVG();
          return new Point2D.Float(width, height);
      }
  }
  
  
  
  
  1.1                  
xml-fop/contrib/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java
  
  Index: MathMLElementMapping.java
  ===================================================================
  /* $Id: MathMLElementMapping.java,v 1.1 2002/04/23 10:26:46 keiron Exp $
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.mathml;
  
  import org.apache.fop.fo.FOTreeBuilder;
  import org.apache.fop.fo.FONode;
  import org.apache.fop.fo.ElementMapping;
  import org.apache.fop.image.analyser.XMLReader;
  import org.apache.fop.image.FopImage;
  import org.w3c.dom.Document;
  
  import java.util.HashMap;
  
  import net.sourceforge.jeuclid.MathBase;
  import net.sourceforge.jeuclid.DOMMathBuilder;
  
  public class MathMLElementMapping implements ElementMapping {
  
      public static final String URI = "http://www.w3.org/1998/Math/MathML";;
  
      private static HashMap foObjs = null;
  
      private static synchronized void setupMathML() {
          if (foObjs == null) {
              foObjs = new HashMap();
              foObjs.put("math", new ME());
              foObjs.put(DEFAULT, new MathMLMaker());
  
              XMLReader.setConverter(URI, new MathMLConverter());
          }
      }
  
      public void addToBuilder(FOTreeBuilder builder) {
          setupMathML();
          builder.addMapping(URI, foObjs);
      }
  
      static class MathMLMaker extends ElementMapping.Maker {
          public FONode make(FONode parent) {
              return new MathMLObj(parent);
          }
      }
  
      static class ME extends ElementMapping.Maker {
          public FONode make(FONode parent) {
              return new MathMLElement(parent);
          }
      }
  
      static class MathMLConverter implements XMLReader.Converter {
          public FopImage.ImageInfo convert(Document doc) {
              try {
                  FopImage.ImageInfo info = new FopImage.ImageInfo();
                  String fontname = "Helvetica";
                  int fontstyle = 0;
                  int inlinefontstyle = 0;
                  int inlinefontsize = 12;
                  int displayfontsize = 12;
  
                  MathBase base = new MathBase(
                                    (new DOMMathBuilder(doc)).getMathRootElement(),
                                    fontname, fontstyle, inlinefontsize,
                                    displayfontsize);
  
                  base.setDebug(false);
  
                  info.data = MathMLElement.createSVG(base);
  
                  info.width = base.getWidth();
                  info.height = base.getHeight();
  
                  info.mimeType = "image/svg+xml";
                  info.str = "http://www.w3.org/2000/svg";;
  
                  return info;
              } catch (Throwable t) {
              }
              return null;
  
          }
      }
  
  }
  
  
  
  1.1                  xml-fop/contrib/mathml/src/org/apache/fop/mathml/MathMLObj.java
  
  Index: MathMLObj.java
  ===================================================================
  /* $Id: MathMLObj.java,v 1.1 2002/04/23 10:26:46 keiron Exp $
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.mathml;
  
  // FOP
  import org.apache.fop.fo.FONode;
  import org.apache.fop.fo.XMLObj;
  
  /**
   * Catch all MathML object as default element.
   */
  public class MathMLObj extends XMLObj {
  
      public MathMLObj(FONode parent) {
          super(parent);
      }
  
      public String getNameSpace() {
          return MathMLElementMapping.URI;
      }
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to