1 /* 2 * gdiplustypes.h 3 * 4 * GDI+ basic type declarations 5 * 6 * This file is part of the w32api package. 7 * 8 * Contributors: 9 * Created by Markus Koenig <markus (at) stber-koenig.de> 10 * 11 * THIS SOFTWARE IS NOT COPYRIGHTED 12 * 13 * This source code is offered for use in the public domain. You may 14 * use, modify or distribute it freely. 15 * 16 * This code is distributed in the hope that it will be useful but 17 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY 18 * DISCLAIMED. This includes but is not limited to warranties of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 */ 22 23 #ifndef __GDIPLUS_TYPES_H 24 #define __GDIPLUS_TYPES_H 25 #if __GNUC__ >=3 26 #pragma GCC system_header 27 #endif 28 29 #define WINGDIPAPI __stdcall 30 #define GDIPCONST const 31 32 typedef enum GpStatus { 33 Ok = 0, 34 GenericError = 1, 35 InvalidParameter = 2, 36 OutOfMemory = 3, 37 ObjectBusy = 4, 38 InsufficientBuffer = 5, 39 NotImplemented = 6, 40 Win32Error = 7, 41 WrongState = 8, 42 Aborted = 9, 43 FileNotFound = 10, 44 ValueOverflow = 11, 45 AccessDenied = 12, 46 UnknownImageFormat = 13, 47 FontFamilyNotFound = 14, 48 FontStyleNotFound = 15, 49 NotTrueTypeFont = 16, 50 UnsupportedGdiplusVersion = 17, 51 GdiplusNotInitialized = 18, 52 PropertyNotFound = 19, 53 PropertyNotSupported = 20, 54 ProfileNotFound = 21 55 } GpStatus; 56 57 #ifdef __cplusplus 58 typedef GpStatus Status; 59 #endif 60 61 typedef struct Size { 62 INT Width; 63 INT Height; 64 65 #ifdef __cplusplus 66 Size(): Width(0), Height(0) {} 67 Size(INT width, INT height): Width(width), Height(height) {} 68 Size(const Size& size): Width(size.Width), Height(size.Height) {} 69 70 BOOL Empty() const { 71 return Width == 0 && Height == 0; 72 } 73 BOOL Equals(const Size& size) const { 74 return Width == size.Width && Height == size.Height; 75 } 76 Size operator+(const Size& size) const { 77 return Size(Width + size.Width, Height + size.Height); 78 } 79 Size operator-(const Size& size) const { 80 return Size(Width - size.Width, Height - size.Height); 81 } 82 #endif /* __cplusplus */ 83 } Size; 84 85 typedef struct SizeF { 86 REAL Width; 87 REAL Height; 88 89 #ifdef __cplusplus 90 SizeF(): Width(0.0f), Height(0.0f) {} 91 SizeF(REAL width, REAL height): Width(width), Height(height) {} 92 SizeF(const SizeF& size): Width(size.Width), Height(size.Height) {} 93 94 BOOL Empty() const { 95 return Width == 0.0f && Height == 0.0f; 96 } 97 BOOL Equals(const SizeF& size) const { 98 return Width == size.Width && Height == size.Height; 99 } 100 SizeF operator+(const SizeF& size) const { 101 return SizeF(Width + size.Width, Height + size.Height); 102 } 103 SizeF operator-(const SizeF& size) const { 104 return SizeF(Width - size.Width, Height - size.Height); 105 } 106 #endif /* __cplusplus */ 107 } SizeF; 108 109 typedef struct Point { 110 INT X; 111 INT Y; 112 113 #ifdef __cplusplus 114 Point(): X(0), Y(0) {} 115 Point(INT x, INT y): X(x), Y(y) {} 116 Point(const Point& point): X(point.X), Y(point.Y) {} 117 Point(const Size& size): X(size.Width), Y(size.Height) {} 118 119 BOOL Equals(const Point& point) const { 120 return X == point.X && Y == point.Y; 121 } 122 Point operator+(const Point& point) const { 123 return Point(X + point.X, Y + point.Y); 124 } 125 Point operator-(const Point& point) const { 126 return Point(X - point.X, Y - point.Y); 127 } 128 #endif /* __cplusplus */ 129 } Point; 130 131 typedef struct PointF { 132 REAL X; 133 REAL Y; 134 135 #ifdef __cplusplus 136 PointF(): X(0.0f), Y(0.0f) {} 137 PointF(REAL x, REAL y): X(x), Y(y) {} 138 PointF(const PointF& point): X(point.X), Y(point.Y) {} 139 PointF(const SizeF& size): X(size.Width), Y(size.Height) {} 140 141 BOOL Equals(const PointF& point) const { 142 return X == point.X && Y == point.Y; 143 } 144 PointF operator+(const PointF& point) const { 145 return PointF(X + point.X, Y + point.Y); 146 } 147 PointF operator-(const PointF& point) const { 148 return PointF(X - point.X, Y - point.Y); 149 } 150 #endif /* __cplusplus */ 151 } PointF; 152 153 typedef struct Rect { 154 INT X; 155 INT Y; 156 INT Width; 157 INT Height; 158 159 #ifdef __cplusplus 160 Rect(): X(0), Y(0), Width(0), Height(0) {} 161 Rect(const Point& location, const Size& size): 162 X(location.X), Y(location.Y), 163 Width(size.Width), Height(size.Height) {} 164 Rect(INT x, INT y, INT width, INT height): 165 X(x), Y(y), Width(width), Height(height) {} 166 167 Rect* Clone() const { 168 return new Rect(X, Y, Width, Height); 169 } 170 BOOL Contains(INT x, INT y) const { 171 return X <= x && Y <= y && x < X+Width && y < Y+Height; 172 } 173 BOOL Contains(const Point& point) const { 174 return Contains(point.X, point.Y); 175 } 176 BOOL Contains(const Rect& rect) const { 177 return X <= rect.X && Y <= rect.Y 178 && rect.X+rect.Width <= X+Width 179 && rect.Y+rect.Height <= Y+Height; 180 } 181 BOOL Equals(const Rect& rect) const { 182 return X == rect.X && Y == rect.Y 183 && Width == rect.Width && Height == rect.Height; 184 } 185 INT GetBottom() const { 186 return Y+Height; 187 } 188 VOID GetBounds(Rect *rect) const { 189 if (rect != NULL) { 190 rect->X = X; 191 rect->Y = Y; 192 rect->Width = Width; 193 rect->Height = Height; 194 } 195 } 196 INT GetLeft() const { 197 return X; 198 } 199 VOID GetLocation(Point *point) const { 200 if (point != NULL) { 201 point->X = X; 202 point->Y = Y; 203 } 204 } 205 INT GetRight() const { 206 return X+Width; 207 } 208 VOID GetSize(Size *size) const { 209 if (size != NULL) { 210 size->Width = Width; 211 size->Height = Height; 212 } 213 } 214 INT GetTop() const { 215 return Y; 216 } 217 BOOL IsEmptyArea() const { 218 return Width <= 0 || Height <= 0; 219 } 220 VOID Inflate(INT dx, INT dy) { 221 X -= dx; 222 Y -= dy; 223 Width += 2*dx; 224 Height += 2*dy; 225 } 226 VOID Inflate(const Point& point) { 227 Inflate(point.X, point.Y); 228 } 229 static BOOL Intersect(Rect& c, const Rect& a, const Rect& b) { 230 INT intersectLeft = (a.X < b.X) ? b.X : a.X; 231 INT intersectTop = (a.Y < b.Y) ? b.Y : a.Y; 232 INT intersectRight = (a.GetRight() < b.GetRight()) 233 ? a.GetRight() : b.GetRight(); 234 INT intersectBottom = (a.GetBottom() < b.GetBottom()) 235 ? a.GetBottom() : b.GetBottom(); 236 c.X = intersectLeft; 237 c.Y = intersectTop; 238 c.Width = intersectRight - intersectLeft; 239 c.Height = intersectBottom - intersectTop; 240 return !c.IsEmptyArea(); 241 } 242 BOOL Intersect(const Rect& rect) { 243 return Intersect(*this, *this, rect); 244 } 245 BOOL IntersectsWith(const Rect& rc) const { 246 INT intersectLeft = (X < rc.X) ? rc.X : X; 247 INT intersectTop = (Y < rc.Y) ? rc.Y : Y; 248 INT intersectRight = (GetRight() < rc.GetRight()) 249 ? GetRight() : rc.GetRight(); 250 INT intersectBottom = (GetBottom() < rc.GetBottom()) 251 ? GetBottom() : rc.GetBottom(); 252 return intersectLeft < intersectRight 253 && intersectTop < intersectBottom; 254 } 255 VOID Offset(INT dx, INT dy) { 256 X += dx; 257 Y += dy; 258 } 259 VOID Offset(const Point& point) { 260 Offset(point.X, point.Y); 261 } 262 static BOOL Union(Rect& c, const Rect& a, const Rect& b) { 263 INT unionLeft = (a.X < b.X) ? a.X : b.X; 264 INT unionTop = (a.Y < b.Y) ? a.Y : b.Y; 265 INT unionRight = (a.GetRight() < b.GetRight()) 266 ? b.GetRight() : a.GetRight(); 267 INT unionBottom = (a.GetBottom() < b.GetBottom()) 268 ? b.GetBottom() : a.GetBottom(); 269 c.X = unionLeft; 270 c.Y = unionTop; 271 c.Width = unionRight - unionLeft; 272 c.Height = unionBottom - unionTop; 273 return !c.IsEmptyArea(); 274 } 275 #endif /* __cplusplus */ 276 } Rect; 277 278 typedef struct RectF { 279 REAL X; 280 REAL Y; 281 REAL Width; 282 REAL Height; 283 284 #ifdef __cplusplus 285 RectF(): X(0.0f), Y(0.0f), Width(0.0f), Height(0.0f) {} 286 RectF(const PointF& location, const SizeF& size): 287 X(location.X), Y(location.Y), 288 Width(size.Width), Height(size.Height) {} 289 RectF(REAL x, REAL y, REAL width, REAL height): 290 X(x), Y(y), Width(width), Height(height) {} 291 292 RectF* Clone() const { 293 return new RectF(X, Y, Width, Height); 294 } 295 BOOL Contains(REAL x, REAL y) const { 296 return X <= x && Y <= y && x < X+Width && y < Y+Height; 297 } 298 BOOL Contains(const PointF& point) const { 299 return Contains(point.X, point.Y); 300 } 301 BOOL Contains(const RectF& rect) const { 302 return X <= rect.X && Y <= rect.Y 303 && rect.X+rect.Width <= X+Width 304 && rect.Y+rect.Height <= Y+Height; 305 } 306 BOOL Equals(const RectF& rect) const { 307 return X == rect.X && Y == rect.Y 308 && Width == rect.Width && Height == rect.Height; 309 } 310 REAL GetBottom() const { 311 return Y+Height; 312 } 313 VOID GetBounds(RectF *rect) const { 314 if (rect != NULL) { 315 rect->X = X; 316 rect->Y = Y; 317 rect->Width = Width; 318 rect->Height = Height; 319 } 320 } 321 REAL GetLeft() const { 322 return X; 323 } 324 VOID GetLocation(PointF *point) const { 325 if (point != NULL) { 326 point->X = X; 327 point->Y = Y; 328 } 329 } 330 REAL GetRight() const { 331 return X+Width; 332 } 333 VOID GetSize(SizeF *size) const { 334 if (size != NULL) { 335 size->Width = Width; 336 size->Height = Height; 337 } 338 } 339 REAL GetTop() const { 340 return Y; 341 } 342 BOOL IsEmptyArea() const { 343 return Width <= 0.0f || Height <= 0.0f; 344 } 345 VOID Inflate(REAL dx, REAL dy) { 346 X -= dx; 347 Y -= dy; 348 Width += 2*dx; 349 Height += 2*dy; 350 } 351 VOID Inflate(const PointF& point) { 352 Inflate(point.X, point.Y); 353 } 354 static BOOL Intersect(RectF& c, const RectF& a, const RectF& b) { 355 INT intersectLeft = (a.X < b.X) ? b.X : a.X; 356 INT intersectTop = (a.Y < b.Y) ? b.Y : a.Y; 357 INT intersectRight = (a.GetRight() < b.GetRight()) 358 ? a.GetRight() : b.GetRight(); 359 INT intersectBottom = (a.GetBottom() < b.GetBottom()) 360 ? a.GetBottom() : b.GetBottom(); 361 c.X = intersectLeft; 362 c.Y = intersectTop; 363 c.Width = intersectRight - intersectLeft; 364 c.Height = intersectBottom - intersectTop; 365 return !c.IsEmptyArea(); 366 } 367 BOOL Intersect(const RectF& rect) { 368 return Intersect(*this, *this, rect); 369 } 370 BOOL IntersectsWith(const RectF& rc) const { 371 INT intersectLeft = (X < rc.X) ? rc.X : X; 372 INT intersectTop = (Y < rc.Y) ? rc.Y : Y; 373 INT intersectRight = (GetRight() < rc.GetRight()) 374 ? GetRight() : rc.GetRight(); 375 INT intersectBottom = (GetBottom() < rc.GetBottom()) 376 ? GetBottom() : rc.GetBottom(); 377 return intersectLeft < intersectRight 378 && intersectTop < intersectBottom; 379 } 380 VOID Offset(REAL dx, REAL dy) { 381 X += dx; 382 Y += dy; 383 } 384 VOID Offset(const PointF& point) { 385 Offset(point.X, point.Y); 386 } 387 static BOOL Union(RectF& c, const RectF& a, const RectF& b) { 388 INT unionLeft = (a.X < b.X) ? a.X : b.X; 389 INT unionTop = (a.Y < b.Y) ? a.Y : b.Y; 390 INT unionRight = (a.GetRight() < b.GetRight()) 391 ? b.GetRight() : a.GetRight(); 392 INT unionBottom = (a.GetBottom() < b.GetBottom()) 393 ? b.GetBottom() : a.GetBottom(); 394 c.X = unionLeft; 395 c.Y = unionTop; 396 c.Width = unionRight - unionLeft; 397 c.Height = unionBottom - unionTop; 398 return !c.IsEmptyArea(); 399 } 400 #endif /* __cplusplus */ 401 } RectF; 402 403 /* FIXME: Are descendants of this class, when compiled with g++, 404 binary compatible with MSVC++ code (especially GDIPLUS.DLL of course)? */ 405 #ifdef __cplusplus 406 struct GdiplusAbort { 407 virtual HRESULT __stdcall Abort(void) {} 408 }; 409 #else 410 typedef struct GdiplusAbort GdiplusAbort; /* incomplete type */ 411 #endif 412 413 typedef struct CharacterRange { 414 INT First; 415 INT Length; 416 417 #ifdef __cplusplus 418 CharacterRange(): First(0), Length(0) {} 419 CharacterRange(INT first, INT length): First(first), Length(length) {} 420 CharacterRange& operator=(const CharacterRange& rhs) { 421 /* This gracefully handles self-assignment */ 422 First = rhs.First; 423 Length = rhs.Length; 424 return *this; 425 } 426 #endif /* __cplusplus */ 427 } CharacterRange; 428 429 typedef struct PathData { 430 INT Count; 431 PointF *Points; 432 BYTE *Types; 433 434 #ifdef __cplusplus 435 friend class GraphicsPath; 436 437 PathData(): Count(0), Points(NULL), Types(NULL) {} 438 ~PathData() { 439 FreeArrays(); 440 } 441 private: 442 /* used by GraphicsPath::GetPathData, defined in gdipluspath.h */ 443 Status AllocateArrays(INT capacity); 444 VOID FreeArrays(); 445 #endif /* __cplusplus */ 446 } PathData; 447 448 /* Callback function types */ 449 /* FIXME: need a correct definition for these function pointer types */ 450 typedef void *DebugEventProc; 451 typedef BOOL CALLBACK (*EnumerateMetafileProc)(EmfPlusRecordType,UINT,UINT,const BYTE*,VOID*); 452 typedef void *DrawImageAbort; 453 typedef void *GetThumbnailImageAbort; 454 455 456 #endif /* __GDIPLUS_TYPES_H */ 457