2006-11-22 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System.Drawing / System.Drawing.Drawing2D / GraphicsPath.cs
index 8c5c8cf173f12d81b7ed257cf49066616cb25d9b..f2ed22d1c05b7748b34f36f830a63de19f8944a4 100644 (file)
@@ -148,12 +148,17 @@ namespace System.Drawing.Drawing2D
                                GDIPlus.CheckStatus (status);
 
                                PointF [] points = new PointF [count];
-                               status = GDIPlus.GdipGetPathPoints (nativePath, points, count); 
-                               GDIPlus.CheckStatus (status);                   
-
                                byte [] types = new byte [count];
-                               status = GDIPlus.GdipGetPathTypes (nativePath, types, count);
-                               GDIPlus.CheckStatus (status);
+
+                               // status would fail if we ask points or types with a 0 count
+                               // anyway that would only mean two unrequired unmanaged calls
+                               if (count > 0) {
+                                       status = GDIPlus.GdipGetPathPoints (nativePath, points, count);
+                                       GDIPlus.CheckStatus (status);
+
+                                       status = GDIPlus.GdipGetPathTypes (nativePath, types, count);
+                                       GDIPlus.CheckStatus (status);
+                               }
 
                                PathData pdata = new PathData ();
                                pdata.Points = points;
@@ -352,38 +357,27 @@ namespace System.Drawing.Drawing2D
                 //
                 // AddLines
                 //
-                public void AddLines (Point [] points)
-                {
+               public void AddLines (Point[] points)
+               {
                        if (points == null)
                                throw new ArgumentNullException ("points");
                        if (points.Length == 0)
                                throw new ArgumentException ("points");
 
-                        int length = points.Length;
-                        for (int i = 0; i < length - 1; i++) {
-                                int j = i + 1;
-                                Status status = GDIPlus.GdipAddPathLineI (
-                                        nativePath, points [i].X, points [i].Y, points [j].X, points [j].Y);
-                                GDIPlus.CheckStatus (status);                          
-                        }
-                }
+                       Status status = GDIPlus.GdipAddPathLine2I (nativePath, points, points.Length);
+                       GDIPlus.CheckStatus (status);                           
+               }
 
-                public void AddLines (PointF [] points)
-                {
+               public void AddLines (PointF[] points)
+               {
                        if (points == null)
                                throw new ArgumentNullException ("points");
                        if (points.Length == 0)
                                throw new ArgumentException ("points");
 
-                        int length = points.Length;
-
-                        for (int i = 0; i < length - 1; i++) {
-                                int j = i + 1;
-                                Status status = GDIPlus.GdipAddPathLine (
-                                        nativePath, points [i].X, points [i].Y, points [j].X, points [j].Y);
-                                GDIPlus.CheckStatus (status);                          
-                        }
-                }
+                       Status status = GDIPlus.GdipAddPathLine2 (nativePath, points, points.Length);
+                       GDIPlus.CheckStatus (status);                           
+               }
         
                 //
                 // AddPie
@@ -610,47 +604,45 @@ namespace System.Drawing.Drawing2D
                         GDIPlus.CheckStatus (status);                          
                 }
                 
-               [MonoTODO ("GdipAddStringI isn't implemented in libgdiplus")]
+               [MonoTODO ("The StringFormat parameter is ignored when using libgdiplus.")]
                public void AddString (string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
                {
-                       Rectangle layout;
+                       Rectangle layout = new Rectangle ();
                        layout.X = origin.X;
                        layout.Y = origin.Y;
                        AddString (s, family, style, emSize, layout, format);
                }
 
-               [MonoTODO ("GdipAddString isn't implemented in libgdiplus")]
+               [MonoTODO ("The StringFormat parameter is ignored when using libgdiplus.")]
                public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
                {
-                       RectangleF layout;
+                       RectangleF layout = new RectangleF ();
                        layout.X = origin.X;
                        layout.Y = origin.Y;
                        AddString (s, family, style, emSize, layout, format);
                 }
 
-               [MonoTODO ("GdipAddStringI isn't implemented in libgdiplus")]
+               [MonoTODO ("The layoutRect and StringFormat parameters are ignored when using libgdiplus.")]
                public void AddString (string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
                {
-                       if (s == null)
-                               throw new ArgumentNullException ("s");
+                       if (family == null)
+                               throw new ArgumentException ("family");
 
-                       IntPtr ffamily = (family == null) ? IntPtr.Zero : family.NativeObject;
                        IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
-
-                       Status status = GDIPlus.GdipAddStringI (nativePath, s, s.Length, ffamily, style, emSize, ref layoutRect, sformat);
+                       // note: the NullReferenceException on s.Length is the expected (MS) exception
+                       Status status = GDIPlus.GdipAddPathStringI (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
                        GDIPlus.CheckStatus (status);
                }
 
-               [MonoTODO ("GdipAddString isn't implemented in libgdiplus")]
+               [MonoTODO ("The layoutRect and StringFormat parameters are ignored when using libgdiplus.")]
                public void AddString (string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
                {
-                       if (s == null)
-                               throw new ArgumentNullException ("s");
+                       if (family == null)
+                               throw new ArgumentException ("family");
 
-                       IntPtr ffamily = (family == null) ? IntPtr.Zero : family.NativeObject;
                        IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
-
-                       Status status = GDIPlus.GdipAddString (nativePath, s, s.Length, ffamily, style, emSize, ref layoutRect, sformat);
+                       // note: the NullReferenceException on s.Length is the expected (MS) exception
+                       Status status = GDIPlus.GdipAddPathString (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
                        GDIPlus.CheckStatus (status);
                }
 
@@ -703,7 +695,6 @@ namespace System.Drawing.Drawing2D
                        return GetBounds (matrix, null);
                 }
 
-                [MonoTODO ("GdipGetPathWorldBounds doesn't support pens in libgdiplus (missing GdipWidenPath)")]
                 public RectangleF GetBounds (Matrix matrix, Pen pen)
                 {
                         RectangleF retval;
@@ -717,103 +708,101 @@ namespace System.Drawing.Drawing2D
                         return retval;
                 }
 
-                [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
                public bool IsOutlineVisible (Point point, Pen pen)
                {
                         return IsOutlineVisible (point.X, point.Y, pen, null);
                 }              
                
-                [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
                public bool IsOutlineVisible (PointF point, Pen pen)
                {
                        return IsOutlineVisible (point.X, point.Y, pen, null);
                 } 
                
-                [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
                public bool IsOutlineVisible (int x, int y, Pen pen)
                {
                         return IsOutlineVisible (x, y, pen, null);
                 }
 
-                [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
                public bool IsOutlineVisible (float x, float y, Pen pen)
                {
                        return IsOutlineVisible (x, y, pen, null);
                 }              
                
-                [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
+                [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
                public bool IsOutlineVisible (Point pt, Pen pen, Graphics graphics)
                {
                        return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
                 }              
                
-                [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
+                [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
                public bool IsOutlineVisible (PointF pt, Pen pen, Graphics graphics)
                {
                        return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
                 }              
                                
-                [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
+                [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
                public bool IsOutlineVisible (int x, int y, Pen pen, Graphics graphics)
                {
+                       if (pen == null)
+                               throw new ArgumentNullException ("pen");
+
                         bool result;
                         IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
                         
-                       Status s = GDIPlus.GdipIsOutlineVisiblePathPointI (nativePath, x, y, g, out result);
+                       Status s = GDIPlus.GdipIsOutlineVisiblePathPointI (nativePath, x, y, pen.nativeObject, g, out result);
                         GDIPlus.CheckStatus (s);
 
                         return result;
                 }              
 
-                [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
+                [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
                public bool IsOutlineVisible (float x, float y, Pen pen, Graphics graphics)
                {
+                       if (pen == null)
+                               throw new ArgumentNullException ("pen");
+
                         bool result;
                         IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
                         
-                       Status s = GDIPlus.GdipIsOutlineVisiblePathPoint (nativePath, x, y, g, out result);
+                       Status s = GDIPlus.GdipIsOutlineVisiblePathPoint (nativePath, x, y, pen.nativeObject, g, out result);
                         GDIPlus.CheckStatus (s);
 
                         return result;
                 }              
                 
-                [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
                 public bool IsVisible (Point point)
                 {
                        return IsVisible (point.X, point.Y, null);
                 }              
                 
-                [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
                 public bool IsVisible (PointF point)
                 {
                        return IsVisible (point.X, point.Y, null);
                 }              
                 
-                [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
                 public bool IsVisible (int x, int y)
                 {
                        return IsVisible (x, y, null);
                 }
 
-                [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
                 public bool IsVisible (float x, float y)
                 {
                        return IsVisible (x, y, null);
                 }                              
                 
-                [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
+                [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
                 public bool IsVisible (Point pt, Graphics graphics)
                 {
                        return IsVisible (pt.X, pt.Y, graphics);
                 }              
                 
-                [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
+                [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
                 public bool IsVisible (PointF pt, Graphics graphics)
                 {
                        return IsVisible (pt.X, pt.Y, graphics);
                 }              
                                 
-                [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
+                [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
                 public bool IsVisible (int x, int y, Graphics graphics)
                 {
                         bool retval;
@@ -827,7 +816,7 @@ namespace System.Drawing.Drawing2D
                         return retval;
                 }              
                 
-                [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
+                [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
                 public bool IsVisible (float x, float y, Graphics graphics)
                 {
                         bool retval;
@@ -904,7 +893,10 @@ namespace System.Drawing.Drawing2D
                 {
                        if (pen == null)
                                throw new ArgumentNullException ("pen");
-
+#if NET_2_0
+                       if (PointCount == 0)
+                               return;
+#endif
                        IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
 
                        Status s = GDIPlus.GdipWidenPath (nativePath, pen.nativeObject, m, flatness);