xref: /reactos/sdk/include/psdk/gdiplusmetafile.h (revision 019f21ee)
1 /*
2  * GdiPlusMetaFile.h
3  *
4  * Windows GDI+
5  *
6  * This file is part of the w32api package.
7  *
8  * THIS SOFTWARE IS NOT COPYRIGHTED
9  *
10  * This source code is offered for use in the public domain. You may
11  * use, modify or distribute it freely.
12  *
13  * This code is distributed in the hope that it will be useful but
14  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
15  * DISCLAIMED. This includes but is not limited to warranties of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  */
18 
19 #ifndef _GDIPLUSMETAFILE_H
20 #define _GDIPLUSMETAFILE_H
21 
22 class Metafile : public Image
23 {
24   public:
25     Metafile(HDC referenceHdc, EmfType type = EmfTypeEmfPlusDual, const WCHAR *description = NULL)
26     {
27         GpMetafile *metafile = NULL;
28         lastStatus =
29             DllExports::GdipRecordMetafile(referenceHdc, type, NULL, MetafileFrameUnitGdi, description, &metafile);
30         SetNativeImage(metafile);
31     }
32 
33     Metafile(const WCHAR *filename)
34     {
35         GpMetafile *metafile = NULL;
36         lastStatus = DllExports::GdipCreateMetafileFromFile(filename, &metafile);
37         SetNativeImage(metafile);
38     }
39 
40     Metafile(
41         HDC referenceHdc,
42         const RectF &frameRect,
43         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
44         EmfType type = EmfTypeEmfPlusDual,
45         const WCHAR *description = NULL)
46     {
47         GpMetafile *metafile = NULL;
48         lastStatus = DllExports::GdipRecordMetafile(referenceHdc, type, &frameRect, frameUnit, description, &metafile);
49         SetNativeImage(metafile);
50     }
51 
52     Metafile(HMETAFILE hWmf, const WmfPlaceableFileHeader *wmfPlaceableFileHeader, BOOL deleteWmf = FALSE)
53     {
54         GpMetafile *metafile = NULL;
55         lastStatus = DllExports::GdipCreateMetafileFromWmf(hWmf, deleteWmf, wmfPlaceableFileHeader, &metafile);
56         SetNativeImage(metafile);
57     }
58 
59     Metafile(
60         const WCHAR *fileName,
61         HDC referenceHdc,
62         const Rect &frameRect,
63         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
64         EmfType type = EmfTypeEmfPlusDual,
65         const WCHAR *description = NULL)
66     {
67         GpMetafile *metafile = NULL;
68         lastStatus = DllExports::GdipRecordMetafileFileNameI(
69             fileName, referenceHdc, type, &frameRect, frameUnit, description, &metafile);
70         SetNativeImage(metafile);
71     }
72 
73     Metafile(
74         IStream *stream,
75         HDC referenceHdc,
76         const RectF &frameRect,
77         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
78         EmfType type = EmfTypeEmfPlusDual,
79         const WCHAR *description = NULL)
80     {
81         GpMetafile *metafile = NULL;
82         lastStatus = DllExports::GdipRecordMetafile(referenceHdc, type, &frameRect, frameUnit, description, &metafile);
83         SetNativeImage(metafile);
84     }
85 
86     Metafile(IStream *stream, HDC referenceHdc, EmfType type = EmfTypeEmfPlusDual, const WCHAR *description = NULL)
87     {
88         GpMetafile *metafile = NULL;
89         lastStatus = DllExports::GdipRecordMetafileStream(
90             stream, referenceHdc, type, NULL, MetafileFrameUnitGdi, description, &metafile);
91         SetNativeImage(metafile);
92     }
93 
94     Metafile(
95         IStream *stream,
96         HDC referenceHdc,
97         const Rect &frameRect,
98         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
99         EmfType type = EmfTypeEmfPlusDual,
100         const WCHAR *description = NULL)
101     {
102         GpMetafile *metafile = NULL;
103         lastStatus = DllExports::GdipRecordMetafileI(referenceHdc, type, &frameRect, frameUnit, description, &metafile);
104         SetNativeImage(metafile);
105     }
106 
107     Metafile(
108         const WCHAR *fileName,
109         HDC referenceHdc,
110         const RectF &frameRect,
111         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
112         EmfType type = EmfTypeEmfPlusDual,
113         const WCHAR *description = NULL)
114     {
115         GpMetafile *metafile = NULL;
116         lastStatus = DllExports::GdipRecordMetafileFileName(
117             fileName, referenceHdc, type, &frameRect, frameUnit, description, &metafile);
118         SetNativeImage(metafile);
119     }
120 
121     Metafile(
122         const WCHAR *fileName,
123         HDC referenceHdc,
124         EmfType type = EmfTypeEmfPlusDual,
125         const WCHAR *description = NULL)
126     {
127         GpMetafile *metafile = NULL;
128         lastStatus = DllExports::GdipRecordMetafileFileName(
129             fileName, referenceHdc, type, NULL, MetafileFrameUnitGdi, description, &metafile);
130         SetNativeImage(metafile);
131     }
132 
133     Metafile(IStream *stream)
134     {
135         GpMetafile *metafile = NULL;
136         lastStatus = DllExports::GdipCreateMetafileFromStream(stream, &metafile);
137         SetNativeImage(metafile);
138     }
139 
140     Metafile(HENHMETAFILE hEmf, BOOL deleteEmf = FALSE)
141     {
142         GpMetafile *metafile = NULL;
143         lastStatus = DllExports::GdipCreateMetafileFromEmf(hEmf, deleteEmf, &metafile);
144         SetNativeImage(metafile);
145     }
146 
147     Metafile(
148         HDC referenceHdc,
149         const Rect &frameRect,
150         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
151         EmfType type = EmfTypeEmfPlusDual,
152         const WCHAR *description = NULL)
153     {
154         GpMetafile *metafile = NULL;
155         lastStatus = DllExports::GdipRecordMetafileI(referenceHdc, type, &frameRect, frameUnit, description, &metafile);
156         SetNativeImage(metafile);
157     }
158 
159     static UINT
160     EmfToWmfBits(
161         HENHMETAFILE hemf,
162         UINT cbData16,
163         LPBYTE pData16,
164         INT iMapMode = MM_ANISOTROPIC,
165         EmfToWmfBitsFlags eFlags = EmfToWmfBitsFlagsDefault)
166     {
167         return DllExports::GdipEmfToWmfBits(hemf, cbData16, pData16, iMapMode, eFlags);
168     }
169 
170     UINT
171     GetDownLevelRasterizationLimit() const
172     {
173 #if 1
174         return 0; // FIXME
175 #else
176         UINT metafileRasterizationLimitDpi = 0;
177         SetStatus(DllExports::GdipGetMetafileDownLevelRasterizationLimit(
178             GetNativeMetafile(), &metafileRasterizationLimitDpi));
179         return metafileRasterizationLimitDpi;
180 #endif
181     }
182 
183     HENHMETAFILE
184     GetHENHMETAFILE() const
185     {
186         HENHMETAFILE hEmf;
187         SetStatus(DllExports::GdipGetHemfFromMetafile(GetNativeMetafile(), &hEmf));
188         return hEmf;
189     }
190 
191     static Status
192     GetMetafileHeader(const WCHAR *filename, MetafileHeader *header)
193     {
194         return DllExports::GdipGetMetafileHeaderFromFile(filename, header);
195     }
196 
197     static Status
198     GetMetafileHeader(HENHMETAFILE hEmf, MetafileHeader *header)
199     {
200         return DllExports::GdipGetMetafileHeaderFromEmf(hEmf, header);
201     }
202 
203     static Status
204     GetMetafileHeader(HMETAFILE hWmf, const WmfPlaceableFileHeader *wmfPlaceableFileHeader, MetafileHeader *header)
205     {
206         return DllExports::GdipGetMetafileHeaderFromWmf(hWmf, wmfPlaceableFileHeader, header);
207     }
208 
209     Status
210     GetMetafileHeader(MetafileHeader *header) const
211     {
212         return SetStatus(DllExports::GdipGetMetafileHeaderFromMetafile(GetNativeMetafile(), header));
213     }
214 
215     static Status
216     GetMetafileHeader(IStream *stream, MetafileHeader *header)
217     {
218         return DllExports::GdipGetMetafileHeaderFromStream(stream, header);
219     }
220 
221     Status
222     PlayRecord(EmfPlusRecordType recordType, UINT flags, UINT dataSize, const BYTE *data)
223     {
224         return SetStatus(DllExports::GdipPlayMetafileRecord(GetNativeMetafile(), recordType, flags, dataSize, data));
225     }
226 
227     Status
228     SetDownLevelRasterizationLimit(UINT metafileRasterizationLimitDpi)
229     {
230         return SetStatus(
231             DllExports::GdipSetMetafileDownLevelRasterizationLimit(GetNativeMetafile(), metafileRasterizationLimitDpi));
232     }
233 
234   protected:
235     GpMetafile *
236     GetNativeMetafile() const
237     {
238         return static_cast<GpMetafile *>(nativeImage);
239     }
240 
241     // get native
242     friend inline GpMetafile *&
243     getNat(const Metafile *metafile)
244     {
245         return reinterpret_cast<GpMetafile *&>(const_cast<Metafile *>(metafile)->nativeImage);
246     }
247 };
248 
249 #endif /* _GDIPLUSMETAFILE_H */
250