jeremias 2003/01/29 08:25:25 Added: examples/mathml .cvsignore README build.bat build.sh build.xml examples/mathml/docs example.mml mathml.fo examples/mathml/lib readme.txt examples/mathml/resources/META-INF/services org.apache.fop.fo.ElementMapping examples/mathml/src/org/apache/fop/mathml MathMLElement.java MathMLElementMapping.java MathMLObj.java Log: Move over from contrib/mathml Revision Changes Path 1.1 xml-fop/examples/mathml/.cvsignore Index: .cvsignore =================================================================== build 1.1 xml-fop/examples/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 CML into SVG. The SVG is then handled as normal. 1.1 xml-fop/examples/mathml/build.bat Index: build.bat =================================================================== @echo off echo MathML Build System echo --------------------- if "%JAVA_HOME%" == "" goto error set LIBDIR=..\..\lib set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\ant.jar set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xml-apis.jar set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xercesImpl-2.2.1.jar set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xalan-2.4.1.jar set ANT_HOME=%LIBDIR% echo Building with classpath %LOCALCLASSPATH% echo Starting Ant... %JAVA_HOME%\bin\java.exe -Dant.home=%ANT_HOME% -classpath "%LOCALCLASSPATH%" org.apache.tools.ant.Main %1 %2 %3 %4 %5 goto end :error echo ERROR: JAVA_HOME not found in your environment. echo Please, set the JAVA_HOME variable in your environment to match the echo location of the Java Virtual Machine you want to use. :end rem set LOCALCLASSPATH= pause 1.1 xml-fop/examples/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 LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/ant.jar LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/xml-apis.jar LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/xercesImpl-2.2.1.jar LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/xalan-2.4.1.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/examples/mathml/build.xml Index: build.xml =================================================================== <?xml version="1.0"?> <!-- =========================================================================== ============================================================================ --> <project default="package" basedir="."> <path id="libs-build-classpath"> <fileset dir="../../lib"> <include name="*.jar"/> </fileset> <fileset dir="../../build"> <include name="fop.jar"/> </fileset> <fileset dir="lib"> <include name="*.jar"/> </fileset> </path> <!-- =================================================================== --> <!-- 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="on"/> <property name="optimize" value="off"/> <property name="deprecation" value="on"/> <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"/> <available property="jeuclid.present" classname="net.sourceforge.jeuclid.MathBase" classpathref="libs-build-classpath"/> </target> <target name="jeuclid-check" depends="init" unless="jeuclid.present"> <echo message="============================================================================="/> <echo message="jeuclid.jar is missing in the lib directory."/> <echo message="You can download it at: http://sourceforge.net/projects/jeuclid/"/> <echo message="============================================================================="/> <fail message="Dependecy check failed."/> </target> <!-- =================================================================== --> <!-- Help on usage --> <!-- =================================================================== --> <target name="usage"> <echo message="Use the -projecthelp option instead"/> </target> <!-- =================================================================== --> <!-- Prepares the build directory --> <!-- =================================================================== --> <target name="prepare" depends="init, jeuclid-check"> <!-- 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" description="Compile the Java sources"> <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=""> <classpath refid="libs-build-classpath"/> </javac> </target> <!-- =================================================================== --> <!-- Creates the class package --> <!-- =================================================================== --> <target name="package" depends="compile" description="Create jar file"> <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" description="Cleans the build directory"> <delete dir="${build.dir}"/> </target> </project> 1.1 xml-fop/examples/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>︷</mo> <mrow> <mi>k</mi> <mtext> </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>︷</mo> <mrow> <mi>ℓ</mi> <mtext> </mtext> <mi>b</mi> <mtext>'s</mtext> </mrow> </mover> </mover> </mrow> <munder> <mo>︸</mo> <mrow> <mi>k</mi> <mo>+</mo> <mi>ℓ</mi> <mtext> elements</mtext> </mrow> </munder> </munder> <mo stretchy="false">}</mo> </mrow> </math> 1.1 xml-fop/examples/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/examples/mathml/lib/readme.txt Index: readme.txt =================================================================== Put jeuclid.jar in this directory! 1.1 xml-fop/examples/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/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java Index: MathMLElement.java =================================================================== /* $Id: MathMLElement.java,v 1.1 2003/01/29 16:25:25 jeremias 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) { userAgent.getLogger().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/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java Index: MathMLElementMapping.java =================================================================== /* $Id: MathMLElementMapping.java,v 1.1 2003/01/29 16:25:25 jeremias 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/examples/mathml/src/org/apache/fop/mathml/MathMLObj.java Index: MathMLObj.java =================================================================== /* $Id: MathMLObj.java,v 1.1 2003/01/29 16:25:25 jeremias 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]