Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

671 lines
18 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * GdiplusHeaders.h
  8. *
  9. * Abstract:
  10. *
  11. * GDI+ Region, Font, Image, CustomLineCap class definitions.
  12. *
  13. *
  14. * Class definition and inline class implementation are separated into
  15. * different files to avoid circular dependencies.
  16. *
  17. \**************************************************************************/
  18. #ifndef _GDIPLUSHEADERS_H
  19. #define _GDIPLUSHEADERS_H
  20. class Region : public GdiplusBase
  21. {
  22. public:
  23. friend class Graphics;
  24. Region();
  25. Region(IN const RectF& rect);
  26. Region(IN const Rect& rect);
  27. Region(IN const GraphicsPath* path);
  28. Region(IN const BYTE* regionData, IN INT size);
  29. Region(IN HRGN hRgn);
  30. static Region* FromHRGN(IN HRGN hRgn);
  31. ~Region();
  32. Region* Clone() const;
  33. Status MakeInfinite();
  34. Status MakeEmpty();
  35. UINT GetDataSize() const;
  36. // buffer - where to put the data
  37. // bufferSize - how big the buffer is (should be at least as big as GetDataSize())
  38. // sizeFilled - if not NULL, this is an OUT param that says how many bytes
  39. // of data were written to the buffer.
  40. Status GetData(OUT BYTE* buffer,
  41. IN UINT bufferSize,
  42. OUT UINT* sizeFilled = NULL) const;
  43. Status Intersect(IN const Rect& rect);
  44. Status Intersect(IN const RectF& rect);
  45. Status Intersect(IN const GraphicsPath* path);
  46. Status Intersect(IN const Region* region);
  47. Status Union(IN const Rect& rect);
  48. Status Union(IN const RectF& rect);
  49. Status Union(IN const GraphicsPath* path);
  50. Status Union(IN const Region* region);
  51. Status Xor(IN const Rect& rect);
  52. Status Xor(IN const RectF& rect);
  53. Status Xor(IN const GraphicsPath* path);
  54. Status Xor(IN const Region* region);
  55. Status Exclude(IN const Rect& rect);
  56. Status Exclude(IN const RectF& rect);
  57. Status Exclude(IN const GraphicsPath* path);
  58. Status Exclude(IN const Region* region);
  59. Status Complement(IN const Rect& rect);
  60. Status Complement(IN const RectF& rect);
  61. Status Complement(IN const GraphicsPath* path);
  62. Status Complement(IN const Region* region);
  63. Status Translate(IN REAL dx,
  64. IN REAL dy);
  65. Status Translate(IN INT dx,
  66. IN INT dy);
  67. Status Transform(IN const Matrix* matrix);
  68. Status GetBounds(OUT Rect* rect,
  69. IN const Graphics* g) const;
  70. Status GetBounds(OUT RectF* rect,
  71. IN const Graphics* g) const;
  72. HRGN GetHRGN (IN const Graphics * g) const;
  73. BOOL IsEmpty(IN const Graphics *g) const;
  74. BOOL IsInfinite(IN const Graphics *g) const;
  75. BOOL IsVisible(IN INT x,
  76. IN INT y,
  77. IN const Graphics* g = NULL) const
  78. {
  79. return IsVisible(Point(x, y), g);
  80. }
  81. BOOL IsVisible(IN const Point& point,
  82. IN const Graphics* g = NULL) const;
  83. BOOL IsVisible(IN REAL x,
  84. IN REAL y,
  85. IN const Graphics* g = NULL) const
  86. {
  87. return IsVisible(PointF(x, y), g);
  88. }
  89. BOOL IsVisible(IN const PointF& point,
  90. IN const Graphics* g = NULL) const;
  91. BOOL IsVisible(IN INT x,
  92. IN INT y,
  93. IN INT width,
  94. IN INT height,
  95. IN const Graphics* g) const
  96. {
  97. return IsVisible(Rect(x, y, width, height), g);
  98. }
  99. BOOL IsVisible(IN const Rect& rect,
  100. IN const Graphics* g = NULL) const;
  101. BOOL IsVisible(IN REAL x,
  102. IN REAL y,
  103. IN REAL width,
  104. IN REAL height,
  105. IN const Graphics* g = NULL) const
  106. {
  107. return IsVisible(RectF(x, y, width, height), g);
  108. }
  109. BOOL IsVisible(IN const RectF& rect,
  110. IN const Graphics* g = NULL) const;
  111. BOOL Equals(IN const Region* region,
  112. IN const Graphics* g) const;
  113. UINT GetRegionScansCount(IN const Matrix* matrix) const;
  114. Status GetRegionScans(IN const Matrix* matrix,
  115. OUT RectF* rects,
  116. OUT INT* count) const;
  117. Status GetRegionScans(IN const Matrix* matrix,
  118. OUT Rect* rects,
  119. OUT INT* count) const;
  120. Status GetLastStatus() const;
  121. protected:
  122. private:
  123. Region(const Region &region);
  124. Region& operator=(const Region &region);
  125. protected:
  126. Status SetStatus(Status status) const
  127. {
  128. if (status != Ok)
  129. return (lastResult = status);
  130. else
  131. return status;
  132. }
  133. Region(GpRegion* nativeRegion);
  134. VOID SetNativeRegion(GpRegion* nativeRegion);
  135. protected:
  136. GpRegion* nativeRegion;
  137. mutable Status lastResult;
  138. };
  139. //--------------------------------------------------------------------------
  140. // FontFamily
  141. //--------------------------------------------------------------------------
  142. class FontFamily : public GdiplusBase
  143. {
  144. public:
  145. friend class Font;
  146. friend class Graphics;
  147. friend class GraphicsPath;
  148. friend class FontCollection;
  149. FontFamily();
  150. FontFamily(
  151. IN const WCHAR *name,
  152. IN const FontCollection *fontCollection = NULL
  153. );
  154. ~FontFamily();
  155. static const FontFamily *GenericSansSerif();
  156. static const FontFamily *GenericSerif();
  157. static const FontFamily *GenericMonospace();
  158. Status GetFamilyName(
  159. OUT WCHAR name[LF_FACESIZE],
  160. IN LANGID language = 0
  161. ) const;
  162. FontFamily * Clone() const;
  163. BOOL IsAvailable() const
  164. {
  165. return (nativeFamily != NULL);
  166. };
  167. BOOL IsStyleAvailable(IN INT style) const;
  168. UINT16 GetEmHeight (IN INT style) const;
  169. UINT16 GetCellAscent (IN INT style) const;
  170. UINT16 GetCellDescent (IN INT style) const;
  171. UINT16 GetLineSpacing (IN INT style) const;
  172. Status GetLastStatus() const;
  173. private:
  174. FontFamily(const FontFamily &);
  175. FontFamily& operator=(const FontFamily &);
  176. protected:
  177. Status SetStatus(Status status) const;
  178. FontFamily(GpFontFamily * nativeFamily, Status status);
  179. protected:
  180. GpFontFamily *nativeFamily;
  181. mutable Status lastResult;
  182. };
  183. static FontFamily *GenericSansSerifFontFamily = NULL;
  184. static FontFamily *GenericSerifFontFamily = NULL;
  185. static FontFamily *GenericMonospaceFontFamily = NULL;
  186. static BYTE GenericSansSerifFontFamilyBuffer[sizeof(FontFamily)] = {0};
  187. static BYTE GenericSerifFontFamilyBuffer [sizeof(FontFamily)] = {0};
  188. static BYTE GenericMonospaceFontFamilyBuffer[sizeof(FontFamily)] = {0};
  189. //--------------------------------------------------------------------------
  190. // Font
  191. //--------------------------------------------------------------------------
  192. class Font : public GdiplusBase
  193. {
  194. public:
  195. friend class Graphics;
  196. Font(IN HDC hdc);
  197. Font(IN HDC hdc,
  198. IN const LOGFONTA* logfont);
  199. Font(IN HDC hdc,
  200. IN const LOGFONTW* logfont);
  201. Font(IN HDC hdc,
  202. IN const HFONT hfont);
  203. Font(
  204. IN const FontFamily * family,
  205. IN REAL emSize,
  206. IN INT style = FontStyleRegular,
  207. IN Unit unit = UnitPoint
  208. );
  209. Font(
  210. IN const WCHAR * familyName,
  211. IN REAL emSize,
  212. IN INT style = FontStyleRegular,
  213. IN Unit unit = UnitPoint,
  214. IN const FontCollection * fontCollection = NULL
  215. );
  216. Status GetLogFontA(IN const Graphics* g,
  217. OUT LOGFONTA * logfontA) const;
  218. Status GetLogFontW(IN const Graphics* g,
  219. OUT LOGFONTW * logfontW) const;
  220. Font* Clone() const;
  221. ~Font();
  222. BOOL IsAvailable() const;
  223. INT GetStyle() const;
  224. REAL GetSize() const;
  225. Unit GetUnit() const;
  226. Status GetLastStatus() const;
  227. REAL GetHeight(IN const Graphics *graphics) const;
  228. REAL GetHeight(IN REAL dpi) const;
  229. Status GetFamily(OUT FontFamily *family) const;
  230. private:
  231. Font(const Font &);
  232. Font& operator=(const Font &);
  233. protected:
  234. Font(GpFont* font, Status status);
  235. VOID SetNativeFont(GpFont *Font);
  236. Status SetStatus(Status status) const;
  237. protected:
  238. GpFont* nativeFont;
  239. mutable Status lastResult;
  240. };
  241. //--------------------------------------------------------------------------
  242. // Font Collection
  243. //--------------------------------------------------------------------------
  244. class FontCollection : public GdiplusBase
  245. {
  246. public:
  247. friend class FontFamily;
  248. FontCollection();
  249. virtual ~FontCollection();
  250. INT GetFamilyCount() const;
  251. Status GetFamilies(
  252. IN INT numSought,
  253. OUT FontFamily * gpfamilies,
  254. OUT INT * numFound
  255. ) const;
  256. Status GetLastStatus() const;
  257. private:
  258. FontCollection(const FontCollection &);
  259. FontCollection& operator=(const FontCollection &);
  260. protected:
  261. Status SetStatus(Status status) const ;
  262. GpFontCollection *nativeFontCollection;
  263. mutable Status lastResult;
  264. };
  265. class InstalledFontCollection : public FontCollection
  266. {
  267. public:
  268. InstalledFontCollection();
  269. ~InstalledFontCollection();
  270. private:
  271. InstalledFontCollection(const InstalledFontCollection &);
  272. InstalledFontCollection& operator=(const InstalledFontCollection &);
  273. protected:
  274. Status SetStatus(Status status) const ;
  275. };
  276. class PrivateFontCollection : public FontCollection
  277. {
  278. public:
  279. PrivateFontCollection();
  280. ~PrivateFontCollection();
  281. Status AddFontFile(IN const WCHAR* filename);
  282. Status AddMemoryFont(IN const VOID* memory,
  283. IN INT length);
  284. private:
  285. PrivateFontCollection(const PrivateFontCollection &);
  286. PrivateFontCollection& operator=(const PrivateFontCollection &);
  287. };
  288. //--------------------------------------------------------------------------
  289. // Abstract base class for Image and Metafile
  290. //--------------------------------------------------------------------------
  291. class Image : public GdiplusBase
  292. {
  293. public:
  294. friend class Brush;
  295. friend class TextureBrush;
  296. friend class Graphics;
  297. Image(
  298. IN const WCHAR* filename,
  299. IN BOOL useEmbeddedColorManagement = FALSE
  300. );
  301. Image(
  302. IN IStream* stream,
  303. IN BOOL useEmbeddedColorManagement = FALSE
  304. );
  305. static Image* FromFile(
  306. IN const WCHAR* filename,
  307. IN BOOL useEmbeddedColorManagement = FALSE
  308. );
  309. static Image* FromStream(
  310. IN IStream* stream,
  311. IN BOOL useEmbeddedColorManagement = FALSE
  312. );
  313. virtual ~Image();
  314. virtual Image* Clone();
  315. Status Save(IN const WCHAR* filename,
  316. IN const CLSID* clsidEncoder,
  317. IN const EncoderParameters *encoderParams = NULL);
  318. Status Save(IN IStream* stream,
  319. IN const CLSID* clsidEncoder,
  320. IN const EncoderParameters *encoderParams = NULL);
  321. Status SaveAdd(IN const EncoderParameters* encoderParams);
  322. Status SaveAdd(IN Image* newImage,
  323. IN const EncoderParameters* encoderParams);
  324. ImageType GetType() const;
  325. Status GetPhysicalDimension(OUT SizeF* size);
  326. Status GetBounds(OUT RectF* srcRect,
  327. OUT Unit* srcUnit);
  328. UINT GetWidth();
  329. UINT GetHeight();
  330. REAL GetHorizontalResolution();
  331. REAL GetVerticalResolution();
  332. UINT GetFlags();
  333. Status GetRawFormat(OUT GUID *format);
  334. PixelFormat GetPixelFormat();
  335. INT GetPaletteSize();
  336. Status GetPalette(OUT ColorPalette* palette,
  337. IN INT size);
  338. Status SetPalette(IN const ColorPalette* palette);
  339. Image* GetThumbnailImage(IN UINT thumbWidth,
  340. IN UINT thumbHeight,
  341. IN GetThumbnailImageAbort callback = NULL,
  342. IN VOID* callbackData = NULL);
  343. UINT GetFrameDimensionsCount();
  344. Status GetFrameDimensionsList(OUT GUID* dimensionIDs,
  345. IN UINT count);
  346. UINT GetFrameCount(IN const GUID* dimensionID);
  347. Status SelectActiveFrame(IN const GUID* dimensionID,
  348. IN UINT frameIndex);
  349. Status RotateFlip(IN RotateFlipType rotateFlipType);
  350. UINT GetPropertyCount();
  351. Status GetPropertyIdList(IN UINT numOfProperty,
  352. OUT PROPID* list);
  353. UINT GetPropertyItemSize(IN PROPID propId);
  354. Status GetPropertyItem(IN PROPID propId,
  355. IN UINT propSize,
  356. OUT PropertyItem* buffer);
  357. Status GetPropertySize(OUT UINT* totalBufferSize,
  358. OUT UINT* numProperties);
  359. Status GetAllPropertyItems(IN UINT totalBufferSize,
  360. IN UINT numProperties,
  361. OUT PropertyItem* allItems);
  362. Status RemovePropertyItem(IN PROPID propId);
  363. Status SetPropertyItem(IN const PropertyItem* item);
  364. UINT GetEncoderParameterListSize(IN const CLSID* clsidEncoder);
  365. Status GetEncoderParameterList(IN const CLSID* clsidEncoder,
  366. IN UINT size,
  367. OUT EncoderParameters* buffer);
  368. Status GetLastStatus() const;
  369. protected:
  370. Image() {}
  371. Image(GpImage *nativeImage, Status status);
  372. VOID SetNativeImage(GpImage* nativeImage);
  373. Status SetStatus(Status status) const
  374. {
  375. if (status != Ok)
  376. return (lastResult = status);
  377. else
  378. return status;
  379. }
  380. GpImage* nativeImage;
  381. mutable Status lastResult;
  382. mutable Status loadStatus;
  383. private:
  384. Image(IN const Image& C);
  385. Image& operator=(IN const Image& C);
  386. };
  387. class Bitmap : public Image
  388. {
  389. public:
  390. friend class Image;
  391. friend class CachedBitmap;
  392. Bitmap(
  393. IN const WCHAR *filename,
  394. IN BOOL useEmbeddedColorManagement = FALSE
  395. );
  396. Bitmap(
  397. IN IStream *stream,
  398. IN BOOL useEmbeddedColorManagement = FALSE
  399. );
  400. static Bitmap* FromFile(
  401. IN const WCHAR *filename,
  402. IN BOOL useEmbeddedColorManagement = FALSE
  403. );
  404. static Bitmap* FromStream(
  405. IN IStream *stream,
  406. IN BOOL useEmbeddedColorManagement = FALSE
  407. );
  408. Bitmap(IN INT width,
  409. IN INT height,
  410. IN INT stride, PixelFormat format,
  411. IN BYTE* scan0);
  412. Bitmap(IN INT width,
  413. IN INT height,
  414. IN PixelFormat format = PixelFormat32bppARGB);
  415. Bitmap(IN INT width,
  416. IN INT height,
  417. IN Graphics* target);
  418. Bitmap* Clone(IN const Rect& rect,
  419. IN PixelFormat format);
  420. Bitmap* Clone(IN INT x,
  421. IN INT y,
  422. IN INT width,
  423. IN INT height,
  424. IN PixelFormat format);
  425. Bitmap* Clone(IN const RectF& rect,
  426. IN PixelFormat format);
  427. Bitmap* Clone(IN REAL x,
  428. IN REAL y,
  429. IN REAL width,
  430. IN REAL height,
  431. IN PixelFormat format);
  432. Status LockBits(IN const Rect* rect,
  433. IN UINT flags,
  434. IN PixelFormat format,
  435. OUT BitmapData* lockedBitmapData);
  436. Status UnlockBits(IN BitmapData* lockedBitmapData);
  437. Status GetPixel(IN INT x,
  438. IN INT y,
  439. OUT Color *color);
  440. Status SetPixel(IN INT x,
  441. IN INT y,
  442. IN const Color &color);
  443. Status SetResolution(IN REAL xdpi,
  444. IN REAL ydpi);
  445. Bitmap(IN IDirectDrawSurface7* surface);
  446. Bitmap(IN const BITMAPINFO* gdiBitmapInfo,
  447. IN VOID* gdiBitmapData);
  448. Bitmap(IN HBITMAP hbm,
  449. IN HPALETTE hpal);
  450. Bitmap(IN HICON hicon);
  451. Bitmap(IN HINSTANCE hInstance,
  452. IN const WCHAR * bitmapName);
  453. static Bitmap* FromDirectDrawSurface7(IN IDirectDrawSurface7* surface);
  454. static Bitmap* FromBITMAPINFO(IN const BITMAPINFO* gdiBitmapInfo,
  455. IN VOID* gdiBitmapData);
  456. static Bitmap* FromHBITMAP(IN HBITMAP hbm,
  457. IN HPALETTE hpal);
  458. static Bitmap* FromHICON(IN HICON hicon);
  459. static Bitmap* FromResource(IN HINSTANCE hInstance,
  460. IN const WCHAR * bitmapName);
  461. Status GetHBITMAP(IN const Color& colorBackground,
  462. OUT HBITMAP *hbmReturn);
  463. Status GetHICON(HICON *hicon);
  464. private:
  465. Bitmap(const Bitmap &);
  466. Bitmap& operator=(const Bitmap &);
  467. protected:
  468. Bitmap(GpBitmap *nativeBitmap);
  469. };
  470. class CustomLineCap : public GdiplusBase
  471. {
  472. public:
  473. friend class Pen;
  474. CustomLineCap(
  475. IN const GraphicsPath* fillPath,
  476. IN const GraphicsPath* strokePath,
  477. IN LineCap baseCap = LineCapFlat,
  478. IN REAL baseInset = 0
  479. );
  480. virtual ~CustomLineCap();
  481. CustomLineCap* Clone() const;
  482. // This changes both the start and end cap.
  483. Status SetStrokeCap(IN LineCap strokeCap)
  484. {
  485. return SetStrokeCaps(strokeCap, strokeCap);
  486. }
  487. Status SetStrokeCaps(IN LineCap startCap,
  488. IN LineCap endCap);
  489. Status GetStrokeCaps(OUT LineCap* startCap,
  490. OUT LineCap* endCap) const;
  491. Status SetStrokeJoin(IN LineJoin lineJoin);
  492. LineJoin GetStrokeJoin() const;
  493. Status SetBaseCap(IN LineCap baseCap);
  494. LineCap GetBaseCap() const;
  495. Status SetBaseInset(IN REAL inset);
  496. REAL GetBaseInset() const;
  497. Status SetWidthScale(IN REAL widthScale);
  498. REAL GetWidthScale() const;
  499. Status GetLastStatus() const;
  500. protected:
  501. CustomLineCap();
  502. private:
  503. CustomLineCap(const CustomLineCap &);
  504. CustomLineCap& operator=(const CustomLineCap &);
  505. protected:
  506. CustomLineCap(GpCustomLineCap* nativeCap, Status status)
  507. {
  508. lastResult = status;
  509. SetNativeCap(nativeCap);
  510. }
  511. VOID SetNativeCap(GpCustomLineCap* nativeCap)
  512. {
  513. this->nativeCap = nativeCap;
  514. }
  515. Status SetStatus(Status status) const
  516. {
  517. if (status != Ok)
  518. return (lastResult = status);
  519. else
  520. return status;
  521. }
  522. protected:
  523. GpCustomLineCap* nativeCap;
  524. mutable Status lastResult;
  525. };
  526. class CachedBitmap : public GdiplusBase
  527. {
  528. friend Graphics;
  529. public:
  530. CachedBitmap(IN Bitmap *bitmap,
  531. IN Graphics *graphics);
  532. virtual ~CachedBitmap();
  533. Status GetLastStatus() const;
  534. private:
  535. CachedBitmap(const CachedBitmap &);
  536. CachedBitmap& operator=(const CachedBitmap &);
  537. protected:
  538. GpCachedBitmap *nativeCachedBitmap;
  539. mutable Status lastResult;
  540. };
  541. #endif // !_GDIPLUSHEADERS.HPP