Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/print/PrinterGraphicsConfig.java
41153 views
1
/*
2
* Copyright (c) 2004, 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.print;
27
28
import java.awt.GraphicsConfiguration;
29
import java.awt.GraphicsDevice;
30
import java.awt.Rectangle;
31
import java.awt.Transparency;
32
import java.awt.geom.AffineTransform;
33
import java.awt.image.BufferedImage;
34
import java.awt.image.ColorModel;
35
import java.awt.image.DirectColorModel;
36
37
public final class PrinterGraphicsConfig extends GraphicsConfiguration {
38
39
static ColorModel theModel;
40
41
private final GraphicsDevice device;
42
private final int pageWidth;
43
private final int pageHeight;
44
private final AffineTransform deviceTransform;
45
46
public PrinterGraphicsConfig(String printerID, AffineTransform deviceTx,
47
int pageWid, int pageHgt) {
48
this.pageWidth = pageWid;
49
this.pageHeight = pageHgt;
50
this.deviceTransform = deviceTx;
51
this.device = new PrinterGraphicsDevice(this, printerID);
52
}
53
54
/**
55
* Return the graphics device associated with this configuration.
56
*/
57
@Override
58
public GraphicsDevice getDevice() {
59
return device;
60
}
61
62
/**
63
* Returns the color model associated with this configuration.
64
*/
65
@Override
66
public ColorModel getColorModel() {
67
if (theModel == null) {
68
BufferedImage bufImg =
69
new BufferedImage(1,1, BufferedImage.TYPE_3BYTE_BGR);
70
theModel = bufImg.getColorModel();
71
}
72
73
return theModel;
74
}
75
76
/**
77
* Returns the color model associated with this configuration that
78
* supports the specified transparency.
79
*/
80
@Override
81
public ColorModel getColorModel(int transparency) {
82
switch (transparency) {
83
case Transparency.OPAQUE:
84
return getColorModel();
85
case Transparency.BITMASK:
86
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
87
case Transparency.TRANSLUCENT:
88
return ColorModel.getRGBdefault();
89
default:
90
return null;
91
}
92
}
93
94
/**
95
* Returns the default Transform for this configuration. This
96
* Transform is typically the Identity transform for most normal
97
* screens. Device coordinates for screen and printer devices will
98
* have the origin in the upper left-hand corner of the target region of
99
* the device, with X coordinates
100
* increasing to the right and Y coordinates increasing downwards.
101
* For image buffers, this Transform will be the Identity transform.
102
*/
103
@Override
104
public AffineTransform getDefaultTransform() {
105
return new AffineTransform(deviceTransform);
106
}
107
108
/**
109
*
110
* Returns a Transform that can be composed with the default Transform
111
* of a Graphics2D so that 72 units in user space will equal 1 inch
112
* in device space.
113
* Given a Graphics2D, g, one can reset the transformation to create
114
* such a mapping by using the following pseudocode:
115
* <pre>
116
* GraphicsConfiguration gc = g.getGraphicsConfiguration();
117
*
118
* g.setTransform(gc.getDefaultTransform());
119
* g.transform(gc.getNormalizingTransform());
120
* </pre>
121
* Note that sometimes this Transform will be identity (e.g. for
122
* printers or metafile output) and that this Transform is only
123
* as accurate as the information supplied by the underlying system.
124
* For image buffers, this Transform will be the Identity transform,
125
* since there is no valid distance measurement.
126
*/
127
@Override
128
public AffineTransform getNormalizingTransform() {
129
return new AffineTransform();
130
}
131
132
@Override
133
public Rectangle getBounds() {
134
return new Rectangle(0, 0, pageWidth, pageHeight);
135
}
136
}
137
138