PageRenderTime 105ms CodeModel.GetById 10ms app.highlight 86ms RepoModel.GetById 1ms app.codeStats 1ms

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

Large files files are truncated, but you can click here to view the full file