KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > svg > PDFGraphicsConfiguration


1 /*
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */

17
18 /* $Id: PDFGraphicsConfiguration.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.svg;
21
22 import java.awt.Rectangle JavaDoc;
23 import java.awt.GraphicsDevice JavaDoc;
24 import java.awt.Transparency JavaDoc;
25 import java.awt.image.ColorModel JavaDoc;
26 import java.awt.geom.AffineTransform JavaDoc;
27 import java.awt.image.BufferedImage JavaDoc;
28
29 /**
30  * Our implementation of the class that returns information about
31  * roughly what we can handle and want to see (alpha for example).
32  */

33 class PDFGraphicsConfiguration extends GraphicsConfiguration {
34     // We use this to get a good colormodel..
35
private static final BufferedImage JavaDoc BI_WITH_ALPHA =
36         new BufferedImage JavaDoc(1, 1, BufferedImage.TYPE_INT_ARGB);
37     // We use this to get a good colormodel..
38
private static final BufferedImage JavaDoc BI_WITHOUT_ALPHA =
39         new BufferedImage JavaDoc(1, 1, BufferedImage.TYPE_INT_RGB);
40
41     /**
42      * Construct a buffered image with an alpha channel, unless
43      * transparencty is OPAQUE (no alpha at all).
44      *
45      * @param width the width of the image
46      * @param height the height of the image
47      * @param transparency the alpha value of the image
48      * @return the new buffered image
49      */

50     public BufferedImage JavaDoc createCompatibleImage(int width, int height,
51             int transparency) {
52         if (transparency == Transparency.OPAQUE) {
53             return new BufferedImage JavaDoc(width, height,
54                                      BufferedImage.TYPE_INT_RGB);
55         } else {
56             return new BufferedImage JavaDoc(width, height,
57                                      BufferedImage.TYPE_INT_ARGB);
58         }
59     }
60
61     /**
62      * Construct a buffered image with an alpha channel.
63      *
64      * @param width the width of the image
65      * @param height the height of the image
66      * @return the new buffered image
67      */

68     public BufferedImage JavaDoc createCompatibleImage(int width, int height) {
69         return new BufferedImage JavaDoc(width, height,
70                                  BufferedImage.TYPE_INT_ARGB);
71     }
72
73     /**
74      * TODO: This should return the page bounds in Pts,
75      * I couldn't figure out how to get this for the current
76      * page from the PDFDocument (this still works for now,
77      * but it should be fixed...).
78      *
79      * @return the bounds of the PDF document page
80      */

81     public Rectangle JavaDoc getBounds() {
82         return null;
83     }
84
85     /**
86      * Return a good default color model for this 'device'.
87      * @return the colour model for the configuration
88      */

89     public ColorModel JavaDoc getColorModel() {
90         return BI_WITH_ALPHA.getColorModel();
91     }
92
93     /**
94      * Return a good color model given <tt>transparency</tt>
95      *
96      * @param transparency the alpha value for the colour model
97      * @return the colour model for the configuration
98      */

99     public ColorModel JavaDoc getColorModel(int transparency) {
100         if (transparency == Transparency.OPAQUE) {
101             return BI_WITHOUT_ALPHA.getColorModel();
102         } else {
103             return BI_WITH_ALPHA.getColorModel();
104         }
105     }
106
107     /**
108      * The default transform (1:1).
109      *
110      * @return the default transform for the configuration
111      */

112     public AffineTransform JavaDoc getDefaultTransform() {
113         return new AffineTransform JavaDoc();
114     }
115
116     /**
117      * The normalizing transform (1:1) (since we currently
118      * render images at 72dpi, which we might want to change
119      * in the future).
120      *
121      * @return the normalizing transform for the configuration
122      */

123     public AffineTransform JavaDoc getNormalizingTransform() {
124         return new AffineTransform JavaDoc(2, 0, 0, 2, 0, 0);
125     }
126
127     /**
128      * Return our dummy instance of GraphicsDevice
129      *
130      * @return the PDF graphics device
131      */

132     public GraphicsDevice JavaDoc getDevice() {
133         return new PDFGraphicsDevice(this);
134     }
135
136 }
137
138
Popular Tags