2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
/* $Id: PSGraphics2DAdapter.java 426576 2006-07-28 15:44:37Z jeremias $ */
20
package org.apache.fop.render.ps;
22
import java.awt.Dimension;
23
import java.awt.geom.AffineTransform;
24
import java.awt.geom.Rectangle2D;
25
import java.io.IOException;
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;
34
* Graphics2DAdapter implementation for PostScript.
36
public class PSGraphics2DAdapter implements Graphics2DAdapter {
38
private PSRenderer renderer;
42
* @param renderer the Renderer instance to which this instance belongs
44
public PSGraphics2DAdapter(PSRenderer renderer) {
45
this.renderer = renderer;
48
/** @see org.apache.fop.render.Graphics2DAdapter */
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;
54
float fwidth = width / 1000f;
55
float fheight = height / 1000f;
59
// get the 'width' and 'height' attributes of the SVG document
60
Dimension dim = painter.getImageSize();
61
float imw = (float)dim.getWidth() / 1000f;
62
float imh = (float)dim.getHeight() / 1000f;
64
float sx = fwidth / (float)imw;
65
float sy = fheight / (float)imh;
67
gen.commentln("%FOPBeginGraphics2D");
68
gen.saveGraphicsState();
69
// Clip to the image area.
70
gen.writeln("newpath");
71
gen.defineRect(fx, fy, fwidth, fheight);
74
// transform so that the coordinates (0,0) is from the top left
75
// and positive is down and to the right. (0,0) is where the
77
gen.concatMatrix(sx, 0, 0, sy, fx, fy);
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();
84
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);
89
gen.restoreGraphicsState();
90
gen.commentln("%FOPEndGraphics2D");