diff options
author | Jeremias Maerki <jeremias@apache.org> | 2003-01-29 16:25:25 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2003-01-29 16:25:25 +0000 |
commit | 3bb877507c6bbeb32ca72d0aa2196f2203e6de09 (patch) | |
tree | fe9a69b9d2421583735732462c3fe27ca8153677 /examples/mathml | |
parent | 5b2e97ba5b0fc57ba7e5edf1acdba8da31065eef (diff) | |
download | xmlgraphics-fop-3bb877507c6bbeb32ca72d0aa2196f2203e6de09.tar.gz xmlgraphics-fop-3bb877507c6bbeb32ca72d0aa2196f2203e6de09.zip |
Move over from contrib/mathml
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195908 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'examples/mathml')
-rw-r--r-- | examples/mathml/.cvsignore | 1 | ||||
-rw-r--r-- | examples/mathml/README | 10 | ||||
-rwxr-xr-x | examples/mathml/build.bat | 35 | ||||
-rw-r--r-- | examples/mathml/build.sh | 30 | ||||
-rw-r--r-- | examples/mathml/build.xml | 139 | ||||
-rw-r--r-- | examples/mathml/docs/example.mml | 63 | ||||
-rw-r--r-- | examples/mathml/docs/mathml.fo | 172 | ||||
-rw-r--r-- | examples/mathml/lib/readme.txt | 1 | ||||
-rw-r--r-- | examples/mathml/resources/META-INF/services/org.apache.fop.fo.ElementMapping | 2 | ||||
-rw-r--r-- | examples/mathml/src/org/apache/fop/mathml/MathMLElement.java | 124 | ||||
-rw-r--r-- | examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java | 87 | ||||
-rw-r--r-- | examples/mathml/src/org/apache/fop/mathml/MathMLObj.java | 26 |
12 files changed, 690 insertions, 0 deletions
diff --git a/examples/mathml/.cvsignore b/examples/mathml/.cvsignore new file mode 100644 index 000000000..378eac25d --- /dev/null +++ b/examples/mathml/.cvsignore @@ -0,0 +1 @@ +build diff --git a/examples/mathml/README b/examples/mathml/README new file mode 100644 index 000000000..72860b124 --- /dev/null +++ b/examples/mathml/README @@ -0,0 +1,10 @@ +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. + diff --git a/examples/mathml/build.bat b/examples/mathml/build.bat new file mode 100755 index 000000000..96aa30a7f --- /dev/null +++ b/examples/mathml/build.bat @@ -0,0 +1,35 @@ +@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
\ No newline at end of file diff --git a/examples/mathml/build.sh b/examples/mathml/build.sh new file mode 100644 index 000000000..986d3c1e3 --- /dev/null +++ b/examples/mathml/build.sh @@ -0,0 +1,30 @@ +#!/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 $* diff --git a/examples/mathml/build.xml b/examples/mathml/build.xml new file mode 100644 index 000000000..78e84b514 --- /dev/null +++ b/examples/mathml/build.xml @@ -0,0 +1,139 @@ +<?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> + diff --git a/examples/mathml/docs/example.mml b/examples/mathml/docs/example.mml new file mode 100644 index 000000000..0f04968c2 --- /dev/null +++ b/examples/mathml/docs/example.mml @@ -0,0 +1,63 @@ +<?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> diff --git a/examples/mathml/docs/mathml.fo b/examples/mathml/docs/mathml.fo new file mode 100644 index 000000000..a5ff53f26 --- /dev/null +++ b/examples/mathml/docs/mathml.fo @@ -0,0 +1,172 @@ +<?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> + diff --git a/examples/mathml/lib/readme.txt b/examples/mathml/lib/readme.txt new file mode 100644 index 000000000..9166db6f7 --- /dev/null +++ b/examples/mathml/lib/readme.txt @@ -0,0 +1 @@ +Put jeuclid.jar in this directory! diff --git a/examples/mathml/resources/META-INF/services/org.apache.fop.fo.ElementMapping b/examples/mathml/resources/META-INF/services/org.apache.fop.fo.ElementMapping new file mode 100644 index 000000000..406a8319a --- /dev/null +++ b/examples/mathml/resources/META-INF/services/org.apache.fop.fo.ElementMapping @@ -0,0 +1,2 @@ +org.apache.fop.mathml.MathMLElementMapping + diff --git a/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java b/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java new file mode 100644 index 000000000..066b7b54c --- /dev/null +++ b/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java @@ -0,0 +1,124 @@ +/* $Id$ + * 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); + } +} + diff --git a/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java b/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java new file mode 100644 index 000000000..f1f2b0fd3 --- /dev/null +++ b/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java @@ -0,0 +1,87 @@ +/* $Id$ + * 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; + + } + } + +} diff --git a/examples/mathml/src/org/apache/fop/mathml/MathMLObj.java b/examples/mathml/src/org/apache/fop/mathml/MathMLObj.java new file mode 100644 index 000000000..f7f8d82ca --- /dev/null +++ b/examples/mathml/src/org/apache/fop/mathml/MathMLObj.java @@ -0,0 +1,26 @@ +/* $Id$ + * 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; + } +} + |