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.

319 lines
9.7 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * Metafile.h
  8. *
  9. * Abstract:
  10. *
  11. * Metafile related declarations
  12. *
  13. * Revision History:
  14. *
  15. * 4/26/1999 DCurtis
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #ifndef _GDIPLUSMETAFILE_H
  20. #define _GDIPLUSMETAFILE_H
  21. class Metafile : public Image
  22. {
  23. public:
  24. friend class Image;
  25. // Read a metafile
  26. Metafile()
  27. {
  28. SetNativeImage(NULL);
  29. lastResult = Ok;
  30. }
  31. // Playback a metafile from a HMETAFILE
  32. // If deleteWmf is TRUE, then when the metafile is deleted,
  33. // the hWmf will also be deleted. Otherwise, it won't be.
  34. Metafile(IN HMETAFILE hWmf,
  35. IN APMFileHeader * apmFileHeader,
  36. IN BOOL deleteWmf = FALSE)
  37. {
  38. GpMetafile * metafile = NULL;
  39. lastResult = DllExports::GdipCreateMetafileFromWmf(hWmf, deleteWmf, apmFileHeader, &metafile);
  40. SetNativeImage(metafile);
  41. }
  42. // Playback a metafile from a HENHMETAFILE
  43. // If deleteEmf is TRUE, then when the metafile is deleted,
  44. // the hEmf will also be deleted. Otherwise, it won't be.
  45. Metafile(IN HENHMETAFILE hEmf,
  46. IN BOOL deleteEmf = FALSE)
  47. {
  48. GpMetafile * metafile = NULL;
  49. lastResult = DllExports::GdipCreateMetafileFromEmf(hEmf, deleteEmf, &metafile);
  50. SetNativeImage(metafile);
  51. }
  52. // Playback a metafile from a file
  53. Metafile(IN const WCHAR* filename)
  54. {
  55. GpMetafile * metafile = NULL;
  56. lastResult = DllExports::GdipCreateMetafileFromFile(filename, &metafile);
  57. SetNativeImage(metafile);
  58. }
  59. // Playback a metafile from a stream
  60. Metafile(IN IStream* stream)
  61. {
  62. GpMetafile * metafile = NULL;
  63. lastResult = DllExports::GdipCreateMetafileFromStream(stream, &metafile);
  64. SetNativeImage(metafile);
  65. }
  66. // Record a metafile to memory
  67. Metafile(
  68. IN HDC referenceHdc,
  69. IN EmfType type = EmfTypeEmfPlusDual,
  70. IN const WCHAR * description = NULL
  71. )
  72. {
  73. GpMetafile * metafile = NULL;
  74. lastResult = DllExports::GdipRecordMetafile(
  75. referenceHdc, type, NULL, MetafileFrameUnitGdi,
  76. description, &metafile);
  77. SetNativeImage(metafile);
  78. }
  79. // Record a metafile to memory
  80. Metafile(
  81. IN HDC referenceHdc,
  82. IN const RectF & frameRect,
  83. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  84. IN EmfType type = EmfTypeEmfPlusDual,
  85. IN const WCHAR * description = NULL
  86. )
  87. {
  88. GpMetafile * metafile = NULL;
  89. lastResult = DllExports::GdipRecordMetafile(
  90. referenceHdc, type, &frameRect, frameUnit,
  91. description, &metafile);
  92. SetNativeImage(metafile);
  93. }
  94. // Record a metafile to memory
  95. Metafile(
  96. IN HDC referenceHdc,
  97. IN const Rect & frameRect,
  98. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  99. IN EmfType type = EmfTypeEmfPlusDual,
  100. IN const WCHAR * description = NULL
  101. )
  102. {
  103. GpMetafile * metafile = NULL;
  104. lastResult = DllExports::GdipRecordMetafileI(
  105. referenceHdc, type, &frameRect, frameUnit,
  106. description, &metafile);
  107. SetNativeImage(metafile);
  108. }
  109. // Record a metafile to a file
  110. Metafile(
  111. IN const WCHAR* fileName,
  112. IN HDC referenceHdc,
  113. IN EmfType type = EmfTypeEmfPlusDual,
  114. IN const WCHAR * description = NULL
  115. )
  116. {
  117. GpMetafile * metafile = NULL;
  118. lastResult = DllExports::GdipRecordMetafileFileName(fileName,
  119. referenceHdc, type, NULL, MetafileFrameUnitGdi,
  120. description, &metafile);
  121. SetNativeImage(metafile);
  122. }
  123. // Record a metafile to a file
  124. Metafile(
  125. IN const WCHAR* fileName,
  126. IN HDC referenceHdc,
  127. IN const RectF & frameRect,
  128. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  129. IN EmfType type = EmfTypeEmfPlusDual,
  130. IN const WCHAR * description = NULL
  131. )
  132. {
  133. GpMetafile * metafile = NULL;
  134. lastResult = DllExports::GdipRecordMetafileFileName(fileName,
  135. referenceHdc, type, &frameRect, frameUnit,
  136. description, &metafile);
  137. SetNativeImage(metafile);
  138. }
  139. // Record a metafile to a file
  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. // Record a metafile to a stream
  156. Metafile(
  157. IN IStream * stream,
  158. IN HDC referenceHdc,
  159. IN EmfType type = EmfTypeEmfPlusDual,
  160. IN const WCHAR * description = NULL
  161. )
  162. {
  163. GpMetafile * metafile = NULL;
  164. lastResult = DllExports::GdipRecordMetafileStream(stream,
  165. referenceHdc, type, NULL, MetafileFrameUnitGdi,
  166. description, &metafile);
  167. SetNativeImage(metafile);
  168. }
  169. // Record a metafile to a stream
  170. Metafile(
  171. IN IStream * stream,
  172. IN HDC referenceHdc,
  173. IN const RectF & frameRect,
  174. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  175. IN EmfType type = EmfTypeEmfPlusDual,
  176. IN const WCHAR * description = NULL
  177. )
  178. {
  179. GpMetafile * metafile = NULL;
  180. lastResult = DllExports::GdipRecordMetafileStream(stream,
  181. referenceHdc, type, &frameRect, frameUnit,
  182. description, &metafile);
  183. SetNativeImage(metafile);
  184. }
  185. // Write a metafile to a stream with down-level GDI records
  186. Metafile(
  187. IN IStream * stream,
  188. IN HDC referenceHdc,
  189. IN const Rect & frameRect,
  190. IN MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
  191. IN EmfType type = EmfTypeEmfPlusDual,
  192. IN const WCHAR * description = NULL
  193. )
  194. {
  195. GpMetafile * metafile = NULL;
  196. lastResult = DllExports::GdipRecordMetafileStreamI(stream,
  197. referenceHdc, type, &frameRect, frameUnit,
  198. description, &metafile);
  199. SetNativeImage(metafile);
  200. }
  201. static Status GetMetafileHeader(
  202. IN HMETAFILE hWmf,
  203. IN APMFileHeader * apmFileHeader,
  204. OUT MetafileHeader * header
  205. )
  206. {
  207. return DllExports::GdipGetMetafileHeaderFromWmf(hWmf, apmFileHeader, header);
  208. }
  209. static Status GetMetafileHeader(
  210. IN HENHMETAFILE hEmf,
  211. OUT MetafileHeader * header
  212. )
  213. {
  214. return DllExports::GdipGetMetafileHeaderFromEmf(hEmf, header);
  215. }
  216. static Status GetMetafileHeader(
  217. IN const WCHAR* filename,
  218. OUT MetafileHeader * header
  219. )
  220. {
  221. return DllExports::GdipGetMetafileHeaderFromFile(filename, header);
  222. }
  223. static Status GetMetafileHeader(
  224. IN IStream * stream,
  225. OUT MetafileHeader * header
  226. )
  227. {
  228. return DllExports::GdipGetMetafileHeaderFromStream(stream, header);
  229. }
  230. Status GetMetafileHeader(
  231. OUT MetafileHeader * header
  232. ) const
  233. {
  234. return SetStatus(DllExports::GdipGetMetafileHeaderFromMetafile(
  235. (GpMetafile *)nativeImage,
  236. header));
  237. }
  238. // Once this method is called, the Metafile object is in an invalid state
  239. // and can no longer be used. It is the responsiblity of the caller to
  240. // invoke DeleteEnhMetaFile to delete this hEmf.
  241. HENHMETAFILE GetHENHMETAFILE()
  242. {
  243. HENHMETAFILE hEmf;
  244. SetStatus(DllExports::GdipGetHemfFromMetafile((GpMetafile *)nativeImage, &hEmf));
  245. return hEmf;
  246. }
  247. // Used in conjuction with Graphics::EnumerateMetafile to play an EMF+
  248. // The data must be DWORD aligned if it's an EMF or EMF+. It must be
  249. // WORD aligned if it's a WMF.
  250. Status
  251. 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. };
  266. #endif // !_METAFILE_H