| 1 |
/* ===================================================================== |
| 2 |
* JFreePDF : a fast, light-weight PDF library for the Java(tm) platform |
| 3 |
* ===================================================================== |
| 4 |
* |
| 5 |
* (C)opyright 2013-2022, by David Gilbert. All rights reserved. |
| 6 |
* |
| 7 |
* https://github.com/jfree/orsonpdf |
| 8 |
* |
| 9 |
* This program is free software: you can redistribute it and/or modify |
| 10 |
* it under the terms of the GNU General Public License as published by |
| 11 |
* the Free Software Foundation, either version 3 of the License, or |
| 12 |
* (at your option) any later version. |
| 13 |
* |
| 14 |
* This program is distributed in the hope that it will be useful, |
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
* GNU General Public License for more details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
* |
| 22 |
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
| 23 |
* Other names may be trademarks of their respective owners.] |
| 24 |
* |
| 25 |
* If you do not wish to be bound by the terms of the GPL, an alternative |
| 26 |
* runtime license is available to JFree sponsors: |
| 27 |
* |
| 28 |
* https://github.com/sponsors/jfree |
| 29 |
* |
| 30 |
*/ |
| 31 |
|
| 32 |
package org.jfree.pdf; |
| 33 |
|
| 34 |
import java.awt.AWTException; |
| 35 |
import java.awt.GraphicsConfiguration; |
| 36 |
import java.awt.GraphicsDevice; |
| 37 |
import java.awt.ImageCapabilities; |
| 38 |
import java.awt.Rectangle; |
| 39 |
import java.awt.Transparency; |
| 40 |
import java.awt.geom.AffineTransform; |
| 41 |
import java.awt.image.BufferedImage; |
| 42 |
import java.awt.image.ColorModel; |
| 43 |
import java.awt.image.DirectColorModel; |
| 44 |
import java.awt.image.VolatileImage; |
| 45 |
|
| 46 |
/** |
| 47 |
* A graphics configuration for the {@link PDFGraphics2D} class. |
| 48 |
*/ |
| 49 |
public class PDFGraphicsConfiguration extends GraphicsConfiguration { |
| 50 |
|
| 51 |
private GraphicsDevice device; |
| 52 |
|
| 53 |
private int width, height; |
| 54 |
|
| 55 |
/** |
| 56 |
* Creates a new instance. |
| 57 |
* |
| 58 |
* @param width the width of the bounds. |
| 59 |
* @param height the height of the bounds. |
| 60 |
*/ |
| 61 |
public PDFGraphicsConfiguration(int width, int height) { |
| 62 |
super(); |
| 63 |
this.width = width; |
| 64 |
this.height = height; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Returns the graphics device that this configuration is associated with. |
| 69 |
* |
| 70 |
* @return The graphics device (never {@code null}). |
| 71 |
*/ |
| 72 |
@Override |
| 73 |
public GraphicsDevice getDevice() { |
| 74 |
if (this.device == null) { |
| 75 |
this.device = new PDFGraphicsDevice("JFreePDF-GraphicsDevice", |
| 76 |
this); |
| 77 |
} |
| 78 |
return this.device; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns the color model for this configuration. |
| 83 |
* |
| 84 |
* @return The color model. |
| 85 |
*/ |
| 86 |
@Override |
| 87 |
public ColorModel getColorModel() { |
| 88 |
return getColorModel(Transparency.TRANSLUCENT); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Returns the color model for the specified transparency type, or |
| 93 |
* {@code null}. |
| 94 |
* |
| 95 |
* @param transparency the transparency type. |
| 96 |
* |
| 97 |
* @return A color model (possibly {@code null}). |
| 98 |
*/ |
| 99 |
@Override |
| 100 |
public ColorModel getColorModel(int transparency) { |
| 101 |
if (transparency == Transparency.TRANSLUCENT) { |
| 102 |
return ColorModel.getRGBdefault(); |
| 103 |
} else if (transparency == Transparency.OPAQUE) { |
| 104 |
return new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff); |
| 105 |
} else { |
| 106 |
return null; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Returns the default transform. |
| 112 |
* |
| 113 |
* @return The default transform. |
| 114 |
*/ |
| 115 |
@Override |
| 116 |
public AffineTransform getDefaultTransform() { |
| 117 |
return new AffineTransform(); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Returns the normalizing transform. |
| 122 |
* |
| 123 |
* @return The normalizing transform. |
| 124 |
*/ |
| 125 |
@Override |
| 126 |
public AffineTransform getNormalizingTransform() { |
| 127 |
return new AffineTransform(); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Returns the bounds for this configuration. |
| 132 |
* |
| 133 |
* @return The bounds. |
| 134 |
*/ |
| 135 |
@Override |
| 136 |
public Rectangle getBounds() { |
| 137 |
return new Rectangle(this.width, this.height); |
| 138 |
} |
| 139 |
|
| 140 |
private BufferedImage img = new BufferedImage(10, 10, |
| 141 |
BufferedImage.TYPE_INT_ARGB); |
| 142 |
|
| 143 |
@Override |
| 144 |
public VolatileImage createCompatibleVolatileImage(int width, int height, |
| 145 |
ImageCapabilities caps, int transparency) throws AWTException { |
| 146 |
return img.createGraphics().getDeviceConfiguration() |
| 147 |
.createCompatibleVolatileImage(width, height, caps, |
| 148 |
transparency); |
| 149 |
} |
| 150 |
|
| 151 |
} |