From cc2a5e8e3c2059b96df89497cb00c3d5a2583d15 Mon Sep 17 00:00:00 2001 From: Maximilian Berger Date: Wed, 21 Jan 2009 11:59:20 +0000 Subject: Removed MathML example as per discussion on fop-dev mailing list git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@736295 13f79535-47bb-0310-9956-ffa450edef68 --- examples/mathml/README | 21 +-- examples/mathml/build.xml | 155 ----------------- examples/mathml/docs/example.mml | 63 ------- examples/mathml/docs/mathml.fo | 172 ------------------- examples/mathml/lib/readme.txt | 1 - .../services/org.apache.fop.fo.ElementMapping | 2 - ...xmlgraphics.image.loader.spi.ImageLoaderFactory | 1 - ...che.xmlgraphics.image.loader.spi.ImagePreloader | 1 - .../fop/mathml/ImageLoaderFactoryMathML.java | 66 ------- .../org/apache/fop/mathml/ImageLoaderMathML.java | 71 -------- .../src/org/apache/fop/mathml/MathMLElement.java | 163 ------------------ .../apache/fop/mathml/MathMLElementMapping.java | 68 -------- .../src/org/apache/fop/mathml/MathMLObj.java | 48 ------ .../src/org/apache/fop/mathml/PreloaderMathML.java | 189 --------------------- 14 files changed, 5 insertions(+), 1016 deletions(-) delete mode 100644 examples/mathml/build.xml delete mode 100644 examples/mathml/docs/example.mml delete mode 100644 examples/mathml/docs/mathml.fo delete mode 100644 examples/mathml/lib/readme.txt delete mode 100644 examples/mathml/resources/META-INF/services/org.apache.fop.fo.ElementMapping delete mode 100644 examples/mathml/resources/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory delete mode 100644 examples/mathml/resources/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader delete mode 100644 examples/mathml/src/org/apache/fop/mathml/ImageLoaderFactoryMathML.java delete mode 100644 examples/mathml/src/org/apache/fop/mathml/ImageLoaderMathML.java delete mode 100644 examples/mathml/src/org/apache/fop/mathml/MathMLElement.java delete mode 100644 examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java delete mode 100644 examples/mathml/src/org/apache/fop/mathml/MathMLObj.java delete mode 100644 examples/mathml/src/org/apache/fop/mathml/PreloaderMathML.java (limited to 'examples') diff --git a/examples/mathml/README b/examples/mathml/README index 93474086d..9455ef859 100644 --- a/examples/mathml/README +++ b/examples/mathml/README @@ -1,21 +1,10 @@ FOP MathML Readme -This directory contains an extension for MathML that can be used with FOP. +The MathML extension is now maintained by the JEuclid project: -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. +http://jeuclid.sourceforge.net/jeuclid-fop/ -Building the MathML extension: -To build the MathML extension, please download JEuclid using the link above. -Put the jeuclid.jar into the lib directory and run the Ant build script in -this directory. +Further information: -Usage: -When you've built the MathML extension, add jeuclid.jar and -build/mathml-fop.jar to the classpath used when running FOP. You can then -simply use MathML directly in fo:instream-foreign-object elements or -reference a MathML file in fo:external-graphic elements as shown in -the demo file: docs/mathml.fo \ No newline at end of file +http://jeuclid.sourceforge.net/ +http://sourceforge.net/projects/jeuclid/ diff --git a/examples/mathml/build.xml b/examples/mathml/build.xml deleted file mode 100644 index c24c06b24..000000000 --- a/examples/mathml/build.xml +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/mathml/docs/example.mml b/examples/mathml/docs/example.mml deleted file mode 100644 index 0f04968c2..000000000 --- a/examples/mathml/docs/example.mml +++ /dev/null @@ -1,63 +0,0 @@ - - - - { - - - - - - - - a - , - ... - , - a - - - - - k -   - a - 's - - - - , - - - - - - b - , - ... - , - b - - - - - -   - b - 's - - - - - - - - k - + - -  elements - - - - } - - diff --git a/examples/mathml/docs/mathml.fo b/examples/mathml/docs/mathml.fo deleted file mode 100644 index e5707b6bd..000000000 --- a/examples/mathml/docs/mathml.fo +++ /dev/null @@ -1,172 +0,0 @@ - - - - - - - - - - - - - MathML Extension - - - Page - - - - - - The MathML Extension - - - -The mathml extension is an addition to FOP that can be used to draw mathml -expressions. - - - - Examples - - - - - - - - I - - ( - x - ) - - = - F - ( - x - ) - + - C - - - - - - - - - - - - ( - - - - - ( - - - - a - - - b - - - - - c - - - d - - - - ) - - - - - ( - - - - e - - - f - - - - - g - - - h - - - - ) - - - - - - 0 - - - - ( - - - - i - - - j - - - - - k - - - l - - - - ) - - - - - ) - - - - - - - - -An external mathml document. - - - - - - - - - diff --git a/examples/mathml/lib/readme.txt b/examples/mathml/lib/readme.txt deleted file mode 100644 index 9166db6f7..000000000 --- a/examples/mathml/lib/readme.txt +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 406a8319a..000000000 --- a/examples/mathml/resources/META-INF/services/org.apache.fop.fo.ElementMapping +++ /dev/null @@ -1,2 +0,0 @@ -org.apache.fop.mathml.MathMLElementMapping - diff --git a/examples/mathml/resources/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory b/examples/mathml/resources/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory deleted file mode 100644 index ab58234d4..000000000 --- a/examples/mathml/resources/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory +++ /dev/null @@ -1 +0,0 @@ -org.apache.fop.mathml.ImageLoaderFactoryMathML diff --git a/examples/mathml/resources/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader b/examples/mathml/resources/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader deleted file mode 100644 index 870684c8f..000000000 --- a/examples/mathml/resources/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader +++ /dev/null @@ -1 +0,0 @@ -org.apache.fop.mathml.PreloaderMathML diff --git a/examples/mathml/src/org/apache/fop/mathml/ImageLoaderFactoryMathML.java b/examples/mathml/src/org/apache/fop/mathml/ImageLoaderFactoryMathML.java deleted file mode 100644 index cac43c721..000000000 --- a/examples/mathml/src/org/apache/fop/mathml/ImageLoaderFactoryMathML.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.mathml; - -import org.apache.xmlgraphics.image.loader.ImageFlavor; -import org.apache.xmlgraphics.image.loader.impl.AbstractImageLoaderFactory; -import org.apache.xmlgraphics.image.loader.spi.ImageLoader; - -/** - * Factory class for the ImageLoader for MathML. - */ -public class ImageLoaderFactoryMathML extends AbstractImageLoaderFactory { - - /** MathML MIME type */ - public static final String MIME_MATHML = "text/mathml"; - - private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { - ImageFlavor.GRAPHICS2D}; - - private static final String[] MIMES = new String[] { - MIME_MATHML}; - - /** {@inheritDoc} */ - public String[] getSupportedMIMETypes() { - return MIMES; - } - - /** {@inheritDoc} */ - public ImageFlavor[] getSupportedFlavors(String mime) { - return FLAVORS; - } - - /** {@inheritDoc} */ - public ImageLoader newImageLoader(ImageFlavor targetFlavor) { - return new ImageLoaderMathML(targetFlavor); - } - - /** {@inheritDoc} */ - public int getUsagePenalty(String mime, ImageFlavor flavor) { - return 0; - } - - /** {@inheritDoc} */ - public boolean isAvailable() { - //TODO Refine! - return true; - } - -} diff --git a/examples/mathml/src/org/apache/fop/mathml/ImageLoaderMathML.java b/examples/mathml/src/org/apache/fop/mathml/ImageLoaderMathML.java deleted file mode 100644 index d110ca3dc..000000000 --- a/examples/mathml/src/org/apache/fop/mathml/ImageLoaderMathML.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.mathml; - -import java.io.IOException; -import java.util.Map; - -import org.apache.xmlgraphics.image.loader.Image; -import org.apache.xmlgraphics.image.loader.ImageException; -import org.apache.xmlgraphics.image.loader.ImageFlavor; -import org.apache.xmlgraphics.image.loader.ImageInfo; -import org.apache.xmlgraphics.image.loader.ImageSessionContext; -import org.apache.xmlgraphics.image.loader.impl.AbstractImageLoader; -import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; - -/** - * ImageLoader for MathML (using JEuclid). - */ -public class ImageLoaderMathML extends AbstractImageLoader { - - private ImageFlavor targetFlavor; - - /** - * Main constructor. - * @param targetFlavor the target flavor - */ - public ImageLoaderMathML(ImageFlavor targetFlavor) { - if (!(ImageFlavor.GRAPHICS2D.equals(targetFlavor))) { - throw new IllegalArgumentException("Unsupported target ImageFlavor: " + targetFlavor); - } - this.targetFlavor = targetFlavor; - } - - /** {@inheritDoc} */ - public ImageFlavor getTargetFlavor() { - return this.targetFlavor; - } - - /** {@inheritDoc} */ - public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session) - throws ImageException, IOException { - if (!ImageLoaderFactoryMathML.MIME_MATHML.equals(info.getMimeType())) { - throw new IllegalArgumentException("ImageInfo must be from an MathML image"); - } - Image img = info.getOriginalImage(); - if (!(img instanceof ImageGraphics2D)) { - throw new IllegalArgumentException( - "ImageInfo was expected to contain the MathML document as Graphics2D image"); - } - ImageGraphics2D g2dImage = (ImageGraphics2D)img; - return g2dImage; - } - -} diff --git a/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java b/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java deleted file mode 100644 index 9bd326f2b..000000000 --- a/examples/mathml/src/org/apache/fop/mathml/MathMLElement.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.mathml; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.geom.Point2D; - -import net.sourceforge.jeuclid.DOMMathBuilder; -import net.sourceforge.jeuclid.MathBase; - -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import org.xml.sax.Attributes; -import org.xml.sax.Locator; - -import org.apache.batik.dom.svg.SVGDOMImplementation; -import org.apache.batik.svggen.SVGGraphics2D; - -import org.apache.fop.apps.FOPException; -import org.apache.fop.fo.FONode; -import org.apache.fop.fo.PropertyList; - -/** - * Defines the top-level element for MathML. - */ -public class MathMLElement extends MathMLObj { - - private Document svgDoc = null; - private float width; - private float height; - private boolean converted = false; - - /** - * @see org.apache.fop.fo.FONode#FONode(FONode) - */ - public MathMLElement(FONode parent) { - super(parent); - } - - /** {@inheritDoc} */ - public void processNode(String elementName, - Locator locator, - Attributes attlist, - PropertyList propertyList) throws FOPException { - super.processNode(elementName, locator, attlist, propertyList); - createBasicDocument(); - } - - /** - * Converts the MathML to SVG. - */ - 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) { - getLogger().error("Could not convert MathML to SVG", t); - width = 0; - height = 0; - } - - } - - /** - * Create the SVG from MathML. - * @param base the root element - * @return the DOM document containing SVG - */ - 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; - - } - - /** {@inheritDoc} */ - public Document getDOMDocument() { - convertToSVG(); - return doc; - } - - /** {@inheritDoc} */ - public String getNamespaceURI() { - if (svgDoc == null) { - return MathMLElementMapping.NAMESPACE; - } - return "http://www.w3.org/2000/svg"; - } - - /** {@inheritDoc} */ - 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 deleted file mode 100644 index c9854d1c7..000000000 --- a/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.mathml; - -import java.util.HashMap; - -import org.w3c.dom.DOMImplementation; - -import org.apache.fop.fo.ElementMapping; -import org.apache.fop.fo.FONode; - -/** - * This class provides the element mapping for FOP. - */ -public class MathMLElementMapping extends ElementMapping { - - /** MathML Namespace */ - public static final String NAMESPACE = "http://www.w3.org/1998/Math/MathML"; - - /** Main constructor. */ - public MathMLElementMapping() { - this.namespaceURI = NAMESPACE; - } - - /** {@inheritDoc} */ - public DOMImplementation getDOMImplementation() { - return getDefaultDOMImplementation(); - } - - /** {@inheritDoc} */ - protected void initialize() { - if (foObjs == null) { - foObjs = new HashMap(); - foObjs.put("math", new ME()); - foObjs.put(DEFAULT, new MathMLMaker()); - } - } - - 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); - } - } - -} diff --git a/examples/mathml/src/org/apache/fop/mathml/MathMLObj.java b/examples/mathml/src/org/apache/fop/mathml/MathMLObj.java deleted file mode 100644 index f2f5317e3..000000000 --- a/examples/mathml/src/org/apache/fop/mathml/MathMLObj.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.mathml; - -// FOP -import org.apache.fop.fo.FONode; -import org.apache.fop.fo.XMLObj; - -/** - * Catch all MathML objects as default element. - */ -public class MathMLObj extends XMLObj { - - /** - * @see org.apache.fop.fo.FONode#FONode(FONode) - */ - public MathMLObj(FONode parent) { - super(parent); - } - - /** {@inheritDoc} */ - public String getNamespaceURI() { - return MathMLElementMapping.NAMESPACE; - } - - /** {@inheritDoc} */ - public String getNormalNamespacePrefix() { - return "mathml"; - } -} - diff --git a/examples/mathml/src/org/apache/fop/mathml/PreloaderMathML.java b/examples/mathml/src/org/apache/fop/mathml/PreloaderMathML.java deleted file mode 100644 index 193ccf6e3..000000000 --- a/examples/mathml/src/org/apache/fop/mathml/PreloaderMathML.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.mathml; - -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.io.InputStream; - -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.sax.SAXResult; -import javax.xml.transform.stream.StreamSource; - -import net.sourceforge.jeuclid.MathBase; -import net.sourceforge.jeuclid.SAXMathBuilder; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.xmlgraphics.image.loader.Image; -import org.apache.xmlgraphics.image.loader.ImageContext; -import org.apache.xmlgraphics.image.loader.ImageInfo; -import org.apache.xmlgraphics.image.loader.ImageSize; -import org.apache.xmlgraphics.image.loader.impl.AbstractImagePreloader; -import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; -import org.apache.xmlgraphics.image.loader.util.ImageUtil; -import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; - -import org.apache.fop.util.UnclosableInputStream; - -/** - * Image preloader for MathML images. - */ -public class PreloaderMathML extends AbstractImagePreloader { - - /** Logger instance */ - private static Log log = LogFactory.getLog(PreloaderMathML.class); - - private boolean jeuclidAvailable = true; - - /** {@inheritDoc} */ - public ImageInfo preloadImage(String uri, Source src, ImageContext context) - throws IOException { - if (!ImageUtil.hasInputStream(src)) { - //TODO Remove this and support DOMSource and possibly SAXSource - return null; - } - ImageInfo info = null; - if (jeuclidAvailable) { - try { - Loader loader = new Loader(); - info = loader.getImage(uri, src, context); - } catch (NoClassDefFoundError e) { - jeuclidAvailable = false; - log.warn("JEuclid not in class path", e); - return null; - } - } - if (info != null) { - ImageUtil.closeQuietly(src); //Image is fully read - } - return info; - } - - /** - * This method is put in another class so that the class loader does not - * attempt to load JEuclid related classes when constructing the MathMLPreloader - * class. - */ - class Loader { - - private ImageInfo getImage(String uri, Source src, ImageContext context) { - - InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src)); - try { - int length = in.available(); - in.mark(length + 1); - - TransformerFactory tFactory = TransformerFactory.newInstance(); - Transformer transformer = tFactory.newTransformer(); - Source source = new StreamSource(in); - SAXMathBuilder mathBuilder = new SAXMathBuilder(); - SAXResult res = new SAXResult(mathBuilder); - transformer.transform(source, res); - - String fontname = "Helvetica"; - int fontstyle = 0; - int displayfontsize = 12; - int inlinefontsize = 12; - - if (mathBuilder.getMathRootElement() == null) { - //not a MathML document - try { - in.reset(); - } catch (IOException ioe) { - log.error("Error while resetting ImageInputStream", ioe); - } - return null; - } - final MathBase base = new MathBase( - mathBuilder.getMathRootElement(), - fontname, fontstyle, inlinefontsize, - displayfontsize); - - ImageInfo info = new ImageInfo(uri, "text/mathml"); - final ImageSize size = new ImageSize(); - size.setSizeInMillipoints( - Math.round(base.getWidth() * 1000), - Math.round(base.getHeight() * 1000)); - //Set the resolution to that of the FOUserAgent - size.setResolution(context.getSourceResolution()); - size.calcPixelsFromSize(); - info.setSize(size); - - Graphics2DImagePainter painter = new Graphics2DImagePainter() { - - public Dimension getImageSize() { - return size.getDimensionMpt(); - } - - public void paint(Graphics2D g2d, Rectangle2D area) { - base.paint(g2d); - } - - }; - - //The whole image had to be loaded for this, so keep it - Image image = new ImageGraphics2D(info, painter); - info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image); - - return info; - } catch (NoClassDefFoundError ncdfe) { - try { - in.reset(); - } catch (IOException ioe) { - // we're more interested in the original exception - } - jeuclidAvailable = false; - log.warn("JEuclid not in class path", ncdfe); - return null; - } catch (IOException e) { - // If the MathML is invalid then it throws an IOException - // so there is no way of knowing if it is an svg document - - log.debug("Error while trying to load stream as an MathML file: " - + e.getMessage()); - // assuming any exception means this document is not svg - // or could not be loaded for some reason - try { - in.reset(); - } catch (IOException ioe) { - // we're more interested in the original exception - } - return null; - } catch (TransformerException e) { - try { - in.reset(); - } catch (IOException ioe) { - // we're more interested in the original exception - } - log.debug("Error while trying to parsing a MathML file: " - + e.getMessage()); - return null; - } - } - } - -} -- cgit v1.2.3