Leaked source code of windows server 2003
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.

381 lines
12 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * GdiplusMetafile.h
  8. *
  9. * Abstract:
  10. *
  11. * GDI+ Metafile class
  12. *
  13. \**************************************************************************/
  14. #ifndef _GDIPLUSMETAFILE_H
  15. #define _GDIPLUSMETAFILE_H
  16. class Metafile : public Image
  17. {
  18. public:
  19. friend class Image;
  20. // Playback a metafile from a HMETAFILE
  21. // If deleteWmf is TRUE, then when the metafile is deleted,
  22. // the hWmf will also be deleted. Otherwise, it won't be.
  23. Metafile(IN HMETAFILE hWmf,
  24. IN const WmfPlaceableFileHeader * wmfPlaceableFileHeader,
  25. IN BOOL deleteWmf = FALSE)
  26. {
  27. GpMetafile * metafile = NULL;
  28. lastResult = DllExports::GdipCreateMetafileFromWmf(hWmf, deleteWmf,
  29. wmfPlaceableFileHeader,
  30. &metafile);
  31. SetNativeImage(metafile);
  32. }
  33. // Playback a metafile from a HENHMETAFILE
  34. // If deleteEmf is TRUE, then when the metafile is deleted,
  35. // the hEmf will also be deleted. Otherwise, it won't be.
  36. Metafile(IN HENHMETAFILE hEmf,
  37. IN BOOL deleteEmf = FALSE)
  38. {
  39. GpMetafile * metafile = NULL;
  40. lastResult = DllExports::GdipCreateMetafileFromEmf(hEmf, deleteEmf,
  41. &metafile);
  42. SetNativeImage(metafile);
  43. }
  44. Metafile(IN const WCHAR* filename)
  45. {
  46. GpMetafile * metafile = NULL;
  47. lastResult = DllExports::GdipCreateMetafileFromFile(filename,
  48. &metafile);
  49. SetNativeImage(metafile);
  50. }
  51. // Playback a WMF metafile from a file.
  52. Metafile(IN const WCHAR* filename,
  53. IN const WmfPlaceableFileHeader * wmfPlaceableFileHeader
  54. )
  55. {
  56. GpMetafile * metafile = NULL;
  57. lastResult = DllExports::GdipCreateMetafileFromWmfFile(filename,
  58. wmfPlaceableFileHeader,
  59. &metafile);
  60. SetNativeImage(metafile);
  61. }
  62. Metafile(IN IStream* stream)
  63. {
  64. GpMetafile * metafile = NULL;
  65. lastResult = DllExports::GdipCreateMetafileFromStream(stream,
  66. &metafile);
  67. SetNativeImage(metafile);
  68. }
  69. // Record a metafile to memory.
  70. Metafile(
  71. IN HDC referenceHdc,
  72. IN EmfType type = EmfTypeEmfPlusDual,
  73. IN const WCHAR * description = NULL
  74. )
  75. {
  76. GpMetafile * metafile = NULL;
  77. lastResult = DllExports::GdipRecordMetafile(
  78. referenceHdc, type, NULL, MetafileFrameUnitGdi,
  79. description, &metafile);
  80. SetNativeImage(metafile);
  81. }
  82. // Record a metafile to memory.
  83. Metafile(
  84. IN HDC referenceHdc,
  85. IN const RectF & frameRect,
  86. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  87. IN EmfType type = EmfTypeEmfPlusDual,
  88. IN const WCHAR * description = NULL
  89. )
  90. {
  91. GpMetafile * metafile = NULL;
  92. lastResult = DllExports::GdipRecordMetafile(
  93. referenceHdc, type, &frameRect, frameUnit,
  94. description, &metafile);
  95. SetNativeImage(metafile);
  96. }
  97. // Record a metafile to memory.
  98. Metafile(
  99. IN HDC referenceHdc,
  100. IN const Rect & frameRect,
  101. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  102. IN EmfType type = EmfTypeEmfPlusDual,
  103. IN const WCHAR * description = NULL
  104. )
  105. {
  106. GpMetafile * metafile = NULL;
  107. lastResult = DllExports::GdipRecordMetafileI(
  108. referenceHdc, type, &frameRect, frameUnit,
  109. description, &metafile);
  110. SetNativeImage(metafile);
  111. }
  112. Metafile(
  113. IN const WCHAR* fileName,
  114. IN HDC referenceHdc,
  115. IN EmfType type = EmfTypeEmfPlusDual,
  116. IN const WCHAR * description = NULL
  117. )
  118. {
  119. GpMetafile * metafile = NULL;
  120. lastResult = DllExports::GdipRecordMetafileFileName(fileName,
  121. referenceHdc, type, NULL, MetafileFrameUnitGdi,
  122. description, &metafile);
  123. SetNativeImage(metafile);
  124. }
  125. Metafile(
  126. IN const WCHAR* fileName,
  127. IN HDC referenceHdc,
  128. IN const RectF & frameRect,
  129. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  130. IN EmfType type = EmfTypeEmfPlusDual,
  131. IN const WCHAR * description = NULL
  132. )
  133. {
  134. GpMetafile * metafile = NULL;
  135. lastResult = DllExports::GdipRecordMetafileFileName(fileName,
  136. referenceHdc, type, &frameRect, frameUnit,
  137. description, &metafile);
  138. SetNativeImage(metafile);
  139. }
  140. Metafile(
  141. IN const WCHAR* fileName,
  142. IN HDC referenceHdc,
  143. IN const Rect & frameRect,
  144. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  145. IN EmfType type = EmfTypeEmfPlusDual,
  146. IN const WCHAR * description = NULL
  147. )
  148. {
  149. GpMetafile * metafile = NULL;
  150. lastResult = DllExports::GdipRecordMetafileFileNameI(fileName,
  151. referenceHdc, type, &frameRect, frameUnit,
  152. description, &metafile);
  153. SetNativeImage(metafile);
  154. }
  155. Metafile(
  156. IN IStream * stream,
  157. IN HDC referenceHdc,
  158. IN EmfType type = EmfTypeEmfPlusDual,
  159. IN const WCHAR * description = NULL
  160. )
  161. {
  162. GpMetafile * metafile = NULL;
  163. lastResult = DllExports::GdipRecordMetafileStream(stream,
  164. referenceHdc, type, NULL, MetafileFrameUnitGdi,
  165. description, &metafile);
  166. SetNativeImage(metafile);
  167. }
  168. Metafile(
  169. IN IStream * stream,
  170. IN HDC referenceHdc,
  171. IN const RectF & frameRect,
  172. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  173. IN EmfType type = EmfTypeEmfPlusDual,
  174. IN const WCHAR * description = NULL
  175. )
  176. {
  177. GpMetafile * metafile = NULL;
  178. lastResult = DllExports::GdipRecordMetafileStream(stream,
  179. referenceHdc, type, &frameRect, frameUnit,
  180. description, &metafile);
  181. SetNativeImage(metafile);
  182. }
  183. Metafile(
  184. IN IStream * stream,
  185. IN HDC referenceHdc,
  186. IN const Rect & frameRect,
  187. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  188. IN EmfType type = EmfTypeEmfPlusDual,
  189. IN const WCHAR * description = NULL
  190. )
  191. {
  192. GpMetafile * metafile = NULL;
  193. lastResult = DllExports::GdipRecordMetafileStreamI(stream,
  194. referenceHdc, type, &frameRect, frameUnit,
  195. description, &metafile);
  196. SetNativeImage(metafile);
  197. }
  198. static Status GetMetafileHeader(
  199. IN HMETAFILE hWmf,
  200. IN const WmfPlaceableFileHeader * wmfPlaceableFileHeader,
  201. OUT MetafileHeader * header
  202. )
  203. {
  204. return DllExports::GdipGetMetafileHeaderFromWmf(hWmf,
  205. wmfPlaceableFileHeader,
  206. header);
  207. }
  208. static Status GetMetafileHeader(
  209. IN HENHMETAFILE hEmf,
  210. OUT MetafileHeader * header
  211. )
  212. {
  213. return DllExports::GdipGetMetafileHeaderFromEmf(hEmf, header);
  214. }
  215. static Status GetMetafileHeader(
  216. IN const WCHAR* filename,
  217. OUT MetafileHeader * header
  218. )
  219. {
  220. return DllExports::GdipGetMetafileHeaderFromFile(filename, header);
  221. }
  222. static Status GetMetafileHeader(
  223. IN IStream * stream,
  224. OUT MetafileHeader * header
  225. )
  226. {
  227. return DllExports::GdipGetMetafileHeaderFromStream(stream, header);
  228. }
  229. Status GetMetafileHeader(
  230. OUT MetafileHeader * header
  231. ) const
  232. {
  233. return SetStatus(DllExports::GdipGetMetafileHeaderFromMetafile(
  234. (GpMetafile *)nativeImage,
  235. header));
  236. }
  237. // Once this method is called, the Metafile object is in an invalid state
  238. // and can no longer be used. It is the responsiblity of the caller to
  239. // invoke DeleteEnhMetaFile to delete this hEmf.
  240. HENHMETAFILE GetHENHMETAFILE()
  241. {
  242. HENHMETAFILE hEmf;
  243. SetStatus(DllExports::GdipGetHemfFromMetafile(
  244. (GpMetafile *)nativeImage,
  245. &hEmf));
  246. return hEmf;
  247. }
  248. // Used in conjuction with Graphics::EnumerateMetafile to play an EMF+
  249. // The data must be DWORD aligned if it's an EMF or EMF+. It must be
  250. // WORD aligned if it's a WMF.
  251. Status PlayRecord(
  252. IN EmfPlusRecordType recordType,
  253. IN UINT flags,
  254. IN UINT dataSize,
  255. IN const BYTE * data
  256. ) const
  257. {
  258. return SetStatus(DllExports::GdipPlayMetafileRecord(
  259. (GpMetafile *)nativeImage,
  260. recordType,
  261. flags,
  262. dataSize,
  263. data));
  264. }
  265. // If you're using a printer HDC for the metafile, but you want the
  266. // metafile rasterized at screen resolution, then use this API to set
  267. // the rasterization dpi of the metafile to the screen resolution,
  268. // e.g. 96 dpi or 120 dpi.
  269. Status SetDownLevelRasterizationLimit(
  270. IN UINT metafileRasterizationLimitDpi
  271. )
  272. {
  273. return SetStatus(DllExports::
  274. GdipSetMetafileDownLevelRasterizationLimit(
  275. (GpMetafile *)nativeImage,
  276. metafileRasterizationLimitDpi));
  277. }
  278. UINT GetDownLevelRasterizationLimit() const
  279. {
  280. UINT metafileRasterizationLimitDpi = 0;
  281. SetStatus(DllExports::GdipGetMetafileDownLevelRasterizationLimit(
  282. (GpMetafile *)nativeImage,
  283. &metafileRasterizationLimitDpi));
  284. return metafileRasterizationLimitDpi;
  285. }
  286. static UINT Metafile::EmfToWmfBits(
  287. IN HENHMETAFILE hemf,
  288. IN UINT cbData16,
  289. OUT LPBYTE pData16,
  290. IN INT iMapMode = MM_ANISOTROPIC,
  291. IN INT eFlags = EmfToWmfBitsFlagsDefault
  292. )
  293. {
  294. return DllExports::GdipEmfToWmfBits(
  295. hemf,
  296. cbData16,
  297. pData16,
  298. iMapMode,
  299. eFlags);
  300. }
  301. protected:
  302. Metafile()
  303. {
  304. SetNativeImage(NULL);
  305. lastResult = Ok;
  306. }
  307. private:
  308. Metafile(const Metafile &);
  309. Metafile& operator=(const Metafile &);
  310. };
  311. #endif // !_METAFILE_H