1 /* 2 * Copyright (C) 2007 Google (Evan Stade) 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19 #ifndef _GDIPLUSTYPES_H 20 #define _GDIPLUSTYPES_H 21 22 typedef float REAL; 23 24 enum Status 25 { 26 Ok = 0, 27 GenericError = 1, 28 InvalidParameter = 2, 29 OutOfMemory = 3, 30 ObjectBusy = 4, 31 InsufficientBuffer = 5, 32 NotImplemented = 6, 33 Win32Error = 7, 34 WrongState = 8, 35 Aborted = 9, 36 FileNotFound = 10, 37 ValueOverflow = 11, 38 AccessDenied = 12, 39 UnknownImageFormat = 13, 40 FontFamilyNotFound = 14, 41 FontStyleNotFound = 15, 42 NotTrueTypeFont = 16, 43 UnsupportedGdiplusVersion = 17, 44 GdiplusNotInitialized = 18, 45 PropertyNotFound = 19, 46 PropertyNotSupported = 20, 47 ProfileNotFound = 21 48 }; 49 50 #ifdef __cplusplus 51 extern "C" 52 { 53 #endif 54 55 typedef BOOL(CALLBACK *ImageAbort)(VOID *); 56 typedef ImageAbort DrawImageAbort; 57 typedef ImageAbort GetThumbnailImageAbort; 58 typedef struct GdiplusAbort GdiplusAbort; 59 60 typedef BOOL(CALLBACK *EnumerateMetafileProc)(EmfPlusRecordType, UINT, UINT, const BYTE *, VOID *); 61 62 #ifdef __cplusplus 63 } 64 #endif 65 66 #ifdef __cplusplus 67 68 class Size; 69 70 class Point 71 { 72 public: 73 Point() 74 { 75 X = Y = 0; 76 } 77 78 Point(IN const Point &pt) 79 { 80 X = pt.X; 81 Y = pt.Y; 82 } 83 84 Point(const Size &size); 85 86 Point(IN INT x, IN INT y) 87 { 88 X = x; 89 Y = y; 90 } 91 92 Point 93 operator+(IN const Point &pt) const 94 { 95 return Point(X + pt.X, Y + pt.Y); 96 } 97 98 Point 99 operator-(IN const Point &pt) const 100 { 101 return Point(X - pt.X, Y - pt.Y); 102 } 103 104 BOOL 105 Equals(IN const Point &pt) const 106 { 107 return (X == pt.X) && (Y == pt.Y); 108 } 109 110 public: 111 INT X; 112 INT Y; 113 }; 114 115 class SizeF; 116 117 class PointF 118 { 119 public: 120 PointF() 121 { 122 X = Y = 0.0f; 123 } 124 125 PointF(IN const PointF &pt) 126 { 127 X = pt.X; 128 Y = pt.Y; 129 } 130 131 PointF(const SizeF &size); 132 133 PointF(IN REAL x, IN REAL y) 134 { 135 X = x; 136 Y = y; 137 } 138 139 PointF 140 operator+(IN const PointF &pt) const 141 { 142 return PointF(X + pt.X, Y + pt.Y); 143 } 144 145 PointF 146 operator-(IN const PointF &pt) const 147 { 148 return PointF(X - pt.X, Y - pt.Y); 149 } 150 151 BOOL 152 Equals(IN const PointF &pt) const 153 { 154 return (X == pt.X) && (Y == pt.Y); 155 } 156 157 public: 158 REAL X; 159 REAL Y; 160 }; 161 162 class PathData 163 { 164 public: 165 PathData() 166 { 167 Count = 0; 168 Points = NULL; 169 Types = NULL; 170 } 171 172 ~PathData() 173 { 174 if (Points != NULL) 175 { 176 delete Points; 177 } 178 179 if (Types != NULL) 180 { 181 delete Types; 182 } 183 } 184 185 private: 186 PathData(const PathData &); 187 PathData & 188 operator=(const PathData &); 189 190 public: 191 INT Count; 192 PointF *Points; 193 BYTE *Types; 194 }; 195 196 class SizeF 197 { 198 public: 199 REAL Width; 200 REAL Height; 201 202 SizeF() : Width(0), Height(0) 203 { 204 } 205 206 SizeF(const SizeF &size) : Width(size.Width), Height(size.Height) 207 { 208 } 209 210 SizeF(REAL width, REAL height) : Width(width), Height(height) 211 { 212 } 213 214 BOOL 215 Empty() const 216 { 217 return Width == 0 && Height == 0; 218 } 219 220 BOOL 221 Equals(const SizeF &sz) const 222 { 223 return Width == sz.Width && Height == sz.Height; 224 } 225 226 SizeF 227 operator+(const SizeF &sz) const 228 { 229 return SizeF(Width + sz.Width, Height + sz.Height); 230 } 231 232 SizeF 233 operator-(const SizeF &sz) const 234 { 235 return SizeF(Width - sz.Width, Height - sz.Height); 236 } 237 }; 238 239 #define REAL_EPSILON 1.192092896e-07F /* FLT_EPSILON */ 240 241 class RectF 242 { 243 public: 244 REAL X; 245 REAL Y; 246 REAL Width; 247 REAL Height; 248 249 RectF() : X(0), Y(0), Width(0), Height(0) 250 { 251 } 252 253 RectF(const PointF &location, const SizeF &size) 254 : X(location.X), Y(location.Y), Width(size.Width), Height(size.Height) 255 { 256 } 257 258 RectF(REAL x, REAL y, REAL width, REAL height) : X(x), Y(y), Width(width), Height(height) 259 { 260 } 261 262 RectF * 263 Clone() const 264 { 265 return new RectF(X, Y, Width, Height); 266 } 267 268 BOOL 269 Contains(const PointF &pt) const 270 { 271 return Contains(pt.X, pt.Y); 272 } 273 274 BOOL 275 Contains(const RectF &rect) const 276 { 277 return X <= rect.X && rect.GetRight() <= GetRight() && Y <= rect.Y && rect.GetBottom() <= GetBottom(); 278 } 279 280 BOOL 281 Contains(REAL x, REAL y) const 282 { 283 return X <= x && x < X + Width && Y <= y && y < Y + Height; 284 } 285 286 BOOL 287 Equals(const RectF &rect) const 288 { 289 return X == rect.X && Y == rect.Y && Width == rect.Width && Height == rect.Height; 290 } 291 292 REAL 293 GetBottom() const 294 { 295 return Y + Height; 296 } 297 298 VOID 299 GetBounds(RectF *rect) const 300 { 301 rect->X = X; 302 rect->Y = Y; 303 rect->Width = Width; 304 rect->Height = Height; 305 } 306 307 REAL 308 GetLeft() const 309 { 310 return X; 311 } 312 313 VOID 314 GetLocation(PointF *point) const 315 { 316 point->X = X; 317 point->Y = Y; 318 } 319 320 REAL 321 GetRight() const 322 { 323 return X + Width; 324 } 325 326 VOID 327 GetSize(SizeF *size) const 328 { 329 size->Width = Width; 330 size->Height = Height; 331 } 332 333 REAL 334 GetTop() const 335 { 336 return Y; 337 } 338 339 VOID 340 Inflate(REAL dx, REAL dy) 341 { 342 X -= dx; 343 Y -= dy; 344 Width += 2 * dx; 345 Height += 2 * dy; 346 } 347 348 VOID 349 Inflate(const PointF &point) 350 { 351 Inflate(point.X, point.Y); 352 } 353 354 static BOOL 355 Intersect(RectF &c, const RectF &a, const RectF &b) 356 { 357 // FIXME 358 return FALSE; 359 } 360 361 BOOL 362 Intersect(const RectF &rect) 363 { 364 return Intersect(*this, *this, rect); 365 } 366 367 BOOL 368 IntersectsWith(const RectF &rect) const 369 { 370 return GetLeft() < rect.GetRight() && GetTop() < rect.GetTop() && GetRight() > rect.GetLeft() && 371 GetBottom() > rect.GetTop(); 372 } 373 374 BOOL 375 IsEmptyArea() const 376 { 377 return (Width <= REAL_EPSILON) || (Height <= REAL_EPSILON); 378 } 379 380 VOID 381 Offset(REAL dx, REAL dy) 382 { 383 X += dx; 384 Y += dy; 385 } 386 387 VOID 388 Offset(const PointF &point) 389 { 390 Offset(point.X, point.Y); 391 } 392 393 static BOOL 394 Union(RectF &c, const RectF &a, const RectF &b) 395 { 396 // FIXME 397 return FALSE; 398 } 399 }; 400 401 class Size 402 { 403 public: 404 INT Width; 405 INT Height; 406 407 Size() : Width(0), Height(0) 408 { 409 } 410 411 Size(const Size &size) : Width(size.Width), Height(size.Height) 412 { 413 } 414 415 Size(INT width, INT height) : Width(width), Height(height) 416 { 417 } 418 419 BOOL 420 Empty() const 421 { 422 return Width == 0 && Height == 0; 423 } 424 425 BOOL 426 Equals(const Size &sz) const 427 { 428 return Width == sz.Width && Height == sz.Height; 429 } 430 431 Size 432 operator+(const Size &sz) const 433 { 434 return Size(Width + sz.Width, Height + sz.Height); 435 } 436 437 Size 438 operator-(const Size &sz) const 439 { 440 return Size(Width - sz.Width, Height - sz.Height); 441 } 442 }; 443 444 class Rect 445 { 446 public: 447 INT X; 448 INT Y; 449 INT Width; 450 INT Height; 451 452 Rect() : X(0), Y(0), Width(0), Height(0) 453 { 454 } 455 456 Rect(const Point &location, const Size &size) : X(location.X), Y(location.Y), Width(size.Width), Height(size.Height) 457 { 458 } 459 460 Rect(INT x, INT y, INT width, INT height) : X(x), Y(y), Width(width), Height(height) 461 { 462 } 463 464 Rect * 465 Clone() const 466 { 467 return new Rect(X, Y, Width, Height); 468 } 469 470 BOOL 471 Contains(const Point &pt) const 472 { 473 return Contains(pt.X, pt.Y); 474 } 475 476 BOOL 477 Contains(const Rect &rect) const 478 { 479 return X <= rect.X && rect.GetRight() <= GetRight() && Y <= rect.Y && rect.GetBottom() <= GetBottom(); 480 } 481 482 BOOL 483 Contains(INT x, INT y) const 484 { 485 return X <= x && x < X + Width && Y <= y && y < Y + Height; 486 } 487 488 BOOL 489 Equals(const Rect &rect) const 490 { 491 return X == rect.X && Y == rect.Y && Width == rect.Width && Height == rect.Height; 492 } 493 494 INT 495 GetBottom() const 496 { 497 return Y + Height; 498 } 499 500 VOID 501 GetBounds(Rect *rect) const 502 { 503 rect->X = X; 504 rect->Y = Y; 505 rect->Width = Width; 506 rect->Height = Height; 507 } 508 509 INT 510 GetLeft() const 511 { 512 return X; 513 } 514 515 VOID 516 GetLocation(Point *point) const 517 { 518 point->X = X; 519 point->Y = Y; 520 } 521 522 INT 523 GetRight() const 524 { 525 return X + Width; 526 } 527 528 VOID 529 GetSize(Size *size) const 530 { 531 size->Width = Width; 532 size->Height = Height; 533 } 534 535 INT 536 GetTop() const 537 { 538 return Y; 539 } 540 541 VOID 542 Inflate(INT dx, INT dy) 543 { 544 X -= dx; 545 Y -= dy; 546 Width += 2 * dx; 547 Height += 2 * dy; 548 } 549 550 VOID 551 Inflate(const Point &point) 552 { 553 Inflate(point.X, point.Y); 554 } 555 556 static BOOL 557 Intersect(Rect &c, const Rect &a, const Rect &b) 558 { 559 // FIXME 560 return FALSE; 561 } 562 563 BOOL 564 Intersect(const Rect &rect) 565 { 566 return Intersect(*this, *this, rect); 567 } 568 569 BOOL 570 IntersectsWith(const Rect &rect) const 571 { 572 return GetLeft() < rect.GetRight() && GetTop() < rect.GetTop() && GetRight() > rect.GetLeft() && 573 GetBottom() > rect.GetTop(); 574 } 575 576 BOOL 577 IsEmptyArea() const 578 { 579 return Width <= 0 || Height <= 0; 580 } 581 582 VOID 583 Offset(INT dx, INT dy) 584 { 585 X += dx; 586 Y += dy; 587 } 588 589 VOID 590 Offset(const Point &point) 591 { 592 Offset(point.X, point.Y); 593 } 594 595 static BOOL 596 Union(Rect &c, const Rect &a, const Rect &b) 597 { 598 // FIXME 599 return FALSE; 600 } 601 }; 602 603 class CharacterRange 604 { 605 public: 606 CharacterRange() 607 { 608 First = Length = 0; 609 } 610 611 CharacterRange(INT first, INT length) 612 { 613 First = first; 614 Length = length; 615 } 616 617 CharacterRange & 618 operator=(const CharacterRange &rhs) 619 { 620 First = rhs.First; 621 Length = rhs.Length; 622 return *this; 623 } 624 625 public: 626 INT First; 627 INT Length; 628 }; 629 630 inline Point::Point(const Size &size) : X(size.Width), Y(size.Height) 631 { 632 } 633 634 inline PointF::PointF(const SizeF &size) : X(size.Width), Y(size.Height) 635 { 636 } 637 638 #else /* end of c++ typedefs */ 639 640 typedef struct Point 641 { 642 INT X; 643 INT Y; 644 } Point; 645 646 typedef struct PointF 647 { 648 REAL X; 649 REAL Y; 650 } PointF; 651 652 typedef struct PathData 653 { 654 INT Count; 655 PointF *Points; 656 BYTE *Types; 657 } PathData; 658 659 typedef struct RectF 660 { 661 REAL X; 662 REAL Y; 663 REAL Width; 664 REAL Height; 665 } RectF; 666 667 typedef struct Rect 668 { 669 INT X; 670 INT Y; 671 INT Width; 672 INT Height; 673 } Rect; 674 675 typedef struct CharacterRange 676 { 677 INT First; 678 INT Length; 679 } CharacterRange; 680 681 typedef enum Status Status; 682 683 #endif /* end of c typedefs */ 684 685 #endif 686