GdiPlusTypes.h 17 KB

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