01: /*
02: * $Id: PDFPaint.java,v 1.3 2007/12/20 18:17:41 rbair Exp $
03: *
04: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
05: * Santa Clara, California 95054, U.S.A. All rights reserved.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20: */
21:
22: package com.sun.pdfview;
23:
24: import java.awt.Color;
25: import java.awt.Graphics2D;
26: import java.awt.Paint;
27: import java.awt.geom.GeneralPath;
28: import java.awt.geom.Rectangle2D;
29:
30: /**
31: * PDFPaint is some kind of shader that knows how to fill a path.
32: * At the moment, only a solid color is implemented, but gradients
33: * and textures should be possible, too.
34: * @author Mike Wessler
35: */
36: public class PDFPaint {
37: private Paint mainPaint;
38:
39: /**
40: * create a new PDFPaint based on a solid color
41: */
42: protected PDFPaint(Paint p) {
43: this .mainPaint = p;
44: }
45:
46: /**
47: * get the PDFPaint representing a solid color
48: */
49: public static PDFPaint getColorPaint(Color c) {
50: return getPaint(c);
51: }
52:
53: /**
54: * get the PDFPaint representing a generic paint
55: */
56: public static PDFPaint getPaint(Paint p) {
57: return new PDFPaint(p);
58: }
59:
60: /**
61: * fill a path with the paint, and record the dirty area.
62: * @param state the current graphics state
63: * @param g the graphics into which to draw
64: * @param s the path to fill
65: */
66: public Rectangle2D fill(PDFRenderer state, Graphics2D g,
67: GeneralPath s) {
68: g.setPaint(mainPaint);
69: g.fill(s);
70:
71: return s.createTransformedShape(g.getTransform()).getBounds2D();
72: }
73:
74: /**
75: * get the primary color associated with this PDFPaint.
76: */
77: public Paint getPaint() {
78: return mainPaint;
79: }
80: }
|