1 17 18 19 20 package org.apache.fop.render.ps; 21 22 import java.awt.Dimension ; 23 import java.awt.geom.AffineTransform ; 24 import java.awt.geom.Rectangle2D ; 25 import java.io.IOException ; 26 27 import org.apache.fop.render.Graphics2DAdapter; 28 import org.apache.fop.render.Graphics2DImagePainter; 29 import org.apache.fop.render.RendererContext; 30 import org.apache.xmlgraphics.java2d.ps.PSGraphics2D; 31 import org.apache.xmlgraphics.ps.PSGenerator; 32 33 36 public class PSGraphics2DAdapter implements Graphics2DAdapter { 37 38 private PSRenderer renderer; 39 40 44 public PSGraphics2DAdapter(PSRenderer renderer) { 45 this.renderer = renderer; 46 } 47 48 49 public void paintImage(Graphics2DImagePainter painter, 50 RendererContext context, 51 int x, int y, int width, int height) throws IOException { 52 PSGenerator gen = renderer.gen; 53 54 float fwidth = width / 1000f; 55 float fheight = height / 1000f; 56 float fx = x / 1000f; 57 float fy = y / 1000f; 58 59 Dimension dim = painter.getImageSize(); 61 float imw = (float)dim.getWidth() / 1000f; 62 float imh = (float)dim.getHeight() / 1000f; 63 64 float sx = fwidth / (float)imw; 65 float sy = fheight / (float)imh; 66 67 gen.commentln("%FOPBeginGraphics2D"); 68 gen.saveGraphicsState(); 69 gen.writeln("newpath"); 71 gen.defineRect(fx, fy, fwidth, fheight); 72 gen.writeln("clip"); 73 74 gen.concatMatrix(sx, 0, 0, sy, fx, fy); 78 79 final boolean textAsShapes = false; 80 PSGraphics2D graphics = new PSGraphics2D(textAsShapes, gen); 81 graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); 82 AffineTransform transform = new AffineTransform (); 83 transform.translate(fx, fy); 85 gen.getCurrentState().concatMatrix(transform); 86 Rectangle2D area = new Rectangle2D.Double (0.0, 0.0, imw, imh); 87 painter.paint(graphics, area); 88 89 gen.restoreGraphicsState(); 90 gen.commentln("%FOPEndGraphics2D"); 91 } 92 93 } 94 | Popular Tags |