2007-05-15 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 15 May 2007 20:12:03 +0000 (20:12 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 15 May 2007 20:12:03 +0000 (20:12 -0000)
* Graphics.cs: Fix DrawImageUnscaled for empty (width or height <= 0)
Fix NRE in DrawImageUnscaledAndClipped. Remove lines with only tabs in
them.
* RectangleF.cs: A rectangle with a negative width or height is also
empty.

svn path=/trunk/mcs/; revision=77435

mcs/class/System.Drawing/System.Drawing/ChangeLog
mcs/class/System.Drawing/System.Drawing/Graphics.cs
mcs/class/System.Drawing/System.Drawing/RectangleF.cs

index 6032f9b6cdb8e8aed8de68aee613b9cd028e0cef..5000e844db7be10979914752cbcd9a91b63caa35 100644 (file)
@@ -1,3 +1,11 @@
+2007-05-15  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * Graphics.cs: Fix DrawImageUnscaled for empty (width or height <= 0)
+       Fix NRE in DrawImageUnscaledAndClipped. Remove lines with only tabs in
+       them.
+       * RectangleF.cs: A rectangle with a negative width or height is also
+       empty.
+
 2007-05-09 Igor Zelmanovich <igorz@mainsoft.com>
 
        * FontConverter.cs: for TARGET_JVM destructor is not used.
index 49a20c881f4d823fdb7299c2d5bee5e90f90cba9..19821fbb28d817e6dd5d53562644f22f024051f9 100644 (file)
@@ -610,7 +610,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, PointF point)
                {
                        if (image == null)
@@ -620,7 +619,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point [] destPoints)
                {
                        if (image == null)
@@ -632,7 +630,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point point)
                {
                        if (image == null)
@@ -640,7 +637,6 @@ namespace System.Drawing
                        DrawImage (image, point.X, point.Y);
                }
 
-               
                public void DrawImage (Image image, Rectangle rect)
                {
                        if (image == null)
@@ -648,7 +644,6 @@ namespace System.Drawing
                        DrawImage (image, rect.X, rect.Y, rect.Width, rect.Height);
                }
 
-               
                public void DrawImage (Image image, PointF [] destPoints)
                {
                        if (image == null)
@@ -659,7 +654,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, int x, int y)
                {
                        if (image == null)
@@ -668,7 +662,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, float x, float y)
                {
                        if (image == null)
@@ -677,7 +670,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
                {
                        if (image == null)
@@ -700,7 +692,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit)
                {
                        if (image == null)
@@ -715,7 +706,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
                {
                        if (image == null)
@@ -730,7 +720,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, 
                                 ImageAttributes imageAttr)
                {
@@ -754,7 +743,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, 
                                 ImageAttributes imageAttr)
                {
@@ -769,7 +757,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
                {                       
                        if (image == null)
@@ -794,7 +781,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
                {
                        if (image == null)
@@ -808,7 +794,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
                {
                        if (image == null)
@@ -823,7 +808,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
                {
                        if (image == null)
@@ -838,7 +822,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit)
                {
                        if (image == null)
@@ -859,7 +842,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit)
                {
                        if (image == null)
@@ -871,7 +853,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs)
                {
                        if (image == null)
@@ -918,7 +899,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
                {
                        if (image == null)
@@ -930,7 +910,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
                {
                        if (image == null)
@@ -944,15 +923,11 @@ namespace System.Drawing
                
                public void DrawImageUnscaled (Image image, Point point)
                {
-                       if (image == null)
-                               throw new ArgumentNullException ("image");
                        DrawImageUnscaled (image, point.X, point.Y);
                }
                
                public void DrawImageUnscaled (Image image, Rectangle rect)
                {
-                       if (image == null)
-                               throw new ArgumentNullException ("image");
                        DrawImageUnscaled (image, rect.X, rect.Y, rect.Width, rect.Height);
                }
                
@@ -967,20 +942,27 @@ namespace System.Drawing
                {
                        if (image == null)
                                throw new ArgumentNullException ("image");
-                       Image tmpImg = new Bitmap (width, height);
-                       Graphics g = FromImage (tmpImg);
-                       g.DrawImage (image, 0, 0, image.Width, image.Height);
-                       this.DrawImage (tmpImg, x, y, width, height);
-                       tmpImg.Dispose ();
-                       g.Dispose ();
+
+                       // avoid creating an empty, or negative w/h, bitmap...
+                       if ((width <= 0) || (height <= 0))
+                               return;
+
+                       using (Image tmpImg = new Bitmap (width, height)) {
+                               using (Graphics g = FromImage (tmpImg)) {
+                                       g.DrawImage (image, 0, 0, image.Width, image.Height);
+                                       DrawImage (tmpImg, x, y, width, height);
+                               }
+                       }
                }
 
 #if NET_2_0
                public void DrawImageUnscaledAndClipped (Image image, Rectangle rect)
                {
-                       int height, width;                      
-                       width = (image.Width > rect.Width) ? rect.Width : image.Width;
-                       height = (image.Height > rect.Height) ? rect.Height : image.Height;
+                       if (image == null)
+                               throw new ArgumentNullException ("image");
+
+                       int width = (image.Width > rect.Width) ? rect.Width : image.Width;
+                       int height = (image.Height > rect.Height) ? rect.Height : image.Height;
 
                        DrawImageUnscaled (image, rect.X, rect.Y, width, height);                       
                }
index 176855f14c6e43d2c613a63cca668f66eaa2bf97..495dea14fbed1cc589fb55f304d0b0b939d83031 100644 (file)
@@ -5,11 +5,7 @@
 //   Mike Kestner (mkestner@speakeasy.net)
 //
 // Copyright (C) 2001 Mike Kestner
-// Copyright (C) 2004 Novell, Inc. http://www.novell.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2007 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -310,7 +306,7 @@ namespace System.Drawing
                [Browsable (false)]
                public bool IsEmpty {
                        get {
-                               return (width == 0 || height == 0);
+                               return (width <= 0 || height <= 0);
                        }
                }