src/macosx/classes/com/apple/laf/AquaPainter.java

Print this page

        

@@ -36,10 +36,14 @@
 import sun.awt.image.*;
 import sun.java2d.*;
 import sun.print.*;
 import apple.laf.*;
 import apple.laf.JRSUIUtils.NineSliceMetricsProvider;
+import java.awt.geom.AffineTransform;
+import static java.awt.geom.AffineTransform.TYPE_FLIP;
+import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE;
+import static java.awt.geom.AffineTransform.TYPE_TRANSLATION;
 import sun.awt.image.ImageCache;
 
 abstract class AquaPainter <T extends JRSUIState> {
     static <T extends JRSUIState> AquaPainter<T> create(final T state) {
         return new AquaSingleImagePainter<>(state);

@@ -146,20 +150,35 @@
                 final Rectangle bounds) {
             if (bounds.width <= 0 || bounds.height <= 0) {
                 return;
             }
 
-            int scale = 1;
+            int imgW = bounds.width;
+            int imgH = bounds.height;
+
             if (g instanceof SunGraphics2D) {
-                scale = ((SunGraphics2D) g).surfaceData.getDefaultScale();
+                AffineTransform transform = ((SunGraphics2D) g).transform;
+                int type = transform.getType();
+
+                if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) {
+                    //  identity scale
+                } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP
+                        | TYPE_MASK_SCALE)) == 0) {
+                    imgW = (int) (bounds.width * transform.getScaleX());
+                    imgH = (int) (bounds.height * transform.getScaleY());
+                } else {
+                    imgW = (int) (bounds.width * Math.hypot(
+                            transform.getScaleX(), transform.getShearY()));
+                    imgH = (int) (bounds.height * Math.hypot(
+                            transform.getShearX(), transform.getScaleY()));
             }
+            }
+
             final GraphicsConfiguration config = g.getDeviceConfiguration();
             final ImageCache cache = ImageCache.getInstance();
-            final int imgW = bounds.width * scale;
-            final int imgH = bounds.height * scale;
             AquaPixelsKey key = new AquaPixelsKey(config,
-                    imgW, imgH, scale, controlState);
+                    imgW, imgH, controlState);
             BufferedImage img = (BufferedImage) cache.getImage(key);
             if (img == null) {
                 img = new BufferedImage(imgW, imgH, BufferedImage.TYPE_INT_ARGB_PRE);
                 if (!controlState.is(JRSUIConstants.Animating.YES)) {
                     cache.setImage(key, img);

@@ -185,21 +204,19 @@
 
         // key parts
         private final GraphicsConfiguration config;
         private final int w;
         private final int h;
-        private final int scale;
         private final JRSUIState state;
 
         AquaPixelsKey(final GraphicsConfiguration config,
-                final int w, final int h, final int scale,
+                final int w, final int h,
                 final JRSUIState state) {
             this.pixelCount = w * h;
             this.config = config;
             this.w = w;
             this.h = h;
-            this.scale = scale;
             this.state = state;
             this.hash = hash();
         }
 
         public int getPixelCount() {

@@ -208,11 +225,10 @@
 
         private int hash() {
             int hash = config != null ? config.hashCode() : 0;
             hash = 31 * hash + w;
             hash = 31 * hash + h;
-            hash = 31 * hash + scale;
             hash = 31 * hash + state.hashCode();
             return hash;
         }
 
         @Override

@@ -223,11 +239,11 @@
         @Override
         public boolean equals(Object obj) {
             if (obj instanceof AquaPixelsKey) {
                 AquaPixelsKey key = (AquaPixelsKey) obj;
                 return config == key.config && w == key.w && h == key.h
-                        && scale == key.scale && state.equals(key.state);
+                        && state.equals(key.state);
             }
             return false;
         }
     }