X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Drawing%2FSystem.Drawing.Drawing2D%2FGraphicsPathIterator.cs;h=dbd2f4341dc4fe54ee265bc78659fe7a5572a077;hb=c39145af2464b19374fac41b252e07480ae1a197;hp=44bfeda66289813648dcccca7e06535c6cb92874;hpb=e5aa23189bfdb75e36528e491537ec26ca0fc0c0;p=mono.git diff --git a/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPathIterator.cs b/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPathIterator.cs index 44bfeda6628..dbd2f4341dc 100644 --- a/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPathIterator.cs +++ b/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPathIterator.cs @@ -1,13 +1,12 @@ -// -// System.Drawing.Drawing2D.GraphicsPathIterator.cs -// -// Author: -// Dennis Hayes (dennish@Raytek.com) -// Duncan Mak (duncan@ximian.com) -// -// (C) 2002/3 Ximian, Inc -// - +// +// System.Drawing.Drawing2D.GraphicsPathIterator.cs +// +// Author: +// Dennis Hayes (dennish@Raytek.com) +// Duncan Mak (duncan@ximian.com) +// Ravindra (rkumar@novell.com) +// +// Copyright (C) 2002/3 Ximian, Inc (http://www.ximian.com) // // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // @@ -30,115 +29,174 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -using System; -using System.Drawing; - -namespace System.Drawing.Drawing2D -{ - public sealed class GraphicsPathIterator : MarshalByRefObject, IDisposable - { - PointF [] _points; - byte [] _types; - int _count; - int _current; - - // Constructors - public GraphicsPathIterator (GraphicsPath path) - { - this._points = path.PathPoints; - this._types = path.PathTypes; - this._count = path.PointCount; - this._current = 0; - } - - // Public Properites - public int Count { - get { - return _count; - } - } - - public int SubpathCount { - get { - int count = 0; - - foreach (byte b in _types) - if (b == (byte) PathPointType.Start) - count++; - - return count; - } - } - - // Public Methods. - public int CopyData (ref PointF [] points, ref byte [] types, int startIndex, int endIndex) - { - for (int i = 0, j = startIndex; j < endIndex; i++, j++) { - points [i] = _points [j]; - types [i] = _types [j]; - } - - return endIndex - startIndex; - } - - public void Dispose () - { - } - - ~GraphicsPathIterator () - { - } - - public int Enumerate (ref PointF [] points, ref byte [] types) - { - points = _points; - types = _types; - - return _count; - } - - public bool HasCurve () - { - foreach (byte b in _types) - if (b == (byte) PathPointType.Bezier) - return true; - - return false; - } - - [MonoTODO] - public int NextMarker (GraphicsPath path) - { - throw new NotImplementedException (); - } - - [MonoTODO] - public int NextMarker (out int startIndex, out int endIndex) - { - throw new NotImplementedException (); - } - - [MonoTODO] - public int NextPathType (out byte pathType, out int startIndex, out int endIndex) - { - throw new NotImplementedException (); - } - - [MonoTODO] - public int NextSubpath (GraphicsPath path, out bool isClosed) - { - throw new NotImplementedException (); - } - - [MonoTODO] - public int NextSubpath (out int startIndex, out int endIndex, out bool isClosed) - { - throw new NotImplementedException (); - } - - public void Rewind () - { - _current = 0; - } - } -} +using System; +using System.Drawing; + +namespace System.Drawing.Drawing2D +{ + public sealed class GraphicsPathIterator : MarshalByRefObject, IDisposable + { + private IntPtr nativeObject = IntPtr.Zero; + + // Constructors + internal GraphicsPathIterator (IntPtr native) + { + this.nativeObject = native; + } + + public GraphicsPathIterator (GraphicsPath path) + { + Status status = GDIPlus.GdipCreatePathIter (out nativeObject, path.NativeObject); + GDIPlus.CheckStatus (status); + } + + internal IntPtr NativeObject { + get { + return nativeObject; + } + set { + nativeObject = value; + } + } + + // Public Properites + + public int Count { + get { + int count; + Status status = GDIPlus.GdipPathIterGetCount (nativeObject, out count); + GDIPlus.CheckStatus (status); + + return count; + } + } + + public int SubpathCount { + get { + int count; + Status status = GDIPlus.GdipPathIterGetSubpathCount (nativeObject, out count); + GDIPlus.CheckStatus (status); + + return count; + } + } + + internal void Dispose (bool disposing) + { + Status status; + if (nativeObject != IntPtr.Zero) { + status = GDIPlus.GdipDeletePathIter (nativeObject); + GDIPlus.CheckStatus (status); + + nativeObject = IntPtr.Zero; + } + } + + // Public Methods. + + public int CopyData (ref PointF [] points, ref byte [] types, int startIndex, int endIndex) + { + Status status; + int resultCount; + + if (points.Length != types.Length) + throw new ArgumentException ("Invalid arguments passed. Both arrays should have the same length."); + + status = GDIPlus.GdipPathIterCopyData (nativeObject, out resultCount, points, types, startIndex, endIndex); + GDIPlus.CheckStatus (status); + + return resultCount; + } + + public void Dispose () + { + Dispose (true); + System.GC.SuppressFinalize (this); + } + + ~GraphicsPathIterator () + { + Dispose (false); + } + + public int Enumerate (ref PointF [] points, ref byte [] types) + { + Status status; + int resultCount; + int count = points.Length; + + if (count != types.Length) + throw new ArgumentException ("Invalid arguments passed. Both arrays should have the same length."); + + status = GDIPlus.GdipPathIterEnumerate (nativeObject, out resultCount, points, types, count); + GDIPlus.CheckStatus (status); + + return resultCount; + } + + public bool HasCurve () + { + bool curve; + Status status = GDIPlus.GdipPathIterHasCurve (nativeObject, out curve); + GDIPlus.CheckStatus (status); + + return curve; + } + + public int NextMarker (GraphicsPath path) + { + Status status; + int resultCount; + status = GDIPlus.GdipPathIterNextMarkerPath (nativeObject, out resultCount, path.NativeObject); + GDIPlus.CheckStatus (status); + + return resultCount; + } + + public int NextMarker (out int startIndex, out int endIndex) + { + Status status; + int resultCount; + status = GDIPlus.GdipPathIterNextMarker (nativeObject, out resultCount, out startIndex, out endIndex); + GDIPlus.CheckStatus (status); + + return resultCount; + } + + public int NextPathType (out byte pathType, out int startIndex, out int endIndex) + { + Status status; + int resultCount; + status = GDIPlus.GdipPathIterNextPathType (nativeObject, out resultCount, out pathType, out startIndex, out endIndex); + GDIPlus.CheckStatus (status); + + return resultCount; + } + + public int NextSubpath (GraphicsPath path, out bool isClosed) + { + Status status; + int resultCount; + status = GDIPlus.GdipPathIterNextSubpathPath (nativeObject, out resultCount, path.NativeObject, out isClosed); + GDIPlus.CheckStatus (status); + + return resultCount; + } + + public int NextSubpath (out int startIndex, out int endIndex, out bool isClosed) + { + Status status; + int resultCount; + status = GDIPlus.GdipPathIterNextSubpath (nativeObject, out resultCount, out startIndex, out endIndex, out isClosed); + GDIPlus.CheckStatus (status); + + return resultCount; + } + + public void Rewind () + { + Status status = GDIPlus.GdipPathIterRewind (nativeObject); + GDIPlus.CheckStatus (status); + } + } +}