PageRenderTime 28ms CodeModel.GetById 2ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/binding/win32/gdiplusmetafile.d

http://github.com/wilkie/djehuty
D | 425 lines | 224 code | 66 blank | 135 comment | 8 complexity | 904d24c0caba91786e83ee1226f4d60d MD5 | raw file
  1/*
  2 * gdiplusmetafile.d
  3 *
  4 * This module implements GdiPlusMetaFile.h for D. The original
  5 * copyright info is given below.
  6 *
  7 * Author: Dave Wilkinson
  8 * Originated: November 25th, 2009
  9 *
 10 */
 11
 12module binding.win32.gdiplusmetafile;
 13
 14import binding.win32.windef;
 15import binding.win32.winbase;
 16import binding.win32.winnt;
 17import binding.win32.wingdi;
 18import binding.win32.guiddef;
 19import binding.win32.gdiplusbase;
 20import binding.win32.gdiplustypes;
 21import binding.win32.gdiplusenums;
 22import binding.win32.gdipluspixelformats;
 23import binding.win32.gdiplusgpstubs;
 24import binding.win32.gdiplusmetaheader;
 25import binding.win32.gdipluspixelformats;
 26import binding.win32.gdipluscolor;
 27import binding.win32.gdipluscolormatrix;
 28import binding.win32.gdiplusflat;
 29import binding.win32.gdiplusimaging;
 30import binding.win32.gdiplusbitmap;
 31import binding.win32.gdiplusimageattributes;
 32import binding.win32.gdiplusmatrix;
 33import binding.win32.gdiplusgraphics;
 34
 35/**************************************************************************\
 36*
 37* Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
 38*
 39* Module Name:
 40*
 41*   GdiplusMetafile.h
 42*
 43* Abstract:
 44*
 45*   GDI+ Metafile class
 46*
 47\**************************************************************************/
 48
 49
 50class Metafile : Image {
 51    // Playback a metafile from a HMETAFILE
 52    // If deleteWmf is TRUE, then when the metafile is deleted,
 53    // the hWmf will also be deleted.  Otherwise, it won't be.
 54    
 55    this(
 56        in HMETAFILE                      hWmf,
 57        in WmfPlaceableFileHeader * wmfPlaceableFileHeader,
 58        in BOOL                           deleteWmf = FALSE) {
 59
 60        GpMetafile *    metafile = null;
 61    
 62        lastResult = GdipCreateMetafileFromWmf(hWmf, deleteWmf, 
 63                                                           wmfPlaceableFileHeader, 
 64                                                           &metafile);
 65    
 66        SetNativeImage(metafile);            
 67    }
 68
 69    // Playback a metafile from a HENHMETAFILE
 70    // If deleteEmf is TRUE, then when the metafile is deleted,
 71    // the hEmf will also be deleted.  Otherwise, it won't be.
 72    
 73    this(in HENHMETAFILE hEmf, in BOOL deleteEmf = FALSE) {
 74        GpMetafile *    metafile = null;
 75    
 76        lastResult = GdipCreateMetafileFromEmf(hEmf, deleteEmf, 
 77                                                           &metafile);
 78    
 79        SetNativeImage(metafile);        
 80    }
 81    
 82    this(in WCHAR* filename) {  
 83        GpMetafile *    metafile = null;
 84    
 85        lastResult = GdipCreateMetafileFromFile(filename, 
 86                                                            &metafile);
 87    
 88        SetNativeImage(metafile);      
 89    }
 90
 91    // Playback a WMF metafile from a file.
 92
 93    this(in WCHAR* filename, in WmfPlaceableFileHeader* wmfPlaceableFileHeader) {   
 94        GpMetafile *    metafile = null;
 95        
 96        lastResult = GdipCreateMetafileFromWmfFile(filename, 
 97                                                               wmfPlaceableFileHeader, 
 98                                                               &metafile);
 99        
100        SetNativeImage(metafile);     
101    }
102
103    //this(in IStream* stream) {
104 //       GpMetafile *    metafile = null;
105  //  
106   //     lastResult = GdipCreateMetafileFromStream(stream, 
107       //                                                       &metafile);
108    //
109     //   SetNativeImage(metafile);
110    //    
111    //}
112
113    // Record a metafile to memory.
114
115    this(in HDC referenceHdc, in EmfType type = EmfType.EmfTypeEmfPlusDual, in WCHAR* description = null) {  
116        GpMetafile *    metafile = null;
117    
118        lastResult = GdipRecordMetafile(
119                        referenceHdc, type, null, MetafileFrameUnit.MetafileFrameUnitGdi,
120                        description, &metafile);
121    
122        SetNativeImage(metafile);      
123    } 
124    
125    // Record a metafile to memory.
126
127    this(in HDC referenceHdc, in RectF frameRect, in MetafileFrameUnit frameUnit = MetafileFrameUnit.MetafileFrameUnitGdi,
128            in EmfType type = EmfType.EmfTypeEmfPlusDual, in WCHAR* description = null) {
129        GpMetafile *    metafile = null;
130    
131        lastResult = GdipRecordMetafile(
132                        referenceHdc, type, &frameRect, frameUnit,
133                        description, &metafile);
134    
135        SetNativeImage(metafile);         
136    }
137
138    // Record a metafile to memory.
139
140    this(
141        in HDC                 referenceHdc,
142        in Rect         frameRect,
143        in MetafileFrameUnit   frameUnit   = MetafileFrameUnit.MetafileFrameUnitGdi,
144        in EmfType             type        = EmfType.EmfTypeEmfPlusDual,
145        in WCHAR *       description = null
146        ) {      
147        GpMetafile *    metafile = null;
148    
149        lastResult = GdipRecordMetafileI(
150                        referenceHdc, type, &frameRect, frameUnit,
151                        description, &metafile);
152    
153        SetNativeImage(metafile);      
154    }
155
156    this(
157        in WCHAR*        fileName,
158        in HDC                 referenceHdc,
159        in EmfType             type        = EmfType.EmfTypeEmfPlusDual,
160        in WCHAR *       description = null
161        ) {  
162        GpMetafile *    metafile = null;
163    
164        lastResult = GdipRecordMetafileFileName(fileName,
165                        referenceHdc, type, null, MetafileFrameUnit.MetafileFrameUnitGdi,
166                        description, &metafile);
167    
168        SetNativeImage(metafile);          
169    }
170
171    this(
172        in WCHAR*        fileName,
173        in HDC                 referenceHdc,
174        in RectF       frameRect,
175        in MetafileFrameUnit   frameUnit   = MetafileFrameUnit.MetafileFrameUnitGdi,
176        in EmfType             type        = EmfType.EmfTypeEmfPlusDual,
177        in WCHAR *       description = null
178        ) {    
179        GpMetafile *    metafile = null;
180    
181        lastResult = GdipRecordMetafileFileName(fileName,
182                        referenceHdc, type, &frameRect, frameUnit,
183                        description, &metafile);
184    
185        SetNativeImage(metafile);        
186    }
187
188    this(
189        in WCHAR*        fileName,
190        in HDC                 referenceHdc,
191        in Rect         frameRect,
192        in MetafileFrameUnit   frameUnit   = MetafileFrameUnit.MetafileFrameUnitGdi,
193        in EmfType             type        = EmfType.EmfTypeEmfPlusDual,
194        in WCHAR *       description = null
195        ) {
196        GpMetafile *    metafile = null;
197    
198        lastResult = GdipRecordMetafileFileNameI(fileName,
199                        referenceHdc, type, &frameRect, frameUnit,
200                        description, &metafile);
201    
202        SetNativeImage(metafile);
203    }
204    
205    /*
206    this(
207        in IStream *           stream,
208        in HDC                 referenceHdc,
209        in EmfType             type        = EmfType.EmfTypeEmfPlusDual,
210        in WCHAR *       description = null
211        ) {  
212        GpMetafile *    metafile = null;
213    
214        lastResult = GdipRecordMetafileStream(stream,
215                        referenceHdc, type, null, MetafileFrameUnitGdi,
216                        description, &metafile);
217    
218        SetNativeImage(metafile);          
219    }
220
221    this(
222        in IStream *           stream,
223        in HDC                 referenceHdc,
224        in RectF        frameRect,
225        in MetafileFrameUnit   frameUnit   = MetafileFrameUnit.MetafileFrameUnitGdi,
226        in EmfType             type        = EmfType.EmfTypeEmfPlusDual,
227        in WCHAR *       description = null
228        ) {   
229        GpMetafile *    metafile = null;
230    
231        lastResult = GdipRecordMetafileStream(stream,
232                        referenceHdc, type, &frameRect, frameUnit,
233                        description, &metafile);
234    
235        SetNativeImage(metafile);         
236    }
237
238    this(
239        in IStream *           stream,
240        in HDC                 referenceHdc,
241        in Rect         frameRect,
242        in MetafileFrameUnit   frameUnit   = MetafileFrameUnit.MetafileFrameUnitGdi,
243        in EmfType             type        = EmfType.EmfTypeEmfPlusDual,
244        in WCHAR *       description = null
245        ) {       
246        GpMetafile *    metafile = null;
247    
248        lastResult = GdipRecordMetafileStreamI(stream,
249                        referenceHdc, type, &frameRect, frameUnit,
250                        description, &metafile);
251    
252        SetNativeImage(metafile);     
253    }*/
254
255    static Status GetMetafileHeader(in HMETAFILE hWmf, in WmfPlaceableFileHeader* wmfPlaceableFileHeader, MetafileHeader* header) {
256        return GdipGetMetafileHeaderFromWmf(hWmf, wmfPlaceableFileHeader, header);
257    }
258
259    static Status GetMetafileHeader(in HENHMETAFILE hEmf, MetafileHeader* header) {
260        return GdipGetMetafileHeaderFromEmf(hEmf, header);
261    }
262
263    static Status GetMetafileHeader(in WCHAR* filename, MetafileHeader* header) {  
264        return GdipGetMetafileHeaderFromFile(filename, header);          
265    }
266    
267/*
268    static Status GetMetafileHeader(
269        in IStream *           stream,
270        MetafileHeader *   header
271        ) {            
272        return GdipGetMetafileHeaderFromStream(stream, header);
273    }
274*/
275
276    Status GetMetafileHeader(MetafileHeader* header) { 
277        return SetStatus(GdipGetMetafileHeaderFromMetafile(
278                                              cast(GpMetafile *)nativeImage,
279                                              header));       
280    }
281
282    // Once this method is called, the Metafile object is in an invalid state
283    // and can no longer be used.  It is the responsiblity of the caller to
284    // invoke DeleteEnhMetaFile to delete this hEmf.
285
286    HENHMETAFILE GetHENHMETAFILE() {
287        HENHMETAFILE hEmf;
288    
289        SetStatus(GdipGetHemfFromMetafile(
290                                  cast(GpMetafile *)nativeImage, 
291                                  &hEmf));
292    
293        return hEmf;        
294    }
295
296    // Used in conjuction with Graphics::EnumerateMetafile to play an EMF+
297    // The data must be DWORD aligned if it's an EMF or EMF+.  It must be
298    // WORD aligned if it's a WMF.
299    
300    Status PlayRecord(in EmfPlusRecordType recordType, in UINT flags, in UINT dataSize, in BYTE* data) {
301        return SetStatus(GdipPlayMetafileRecord(
302                                cast(GpMetafile *)nativeImage,
303                                recordType,
304                                flags,
305                                dataSize,
306                                data));          
307    }
308
309    // If you're using a printer HDC for the metafile, but you want the
310    // metafile rasterized at screen resolution, then use this API to set
311    // the rasterization dpi of the metafile to the screen resolution,
312    // e.g. 96 dpi or 120 dpi.
313    
314    Status SetDownLevelRasterizationLimit(in UINT metafileRasterizationLimitDpi) {
315        return SetStatus(
316                         GdipSetMetafileDownLevelRasterizationLimit(
317                                cast(GpMetafile *)nativeImage,
318                                metafileRasterizationLimitDpi));
319    }
320
321    UINT GetDownLevelRasterizationLimit() {    
322        UINT metafileRasterizationLimitDpi = 0;
323    
324        SetStatus(GdipGetMetafileDownLevelRasterizationLimit(
325                                cast(GpMetafile *)nativeImage,
326                                &metafileRasterizationLimitDpi));
327    
328        return metafileRasterizationLimitDpi;    
329    }
330
331    static UINT EmfToWmfBits(in HENHMETAFILE hemf, in UINT cbData16, LPBYTE pData16, in INT iMapMode = MM_ANISOTROPIC, in INT eFlags = EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault) {
332        return GdipEmfToWmfBits(
333            hemf,
334            cbData16,
335            pData16,
336            iMapMode,
337            eFlags);
338    }
339
340version(GDIPLUS6) {
341    Status ConvertToEmfPlus(
342        in Graphics* refGraphics,
343        in INT* conversionFailureFlag = null,
344        in EmfType emfType = EmfType.EmfTypeEmfPlusOnly,
345        in WCHAR* description = null
346    ) {
347        GpMetafile * metafile = null;
348        GpStatus status = GdipConvertToEmfPlus(
349            cast(GpGraphics*)refGraphics.nativeGraphics,
350            cast(GpMetafile *)nativeImage,
351            conversionFailureFlag,
352            emfType, description, &metafile);
353
354        if (metafile !is null) {
355            if (status == Status.Ok) {
356                GdipDisposeImage(nativeImage);
357                SetNativeImage(metafile);
358            }
359            else {
360                GdipDisposeImage(metafile);
361            }
362        }
363        return status;
364    }
365
366    Status ConvertToEmfPlus(
367        in Graphics* refGraphics,
368        in WCHAR* filename,
369        in INT* conversionFailureFlag = null,
370        in EmfType emfType = EmfType.EmfTypeEmfPlusOnly,
371        in WCHAR* description = null
372    ) {
373        GpMetafile * metafile = null;
374        GpStatus status = GdipConvertToEmfPlusToFile(
375            cast(GpGraphics*)refGraphics.nativeGraphics,
376            cast(GpMetafile *)nativeImage,
377            conversionFailureFlag,
378            filename, emfType, description, &metafile);
379
380        if (metafile !is null) {
381            if (status == Status.Ok) {
382                GdipDisposeImage(nativeImage);
383                SetNativeImage(metafile);
384            }
385            else {
386                GdipDisposeImage(metafile);
387            }
388        }
389        return status;
390    }
391}
392
393/*    Status ConvertToEmfPlus(
394        in Graphics* refGraphics,
395        in IStream* stream,
396        in INT* conversionFailureFlag = null,
397        in EmfType emfType = EmfType.EmfTypeEmfPlusOnly,
398        in WCHAR* description = null
399    ) {
400        GpMetafile * metafile = null;
401        GpStatus status = GdipConvertToEmfPlusToStream(
402            cast(GpGraphics*)refGraphics.nativeGraphics,
403            cast(GpMetafile *)nativeImage,
404            conversionFailureFlag,
405            stream, emfType, description, &metafile);
406
407        if (metafile != null) {
408            if (status == Status.Ok) {
409                GdipDisposeImage(nativeImage);
410                SetNativeImage(metafile);
411            }
412            else {
413                GdipDisposeImage(metafile);
414            }
415        }
416        return status;
417    }
418*/
419
420protected:
421    this() {
422        SetNativeImage(null);
423        lastResult = Status.Ok;
424    }
425}