GraphicsPath.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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. 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. public void AddBeziers (Point [] pts)
  236. {
  237. if (pts == null)
  238. throw new ArgumentNullException ("pts");
  239. Status status = GDIPlus.GdipAddPathBeziersI (nativePath, pts, pts.Length);
  240. GDIPlus.CheckStatus (status);
  241. }
  242. public void AddBeziers (PointF [] pts)
  243. {
  244. if (pts == null)
  245. throw new ArgumentNullException ("pts");
  246. Status status = GDIPlus.GdipAddPathBeziers (nativePath, pts, pts.Length);
  247. GDIPlus.CheckStatus (status);
  248. }
  249. //
  250. // AddEllipse
  251. //
  252. public void AddEllipse (RectangleF r)
  253. {
  254. Status status = GDIPlus.GdipAddPathEllipse (nativePath, r.X, r.Y, r.Width, r.Height);
  255. GDIPlus.CheckStatus (status);
  256. }
  257. public void AddEllipse (float x, float y, float width, float height)
  258. {
  259. Status status = GDIPlus.GdipAddPathEllipse (nativePath, x, y, width, height);
  260. GDIPlus.CheckStatus (status);
  261. }
  262. public void AddEllipse (Rectangle r)
  263. {
  264. Status status = GDIPlus.GdipAddPathEllipseI (nativePath, r.X, r.Y, r.Width, r.Height);
  265. GDIPlus.CheckStatus (status);
  266. }
  267. public void AddEllipse (int x, int y, int width, int height)
  268. {
  269. Status status = GDIPlus.GdipAddPathEllipseI (nativePath, x, y, width, height);
  270. GDIPlus.CheckStatus (status);
  271. }
  272. //
  273. // AddLine
  274. //
  275. public void AddLine (Point a, Point b)
  276. {
  277. Status status = GDIPlus.GdipAddPathLineI (nativePath, a.X, a.Y, b.X, b.Y);
  278. GDIPlus.CheckStatus (status);
  279. }
  280. public void AddLine (PointF a, PointF b)
  281. {
  282. Status status = GDIPlus.GdipAddPathLine (nativePath, a.X, a.Y, b.X,
  283. b.Y);
  284. GDIPlus.CheckStatus (status);
  285. }
  286. public void AddLine (int x1, int y1, int x2, int y2)
  287. {
  288. Status status = GDIPlus.GdipAddPathLineI (nativePath, x1, y1, x2, y2);
  289. GDIPlus.CheckStatus (status);
  290. }
  291. public void AddLine (float x1, float y1, float x2, float y2)
  292. {
  293. Status status = GDIPlus.GdipAddPathLine (nativePath, x1, y1, x2,
  294. y2);
  295. GDIPlus.CheckStatus (status);
  296. }
  297. //
  298. // AddLines
  299. //
  300. public void AddLines (Point[] points)
  301. {
  302. if (points == null)
  303. throw new ArgumentNullException ("points");
  304. if (points.Length == 0)
  305. throw new ArgumentException ("points");
  306. Status status = GDIPlus.GdipAddPathLine2I (nativePath, points, points.Length);
  307. GDIPlus.CheckStatus (status);
  308. }
  309. public void AddLines (PointF[] points)
  310. {
  311. if (points == null)
  312. throw new ArgumentNullException ("points");
  313. if (points.Length == 0)
  314. throw new ArgumentException ("points");
  315. Status status = GDIPlus.GdipAddPathLine2 (nativePath, points, points.Length);
  316. GDIPlus.CheckStatus (status);
  317. }
  318. //
  319. // AddPie
  320. //
  321. public void AddPie (Rectangle rect, float startAngle, float sweepAngle)
  322. {
  323. Status status = GDIPlus.GdipAddPathPie (
  324. nativePath, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
  325. GDIPlus.CheckStatus (status);
  326. }
  327. public void AddPie (int x, int y, int width, int height, float startAngle, float sweepAngle)
  328. {
  329. Status status = GDIPlus.GdipAddPathPieI (nativePath, x, y, width, height, startAngle, sweepAngle);
  330. GDIPlus.CheckStatus (status);
  331. }
  332. public void AddPie (float x, float y, float width, float height, float startAngle, float sweepAngle)
  333. {
  334. Status status = GDIPlus.GdipAddPathPie (nativePath, x, y, width, height, startAngle, sweepAngle);
  335. GDIPlus.CheckStatus (status);
  336. }
  337. //
  338. // AddPolygon
  339. //
  340. public void AddPolygon (Point [] points)
  341. {
  342. if (points == null)
  343. throw new ArgumentNullException ("points");
  344. Status status = GDIPlus.GdipAddPathPolygonI (nativePath, points, points.Length);
  345. GDIPlus.CheckStatus (status);
  346. }
  347. public void AddPolygon (PointF [] points)
  348. {
  349. if (points == null)
  350. throw new ArgumentNullException ("points");
  351. Status status = GDIPlus.GdipAddPathPolygon (nativePath, points, points.Length);
  352. GDIPlus.CheckStatus (status);
  353. }
  354. //
  355. // AddRectangle
  356. //
  357. public void AddRectangle (Rectangle rect)
  358. {
  359. Status status = GDIPlus.GdipAddPathRectangleI (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
  360. GDIPlus.CheckStatus (status);
  361. }
  362. public void AddRectangle (RectangleF rect)
  363. {
  364. Status status = GDIPlus.GdipAddPathRectangle (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
  365. GDIPlus.CheckStatus (status);
  366. }
  367. //
  368. // AddRectangles
  369. //
  370. public void AddRectangles (Rectangle [] rects)
  371. {
  372. if (rects == null)
  373. throw new ArgumentNullException ("rects");
  374. if (rects.Length == 0)
  375. throw new ArgumentException ("rects");
  376. Status status = GDIPlus.GdipAddPathRectanglesI (nativePath, rects, rects.Length);
  377. GDIPlus.CheckStatus (status);
  378. }
  379. public void AddRectangles (RectangleF [] rects)
  380. {
  381. if (rects == null)
  382. throw new ArgumentNullException ("rects");
  383. if (rects.Length == 0)
  384. throw new ArgumentException ("rects");
  385. Status status = GDIPlus.GdipAddPathRectangles (nativePath, rects, rects.Length);
  386. GDIPlus.CheckStatus (status);
  387. }
  388. //
  389. // AddPath
  390. //
  391. public void AddPath (GraphicsPath addingPath, bool connect)
  392. {
  393. if (addingPath == null)
  394. throw new ArgumentNullException ("addingPath");
  395. Status status = GDIPlus.GdipAddPathPath (nativePath, addingPath.nativePath, connect);
  396. GDIPlus.CheckStatus (status);
  397. }
  398. public PointF GetLastPoint ()
  399. {
  400. PointF pt;
  401. Status status = GDIPlus.GdipGetPathLastPoint (nativePath, out pt);
  402. GDIPlus.CheckStatus (status);
  403. return pt;
  404. }
  405. //
  406. // AddClosedCurve
  407. //
  408. public void AddClosedCurve (Point [] points)
  409. {
  410. if (points == null)
  411. throw new ArgumentNullException ("points");
  412. Status status = GDIPlus.GdipAddPathClosedCurveI (nativePath, points, points.Length);
  413. GDIPlus.CheckStatus (status);
  414. }
  415. public void AddClosedCurve (PointF [] points)
  416. {
  417. if (points == null)
  418. throw new ArgumentNullException ("points");
  419. Status status = GDIPlus.GdipAddPathClosedCurve (nativePath, points, points.Length);
  420. GDIPlus.CheckStatus (status);
  421. }
  422. public void AddClosedCurve (Point [] points, float tension)
  423. {
  424. if (points == null)
  425. throw new ArgumentNullException ("points");
  426. Status status = GDIPlus.GdipAddPathClosedCurve2I (nativePath, points, points.Length, tension);
  427. GDIPlus.CheckStatus (status);
  428. }
  429. public void AddClosedCurve (PointF [] points, float tension)
  430. {
  431. if (points == null)
  432. throw new ArgumentNullException ("points");
  433. Status status = GDIPlus.GdipAddPathClosedCurve2 (nativePath, points, points.Length, tension);
  434. GDIPlus.CheckStatus (status);
  435. }
  436. //
  437. // AddCurve
  438. //
  439. public void AddCurve (Point [] points)
  440. {
  441. if (points == null)
  442. throw new ArgumentNullException ("points");
  443. Status status = GDIPlus.GdipAddPathCurveI (nativePath, points, points.Length);
  444. GDIPlus.CheckStatus (status);
  445. }
  446. public void AddCurve (PointF [] points)
  447. {
  448. if (points == null)
  449. throw new ArgumentNullException ("points");
  450. Status status = GDIPlus.GdipAddPathCurve (nativePath, points, points.Length);
  451. GDIPlus.CheckStatus (status);
  452. }
  453. public void AddCurve (Point [] points, float tension)
  454. {
  455. if (points == null)
  456. throw new ArgumentNullException ("points");
  457. Status status = GDIPlus.GdipAddPathCurve2I (nativePath, points, points.Length, tension);
  458. GDIPlus.CheckStatus (status);
  459. }
  460. public void AddCurve (PointF [] points, float tension)
  461. {
  462. if (points == null)
  463. throw new ArgumentNullException ("points");
  464. Status status = GDIPlus.GdipAddPathCurve2 (nativePath, points, points.Length, tension);
  465. GDIPlus.CheckStatus (status);
  466. }
  467. public void AddCurve (Point [] points, int offset, int numberOfSegments, float tension)
  468. {
  469. if (points == null)
  470. throw new ArgumentNullException ("points");
  471. Status status = GDIPlus.GdipAddPathCurve3I (nativePath, points, points.Length,
  472. offset, numberOfSegments, tension);
  473. GDIPlus.CheckStatus (status);
  474. }
  475. public void AddCurve (PointF [] points, int offset, int numberOfSegments, float tension)
  476. {
  477. if (points == null)
  478. throw new ArgumentNullException ("points");
  479. Status status = GDIPlus.GdipAddPathCurve3 (nativePath, points, points.Length,
  480. offset, numberOfSegments, tension);
  481. GDIPlus.CheckStatus (status);
  482. }
  483. public void Reset ()
  484. {
  485. Status status = GDIPlus.GdipResetPath (nativePath);
  486. GDIPlus.CheckStatus (status);
  487. }
  488. public void Reverse ()
  489. {
  490. Status status = GDIPlus.GdipReversePath (nativePath);
  491. GDIPlus.CheckStatus (status);
  492. }
  493. public void Transform (Matrix matrix)
  494. {
  495. if (matrix == null)
  496. throw new ArgumentNullException ("matrix");
  497. Status status = GDIPlus.GdipTransformPath (nativePath, matrix.nativeMatrix);
  498. GDIPlus.CheckStatus (status);
  499. }
  500. [MonoTODO ("StringFormat isn't supported inside libgdiplus")]
  501. public void AddString (string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
  502. {
  503. Rectangle layout = new Rectangle ();
  504. layout.X = origin.X;
  505. layout.Y = origin.Y;
  506. AddString (s, family, style, emSize, layout, format);
  507. }
  508. [MonoTODO ("StringFormat isn't supported inside libgdiplus")]
  509. public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
  510. {
  511. RectangleF layout = new RectangleF ();
  512. layout.X = origin.X;
  513. layout.Y = origin.Y;
  514. AddString (s, family, style, emSize, layout, format);
  515. }
  516. [MonoTODO ("layoutRect and StringFormat aren't supported inside libgdiplus")]
  517. public void AddString (string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
  518. {
  519. if (family == null)
  520. throw new ArgumentException ("family");
  521. IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
  522. // note: the NullReferenceException on s.Length is the expected (MS) exception
  523. Status status = GDIPlus.GdipAddPathStringI (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
  524. GDIPlus.CheckStatus (status);
  525. }
  526. [MonoTODO ("layoutRect and StringFormat aren't supported inside libgdiplus")]
  527. public void AddString (string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
  528. {
  529. if (family == null)
  530. throw new ArgumentException ("family");
  531. IntPtr sformat = (format == null) ? IntPtr.Zero : format.NativeObject;
  532. // note: the NullReferenceException on s.Length is the expected (MS) exception
  533. Status status = GDIPlus.GdipAddPathString (nativePath, s, s.Length, family.NativeObject, style, emSize, ref layoutRect, sformat);
  534. GDIPlus.CheckStatus (status);
  535. }
  536. public void ClearMarkers()
  537. {
  538. Status s = GDIPlus.GdipClearPathMarkers (nativePath);
  539. GDIPlus.CheckStatus (s);
  540. }
  541. public void CloseAllFigures()
  542. {
  543. Status s = GDIPlus.GdipClosePathFigures (nativePath);
  544. GDIPlus.CheckStatus (s);
  545. }
  546. public void CloseFigure()
  547. {
  548. Status s = GDIPlus.GdipClosePathFigure (nativePath);
  549. GDIPlus.CheckStatus (s);
  550. }
  551. public void Flatten ()
  552. {
  553. Flatten (null, FlatnessDefault);
  554. }
  555. public void Flatten (Matrix matrix)
  556. {
  557. Flatten (matrix, FlatnessDefault);
  558. }
  559. public void Flatten (Matrix matrix, float flatness)
  560. {
  561. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  562. Status status = GDIPlus.GdipFlattenPath (nativePath, m, flatness);
  563. GDIPlus.CheckStatus (status);
  564. }
  565. public RectangleF GetBounds ()
  566. {
  567. return GetBounds (null, null);
  568. }
  569. public RectangleF GetBounds (Matrix matrix)
  570. {
  571. return GetBounds (matrix, null);
  572. }
  573. public RectangleF GetBounds (Matrix matrix, Pen pen)
  574. {
  575. RectangleF retval;
  576. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  577. IntPtr p = (pen == null) ? IntPtr.Zero : pen.nativeObject;
  578. Status s = GDIPlus.GdipGetPathWorldBounds (nativePath, out retval, m, p);
  579. GDIPlus.CheckStatus (s);
  580. return retval;
  581. }
  582. public bool IsOutlineVisible (Point point, Pen pen)
  583. {
  584. return IsOutlineVisible (point.X, point.Y, pen, null);
  585. }
  586. public bool IsOutlineVisible (PointF point, Pen pen)
  587. {
  588. return IsOutlineVisible (point.X, point.Y, pen, null);
  589. }
  590. public bool IsOutlineVisible (int x, int y, Pen pen)
  591. {
  592. return IsOutlineVisible (x, y, pen, null);
  593. }
  594. public bool IsOutlineVisible (float x, float y, Pen pen)
  595. {
  596. return IsOutlineVisible (x, y, pen, null);
  597. }
  598. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  599. public bool IsOutlineVisible (Point pt, Pen pen, Graphics graphics)
  600. {
  601. return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
  602. }
  603. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  604. public bool IsOutlineVisible (PointF pt, Pen pen, Graphics graphics)
  605. {
  606. return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
  607. }
  608. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  609. public bool IsOutlineVisible (int x, int y, Pen pen, Graphics graphics)
  610. {
  611. if (pen == null)
  612. throw new ArgumentNullException ("pen");
  613. bool result;
  614. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  615. Status s = GDIPlus.GdipIsOutlineVisiblePathPointI (nativePath, x, y, pen.nativeObject, g, out result);
  616. GDIPlus.CheckStatus (s);
  617. return result;
  618. }
  619. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  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. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  647. public bool IsVisible (Point pt, Graphics graphics)
  648. {
  649. return IsVisible (pt.X, pt.Y, graphics);
  650. }
  651. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  652. public bool IsVisible (PointF pt, Graphics graphics)
  653. {
  654. return IsVisible (pt.X, pt.Y, graphics);
  655. }
  656. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  657. public bool IsVisible (int x, int y, Graphics graphics)
  658. {
  659. bool retval;
  660. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  661. Status s = GDIPlus.GdipIsVisiblePathPointI (nativePath, x, y, g, out retval);
  662. GDIPlus.CheckStatus (s);
  663. return retval;
  664. }
  665. [MonoTODO ("Graphics parameter is currently ignored in libgdiplus")]
  666. public bool IsVisible (float x, float y, Graphics graphics)
  667. {
  668. bool retval;
  669. IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
  670. Status s = GDIPlus.GdipIsVisiblePathPoint (nativePath, x, y, g, out retval);
  671. GDIPlus.CheckStatus (s);
  672. return retval;
  673. }
  674. public void SetMarkers ()
  675. {
  676. Status s = GDIPlus.GdipSetPathMarker (nativePath);
  677. GDIPlus.CheckStatus (s);
  678. }
  679. public void StartFigure()
  680. {
  681. Status s = GDIPlus.GdipStartPathFigure (nativePath);
  682. GDIPlus.CheckStatus (s);
  683. }
  684. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  685. public void Warp (PointF[] destPoints, RectangleF srcRect)
  686. {
  687. Warp (destPoints, srcRect, null, WarpMode.Perspective, FlatnessDefault);
  688. }
  689. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  690. public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix)
  691. {
  692. Warp (destPoints, srcRect, matrix, WarpMode.Perspective, FlatnessDefault);
  693. }
  694. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  695. public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode)
  696. {
  697. Warp (destPoints, srcRect, matrix, warpMode, FlatnessDefault);
  698. }
  699. [MonoTODO ("GdipWarpPath isn't implemented in libgdiplus")]
  700. public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode, float flatness)
  701. {
  702. if (destPoints == null)
  703. throw new ArgumentNullException ("destPoints");
  704. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  705. Status s = GDIPlus.GdipWarpPath (nativePath, m, destPoints, destPoints.Length,
  706. srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, warpMode, flatness);
  707. GDIPlus.CheckStatus (s);
  708. }
  709. [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
  710. public void Widen (Pen pen)
  711. {
  712. Widen (pen, null, FlatnessDefault);
  713. }
  714. [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
  715. public void Widen (Pen pen, Matrix matrix)
  716. {
  717. Widen (pen, matrix, FlatnessDefault);
  718. }
  719. [MonoTODO ("GdipWidenPath isn't implemented in libgdiplus")]
  720. public void Widen (Pen pen, Matrix matrix, float flatness)
  721. {
  722. if (pen == null)
  723. throw new ArgumentNullException ("pen");
  724. #if NET_2_0
  725. if (PointCount == 0)
  726. return;
  727. #endif
  728. IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
  729. Status s = GDIPlus.GdipWidenPath (nativePath, pen.nativeObject, m, flatness);
  730. GDIPlus.CheckStatus (s);
  731. }
  732. }
  733. }