GraphicsPath.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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 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. status = GDIPlus.GdipGetPathPoints (nativePath, points, count);
  128. GDIPlus.CheckStatus (status);
  129. byte [] types = new byte [count];
  130. status = GDIPlus.GdipGetPathTypes (nativePath, types, count);
  131. GDIPlus.CheckStatus (status);
  132. PathData pdata = new PathData ();
  133. pdata.Points = points;
  134. pdata.Types = types;
  135. return pdata;
  136. }
  137. }
  138. public PointF [] PathPoints {
  139. get {
  140. int count;
  141. Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
  142. GDIPlus.CheckStatus (status);
  143. if (count == 0)
  144. throw new ArgumentException ("PathPoints");
  145. PointF [] points = new PointF [count];
  146. status = GDIPlus.GdipGetPathPoints (nativePath, points, count);
  147. GDIPlus.CheckStatus (status);
  148. return points;
  149. }
  150. }
  151. public byte [] PathTypes {
  152. get {
  153. int count;
  154. Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
  155. GDIPlus.CheckStatus (status);
  156. if (count == 0)
  157. throw new ArgumentException ("PathTypes");
  158. byte [] types = new byte [count];
  159. status = GDIPlus.GdipGetPathTypes (nativePath, types, count);
  160. GDIPlus.CheckStatus (status);
  161. return types;
  162. }
  163. }
  164. public int PointCount {
  165. get {
  166. int count;
  167. Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
  168. GDIPlus.CheckStatus (status);
  169. return count;
  170. }
  171. }
  172. internal IntPtr NativeObject {
  173. get {
  174. return nativePath;
  175. }
  176. set {
  177. nativePath = value;
  178. }
  179. }
  180. //
  181. // AddArc
  182. //
  183. public void AddArc (Rectangle rect, float start_angle, float sweep_angle)
  184. {
  185. Status status = GDIPlus.GdipAddPathArcI (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
  186. GDIPlus.CheckStatus (status);
  187. }
  188. public void AddArc (RectangleF rect, float start_angle, float sweep_angle)
  189. {
  190. Status status = GDIPlus.GdipAddPathArc (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
  191. GDIPlus.CheckStatus (status);
  192. }
  193. public void AddArc (int x, int y, int width, int height, float start_angle, float sweep_angle)
  194. {
  195. Status status = GDIPlus.GdipAddPathArcI (nativePath, x, y, width, height, start_angle, sweep_angle);
  196. GDIPlus.CheckStatus (status);
  197. }
  198. public void AddArc (float x, float y, float width, float height, float start_angle, float sweep_angle)
  199. {
  200. Status status = GDIPlus.GdipAddPathArc (nativePath, x, y, width, height, start_angle, sweep_angle);
  201. GDIPlus.CheckStatus (status);
  202. }
  203. //
  204. // AddBezier
  205. //
  206. public void AddBezier (Point pt1, Point pt2, Point pt3, Point pt4)
  207. {
  208. Status status = GDIPlus.GdipAddPathBezierI (nativePath, pt1.X, pt1.Y,
  209. pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
  210. GDIPlus.CheckStatus (status);
  211. }
  212. public void AddBezier (PointF pt1, PointF pt2, PointF pt3, PointF pt4)
  213. {
  214. Status status = GDIPlus.GdipAddPathBezier (nativePath, pt1.X, pt1.Y,
  215. pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
  216. GDIPlus.CheckStatus (status);
  217. }
  218. public void AddBezier (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
  219. {
  220. Status status = GDIPlus.GdipAddPathBezierI (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
  221. GDIPlus.CheckStatus (status);
  222. }
  223. public void AddBezier (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
  224. {
  225. Status status = GDIPlus.GdipAddPathBezier (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
  226. GDIPlus.CheckStatus (status);
  227. }
  228. //
  229. // AddBeziers
  230. //
  231. public void AddBeziers (Point [] pts)
  232. {
  233. if (pts == null)
  234. throw new ArgumentNullException ("pts");
  235. Status status = GDIPlus.GdipAddPathBeziersI (nativePath, pts, pts.Length);
  236. GDIPlus.CheckStatus (status);
  237. }
  238. public void AddBeziers (PointF [] pts)
  239. {
  240. if (pts == null)
  241. throw new ArgumentNullException ("pts");
  242. Status status = GDIPlus.GdipAddPathBeziers (nativePath, pts, pts.Length);
  243. GDIPlus.CheckStatus (status);
  244. }
  245. //
  246. // AddEllipse
  247. //
  248. public void AddEllipse (RectangleF r)
  249. {
  250. Status status = GDIPlus.GdipAddPathEllipse (nativePath, r.X, r.Y, r.Width, r.Height);
  251. GDIPlus.CheckStatus (status);
  252. }
  253. public void AddEllipse (float x, float y, float width, float height)
  254. {
  255. Status status = GDIPlus.GdipAddPathEllipse (nativePath, x, y, width, height);
  256. GDIPlus.CheckStatus (status);
  257. }
  258. public void AddEllipse (Rectangle r)
  259. {
  260. Status status = GDIPlus.GdipAddPathEllipseI (nativePath, r.X, r.Y, r.Width, r.Height);
  261. GDIPlus.CheckStatus (status);
  262. }
  263. public void AddEllipse (int x, int y, int width, int height)
  264. {
  265. Status status = GDIPlus.GdipAddPathEllipseI (nativePath, x, y, width, height);
  266. GDIPlus.CheckStatus (status);
  267. }
  268. //
  269. // AddLine
  270. //
  271. public void AddLine (Point a, Point b)
  272. {
  273. Status status = GDIPlus.GdipAddPathLineI (nativePath, a.X, a.Y, b.X, b.Y);
  274. GDIPlus.CheckStatus (status);
  275. }
  276. public void AddLine (PointF a, PointF b)
  277. {
  278. Status status = GDIPlus.GdipAddPathLine (nativePath, a.X, a.Y, b.X,
  279. b.Y);
  280. GDIPlus.CheckStatus (status);
  281. }
  282. public void AddLine (int x1, int y1, int x2, int y2)
  283. {
  284. Status status = GDIPlus.GdipAddPathLineI (nativePath, x1, y1, x2, y2);
  285. GDIPlus.CheckStatus (status);
  286. }
  287. public void AddLine (float x1, float y1, float x2, float y2)
  288. {
  289. Status status = GDIPlus.GdipAddPathLine (nativePath, x1, y1, x2,
  290. y2);
  291. GDIPlus.CheckStatus (status);
  292. }
  293. //
  294. // AddLines
  295. //
  296. public void AddLines (Point[] points)
  297. {
  298. if (points == null)
  299. throw new ArgumentNullException ("points");
  300. if (points.Length == 0)
  301. throw new ArgumentException ("points");
  302. Status status = GDIPlus.GdipAddPathLine2I (nativePath, points, points.Length);
  303. GDIPlus.CheckStatus (status);
  304. }
  305. public void AddLines (PointF[] points)
  306. {
  307. if (points == null)
  308. throw new ArgumentNullException ("points");
  309. if (points.Length == 0)
  310. throw new ArgumentException ("points");
  311. Status status = GDIPlus.GdipAddPathLine2 (nativePath, points, points.Length);
  312. GDIPlus.CheckStatus (status);
  313. }
  314. //
  315. // AddPie
  316. //
  317. public void AddPie (Rectangle rect, float startAngle, float sweepAngle)
  318. {
  319. Status status = GDIPlus.GdipAddPathPie (
  320. nativePath, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
  321. GDIPlus.CheckStatus (status);
  322. }
  323. public void AddPie (int x, int y, int width, int height, float startAngle, float sweepAngle)
  324. {
  325. Status status = GDIPlus.GdipAddPathPieI (nativePath, x, y, width, height, startAngle, sweepAngle);
  326. GDIPlus.CheckStatus (status);
  327. }
  328. public void AddPie (float x, float y, float width, float height, float startAngle, float sweepAngle)
  329. {
  330. Status status = GDIPlus.GdipAddPathPie (nativePath, x, y, width, height, startAngle, sweepAngle);
  331. GDIPlus.CheckStatus (status);
  332. }
  333. //
  334. // AddPolygon
  335. //
  336. public void AddPolygon (Point [] points)
  337. {
  338. if (points == null)
  339. throw new ArgumentNullException ("points");
  340. Status status = GDIPlus.GdipAddPathPolygonI (nativePath, points, points.Length);
  341. GDIPlus.CheckStatus (status);
  342. }
  343. public void AddPolygon (PointF [] points)
  344. {
  345. if (points == null)
  346. throw new ArgumentNullException ("points");
  347. Status status = GDIPlus.GdipAddPathPolygon (nativePath, points, points.Length);
  348. GDIPlus.CheckStatus (status);
  349. }
  350. //
  351. // AddRectangle
  352. //
  353. public void AddRectangle (Rectangle rect)
  354. {
  355. Status status = GDIPlus.GdipAddPathRectangleI (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
  356. GDIPlus.CheckStatus (status);
  357. }
  358. public void AddRectangle (RectangleF rect)
  359. {
  360. Status status = GDIPlus.GdipAddPathRectangle (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
  361. GDIPlus.CheckStatus (status);
  362. }
  363. //
  364. // AddRectangles
  365. //
  366. public void AddRectangles (Rectangle [] rects)
  367. {
  368. if (rects == null)
  369. throw new ArgumentNullException ("rects");
  370. if (rects.Length == 0)
  371. throw new ArgumentException ("rects");
  372. Status status = GDIPlus.GdipAddPathRectanglesI (nativePath, rects, rects.Length);
  373. GDIPlus.CheckStatus (status);
  374. }
  375. public void AddRectangles (RectangleF [] rects)
  376. {
  377. if (rects == null)
  378. throw new ArgumentNullException ("rects");
  379. if (rects.Length == 0)
  380. throw new ArgumentException ("rects");
  381. Status status = GDIPlus.GdipAddPathRectangles (nativePath, rects, rects.Length);
  382. GDIPlus.CheckStatus (status);
  383. }
  384. //
  385. // AddPath
  386. //
  387. public void AddPath (GraphicsPath addingPath, bool connect)
  388. {
  389. if (addingPath == null)
  390. throw new ArgumentNullException ("addingPath");
  391. Status status = GDIPlus.GdipAddPathPath (nativePath, addingPath.nativePath, connect);
  392. GDIPlus.CheckStatus (status);
  393. }
  394. public PointF GetLastPoint ()
  395. {
  396. PointF pt;
  397. Status status = GDIPlus.GdipGetPathLastPoint (nativePath, out pt);
  398. GDIPlus.CheckStatus (status);
  399. return pt;
  400. }
  401. //
  402. // AddClosedCurve
  403. //
  404. public void AddClosedCurve (Point [] points)
  405. {
  406. if (points == null)
  407. throw new ArgumentNullException ("points");
  408. Status status = GDIPlus.GdipAddPathClosedCurveI (nativePath, points, points.Length);
  409. GDIPlus.CheckStatus (status);
  410. }
  411. public void AddClosedCurve (PointF [] points)
  412. {
  413. if (points == null)
  414. throw new ArgumentNullException ("points");
  415. Status status = GDIPlus.GdipAddPathClosedCurve (nativePath, points, points.Length);
  416. GDIPlus.CheckStatus (status);
  417. }
  418. public void AddClosedCurve (Point [] points, float tension)
  419. {
  420. if (points == null)
  421. throw new ArgumentNullException ("points");
  422. Status status = GDIPlus.GdipAddPathClosedCurve2I (nativePath, points, points.Length, tension);
  423. GDIPlus.CheckStatus (status);
  424. }
  425. public void AddClosedCurve (PointF [] points, float tension)
  426. {
  427. if (points == null)
  428. throw new ArgumentNullException ("points");
  429. Status status = GDIPlus.GdipAddPathClosedCurve2 (nativePath, points, points.Length, tension);
  430. GDIPlus.CheckStatus (status);
  431. }
  432. //
  433. // AddCurve
  434. //
  435. public void AddCurve (Point [] points)
  436. {
  437. if (points == null)
  438. throw new ArgumentNullException ("points");
  439. Status status = GDIPlus.GdipAddPathCurveI (nativePath, points, points.Length);
  440. GDIPlus.CheckStatus (status);
  441. }
  442. public void AddCurve (PointF [] points)
  443. {
  444. if (points == null)
  445. throw new ArgumentNullException ("points");
  446. Status status = GDIPlus.GdipAddPathCurve (nativePath, points, points.Length);
  447. GDIPlus.CheckStatus (status);
  448. }
  449. public void AddCurve (Point [] points, float tension)
  450. {
  451. if (points == null)
  452. throw new ArgumentNullException ("points");
  453. Status status = GDIPlus.GdipAddPathCurve2I (nativePath, points, points.Length, tension);
  454. GDIPlus.CheckStatus (status);
  455. }
  456. public void AddCurve (PointF [] points, float tension)
  457. {
  458. if (points == null)
  459. throw new ArgumentNullException ("points");
  460. Status status = GDIPlus.GdipAddPathCurve2 (nativePath, points, points.Length, tension);
  461. GDIPlus.CheckStatus (status);
  462. }
  463. public void AddCurve (Point [] points, int offset, int numberOfSegments, float tension)
  464. {
  465. if (points == null)
  466. throw new ArgumentNullException ("points");
  467. Status status = GDIPlus.GdipAddPathCurve3I (nativePath, points, points.Length,
  468. offset, numberOfSegments, tension);
  469. GDIPlus.CheckStatus (status);
  470. }
  471. public void AddCurve (PointF [] points, int offset, int numberOfSegments, float tension)
  472. {
  473. if (points == null)
  474. throw new ArgumentNullException ("points");
  475. Status status = GDIPlus.GdipAddPathCurve3 (nativePath, points, points.Length,
  476. offset, numberOfSegments, tension);
  477. GDIPlus.CheckStatus (status);
  478. }
  479. public void Reset ()
  480. {
  481. Status status = GDIPlus.GdipResetPath (nativePath);
  482. GDIPlus.CheckStatus (status);
  483. }
  484. public void Reverse ()
  485. {
  486. Status status = GDIPlus.GdipReversePath (nativePath);
  487. GDIPlus.CheckStatus (status);
  488. }
  489. public void Transform (Matrix matrix)
  490. {
  491. if (matrix == null)
  492. throw new ArgumentNullException ("matrix");
  493. Status status = GDIPlus.GdipTransformPath (nativePath, matrix.nativeMatrix);
  494. GDIPlus.CheckStatus (status);
  495. }
  496. [MonoTODO ("StringFormat isn't supported inside libgdiplus")]
  497. public void AddString (string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
  498. {
  499. Rectangle layout = new Rectangle ();
  500. layout.X = origin.X;
  501. layout.Y = origin.Y;
  502. AddString (s, family, style, emSize, layout, format);
  503. }
  504. [MonoTODO ("StringFormat isn't supported inside libgdiplus")]
  505. public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
  506. {
  507. RectangleF layout = new RectangleF ();
  508. layout.X = origin.X;
  509. layout.Y = origin.Y;
  510. AddString (s, family, style, emSize, layout, format);
  511. }
  512. [MonoTODO ("layoutRect and StringFormat aren't supported inside libgdiplus")]
  513. public void AddString (string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
  514. {
  515. if (family == null)
  516. throw new ArgumentException ("family");
  517. IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
  518. // note: the NullReferenceException on s.Length is the expected (MS) exception
  519. Status status = GDIPlus.GdipAddPathStringI (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
  520. GDIPlus.CheckStatus (status);
  521. }
  522. [MonoTODO ("layoutRect and StringFormat aren't supported inside libgdiplus")]
  523. public void AddString (string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
  524. {
  525. if (family == null)
  526. throw new ArgumentException ("family");
  527. IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
  528. // note: the NullReferenceException on s.Length is the expected (MS) exception
  529. Status status = GDIPlus.GdipAddPathString (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
  530. GDIPlus.CheckStatus (status);
  531. }
  532. public void ClearMarkers()
  533. {
  534. Status s = GDIPlus.GdipClearPathMarkers (nativePath);
  535. GDIPlus.CheckStatus (s);
  536. }
  537. public void CloseAllFigures()
  538. {
  539. Status s = GDIPlus.GdipClosePathFigures (nativePath);
  540. GDIPlus.CheckStatus (s);
  541. }
  542. public void CloseFigure()
  543. {
  544. Status s = GDIPlus.GdipClosePathFigure (nativePath);
  545. GDIPlus.CheckStatus (s);
  546. }
  547. public void Flatten ()
  548. {
  549. Flatten (null, FlatnessDefault);
  550. }
  551. public void Flatten (Matrix matrix)
  552. {
  553. Flatten (matrix, FlatnessDefault);
  554. }
  555. public void Flatten (Matrix matrix, float flatness)
  556. {
  557. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  558. Status status = GDIPlus.GdipFlattenPath (nativePath, m, flatness);
  559. GDIPlus.CheckStatus (status);
  560. }
  561. public RectangleF GetBounds ()
  562. {
  563. return GetBounds (null, null);
  564. }
  565. public RectangleF GetBounds (Matrix matrix)
  566. {
  567. return GetBounds (matrix, null);
  568. }
  569. public RectangleF GetBounds (Matrix matrix, Pen pen)
  570. {
  571. RectangleF retval;
  572. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  573. IntPtr p = (pen == null) ? IntPtr.Zero : pen.nativeObject;
  574. Status s = GDIPlus.GdipGetPathWorldBounds (nativePath, out retval, m, p);
  575. GDIPlus.CheckStatus (s);
  576. return retval;
  577. }
  578. public bool IsOutlineVisible (Point point, Pen pen)
  579. {
  580. return IsOutlineVisible (point.X, point.Y, pen, null);
  581. }
  582. public bool IsOutlineVisible (PointF point, Pen pen)
  583. {
  584. return IsOutlineVisible (point.X, point.Y, pen, null);
  585. }
  586. public bool IsOutlineVisible (int x, int y, Pen pen)
  587. {
  588. return IsOutlineVisible (x, y, pen, null);
  589. }
  590. public bool IsOutlineVisible (float x, float y, Pen pen)
  591. {
  592. return IsOutlineVisible (x, y, pen, null);
  593. }
  594. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  595. public bool IsOutlineVisible (Point pt, Pen pen, Graphics graphics)
  596. {
  597. return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
  598. }
  599. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  600. public bool IsOutlineVisible (PointF pt, Pen pen, Graphics graphics)
  601. {
  602. return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
  603. }
  604. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  605. public bool IsOutlineVisible (int x, int y, Pen pen, Graphics graphics)
  606. {
  607. if (pen == null)
  608. throw new ArgumentNullException ("pen");
  609. bool result;
  610. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  611. Status s = GDIPlus.GdipIsOutlineVisiblePathPointI (nativePath, x, y, pen.nativeObject, g, out result);
  612. GDIPlus.CheckStatus (s);
  613. return result;
  614. }
  615. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  616. public bool IsOutlineVisible (float x, float y, Pen pen, Graphics graphics)
  617. {
  618. if (pen == null)
  619. throw new ArgumentNullException ("pen");
  620. bool result;
  621. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  622. Status s = GDIPlus.GdipIsOutlineVisiblePathPoint (nativePath, x, y, pen.nativeObject, g, out result);
  623. GDIPlus.CheckStatus (s);
  624. return result;
  625. }
  626. public bool IsVisible (Point point)
  627. {
  628. return IsVisible (point.X, point.Y, null);
  629. }
  630. public bool IsVisible (PointF point)
  631. {
  632. return IsVisible (point.X, point.Y, null);
  633. }
  634. public bool IsVisible (int x, int y)
  635. {
  636. return IsVisible (x, y, null);
  637. }
  638. public bool IsVisible (float x, float y)
  639. {
  640. return IsVisible (x, y, null);
  641. }
  642. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  643. public bool IsVisible (Point pt, Graphics graphics)
  644. {
  645. return IsVisible (pt.X, pt.Y, graphics);
  646. }
  647. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  648. public bool IsVisible (PointF pt, Graphics graphics)
  649. {
  650. return IsVisible (pt.X, pt.Y, graphics);
  651. }
  652. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  653. public bool IsVisible (int x, int y, Graphics graphics)
  654. {
  655. bool retval;
  656. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  657. Status s = GDIPlus.GdipIsVisiblePathPointI (nativePath, x, y, g, out retval);
  658. GDIPlus.CheckStatus (s);
  659. return retval;
  660. }
  661. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  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 ONLY_1_1
  721. if (PointCount == 0)
  722. throw new OutOfMemoryException ();
  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. }