Home | History | Annotate | Download | only in include
      1 /**************************************************************************\
      2 *
      3 * Copyright (c) 1998-2000, Microsoft Corp.  All Rights Reserved.
      4 *
      5 * Module Name:
      6 *
      7 *   GdiplusTypes.h
      8 *
      9 * Abstract:
     10 *
     11 *   Basic types used by GDI+
     12 *
     13 \**************************************************************************/
     14 
     15 #ifndef _GDIPLUSTYPES_H
     16 #define _GDIPLUSTYPES_H
     17 
     18 #ifndef DCR_USE_NEW_175866
     19 
     20 //--------------------------------------------------------------------------
     21 // LIB version initialization functions
     22 //--------------------------------------------------------------------------
     23 
     24 typedef VOID (__cdecl *DEBUGEVENTFUNCTION)(INT level, CHAR *message);
     25 
     26 extern "C" BOOL __stdcall InitializeGdiplus(DEBUGEVENTFUNCTION);
     27 extern "C" VOID __stdcall UninitializeGdiplus();
     28 
     29 #endif
     30 
     31 //--------------------------------------------------------------------------
     32 // Callback functions
     33 //--------------------------------------------------------------------------
     34 
     35 extern "C" {
     36 typedef BOOL (CALLBACK * ImageAbort)(VOID *);
     37 typedef ImageAbort DrawImageAbort;
     38 typedef ImageAbort GetThumbnailImageAbort;
     39 }
     40 
     41 // Callback for EnumerateMetafile methods.  The parameters are:
     42 
     43 //      recordType      WMF, EMF, or EMF+ record type
     44 //      flags           (always 0 for WMF/EMF records)
     45 //      dataSize        size of the record data (in bytes), or 0 if no data
     46 //      data            pointer to the record data, or NULL if no data
     47 //      callbackData    pointer to callbackData, if any
     48 
     49 // This method can then call Metafile::PlayRecord to play the
     50 // record that was just enumerated.  If this method  returns
     51 // FALSE, the enumeration process is aborted.  Otherwise, it continues.
     52 
     53 extern "C" {
     54 typedef BOOL (CALLBACK * EnumerateMetafileProc)(EmfPlusRecordType,UINT,UINT,const BYTE*,VOID*);
     55 }
     56 
     57 //--------------------------------------------------------------------------
     58 // Primitive data types
     59 //
     60 // NOTE:
     61 //  Types already defined in standard header files:
     62 //      INT8
     63 //      UINT8
     64 //      INT16
     65 //      UINT16
     66 //      INT32
     67 //      UINT32
     68 //      INT64
     69 //      UINT64
     70 //
     71 //  Avoid using the following types:
     72 //      LONG - use INT
     73 //      ULONG - use UINT
     74 //      DWORD - use UINT32
     75 //--------------------------------------------------------------------------
     76 
     77 typedef float REAL;
     78 
     79 #define REAL_MAX            FLT_MAX
     80 #define REAL_MIN            FLT_MIN
     81 #define REAL_TOLERANCE     (FLT_MIN * 100)
     82 #define REAL_EPSILON        1.192092896e-07F        /* FLT_EPSILON */
     83 
     84 //--------------------------------------------------------------------------
     85 // Forward declarations of various internal classes
     86 //--------------------------------------------------------------------------
     87 
     88 class Size;
     89 class SizeF;
     90 class Point;
     91 class PointF;
     92 class Rect;
     93 class RectF;
     94 class CharacterRange;
     95 
     96 //--------------------------------------------------------------------------
     97 // Return values from any GDI+ API
     98 //--------------------------------------------------------------------------
     99 
    100 enum Status
    101 {
    102     Ok = 0,
    103     GenericError = 1,
    104     InvalidParameter = 2,
    105     OutOfMemory = 3,
    106     ObjectBusy = 4,
    107     InsufficientBuffer = 5,
    108     NotImplemented = 6,
    109     Win32Error = 7,
    110     WrongState = 8,
    111     Aborted = 9,
    112 #ifdef DCR_USE_NEW_135429
    113     FileNotFound = 10,
    114     ValueOverflow = 11,
    115     AccessDenied = 12,
    116     UnknownImageFormat = 13,
    117     FontFamilyNotFound = 14,
    118     FontStyleNotFound = 15,
    119     NotTrueTypeFont = 16,
    120 #else
    121     NotFound = 10,
    122     ValueOverflow = 11,
    123 #endif
    124     UnsupportedGdiplusVersion = 17,
    125     GdiplusNotInitialized
    126 
    127 };
    128 
    129 //--------------------------------------------------------------------------
    130 // Represents a dimension in a 2D coordinate system
    131 //  (floating-point coordinates)
    132 //--------------------------------------------------------------------------
    133 
    134 class SizeF
    135 {
    136 public:
    137 
    138    // Default constructor
    139     SizeF()
    140     {
    141         Width = Height = 0.0f;
    142     }
    143 
    144     SizeF(IN const SizeF& size)
    145     {
    146         Width = size.Width;
    147         Height = size.Height;
    148     }
    149 
    150     SizeF(IN REAL width,
    151           IN REAL height)
    152     {
    153         Width = width;
    154         Height = height;
    155     }
    156 
    157     SizeF operator+(IN const SizeF& sz) const
    158     {
    159         return SizeF(Width + sz.Width,
    160                      Height + sz.Height);
    161     }
    162 
    163     SizeF operator-(IN const SizeF& sz) const
    164     {
    165         return SizeF(Width - sz.Width,
    166                      Height - sz.Height);
    167     }
    168 
    169     BOOL Equals(IN const SizeF& sz) const
    170     {
    171         return (Width == sz.Width) && (Height == sz.Height);
    172     }
    173 
    174     BOOL Empty() const
    175     {
    176         return (Width == 0.0f && Height == 0.0f);
    177     }
    178 
    179 public:
    180 
    181     REAL Width;
    182     REAL Height;
    183 };
    184 
    185 //--------------------------------------------------------------------------
    186 // Represents a dimension in a 2D coordinate system
    187 //  (integer coordinates)
    188 //--------------------------------------------------------------------------
    189 
    190 class Size
    191 {
    192 public:
    193 
    194    // Default constructor
    195     Size()
    196     {
    197         Width = Height = 0;
    198     }
    199 
    200     Size(IN const Size& size)
    201     {
    202         Width = size.Width;
    203         Height = size.Height;
    204     }
    205 
    206     Size(IN INT width,
    207          IN INT height)
    208     {
    209         Width = width;
    210         Height = height;
    211     }
    212 
    213     Size operator+(IN const Size& sz) const
    214     {
    215         return Size(Width + sz.Width,
    216                     Height + sz.Height);
    217     }
    218 
    219     Size operator-(IN const Size& sz) const
    220     {
    221         return Size(Width - sz.Width,
    222                     Height - sz.Height);
    223     }
    224 
    225     BOOL Equals(IN const Size& sz) const
    226     {
    227         return (Width == sz.Width) && (Height == sz.Height);
    228     }
    229 
    230     BOOL Empty() const
    231     {
    232         return (Width == 0 && Height == 0);
    233     }
    234 
    235 public:
    236 
    237     INT Width;
    238     INT Height;
    239 };
    240 
    241 //--------------------------------------------------------------------------
    242 // Represents a location in a 2D coordinate system
    243 //  (floating-point coordinates)
    244 //--------------------------------------------------------------------------
    245 
    246 class PointF
    247 {
    248 public:
    249    PointF()
    250    {
    251        X = Y = 0.0f;
    252    }
    253 
    254    PointF(IN const PointF &point)
    255    {
    256        X = point.X;
    257        Y = point.Y;
    258    }
    259 
    260    PointF(IN const SizeF &size)
    261    {
    262        X = size.Width;
    263        Y = size.Height;
    264    }
    265 
    266    PointF(IN REAL x,
    267           IN REAL y)
    268    {
    269        X = x;
    270        Y = y;
    271    }
    272 
    273    PointF operator+(IN const PointF& point) const
    274    {
    275        return PointF(X + point.X,
    276                      Y + point.Y);
    277    }
    278 
    279    PointF operator-(IN const PointF& point) const
    280    {
    281        return PointF(X - point.X,
    282                      Y - point.Y);
    283    }
    284 
    285    BOOL Equals(IN const PointF& point)
    286    {
    287        return (X == point.X) && (Y == point.Y);
    288    }
    289 
    290 public:
    291 
    292     REAL X;
    293     REAL Y;
    294 };
    295 
    296 //--------------------------------------------------------------------------
    297 // Represents a location in a 2D coordinate system
    298 //  (integer coordinates)
    299 //--------------------------------------------------------------------------
    300 
    301 class Point
    302 {
    303 public:
    304    Point()
    305    {
    306        X = Y = 0;
    307    }
    308 
    309    Point(IN const Point &point)
    310    {
    311        X = point.X;
    312        Y = point.Y;
    313    }
    314 
    315    Point(IN const Size &size)
    316    {
    317        X = size.Width;
    318        Y = size.Height;
    319    }
    320 
    321    Point(IN INT x,
    322          IN INT y)
    323    {
    324        X = x;
    325        Y = y;
    326    }
    327 
    328    Point operator+(IN const Point& point) const
    329    {
    330        return Point(X + point.X,
    331                     Y + point.Y);
    332    }
    333 
    334    Point operator-(IN const Point& point) const
    335    {
    336        return Point(X - point.X,
    337                     Y - point.Y);
    338    }
    339 
    340    BOOL Equals(IN const Point& point)
    341    {
    342        return (X == point.X) && (Y == point.Y);
    343    }
    344 
    345 public:
    346 
    347     INT X;
    348     INT Y;
    349 };
    350 
    351 //--------------------------------------------------------------------------
    352 // Represents a rectangle in a 2D coordinate system
    353 //  (floating-point coordinates)
    354 //--------------------------------------------------------------------------
    355 
    356 class RectF
    357 {
    358 public:
    359 
    360     // Default constructor
    361 
    362     RectF()
    363     {
    364         X = Y = Width = Height = 0.0f;
    365     }
    366 
    367     RectF(IN REAL x,
    368           IN REAL y,
    369           IN REAL width,
    370           IN REAL height)
    371     {
    372         X = x;
    373         Y = y;
    374         Width = width;
    375         Height = height;
    376     }
    377 
    378     RectF(IN const PointF& location,
    379           IN const SizeF& size)
    380     {
    381         X = location.X;
    382         Y = location.Y;
    383         Width = size.Width;
    384         Height = size.Height;
    385     }
    386 
    387     RectF* Clone() const
    388     {
    389         return new RectF(X, Y, Width, Height);
    390     }
    391 
    392     VOID GetLocation(OUT PointF* point) const
    393     {
    394         point->X = X;
    395         point->Y = Y;
    396     }
    397 
    398     VOID GetSize(OUT SizeF* size) const
    399     {
    400         size->Width = Width;
    401         size->Height = Height;
    402     }
    403 
    404     VOID GetBounds(OUT RectF* rect) const
    405     {
    406         rect->X = X;
    407         rect->Y = Y;
    408         rect->Width = Width;
    409         rect->Height = Height;
    410     }
    411 
    412     // Return the left, top, right, and bottom
    413     // coordinates of the rectangle
    414 
    415     REAL GetLeft() const
    416     {
    417         return X;
    418     }
    419 
    420     REAL GetTop() const
    421     {
    422         return Y;
    423     }
    424 
    425     REAL GetRight() const
    426     {
    427         return X+Width;
    428     }
    429 
    430     REAL GetBottom() const
    431     {
    432         return Y+Height;
    433     }
    434 
    435     // Determine if the rectangle is empty
    436     BOOL IsEmptyArea() const
    437     {
    438         return (Width <= REAL_EPSILON) || (Height <= REAL_EPSILON);
    439     }
    440 
    441     BOOL Equals(IN const RectF & rect) const
    442     {
    443         return X == rect.X &&
    444                Y == rect.Y &&
    445                Width == rect.Width &&
    446                Height == rect.Height;
    447     }
    448 
    449     BOOL Contains(IN REAL x,
    450                   IN REAL y) const
    451     {
    452         return x >= X && x < X+Width &&
    453                y >= Y && y < Y+Height;
    454     }
    455 
    456     BOOL Contains(IN const PointF& pt) const
    457     {
    458         return Contains(pt.X, pt.Y);
    459     }
    460 
    461     BOOL Contains(IN const RectF& rect) const
    462     {
    463         return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
    464                (Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
    465     }
    466 
    467     VOID Inflate(IN REAL dx,
    468                  IN REAL dy)
    469     {
    470         X -= dx;
    471         Y -= dy;
    472         Width += 2*dx;
    473         Height += 2*dy;
    474     }
    475 
    476     VOID Inflate(IN const PointF& point)
    477     {
    478         Inflate(point.X, point.Y);
    479     }
    480 
    481     // Intersect the current rect with the specified object
    482 
    483     BOOL Intersect(IN const RectF& rect)
    484     {
    485         return Intersect(*this, *this, rect);
    486     }
    487 
    488     // Intersect rect a and b and save the result into c
    489     // Notice that c may be the same object as a or b.
    490 
    491     static BOOL Intersect(OUT RectF& c,
    492                           IN const RectF& a,
    493                           IN const RectF& b)
    494     {
    495         REAL right = min(a.GetRight(), b.GetRight());
    496         REAL bottom = min(a.GetBottom(), b.GetBottom());
    497         REAL left = max(a.GetLeft(), b.GetLeft());
    498         REAL top = max(a.GetTop(), b.GetTop());
    499 
    500         c.X = left;
    501         c.Y = top;
    502         c.Width = right - left;
    503         c.Height = bottom - top;
    504         return !c.IsEmptyArea();
    505     }
    506 
    507     // Determine if the specified rect intersects with the
    508     // current rect object.
    509 
    510     BOOL IntersectsWith(IN const RectF& rect) const
    511     {
    512         return (GetLeft() < rect.GetRight() &&
    513                 GetTop() < rect.GetTop() &&
    514                 GetRight() > rect.GetLeft() &&
    515                 GetBottom() > rect.GetTop());
    516     }
    517 
    518     static BOOL Union(OUT RectF& c,
    519                       IN const RectF& a,
    520                       IN const RectF& b)
    521     {
    522         REAL right = max(a.GetRight(), b.GetRight());
    523         REAL bottom = max(a.GetBottom(), b.GetBottom());
    524         REAL left = min(a.GetLeft(), b.GetLeft());
    525         REAL top = min(a.GetTop(), b.GetTop());
    526 
    527         c.X = left;
    528         c.Y = top;
    529         c.Width = right - left;
    530         c.Height = bottom - top;
    531         return !c.IsEmptyArea();
    532     }
    533 
    534     VOID Offset(IN const PointF& point)
    535     {
    536         Offset(point.X, point.Y);
    537     }
    538 
    539     VOID Offset(IN REAL dx,
    540                 IN REAL dy)
    541     {
    542         X += dx;
    543         Y += dy;
    544     }
    545 
    546 public:
    547 
    548     REAL X;
    549     REAL Y;
    550     REAL Width;
    551     REAL Height;
    552 };
    553 
    554 //--------------------------------------------------------------------------
    555 // Represents a rectangle in a 2D coordinate system
    556 //  (integer coordinates)
    557 //--------------------------------------------------------------------------
    558 
    559 class Rect
    560 {
    561 public:
    562 
    563     // Default constructor
    564 
    565     Rect()
    566     {
    567         X = Y = Width = Height = 0;
    568     }
    569 
    570     Rect(IN INT x,
    571          IN INT y,
    572          IN INT width,
    573          IN INT height)
    574     {
    575         X = x;
    576         Y = y;
    577         Width = width;
    578         Height = height;
    579     }
    580 
    581     Rect(IN const Point& location,
    582          IN const Size& size)
    583     {
    584         X = location.X;
    585         Y = location.Y;
    586         Width = size.Width;
    587         Height = size.Height;
    588     }
    589 
    590     Rect* Clone() const
    591     {
    592         return new Rect(X, Y, Width, Height);
    593     }
    594 
    595     VOID GetLocation(OUT Point* point) const
    596     {
    597         point->X = X;
    598         point->Y = Y;
    599     }
    600 
    601     VOID GetSize(OUT Size* size) const
    602     {
    603         size->Width = Width;
    604         size->Height = Height;
    605     }
    606 
    607     VOID GetBounds(OUT Rect* rect) const
    608     {
    609         rect->X = X;
    610         rect->Y = Y;
    611         rect->Width = Width;
    612         rect->Height = Height;
    613     }
    614 
    615     // Return the left, top, right, and bottom
    616     // coordinates of the rectangle
    617 
    618     INT GetLeft() const
    619     {
    620         return X;
    621     }
    622 
    623     INT GetTop() const
    624     {
    625         return Y;
    626     }
    627 
    628     INT GetRight() const
    629     {
    630         return X+Width;
    631     }
    632 
    633     INT GetBottom() const
    634     {
    635         return Y+Height;
    636     }
    637 
    638     // Determine if the rectangle is empty
    639     BOOL IsEmptyArea() const
    640     {
    641         return (Width <= 0) || (Height <= 0);
    642     }
    643 
    644     BOOL Equals(IN const Rect & rect) const
    645     {
    646         return X == rect.X &&
    647                Y == rect.Y &&
    648                Width == rect.Width &&
    649                Height == rect.Height;
    650     }
    651 
    652     BOOL Contains(IN INT x,
    653                   IN INT y) const
    654     {
    655         return x >= X && x < X+Width &&
    656                y >= Y && y < Y+Height;
    657     }
    658 
    659     BOOL Contains(IN const Point& pt) const
    660     {
    661         return Contains(pt.X, pt.Y);
    662     }
    663 
    664     BOOL Contains(IN Rect& rect) const
    665     {
    666         return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
    667                (Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
    668     }
    669 
    670     VOID Inflate(IN INT dx,
    671                  IN INT dy)
    672     {
    673         X -= dx;
    674         Y -= dy;
    675         Width += 2*dx;
    676         Height += 2*dy;
    677     }
    678 
    679     VOID Inflate(IN const Point& point)
    680     {
    681         Inflate(point.X, point.Y);
    682     }
    683 
    684     // Intersect the current rect with the specified object
    685 
    686     BOOL Intersect(IN const Rect& rect)
    687     {
    688         return Intersect(*this, *this, rect);
    689     }
    690 
    691     // Intersect rect a and b and save the result into c
    692     // Notice that c may be the same object as a or b.
    693 
    694     static BOOL Intersect(OUT Rect& c,
    695                           IN const Rect& a,
    696                           IN const Rect& b)
    697     {
    698         INT right = min(a.GetRight(), b.GetRight());
    699         INT bottom = min(a.GetBottom(), b.GetBottom());
    700         INT left = max(a.GetLeft(), b.GetLeft());
    701         INT top = max(a.GetTop(), b.GetTop());
    702 
    703         c.X = left;
    704         c.Y = top;
    705         c.Width = right - left;
    706         c.Height = bottom - top;
    707         return !c.IsEmptyArea();
    708     }
    709 
    710     // Determine if the specified rect intersects with the
    711     // current rect object.
    712 
    713     BOOL IntersectsWith(IN const Rect& rect) const
    714     {
    715         return (GetLeft() < rect.GetRight() &&
    716                 GetTop() < rect.GetTop() &&
    717                 GetRight() > rect.GetLeft() &&
    718                 GetBottom() > rect.GetTop());
    719     }
    720 
    721     static BOOL Union(OUT Rect& c,
    722                       IN const Rect& a,
    723                       IN const Rect& b)
    724     {
    725         INT right = max(a.GetRight(), b.GetRight());
    726         INT bottom = max(a.GetBottom(), b.GetBottom());
    727         INT left = min(a.GetLeft(), b.GetLeft());
    728         INT top = min(a.GetTop(), b.GetTop());
    729 
    730         c.X = left;
    731         c.Y = top;
    732         c.Width = right - left;
    733         c.Height = bottom - top;
    734         return !c.IsEmptyArea();
    735     }
    736 
    737     VOID Offset(IN const Point& point)
    738     {
    739         Offset(point.X, point.Y);
    740     }
    741 
    742     VOID Offset(IN INT dx,
    743                 IN INT dy)
    744     {
    745         X += dx;
    746         Y += dy;
    747     }
    748 
    749 public:
    750 
    751     INT X;
    752     INT Y;
    753     INT Width;
    754     INT Height;
    755 };
    756 
    757 // A user must mange memory for PathData.
    758 
    759 class PathData
    760 {
    761 public:
    762     PathData()
    763     {
    764         Count = 0;
    765         Points = NULL;
    766         Types = NULL;
    767     }
    768 
    769     ~PathData()
    770     {
    771         if (Points != NULL)
    772         {
    773             delete Points;
    774         }
    775 
    776         if (Types != NULL)
    777         {
    778             delete Types;
    779         }
    780     }
    781 
    782 #ifdef DCR_USE_NEW_250932
    783 
    784 private:
    785     PathData(const PathData &);
    786     PathData& operator=(const PathData &);
    787 
    788 #endif
    789 
    790 public:
    791     INT Count;
    792     PointF* Points;
    793     BYTE* Types;
    794 };
    795 
    796 
    797 //-----------------------------
    798 // text character range
    799 //-----------------------------
    800 
    801 class CharacterRange
    802 {
    803 public:
    804     CharacterRange(
    805         INT first,
    806         INT length
    807     ) :
    808         First   (first),
    809         Length  (length)
    810     {}
    811 
    812     CharacterRange() : First(0), Length(0)
    813     {}
    814 
    815     CharacterRange & operator = (const CharacterRange &rhs)
    816     {
    817         First  = rhs.First;
    818         Length = rhs.Length;
    819         return *this;
    820     }
    821 
    822     INT First;
    823     INT Length;
    824 };
    825 
    826 #endif // !_GDIPLUSTYPES_HPP
    827