Author: spouliot
Date: 2007-05-15 16:12:03 -0400 (Tue, 15 May 2007)
New Revision: 77435

Modified:
   trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
   trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs
   trunk/mcs/class/System.Drawing/System.Drawing/RectangleF.cs
Log:
2007-05-15  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * 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.



Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2007-05-15 
20:09:49 UTC (rev 77434)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2007-05-15 
20:12:03 UTC (rev 77435)
@@ -1,3 +1,11 @@
+2007-05-15  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * 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 <[EMAIL PROTECTED]>
 
        * FontConverter.cs: for TARGET_JVM destructor is not used.

Modified: trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs   2007-05-15 
20:09:49 UTC (rev 77434)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs   2007-05-15 
20:12:03 UTC (rev 77435)
@@ -610,7 +610,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, PointF point)
                {
                        if (image == null)
@@ -620,7 +619,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point [] destPoints)
                {
                        if (image == null)
@@ -632,7 +630,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point point)
                {
                        if (image == null)
@@ -640,7 +637,6 @@
                        DrawImage (image, point.X, point.Y);
                }
 
-               
                public void DrawImage (Image image, Rectangle rect)
                {
                        if (image == null)
@@ -648,7 +644,6 @@
                        DrawImage (image, rect.X, rect.Y, rect.Width, 
rect.Height);
                }
 
-               
                public void DrawImage (Image image, PointF [] destPoints)
                {
                        if (image == null)
@@ -659,7 +654,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, int x, int y)
                {
                        if (image == null)
@@ -668,7 +662,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, float x, float y)
                {
                        if (image == null)
@@ -677,7 +670,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Rectangle destRect, 
Rectangle srcRect, GraphicsUnit srcUnit)
                {
                        if (image == null)
@@ -700,7 +692,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point [] destPoints, 
Rectangle srcRect, GraphicsUnit srcUnit)
                {
                        if (image == null)
@@ -715,7 +706,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, PointF [] destPoints, 
RectangleF srcRect, GraphicsUnit srcUnit)
                {
                        if (image == null)
@@ -730,7 +720,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, Point [] destPoints, 
Rectangle srcRect, GraphicsUnit srcUnit, 
                                 ImageAttributes imageAttr)
                {
@@ -754,7 +743,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, PointF [] destPoints, 
RectangleF srcRect, GraphicsUnit srcUnit, 
                                 ImageAttributes imageAttr)
                {
@@ -769,7 +757,6 @@
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawImage (Image image, int x, int y, Rectangle 
srcRect, GraphicsUnit srcUnit)
                {                       
                        if (image == null)
@@ -794,7 +781,6 @@
                        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 @@
                        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 @@
                        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 @@
                        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 @@
                        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 @@
                        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 @@
                        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 @@
                        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 @@
                
                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,21 +942,28 @@
                {
                        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);                       
                }
 #endif

Modified: trunk/mcs/class/System.Drawing/System.Drawing/RectangleF.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/RectangleF.cs 2007-05-15 
20:09:49 UTC (rev 77434)
+++ trunk/mcs/class/System.Drawing/System.Drawing/RectangleF.cs 2007-05-15 
20:12:03 UTC (rev 77435)
@@ -5,12 +5,8 @@
 //   Mike Kestner ([EMAIL PROTECTED])
 //
 // Copyright (C) 2001 Mike Kestner
-// Copyright (C) 2004 Novell, Inc. http://www.novell.com
+// Copyright (C) 2004, 2007 Novell, Inc (http://www.novell.com)
 //
-
-//
-// Copyright (C) 2004 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
 // "Software"), to deal in the Software without restriction, including
@@ -310,7 +306,7 @@
                [Browsable (false)]
                public bool IsEmpty {
                        get {
-                               return (width == 0 || height == 0);
+                               return (width <= 0 || height <= 0);
                        }
                }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to