/binding/win32/gdiplusgraphics.d

http://github.com/wilkie/djehuty · D · 2335 lines · 1996 code · 291 blank · 48 comment · 22 complexity · a3dcf82dac6e4451f872aa9db2317a02 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * gdiplusgraphics.d
  3. *
  4. * This module implements GdiPlusGraphics.h for D. The original
  5. * copyright info is given below.
  6. *
  7. * Author: Dave Wilkinson
  8. * Originated: November 25th, 2009
  9. *
  10. */
  11. module binding.win32.gdiplusgraphics;
  12. import binding.win32.windef;
  13. import binding.win32.winbase;
  14. import binding.win32.winnt;
  15. import binding.win32.wingdi;
  16. import binding.win32.guiddef;
  17. import binding.win32.gdiplusbase;
  18. import binding.win32.gdiplustypes;
  19. import binding.win32.gdiplusenums;
  20. import binding.win32.gdipluspixelformats;
  21. import binding.win32.gdiplusgpstubs;
  22. import binding.win32.gdiplusmetaheader;
  23. import binding.win32.gdipluspixelformats;
  24. import binding.win32.gdipluscolor;
  25. import binding.win32.gdipluscolormatrix;
  26. import binding.win32.gdiplusflat;
  27. import binding.win32.gdiplusimaging;
  28. import binding.win32.gdiplusbitmap;
  29. import binding.win32.gdiplusimageattributes;
  30. import binding.win32.gdiplusmatrix;
  31. import binding.win32.gdiplusregion;
  32. import binding.win32.gdiplusbrush;
  33. import binding.win32.gdipluspen;
  34. import binding.win32.gdiplusfont;
  35. import binding.win32.gdipluspath;
  36. import binding.win32.gdiplusstringformat;
  37. import binding.win32.gdipluscachedbitmap;
  38. import binding.win32.gdipluseffects;
  39. import binding.win32.gdiplusmetafile;
  40. /**************************************************************************\
  41. *
  42. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  43. *
  44. * Module Name:
  45. *
  46. * GdiplusGraphics.h
  47. *
  48. * Abstract:
  49. *
  50. * GDI+ Graphics Object
  51. *
  52. \**************************************************************************/
  53. extern(System):
  54. class Graphics : GdiplusBase {
  55. static Graphics FromHDC(in HDC hdc) {
  56. return new Graphics(hdc);
  57. }
  58. static Graphics FromHDC(in HDC hdc, in HANDLE hdevice) {
  59. return new Graphics(hdc, hdevice);
  60. }
  61. static Graphics FromHWND(in HWND hwnd, in BOOL icm = FALSE) {
  62. return new Graphics(hwnd, icm);
  63. }
  64. static Graphics FromImage(in Image image) {
  65. return new Graphics(image);
  66. }
  67. this(in HDC hdc) {
  68. GpGraphics *graphics = null;
  69. lastResult = GdipCreateFromHDC(hdc, &graphics);
  70. SetNativeGraphics(graphics);
  71. }
  72. this(in HDC hdc, in HANDLE hdevice) {
  73. GpGraphics *graphics = null;
  74. lastResult = GdipCreateFromHDC2(hdc, hdevice, &graphics);
  75. SetNativeGraphics(graphics);
  76. }
  77. this(in HWND hwnd, in BOOL icm) {
  78. GpGraphics *graphics = null;
  79. if (icm) {
  80. lastResult = GdipCreateFromHWNDICM(hwnd, &graphics);
  81. }
  82. else {
  83. lastResult = GdipCreateFromHWND(hwnd, &graphics);
  84. }
  85. SetNativeGraphics(graphics);
  86. }
  87. this(in Image image) {
  88. GpGraphics *graphics = null;
  89. if (image !is null) {
  90. lastResult = GdipGetImageGraphicsContext(
  91. image.nativeImage, &graphics);
  92. }
  93. SetNativeGraphics(graphics);
  94. }
  95. ~this() {
  96. GdipDeleteGraphics(nativeGraphics);
  97. }
  98. VOID Flush(in FlushIntention intention = FlushIntention.FlushIntentionFlush) {
  99. GdipFlush(nativeGraphics, intention);
  100. }
  101. //------------------------------------------------------------------------
  102. // GDI Interop methods
  103. //------------------------------------------------------------------------
  104. // Locks the graphics until ReleaseDC is called
  105. HDC GetHDC() {
  106. HDC hdc = null;
  107. SetStatus(GdipGetDC(nativeGraphics, &hdc));
  108. return hdc;
  109. }
  110. VOID ReleaseHDC(in HDC hdc) {
  111. SetStatus(GdipReleaseDC(nativeGraphics, hdc));
  112. }
  113. //------------------------------------------------------------------------
  114. // Rendering modes
  115. //------------------------------------------------------------------------
  116. Status SetRenderingOrigin(in INT x, in INT y) {
  117. return SetStatus(
  118. GdipSetRenderingOrigin(
  119. nativeGraphics, x, y
  120. )
  121. );
  122. }
  123. Status GetRenderingOrigin(ref INT x, ref INT y) {
  124. return SetStatus(
  125. GdipGetRenderingOrigin(
  126. nativeGraphics, &x, &y
  127. )
  128. );
  129. }
  130. Status SetCompositingMode(in CompositingMode compositingMode) {
  131. return SetStatus(GdipSetCompositingMode(nativeGraphics, compositingMode));
  132. }
  133. CompositingMode GetCompositingMode() {
  134. CompositingMode mode;
  135. SetStatus(GdipGetCompositingMode(nativeGraphics,
  136. &mode));
  137. return mode;
  138. }
  139. Status SetCompositingQuality(in CompositingQuality compositingQuality) {
  140. return SetStatus(GdipSetCompositingQuality(
  141. nativeGraphics,
  142. compositingQuality));
  143. }
  144. CompositingQuality GetCompositingQuality() {
  145. CompositingQuality quality;
  146. SetStatus(GdipGetCompositingQuality(
  147. nativeGraphics,
  148. &quality));
  149. return quality;
  150. }
  151. Status SetTextRenderingHint(in TextRenderingHint newMode) {
  152. return SetStatus(GdipSetTextRenderingHint(nativeGraphics,
  153. newMode));
  154. }
  155. TextRenderingHint GetTextRenderingHint() {
  156. TextRenderingHint hint;
  157. SetStatus(GdipGetTextRenderingHint(nativeGraphics,
  158. &hint));
  159. return hint;
  160. }
  161. Status SetTextContrast(in UINT contrast) {
  162. return SetStatus(GdipSetTextContrast(nativeGraphics, contrast));
  163. }
  164. UINT GetTextContrast() {
  165. UINT contrast;
  166. SetStatus(GdipGetTextContrast(nativeGraphics, &contrast));
  167. return contrast;
  168. }
  169. InterpolationMode GetInterpolationMode() {
  170. InterpolationMode mode = InterpolationMode.InterpolationModeInvalid;
  171. SetStatus(GdipGetInterpolationMode(nativeGraphics, &mode));
  172. return mode;
  173. }
  174. Status SetInterpolationMode(in InterpolationMode interpolationMode) {
  175. return SetStatus(GdipSetInterpolationMode(nativeGraphics, interpolationMode));
  176. }
  177. version(GDIPLUS6) {
  178. Status SetAbort(GdiplusAbort *pIAbort) {
  179. return SetStatus(GdipGraphicsSetAbort(
  180. nativeGraphics,
  181. pIAbort
  182. ));
  183. }
  184. }
  185. SmoothingMode GetSmoothingMode() {
  186. SmoothingMode smoothingMode = SmoothingMode.SmoothingModeInvalid;
  187. SetStatus(GdipGetSmoothingMode(nativeGraphics,
  188. &smoothingMode));
  189. return smoothingMode;
  190. }
  191. Status SetSmoothingMode(in SmoothingMode smoothingMode) {
  192. return SetStatus(GdipSetSmoothingMode(nativeGraphics,
  193. smoothingMode));
  194. }
  195. PixelOffsetMode GetPixelOffsetMode() {
  196. PixelOffsetMode pixelOffsetMode = PixelOffsetMode.PixelOffsetModeInvalid;
  197. SetStatus(GdipGetPixelOffsetMode(nativeGraphics,
  198. &pixelOffsetMode));
  199. return pixelOffsetMode;
  200. }
  201. Status SetPixelOffsetMode(in PixelOffsetMode pixelOffsetMode) {
  202. return SetStatus(GdipSetPixelOffsetMode(nativeGraphics,
  203. pixelOffsetMode));
  204. }
  205. //------------------------------------------------------------------------
  206. // Manipulate current world transform
  207. //------------------------------------------------------------------------
  208. Status SetTransform(in Matrix matrix) {
  209. return SetStatus(GdipSetWorldTransform(nativeGraphics,
  210. matrix.nativeMatrix));
  211. }
  212. Status ResetTransform() {
  213. return SetStatus(GdipResetWorldTransform(nativeGraphics));
  214. }
  215. Status MultiplyTransform(in Matrix matrix, in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
  216. return SetStatus(GdipMultiplyWorldTransform(nativeGraphics,
  217. matrix.nativeMatrix,
  218. order));
  219. }
  220. Status TranslateTransform(in REAL dx, in REAL dy, in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
  221. return SetStatus(GdipTranslateWorldTransform(nativeGraphics, dx, dy, order));
  222. }
  223. Status ScaleTransform(in REAL sx, in REAL sy, in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
  224. return SetStatus(GdipScaleWorldTransform(nativeGraphics, sx, sy, order));
  225. }
  226. Status RotateTransform(in REAL angle, in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
  227. return SetStatus(GdipRotateWorldTransform(nativeGraphics, angle, order));
  228. }
  229. Status GetTransform(Matrix* matrix) {
  230. return SetStatus(GdipGetWorldTransform(nativeGraphics, matrix.nativeMatrix));
  231. }
  232. Status SetPageUnit(in Unit unit) {
  233. return SetStatus(GdipSetPageUnit(nativeGraphics, unit));
  234. }
  235. Status SetPageScale(in REAL scale) {
  236. return SetStatus(GdipSetPageScale(nativeGraphics, scale));
  237. }
  238. Unit GetPageUnit() {
  239. Unit unit;
  240. SetStatus(GdipGetPageUnit(nativeGraphics, &unit));
  241. return unit;
  242. }
  243. REAL GetPageScale() {
  244. REAL scale;
  245. SetStatus(GdipGetPageScale(nativeGraphics, &scale));
  246. return scale;
  247. }
  248. REAL GetDpiX() {
  249. REAL dpi;
  250. SetStatus(GdipGetDpiX(nativeGraphics, &dpi));
  251. return dpi;
  252. }
  253. REAL GetDpiY() {
  254. REAL dpi;
  255. SetStatus(GdipGetDpiY(nativeGraphics, &dpi));
  256. return dpi;
  257. }
  258. Status TransformPoints(in CoordinateSpace destSpace, in CoordinateSpace srcSpace, PointF* pts, in INT count) {
  259. return SetStatus(GdipTransformPoints(nativeGraphics, destSpace, srcSpace, pts, count));
  260. }
  261. Status TransformPoints(in CoordinateSpace destSpace, in CoordinateSpace srcSpace, in Point* pts, in INT count) {
  262. return SetStatus(GdipTransformPointsI(nativeGraphics, destSpace, srcSpace, pts, count));
  263. }
  264. //------------------------------------------------------------------------
  265. // GetNearestColor (for <= 8bpp surfaces). Note: Alpha is ignored.
  266. //------------------------------------------------------------------------
  267. Status GetNearestColor(in Color color) {
  268. if (color is null) {
  269. return SetStatus(Status.InvalidParameter);
  270. }
  271. ARGB argb = color.GetValue();
  272. Status status = SetStatus(GdipGetNearestColor(nativeGraphics, &argb));
  273. color.SetValue(argb);
  274. return status;
  275. }
  276. Status DrawLine(in Pen pen, in REAL x1, in REAL y1, in REAL x2, in REAL y2) {
  277. return SetStatus(GdipDrawLine(nativeGraphics,
  278. pen.nativePen, x1, y1, x2,
  279. y2));
  280. }
  281. Status DrawLine(in Pen pen, in PointF pt1, in PointF pt2) {
  282. return DrawLine(pen, pt1.X, pt1.Y, pt2.X, pt2.Y);
  283. }
  284. Status DrawLines(in Pen pen,
  285. in PointF* points,
  286. in INT count)
  287. {
  288. return SetStatus(GdipDrawLines(nativeGraphics,
  289. pen.nativePen,
  290. points, count));
  291. }
  292. Status DrawLine(in Pen pen,
  293. in INT x1,
  294. in INT y1,
  295. in INT x2,
  296. in INT y2)
  297. {
  298. return SetStatus(GdipDrawLineI(nativeGraphics,
  299. pen.nativePen,
  300. x1,
  301. y1,
  302. x2,
  303. y2));
  304. }
  305. Status DrawLine(in Pen pen,
  306. in Point pt1,
  307. in Point pt2)
  308. {
  309. return DrawLine(pen,
  310. pt1.X,
  311. pt1.Y,
  312. pt2.X,
  313. pt2.Y);
  314. }
  315. Status DrawLines(in Pen pen,
  316. in Point* points,
  317. in INT count)
  318. {
  319. return SetStatus(GdipDrawLinesI(nativeGraphics,
  320. pen.nativePen,
  321. points,
  322. count));
  323. }
  324. Status DrawArc(in Pen pen,
  325. in REAL x,
  326. in REAL y,
  327. in REAL width,
  328. in REAL height,
  329. in REAL startAngle,
  330. in REAL sweepAngle)
  331. {
  332. return SetStatus(GdipDrawArc(nativeGraphics,
  333. pen.nativePen,
  334. x,
  335. y,
  336. width,
  337. height,
  338. startAngle,
  339. sweepAngle));
  340. }
  341. Status DrawArc(in Pen pen,
  342. in RectF rect,
  343. in REAL startAngle,
  344. in REAL sweepAngle)
  345. {
  346. return DrawArc(pen, rect.X, rect.Y, rect.Width, rect.Height,
  347. startAngle, sweepAngle);
  348. }
  349. Status DrawArc(in Pen pen,
  350. in INT x,
  351. in INT y,
  352. in INT width,
  353. in INT height,
  354. in REAL startAngle,
  355. in REAL sweepAngle)
  356. {
  357. return SetStatus(GdipDrawArcI(nativeGraphics,
  358. pen.nativePen,
  359. x,
  360. y,
  361. width,
  362. height,
  363. startAngle,
  364. sweepAngle));
  365. }
  366. Status DrawArc(in Pen pen,
  367. in Rect rect,
  368. in REAL startAngle,
  369. in REAL sweepAngle)
  370. {
  371. return DrawArc(pen,
  372. rect.X,
  373. rect.Y,
  374. rect.Width,
  375. rect.Height,
  376. startAngle,
  377. sweepAngle);
  378. }
  379. Status DrawBezier(in Pen pen,
  380. in REAL x1,
  381. in REAL y1,
  382. in REAL x2,
  383. in REAL y2,
  384. in REAL x3,
  385. in REAL y3,
  386. in REAL x4,
  387. in REAL y4)
  388. {
  389. return SetStatus(GdipDrawBezier(nativeGraphics,
  390. pen.nativePen, x1, y1,
  391. x2, y2, x3, y3, x4, y4));
  392. }
  393. Status DrawBezier(in Pen pen,
  394. in PointF pt1,
  395. in PointF pt2,
  396. in PointF pt3,
  397. in PointF pt4)
  398. {
  399. return DrawBezier(pen,
  400. pt1.X,
  401. pt1.Y,
  402. pt2.X,
  403. pt2.Y,
  404. pt3.X,
  405. pt3.Y,
  406. pt4.X,
  407. pt4.Y);
  408. }
  409. Status DrawBeziers(in Pen pen,
  410. in PointF* points,
  411. in INT count)
  412. {
  413. return SetStatus(GdipDrawBeziers(nativeGraphics,
  414. pen.nativePen,
  415. points,
  416. count));
  417. }
  418. Status DrawBezier(in Pen pen,
  419. in INT x1,
  420. in INT y1,
  421. in INT x2,
  422. in INT y2,
  423. in INT x3,
  424. in INT y3,
  425. in INT x4,
  426. in INT y4)
  427. {
  428. return SetStatus(GdipDrawBezierI(nativeGraphics,
  429. pen.nativePen,
  430. x1,
  431. y1,
  432. x2,
  433. y2,
  434. x3,
  435. y3,
  436. x4,
  437. y4));
  438. }
  439. Status DrawBezier(in Pen pen,
  440. in Point pt1,
  441. in Point pt2,
  442. in Point pt3,
  443. in Point pt4)
  444. {
  445. return DrawBezier(pen,
  446. pt1.X,
  447. pt1.Y,
  448. pt2.X,
  449. pt2.Y,
  450. pt3.X,
  451. pt3.Y,
  452. pt4.X,
  453. pt4.Y);
  454. }
  455. Status DrawBeziers(in Pen pen,
  456. in Point* points,
  457. in INT count)
  458. {
  459. return SetStatus(GdipDrawBeziersI(nativeGraphics,
  460. pen.nativePen,
  461. points,
  462. count));
  463. }
  464. Status DrawRectangle(in Pen pen,
  465. in RectF rect)
  466. {
  467. return DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
  468. }
  469. Status DrawRectangle(in Pen pen,
  470. in REAL x,
  471. in REAL y,
  472. in REAL width,
  473. in REAL height)
  474. {
  475. return SetStatus(GdipDrawRectangle(nativeGraphics,
  476. pen.nativePen, x, y,
  477. width, height));
  478. }
  479. Status DrawRectangles(in Pen pen,
  480. in RectF* rects,
  481. in INT count)
  482. {
  483. return SetStatus(GdipDrawRectangles(nativeGraphics,
  484. pen.nativePen,
  485. rects, count));
  486. }
  487. Status DrawRectangle(in Pen pen,
  488. in Rect rect)
  489. {
  490. return DrawRectangle(pen,
  491. rect.X,
  492. rect.Y,
  493. rect.Width,
  494. rect.Height);
  495. }
  496. Status DrawRectangle(in Pen pen,
  497. in INT x,
  498. in INT y,
  499. in INT width,
  500. in INT height)
  501. {
  502. return SetStatus(GdipDrawRectangleI(nativeGraphics,
  503. pen.nativePen,
  504. x,
  505. y,
  506. width,
  507. height));
  508. }
  509. Status DrawRectangles(in Pen pen,
  510. in Rect* rects,
  511. in INT count)
  512. {
  513. return SetStatus(GdipDrawRectanglesI(nativeGraphics,
  514. pen.nativePen,
  515. rects,
  516. count));
  517. }
  518. Status DrawEllipse(in Pen pen,
  519. in RectF rect)
  520. {
  521. return DrawEllipse(pen, rect.X, rect.Y, rect.Width, rect.Height);
  522. }
  523. Status DrawEllipse(in Pen pen,
  524. in REAL x,
  525. in REAL y,
  526. in REAL width,
  527. in REAL height)
  528. {
  529. return SetStatus(GdipDrawEllipse(nativeGraphics,
  530. pen.nativePen,
  531. x,
  532. y,
  533. width,
  534. height));
  535. }
  536. Status DrawEllipse(in Pen pen,
  537. in Rect rect)
  538. {
  539. return DrawEllipse(pen,
  540. rect.X,
  541. rect.Y,
  542. rect.Width,
  543. rect.Height);
  544. }
  545. Status DrawEllipse(in Pen pen,
  546. in INT x,
  547. in INT y,
  548. in INT width,
  549. in INT height)
  550. {
  551. return SetStatus(GdipDrawEllipseI(nativeGraphics,
  552. pen.nativePen,
  553. x,
  554. y,
  555. width,
  556. height));
  557. }
  558. Status DrawPie(in Pen pen,
  559. in RectF rect,
  560. in REAL startAngle,
  561. in REAL sweepAngle)
  562. {
  563. return DrawPie(pen,
  564. rect.X,
  565. rect.Y,
  566. rect.Width,
  567. rect.Height,
  568. startAngle,
  569. sweepAngle);
  570. }
  571. Status DrawPie(in Pen pen,
  572. in REAL x,
  573. in REAL y,
  574. in REAL width,
  575. in REAL height,
  576. in REAL startAngle,
  577. in REAL sweepAngle)
  578. {
  579. return SetStatus(GdipDrawPie(nativeGraphics,
  580. pen.nativePen,
  581. x,
  582. y,
  583. width,
  584. height,
  585. startAngle,
  586. sweepAngle));
  587. }
  588. Status DrawPie(in Pen pen,
  589. in Rect rect,
  590. in REAL startAngle,
  591. in REAL sweepAngle)
  592. {
  593. return DrawPie(pen,
  594. rect.X,
  595. rect.Y,
  596. rect.Width,
  597. rect.Height,
  598. startAngle,
  599. sweepAngle);
  600. }
  601. Status DrawPie(in Pen pen,
  602. in INT x,
  603. in INT y,
  604. in INT width,
  605. in INT height,
  606. in REAL startAngle,
  607. in REAL sweepAngle)
  608. {
  609. return SetStatus(GdipDrawPieI(nativeGraphics,
  610. pen.nativePen,
  611. x,
  612. y,
  613. width,
  614. height,
  615. startAngle,
  616. sweepAngle));
  617. }
  618. Status DrawPolygon(in Pen pen,
  619. in PointF* points,
  620. in INT count)
  621. {
  622. return SetStatus(GdipDrawPolygon(nativeGraphics,
  623. pen.nativePen,
  624. points,
  625. count));
  626. }
  627. Status DrawPolygon(in Pen pen,
  628. in Point* points,
  629. in INT count)
  630. {
  631. return SetStatus(GdipDrawPolygonI(nativeGraphics,
  632. pen.nativePen,
  633. points,
  634. count));
  635. }
  636. Status DrawPath(in Pen pen,
  637. in GraphicsPath* path)
  638. {
  639. return SetStatus(GdipDrawPath(nativeGraphics,
  640. pen ? pen.nativePen : null,
  641. path ? path.nativePath : null));
  642. }
  643. Status DrawCurve(in Pen pen,
  644. in PointF* points,
  645. in INT count)
  646. {
  647. return SetStatus(GdipDrawCurve(nativeGraphics,
  648. pen.nativePen, points,
  649. count));
  650. }
  651. Status DrawCurve(in Pen pen,
  652. in PointF* points,
  653. in INT count,
  654. in REAL tension)
  655. {
  656. return SetStatus(GdipDrawCurve2(nativeGraphics,
  657. pen.nativePen, points,
  658. count, tension));
  659. }
  660. Status DrawCurve(in Pen pen,
  661. in PointF* points,
  662. in INT count,
  663. in INT offset,
  664. in INT numberOfSegments,
  665. in REAL tension = 0.5f)
  666. {
  667. return SetStatus(GdipDrawCurve3(nativeGraphics,
  668. pen.nativePen, points,
  669. count, offset,
  670. numberOfSegments, tension));
  671. }
  672. Status DrawCurve(in Pen pen,
  673. in Point* points,
  674. in INT count)
  675. {
  676. return SetStatus(GdipDrawCurveI(nativeGraphics,
  677. pen.nativePen,
  678. points,
  679. count));
  680. }
  681. Status DrawCurve(in Pen pen,
  682. in Point* points,
  683. in INT count,
  684. in REAL tension)
  685. {
  686. return SetStatus(GdipDrawCurve2I(nativeGraphics,
  687. pen.nativePen,
  688. points,
  689. count,
  690. tension));
  691. }
  692. Status DrawCurve(in Pen pen,
  693. in Point* points,
  694. in INT count,
  695. in INT offset,
  696. in INT numberOfSegments,
  697. in REAL tension = 0.5f)
  698. {
  699. return SetStatus(GdipDrawCurve3I(nativeGraphics,
  700. pen.nativePen,
  701. points,
  702. count,
  703. offset,
  704. numberOfSegments,
  705. tension));
  706. }
  707. Status DrawClosedCurve(in Pen pen,
  708. in PointF* points,
  709. in INT count)
  710. {
  711. return SetStatus(GdipDrawClosedCurve(nativeGraphics,
  712. pen.nativePen,
  713. points, count));
  714. }
  715. Status DrawClosedCurve(in Pen *pen,
  716. in PointF* points,
  717. in INT count,
  718. in REAL tension)
  719. {
  720. return SetStatus(GdipDrawClosedCurve2(nativeGraphics,
  721. pen.nativePen,
  722. points, count,
  723. tension));
  724. }
  725. Status DrawClosedCurve(in Pen pen,
  726. in Point* points,
  727. in INT count)
  728. {
  729. return SetStatus(GdipDrawClosedCurveI(nativeGraphics,
  730. pen.nativePen,
  731. points,
  732. count));
  733. }
  734. Status DrawClosedCurve(in Pen *pen,
  735. in Point* points,
  736. in INT count,
  737. in REAL tension)
  738. {
  739. return SetStatus(GdipDrawClosedCurve2I(nativeGraphics,
  740. pen.nativePen,
  741. points,
  742. count,
  743. tension));
  744. }
  745. Status Clear(in Color color)
  746. {
  747. return SetStatus(GdipGraphicsClear(
  748. nativeGraphics,
  749. color.GetValue()));
  750. }
  751. Status FillRectangle(in Brush* brush,
  752. in RectF rect)
  753. {
  754. return FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
  755. }
  756. Status FillRectangle(in Brush* brush,
  757. in REAL x,
  758. in REAL y,
  759. in REAL width,
  760. in REAL height)
  761. {
  762. return SetStatus(GdipFillRectangle(nativeGraphics, brush.nativeBrush, x, y, width, height));
  763. }
  764. Status FillRectangles(in Brush* brush,
  765. in RectF* rects,
  766. in INT count)
  767. {
  768. return SetStatus(GdipFillRectangles(nativeGraphics,
  769. brush.nativeBrush,
  770. rects, count));
  771. }
  772. Status FillRectangle(in Brush* brush,
  773. in Rect rect)
  774. {
  775. return FillRectangle(brush,
  776. rect.X,
  777. rect.Y,
  778. rect.Width,
  779. rect.Height);
  780. }
  781. Status FillRectangle(in Brush* brush,
  782. in INT x,
  783. in INT y,
  784. in INT width,
  785. in INT height)
  786. {
  787. return SetStatus(GdipFillRectangleI(nativeGraphics,
  788. brush.nativeBrush,
  789. x,
  790. y,
  791. width,
  792. height));
  793. }
  794. Status FillRectangles(in Brush* brush,
  795. in Rect* rects,
  796. in INT count)
  797. {
  798. return SetStatus(GdipFillRectanglesI(nativeGraphics,
  799. brush.nativeBrush,
  800. rects,
  801. count));
  802. }
  803. Status FillPolygon(in Brush* brush,
  804. in PointF* points,
  805. in INT count)
  806. {
  807. return FillPolygon(brush, points, count, FillMode.FillModeAlternate);
  808. }
  809. Status FillPolygon(in Brush* brush,
  810. in PointF* points,
  811. in INT count,
  812. in FillMode fillMode)
  813. {
  814. return SetStatus(GdipFillPolygon(nativeGraphics,
  815. brush.nativeBrush,
  816. points, count, fillMode));
  817. }
  818. Status FillPolygon(in Brush* brush,
  819. in Point* points,
  820. in INT count)
  821. {
  822. return FillPolygon(brush, points, count, FillMode.FillModeAlternate);
  823. }
  824. Status FillPolygon(in Brush* brush,
  825. in Point* points,
  826. in INT count,
  827. in FillMode fillMode)
  828. {
  829. return SetStatus(GdipFillPolygonI(nativeGraphics,
  830. brush.nativeBrush,
  831. points, count,
  832. fillMode));
  833. }
  834. Status FillEllipse(in Brush* brush,
  835. in RectF rect)
  836. {
  837. return FillEllipse(brush, rect.X, rect.Y, rect.Width, rect.Height);
  838. }
  839. Status FillEllipse(in Brush* brush,
  840. in REAL x,
  841. in REAL y,
  842. in REAL width,
  843. in REAL height)
  844. {
  845. return SetStatus(GdipFillEllipse(nativeGraphics,
  846. brush.nativeBrush, x, y,
  847. width, height));
  848. }
  849. Status FillEllipse(in Brush* brush,
  850. in Rect rect)
  851. {
  852. return FillEllipse(brush, rect.X, rect.Y, rect.Width, rect.Height);
  853. }
  854. Status FillEllipse(in Brush* brush,
  855. in INT x,
  856. in INT y,
  857. in INT width,
  858. in INT height)
  859. {
  860. return SetStatus(GdipFillEllipseI(nativeGraphics,
  861. brush.nativeBrush,
  862. x,
  863. y,
  864. width,
  865. height));
  866. }
  867. Status FillPie(in Brush* brush,
  868. in RectF rect,
  869. in REAL startAngle,
  870. in REAL sweepAngle)
  871. {
  872. return FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height,
  873. startAngle, sweepAngle);
  874. }
  875. Status FillPie(in Brush* brush,
  876. in REAL x,
  877. in REAL y,
  878. in REAL width,
  879. in REAL height,
  880. in REAL startAngle,
  881. in REAL sweepAngle)
  882. {
  883. return SetStatus(GdipFillPie(nativeGraphics,
  884. brush.nativeBrush, x, y,
  885. width, height, startAngle,
  886. sweepAngle));
  887. }
  888. Status FillPie(in Brush* brush,
  889. in Rect rect,
  890. in REAL startAngle,
  891. in REAL sweepAngle)
  892. {
  893. return FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height,
  894. startAngle, sweepAngle);
  895. }
  896. Status FillPie(in Brush* brush,
  897. in INT x,
  898. in INT y,
  899. in INT width,
  900. in INT height,
  901. in REAL startAngle,
  902. in REAL sweepAngle)
  903. {
  904. return SetStatus(GdipFillPieI(nativeGraphics,
  905. brush.nativeBrush,
  906. x,
  907. y,
  908. width,
  909. height,
  910. startAngle,
  911. sweepAngle));
  912. }
  913. Status FillPath(in Brush* brush,
  914. in GraphicsPath* path)
  915. {
  916. return SetStatus(GdipFillPath(nativeGraphics,
  917. brush.nativeBrush,
  918. path.nativePath));
  919. }
  920. Status FillClosedCurve(in Brush* brush,
  921. in PointF* points,
  922. in INT count)
  923. {
  924. return SetStatus(GdipFillClosedCurve(nativeGraphics,
  925. brush.nativeBrush,
  926. points, count));
  927. }
  928. Status FillClosedCurve(in Brush* brush,
  929. in PointF* points,
  930. in INT count,
  931. in FillMode fillMode,
  932. in REAL tension = 0.5f)
  933. {
  934. return SetStatus(GdipFillClosedCurve2(nativeGraphics,
  935. brush.nativeBrush,
  936. points, count,
  937. tension, fillMode));
  938. }
  939. Status FillClosedCurve(in Brush* brush,
  940. in Point* points,
  941. in INT count)
  942. {
  943. return SetStatus(GdipFillClosedCurveI(nativeGraphics,
  944. brush.nativeBrush,
  945. points,
  946. count));
  947. }
  948. Status FillClosedCurve(in Brush* brush,
  949. in Point* points,
  950. in INT count,
  951. in FillMode fillMode,
  952. in REAL tension = 0.5f)
  953. {
  954. return SetStatus(GdipFillClosedCurve2I(nativeGraphics,
  955. brush.nativeBrush,
  956. points, count,
  957. tension, fillMode));
  958. }
  959. Status FillRegion(in Brush* brush,
  960. in Region* region)
  961. {
  962. return SetStatus(GdipFillRegion(nativeGraphics,
  963. brush.nativeBrush,
  964. region.nativeRegion));
  965. }
  966. Status DrawString(in WCHAR* string, in INT length, in Font font,
  967. in RectF layoutRect, in StringFormat stringFormat, in Brush brush) {
  968. return SetStatus(GdipDrawString(
  969. nativeGraphics,
  970. string,
  971. length,
  972. font ? font.nativeFont : null,
  973. &layoutRect,
  974. stringFormat ? stringFormat.nativeFormat : null,
  975. brush ? brush.nativeBrush : null
  976. ));
  977. }
  978. Status
  979. DrawString(
  980. WCHAR *string,
  981. INT length,
  982. Font font,
  983. PointF origin,
  984. Brush brush
  985. )
  986. {
  987. RectF rect;
  988. rect.init(origin.X, origin.Y, 0.0f, 0.0f);
  989. return SetStatus(GdipDrawString(
  990. nativeGraphics,
  991. string,
  992. length,
  993. font ? font.nativeFont : null,
  994. &rect,
  995. null,
  996. brush ? brush.nativeBrush : null
  997. ));
  998. }
  999. Status
  1000. DrawString(
  1001. WCHAR *string,
  1002. INT length,
  1003. Font font,
  1004. PointF origin,
  1005. StringFormat stringFormat,
  1006. Brush brush
  1007. )
  1008. {
  1009. RectF rect;
  1010. rect.init(origin.X, origin.Y, 0.0f, 0.0f);
  1011. return SetStatus(GdipDrawString(
  1012. nativeGraphics,
  1013. string,
  1014. length,
  1015. font ? font.nativeFont : null,
  1016. &rect,
  1017. stringFormat ? stringFormat.nativeFormat : null,
  1018. brush ? brush.nativeBrush : null
  1019. ));
  1020. }
  1021. Status
  1022. MeasureString(
  1023. in WCHAR *string,
  1024. in INT length,
  1025. in Font font,
  1026. in RectF layoutRect,
  1027. in StringFormat stringFormat,
  1028. RectF *boundingBox,
  1029. INT *codepointsFitted = null,
  1030. INT *linesFilled = null
  1031. ) {
  1032. return SetStatus(GdipMeasureString(
  1033. nativeGraphics,
  1034. string,
  1035. length,
  1036. font ? font.nativeFont : null,
  1037. &layoutRect,
  1038. stringFormat ? stringFormat.nativeFormat : null,
  1039. boundingBox,
  1040. codepointsFitted,
  1041. linesFilled
  1042. ));
  1043. }
  1044. Status
  1045. MeasureString(
  1046. in WCHAR *string,
  1047. in INT length,
  1048. in Font font,
  1049. in SizeF *layoutRectSize,
  1050. in StringFormat stringFormat,
  1051. SizeF *size,
  1052. INT *codepointsFitted = null,
  1053. INT *linesFilled = null
  1054. )
  1055. {
  1056. RectF layoutRect;
  1057. layoutRect.init(0, 0, layoutRectSize.Width, layoutRectSize.Height);
  1058. RectF boundingBox;
  1059. Status status;
  1060. if (size is null) {
  1061. return SetStatus(Status.InvalidParameter);
  1062. }
  1063. status = SetStatus(GdipMeasureString(
  1064. nativeGraphics,
  1065. string,
  1066. length,
  1067. font ? font.nativeFont : null,
  1068. &layoutRect,
  1069. stringFormat ? stringFormat.nativeFormat : null,
  1070. size ? &boundingBox : null,
  1071. codepointsFitted,
  1072. linesFilled
  1073. ));
  1074. if (size && status == Status.Ok)
  1075. {
  1076. size.Width = boundingBox.Width;
  1077. size.Height = boundingBox.Height;
  1078. }
  1079. return status;
  1080. }
  1081. Status
  1082. MeasureString(
  1083. in WCHAR *string,
  1084. in INT length,
  1085. in Font font,
  1086. in PointF origin,
  1087. in StringFormat stringFormat,
  1088. RectF *boundingBox
  1089. )
  1090. {
  1091. RectF rect;
  1092. rect.init(origin.X, origin.Y, 0.0f, 0.0f);
  1093. return SetStatus(GdipMeasureString(
  1094. nativeGraphics,
  1095. string,
  1096. length,
  1097. font ? font.nativeFont : null,
  1098. &rect,
  1099. stringFormat ? stringFormat.nativeFormat : null,
  1100. boundingBox,
  1101. null,
  1102. null
  1103. ));
  1104. }
  1105. Status
  1106. MeasureString(
  1107. in WCHAR *string,
  1108. in INT length,
  1109. in Font font,
  1110. in RectF layoutRect,
  1111. RectF *boundingBox
  1112. )
  1113. {
  1114. return SetStatus(GdipMeasureString(
  1115. nativeGraphics,
  1116. string,
  1117. length,
  1118. font ? font.nativeFont : null,
  1119. &layoutRect,
  1120. null,
  1121. boundingBox,
  1122. null,
  1123. null
  1124. ));
  1125. }
  1126. Status
  1127. MeasureString(
  1128. in WCHAR *string,
  1129. in INT length,
  1130. in Font font,
  1131. in PointF origin,
  1132. RectF *boundingBox
  1133. )
  1134. {
  1135. RectF rect;
  1136. rect.init(origin.X, origin.Y, 0.0f, 0.0f);
  1137. return SetStatus(GdipMeasureString(
  1138. nativeGraphics,
  1139. string,
  1140. length,
  1141. font ? font.nativeFont : null,
  1142. &rect,
  1143. null,
  1144. boundingBox,
  1145. null,
  1146. null
  1147. ));
  1148. }
  1149. Status
  1150. MeasureCharacterRanges(
  1151. in WCHAR *string,
  1152. in INT length,
  1153. in Font font,
  1154. in RectF layoutRect,
  1155. in StringFormat stringFormat,
  1156. in INT regionCount,
  1157. Region *regions
  1158. )
  1159. {
  1160. if (!regions || regionCount <= 0)
  1161. {
  1162. return Status.InvalidParameter;
  1163. }
  1164. GpRegion*[] nativeRegions = new GpRegion* [regionCount];
  1165. if (!nativeRegions) {
  1166. return Status.OutOfMemory;
  1167. }
  1168. for (INT i = 0; i < regionCount; i++) {
  1169. nativeRegions[i] = regions[i].nativeRegion;
  1170. }
  1171. Status status = SetStatus(GdipMeasureCharacterRanges(
  1172. nativeGraphics,
  1173. string,
  1174. length,
  1175. font ? font.nativeFont : null,
  1176. layoutRect,
  1177. stringFormat ? stringFormat.nativeFormat : null,
  1178. regionCount,
  1179. nativeRegions.ptr
  1180. ));
  1181. return status;
  1182. }
  1183. Status DrawDriverString(
  1184. in UINT16 *text,
  1185. in INT length,
  1186. in Font font,
  1187. in Brush brush,
  1188. in PointF *positions,
  1189. in INT flags,
  1190. in Matrix matrix
  1191. )
  1192. {
  1193. return SetStatus(GdipDrawDriverString(
  1194. nativeGraphics,
  1195. text,
  1196. length,
  1197. font ? font.nativeFont : null,
  1198. brush ? brush.nativeBrush : null,
  1199. positions,
  1200. flags,
  1201. matrix ? matrix.nativeMatrix : null
  1202. ));
  1203. }
  1204. Status MeasureDriverString(
  1205. in UINT16 *text,
  1206. in INT length,
  1207. in Font font,
  1208. in PointF *positions,
  1209. in INT flags,
  1210. in Matrix matrix,
  1211. RectF *boundingBox
  1212. )
  1213. {
  1214. return SetStatus(GdipMeasureDriverString(
  1215. nativeGraphics,
  1216. text,
  1217. length,
  1218. font ? font.nativeFont : null,
  1219. positions,
  1220. flags,
  1221. matrix ? matrix.nativeMatrix : null,
  1222. boundingBox
  1223. ));
  1224. }
  1225. // Draw a cached bitmap on this graphics destination offset by
  1226. // x, y. Note this will fail with WrongState if the CachedBitmap
  1227. // native format differs from this Graphics.
  1228. Status DrawCachedBitmap(in CachedBitmap cb,
  1229. in INT x,
  1230. in INT y)
  1231. {
  1232. return SetStatus(GdipDrawCachedBitmap(
  1233. nativeGraphics,
  1234. cb.nativeCachedBitmap,
  1235. x, y
  1236. ));
  1237. }
  1238. Status DrawImage(in Image image,
  1239. in PointF point)
  1240. {
  1241. return DrawImage(image, point.X, point.Y);
  1242. }
  1243. Status DrawImage(in Image image,
  1244. in REAL x,
  1245. in REAL y)
  1246. {
  1247. return SetStatus(GdipDrawImage(nativeGraphics,
  1248. image ? image.nativeImage
  1249. : null,
  1250. x,
  1251. y));
  1252. }
  1253. Status DrawImage(in Image image, in RectF rect) {
  1254. return DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
  1255. }
  1256. Status DrawImage(in Image image,
  1257. in REAL x,
  1258. in REAL y,
  1259. in REAL width,
  1260. in REAL height)
  1261. {
  1262. return SetStatus(GdipDrawImageRect(nativeGraphics,
  1263. image ? image.nativeImage
  1264. : null,
  1265. x,
  1266. y,
  1267. width,
  1268. height));
  1269. }
  1270. Status DrawImage(in Image image,
  1271. in Point point)
  1272. {
  1273. return DrawImage(image, point.X, point.Y);
  1274. }
  1275. Status DrawImage(in Image image,
  1276. in INT x,
  1277. in INT y)
  1278. {
  1279. return SetStatus(GdipDrawImageI(nativeGraphics,
  1280. image ? image.nativeImage
  1281. : null,
  1282. x,
  1283. y));
  1284. }
  1285. Status DrawImage(in Image image,
  1286. in Rect rect)
  1287. {
  1288. return DrawImage(image,
  1289. rect.X,
  1290. rect.Y,
  1291. rect.Width,
  1292. rect.Height);
  1293. }
  1294. Status DrawImage(in Image image,
  1295. in INT x,
  1296. in INT y,
  1297. in INT width,
  1298. in INT height) {
  1299. return SetStatus(GdipDrawImageRectI(nativeGraphics,
  1300. image ? image.nativeImage
  1301. : null,
  1302. x,
  1303. y,
  1304. width,
  1305. height));
  1306. }
  1307. Status DrawImage(in Image image,
  1308. in PointF* destPoints,
  1309. in INT count)
  1310. {
  1311. if (count != 3 && count != 4)
  1312. return SetStatus(Status.InvalidParameter);
  1313. return SetStatus(GdipDrawImagePoints(nativeGraphics,
  1314. image ? image.nativeImage
  1315. : null,
  1316. destPoints, count));
  1317. }
  1318. Status DrawImage(in Image image,
  1319. in Point* destPoints,
  1320. in INT count)
  1321. {
  1322. if (count != 3 && count != 4)
  1323. return SetStatus(Status.InvalidParameter);
  1324. return SetStatus(GdipDrawImagePointsI(nativeGraphics,
  1325. image ? image.nativeImage
  1326. : null,
  1327. destPoints,
  1328. count));
  1329. }
  1330. Status DrawImage(in Image image,
  1331. in REAL x,
  1332. in REAL y,
  1333. in REAL srcx,
  1334. in REAL srcy,
  1335. in REAL srcwidth,
  1336. in REAL srcheight,
  1337. in Unit srcUnit)
  1338. {
  1339. return SetStatus(GdipDrawImagePointRect(nativeGraphics,