Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/print/PrinterGraphicsConfig.java
38829 views
/*1* Copyright (c) 2004, 2007, 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;2930import java.awt.Rectangle;31import java.awt.Transparency;32import java.awt.geom.AffineTransform;33import java.awt.image.BufferedImage;34import java.awt.image.ColorModel;35import java.awt.image.DirectColorModel;3637public class PrinterGraphicsConfig extends GraphicsConfiguration {3839static ColorModel theModel;4041GraphicsDevice gd;42int pageWidth, pageHeight;43AffineTransform deviceTransform;4445public PrinterGraphicsConfig(String printerID, AffineTransform deviceTx,46int pageWid, int pageHgt) {47this.pageWidth = pageWid;48this.pageHeight = pageHgt;49this.deviceTransform = deviceTx;50this.gd = new PrinterGraphicsDevice(this, printerID);51}5253/**54* Return the graphics device associated with this configuration.55*/56public GraphicsDevice getDevice() {57return gd;58}5960/**61* Returns the color model associated with this configuration.62*/63public ColorModel getColorModel() {64if (theModel == null) {65BufferedImage bufImg =66new BufferedImage(1,1, BufferedImage.TYPE_3BYTE_BGR);67theModel = bufImg.getColorModel();68}6970return theModel;71}7273/**74* Returns the color model associated with this configuration that75* supports the specified transparency.76*/77public ColorModel getColorModel(int transparency) {78switch (transparency) {79case Transparency.OPAQUE:80return getColorModel();81case Transparency.BITMASK:82return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);83case Transparency.TRANSLUCENT:84return ColorModel.getRGBdefault();85default:86return null;87}88}8990/**91* Returns the default Transform for this configuration. This92* Transform is typically the Identity transform for most normal93* screens. Device coordinates for screen and printer devices will94* have the origin in the upper left-hand corner of the target region of95* the device, with X coordinates96* increasing to the right and Y coordinates increasing downwards.97* For image buffers, this Transform will be the Identity transform.98*/99public AffineTransform getDefaultTransform() {100return new AffineTransform(deviceTransform);101}102103/**104*105* Returns a Transform that can be composed with the default Transform106* of a Graphics2D so that 72 units in user space will equal 1 inch107* in device space.108* Given a Graphics2D, g, one can reset the transformation to create109* such a mapping by using the following pseudocode:110* <pre>111* GraphicsConfiguration gc = g.getGraphicsConfiguration();112*113* g.setTransform(gc.getDefaultTransform());114* g.transform(gc.getNormalizingTransform());115* </pre>116* Note that sometimes this Transform will be identity (e.g. for117* printers or metafile output) and that this Transform is only118* as accurate as the information supplied by the underlying system.119* For image buffers, this Transform will be the Identity transform,120* since there is no valid distance measurement.121*/122public AffineTransform getNormalizingTransform() {123return new AffineTransform();124}125126public Rectangle getBounds() {127return new Rectangle(0, 0, pageWidth, pageHeight);128}129}130131132