cvs commit: xml-fop/src/org/apache/fop/render/ps PSGraphics2D.java PSRenderer.java
jeremias2003/01/08 06:03:35 Modified:src/org/apache/fop/render/ps PSGraphics2D.java PSRenderer.java Log: Adjustments for font refactoring Lots of Javadocs Fixed Checkstyle errors Revision ChangesPath 1.7 +125 -52 xml-fop/src/org/apache/fop/render/ps/PSGraphics2D.java Index: PSGraphics2D.java === RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/ps/PSGraphics2D.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PSGraphics2D.java 27 Jun 2002 11:45:55 - 1.6 +++ PSGraphics2D.java 8 Jan 2003 14:03:35 - 1.7 @@ -1,34 +1,54 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2003 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.render.ps; -import org.apache.fop.pdf.*; -import org.apache.fop.layout.*; -import org.apache.fop.fonts.*; -import org.apache.fop.render.pdf.*; -import org.apache.fop.image.*; -import org.apache.fop.fo.FOUserAgent; - -import org.apache.batik.ext.awt.g2d.*; - +//Java +import java.util.List; import java.text.AttributedCharacterIterator; import java.text.CharacterIterator; -import java.awt.*; +import java.awt.AlphaComposite; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Dimension; import java.awt.Font; +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.image.*; -import java.awt.font.*; -import java.awt.geom.*; -import java.awt.image.renderable.*; -import java.io.*; +import java.awt.Paint; +import java.awt.Rectangle; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.TexturePaint; +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; + +// FOP +import org.apache.fop.layout.FontInfo; +import org.apache.fop.layout.FontState; +import org.apache.fop.pdf.PDFColor; +//import org.apache.fop.pdf.PDFColorSpace; +import org.apache.fop.pdf.PDFNumber; + +// Batik +import org.apache.batik.ext.awt.g2d.AbstractGraphics2D; +import org.apache.batik.ext.awt.g2d.GraphicContext; -import java.util.Map; -import java.util.ArrayList; /** * This concrete implementation of AbstractGraphics2D is a @@ -43,13 +63,15 @@ * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D */ public class PSGraphics2D extends AbstractGraphics2D { -boolean standalone = false; + +private boolean standalone = false; /** * the PDF Document being created */ protected PSRenderer psRenderer; +/** Currently valid FontState */ protected FontState fontState; /** @@ -75,14 +97,21 @@ /** * the current colour for use in svg */ -PDFColor currentColour = new PDFColor(0, 0, 0); +protected PDFColor currentColour = new PDFColor(0, 0, 0); -FontInfo fontInfo; +/** FontInfo containing all available fonts */ +protected FontInfo fontInfo; /** - * 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. + * Create a new Graphics2D that generates PostScript code. + * @param textAsShapes True if text should be rendered as graphics + * @param fs currently valid FontState object + * @param ren PostScript renderer + * @param font current font name + * @param size current font size + * @param xpos current x pos + * @param ypos current y pos + * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D#AbstractGraphics2D(boolean) */ public PSGraphics2D(boolean textAsShapes, FontState fs, PSRenderer ren, String font, int size, int xpos, int ypos) { @@ -95,22 +124,31 @@ fontState = fs; } +/** + * Create a new Graphics2D that generates PostScript code. + * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D#AbstractGraphics2D(boolean) + */ public PSGraphics2D(boolean textAsShapes) { super(textAsShapes); } -public void setGraphicContext(GraphicContext c) { -gc = c;
cvs commit: xml-fop/src/org/apache/fop/render/ps PSGraphics2D.java PSRenderer.java
keiron 01/06/22 07:16:48 Modified:src/org/apache/fop/render/ps PSRenderer.java Added: src/org/apache/fop/render/ps PSGraphics2D.java Log: added support for rendering SVG graphics to ps not fully functional Revision ChangesPath 1.2 +210 -5xml-fop/src/org/apache/fop/render/ps/PSRenderer.java Index: PSRenderer.java === RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/ps/PSRenderer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PSRenderer.java 2001/06/22 09:08:50 1.1 +++ PSRenderer.java 2001/06/22 14:16:46 1.2 @@ -1,4 +1,4 @@ -/* $Id: PSRenderer.java,v 1.1 2001/06/22 09:08:50 keiron Exp $ +/* $Id: PSRenderer.java,v 1.2 2001/06/22 14:16:46 keiron Exp $ * 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. @@ -18,14 +18,36 @@ import org.apache.fop.datatypes.*; import org.apache.fop.fo.properties.*; import org.apache.fop.render.pdf.Font; +import org.apache.fop.image.*; +import org.apache.batik.bridge.*; +import org.apache.batik.swing.svg.*; +import org.apache.batik.swing.gvt.*; +import org.apache.batik.gvt.*; +import org.apache.batik.gvt.renderer.*; +import org.apache.batik.gvt.filter.*; +import org.apache.batik.gvt.event.*; + // SVG import org.w3c.dom.svg.SVGSVGElement; import org.w3c.dom.svg.SVGDocument; +import org.w3c.dom.*; +import org.w3c.dom.svg.*; // Java import java.io.*; import java.util.*; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Enumeration; +import java.util.Vector; +import java.util.Hashtable; +import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; +import java.awt.Point; +import java.awt.RenderingHints; +import java.awt.font.FontRenderContext; +import java.awt.Dimension; /** * Renderer that renders to PostScript. @@ -401,17 +423,94 @@ public void renderSVGArea(SVGArea area) { int x = this.currentXPosition; int y = this.currentYPosition; -SVGSVGElement svg = - ((SVGDocument) area.getSVGDocument()).getRootElement(); +Document doc = area.getSVGDocument(); +SVGSVGElement svg = ((SVGDocument)doc).getRootElement(); int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000); int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000); +float sx = 1, sy = -1; +int xOffset = x, yOffset = y; +/* + * Clip to the svg area. + * Note: To have the svg overlay (under) a text area then use + * an fo:block-container + */ comment("% --- SVG Area"); -/**@todo Implement SVG */ +write("gsave"); +if (w != 0 && h != 0) { +/*write("newpath"); +write(x / 1000f + " " + y / 1000f + " M"); +write((x + w) / 1000f + " " + y / 1000f + " rlineto"); +write((x + w) / 1000f + " " + (y - h) / 1000f + + " rlineto"); +write(x / 1000f + " " + (y - h) / 1000f + " rlineto"); +write("closepath"); +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. +write(xOffset + + " " + yOffset + " translate"); +write(sx + " " + sy + " " + " scale"); + + +UserAgent userAgent = new MUserAgent(new AffineTransform()); + +GVTBuilder builder = new GVTBuilder(); +GraphicsNodeRenderContext rc = getRenderContext(); +BridgeContext ctx = new BridgeContext(userAgent, rc); +GraphicsNode root; +PSGraphics2D graphics = + new PSGraphics2D(false, area.getFontState(), this, +currentFontName, currentFontSize, currentXPosition, +currentYPosition); +graphics.setGraphicContext( + new org.apache.batik.ext.awt.g2d.GraphicContext()); +graphics.setRenderingHints(rc.getRenderingHints()); +try { +root = builder.build(ctx, doc); +root.paint(graphics, rc); +} catch (Exception e) { +MessageHandler.errorln("Error: svg graphic could not be rendered: " + e.getMessage()); +//e.printStackTrace(); +} + +write("grestore"); + comment("% --- SVG Area end"); movetoCurrPosition(); } +public GraphicsNodeRenderContext getRenderContext() { +GraphicsNodeRenderContext nodeRenderContext = n