GraphicsPathIterator.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // System.Drawing.Drawing2D.GraphicsPathIterator.cs
  3. //
  4. // Author:
  5. // Dennis Hayes ([email protected])
  6. // Duncan Mak ([email protected])
  7. // Ravindra ([email protected])
  8. //
  9. // Copyright (C) 2002/3 Ximian, Inc (http://www.ximian.com)
  10. //
  11. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System;
  33. using System.Drawing;
  34. namespace System.Drawing.Drawing2D
  35. {
  36. public sealed class GraphicsPathIterator : MarshalByRefObject, IDisposable
  37. {
  38. private IntPtr nativeObject = IntPtr.Zero;
  39. // Constructors
  40. internal GraphicsPathIterator (IntPtr native)
  41. {
  42. this.nativeObject = native;
  43. }
  44. public GraphicsPathIterator (GraphicsPath path)
  45. {
  46. Status status = GDIPlus.GdipCreatePathIter (out nativeObject, path.NativeObject);
  47. GDIPlus.CheckStatus (status);
  48. }
  49. internal IntPtr NativeObject {
  50. get {
  51. return nativeObject;
  52. }
  53. set {
  54. nativeObject = value;
  55. }
  56. }
  57. // Public Properites
  58. public int Count {
  59. get {
  60. int count;
  61. Status status = GDIPlus.GdipPathIterGetCount (nativeObject, out count);
  62. GDIPlus.CheckStatus (status);
  63. return count;
  64. }
  65. }
  66. public int SubpathCount {
  67. get {
  68. int count;
  69. Status status = GDIPlus.GdipPathIterGetSubpathCount (nativeObject, out count);
  70. GDIPlus.CheckStatus (status);
  71. return count;
  72. }
  73. }
  74. internal void Dispose (bool disposing)
  75. {
  76. Status status;
  77. if (nativeObject != IntPtr.Zero) {
  78. status = GDIPlus.GdipDeletePathIter (nativeObject);
  79. GDIPlus.CheckStatus (status);
  80. nativeObject = IntPtr.Zero;
  81. }
  82. }
  83. // Public Methods.
  84. public int CopyData (ref PointF [] points, ref byte [] types, int startIndex, int endIndex)
  85. {
  86. Status status;
  87. int resultCount;
  88. if (points.Length != types.Length)
  89. throw new ArgumentException ("Invalid arguments passed. Both arrays should have the same length.");
  90. status = GDIPlus.GdipPathIterCopyData (nativeObject, out resultCount, points, types, startIndex, endIndex);
  91. GDIPlus.CheckStatus (status);
  92. return resultCount;
  93. }
  94. public void Dispose ()
  95. {
  96. Dispose (true);
  97. System.GC.SuppressFinalize (this);
  98. }
  99. ~GraphicsPathIterator ()
  100. {
  101. Dispose (false);
  102. }
  103. public int Enumerate (ref PointF [] points, ref byte [] types)
  104. {
  105. Status status;
  106. int resultCount;
  107. int count = points.Length;
  108. if (count != types.Length)
  109. throw new ArgumentException ("Invalid arguments passed. Both arrays should have the same length.");
  110. status = GDIPlus.GdipPathIterEnumerate (nativeObject, out resultCount, points, types, count);
  111. GDIPlus.CheckStatus (status);
  112. return resultCount;
  113. }
  114. public bool HasCurve ()
  115. {
  116. bool curve;
  117. Status status = GDIPlus.GdipPathIterHasCurve (nativeObject, out curve);
  118. GDIPlus.CheckStatus (status);
  119. return curve;
  120. }
  121. public int NextMarker (GraphicsPath path)
  122. {
  123. Status status;
  124. int resultCount;
  125. status = GDIPlus.GdipPathIterNextMarkerPath (nativeObject, out resultCount, path.NativeObject);
  126. GDIPlus.CheckStatus (status);
  127. return resultCount;
  128. }
  129. public int NextMarker (out int startIndex, out int endIndex)
  130. {
  131. Status status;
  132. int resultCount;
  133. status = GDIPlus.GdipPathIterNextMarker (nativeObject, out resultCount, out startIndex, out endIndex);
  134. GDIPlus.CheckStatus (status);
  135. return resultCount;
  136. }
  137. public int NextPathType (out byte pathType, out int startIndex, out int endIndex)
  138. {
  139. Status status;
  140. int resultCount;
  141. status = GDIPlus.GdipPathIterNextPathType (nativeObject, out resultCount, out pathType, out startIndex, out endIndex);
  142. GDIPlus.CheckStatus (status);
  143. return resultCount;
  144. }
  145. public int NextSubpath (GraphicsPath path, out bool isClosed)
  146. {
  147. Status status;
  148. int resultCount;
  149. status = GDIPlus.GdipPathIterNextSubpathPath (nativeObject, out resultCount, path.NativeObject, out isClosed);
  150. GDIPlus.CheckStatus (status);
  151. return resultCount;
  152. }
  153. public int NextSubpath (out int startIndex, out int endIndex, out bool isClosed)
  154. {
  155. Status status;
  156. int resultCount;
  157. status = GDIPlus.GdipPathIterNextSubpath (nativeObject, out resultCount, out startIndex, out endIndex, out isClosed);
  158. GDIPlus.CheckStatus (status);
  159. return resultCount;
  160. }
  161. public void Rewind ()
  162. {
  163. Status status = GDIPlus.GdipPathIterRewind (nativeObject);
  164. GDIPlus.CheckStatus (status);
  165. }
  166. }
  167. }