/GdiPlusTypes2.h

https://github.com/snowie2000/mactype · C Header · 770 lines · 574 code · 127 blank · 69 comment · 40 complexity · ab3ad2acee2f7aa5302da15f46f28b57 MD5 · raw file

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * GdiplusTypes.h
  8. *
  9. * Abstract:
  10. *
  11. * GDI+ Types
  12. *
  13. \**************************************************************************/
  14. #ifndef _GDIPLUSTYPES_H
  15. #define _GDIPLUSTYPES_H
  16. //--------------------------------------------------------------------------
  17. // Callback functions
  18. //--------------------------------------------------------------------------
  19. extern "C" {
  20. typedef BOOL (CALLBACK * ImageAbort)(VOID *);
  21. typedef ImageAbort DrawImageAbort;
  22. typedef ImageAbort GetThumbnailImageAbort;
  23. }
  24. // Callback for EnumerateMetafile methods. The parameters are:
  25. // recordType WMF, EMF, or EMF+ record type
  26. // flags (always 0 for WMF/EMF records)
  27. // dataSize size of the record data (in bytes), or 0 if no data
  28. // data pointer to the record data, or NULL if no data
  29. // callbackData pointer to callbackData, if any
  30. // This method can then call Metafile::PlayRecord to play the
  31. // record that was just enumerated. If this method returns
  32. // FALSE, the enumeration process is aborted. Otherwise, it continues.
  33. #if (GDIPVER >= 0x0110)
  34. // This is the main GDI+ Abort interface
  35. struct __declspec(novtable) GdiplusAbort
  36. {
  37. virtual HRESULT __stdcall Abort(void) = 0;
  38. };
  39. #endif //(GDIPVER >= 0x0110)
  40. //--------------------------------------------------------------------------
  41. // Primitive data types
  42. //
  43. // NOTE:
  44. // Types already defined in standard header files:
  45. // INT8
  46. // UINT8
  47. // INT16
  48. // UINT16
  49. // INT32
  50. // UINT32
  51. // INT64
  52. // UINT64
  53. //
  54. // Avoid using the following types:
  55. // LONG - use INT
  56. // ULONG - use UINT
  57. // DWORD - use UINT32
  58. //--------------------------------------------------------------------------
  59. typedef float REAL;
  60. #define REAL_MAX FLT_MAX
  61. #define REAL_MIN FLT_MIN
  62. #define REAL_TOLERANCE (FLT_MIN * 100)
  63. #define REAL_EPSILON 1.192092896e-07F /* FLT_EPSILON */
  64. //--------------------------------------------------------------------------
  65. // Forward declarations of common classes
  66. //--------------------------------------------------------------------------
  67. class Size;
  68. class SizeF;
  69. class Point;
  70. class PointF;
  71. class Rect;
  72. class RectF;
  73. class CharacterRange;
  74. //--------------------------------------------------------------------------
  75. // Status return values from GDI+ methods
  76. //--------------------------------------------------------------------------
  77. enum Status
  78. {
  79. Ok = 0,
  80. GenericError = 1,
  81. InvalidParameter = 2,
  82. OutOfMemory = 3,
  83. ObjectBusy = 4,
  84. InsufficientBuffer = 5,
  85. NotImplemented = 6,
  86. Win32Error = 7,
  87. WrongState = 8,
  88. Aborted = 9,
  89. FileNotFound = 10,
  90. ValueOverflow = 11,
  91. AccessDenied = 12,
  92. UnknownImageFormat = 13,
  93. FontFamilyNotFound = 14,
  94. FontStyleNotFound = 15,
  95. NotTrueTypeFont = 16,
  96. UnsupportedGdiplusVersion = 17,
  97. GdiplusNotInitialized = 18,
  98. PropertyNotFound = 19,
  99. PropertyNotSupported = 20,
  100. #if (GDIPVER >= 0x0110)
  101. ProfileNotFound = 21,
  102. #endif //(GDIPVER >= 0x0110)
  103. };
  104. //--------------------------------------------------------------------------
  105. // Represents a dimension in a 2D coordinate system (floating-point coordinates)
  106. //--------------------------------------------------------------------------
  107. class SizeF
  108. {
  109. public:
  110. SizeF()
  111. {
  112. Width = Height = 0.0f;
  113. }
  114. SizeF(IN const SizeF& size)
  115. {
  116. Width = size.Width;
  117. Height = size.Height;
  118. }
  119. SizeF(IN REAL width,
  120. IN REAL height)
  121. {
  122. Width = width;
  123. Height = height;
  124. }
  125. SizeF operator+(IN const SizeF& sz) const
  126. {
  127. return SizeF(Width + sz.Width,
  128. Height + sz.Height);
  129. }
  130. SizeF operator-(IN const SizeF& sz) const
  131. {
  132. return SizeF(Width - sz.Width,
  133. Height - sz.Height);
  134. }
  135. BOOL Equals(IN const SizeF& sz) const
  136. {
  137. return (Width == sz.Width) && (Height == sz.Height);
  138. }
  139. BOOL Empty() const
  140. {
  141. return (Width == 0.0f && Height == 0.0f);
  142. }
  143. public:
  144. REAL Width;
  145. REAL Height;
  146. };
  147. //--------------------------------------------------------------------------
  148. // Represents a dimension in a 2D coordinate system (integer coordinates)
  149. //--------------------------------------------------------------------------
  150. class Size
  151. {
  152. public:
  153. Size()
  154. {
  155. Width = Height = 0;
  156. }
  157. Size(IN const Size& size)
  158. {
  159. Width = size.Width;
  160. Height = size.Height;
  161. }
  162. Size(IN INT width,
  163. IN INT height)
  164. {
  165. Width = width;
  166. Height = height;
  167. }
  168. Size operator+(IN const Size& sz) const
  169. {
  170. return Size(Width + sz.Width,
  171. Height + sz.Height);
  172. }
  173. Size operator-(IN const Size& sz) const
  174. {
  175. return Size(Width - sz.Width,
  176. Height - sz.Height);
  177. }
  178. BOOL Equals(IN const Size& sz) const
  179. {
  180. return (Width == sz.Width) && (Height == sz.Height);
  181. }
  182. BOOL Empty() const
  183. {
  184. return (Width == 0 && Height == 0);
  185. }
  186. public:
  187. INT Width;
  188. INT Height;
  189. };
  190. //--------------------------------------------------------------------------
  191. // Represents a location in a 2D coordinate system (floating-point coordinates)
  192. //--------------------------------------------------------------------------
  193. class PointF
  194. {
  195. public:
  196. PointF()
  197. {
  198. X = Y = 0.0f;
  199. }
  200. PointF(IN const PointF &point)
  201. {
  202. X = point.X;
  203. Y = point.Y;
  204. }
  205. PointF(IN const SizeF &size)
  206. {
  207. X = size.Width;
  208. Y = size.Height;
  209. }
  210. PointF(IN REAL x,
  211. IN REAL y)
  212. {
  213. X = x;
  214. Y = y;
  215. }
  216. PointF operator+(IN const PointF& point) const
  217. {
  218. return PointF(X + point.X,
  219. Y + point.Y);
  220. }
  221. PointF operator-(IN const PointF& point) const
  222. {
  223. return PointF(X - point.X,
  224. Y - point.Y);
  225. }
  226. BOOL Equals(IN const PointF& point)
  227. {
  228. return (X == point.X) && (Y == point.Y);
  229. }
  230. public:
  231. REAL X;
  232. REAL Y;
  233. };
  234. //--------------------------------------------------------------------------
  235. // Represents a location in a 2D coordinate system (integer coordinates)
  236. //--------------------------------------------------------------------------
  237. class Point
  238. {
  239. public:
  240. Point()
  241. {
  242. X = Y = 0;
  243. }
  244. Point(IN const Point &point)
  245. {
  246. X = point.X;
  247. Y = point.Y;
  248. }
  249. Point(IN const Size &size)
  250. {
  251. X = size.Width;
  252. Y = size.Height;
  253. }
  254. Point(IN INT x,
  255. IN INT y)
  256. {
  257. X = x;
  258. Y = y;
  259. }
  260. Point operator+(IN const Point& point) const
  261. {
  262. return Point(X + point.X,
  263. Y + point.Y);
  264. }
  265. Point operator-(IN const Point& point) const
  266. {
  267. return Point(X - point.X,
  268. Y - point.Y);
  269. }
  270. BOOL Equals(IN const Point& point)
  271. {
  272. return (X == point.X) && (Y == point.Y);
  273. }
  274. public:
  275. INT X;
  276. INT Y;
  277. };
  278. //--------------------------------------------------------------------------
  279. // Represents a rectangle in a 2D coordinate system (floating-point coordinates)
  280. //--------------------------------------------------------------------------
  281. class RectF
  282. {
  283. public:
  284. RectF()
  285. {
  286. X = Y = Width = Height = 0.0f;
  287. }
  288. RectF(IN REAL x,
  289. IN REAL y,
  290. IN REAL width,
  291. IN REAL height)
  292. {
  293. X = x;
  294. Y = y;
  295. Width = width;
  296. Height = height;
  297. }
  298. RectF(IN const PointF& location,
  299. IN const SizeF& size)
  300. {
  301. X = location.X;
  302. Y = location.Y;
  303. Width = size.Width;
  304. Height = size.Height;
  305. }
  306. RectF* Clone() const
  307. {
  308. return new RectF(X, Y, Width, Height);
  309. }
  310. VOID GetLocation(OUT PointF* point) const
  311. {
  312. point->X = X;
  313. point->Y = Y;
  314. }
  315. VOID GetSize(OUT SizeF* size) const
  316. {
  317. size->Width = Width;
  318. size->Height = Height;
  319. }
  320. VOID GetBounds(OUT RectF* rect) const
  321. {
  322. rect->X = X;
  323. rect->Y = Y;
  324. rect->Width = Width;
  325. rect->Height = Height;
  326. }
  327. REAL GetLeft() const
  328. {
  329. return X;
  330. }
  331. REAL GetTop() const
  332. {
  333. return Y;
  334. }
  335. REAL GetRight() const
  336. {
  337. return X+Width;
  338. }
  339. REAL GetBottom() const
  340. {
  341. return Y+Height;
  342. }
  343. BOOL IsEmptyArea() const
  344. {
  345. return (Width <= REAL_EPSILON) || (Height <= REAL_EPSILON);
  346. }
  347. BOOL Equals(IN const RectF & rect) const
  348. {
  349. return X == rect.X &&
  350. Y == rect.Y &&
  351. Width == rect.Width &&
  352. Height == rect.Height;
  353. }
  354. BOOL Contains(IN REAL x,
  355. IN REAL y) const
  356. {
  357. return x >= X && x < X+Width &&
  358. y >= Y && y < Y+Height;
  359. }
  360. BOOL Contains(IN const PointF& pt) const
  361. {
  362. return Contains(pt.X, pt.Y);
  363. }
  364. BOOL Contains(IN const RectF& rect) const
  365. {
  366. return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
  367. (Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
  368. }
  369. VOID Inflate(IN REAL dx,
  370. IN REAL dy)
  371. {
  372. X -= dx;
  373. Y -= dy;
  374. Width += 2*dx;
  375. Height += 2*dy;
  376. }
  377. VOID Inflate(IN const PointF& point)
  378. {
  379. Inflate(point.X, point.Y);
  380. }
  381. BOOL Intersect(IN const RectF& rect)
  382. {
  383. return Intersect(*this, *this, rect);
  384. }
  385. static BOOL Intersect(OUT RectF& c,
  386. IN const RectF& a,
  387. IN const RectF& b)
  388. {
  389. REAL right = min(a.GetRight(), b.GetRight());
  390. REAL bottom = min(a.GetBottom(), b.GetBottom());
  391. REAL left = max(a.GetLeft(), b.GetLeft());
  392. REAL top = max(a.GetTop(), b.GetTop());
  393. c.X = left;
  394. c.Y = top;
  395. c.Width = right - left;
  396. c.Height = bottom - top;
  397. return !c.IsEmptyArea();
  398. }
  399. BOOL IntersectsWith(IN const RectF& rect) const
  400. {
  401. return (GetLeft() < rect.GetRight() &&
  402. GetTop() < rect.GetBottom() &&
  403. GetRight() > rect.GetLeft() &&
  404. GetBottom() > rect.GetTop());
  405. }
  406. static BOOL Union(OUT RectF& c,
  407. IN const RectF& a,
  408. IN const RectF& b)
  409. {
  410. REAL right = max(a.GetRight(), b.GetRight());
  411. REAL bottom = max(a.GetBottom(), b.GetBottom());
  412. REAL left = min(a.GetLeft(), b.GetLeft());
  413. REAL top = min(a.GetTop(), b.GetTop());
  414. c.X = left;
  415. c.Y = top;
  416. c.Width = right - left;
  417. c.Height = bottom - top;
  418. return !c.IsEmptyArea();
  419. }
  420. VOID Offset(IN const PointF& point)
  421. {
  422. Offset(point.X, point.Y);
  423. }
  424. VOID Offset(IN REAL dx,
  425. IN REAL dy)
  426. {
  427. X += dx;
  428. Y += dy;
  429. }
  430. public:
  431. REAL X;
  432. REAL Y;
  433. REAL Width;
  434. REAL Height;
  435. };
  436. //--------------------------------------------------------------------------
  437. // Represents a rectangle in a 2D coordinate system (integer coordinates)
  438. //--------------------------------------------------------------------------
  439. class Rect
  440. {
  441. public:
  442. Rect()
  443. {
  444. X = Y = Width = Height = 0;
  445. }
  446. Rect(IN INT x,
  447. IN INT y,
  448. IN INT width,
  449. IN INT height)
  450. {
  451. X = x;
  452. Y = y;
  453. Width = width;
  454. Height = height;
  455. }
  456. Rect(IN const Point& location,
  457. IN const Size& size)
  458. {
  459. X = location.X;
  460. Y = location.Y;
  461. Width = size.Width;
  462. Height = size.Height;
  463. }
  464. Rect* Clone() const
  465. {
  466. return new Rect(X, Y, Width, Height);
  467. }
  468. VOID GetLocation(OUT Point* point) const
  469. {
  470. point->X = X;
  471. point->Y = Y;
  472. }
  473. VOID GetSize(OUT Size* size) const
  474. {
  475. size->Width = Width;
  476. size->Height = Height;
  477. }
  478. VOID GetBounds(OUT Rect* rect) const
  479. {
  480. rect->X = X;
  481. rect->Y = Y;
  482. rect->Width = Width;
  483. rect->Height = Height;
  484. }
  485. INT GetLeft() const
  486. {
  487. return X;
  488. }
  489. INT GetTop() const
  490. {
  491. return Y;
  492. }
  493. INT GetRight() const
  494. {
  495. return X+Width;
  496. }
  497. INT GetBottom() const
  498. {
  499. return Y+Height;
  500. }
  501. BOOL IsEmptyArea() const
  502. {
  503. return (Width <= 0) || (Height <= 0);
  504. }
  505. BOOL Equals(IN const Rect & rect) const
  506. {
  507. return X == rect.X &&
  508. Y == rect.Y &&
  509. Width == rect.Width &&
  510. Height == rect.Height;
  511. }
  512. BOOL Contains(IN INT x,
  513. IN INT y) const
  514. {
  515. return x >= X && x < X+Width &&
  516. y >= Y && y < Y+Height;
  517. }
  518. BOOL Contains(IN const Point& pt) const
  519. {
  520. return Contains(pt.X, pt.Y);
  521. }
  522. BOOL Contains(IN Rect& rect) const
  523. {
  524. return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
  525. (Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
  526. }
  527. VOID Inflate(IN INT dx,
  528. IN INT dy)
  529. {
  530. X -= dx;
  531. Y -= dy;
  532. Width += 2*dx;
  533. Height += 2*dy;
  534. }
  535. VOID Inflate(IN const Point& point)
  536. {
  537. Inflate(point.X, point.Y);
  538. }
  539. BOOL Intersect(IN const Rect& rect)
  540. {
  541. return Intersect(*this, *this, rect);
  542. }
  543. static BOOL Intersect(OUT Rect& c,
  544. IN const Rect& a,
  545. IN const Rect& b)
  546. {
  547. INT right = min(a.GetRight(), b.GetRight());
  548. INT bottom = min(a.GetBottom(), b.GetBottom());
  549. INT left = max(a.GetLeft(), b.GetLeft());
  550. INT top = max(a.GetTop(), b.GetTop());
  551. c.X = left;
  552. c.Y = top;
  553. c.Width = right - left;
  554. c.Height = bottom - top;
  555. return !c.IsEmptyArea();
  556. }
  557. BOOL IntersectsWith(IN const Rect& rect) const
  558. {
  559. return (GetLeft() < rect.GetRight() &&
  560. GetTop() < rect.GetBottom() &&
  561. GetRight() > rect.GetLeft() &&
  562. GetBottom() > rect.GetTop());
  563. }
  564. static BOOL Union(OUT Rect& c,
  565. IN const Rect& a,
  566. IN const Rect& b)
  567. {
  568. INT right = max(a.GetRight(), b.GetRight());
  569. INT bottom = max(a.GetBottom(), b.GetBottom());
  570. INT left = min(a.GetLeft(), b.GetLeft());
  571. INT top = min(a.GetTop(), b.GetTop());
  572. c.X = left;
  573. c.Y = top;
  574. c.Width = right - left;
  575. c.Height = bottom - top;
  576. return !c.IsEmptyArea();
  577. }
  578. VOID Offset(IN const Point& point)
  579. {
  580. Offset(point.X, point.Y);
  581. }
  582. VOID Offset(IN INT dx,
  583. IN INT dy)
  584. {
  585. X += dx;
  586. Y += dy;
  587. }
  588. public:
  589. INT X;
  590. INT Y;
  591. INT Width;
  592. INT Height;
  593. };
  594. class PathData
  595. {
  596. public:
  597. PathData()
  598. {
  599. Count = 0;
  600. Points = NULL;
  601. Types = NULL;
  602. }
  603. ~PathData()
  604. {
  605. if (Points != NULL)
  606. {
  607. delete [] Points;
  608. }
  609. if (Types != NULL)
  610. {
  611. delete [] Types;
  612. }
  613. }
  614. private:
  615. PathData(const PathData &);
  616. PathData& operator=(const PathData &);
  617. public:
  618. INT Count;
  619. PointF* Points;
  620. __field_ecount_opt(Count) BYTE* Types;
  621. };
  622. class CharacterRange
  623. {
  624. public:
  625. CharacterRange(
  626. INT first,
  627. INT length
  628. ) :
  629. First (first),
  630. Length (length)
  631. {}
  632. CharacterRange() : First(0), Length(0)
  633. {}
  634. CharacterRange & operator = (const CharacterRange &rhs)
  635. {
  636. First = rhs.First;
  637. Length = rhs.Length;
  638. return *this;
  639. }
  640. INT First;
  641. INT Length;
  642. };
  643. #endif // !_GDIPLUSTYPES_HPP