src/share/classes/sun/java2d/SunGraphics2D.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -80,18 +80,16 @@
 import sun.java2d.loops.RenderLoops;
 import sun.java2d.loops.CompositeType;
 import sun.java2d.loops.SurfaceType;
 import sun.java2d.loops.Blit;
 import sun.java2d.loops.MaskFill;
-import sun.font.FontManager;
 import java.awt.font.FontRenderContext;
 import sun.java2d.loops.XORComposite;
 import sun.awt.ConstrainableGraphics;
 import sun.awt.SunHints;
 import java.util.Map;
 import java.util.Iterator;
-import sun.java2d.DestSurfaceProvider;
 import sun.misc.PerformanceLogger;
 
 import javax.tools.annotation.GenerateNativeHeader;
 
 /**

@@ -1747,30 +1745,32 @@
             r = null;
         } else if (transformState <= TRANSFORM_INT_TRANSLATE) {
             if (usrClip instanceof Rectangle) {
                 r = new Rectangle((Rectangle) usrClip);
             } else {
-                r = usrClip.getBounds();
+                r = new Rectangle();
+                r.setFrame(usrClip.getBounds2D());
             }
             r.translate(-transX, -transY);
         } else {
-            r = getClip().getBounds();
+            r = new Rectangle();
+            r.setFrame(getClip().getBounds2D());
         }
         return r;
     }
 
     public Rectangle getClipBounds(Rectangle r) {
         if (clipState != CLIP_DEVICE) {
             if (transformState <= TRANSFORM_INT_TRANSLATE) {
                 if (usrClip instanceof Rectangle) {
                     r.setBounds((Rectangle) usrClip);
                 } else {
-                    r.setBounds(usrClip.getBounds());
+                    r.setFrame(usrClip.getBounds2D());
                 }
                 r.translate(-transX, -transY);
             } else {
-                r.setBounds(getClip().getBounds());
+                r.setFrame(getClip().getBounds2D());
             }
         } else if (r == null) {
             throw new NullPointerException("null rectangle parameter");
         }
         return r;

@@ -1941,23 +1941,39 @@
             matrix[0] = rect.getX();
             matrix[1] = rect.getY();
             matrix[2] = matrix[0] + rect.getWidth();
             matrix[3] = matrix[1] + rect.getHeight();
             tx.transform(matrix, 0, matrix, 0, 2);
-            rect = new Rectangle2D.Float();
-            rect.setFrameFromDiagonal(matrix[0], matrix[1],
-                                      matrix[2], matrix[3]);
-            return rect;
+            fixRectangleOrientation(matrix, rect);
+            return new Rectangle2D.Double(matrix[0], matrix[1],
+                                          matrix[2] - matrix[0],
+                                          matrix[3] - matrix[1]);
         }
 
         if (tx.isIdentity()) {
             return cloneShape(clip);
         }
 
         return tx.createTransformedShape(clip);
     }
 
+    /**
+     * Sets orientation of the rectangle according to the clip.
+     */
+    private static void fixRectangleOrientation(double[] m, Rectangle2D clip) {
+        if (clip.getWidth() > 0 != (m[2] - m[0] > 0)) {
+            double t = m[0];
+            m[0] = m[2];
+            m[2] = t;
+        }
+        if (clip.getHeight() > 0 != (m[3] - m[1] > 0)) {
+            double t = m[1];
+            m[1] = m[3];
+            m[3] = t;
+        }
+    }
+
     public void clipRect(int x, int y, int w, int h) {
         clip(new Rectangle(x, y, w, h));
     }
 
     public void setClip(int x, int y, int w, int h) {