GraphicsPath.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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. [MonoTODO ("libgdiplus doesn't use the numberOfSegments parameter")]
  464. public void AddCurve (Point [] points, int offset, int numberOfSegments, float tension)
  465. {
  466. if (points == null)
  467. throw new ArgumentNullException ("points");
  468. Status status = GDIPlus.GdipAddPathCurve3I (nativePath, points, points.Length,
  469. offset, numberOfSegments, tension);
  470. GDIPlus.CheckStatus (status);
  471. }
  472. [MonoTODO ("libgdiplus doesn't use the numberOfSegments parameter")]
  473. public void AddCurve (PointF [] points, int offset, int numberOfSegments, float tension)
  474. {
  475. if (points == null)
  476. throw new ArgumentNullException ("points");
  477. Status status = GDIPlus.GdipAddPathCurve3 (nativePath, points, points.Length,
  478. offset, numberOfSegments, tension);
  479. GDIPlus.CheckStatus (status);
  480. }
  481. public void Reset ()
  482. {
  483. Status status = GDIPlus.GdipResetPath (nativePath);
  484. GDIPlus.CheckStatus (status);
  485. }
  486. public void Reverse ()
  487. {
  488. Status status = GDIPlus.GdipReversePath (nativePath);
  489. GDIPlus.CheckStatus (status);
  490. }
  491. public void Transform (Matrix matrix)
  492. {
  493. if (matrix == null)
  494. throw new ArgumentNullException ("matrix");
  495. Status status = GDIPlus.GdipTransformPath (nativePath, matrix.nativeMatrix);
  496. GDIPlus.CheckStatus (status);
  497. }
  498. [MonoTODO ("StringFormat isn't supported inside libgdiplus")]
  499. public void AddString (string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
  500. {
  501. Rectangle layout;
  502. layout.X = origin.X;
  503. layout.Y = origin.Y;
  504. AddString (s, family, style, emSize, layout, format);
  505. }
  506. [MonoTODO ("StringFormat isn't supported inside libgdiplus")]
  507. public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
  508. {
  509. RectangleF layout;
  510. layout.X = origin.X;
  511. layout.Y = origin.Y;
  512. AddString (s, family, style, emSize, layout, format);
  513. }
  514. [MonoTODO ("layoutRect and StringFormat aren't supported inside libgdiplus")]
  515. public void AddString (string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
  516. {
  517. if (family == null)
  518. throw new ArgumentException ("family");
  519. IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
  520. // note: the NullReferenceException on s.Length is the expected (MS) exception
  521. Status status = GDIPlus.GdipAddStringI (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
  522. GDIPlus.CheckStatus (status);
  523. }
  524. [MonoTODO ("layoutRect and StringFormat aren't supported inside libgdiplus")]
  525. public void AddString (string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
  526. {
  527. if (family == null)
  528. throw new ArgumentException ("family");
  529. IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
  530. // note: the NullReferenceException on s.Length is the expected (MS) exception
  531. Status status = GDIPlus.GdipAddString (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
  532. GDIPlus.CheckStatus (status);
  533. }
  534. public void ClearMarkers()
  535. {
  536. Status s = GDIPlus.GdipClearPathMarkers (nativePath);
  537. GDIPlus.CheckStatus (s);
  538. }
  539. public void CloseAllFigures()
  540. {
  541. Status s = GDIPlus.GdipClosePathFigures (nativePath);
  542. GDIPlus.CheckStatus (s);
  543. }
  544. public void CloseFigure()
  545. {
  546. Status s = GDIPlus.GdipClosePathFigure (nativePath);
  547. GDIPlus.CheckStatus (s);
  548. }
  549. public void Flatten ()
  550. {
  551. Flatten (null, FlatnessDefault);
  552. }
  553. public void Flatten (Matrix matrix)
  554. {
  555. Flatten (matrix, FlatnessDefault);
  556. }
  557. public void Flatten (Matrix matrix, float flatness)
  558. {
  559. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  560. Status status = GDIPlus.GdipFlattenPath (nativePath, m, flatness);
  561. GDIPlus.CheckStatus (status);
  562. }
  563. public RectangleF GetBounds ()
  564. {
  565. return GetBounds (null, null);
  566. }
  567. public RectangleF GetBounds (Matrix matrix)
  568. {
  569. return GetBounds (matrix, null);
  570. }
  571. [MonoTODO ("GdipGetPathWorldBounds doesn't support pens in libgdiplus (missing GdipWidenPath)")]
  572. public RectangleF GetBounds (Matrix matrix, Pen pen)
  573. {
  574. RectangleF retval;
  575. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  576. IntPtr p = (pen == null) ? IntPtr.Zero : pen.nativeObject;
  577. Status s = GDIPlus.GdipGetPathWorldBounds (nativePath, out retval, m, p);
  578. GDIPlus.CheckStatus (s);
  579. return retval;
  580. }
  581. [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
  582. public bool IsOutlineVisible (Point point, Pen pen)
  583. {
  584. return IsOutlineVisible (point.X, point.Y, pen, null);
  585. }
  586. [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
  587. public bool IsOutlineVisible (PointF point, Pen pen)
  588. {
  589. return IsOutlineVisible (point.X, point.Y, pen, null);
  590. }
  591. [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
  592. public bool IsOutlineVisible (int x, int y, Pen pen)
  593. {
  594. return IsOutlineVisible (x, y, pen, null);
  595. }
  596. [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
  597. public bool IsOutlineVisible (float x, float y, Pen pen)
  598. {
  599. return IsOutlineVisible (x, y, pen, null);
  600. }
  601. [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
  602. public bool IsOutlineVisible (Point pt, Pen pen, Graphics graphics)
  603. {
  604. return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
  605. }
  606. [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
  607. public bool IsOutlineVisible (PointF pt, Pen pen, Graphics graphics)
  608. {
  609. return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
  610. }
  611. [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
  612. public bool IsOutlineVisible (int x, int y, Pen pen, Graphics graphics)
  613. {
  614. bool result;
  615. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  616. Status s = GDIPlus.GdipIsOutlineVisiblePathPointI (nativePath, x, y, g, out result);
  617. GDIPlus.CheckStatus (s);
  618. return result;
  619. }
  620. [MonoTODO ("GdipIsOutlineVisiblePathPoint[I] isn't implemented in libgdiplus")]
  621. public bool IsOutlineVisible (float x, float y, Pen pen, Graphics graphics)
  622. {
  623. bool result;
  624. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  625. Status s = GDIPlus.GdipIsOutlineVisiblePathPoint (nativePath, x, y, g, out result);
  626. GDIPlus.CheckStatus (s);
  627. return result;
  628. }
  629. [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
  630. public bool IsVisible (Point point)
  631. {
  632. return IsVisible (point.X, point.Y, null);
  633. }
  634. [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
  635. public bool IsVisible (PointF point)
  636. {
  637. return IsVisible (point.X, point.Y, null);
  638. }
  639. [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
  640. public bool IsVisible (int x, int y)
  641. {
  642. return IsVisible (x, y, null);
  643. }
  644. [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
  645. public bool IsVisible (float x, float y)
  646. {
  647. return IsVisible (x, y, null);
  648. }
  649. [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
  650. public bool IsVisible (Point pt, Graphics graphics)
  651. {
  652. return IsVisible (pt.X, pt.Y, graphics);
  653. }
  654. [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
  655. public bool IsVisible (PointF pt, Graphics graphics)
  656. {
  657. return IsVisible (pt.X, pt.Y, graphics);
  658. }
  659. [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
  660. public bool IsVisible (int x, int y, Graphics graphics)
  661. {
  662. bool retval;
  663. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  664. Status s = GDIPlus.GdipIsVisiblePathPointI (nativePath, x, y, g, out retval);
  665. GDIPlus.CheckStatus (s);
  666. return retval;
  667. }
  668. [MonoTODO ("GdipIsVisiblePathPoint[I] isn't implemented in libgdiplus")]
  669. public bool IsVisible (float x, float y, Graphics graphics)
  670. {
  671. bool retval;
  672. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  673. Status s = GDIPlus.GdipIsVisiblePathPoint (nativePath, x, y, g, out retval);
  674. GDIPlus.CheckStatus (s);
  675. return retval;
  676. }
  677. public void SetMarkers ()
  678. {
  679. Status s = GDIPlus.GdipSetPathMarker (nativePath);
  680. GDIPlus.CheckStatus (s);
  681. }
  682. public void StartFigure()
  683. {
  684. Status s = GDIPlus.GdipStartPathFigure (nativePath);
  685. GDIPlus.CheckStatus (s);
  686. }
  687. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  688. public void Warp (PointF[] destPoints, RectangleF srcRect)
  689. {
  690. Warp (destPoints, srcRect, null, WarpMode.Perspective, FlatnessDefault);
  691. }
  692. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  693. public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix)
  694. {
  695. Warp (destPoints, srcRect, matrix, WarpMode.Perspective, FlatnessDefault);
  696. }
  697. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  698. public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode)
  699. {
  700. Warp (destPoints, srcRect, matrix, warpMode, FlatnessDefault);
  701. }
  702. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  703. public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode, float flatness)
  704. {
  705. if (destPoints == null)
  706. throw new ArgumentNullException ("destPoints");
  707. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  708. Status s = GDIPlus.GdipWarpPath (nativePath, m, destPoints, destPoints.Length,
  709. srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, warpMode, flatness);
  710. GDIPlus.CheckStatus (s);
  711. }
  712. [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
  713. public void Widen (Pen pen)
  714. {
  715. Widen (pen, null, FlatnessDefault);
  716. }
  717. [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
  718. public void Widen (Pen pen, Matrix matrix)
  719. {
  720. Widen (pen, matrix, FlatnessDefault);
  721. }
  722. [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
  723. public void Widen (Pen pen, Matrix matrix, float flatness)
  724. {
  725. if (pen == null)
  726. throw new ArgumentNullException ("pen");
  727. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  728. Status s = GDIPlus.GdipWidenPath (nativePath, pen.nativeObject, m, flatness);
  729. GDIPlus.CheckStatus (s);
  730. }
  731. }
  732. }