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