GraphicsPath.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. //
  2. // System.Drawing.Drawing2D.GraphicsPath.cs
  3. //
  4. // Authors:
  5. //
  6. // Miguel de Icaza ([email protected])
  7. // Duncan Mak ([email protected])
  8. // Jordi Mas i Hernandez ([email protected])
  9. // Ravindra ([email protected])
  10. // Sebastien Pouliot <[email protected]>
  11. //
  12. // Copyright (C) 2004,2006-2007 Novell, Inc (http://www.novell.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System.ComponentModel;
  34. using System.Runtime.InteropServices;
  35. namespace System.Drawing.Drawing2D
  36. {
  37. public sealed class GraphicsPath : MarshalByRefObject, ICloneable, IDisposable
  38. {
  39. // 1/4 is the FlatnessDefault as defined in GdiPlusEnums.h
  40. private const float FlatnessDefault = 1.0f / 4.0f;
  41. internal IntPtr nativePath = IntPtr.Zero;
  42. GraphicsPath (IntPtr ptr)
  43. {
  44. nativePath = ptr;
  45. }
  46. public GraphicsPath ()
  47. {
  48. Status status = GDIPlus.GdipCreatePath (FillMode.Alternate, out nativePath);
  49. GDIPlus.CheckStatus (status);
  50. }
  51. public GraphicsPath (FillMode fillMode)
  52. {
  53. Status status = GDIPlus.GdipCreatePath (fillMode, out nativePath);
  54. GDIPlus.CheckStatus (status);
  55. }
  56. public GraphicsPath (Point[] pts, byte[] types)
  57. : this (pts, types, FillMode.Alternate)
  58. {
  59. }
  60. public GraphicsPath (PointF[] pts, byte[] types)
  61. : this (pts, types, FillMode.Alternate)
  62. {
  63. }
  64. public GraphicsPath (Point[] pts, byte[] types, FillMode fillMode)
  65. {
  66. if (pts == null)
  67. throw new ArgumentNullException ("pts");
  68. if (pts.Length != types.Length)
  69. throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
  70. Status status = GDIPlus.GdipCreatePath2I (pts, types, pts.Length, fillMode, out nativePath);
  71. GDIPlus.CheckStatus (status);
  72. }
  73. public GraphicsPath (PointF[] pts, byte[] types, FillMode fillMode)
  74. {
  75. if (pts == null)
  76. throw new ArgumentNullException ("pts");
  77. if (pts.Length != types.Length)
  78. throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
  79. Status status = GDIPlus.GdipCreatePath2 (pts, types, pts.Length, fillMode, out nativePath);
  80. GDIPlus.CheckStatus (status);
  81. }
  82. public object Clone ()
  83. {
  84. IntPtr clone;
  85. Status status = GDIPlus.GdipClonePath (nativePath, out clone);
  86. GDIPlus.CheckStatus (status);
  87. return new GraphicsPath (clone);
  88. }
  89. public void Dispose ()
  90. {
  91. Dispose (true);
  92. System.GC.SuppressFinalize (this);
  93. }
  94. ~GraphicsPath ()
  95. {
  96. Dispose (false);
  97. }
  98. void Dispose (bool disposing)
  99. {
  100. Status status;
  101. if (nativePath != IntPtr.Zero) {
  102. status = GDIPlus.GdipDeletePath (nativePath);
  103. GDIPlus.CheckStatus (status);
  104. nativePath = IntPtr.Zero;
  105. }
  106. }
  107. public FillMode FillMode {
  108. get {
  109. FillMode mode;
  110. Status status = GDIPlus.GdipGetPathFillMode (nativePath, out mode);
  111. GDIPlus.CheckStatus (status);
  112. return mode;
  113. }
  114. set {
  115. if ((value < FillMode.Alternate) || (value > FillMode.Winding))
  116. throw new InvalidEnumArgumentException ("FillMode", (int)value, typeof (FillMode));
  117. Status status = GDIPlus.GdipSetPathFillMode (nativePath, value);
  118. GDIPlus.CheckStatus (status);
  119. }
  120. }
  121. public PathData PathData {
  122. get {
  123. int count;
  124. Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
  125. GDIPlus.CheckStatus (status);
  126. PointF [] points = new PointF [count];
  127. byte [] types = new byte [count];
  128. // status would fail if we ask points or types with a 0 count
  129. // anyway that would only mean two unrequired unmanaged calls
  130. if (count > 0) {
  131. status = GDIPlus.GdipGetPathPoints (nativePath, points, count);
  132. GDIPlus.CheckStatus (status);
  133. status = GDIPlus.GdipGetPathTypes (nativePath, types, count);
  134. GDIPlus.CheckStatus (status);
  135. }
  136. PathData pdata = new PathData ();
  137. pdata.Points = points;
  138. pdata.Types = types;
  139. return pdata;
  140. }
  141. }
  142. public PointF [] PathPoints {
  143. get {
  144. int count;
  145. Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
  146. GDIPlus.CheckStatus (status);
  147. if (count == 0)
  148. throw new ArgumentException ("PathPoints");
  149. PointF [] points = new PointF [count];
  150. status = GDIPlus.GdipGetPathPoints (nativePath, points, count);
  151. GDIPlus.CheckStatus (status);
  152. return points;
  153. }
  154. }
  155. public byte [] PathTypes {
  156. get {
  157. int count;
  158. Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
  159. GDIPlus.CheckStatus (status);
  160. if (count == 0)
  161. throw new ArgumentException ("PathTypes");
  162. byte [] types = new byte [count];
  163. status = GDIPlus.GdipGetPathTypes (nativePath, types, count);
  164. GDIPlus.CheckStatus (status);
  165. return types;
  166. }
  167. }
  168. public int PointCount {
  169. get {
  170. int count;
  171. Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
  172. GDIPlus.CheckStatus (status);
  173. return count;
  174. }
  175. }
  176. internal IntPtr NativeObject {
  177. get {
  178. return nativePath;
  179. }
  180. set {
  181. nativePath = value;
  182. }
  183. }
  184. //
  185. // AddArc
  186. //
  187. public void AddArc (Rectangle rect, float start_angle, float sweep_angle)
  188. {
  189. Status status = GDIPlus.GdipAddPathArcI (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
  190. GDIPlus.CheckStatus (status);
  191. }
  192. public void AddArc (RectangleF rect, float start_angle, float sweep_angle)
  193. {
  194. Status status = GDIPlus.GdipAddPathArc (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
  195. GDIPlus.CheckStatus (status);
  196. }
  197. public void AddArc (int x, int y, int width, int height, float start_angle, float sweep_angle)
  198. {
  199. Status status = GDIPlus.GdipAddPathArcI (nativePath, x, y, width, height, start_angle, sweep_angle);
  200. GDIPlus.CheckStatus (status);
  201. }
  202. public void AddArc (float x, float y, float width, float height, float start_angle, float sweep_angle)
  203. {
  204. Status status = GDIPlus.GdipAddPathArc (nativePath, x, y, width, height, start_angle, sweep_angle);
  205. GDIPlus.CheckStatus (status);
  206. }
  207. //
  208. // AddBezier
  209. //
  210. public void AddBezier (Point pt1, Point pt2, Point pt3, Point pt4)
  211. {
  212. Status status = GDIPlus.GdipAddPathBezierI (nativePath, pt1.X, pt1.Y,
  213. pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
  214. GDIPlus.CheckStatus (status);
  215. }
  216. public void AddBezier (PointF pt1, PointF pt2, PointF pt3, PointF pt4)
  217. {
  218. Status status = GDIPlus.GdipAddPathBezier (nativePath, pt1.X, pt1.Y,
  219. pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
  220. GDIPlus.CheckStatus (status);
  221. }
  222. public void AddBezier (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
  223. {
  224. Status status = GDIPlus.GdipAddPathBezierI (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
  225. GDIPlus.CheckStatus (status);
  226. }
  227. public void AddBezier (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
  228. {
  229. Status status = GDIPlus.GdipAddPathBezier (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
  230. GDIPlus.CheckStatus (status);
  231. }
  232. //
  233. // AddBeziers
  234. //
  235. #if NET_2_0
  236. public void AddBeziers (params Point [] pts)
  237. #else
  238. public void AddBeziers (Point [] pts)
  239. #endif
  240. {
  241. if (pts == null)
  242. throw new ArgumentNullException ("pts");
  243. Status status = GDIPlus.GdipAddPathBeziersI (nativePath, pts, pts.Length);
  244. GDIPlus.CheckStatus (status);
  245. }
  246. public void AddBeziers (PointF [] pts)
  247. {
  248. if (pts == null)
  249. throw new ArgumentNullException ("pts");
  250. Status status = GDIPlus.GdipAddPathBeziers (nativePath, pts, pts.Length);
  251. GDIPlus.CheckStatus (status);
  252. }
  253. //
  254. // AddEllipse
  255. //
  256. public void AddEllipse (RectangleF r)
  257. {
  258. Status status = GDIPlus.GdipAddPathEllipse (nativePath, r.X, r.Y, r.Width, r.Height);
  259. GDIPlus.CheckStatus (status);
  260. }
  261. public void AddEllipse (float x, float y, float width, float height)
  262. {
  263. Status status = GDIPlus.GdipAddPathEllipse (nativePath, x, y, width, height);
  264. GDIPlus.CheckStatus (status);
  265. }
  266. public void AddEllipse (Rectangle r)
  267. {
  268. Status status = GDIPlus.GdipAddPathEllipseI (nativePath, r.X, r.Y, r.Width, r.Height);
  269. GDIPlus.CheckStatus (status);
  270. }
  271. public void AddEllipse (int x, int y, int width, int height)
  272. {
  273. Status status = GDIPlus.GdipAddPathEllipseI (nativePath, x, y, width, height);
  274. GDIPlus.CheckStatus (status);
  275. }
  276. //
  277. // AddLine
  278. //
  279. public void AddLine (Point a, Point b)
  280. {
  281. Status status = GDIPlus.GdipAddPathLineI (nativePath, a.X, a.Y, b.X, b.Y);
  282. GDIPlus.CheckStatus (status);
  283. }
  284. public void AddLine (PointF a, PointF b)
  285. {
  286. Status status = GDIPlus.GdipAddPathLine (nativePath, a.X, a.Y, b.X,
  287. b.Y);
  288. GDIPlus.CheckStatus (status);
  289. }
  290. public void AddLine (int x1, int y1, int x2, int y2)
  291. {
  292. Status status = GDIPlus.GdipAddPathLineI (nativePath, x1, y1, x2, y2);
  293. GDIPlus.CheckStatus (status);
  294. }
  295. public void AddLine (float x1, float y1, float x2, float y2)
  296. {
  297. Status status = GDIPlus.GdipAddPathLine (nativePath, x1, y1, x2,
  298. y2);
  299. GDIPlus.CheckStatus (status);
  300. }
  301. //
  302. // AddLines
  303. //
  304. public void AddLines (Point[] points)
  305. {
  306. if (points == null)
  307. throw new ArgumentNullException ("points");
  308. if (points.Length == 0)
  309. throw new ArgumentException ("points");
  310. Status status = GDIPlus.GdipAddPathLine2I (nativePath, points, points.Length);
  311. GDIPlus.CheckStatus (status);
  312. }
  313. public void AddLines (PointF[] points)
  314. {
  315. if (points == null)
  316. throw new ArgumentNullException ("points");
  317. if (points.Length == 0)
  318. throw new ArgumentException ("points");
  319. Status status = GDIPlus.GdipAddPathLine2 (nativePath, points, points.Length);
  320. GDIPlus.CheckStatus (status);
  321. }
  322. //
  323. // AddPie
  324. //
  325. public void AddPie (Rectangle rect, float startAngle, float sweepAngle)
  326. {
  327. Status status = GDIPlus.GdipAddPathPie (
  328. nativePath, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
  329. GDIPlus.CheckStatus (status);
  330. }
  331. public void AddPie (int x, int y, int width, int height, float startAngle, float sweepAngle)
  332. {
  333. Status status = GDIPlus.GdipAddPathPieI (nativePath, x, y, width, height, startAngle, sweepAngle);
  334. GDIPlus.CheckStatus (status);
  335. }
  336. public void AddPie (float x, float y, float width, float height, float startAngle, float sweepAngle)
  337. {
  338. Status status = GDIPlus.GdipAddPathPie (nativePath, x, y, width, height, startAngle, sweepAngle);
  339. GDIPlus.CheckStatus (status);
  340. }
  341. //
  342. // AddPolygon
  343. //
  344. public void AddPolygon (Point [] points)
  345. {
  346. if (points == null)
  347. throw new ArgumentNullException ("points");
  348. Status status = GDIPlus.GdipAddPathPolygonI (nativePath, points, points.Length);
  349. GDIPlus.CheckStatus (status);
  350. }
  351. public void AddPolygon (PointF [] points)
  352. {
  353. if (points == null)
  354. throw new ArgumentNullException ("points");
  355. Status status = GDIPlus.GdipAddPathPolygon (nativePath, points, points.Length);
  356. GDIPlus.CheckStatus (status);
  357. }
  358. //
  359. // AddRectangle
  360. //
  361. public void AddRectangle (Rectangle rect)
  362. {
  363. Status status = GDIPlus.GdipAddPathRectangleI (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
  364. GDIPlus.CheckStatus (status);
  365. }
  366. public void AddRectangle (RectangleF rect)
  367. {
  368. Status status = GDIPlus.GdipAddPathRectangle (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
  369. GDIPlus.CheckStatus (status);
  370. }
  371. //
  372. // AddRectangles
  373. //
  374. public void AddRectangles (Rectangle [] rects)
  375. {
  376. if (rects == null)
  377. throw new ArgumentNullException ("rects");
  378. if (rects.Length == 0)
  379. throw new ArgumentException ("rects");
  380. Status status = GDIPlus.GdipAddPathRectanglesI (nativePath, rects, rects.Length);
  381. GDIPlus.CheckStatus (status);
  382. }
  383. public void AddRectangles (RectangleF [] rects)
  384. {
  385. if (rects == null)
  386. throw new ArgumentNullException ("rects");
  387. if (rects.Length == 0)
  388. throw new ArgumentException ("rects");
  389. Status status = GDIPlus.GdipAddPathRectangles (nativePath, rects, rects.Length);
  390. GDIPlus.CheckStatus (status);
  391. }
  392. //
  393. // AddPath
  394. //
  395. public void AddPath (GraphicsPath addingPath, bool connect)
  396. {
  397. if (addingPath == null)
  398. throw new ArgumentNullException ("addingPath");
  399. Status status = GDIPlus.GdipAddPathPath (nativePath, addingPath.nativePath, connect);
  400. GDIPlus.CheckStatus (status);
  401. }
  402. public PointF GetLastPoint ()
  403. {
  404. PointF pt;
  405. Status status = GDIPlus.GdipGetPathLastPoint (nativePath, out pt);
  406. GDIPlus.CheckStatus (status);
  407. return pt;
  408. }
  409. //
  410. // AddClosedCurve
  411. //
  412. public void AddClosedCurve (Point [] points)
  413. {
  414. if (points == null)
  415. throw new ArgumentNullException ("points");
  416. Status status = GDIPlus.GdipAddPathClosedCurveI (nativePath, points, points.Length);
  417. GDIPlus.CheckStatus (status);
  418. }
  419. public void AddClosedCurve (PointF [] points)
  420. {
  421. if (points == null)
  422. throw new ArgumentNullException ("points");
  423. Status status = GDIPlus.GdipAddPathClosedCurve (nativePath, points, points.Length);
  424. GDIPlus.CheckStatus (status);
  425. }
  426. public void AddClosedCurve (Point [] points, float tension)
  427. {
  428. if (points == null)
  429. throw new ArgumentNullException ("points");
  430. Status status = GDIPlus.GdipAddPathClosedCurve2I (nativePath, points, points.Length, tension);
  431. GDIPlus.CheckStatus (status);
  432. }
  433. public void AddClosedCurve (PointF [] points, float tension)
  434. {
  435. if (points == null)
  436. throw new ArgumentNullException ("points");
  437. Status status = GDIPlus.GdipAddPathClosedCurve2 (nativePath, points, points.Length, tension);
  438. GDIPlus.CheckStatus (status);
  439. }
  440. //
  441. // AddCurve
  442. //
  443. public void AddCurve (Point [] points)
  444. {
  445. if (points == null)
  446. throw new ArgumentNullException ("points");
  447. Status status = GDIPlus.GdipAddPathCurveI (nativePath, points, points.Length);
  448. GDIPlus.CheckStatus (status);
  449. }
  450. public void AddCurve (PointF [] points)
  451. {
  452. if (points == null)
  453. throw new ArgumentNullException ("points");
  454. Status status = GDIPlus.GdipAddPathCurve (nativePath, points, points.Length);
  455. GDIPlus.CheckStatus (status);
  456. }
  457. public void AddCurve (Point [] points, float tension)
  458. {
  459. if (points == null)
  460. throw new ArgumentNullException ("points");
  461. Status status = GDIPlus.GdipAddPathCurve2I (nativePath, points, points.Length, tension);
  462. GDIPlus.CheckStatus (status);
  463. }
  464. public void AddCurve (PointF [] points, float tension)
  465. {
  466. if (points == null)
  467. throw new ArgumentNullException ("points");
  468. Status status = GDIPlus.GdipAddPathCurve2 (nativePath, points, points.Length, tension);
  469. GDIPlus.CheckStatus (status);
  470. }
  471. public void AddCurve (Point [] points, int offset, int numberOfSegments, float tension)
  472. {
  473. if (points == null)
  474. throw new ArgumentNullException ("points");
  475. Status status = GDIPlus.GdipAddPathCurve3I (nativePath, points, points.Length,
  476. offset, numberOfSegments, tension);
  477. GDIPlus.CheckStatus (status);
  478. }
  479. public void AddCurve (PointF [] points, int offset, int numberOfSegments, float tension)
  480. {
  481. if (points == null)
  482. throw new ArgumentNullException ("points");
  483. Status status = GDIPlus.GdipAddPathCurve3 (nativePath, points, points.Length,
  484. offset, numberOfSegments, tension);
  485. GDIPlus.CheckStatus (status);
  486. }
  487. public void Reset ()
  488. {
  489. Status status = GDIPlus.GdipResetPath (nativePath);
  490. GDIPlus.CheckStatus (status);
  491. }
  492. public void Reverse ()
  493. {
  494. Status status = GDIPlus.GdipReversePath (nativePath);
  495. GDIPlus.CheckStatus (status);
  496. }
  497. public void Transform (Matrix matrix)
  498. {
  499. if (matrix == null)
  500. throw new ArgumentNullException ("matrix");
  501. Status status = GDIPlus.GdipTransformPath (nativePath, matrix.nativeMatrix);
  502. GDIPlus.CheckStatus (status);
  503. }
  504. [MonoTODO ("The StringFormat parameter is ignored when using libgdiplus.")]
  505. public void AddString (string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
  506. {
  507. Rectangle layout = new Rectangle ();
  508. layout.X = origin.X;
  509. layout.Y = origin.Y;
  510. AddString (s, family, style, emSize, layout, format);
  511. }
  512. [MonoTODO ("The StringFormat parameter is ignored when using libgdiplus.")]
  513. public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
  514. {
  515. RectangleF layout = new RectangleF ();
  516. layout.X = origin.X;
  517. layout.Y = origin.Y;
  518. AddString (s, family, style, emSize, layout, format);
  519. }
  520. [MonoTODO ("The layoutRect and StringFormat parameters are ignored when using libgdiplus.")]
  521. public void AddString (string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
  522. {
  523. if (family == null)
  524. throw new ArgumentException ("family");
  525. IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
  526. // note: the NullReferenceException on s.Length is the expected (MS) exception
  527. Status status = GDIPlus.GdipAddPathStringI (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
  528. GDIPlus.CheckStatus (status);
  529. }
  530. [MonoTODO ("The layoutRect and StringFormat parameters are ignored when using libgdiplus.")]
  531. public void AddString (string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
  532. {
  533. if (family == null)
  534. throw new ArgumentException ("family");
  535. IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
  536. // note: the NullReferenceException on s.Length is the expected (MS) exception
  537. Status status = GDIPlus.GdipAddPathString (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
  538. GDIPlus.CheckStatus (status);
  539. }
  540. public void ClearMarkers()
  541. {
  542. Status s = GDIPlus.GdipClearPathMarkers (nativePath);
  543. GDIPlus.CheckStatus (s);
  544. }
  545. public void CloseAllFigures()
  546. {
  547. Status s = GDIPlus.GdipClosePathFigures (nativePath);
  548. GDIPlus.CheckStatus (s);
  549. }
  550. public void CloseFigure()
  551. {
  552. Status s = GDIPlus.GdipClosePathFigure (nativePath);
  553. GDIPlus.CheckStatus (s);
  554. }
  555. public void Flatten ()
  556. {
  557. Flatten (null, FlatnessDefault);
  558. }
  559. public void Flatten (Matrix matrix)
  560. {
  561. Flatten (matrix, FlatnessDefault);
  562. }
  563. public void Flatten (Matrix matrix, float flatness)
  564. {
  565. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  566. Status status = GDIPlus.GdipFlattenPath (nativePath, m, flatness);
  567. GDIPlus.CheckStatus (status);
  568. }
  569. public RectangleF GetBounds ()
  570. {
  571. return GetBounds (null, null);
  572. }
  573. public RectangleF GetBounds (Matrix matrix)
  574. {
  575. return GetBounds (matrix, null);
  576. }
  577. public RectangleF GetBounds (Matrix matrix, Pen pen)
  578. {
  579. RectangleF retval;
  580. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  581. IntPtr p = (pen == null) ? IntPtr.Zero : pen.nativeObject;
  582. Status s = GDIPlus.GdipGetPathWorldBounds (nativePath, out retval, m, p);
  583. GDIPlus.CheckStatus (s);
  584. return retval;
  585. }
  586. public bool IsOutlineVisible (Point point, Pen pen)
  587. {
  588. return IsOutlineVisible (point.X, point.Y, pen, null);
  589. }
  590. public bool IsOutlineVisible (PointF point, Pen pen)
  591. {
  592. return IsOutlineVisible (point.X, point.Y, pen, null);
  593. }
  594. public bool IsOutlineVisible (int x, int y, Pen pen)
  595. {
  596. return IsOutlineVisible (x, y, pen, null);
  597. }
  598. public bool IsOutlineVisible (float x, float y, Pen pen)
  599. {
  600. return IsOutlineVisible (x, y, pen, null);
  601. }
  602. public bool IsOutlineVisible (Point pt, Pen pen, Graphics graphics)
  603. {
  604. return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
  605. }
  606. public bool IsOutlineVisible (PointF pt, Pen pen, Graphics graphics)
  607. {
  608. return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
  609. }
  610. public bool IsOutlineVisible (int x, int y, Pen pen, Graphics graphics)
  611. {
  612. if (pen == null)
  613. throw new ArgumentNullException ("pen");
  614. bool result;
  615. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  616. Status s = GDIPlus.GdipIsOutlineVisiblePathPointI (nativePath, x, y, pen.nativeObject, g, out result);
  617. GDIPlus.CheckStatus (s);
  618. return result;
  619. }
  620. public bool IsOutlineVisible (float x, float y, Pen pen, Graphics graphics)
  621. {
  622. if (pen == null)
  623. throw new ArgumentNullException ("pen");
  624. bool result;
  625. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  626. Status s = GDIPlus.GdipIsOutlineVisiblePathPoint (nativePath, x, y, pen.nativeObject, g, out result);
  627. GDIPlus.CheckStatus (s);
  628. return result;
  629. }
  630. public bool IsVisible (Point point)
  631. {
  632. return IsVisible (point.X, point.Y, null);
  633. }
  634. public bool IsVisible (PointF point)
  635. {
  636. return IsVisible (point.X, point.Y, null);
  637. }
  638. public bool IsVisible (int x, int y)
  639. {
  640. return IsVisible (x, y, null);
  641. }
  642. public bool IsVisible (float x, float y)
  643. {
  644. return IsVisible (x, y, null);
  645. }
  646. public bool IsVisible (Point pt, Graphics graphics)
  647. {
  648. return IsVisible (pt.X, pt.Y, graphics);
  649. }
  650. public bool IsVisible (PointF pt, Graphics graphics)
  651. {
  652. return IsVisible (pt.X, pt.Y, graphics);
  653. }
  654. public bool IsVisible (int x, int y, Graphics graphics)
  655. {
  656. bool retval;
  657. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  658. Status s = GDIPlus.GdipIsVisiblePathPointI (nativePath, x, y, g, out retval);
  659. GDIPlus.CheckStatus (s);
  660. return retval;
  661. }
  662. public bool IsVisible (float x, float y, Graphics graphics)
  663. {
  664. bool retval;
  665. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  666. Status s = GDIPlus.GdipIsVisiblePathPoint (nativePath, x, y, g, out retval);
  667. GDIPlus.CheckStatus (s);
  668. return retval;
  669. }
  670. public void SetMarkers ()
  671. {
  672. Status s = GDIPlus.GdipSetPathMarker (nativePath);
  673. GDIPlus.CheckStatus (s);
  674. }
  675. public void StartFigure()
  676. {
  677. Status s = GDIPlus.GdipStartPathFigure (nativePath);
  678. GDIPlus.CheckStatus (s);
  679. }
  680. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  681. public void Warp (PointF[] destPoints, RectangleF srcRect)
  682. {
  683. Warp (destPoints, srcRect, null, WarpMode.Perspective, FlatnessDefault);
  684. }
  685. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  686. public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix)
  687. {
  688. Warp (destPoints, srcRect, matrix, WarpMode.Perspective, FlatnessDefault);
  689. }
  690. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  691. public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode)
  692. {
  693. Warp (destPoints, srcRect, matrix, warpMode, FlatnessDefault);
  694. }
  695. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  696. public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode, float flatness)
  697. {
  698. if (destPoints == null)
  699. throw new ArgumentNullException ("destPoints");
  700. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  701. Status s = GDIPlus.GdipWarpPath (nativePath, m, destPoints, destPoints.Length,
  702. srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, warpMode, flatness);
  703. GDIPlus.CheckStatus (s);
  704. }
  705. [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
  706. public void Widen (Pen pen)
  707. {
  708. Widen (pen, null, FlatnessDefault);
  709. }
  710. [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
  711. public void Widen (Pen pen, Matrix matrix)
  712. {
  713. Widen (pen, matrix, FlatnessDefault);
  714. }
  715. [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
  716. public void Widen (Pen pen, Matrix matrix, float flatness)
  717. {
  718. if (pen == null)
  719. throw new ArgumentNullException ("pen");
  720. #if NET_2_0
  721. if (PointCount == 0)
  722. return;
  723. #endif
  724. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  725. Status s = GDIPlus.GdipWidenPath (nativePath, pen.nativeObject, m, flatness);
  726. GDIPlus.CheckStatus (s);
  727. }
  728. }
  729. }