Path: blob/master/src/java.desktop/share/classes/sun/print/PrinterGraphicsConfig.java
41153 views
/*1* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.print;2627import java.awt.GraphicsConfiguration;28import java.awt.GraphicsDevice;29import java.awt.Rectangle;30import java.awt.Transparency;31import java.awt.geom.AffineTransform;32import java.awt.image.BufferedImage;33import java.awt.image.ColorModel;34import java.awt.image.DirectColorModel;3536public final class PrinterGraphicsConfig extends GraphicsConfiguration {3738static ColorModel theModel;3940private final GraphicsDevice device;41private final int pageWidth;42private final int pageHeight;43private final AffineTransform deviceTransform;4445public PrinterGraphicsConfig(String printerID, AffineTransform deviceTx,46int pageWid, int pageHgt) {47this.pageWidth = pageWid;48this.pageHeight = pageHgt;49this.deviceTransform = deviceTx;50this.device = new PrinterGraphicsDevice(this, printerID);51}5253/**54* Return the graphics device associated with this configuration.55*/56@Override57public GraphicsDevice getDevice() {58return device;59}6061/**62* Returns the color model associated with this configuration.63*/64@Override65public ColorModel getColorModel() {66if (theModel == null) {67BufferedImage bufImg =68new BufferedImage(1,1, BufferedImage.TYPE_3BYTE_BGR);69theModel = bufImg.getColorModel();70}7172return theModel;73}7475/**76* Returns the color model associated with this configuration that77* supports the specified transparency.78*/79@Override80public ColorModel getColorModel(int transparency) {81switch (transparency) {82case Transparency.OPAQUE:83return getColorModel();84case Transparency.BITMASK:85return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);86case Transparency.TRANSLUCENT:87return ColorModel.getRGBdefault();88default:89return null;90}91}9293/**94* Returns the default Transform for this configuration. This95* Transform is typically the Identity transform for most normal96* screens. Device coordinates for screen and printer devices will97* have the origin in the upper left-hand corner of the target region of98* the device, with X coordinates99* increasing to the right and Y coordinates increasing downwards.100* For image buffers, this Transform will be the Identity transform.101*/102@Override103public AffineTransform getDefaultTransform() {104return new AffineTransform(deviceTransform);105}106107/**108*109* Returns a Transform that can be composed with the default Transform110* of a Graphics2D so that 72 units in user space will equal 1 inch111* in device space.112* Given a Graphics2D, g, one can reset the transformation to create113* such a mapping by using the following pseudocode:114* <pre>115* GraphicsConfiguration gc = g.getGraphicsConfiguration();116*117* g.setTransform(gc.getDefaultTransform());118* g.transform(gc.getNormalizingTransform());119* </pre>120* Note that sometimes this Transform will be identity (e.g. for121* printers or metafile output) and that this Transform is only122* as accurate as the information supplied by the underlying system.123* For image buffers, this Transform will be the Identity transform,124* since there is no valid distance measurement.125*/126@Override127public AffineTransform getNormalizingTransform() {128return new AffineTransform();129}130131@Override132public Rectangle getBounds() {133return new Rectangle(0, 0, pageWidth, pageHeight);134}135}136137138