< prev index next >
src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java
Print this page
@@ -242,11 +242,10 @@
public Region clipRegion;
public Shape usrClip;
protected Region devClip; // Actual physical drawable in pixels
- private final int devScale; // Actual physical scale factor
private int resolutionVariantHint;
// cached state for text rendering
private boolean validFontInfo;
private FontInfo fontInfo;
@@ -266,12 +265,10 @@
public SunGraphics2D(SurfaceData sd, Color fg, Color bg, Font f) {
surfaceData = sd;
foregroundColor = fg;
backgroundColor = bg;
-
- transform = new AffineTransform();
stroke = defaultStroke;
composite = defaultComposite;
paint = foregroundColor;
imageComp = CompositeType.SrcOverNoEa;
@@ -285,27 +282,31 @@
strokeHint = SunHints.INTVAL_STROKE_DEFAULT;
resolutionVariantHint = SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT;
interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
- validateColor();
-
- devScale = sd.getDefaultScale();
- if (devScale != 1) {
- transform.setToScale(devScale, devScale);
+ transform = getDefaultTransform();
+ if (!transform.isIdentity()) {
invalidateTransform();
}
+ validateColor();
+
font = f;
if (font == null) {
font = defaultFont;
}
setDevClip(sd.getBounds());
invalidatePipe();
}
+ private AffineTransform getDefaultTransform() {
+ GraphicsConfiguration gc = getDeviceConfiguration();
+ return (gc == null) ? new AffineTransform() : gc.getDefaultTransform();
+ }
+
protected Object clone() {
try {
SunGraphics2D g = (SunGraphics2D) super.clone();
g.transform = new AffineTransform(this.transform);
if (hints != null) {
@@ -1608,15 +1609,14 @@
* @see TransformChain
* @see AffineTransform
*/
@Override
public void setTransform(AffineTransform Tx) {
- if ((constrainX | constrainY) == 0 && devScale == 1) {
+ if ((constrainX | constrainY) == 0) {
transform.setTransform(Tx);
} else {
- transform.setTransform(devScale, 0, 0, devScale, constrainX,
- constrainY);
+ transform.setToTranslation(constrainX, constrainY);
transform.concatenate(Tx);
}
invalidateTransform();
}
@@ -1672,17 +1672,15 @@
* @see #transform
* @see #setTransform
*/
@Override
public AffineTransform getTransform() {
- if ((constrainX | constrainY) == 0 && devScale == 1) {
+ if ((constrainX | constrainY) == 0) {
return new AffineTransform(transform);
}
- final double invScale = 1.0 / devScale;
- AffineTransform tx = new AffineTransform(invScale, 0, 0, invScale,
- -constrainX * invScale,
- -constrainY * invScale);
+ AffineTransform tx
+ = AffineTransform.getTranslateInstance(-constrainX, -constrainY);
tx.concatenate(transform);
return tx;
}
/**
< prev index next >