// Duncan Mak (duncan@ximian.com)
// Jordi Mas i Hernandez (jordi@ximian.com)
// Ravindra (rkumar@novell.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004,2006 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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
-using System.Drawing;
+using System.ComponentModel;
using System.Runtime.InteropServices;
namespace System.Drawing.Drawing2D
{
public sealed class GraphicsPath : MarshalByRefObject, ICloneable, IDisposable
{
+ // 1/4 is the FlatnessDefault as defined in GdiPlusEnums.h
+ private const float FlatnessDefault = 1.0f / 4.0f;
+
internal IntPtr nativePath = IntPtr.Zero;
GraphicsPath (IntPtr ptr)
}
public GraphicsPath (Point[] pts, byte[] types)
+ : this (pts, types, FillMode.Alternate)
{
- Status status;
- if (pts.Length != types.Length)
- throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
-
- status = GDIPlus.GdipCreatePath2I (pts, types, pts.Length, FillMode.Alternate, out nativePath);
- GDIPlus.CheckStatus (status);
}
public GraphicsPath (PointF[] pts, byte[] types)
+ : this (pts, types, FillMode.Alternate)
{
- Status status;
- if (pts.Length != types.Length)
- throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
-
- status = GDIPlus.GdipCreatePath2 (pts, types, pts.Length, FillMode.Alternate, out nativePath);
- GDIPlus.CheckStatus (status);
}
public GraphicsPath (Point[] pts, byte[] types, FillMode fillMode)
{
- Status status;
+ if (pts == null)
+ throw new ArgumentNullException ("pts");
if (pts.Length != types.Length)
throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
- status = GDIPlus.GdipCreatePath2I (pts, types, pts.Length, fillMode, out nativePath);
+ Status status = GDIPlus.GdipCreatePath2I (pts, types, pts.Length, fillMode, out nativePath);
GDIPlus.CheckStatus (status);
}
public GraphicsPath (PointF[] pts, byte[] types, FillMode fillMode)
{
- Status status;
+ if (pts == null)
+ throw new ArgumentNullException ("pts");
if (pts.Length != types.Length)
throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
- status = GDIPlus.GdipCreatePath2 (pts, types, pts.Length, fillMode, out nativePath);
+ Status status = GDIPlus.GdipCreatePath2 (pts, types, pts.Length, fillMode, out nativePath);
GDIPlus.CheckStatus (status);
}
return mode;
}
set {
+ if ((value < FillMode.Alternate) || (value > FillMode.Winding))
+ throw new InvalidEnumArgumentException ("FillMode", (int)value, typeof (FillMode));
+
Status status = GDIPlus.GdipSetPathFillMode (nativePath, value);
GDIPlus.CheckStatus (status);
}
public PathData PathData {
get {
+ int count;
+ Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
+ GDIPlus.CheckStatus (status);
+
+ PointF [] points = new PointF [count];
+ byte [] types = new byte [count];
+
+ // 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 = PathPoints;
- pdata.Types = PathTypes;
+ pdata.Points = points;
+ pdata.Types = types;
return pdata;
}
}
int count;
Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
GDIPlus.CheckStatus (status);
+ if (count == 0)
+ throw new ArgumentException ("PathPoints");
PointF [] points = new PointF [count];
status = GDIPlus.GdipGetPathPoints (nativePath, points, count);
int count;
Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
GDIPlus.CheckStatus (status);
+ if (count == 0)
+ throw new ArgumentException ("PathTypes");
byte [] types = new byte [count];
status = GDIPlus.GdipGetPathTypes (nativePath, types, count);
//
public void AddBeziers (Point [] pts)
{
+ if (pts == null)
+ throw new ArgumentNullException ("pts");
Status status = GDIPlus.GdipAddPathBeziersI (nativePath, pts, pts.Length);
GDIPlus.CheckStatus (status);
}
public void AddBeziers (PointF [] pts)
{
+ if (pts == null)
+ throw new ArgumentNullException ("pts");
Status status = GDIPlus.GdipAddPathBeziers (nativePath, pts, pts.Length);
GDIPlus.CheckStatus (status);
}
//
// AddLines
//
- public void AddLines (Point [] points)
- {
- int length = points.Length;
+ public void AddLines (Point[] points)
+ {
+ if (points == null)
+ throw new ArgumentNullException ("points");
+ if (points.Length == 0)
+ throw new ArgumentException ("points");
- 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)
- {
- int length = points.Length;
+ public void AddLines (PointF[] points)
+ {
+ if (points == null)
+ throw new ArgumentNullException ("points");
+ if (points.Length == 0)
+ throw new ArgumentException ("points");
- 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
//
public void AddPolygon (Point [] points)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathPolygonI (nativePath, points, points.Length);
GDIPlus.CheckStatus (status);
}
public void AddPolygon (PointF [] points)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathPolygon (nativePath, points, points.Length);
GDIPlus.CheckStatus (status);
}
//
public void AddRectangles (Rectangle [] rects)
{
+ if (rects == null)
+ throw new ArgumentNullException ("rects");
+ if (rects.Length == 0)
+ throw new ArgumentException ("rects");
+
Status status = GDIPlus.GdipAddPathRectanglesI (nativePath, rects, rects.Length);
GDIPlus.CheckStatus (status);
}
public void AddRectangles (RectangleF [] rects)
{
+ if (rects == null)
+ throw new ArgumentNullException ("rects");
+ if (rects.Length == 0)
+ throw new ArgumentException ("rects");
+
Status status = GDIPlus.GdipAddPathRectangles (nativePath, rects, rects.Length);
GDIPlus.CheckStatus (status);
}
//
public void AddPath (GraphicsPath addingPath, bool connect)
{
+ if (addingPath == null)
+ throw new ArgumentNullException ("addingPath");
+
Status status = GDIPlus.GdipAddPathPath (nativePath, addingPath.nativePath, connect);
GDIPlus.CheckStatus (status);
}
//
public void AddClosedCurve (Point [] points)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathClosedCurveI (nativePath, points, points.Length);
GDIPlus.CheckStatus (status);
}
public void AddClosedCurve (PointF [] points)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathClosedCurve (nativePath, points, points.Length);
GDIPlus.CheckStatus (status);
}
public void AddClosedCurve (Point [] points, float tension)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathClosedCurve2I (nativePath, points, points.Length, tension);
GDIPlus.CheckStatus (status);
}
public void AddClosedCurve (PointF [] points, float tension)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathClosedCurve2 (nativePath, points, points.Length, tension);
GDIPlus.CheckStatus (status);
}
//
public void AddCurve (Point [] points)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathCurveI (nativePath, points, points.Length);
GDIPlus.CheckStatus (status);
}
public void AddCurve (PointF [] points)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathCurve (nativePath, points, points.Length);
GDIPlus.CheckStatus (status);
}
public void AddCurve (Point [] points, float tension)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathCurve2I (nativePath, points, points.Length, tension);
GDIPlus.CheckStatus (status);
}
public void AddCurve (PointF [] points, float tension)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathCurve2 (nativePath, points, points.Length, tension);
GDIPlus.CheckStatus (status);
}
public void AddCurve (Point [] points, int offset, int numberOfSegments, float tension)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathCurve3I (nativePath, points, points.Length,
offset, numberOfSegments, tension);
public void AddCurve (PointF [] points, int offset, int numberOfSegments, float tension)
{
+ if (points == null)
+ throw new ArgumentNullException ("points");
+
Status status = GDIPlus.GdipAddPathCurve3 (nativePath, points, points.Length,
offset, numberOfSegments, tension);
public void Transform (Matrix matrix)
{
+ if (matrix == null)
+ throw new ArgumentNullException ("matrix");
+
Status status = GDIPlus.GdipTransformPath (nativePath, matrix.nativeMatrix);
GDIPlus.CheckStatus (status);
}
- [MonoTODO]
- public void AddString (string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void AddString (string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void AddString (string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
+ [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 = new Rectangle ();
+ layout.X = origin.X;
+ layout.Y = origin.Y;
+ AddString (s, family, style, emSize, layout, format);
+ }
+
+ [MonoTODO ("The StringFormat parameter is ignored when using libgdiplus.")]
+ public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
{
- throw new NotImplementedException ();
- }
-
+ RectangleF layout = new RectangleF ();
+ layout.X = origin.X;
+ layout.Y = origin.Y;
+ AddString (s, family, style, emSize, layout, format);
+ }
+
+ [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 (family == null)
+ throw new ArgumentException ("family");
+
+ IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
+ // 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 ("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 (family == null)
+ throw new ArgumentException ("family");
+
+ IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
+ // 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);
+ }
+
public void ClearMarkers()
{
Status s = GDIPlus.GdipClearPathMarkers (nativePath);
public void Flatten ()
{
- // 1/4 is the FlatnessDefault as defined in GdiPlusEnums.h
- Flatten (null, 1.0f / 4.0f);
+ Flatten (null, FlatnessDefault);
}
public void Flatten (Matrix matrix)
{
- Flatten (matrix, 1.0f / 4.0f);
+ Flatten (matrix, FlatnessDefault);
}
public void Flatten (Matrix matrix, float flatness)
{
- Status status = GDIPlus.GdipFlattenPath (nativePath, matrix.nativeMatrix, flatness);
+ IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
+ Status status = GDIPlus.GdipFlattenPath (nativePath, m, flatness);
GDIPlus.CheckStatus (status);
}
return GetBounds (matrix, null);
}
- [MonoTODO]
public RectangleF GetBounds (Matrix matrix, Pen pen)
{
RectangleF retval;
return IsOutlineVisible (x, y, pen, null);
}
+ [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 ("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]
+ [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]
+ [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;
return IsVisible (x, y, null);
}
+ [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
public bool IsVisible (Point pt, Graphics graphics)
{
return IsVisible (pt.X, pt.Y, graphics);
}
+ [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
public bool IsVisible (PointF pt, Graphics graphics)
{
return IsVisible (pt.X, pt.Y, graphics);
}
- [MonoTODO]
+ [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
public bool IsVisible (int x, int y, Graphics graphics)
{
bool retval;
return retval;
}
- [MonoTODO]
+ [MonoTODO ("The Graphics parameter is ignored when using libgdiplus.")]
public bool IsVisible (float x, float y, Graphics graphics)
{
bool retval;
GDIPlus.CheckStatus (s);
}
+ [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
public void Warp (PointF[] destPoints, RectangleF srcRect)
{
- Warp (destPoints, srcRect, null, WarpMode.Perspective, 1.0f / 4.0f);
+ Warp (destPoints, srcRect, null, WarpMode.Perspective, FlatnessDefault);
}
+ [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix)
{
- Warp (destPoints, srcRect, matrix, WarpMode.Perspective, 1.0f / 4.0f);
+ Warp (destPoints, srcRect, matrix, WarpMode.Perspective, FlatnessDefault);
}
+ [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode)
{
- Warp (destPoints, srcRect, matrix, warpMode, 1.0f / 4.0f);
+ Warp (destPoints, srcRect, matrix, warpMode, FlatnessDefault);
}
- [MonoTODO]
+ [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode, float flatness)
{
+ if (destPoints == null)
+ throw new ArgumentNullException ("destPoints");
+
IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
Status s = GDIPlus.GdipWarpPath (nativePath, m, destPoints, destPoints.Length,
GDIPlus.CheckStatus (s);
}
+ [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
public void Widen (Pen pen)
{
- Widen (pen, null, 1.0f / 4.0f);
+ Widen (pen, null, FlatnessDefault);
}
+ [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
public void Widen (Pen pen, Matrix matrix)
{
- Widen (pen, matrix, 1.0f / 4.0f);
+ Widen (pen, matrix, FlatnessDefault);
}
- [MonoTODO]
+ [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
public void Widen (Pen pen, Matrix matrix, float flatness)
{
- IntPtr p = (pen == null) ? IntPtr.Zero : pen.nativeObject;
+ 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, p, m, flatness);
-
- GDIPlus.CheckStatus (s);
+ Status s = GDIPlus.GdipWidenPath (nativePath, pen.nativeObject, m, flatness);
+ GDIPlus.CheckStatus (s);
}
}
}
-
-