001/* =====================================================================
002 * JFreePDF : a fast, light-weight PDF library for the Java(tm) platform
003 * =====================================================================
004 * 
005 * (C)opyright 2013-2020, by Object Refinery Limited.  All rights reserved.
006 *
007 * Project Info:  http://www.object-refinery.com/orsonpdf/index.html
008 * 
009 * This program is free software: you can redistribute it and/or modify
010 * it under the terms of the GNU General Public License as published by
011 * the Free Software Foundation, either version 3 of the License, or
012 * (at your option) any later version.
013 *
014 * This program is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 *
019 * You should have received a copy of the GNU General Public License
020 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
021 * 
022 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
023 * Other names may be trademarks of their respective owners.]
024 * 
025 * If you do not wish to be bound by the terms of the GPL, an alternative
026 * commercial license can be purchased.  For details, please see visit the
027 * Orson PDF home page:
028 * 
029 * http://www.object-refinery.com/orsonpdf/index.html
030 * 
031 */
032
033package org.jfree.pdf;
034
035import java.awt.AWTException;
036import java.awt.GraphicsConfiguration;
037import java.awt.GraphicsDevice;
038import java.awt.ImageCapabilities;
039import java.awt.Rectangle;
040import java.awt.Transparency;
041import java.awt.geom.AffineTransform;
042import java.awt.image.BufferedImage;
043import java.awt.image.ColorModel;
044import java.awt.image.DirectColorModel;
045import java.awt.image.VolatileImage;
046
047/**
048 * A graphics configuration for the {@link PDFGraphics2D} class.
049 */
050public class PDFGraphicsConfiguration extends GraphicsConfiguration {
051
052    private GraphicsDevice device;
053    
054    private int width, height;
055    
056    /**
057     * Creates a new instance.
058     * 
059     * @param width  the width of the bounds.
060     * @param height  the height of the bounds.
061     */
062    public PDFGraphicsConfiguration(int width, int height) {
063      super(); 
064      this.width = width;
065      this.height = height;
066    }
067    
068    /**
069     * Returns the graphics device that this configuration is associated with.
070     * 
071     * @return The graphics device (never {@code null}).
072     */
073    @Override
074    public GraphicsDevice getDevice() {
075        if (this.device == null) {
076            this.device = new PDFGraphicsDevice("JFreePDF-GraphicsDevice", 
077                    this);
078        }
079        return this.device;
080    }
081
082    /**
083     * Returns the color model for this configuration.
084     * 
085     * @return The color model.
086     */
087    @Override
088    public ColorModel getColorModel() {
089        return getColorModel(Transparency.TRANSLUCENT);
090    }
091
092    /**
093     * Returns the color model for the specified transparency type, or 
094     * {@code null}.
095     * 
096     * @param transparency  the transparency type.
097     * 
098     * @return A color model (possibly {@code null}).
099     */
100    @Override
101    public ColorModel getColorModel(int transparency) {
102        if (transparency == Transparency.TRANSLUCENT) {
103            return ColorModel.getRGBdefault();
104        } else if (transparency == Transparency.OPAQUE) {
105            return new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff);
106        } else {
107            return null;
108        }
109    }
110
111    /**
112     * Returns the default transform.
113     * 
114     * @return The default transform. 
115     */
116    @Override
117    public AffineTransform getDefaultTransform() {
118        return new AffineTransform();
119    }
120
121    /**
122     * Returns the normalizing transform.
123     * 
124     * @return The normalizing transform. 
125     */
126    @Override
127    public AffineTransform getNormalizingTransform() {
128        return new AffineTransform();
129    }
130    
131    /**
132     * Returns the bounds for this configuration.
133     * 
134     * @return The bounds. 
135     */
136    @Override
137    public Rectangle getBounds() {
138        return new Rectangle(this.width, this.height);
139    }
140        
141    private BufferedImage img = new BufferedImage(10, 10, 
142            BufferedImage.TYPE_INT_ARGB);
143    
144    @Override
145    public VolatileImage createCompatibleVolatileImage(int width, int height, 
146            ImageCapabilities caps, int transparency) throws AWTException {
147        return img.createGraphics().getDeviceConfiguration()
148                .createCompatibleVolatileImage(width, height, caps, 
149                        transparency);
150    }
151
152}