[FOray-commit] SF.net SVN: foray: [10274] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2007-11-10 01:19:13
|
Revision: 10274
http://foray.svn.sourceforge.net/foray/?rev=10274&view=rev
Author: victormote
Date: 2007-11-09 17:19:14 -0800 (Fri, 09 Nov 2007)
Log Message:
-----------
Improvements to MathML processing.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/java/org/foray/graphic/MathGraphic4a.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXObject.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PdfXFormMath.java
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/MathGraphic4a.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/MathGraphic4a.java 2007-11-09 19:11:22 UTC (rev 10273)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/MathGraphic4a.java 2007-11-10 01:19:14 UTC (rev 10274)
@@ -36,6 +36,7 @@
import org.w3c.dom.mathml.MathMLDocument;
import org.w3c.dom.svg.SVGDocument;
+import java.awt.color.ColorSpace;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.URL;
@@ -164,4 +165,13 @@
return this.svgGraphic.absoluteHeightReal();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ColorSpace getColorSpace() throws GraphicException {
+ this.loadImageWrapper();
+ return this.svgGraphic.getColorSpace();
+ }
+
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXObject.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXObject.java 2007-11-09 19:11:22 UTC (rev 10273)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXObject.java 2007-11-10 01:19:14 UTC (rev 10274)
@@ -42,6 +42,7 @@
import org.axsl.graphic.EpsGraphic;
import org.axsl.graphic.Graphic;
import org.axsl.graphic.GraphicException;
+import org.axsl.graphic.MathGraphic;
import org.axsl.graphic.SvgGraphic;
import org.axsl.pdf.PdfException;
@@ -108,6 +109,10 @@
final SvgGraphic svgGraphic = (SvgGraphic) img;
xObject = new PDFXFormSvg(pdfDoc, svgGraphic, fontConsumer,
strokeText);
+ } else if (img instanceof MathGraphic) {
+ final MathGraphic mathGraphic = (MathGraphic) img;
+ xObject = new PdfXFormMath(pdfDoc, mathGraphic, fontConsumer,
+ strokeText);
} else if (img.getGraphicType() == Graphic.Type.PDF) {
xObject = new PDFXReference(pdfDoc, img);
} else {
Added: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PdfXFormMath.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PdfXFormMath.java (rev 0)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PdfXFormMath.java 2007-11-10 01:19:14 UTC (rev 10274)
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2007 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy: victormote $
+ */
+
+package org.foray.pdf.object;
+
+import org.foray.common.Mime;
+import org.foray.ps.FOrayBoundingBox;
+
+import org.axsl.font.FontConsumer;
+import org.axsl.graphic.GraphicException;
+import org.axsl.graphic.MathGraphic;
+import org.axsl.graphic.output.GraphicOutput;
+import org.axsl.graphic.output.GraphicPdf;
+import org.axsl.ps.BoundingBox;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.ByteArrayOutputStream;
+
+/**
+ * A PDF "Form" XObject containing a MathML document.
+ */
+public class PdfXFormMath extends PDFXForm {
+
+ /** The Graphic instance associated with this XObject. */
+ private MathGraphic graphic;
+
+ /** The FontConsumer to use for resolving fonts in the MathML document. */
+ private FontConsumer fontConsumer;
+
+ /** True if text should be stroked, false if it should use a font. */
+ private boolean strokeText;
+
+ /**
+ * Constructor.
+ * @param doc The parent PDF document.
+ * @param graphic The form to be encapsulated.
+ * @param fontConsumer The font consumer to use for resolving fonts in the
+ * SVG.
+ * @param strokeText Set to true if text should be stroked, false if it
+ * should be drawn with a font.
+ * @throws GraphicException For errors getting the appropriate filter.
+ */
+ public PdfXFormMath(final PDFDocument doc, final MathGraphic graphic,
+ final FontConsumer fontConsumer, final boolean strokeText)
+ throws GraphicException {
+ super(doc, graphic);
+ this.graphic = graphic;
+ this.fontConsumer = fontConsumer;
+ this.strokeText = strokeText;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected byte[] getPdfContent() throws GraphicException {
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ final GraphicOutput graphicOutput = this.graphic.getGraphicOutput(
+ Mime.PDF.getMimeString());
+ if (! (graphicOutput instanceof GraphicPdf)) {
+ throw new GraphicException("Unable to get PDF output helper for "
+ + this.graphic.getUrl());
+ }
+ final GraphicPdf graphicPdf = (GraphicPdf) graphicOutput;
+ graphicPdf.drawVectorContent(outputStream, this.getPDFDocument(),
+ this.fontConsumer, this.strokeText, false);
+ return outputStream.toByteArray();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public float getHorizontalScaling(
+ final Rectangle2D.Float contentRectangle) {
+ final float graphicWidth = FOrayBoundingBox.width(getBoundingBox());
+ return contentRectangle.width / graphicWidth;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public float getVerticalScaling(final Rectangle2D.Float contentRectangle) {
+ final float graphicHeight = FOrayBoundingBox.height(getBoundingBox());
+ return contentRectangle.height / graphicHeight;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MathGraphic getGraphic() {
+ return this.graphic;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected float[] getBoundingBox() {
+ final float[] box = new float[BoundingBox.BBOX_ENTRIES];
+ box[BoundingBox.BBOX_LOWER_LEFT_X_INDEX] = 0;
+ box[BoundingBox.BBOX_LOWER_LEFT_Y_INDEX] = 0;
+ try {
+ box[BoundingBox.BBOX_UPPER_RIGHT_X_INDEX] =
+ this.getGraphic().pixelWidth();
+ box[BoundingBox.BBOX_UPPER_RIGHT_Y_INDEX] =
+ this.getGraphic().pixelHeight();
+ } catch (final GraphicException e) {
+ this.getLogger().error("Error getting SVG dimensions in "
+ + this.getClass().getName());
+ }
+ return box;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected String specialXFormDict() {
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected AffineTransform getUserSpaceTransform() {
+ /* The -1 for "sy" inverts the image. SVG (at least Batik) and PDF
+ * are upside-down from each other. */
+ final AffineTransform transform = AffineTransform.getScaleInstance(1,
+ -1);
+
+ /* Because SVG and PDF are upside-down, the graphic thinks it is at the
+ * top of the image when it is actually at the bottom. Therefore, we
+ * need a translate to move it up the page by the height of the
+ * graphic. */
+ try {
+ transform.translate(0, this.getGraphic().pixelHeight() * -1);
+ } catch (final GraphicException e) {
+ this.getLogger().error("Error getting SVG dimensions.");
+ }
+
+ return transform;
+ }
+
+}
Property changes on: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PdfXFormMath.java
___________________________________________________________________
Name: svn:keywords
+ "Author Id Rev Date URL"
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|