1 /* 2 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.lwawt.macosx; 27 28 import java.awt.Component; 29 import java.awt.Graphics2D; 30 import java.awt.GraphicsConfiguration; 31 import java.awt.GraphicsDevice; 32 import java.awt.Rectangle; 33 import java.awt.Transparency; 34 import java.awt.geom.AffineTransform; 35 import java.awt.image.BufferedImage; 36 import java.awt.image.ColorModel; 37 import java.awt.image.VolatileImage; 38 import java.awt.print.PageFormat; 39 40 public final class CPrinterGraphicsConfig extends GraphicsConfiguration { 41 getConfig(PageFormat pf)42 public static CPrinterGraphicsConfig getConfig(PageFormat pf) { 43 return new CPrinterGraphicsConfig(pf); 44 } 45 46 private final GraphicsDevice device; 47 private final PageFormat pf; 48 CPrinterGraphicsConfig(PageFormat pf)49 public CPrinterGraphicsConfig(PageFormat pf) { 50 this.device = new CPrinterDevice(this); 51 this.pf = pf; 52 } 53 getPageFormat()54 public PageFormat getPageFormat() { 55 return pf; 56 } 57 58 /** 59 * Returns the {@link GraphicsDevice} associated with this 60 * {@code GraphicsConfiguration}. 61 * @return a {@code GraphicsDevice} object that is 62 * associated with this {@code GraphicsConfiguration}. 63 */ 64 @Override getDevice()65 public GraphicsDevice getDevice() { 66 return device; 67 } 68 69 /** 70 * Returns a {@link BufferedImage} with a data layout and color model 71 * compatible with this {@code GraphicsConfiguration}. This 72 * method has nothing to do with memory-mapping 73 * a device. The returned {@code BufferedImage} has 74 * a layout and color model that is closest to this native device 75 * configuration and can therefore be optimally blitted to this 76 * device. 77 * @param width the width of the returned {@code BufferedImage} 78 * @param height the height of the returned {@code BufferedImage} 79 * @return a {@code BufferedImage} whose data layout and color 80 * model is compatible with this {@code GraphicsConfiguration}. 81 */ 82 @Override createCompatibleImage(int width, int height)83 public BufferedImage createCompatibleImage(int width, int height) { 84 return createCompatibleImage(width, height, Transparency.OPAQUE); 85 } 86 87 /** 88 * Returns a {@link VolatileImage} with a data layout and color model 89 * compatible with this {@code GraphicsConfiguration}. 90 * The returned {@code VolatileImage} 91 * may have data that is stored optimally for the underlying graphics 92 * device and may therefore benefit from platform-specific rendering 93 * acceleration. 94 * @param width the width of the returned {@code VolatileImage} 95 * @param height the height of the returned {@code VolatileImage} 96 * @return a {@code VolatileImage} whose data layout and color 97 * model is compatible with this {@code GraphicsConfiguration}. 98 * @see Component#createVolatileImage(int, int) 99 */ 100 @Override createCompatibleVolatileImage(int width, int height)101 public VolatileImage createCompatibleVolatileImage(int width, int height) { 102 return createCompatibleVolatileImage(width, height, Transparency.OPAQUE); 103 } 104 105 // empty implementation (this should not be called) 106 @Override createCompatibleVolatileImage(int width, int height, int transparency)107 public VolatileImage createCompatibleVolatileImage(int width, int height, int transparency) { 108 return null; 109 } 110 111 /** 112 * Returns a {@code BufferedImage} that supports the specified 113 * transparency and has a data layout and color model 114 * compatible with this {@code GraphicsConfiguration}. This 115 * method has nothing to do with memory-mapping 116 * a device. The returned {@code BufferedImage} has a layout and 117 * color model that can be optimally blitted to a device 118 * with this {@code GraphicsConfiguration}. 119 * @param width the width of the returned {@code BufferedImage} 120 * @param height the height of the returned {@code BufferedImage} 121 * @param transparency the specified transparency mode 122 * @return a {@code BufferedImage} whose data layout and color 123 * model is compatible with this {@code GraphicsConfiguration} 124 * and also supports the specified transparency. 125 * @see Transparency#OPAQUE 126 * @see Transparency#BITMASK 127 * @see Transparency#TRANSLUCENT 128 */ 129 @Override createCompatibleImage(int width, int height, int transparency)130 public BufferedImage createCompatibleImage(int width, int height, int transparency) { 131 //+++gdb what to do? 132 return null; 133 } 134 135 /** 136 * Returns the {@link ColorModel} associated with this 137 * {@code GraphicsConfiguration}. 138 * @return a {@code ColorModel} object that is associated with 139 * this {@code GraphicsConfiguration}. 140 */ 141 @Override getColorModel()142 public ColorModel getColorModel() { 143 return getColorModel(Transparency.OPAQUE); 144 } 145 146 /** 147 * Returns the {@code ColorModel} associated with this 148 * {@code GraphicsConfiguration} that supports the specified 149 * transparency. 150 * @param transparency the specified transparency mode 151 * @return a {@code ColorModel} object that is associated with 152 * this {@code GraphicsConfiguration} and supports the 153 * specified transparency. 154 */ 155 @Override getColorModel(int transparency)156 public ColorModel getColorModel(int transparency) { 157 return ColorModel.getRGBdefault(); 158 } 159 160 /** 161 * Returns the default {@link AffineTransform} for this 162 * {@code GraphicsConfiguration}. This 163 * {@code AffineTransform} is typically the Identity transform 164 * for most normal screens. The default {@code AffineTransform} 165 * maps coordinates onto the device such that 72 user space 166 * coordinate units measure approximately 1 inch in device 167 * space. The normalizing transform can be used to make 168 * this mapping more exact. Coordinates in the coordinate space 169 * defined by the default {@code AffineTransform} for screen and 170 * printer devices have the origin in the upper left-hand corner of 171 * the target region of the device, with X coordinates 172 * increasing to the right and Y coordinates increasing downwards. 173 * For image buffers not associated with a device, such as those not 174 * created by {@code createCompatibleImage}, 175 * this {@code AffineTransform} is the Identity transform. 176 * @return the default {@code AffineTransform} for this 177 * {@code GraphicsConfiguration}. 178 */ 179 @Override getDefaultTransform()180 public AffineTransform getDefaultTransform() { 181 return new AffineTransform(); 182 } 183 184 /** 185 * Returns an {@code AffineTransform} that can be concatenated 186 * with the default {@code AffineTransform} 187 * of a {@code GraphicsConfiguration} so that 72 units in user 188 * space equals 1 inch in device space. 189 * <p> 190 * For a particular {@link Graphics2D}, g, one 191 * can reset the transformation to create 192 * such a mapping by using the following pseudocode: 193 * <pre> 194 * GraphicsConfiguration gc = g.getGraphicsConfiguration(); 195 * 196 * g.setTransform(gc.getDefaultTransform()); 197 * g.transform(gc.getNormalizingTransform()); 198 * </pre> 199 * Note that sometimes this {@code AffineTransform} is identity, 200 * such as for printers or metafile output, and that this 201 * {@code AffineTransform} is only as accurate as the information 202 * supplied by the underlying system. For image buffers not 203 * associated with a device, such as those not created by 204 * {@code createCompatibleImage}, this 205 * {@code AffineTransform} is the Identity transform 206 * since there is no valid distance measurement. 207 * @return an {@code AffineTransform} to concatenate to the 208 * default {@code AffineTransform} so that 72 units in user 209 * space is mapped to 1 inch in device space. 210 */ 211 @Override getNormalizingTransform()212 public AffineTransform getNormalizingTransform() { 213 return new AffineTransform(); 214 } 215 216 /** 217 * Returns the bounds of the {@code GraphicsConfiguration} 218 * in the device coordinates. In a multi-screen environment 219 * with a virtual device, the bounds can have negative X 220 * or Y origins. 221 * @return the bounds of the area covered by this 222 * {@code GraphicsConfiguration}. 223 * @since 1.3 224 */ 225 @Override getBounds()226 public Rectangle getBounds() { 227 return new Rectangle(0, 0, (int)pf.getWidth(), (int)pf.getHeight()); 228 } 229 } 230