OSDN Git Service

Apply LICENSE to all files as appropriate.
[mingw/mingw-org-wsl.git] / include / gdiplus / gdiplusmetafile.h
1 /**
2  * @file gdiplusmetafile.h
3  * @copy 2012 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 /*
25  * gdiplusmetafile.h
26  *
27  * GDI+ Metafile class
28  *
29  * This file is part of the w32api package.
30  *
31  * Contributors:
32  *   Created by Markus Koenig <markus@stber-koenig.de>
33  *
34  * THIS SOFTWARE IS NOT COPYRIGHTED
35  *
36  * This source code is offered for use in the public domain. You may
37  * use, modify or distribute it freely.
38  *
39  * This code is distributed in the hope that it will be useful but
40  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
41  * DISCLAIMED. This includes but is not limited to warranties of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
43  *
44  */
45
46 #ifndef __GDIPLUS_METAFILE_H
47 #define __GDIPLUS_METAFILE_H
48 #pragma GCC system_header
49
50 #ifndef __cplusplus
51 #error "A C++ compiler is required to include gdiplusmetafile.h."
52 #endif
53
54 class Metafile: public Image
55 {
56 public:
57         static UINT EmfToWmfBits(HENHMETAFILE hEmf,
58                         UINT cbData16, LPBYTE pData16,
59                         INT iMapMode = MM_ANISOTROPIC,
60                         EmfToWmfBitsFlags eFlags = EmfToWmfBitsFlagsDefault)
61         {
62                 return DllExports::GdipEmfToWmfBits(hEmf,
63                                 cbData16, pData16, iMapMode, eFlags);
64         }
65         static Status GetMetafileHeader(const WCHAR *filename,
66                         MetafileHeader *header)
67         {
68                 return DllExports::GdipGetMetafileHeaderFromFile(
69                                 filename, header);
70         }
71         static Status GetMetafileHeader(IStream *stream, MetafileHeader *header)
72         {
73                 return DllExports::GdipGetMetafileHeaderFromStream(
74                                 stream, header);
75         }
76         ////TODO: Metafile::GetMetafileHeader
77         //static Status GetMetafileHeader(HMETAFILE hWmf,
78         //              const WmfPlaceableFileHeader *wmfPlaceableFileHeader,
79         //              MetafileHeader *header)
80         //{
81         //      // WTF: No flat API to do this.
82         //      return NotImplemented;
83         //}
84         static Status GetMetafileHeader(HENHMETAFILE hEmf,
85                         MetafileHeader *header)
86         {
87                 return DllExports::GdipGetMetafileHeaderFromEmf(hEmf, header);
88         }
89
90         Metafile(HMETAFILE hWmf,
91                         const WmfPlaceableFileHeader *wmfPlaceableFileHeader,
92                         BOOL deleteWmf = FALSE): Image(NULL, Ok)
93         {
94                 GpMetafile *nativeMetafile = NULL;
95                 lastStatus = DllExports::GdipCreateMetafileFromWmf(
96                                 hWmf, deleteWmf, wmfPlaceableFileHeader,
97                                 &nativeMetafile);
98                 nativeImage = nativeMetafile;
99         }
100         Metafile(HENHMETAFILE hEmf, BOOL deleteEmf = FALSE): Image(NULL, Ok)
101         {
102                 GpMetafile *nativeMetafile = NULL;
103                 lastStatus = DllExports::GdipCreateMetafileFromEmf(
104                                 hEmf, deleteEmf, &nativeMetafile);
105                 nativeImage = nativeMetafile;
106         }
107         Metafile(const WCHAR *filename): Image(NULL, Ok)
108         {
109                 GpMetafile *nativeMetafile = NULL;
110                 lastStatus = DllExports::GdipCreateMetafileFromFile(
111                                 filename, &nativeMetafile);
112                 nativeImage = nativeMetafile;
113         }
114         Metafile(const WCHAR *filename,
115                         const WmfPlaceableFileHeader *wmfPlaceableFileHeader):
116                         Image(NULL, Ok)
117         {
118                 GpMetafile *nativeMetafile = NULL;
119                 lastStatus = DllExports::GdipCreateMetafileFromWmfFile(
120                                 filename, wmfPlaceableFileHeader,
121                                 &nativeMetafile);
122                 nativeImage = nativeMetafile;
123         }
124         Metafile(IStream *stream): Image(NULL, Ok)
125         {
126                 GpMetafile *nativeMetafile = NULL;
127                 lastStatus = DllExports::GdipCreateMetafileFromStream(
128                                 stream, &nativeMetafile);
129                 nativeImage = nativeMetafile;
130         }
131         Metafile(HDC referenceHdc, EmfType type = EmfTypeEmfPlusDual,
132                         const WCHAR *description = NULL): Image(NULL, Ok)
133         {
134                 GpMetafile *nativeMetafile = NULL;
135                 lastStatus = DllExports::GdipRecordMetafile(
136                                 referenceHdc, type, NULL, MetafileFrameUnitGdi,
137                                 description, &nativeMetafile);
138                 nativeImage = nativeMetafile;
139         }
140         Metafile(HDC referenceHdc, const RectF& frameRect,
141                         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
142                         EmfType type = EmfTypeEmfPlusDual,
143                         const WCHAR *description = NULL): Image(NULL, Ok)
144         {
145                 GpMetafile *nativeMetafile = NULL;
146                 lastStatus = DllExports::GdipRecordMetafile(
147                                 referenceHdc, type, &frameRect, frameUnit,
148                                 description, &nativeMetafile);
149                 nativeImage = nativeMetafile;
150         }
151         Metafile(HDC referenceHdc, const Rect& frameRect,
152                         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
153                         EmfType type = EmfTypeEmfPlusDual,
154                         const WCHAR *description = NULL): Image(NULL, Ok)
155         {
156                 GpMetafile *nativeMetafile = NULL;
157                 lastStatus = DllExports::GdipRecordMetafileI(
158                                 referenceHdc, type, &frameRect, frameUnit,
159                                 description, &nativeMetafile);
160                 nativeImage = nativeMetafile;
161         }
162         Metafile(const WCHAR *filename, HDC referenceHdc,
163                         EmfType type = EmfTypeEmfPlusDual,
164                         const WCHAR *description = NULL): Image(NULL, Ok)
165         {
166                 GpMetafile *nativeMetafile = NULL;
167                 lastStatus = DllExports::GdipRecordMetafileFileName(
168                                 filename, referenceHdc, type, NULL,
169                                 MetafileFrameUnitGdi, description,
170                                 &nativeMetafile);
171                 nativeImage = nativeMetafile;
172         }
173         Metafile(const WCHAR *filename, HDC referenceHdc,
174                         const RectF& frameRect,
175                         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
176                         EmfType type = EmfTypeEmfPlusDual,
177                         const WCHAR *description = NULL): Image(NULL, Ok)
178         {
179                 GpMetafile *nativeMetafile = NULL;
180                 lastStatus = DllExports::GdipRecordMetafileFileName(
181                                 filename, referenceHdc, type, &frameRect,
182                                 frameUnit, description, &nativeMetafile);
183                 nativeImage = nativeMetafile;
184         }
185         Metafile(const WCHAR *filename, HDC referenceHdc,
186                         const Rect& frameRect,
187                         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
188                         EmfType type = EmfTypeEmfPlusDual,
189                         const WCHAR *description = NULL): Image(NULL, Ok)
190         {
191                 GpMetafile *nativeMetafile = NULL;
192                 lastStatus = DllExports::GdipRecordMetafileFileNameI(
193                                 filename, referenceHdc, type, &frameRect,
194                                 frameUnit, description, &nativeMetafile);
195                 nativeImage = nativeMetafile;
196         }
197         Metafile(IStream *stream, HDC referenceHdc,
198                         EmfType type = EmfTypeEmfPlusDual,
199                         const WCHAR *description = NULL): Image(NULL, Ok)
200         {
201                 GpMetafile *nativeMetafile = NULL;
202                 lastStatus = DllExports::GdipRecordMetafileStream(
203                                 stream, referenceHdc, type, NULL,
204                                 MetafileFrameUnitGdi, description,
205                                 &nativeMetafile);
206                 nativeImage = nativeMetafile;
207         }
208         Metafile(IStream *stream, HDC referenceHdc, const RectF& frameRect,
209                         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
210                         EmfType type = EmfTypeEmfPlusDual,
211                         const WCHAR *description = NULL): Image(NULL, Ok)
212         {
213                 GpMetafile *nativeMetafile = NULL;
214                 lastStatus = DllExports::GdipRecordMetafileStream(
215                                 stream, referenceHdc, type, &frameRect,
216                                 frameUnit, description, &nativeMetafile);
217                 nativeImage = nativeMetafile;
218         }
219         Metafile(IStream *stream, HDC referenceHdc, const Rect& frameRect,
220                         MetafileFrameUnit frameUnit = MetafileFrameUnitGdi,
221                         EmfType type = EmfTypeEmfPlusDual,
222                         const WCHAR *description = NULL): Image(NULL, Ok)
223         {
224                 GpMetafile *nativeMetafile = NULL;
225                 lastStatus = DllExports::GdipRecordMetafileStreamI(
226                                 stream, referenceHdc, type, &frameRect,
227                                 frameUnit, description, &nativeMetafile);
228                 nativeImage = nativeMetafile;
229         }
230         virtual ~Metafile()
231         {
232         }
233         virtual Metafile* Clone() const
234         {
235                 GpImage *cloneImage = NULL;
236                 Status status = updateStatus(DllExports::GdipCloneImage(
237                                 nativeImage, &cloneImage));
238                 if (status == Ok) {
239                         Metafile *result = new Metafile(cloneImage, lastStatus);
240                         if (!result) {
241                                 DllExports::GdipDisposeImage(cloneImage);
242                                 lastStatus = OutOfMemory;
243                         }
244                         return result;
245                 } else {
246                         return NULL;
247                 }
248         }
249
250         ////TODO: [GDI+ 1.1] Metafile::ConvertToEmfPlus
251         //Status ConvertToEmfPlus(const Graphics *refGraphics,
252         //              BOOL *conversionSuccess = NULL,
253         //              EmfType emfType = EmfTypeEmfPlusOnly,
254         //              const WCHAR *description = NULL)
255         //{
256         //      // FIXME: can't test GdipConvertToEmfPlus because it isn't exported in 1.0
257         //      return updateStatus(DllExports::GdipConvertToEmfPlus(
258         //                      refGraphics ? refGraphics->nativeGraphics : NULL,
259         //                      (GpMetafile*) nativeImage,
260         //                      conversionSuccess, emfType, description, ???));
261         //}
262         ////TODO: [GDI+ 1.1] Metafile::ConvertToEmfPlus
263         //Status ConvertToEmfPlus(const Graphics *refGraphics,
264         //              const WCHAR *filename,
265         //              BOOL *conversionSuccess = NULL,
266         //              EmfType emfType = EmfTypeEmfPlusOnly,
267         //              const WCHAR *description = NULL)
268         //{
269         //      // FIXME: can't test GdipConvertToEmfPlusToFile because it isn't exported in 1.0
270         //      return updateStatus(DllExports::GdipConvertToEmfPlusToFile(
271         //                      refGraphics ? refGraphics->nativeGraphics : NULL,
272         //                      (GpMetafile*) nativeImage, conversionSuccess,
273         //                      filename, emfType, description, ???));
274         //}
275         ////TODO: [GDI+ 1.1] Metafile::ConvertToEmfPlus
276         //Status ConvertToEmfPlus(const Graphics *refGraphics,
277         //              IStream *stream,
278         //              BOOL *conversionSuccess = NULL,
279         //              EmfType emfType = EmfTypeEmfPlusOnly,
280         //              const WCHAR *description = NULL)
281         //{
282         //      // FIXME: can't test GdipConvertToEmfPlusToStream because it isn't exported in 1.0
283         //      return updateStatus(DllExports::GdipConvertToEmfPlusToStream(
284         //                      refGraphics ? refGraphics->nativeGraphics : NULL,
285         //                      (GpMetafile*) nativeImage, conversionSuccess,
286         //                      stream, emfType, description, ???));
287         //}
288         UINT GetDownLevelRasterizationLimit() const
289         {
290                 UINT result = 0;
291                 updateStatus(DllExports::GdipGetMetafileDownLevelRasterizationLimit(
292                                 (GpMetafile*) nativeImage, &result));
293                 return result;
294         }
295         HENHMETAFILE GetHENHMETAFILE()
296         {
297                 HENHMETAFILE result = NULL;
298                 updateStatus(DllExports::GdipGetHemfFromMetafile(
299                                 (GpMetafile*) nativeImage, &result));
300                 return result;
301         }
302         Status GetMetafileHeader(MetafileHeader *header) const
303         {
304                 return updateStatus(DllExports::GdipGetMetafileHeaderFromMetafile(
305                                 (GpMetafile*) nativeImage, header));
306         }
307         Status PlayRecord(EmfPlusRecordType recordType, UINT flags,
308                         UINT dataSize, const BYTE *data) const
309         {
310                 return updateStatus(DllExports::GdipPlayMetafileRecord(
311                                 (GpMetafile*) nativeImage,
312                                 recordType, flags, dataSize, data));
313         }
314         Status SetDownLevelRasterizationLimit(UINT limitDpi)
315         {
316                 return updateStatus(DllExports::GdipSetMetafileDownLevelRasterizationLimit(
317                                 (GpMetafile*) nativeImage, limitDpi));
318         }
319
320 private:
321         Metafile(GpImage *image, Status status): Image(image, status) {}
322         Metafile(const Metafile&);
323         Metafile& operator=(const Metafile&);
324 };
325
326 #endif /* __GDIPLUS_METAFILE_H */