[FOray-commit] SF.net SVN: foray: [9765] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2007-06-13 00:29:45
|
Revision: 9765
http://svn.sourceforge.net/foray/?rev=9765&view=rev
Author: victormote
Date: 2007-06-12 17:29:47 -0700 (Tue, 12 Jun 2007)
Log Message:
-----------
Move the code converting SVG to PostScript from the Renderer module to Graphics.
Modified Paths:
--------------
trunk/foray/foray-graphic/.classpath
trunk/foray/foray-graphic/src/java/org/foray/graphic/SVGGraphic.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/GIFFactory.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/GraphicFactory.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/PDFFactory.java
trunk/foray/foray-render/src/java/org/foray/render/Renderer.java
trunk/foray/foray-render/src/java/org/foray/render/ps/PSRenderer.java
Added Paths:
-----------
trunk/foray/foray-graphic/src/java/org/foray/graphic/TempImage.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java
Removed Paths:
-------------
trunk/foray/foray-render/src/java/org/foray/render/TempImage.java
trunk/foray/foray-render/src/java/org/foray/render/ps/PSGraphics2D.java
Modified: trunk/foray/foray-graphic/.classpath
===================================================================
--- trunk/foray/foray-graphic/.classpath 2007-06-13 00:06:39 UTC (rev 9764)
+++ trunk/foray/foray-graphic/.classpath 2007-06-13 00:29:47 UTC (rev 9765)
@@ -21,5 +21,6 @@
<classpathentry kind="lib" path="/FOray Lib/batik-1.6-dom.jar" sourcepath="/FOray Lib-Build/batik/batik-1.6-sources.zip"/>
<classpathentry kind="lib" path="/FOray Lib/batik-1.6-xml.jar" sourcepath="/FOray Lib-Build/batik/batik-1.6-sources.zip"/>
<classpathentry combineaccessrules="false" kind="src" path="/axslFont-R"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/FOrayPS"/>
<classpathentry kind="output" path="build/eclipse"/>
</classpath>
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/SVGGraphic.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/SVGGraphic.java 2007-06-13 00:06:39 UTC (rev 9764)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/SVGGraphic.java 2007-06-13 00:29:47 UTC (rev 9765)
@@ -28,7 +28,11 @@
package org.foray.graphic;
+import org.foray.common.CharacterOutputStream;
+import org.foray.common.SVGUserAgent;
+import org.foray.common.WKConstants;
import org.foray.graphic.batik.BatikUaAwt;
+import org.foray.graphic.batik.PSGraphics2D;
import org.axsl.fontR.FontConsumer;
import org.axsl.graphicR.Graphic;
@@ -42,6 +46,7 @@
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.gvt.GraphicsNode;
+import org.apache.xmlgraphics.java2d.GraphicContext;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;
@@ -300,11 +305,105 @@
public void drawPS(final OutputStream output, final Point2D location,
final FontConsumer fontConsumer, final boolean strokeText,
final boolean commentsEnabled) {
- /* TODO: Implement this. */
- return;
+ final CharacterOutputStream cos = new CharacterOutputStream(output,
+ commentsEnabled);
+ final double x = location.getX();
+ final double y = location.getY();
+ SVGDocument doc = null;
+ try {
+ doc = this.getSVGDocument();
+ } catch (final GraphicException e) {
+ this.getLogger().error("Error getting SVGDocument in "
+ + this.getClass().getName());
+ return;
+ }
+ BridgeContext ctx = makeBridgeContext();
+ GVTBuilder builder = new GVTBuilder();
+
+ GraphicsNode root;
+ try {
+ root = builder.build(ctx, doc);
+ } catch (final Exception e) {
+ getLogger().error("svg graphic could not be built: "
+ + e.getMessage());
+ getLogger().error(e.getMessage());
+ return;
+ }
+ // get the 'width' and 'height' attributes of the SVG document
+ float w = (float) ctx.getDocumentSize().getWidth();
+ float h = (float) ctx.getDocumentSize().getHeight();
+
+ //log.debug("drawing SVG image: "+x+"/"+y+" "+w+"/"+h);
+ final SVGSVGElement svg = doc.getRootElement();
+ final AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg,
+ w, h);
+
+ w *= WKConstants.MILLIPOINTS_PER_POINT;
+ h *= WKConstants.MILLIPOINTS_PER_POINT;
+
+ ctx = null;
+ builder = null;
+
+ final float sx = 1;
+ final float sy = -1;
+ final int xOffset = (int) Math.round(x);
+ final int yOffset = (int) Math.round(y);
+
+ try {
+ cos.comment("% --- SVG Area");
+ cos.write("gsave");
+ if (w != 0 && h != 0) {
+ cos.write("newpath");
+ cos.write(x + " " + y + " M");
+ cos.write((x + w) + " " + y + " rlineto");
+ cos.write((x + w) + " " + (y - h) + " rlineto");
+ cos.write(x + " " + (y - h) + " rlineto");
+ cos.write("closepath");
+ cos.write("clippath");
+ }
+ // transform so that the coordinates (0,0) is from the top left
+ // and positive is down and to the right. (0,0) is where the
+ // viewBox puts it.
+ cos.write(xOffset + " " + yOffset + " translate");
+ cos.write(
+ (at.getTranslateX() * WKConstants.MILLIPOINTS_PER_POINT)
+ + " "
+ + (-at.getTranslateY() * WKConstants.MILLIPOINTS_PER_POINT)
+ + " translate");
+ cos.write(sx * at.getScaleX() + " " + sy * at.getScaleY()
+ + " scale");
+
+ final PSGraphics2D graphics = new PSGraphics2D(false, cos);
+ graphics.setGraphicContext(new GraphicContext());
+ try {
+ root.paint(graphics);
+ } catch (final Exception e) {
+ getLogger().error("svg graphic could not be rendered: "
+ + e.getMessage());
+ getLogger().error(e.getMessage());
+ }
+
+ cos.write("grestore");
+
+ cos.comment("% --- SVG Area end");
+ } catch (final IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
/**
+ * Creates a BridgeContext instance for use by Batik when rendering an SVG
+ * graphic.
+ * @return A Batik BridgeContext instance.
+ */
+ public BridgeContext makeBridgeContext() {
+ final SVGUserAgent userAgent = new SVGUserAgent(new AffineTransform());
+ userAgent.setLogger(getLogger());
+ return new BridgeContext(userAgent);
+ }
+
+ /**
* {@inheritDoc}
*/
public void drawPdfStreamContent(final OutputStream output,
Copied: trunk/foray/foray-graphic/src/java/org/foray/graphic/TempImage.java (from rev 9748, trunk/foray/foray-render/src/java/org/foray/render/TempImage.java)
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/TempImage.java (rev 0)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/TempImage.java 2007-06-13 00:29:47 UTC (rev 9765)
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2004 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$
+ */
+
+package org.foray.graphic;
+
+import org.foray.common.WKConstants;
+
+import org.axsl.graphicR.Graphic;
+import org.axsl.graphicR.GraphicException;
+import org.axsl.graphicR.GraphicLink;
+
+import java.awt.Color;
+import java.awt.color.ColorSpace;
+import java.net.URL;
+
+/**
+ * An implementation of the axsl Graphic interface that provides the ability
+ * to create a pseudo-graphic that can be used by Renderers.
+ */
+public class TempImage implements Graphic {
+
+ /** An array of empty link to be used as a default. */
+ private static final GraphicLink[] EMPTY_LINKS = new GraphicLink[0];
+
+ /** The image height, in millipoints. */
+ private int height;
+
+ /** The image width, in millipoints. */
+ private int width;
+
+ /** The image color space. */
+ private ColorSpace colorSpace;
+
+ /** The bitmap data for the image. */
+ private byte[] bitmaps;
+
+ /** The transparent color. */
+ private Color transparent = Color.white;
+
+ /** The image's URL. */
+ private URL url;
+
+ /**
+ * Constructor.
+ * @param url The image's URL.
+ * @param width The image width, in millipoints.
+ * @param height The image height, in millipoints.
+ * @param result The bitmap data for the image.
+ */
+ public TempImage(final URL url, final int width, final int height,
+ final byte[] result) {
+ this.url = url;
+ this.height = height;
+ this.width = width;
+ this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+ this.bitmaps = result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isInverted() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URL getURL() {
+ return url;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int pixelWidth() throws GraphicException {
+ return width;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int pixelHeight() throws GraphicException {
+ return height;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ColorSpace getColorSpace() throws GraphicException {
+ return colorSpace;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getBitsPerComponent() throws GraphicException {
+ /* This is a bogus value, intended only to satisfy the interface. */
+ return WKConstants.BITS_PER_BYTE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isTransparent() throws GraphicException {
+ return transparent != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Color getTransparentColor() throws GraphicException {
+ return transparent;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getContent() throws GraphicException {
+ return bitmaps;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getContentSize() throws GraphicException {
+ return width * height
+ * ColorSpace.getInstance(ColorSpace.CS_sRGB).getNumComponents();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close() { }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Graphic.Type getGraphicType() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Graphic.Compression getCompressionType() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getMimeType() {
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int absoluteWidth(final int pixelsPerInch) throws GraphicException {
+ return -1;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int absoluteHeight(final int pixelsPerInch) throws GraphicException {
+ return -1;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getRawSamples() throws GraphicException {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public GraphicLink[] getLinks() {
+ return EMPTY_LINKS;
+ }
+
+}
Copied: trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java (from rev 9764, trunk/foray/foray-render/src/java/org/foray/render/ps/PSGraphics2D.java)
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java (rev 0)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java 2007-06-13 00:29:47 UTC (rev 9765)
@@ -0,0 +1,760 @@
+/*
+ * Copyright 2004 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$
+ */
+
+/*
+ * Known contributors:
+ * Original author: <a href="mailto:ke...@af...">Keiron Liddle</a>
+ */
+
+package org.foray.graphic.batik;
+
+import org.foray.common.CharacterOutputStream;
+import org.foray.common.WKConstants;
+import org.foray.graphic.TempImage;
+import org.foray.ps.PSColor;
+import org.foray.ps.PSMatrix;
+import org.foray.ps.PSReal;
+
+import org.axsl.graphicR.Graphic;
+
+import org.apache.xmlgraphics.java2d.AbstractGraphics2D;
+import org.apache.xmlgraphics.java2d.GraphicContext;
+
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.GradientPaint;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsEnvironment;
+import java.awt.Image;
+import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.Stroke;
+import java.awt.TexturePaint;
+import java.awt.color.ColorSpace;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.PathIterator;
+import java.awt.geom.Point2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferInt;
+import java.awt.image.ImageObserver;
+import java.awt.image.Raster;
+import java.awt.image.RenderedImage;
+import java.awt.image.renderable.RenderableImage;
+import java.io.IOException;
+import java.text.AttributedCharacterIterator;
+import java.text.CharacterIterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Implementation of <tt>AbstractGraphics2D</tt> suitable for integration with
+ * Batik for purposes of converting SVG to PostScript.
+ */
+public class PSGraphics2D extends AbstractGraphics2D {
+
+ /** Constant indicating the number of components needed to describe a
+ * line. */
+ private static final int QTY_LINE_COMPONENTS = 2;
+
+ /** Constant indicating the number of components needed to describe a
+ * cube. */
+ private static final int QTY_CUBIC_COMPONENTS = 6;
+
+ /** The output stream to which we are writing. */
+ private CharacterOutputStream out;
+
+ /** Used to create proper font metrics. */
+ private Graphics2D fmg;
+ {
+ final BufferedImage bi = new BufferedImage(1, 1,
+ BufferedImage.TYPE_INT_ARGB);
+ this.fmg = bi.createGraphics();
+ }
+
+ /**
+ * Create a new PDFGraphics2D with the given pdf document info.
+ * This is used to create a Graphics object for use inside an already
+ * existing document.
+ * @param textAsShapes Indicates whether text should be treated as text
+ * (false), or whether it should be converted to its paths (true).
+ * @param out The output stream to which the content should be written.
+ */
+ public PSGraphics2D(final boolean textAsShapes,
+ final CharacterOutputStream out) {
+ super(textAsShapes);
+ this.out = out;
+ }
+
+ /**
+ * Constructor supporting the {@link #create()} method.
+ * @param g The wrapped graphic.
+ */
+ public PSGraphics2D(final PSGraphics2D g) {
+ super(g);
+ }
+
+ /**
+ * Sets the graphic context.
+ * @param c The new graphic context.
+ */
+ public void setGraphicContext(final GraphicContext c) {
+ gc = c;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Graphics create() {
+ return new PSGraphics2D(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean drawImage(final Image img, final int x, final int y,
+ final ImageObserver observer) {
+ final int width = img.getWidth(observer);
+ final int height = img.getHeight(observer);
+ if (width == -1 || height == -1) {
+ return false;
+ }
+ final Dimension size = new Dimension(width, height);
+ final BufferedImage buf = new BufferedImage(size.width, size.height,
+ BufferedImage.TYPE_INT_ARGB);
+ final int colorComponents = ColorSpace.getInstance(ColorSpace.CS_sRGB)
+ .getNumComponents();
+
+ final Graphics2D g = buf.createGraphics();
+ g.setComposite(AlphaComposite.SrcOver);
+ g.setBackground(new Color(1, 1, 1, 0));
+ g.setPaint(new Color(1, 1, 1, 0));
+ g.fillRect(0, 0, width, height);
+ g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight()));
+
+ if (!g.drawImage(img, 0, 0, observer)) {
+ return false;
+ }
+ g.dispose();
+
+ final byte[] result = new byte[buf.getWidth() * buf.getHeight()
+ * colorComponents];
+
+ final Raster raster = buf.getData();
+ final DataBuffer bd = raster.getDataBuffer();
+
+ int count = 0;
+ switch (bd.getDataType()) {
+ case DataBuffer.TYPE_INT:
+ final int[][] idata = ((DataBufferInt) bd).getBankData();
+ for (int i = 0; i < idata.length; i++) {
+ for (int j = 0; j < idata[i].length; j++) {
+ // mask[maskpos++] = (byte)((idata[i][j] >> 24) & 0xFF);
+ if (((idata[i][j] >> WKConstants.SHIFT_3_BYTES)
+ & WKConstants.MAX_8_BIT_UNSIGNED_BYTE)
+ != WKConstants.MAX_8_BIT_UNSIGNED_INT) {
+ result[count++] = WKConstants.MAX_8_BIT_UNSIGNED_BYTE;
+ result[count++] = WKConstants.MAX_8_BIT_UNSIGNED_BYTE;
+ result[count++] = WKConstants.MAX_8_BIT_UNSIGNED_BYTE;
+ } else {
+ result[count++] = (byte) ((idata[i][j]
+ >> WKConstants.SHIFT_2_BYTES)
+ & WKConstants.MAX_8_BIT_UNSIGNED_BYTE);
+ result[count++] = (byte) ((idata[i][j]
+ >> WKConstants.SHIFT_1_BYTE)
+ & WKConstants.MAX_8_BIT_UNSIGNED_BYTE);
+ result[count++] = (byte) ((idata[i][j])
+ & WKConstants.MAX_8_BIT_UNSIGNED_BYTE);
+ }
+ }
+ }
+ break;
+ default:
+ // error
+ break;
+ }
+
+ try {
+ final Graphic graphic = new TempImage(null, width, height, result);
+ final AffineTransform at = getTransform();
+ final double[] matrix = new double[PSMatrix.QTY_ELEMENTS];
+ at.getMatrix(matrix);
+ this.out.write("gsave");
+ final Shape imclip = getClip();
+ writeClip(imclip);
+ this.out.write("1000 -1000 scale");
+ // psRenderer.write("" + matrix[0] + " " + matrix[1] +
+ // " " + matrix[2] + " " + matrix[3] + " " +
+ // matrix[4] + " " + matrix[5] + " cm\n");
+
+ /* TODO: The following line is commented out to avoid having this
+ * class dependent on the PostScript renderer. After this is all
+ * moved to the Graphics package, this needs to be reworked.
+ * The "graphic" needs to be a real Graphic instance of the proper
+ * type, and should then be converted to PostScript here. */
+ graphic.close();
+// this.psRenderer.renderBitmap(graphic, x, -y, width, height);
+ this.out.write("grestore");
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean drawImage(final Image img, final int x, final int y,
+ final int width, final int height, final ImageObserver observer) {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose() {
+ this.out = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void draw(final Shape s) {
+ try {
+ this.out.write("gsave");
+ final Shape imclip = getClip();
+ writeClip(imclip);
+ final Color c = getColor();
+ this.out.write(c.getRed() + " " + c.getGreen() + " "
+ + c.getBlue() + " setrgbcolor");
+
+ applyPaint(getPaint(), false);
+ applyStroke(getStroke());
+
+ this.out.write("newpath");
+ final PathIterator iter = s.getPathIterator(getTransform());
+ while (!iter.isDone()) {
+ final double vals[] = new double[PSMatrix.QTY_ELEMENTS];
+ final int type = iter.currentSegment(vals);
+ String matrixString = null;
+ switch (type) {
+ case PathIterator.SEG_CUBICTO:
+ matrixString = matrixToString(vals, QTY_CUBIC_COMPONENTS);
+ this.out.write(matrixString + "curveto");
+ break;
+ case PathIterator.SEG_LINETO:
+ matrixString = matrixToString(vals, QTY_LINE_COMPONENTS);
+ this.out.write(matrixString + "lineto");
+ break;
+ case PathIterator.SEG_MOVETO:
+ matrixString = matrixToString(vals, QTY_LINE_COMPONENTS);
+ this.out.write(matrixString + "M");
+ break;
+ case PathIterator.SEG_QUADTO:
+ // psRenderer.write((1000 * PDFNumber.doubleOut(vals[0])) +
+ // " " + (1000 * PDFNumber.doubleOut(vals[1])) + " " +
+ // (1000 * PDFNumber.doubleOut(vals[2])) + " " +
+ // (1000 * PDFNumber.doubleOut(vals[3])) + " y\n");
+ break;
+ case PathIterator.SEG_CLOSE:
+ this.out.write("closepath");
+ break;
+ default:
+ break;
+ }
+ iter.next();
+ }
+ doDrawing(false, true, false);
+ this.out.write("grestore");
+ } catch (final IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Creates a String representation of a given matrix.
+ * @param matrix The matrix to be converted to a String.
+ * @param qtyElements The number of elements active in the matrix.
+ * @return The String representation of the matrix.
+ */
+ private String matrixToString(final double[] matrix,
+ final int qtyElements) {
+ final StringBuilder buffer = new StringBuilder();
+ for (int i = 0; i < qtyElements; i++) {
+ buffer.append(PSReal.doubleOut(
+ WKConstants.MILLIPOINTS_PER_POINT * matrix[i])
+ + " ");
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Creates code to clip along a given shape.
+ * @param s The shape upon which the clip should be created.
+ * @throws IOException For I/O errors writing the content.
+ */
+ protected void writeClip(final Shape s) throws IOException {
+ final PathIterator iter = s.getPathIterator(getTransform());
+ this.out.write("newpath");
+ while (!iter.isDone()) {
+ final double vals[] = new double[PSMatrix.QTY_ELEMENTS];
+ final int type = iter.currentSegment(vals);
+ String matrixString = null;
+ switch (type) {
+ case PathIterator.SEG_CUBICTO:
+ matrixString = matrixToString(vals, QTY_CUBIC_COMPONENTS);
+ this.out.write(matrixString + "curveto");
+ break;
+ case PathIterator.SEG_LINETO:
+ matrixString = matrixToString(vals, QTY_LINE_COMPONENTS);
+ this.out.write(matrixString + "lineto");
+ break;
+ case PathIterator.SEG_MOVETO:
+ matrixString = matrixToString(vals, QTY_LINE_COMPONENTS);
+ this.out.write(matrixString + "M");
+ break;
+ case PathIterator.SEG_QUADTO:
+ // psRenderer.write(1000 * PDFNumber.doubleOut(vals[0]) +
+ // " " + 1000 * PDFNumber.doubleOut(vals[1]) + " " +
+ // 1000 * PDFNumber.doubleOut(vals[2]) + " " +
+ // 1000 * PDFNumber.doubleOut(vals[3]) + " y\n");
+ break;
+ case PathIterator.SEG_CLOSE:
+ this.out.write("closepath");
+ break;
+ default:
+ break;
+ }
+ iter.next();
+ }
+ // clip area
+ this.out.write("clippath");
+ }
+
+ /**
+ * Apply the paint to this graphic.
+ * @param paint The paint to use.
+ * @param fill Indicates whether the paint is for fill (true) or stroke
+ * (false).
+ */
+ protected void applyPaint(final Paint paint, final boolean fill) {
+ if (paint instanceof GradientPaint) {
+ final GradientPaint gp = (GradientPaint) paint;
+ final Color c1 = gp.getColor1();
+ final Color c2 = gp.getColor2();
+ final Point2D p1 = gp.getPoint1();
+ final Point2D p2 = gp.getPoint2();
+
+ final List<Double> theCoords = new ArrayList<Double>();
+ theCoords.add(new Double(p1.getX()));
+ theCoords.add(new Double(p1.getY()));
+ theCoords.add(new Double(p2.getX()));
+ theCoords.add(new Double(p2.getY()));
+
+ final List<Boolean> theExtend = new ArrayList<Boolean>();
+ theExtend.add(new Boolean(true));
+ theExtend.add(new Boolean(true));
+
+ final List<Double> theDomain = new ArrayList<Double>();
+ theDomain.add(new Double(0));
+ theDomain.add(new Double(1));
+
+ final List<Double> theEncode = new ArrayList<Double>();
+ theEncode.add(new Double(0));
+ theEncode.add(new Double(1));
+ theEncode.add(new Double(0));
+ theEncode.add(new Double(1));
+
+ final List<Double> theBounds = new ArrayList<Double>();
+ theBounds.add(new Double(0));
+ theBounds.add(new Double(1));
+
+ final List<Color> someColors = new ArrayList<Color>();
+
+ someColors.add(c1);
+ someColors.add(c2);
+
+ } else if (paint instanceof TexturePaint) { }
+ }
+
+ /**
+ * Draw the graphic using a specified Stroke.
+ * @param stroke The stroke to use for drawing.
+ * @throws IOException For I/O errors writing the content.
+ */
+ protected void applyStroke(final Stroke stroke) throws IOException {
+ if (stroke instanceof BasicStroke) {
+ final BasicStroke bs = (BasicStroke) stroke;
+
+ final float[] da = bs.getDashArray();
+ if (da != null) {
+ this.out.write("[");
+ for (int count = 0; count < da.length; count++) {
+ this.out.write(""
+ + (WKConstants.MILLIPOINTS_PER_POINT
+ * (int) da[count]));
+ if (count < da.length - 1) {
+ this.out.write(" ");
+ }
+ }
+ this.out.write("] ");
+ final float offset = bs.getDashPhase();
+ this.out.write((WKConstants.MILLIPOINTS_PER_POINT
+ * (int) offset) + " setdash");
+ }
+ final int ec = bs.getEndCap();
+ switch (ec) {
+ case BasicStroke.CAP_BUTT:
+ this.out.write(0 + " setlinecap");
+ break;
+ case BasicStroke.CAP_ROUND:
+ this.out.write(1 + " setlinecap");
+ break;
+ case BasicStroke.CAP_SQUARE:
+ this.out.write(2 + " setlinecap");
+ break;
+ }
+
+ final int lj = bs.getLineJoin();
+ switch (lj) {
+ case BasicStroke.JOIN_MITER:
+ this.out.write(0 + " setlinejoin");
+ break;
+ case BasicStroke.JOIN_ROUND:
+ this.out.write(1 + " setlinejoin");
+ break;
+ case BasicStroke.JOIN_BEVEL:
+ this.out.write(2 + " setlinejoin");
+ break;
+ }
+ final float lw = bs.getLineWidth();
+ this.out.write(PSReal.doubleOut(
+ WKConstants.MILLIPOINTS_PER_POINT * lw)
+ + " setlinewidth");
+
+ final float ml = bs.getMiterLimit();
+ this.out.write(PSReal.doubleOut(
+ WKConstants.MILLIPOINTS_PER_POINT * ml)
+ + " setmiterlimit");
+ }
+ }
+
+ /**
+ * Renders a {@link RenderedImage},
+ * applying a transform from image
+ * space into user space before drawing.
+ * The transformation from user space into device space is done with
+ * the current <code>Transform</code> in the <code>Graphics2D</code>.
+ * The specified transformation is applied to the image before the
+ * transform attribute in the <code>Graphics2D</code> context is applied.
+ * The rendering attributes applied include the <code>Clip</code>,
+ * <code>Transform</code>, and <code>Composite</code> attributes. Note
+ * that no rendering is done if the specified transform is
+ * noninvertible.
+ * @param img the image to be rendered
+ * @param xform the transformation from image space into user space
+ * @see AbstractGraphics2D#transform
+ * @see AbstractGraphics2D#setTransform
+ * @see AbstractGraphics2D#setComposite
+ * @see AbstractGraphics2D#clip
+ */
+ public void drawRenderedImage(final RenderedImage img,
+ final AffineTransform xform) {
+ }
+
+
+ /**
+ * Renders a
+ * {@link RenderableImage},
+ * applying a transform from image space into user space before drawing.
+ * The transformation from user space into device space is done with
+ * the current <code>Transform</code> in the <code>Graphics2D</code>.
+ * The specified transformation is applied to the image before the
+ * transform attribute in the <code>Graphics2D</code> context is applied.
+ * The rendering attributes applied include the <code>Clip</code>,
+ * <code>Transform</code>, and <code>Composite</code> attributes. Note
+ * that no rendering is done if the specified transform is
+ * noninvertible.
+ * <p>
+ * Rendering hints set on the <code>Graphics2D</code> object might
+ * be used in rendering the <code>RenderableImage</code>.
+ * If explicit control is required over specific hints recognized by a
+ * specific <code>RenderableImage</code>, or if knowledge of which hints
+ * are used is required, then a <code>RenderedImage</code> should be
+ * obtained directly from the <code>RenderableImage</code>
+ * and rendered using
+ * {@link #drawRenderedImage(RenderedImage, AffineTransform)
+ * drawRenderedImage}.
+ * @param img the image to be rendered
+ * @param xform the transformation from image space into user space
+ * @see AbstractGraphics2D#transform
+ * @see AbstractGraphics2D#setTransform
+ * @see AbstractGraphics2D#setComposite
+ * @see AbstractGraphics2D#clip
+ * @see AbstractGraphics2D#setClip(java.awt.Shape)
+ * @see #drawRenderedImage
+ */
+ public void drawRenderableImage(final RenderableImage img,
+ final AffineTransform xform) {
+ }
+
+ /**
+ * Renders the text specified by the specified <code>String</code>,
+ * using the current <code>Font</code> and <code>Paint</code> attributes
+ * in the <code>Graphics2D</code> context.
+ * The baseline of the first character is at position
+ * (<i>x</i>, <i>y</i>) in the User Space.
+ * The rendering attributes applied include the <code>Clip</code>,
+ * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
+ * <code>Composite</code> attributes. For characters in script systems
+ * such as Hebrew and Arabic, the glyphs can be rendered from right to
+ * left, in which case the coordinate supplied is the location of the
+ * leftmost character on the baseline.
+ * @param s the <code>String</code> to be rendered
+ * @param x The x coordinate where the <code>String</code> should be
+ * rendered.
+ * @param y The y coordinate where the <code>String</code> should be
+ * rendered.
+ * @see AbstractGraphics2D#setPaint
+ * @see java.awt.Graphics#setColor
+ * @see java.awt.Graphics#setFont
+ * @see AbstractGraphics2D#setTransform
+ * @see AbstractGraphics2D#setComposite
+ * @see AbstractGraphics2D#setClip(java.awt.Shape)
+ */
+ public void drawString(final String s, final float x, final float y) {
+ try {
+ this.out.write("BT");
+ final Shape imclip = getClip();
+ writeClip(imclip);
+ final Color c = getColor();
+ this.out.write(c.getRed() + " " + c.getGreen() + " "
+ + c.getBlue() + " setrgbcolor");
+
+ final AffineTransform trans = getTransform();
+ trans.translate(x, y);
+ final double[] vals = new double[PSMatrix.QTY_ELEMENTS];
+ trans.getMatrix(vals);
+
+ final String matrixString = matrixToString(vals,
+ PSMatrix.QTY_ELEMENTS);
+ this.out.write(matrixString + "Tm [" + s + "]");
+
+ this.out.write("ET");
+ } catch (final IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Renders the text of the specified iterator, using the
+ * <code>Graphics2D</code> context's current <code>Paint</code>. The
+ * iterator must specify a font
+ * for each character. The baseline of the
+ * first character is at position (<i>x</i>, <i>y</i>) in the
+ * User Space.
+ * The rendering attributes applied include the <code>Clip</code>,
+ * <code>Transform</code>, <code>Paint</code>, and
+ * <code>Composite</code> attributes.
+ * For characters in script systems such as Hebrew and Arabic,
+ * the glyphs can be rendered from right to left, in which case the
+ * coordinate supplied is the location of the leftmost character
+ * on the baseline.
+ * @param iterator the iterator whose text is to be rendered
+ * @param x The x coordinate where the iterator's text is to be rendered.
+ * @param y The y coordinate where the iterator's text is to be rendered.
+ * @see AbstractGraphics2D#setPaint
+ * @see java.awt.Graphics#setColor
+ * @see AbstractGraphics2D#setTransform
+ * @see AbstractGraphics2D#setComposite
+ * @see AbstractGraphics2D#setClip(java.awt.Shape)
+ */
+ public void drawString(final AttributedCharacterIterator iterator,
+ final float x, final float y) {
+ try {
+ this.out.write("BT");
+ final Shape imclip = getClip();
+ writeClip(imclip);
+ this.out.write(PSColor.toPS(getColor(), true));
+ this.out.write("\n");
+ this.out.write(PSColor.toPS(getBackground(), true));
+ this.out.write("\n");
+
+ final AffineTransform trans = getTransform();
+ trans.translate(x, y);
+ final double[] vals = new double[PSMatrix.QTY_ELEMENTS];
+ trans.getMatrix(vals);
+
+ for (char ch = iterator.first(); ch != CharacterIterator.DONE;
+ ch = iterator.next()) {
+ final String matrixString = matrixToString(vals,
+ PSMatrix.QTY_ELEMENTS);
+ this.out.write(matrixString + "Tm [" + ch + "]");
+ }
+
+ this.out.write("ET");
+ } catch (final IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Fills the interior of a <code>Shape</code> using the settings of the
+ * <code>Graphics2D</code> context. The rendering attributes applied
+ * include the <code>Clip</code>, <code>Transform</code>,
+ * <code>Paint</code>, and <code>Composite</code>.
+ * @param s the <code>Shape</code> to be filled
+ * @see AbstractGraphics2D#setPaint
+ * @see java.awt.Graphics#setColor
+ * @see AbstractGraphics2D#transform
+ * @see AbstractGraphics2D#setTransform
+ * @see AbstractGraphics2D#setComposite
+ * @see AbstractGraphics2D#clip
+ * @see AbstractGraphics2D#setClip(java.awt.Shape)
+ */
+ public void fill(final Shape s) {
+ try {
+ this.out.write("gsave");
+ final Shape imclip = getClip();
+ writeClip(imclip);
+ final Color c = getColor();
+ this.out.write(c.getRed() + " " + c.getGreen() + " "
+ + c.getBlue() + " setrgbcolor");
+
+ applyPaint(getPaint(), true);
+
+ this.out.write("newpath");
+ final PathIterator iter = s.getPathIterator(getTransform());
+ while (!iter.isDone()) {
+ final double vals[] = new double[PSMatrix.QTY_ELEMENTS];
+ final int type = iter.currentSegment(vals);
+ String matrixString = null;
+ switch (type) {
+ case PathIterator.SEG_CUBICTO:
+ matrixString = matrixToString(vals, QTY_CUBIC_COMPONENTS);
+ this.out.write(matrixString + "curveto");
+ break;
+ case PathIterator.SEG_LINETO:
+ matrixString = matrixToString(vals, QTY_LINE_COMPONENTS);
+ this.out.write(matrixString + "lineto");
+ break;
+ case PathIterator.SEG_MOVETO:
+ matrixString = matrixToString(vals, QTY_LINE_COMPONENTS);
+ this.out.write(matrixString + "M");
+ break;
+ case PathIterator.SEG_QUADTO:
+ // psRenderer.write(1000 * PDFNumber.doubleOut(vals[0]) +
+ // " " + 1000 * PDFNumber.doubleOut(vals[1]) + " " +
+ // 1000 * PDFNumber.doubleOut(vals[2]) + " " +
+ // 1000 * PDFNumber.doubleOut(vals[3]) + " y\n");
+ break;
+ case PathIterator.SEG_CLOSE:
+ this.out.write("closepath");
+ break;
+ default:
+ break;
+ }
+ iter.next();
+ }
+ doDrawing(true, false,
+ iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
+ this.out.write("grestore");
+ } catch (final IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Write the command to the renderer.
+ * @param fill Set to true if filling.
+ * @param stroke Set to true if stroking.
+ * @param nonzero Set to true to use the nonzero winding number rule.
+ * @throws IOException For IO errors on output.
+ */
+ protected void doDrawing(final boolean fill, final boolean stroke,
+ final boolean nonzero) throws IOException {
+ if (fill) {
+ if (stroke) {
+ if (!nonzero) {
+ this.out.write("stroke");
+ } else {
+ this.out.write("stroke");
+ }
+ } else {
+ if (!nonzero) {
+ this.out.write("fill");
+ } else {
+ this.out.write("fill");
+ }
+ }
+ } else {
+ this.out.write("stroke");
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public GraphicsConfiguration getDeviceConfiguration() {
+ return GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getDefaultScreenDevice().getDefaultConfiguration();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public FontMetrics getFontMetrics(final Font f) {
+ return this.fmg.getFontMetrics(f);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setXORMode(final Color c1) {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void copyArea(final int x, final int y, final int width,
+ final int height, final int dx, final int dy) {
+ }
+
+}
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/GIFFactory.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/GIFFactory.java 2007-06-13 00:06:39 UTC (rev 9764)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/GIFFactory.java 2007-06-13 00:29:47 UTC (rev 9765)
@@ -28,8 +28,8 @@
package org.foray.graphic.factory;
+import org.foray.graphic.FOrayGraphicServer;
import org.foray.graphic.GIFGraphic;
-import org.foray.graphic.FOrayGraphicServer;
import java.io.BufferedInputStream;
import java.io.IOException;
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/GraphicFactory.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/GraphicFactory.java 2007-06-13 00:06:39 UTC (rev 9764)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/GraphicFactory.java 2007-06-13 00:29:47 UTC (rev 9765)
@@ -33,8 +33,8 @@
package org.foray.graphic.factory;
+import org.foray.graphic.FOrayGraphic;
import org.foray.graphic.FOrayGraphicServer;
-import org.foray.graphic.FOrayGraphic;
import org.apache.commons.logging.Log;
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/PDFFactory.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/PDFFactory.java 2007-06-13 00:06:39 UTC (rev 9764)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/factory/PDFFactory.java 2007-06-13 00:29:47 UTC (rev 9765)
@@ -28,8 +28,8 @@
package org.foray.graphic.factory;
+import org.foray.graphic.FOrayGraphicServer;
import org.foray.graphic.PDFGraphic;
-import org.foray.graphic.FOrayGraphicServer;
import java.io.BufferedInputStream;
import java.io.IOException;
Modified: trunk/foray/foray-render/src/java/org/foray/render/Renderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/Renderer.java 2007-06-13 00:06:39 UTC (rev 9764)
+++ trunk/foray/foray-render/src/java/org/foray/render/Renderer.java 2007-06-13 00:29:47 UTC (rev 9765)
@@ -34,7 +34,6 @@
package org.foray.render;
import org.foray.common.FOrayConstants;
-import org.foray.common.SVGUserAgent;
import org.foray.common.WKConstants;
import org.foray.output.OutputConfig;
import org.foray.output.OutputTarget;
@@ -72,12 +71,10 @@
import org.axsl.graphicR.GraphicException;
import org.axsl.graphicR.SVGGraphic;
-import org.apache.batik.bridge.BridgeContext;
import org.apache.commons.logging.Log;
import java.awt.Color;
import java.awt.Rectangle;
-import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
@@ -598,17 +595,6 @@
public abstract void resetTextCursor();
/**
- * Creates a BridgeContext instance for use by Batik when rendering an SVG
- * graphic.
- * @return A Batik BridgeContext instance.
- */
- public BridgeContext makeBridgeContext() {
- final SVGUserAgent userAgent = new SVGUserAgent(new AffineTransform());
- userAgent.setLogger(getLogger());
- return new BridgeContext(userAgent);
- }
-
- /**
* Converts a Rectangle storing millipoints to one storing points.
* @param input A rectangle whose dimensions are stored as millipoints.
* @return A new rectangle whose dimensions are stored as points.
Deleted: trunk/foray/foray-render/src/java/org/foray/render/TempImage.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/TempImage.java 2007-06-13 00:06:39 UTC (rev 9764)
+++ trunk/foray/foray-render/src/java/org/foray/render/TempImage.java 2007-06-13 00:29:47 UTC (rev 9765)
@@ -1,217 +0,0 @@
-/*
- * Copyright 2004 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$
- */
-
-package org.foray.render;
-
-import org.foray.common.WKConstants;
-
-import org.axsl.graphicR.Graphic;
-import org.axsl.graphicR.GraphicException;
-import org.axsl.graphicR.GraphicLink;
-
-import java.awt.Color;
-import java.awt.color.ColorSpace;
-import java.net.URL;
-
-/**
- * An implementation of the axsl Graphic interface that provides the ability
- * to create a pseudo-graphic that can be used by Renderers.
- */
-public class TempImage implements Graphic {
-
- /** An array of empty link to be used as a default. */
- private static final GraphicLink[] EMPTY_LINKS = new GraphicLink[0];
-
- /** The image height, in millipoints. */
- private int height;
-
- /** The image width, in millipoints. */
- private int width;
-
- /** The image color space. */
- private ColorSpace colorSpace;
-
- /** The bitmap data for the image. */
- private byte[] bitmaps;
-
- /** The transparent color. */
- private Color transparent = Color.white;
-
- /** The image's URL. */
- private URL url;
-
- /**
- * Constructor.
- * @param url The image's URL.
- * @param width The image width, in millipoints.
- * @param height The image height, in millipoints.
- * @param result The bitmap data for the image.
- */
- public TempImage(final URL url, final int width, final int height,
- final byte[] result) {
- this.url = url;
- this.height = height;
- this.width = width;
- this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
- this.bitmaps = result;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isInverted() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public URL getURL() {
- return url;
- }
-
- /**
- * {@inheritDoc}
- */
- public int pixelWidth() throws GraphicException {
- return width;
- }
-
- /**
- * {@inheritDoc}
- */
- public int pixelHeight() throws GraphicException {
- return height;
- }
-
- /**
- * {@inheritDoc}
- */
- public ColorSpace getColorSpace() throws GraphicException {
- return colorSpace;
- }
-
- /**
- * {@inheritDoc}
- */
- public int getBitsPerComponent() throws GraphicException {
- /* This is a bogus value, intended only to satisfy the interface. */
- return WKConstants.BITS_PER_BYTE;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isTransparent() throws GraphicException {
- return transparent != null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Color getTransparentColor() throws GraphicException {
- return transparent;
- }
-
- /**
- * {@inheritDoc}
- */
- public byte[] getContent() throws GraphicException {
- return bitmaps;
- }
-
- /**
- * {@inheritDoc}
- */
- public int getContentSize() throws GraphicException {
- return width * height
- * ColorSpace.getInstance(ColorSpace.CS_sRGB).getNumComponents();
- }
-
- /**
- * {@inheritDoc}
- */
- public void close() { }
-
- /**
- * {@inheritDoc}
- */
- public Graphic.Type getGraphicType() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Graphic.Compression getCompressionType() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getMimeType() {
- return "";
- }
-
- /**
- * {@inheritDoc}
- */
- public String getName() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public int absoluteWidth(final int pixelsPerInch) throws GraphicException {
- return -1;
- }
-
- /**
- * {@inheritDoc}
- */
- public int absoluteHeight(final int pixelsPerInch) throws GraphicException {
- return -1;
- }
-
- /**
- * {@inheritDoc}
- */
- public byte[] getRawSamples() throws GraphicException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public GraphicLink[] getLinks() {
- return EMPTY_LINKS;
- }
-
-}
Deleted: trunk/foray/foray-render/src/java/org/foray/render/ps/PSGraphics2D.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/ps/PSGraphics2D.java 2007-06-13 00:06:39 UTC (rev 9764)
+++ trunk/foray/foray-render/src/java/org/foray/render/ps/PSGraphics2D.java 2007-06-13 00:29:47 UTC (rev 9765)
@@ -1,763 +0,0 @@
-/*
- * Copyright 2004 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$
- */
-
-package org.foray.render.ps;
-
-import org.foray.common.CharacterOutputStream;
-import org.foray.common.WKConstants;
-import org.foray.ps.PSColor;
-import org.foray.ps.PSMatrix;
-import org.foray.ps.PSReal;
-import org.foray.render.TempImage;
-
-import org.axsl.graphicR.Graphic;
-
-import org.apache.batik.ext.awt.g2d.AbstractGraphics2D;
-import org.apache.batik.ext.awt.g2d.GraphicContext;
-
-import java.awt.AlphaComposite;
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.GradientPaint;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsEnvironment;
-import java.awt.Image;
-import java.awt.Paint;
-import java.awt.Rectangle;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.TexturePaint;
-import java.awt.color.ColorSpace;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Point2D;
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferInt;
-import java.awt.image.ImageObserver;
-import java.awt.image.Raster;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.RenderableImage;
-import java.io.IOException;
-import java.text.AttributedCharacterIterator;
-import java.text.CharacterIterator;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * This concrete implementation of <tt>AbstractGraphics2D</tt> is a
- * simple help to programmers to get started with their own
- * implementation of <tt>Graphics2D</tt>.
- * <tt>DefaultGraphics2D</tt> implements all the abstract methods
- * is <tt>AbstractGraphics2D</tt> and makes it easy to start
- * implementing a <tt>Graphic2D</tt> piece-meal.
- *
- * @author <a href="mailto:ke...@af...">Keiron Liddle</a>
- * @version $Id$
- * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D
- */
-public class PSGraphics2D extends AbstractGraphics2D {
-
- /** Constant indicating the number of components needed to describe a
- * line. */
- private static final int QTY_LINE_COMPONENTS = 2;
-
- /** Constant indicating the number of components needed to describe a
- * cube. */
- private static final int QTY_CUBIC_COMPONENTS = 6;
-
- /** The output stream to which we are writing. */
- private CharacterOutputStream out;
-
- /** Used to create proper font metrics. */
- private Graphics2D fmg;
- {
- final BufferedImage bi = new BufferedImage(1, 1,
- BufferedImage.TYPE_INT_ARGB);
- this.fmg = bi.createGraphics();
- }
-
- /**
- * Create a new PDFGraphics2D with the given pdf document info.
- * This is used to create a Graphics object for use inside an already
- * existing document.
- * @param textAsShapes Indicates whether text should be treated as text
- * (false), or whether it should be converted to its paths (true).
- * @param out The output stream to which the content should be written.
- */
- public PSGraphics2D(final boolean textAsShapes,
- final CharacterOutputStream out) {
- super(textAsShapes);
- this.out = out;
- }
-
- /**
- * Constructor supporting the {@link #create()} method.
- * @param g The wrapped graphic.
- */
- public PSGraphics2D(final PSGraphics2D g) {
- super(g);
- }
-
- /**
- * Sets the graphic context.
- * @param c The new graphic context.
- */
- public void setGraphicContext(final GraphicContext c) {
- gc = c;
- }
-
- /**
- * {@inheritDoc}
- */
- public Graphics create() {
- return new PSGraphics2D(this);
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean drawImage(final Image img, final int x, final int y,
- final ImageObserver observer) {
- final int width = img.getWidth(observer);
- final int height = img.getHeight(observer);
- if (width == -1 || height == -1) {
- return false;
- }
- final Dimension size = new Dimension(width, height);
- final BufferedImage buf = new BufferedImage(size.width, size.height,
- BufferedImage.TYPE_INT_ARGB);
- final int colorComponents = ColorSpace.getInstance(ColorSpace.CS_sRGB)
- .getNumComponents();
-
- final Graphics2D g = buf.createGraphics();
- g.setComposite(AlphaComposite.SrcOver);
- g.setBackground(new Color(1, 1, 1, 0));
- g.setPaint(new Color(1, 1, 1, 0));
- g.fillRect(0, 0, width, height);
- g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight()));
-
- if (!g.drawImage(img, 0, 0, observer)) {
- return false;
- }
- g.dispose();
-
- final byte[] result = new byte[buf.getWidth() * buf.getHeight()
- * colorComponents];
-
- final Raster raster = buf.getData();
- final DataBuffer bd = raster.getDataBuffer();
-
- int count = 0;
- switch (bd.getDataType()) {
- case DataBuffer.TYPE_INT:
- final int[][] idata = ((DataBufferInt) bd).getBankData();
- for (int i = 0; i < idata.length; i++) {
- for (int j = 0; j < idata[i].length; j++) {
- // mask[maskpos++] = (byte)((idata[i][j] >> 24) & 0xFF);
- if (((idata[i][j] >> WKConstants.SHIFT_3_BYTES)
- & WKConstants.MAX_8_BIT_UNSIGNED_BYTE)
- != WKConstants.MAX_8_BIT_UNSIGNED_INT) {
- result[count++] = WKConstants.MAX_8_BIT_UNSIGNED_BYTE;
- result[count++] = WKConstants.MAX_8_BIT_UNSIGNED_BYTE;
- result[count++] = WKConstants.MAX_8_BIT_UNSIGNED_BYTE;
- } else {
- result[count++] = (byte) ((idata[i][j]
- >> WKConstants.SHIFT_2_BYTES)
- & WKConstants.MAX_8_BIT_UNSIGNED_BYTE);
- result[count++] = (byte) ((idata[i][j]
- >> WKConstants.SHIFT_1_BYTE)
- & WKConstants.MAX_8_BIT_UNSIGNED_BYTE);
- result[count++] = (byte) ((idata[i][j])
- & WKConstants.MAX_8_BIT_UNSIGNED_BYTE);
- }
- }
- }
- break;
- default:
- // error
- break;
- }
-
- try {
- final Graphic graphic = new TempImage(null, width, height, result);
- final AffineTransform at = getTransform();
- final double[] matrix = new double[PSMatrix.QTY_ELEMENTS];
- at.getMatrix(matrix);
- this.out.write("gsave");
- final Shape imclip = getClip();
- writeClip(imclip);
- this.out.write("1000 -1000 scale");
- // psRenderer.write("" + matrix[0] + " " + matrix[1] +
- // " " + matrix[2] + " " + matrix[3] + " " +
- // matrix[4] + " " + matrix[5] + " cm\n");
-
- /* TODO: The following line is commented out to avoid having this
- * class dependent on the PostScript renderer. After this is all
- * moved to the Graphics package, this needs to be reworked.
- * The "graphic" needs to be a real Graphic instance of the proper
- * type, and should then be converted to PostScript here. */
- graphic.close();
-// this.psRenderer.renderBitmap(graphic, x, -y, width, height);
- this.out.write("grestore");
- } catch (final Exception e) {
- e.printStackTrace();
- }
- return true;
- }
-
- /**
-...
[truncated message content] |