I have been working with very recent SVN/CVS versions of FOP, Batik
and JEuclid.  I have embedded a small fragment of MathML in an XSL-FO
document (actually output from Docbook source by xsltproc):

<fo:instream-foreign-object>
<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML";
overflow="scroll">
          <mml:mrow>
            <mml:mo>∑</mml:mo>
            <mml:mn>4</mml:mn>
            <mml:mo>+</mml:mo>
            <mml:mi>x</mml:mi>
          </mml:mrow>
        </mml:math>
</fo:instream-foreign-object>

I needed two patches to the examples/mathml directory to get this to
work:

First, the constructor for MathBase and DOMMathBuilder have changed in
recent JEuclid (fop-svn-jeuclid-svn.patch).

Secondly, the scaling of the image is completely wrong, because of the
extreme complexity of the dimension handling.  I have found great
difficulty
in understanding this because of the levels of nesting, the interaction
of
JEuclid, Batik and FOP, and the fact that attributes such as height and
width
are copied so frequently from one object to another.  Width and height
seem to come from two different sources which are inconsistent.

The size of the viewport seems to come from
InstreamForeignObject.prepareIntrinsicSize(), which calls
MathMLElement.getDimension(), which calls MathMLElement.convertToSVG()
which calls MathBase.getWidth() and MathBase.getHeight().  This seems
to be the actual extent of the rendered text.

However, later in Batik's SVGSVGElementBridge.createGraphicsNode(),
the "width" and "height" attributes are read from the SVG document:
float w = se.getWidth().getAnimVal().getValue() etc.  I found that
while the actual size of the math text was 48x10 points, the w
and h here were 100x100 - this seems to be a default value.
As a result the math was squashed by a factor of 0.48x0.1 - not what
I want.

It appears that this happens because the MathMLElement class in
FOP's examples/mathml directory does not place the generated <svg>
element at the root of the SVG document, but places it as a child of
ANOTHER <svg> element.  Therefore the "width"/"height" attributes are
not processed by Batik.  There is a comment in MathMLElement.java to
the effect that "this should be done in a better way".  This patch
puts the generated node at the root where it should be, and makes
the text the right size (fop-svn-mathml-root.patch).

I hope that my analysis may be of interest to anyone working on the
FOP/JEuclid integration.

Peter

diff -u -r fop-svn-old/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java fop-svn/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java
--- fop-svn-old/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java	2006-09-20 20:12:33.000000000 +0100
+++ fop-svn/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java	2006-09-20 20:14:28.000000000 +0100
@@ -20,9 +20,12 @@
 package org.apache.fop.mathml;
 
 import java.awt.Color;
+import java.awt.Font;
 import java.awt.Dimension;
 import java.awt.geom.Point2D;
 
+import org.apache.avalon.framework.logger.ConsoleLogger;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.PropertyList;
@@ -81,10 +84,9 @@
                 int displayfontsize = 12;
                 int inlinefontsize = 12;
 
-                MathBase base = new MathBase(
-                                  (new DOMMathBuilder(doc)).getMathRootElement(),
-                                  fontname, fontstyle, inlinefontsize,
-                                  displayfontsize);
+                MathBase base = new MathBase(new Font(fontname, fontstyle, inlinefontsize));
+
+		new DOMMathBuilder(doc, new ConsoleLogger(), base);
 
                 base.setDebug(false);
 
diff -u -r fop-svn-old/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java fop-svn/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java
--- fop-svn-old/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java	2006-09-20 20:12:33.000000000 +0100
+++ fop-svn/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java	2006-09-20 20:14:20.000000000 +0100
@@ -19,6 +19,10 @@
  
 package org.apache.fop.mathml;
 
+import java.awt.Font;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.image.analyser.XMLReader;
@@ -82,10 +86,9 @@
                 int inlinefontsize = 12;
                 int displayfontsize = 12;
 
-                MathBase base = new MathBase(
-                                  (new DOMMathBuilder(doc)).getMathRootElement(),
-                                  fontname, fontstyle, inlinefontsize,
-                                  displayfontsize);
+                MathBase base = new MathBase(new Font(fontname, fontstyle, inlinefontsize));
+
+		new DOMMathBuilder(doc, new ConsoleLogger(), base);
 
                 base.setDebug(false);
 
diff -u -r fop-svn-old/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java fop-svn/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java
--- fop-svn-old/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java	2006-09-20 20:15:44.000000000 +0100
+++ fop-svn/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java	2006-09-20 20:16:56.000000000 +0100
@@ -43,6 +43,10 @@
 import net.sourceforge.jeuclid.MathBase;
 import net.sourceforge.jeuclid.DOMMathBuilder;
 
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+import org.apache.batik.dom.util.DOMUtilities;
+
 /**
  * Defines the top-level element for MathML.
  */
@@ -134,10 +138,9 @@
 
         // this should be done in a better way
         Element root = g.getRoot();
-        svgdocument = impl.createDocument(svgNS, "svg", null);
+        svgdocument = impl.createDocument(svgNS, null, null);
         Node node = svgdocument.importNode(root, true);
-        ((org.apache.batik.dom.svg.SVGOMDocument) svgdocument).
-        getRootElement().appendChild(node);
+	svgdocument.appendChild(node);
 
         return svgdocument;
 

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to