ReactOS  0.4.14-dev-998-g623dd26
metafile.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * FILE: win32ss/gdi/gdi32/objects/metafile.c
5  * PURPOSE: metafile and enhanced metafile support
6  * PROGRAMMERS: Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7  */
8 #include <precomp.h>
9 
10 #define NDEBUG
11 #include <debug.h>
12 
13 /* FUNCTIONS *****************************************************************/
14 
15 /*
16  * @implemented
17  */
18 BOOL
19 WINAPI
21 {
22 #if 0
23  PLDC pLDC = GdiGetLDC(hDC);
24  if ( pLDC )
25  {
26  if ( pLDC->Flags & LDC_PLAY_MFDC ) return TRUE;
27  }
28  return FALSE;
29 #else
31  return FALSE;
32 #endif
33 }
34 
35 /*
36  * @implemented
37  */
38 BOOL
39 WINAPI
41 {
42  ULONG ulObjType;
43 
44  ulObjType = GDI_HANDLE_GET_TYPE(hdc);
45  if (ulObjType == GDILoObjType_LO_METADC16_TYPE)
46  {
47  return TRUE;
48  }
49 
50  if (ulObjType == GDILoObjType_LO_ALTDC_TYPE)
51  {
52 #if 0
53  PLDC pLDC = GdiGetLDC(hdc);
54  if ( !pLDC )
55  {
57  return FALSE;
58  }
59  if ( pLDC->iType == LDC_EMFLDC) return TRUE;
60  return FALSE;
61 #endif
62  return TRUE;
63  }
64 
65  return FALSE;
66 }
67 
68 /*
69  * @implemented
70  */
71 BOOL
72 WINAPI
74 {
75 #if 0
77  {
79  return FALSE;
80  else
81  {
82  PLDC pLDC = GdiGetLDC(hDC);
83  if ( !pLDC )
84  {
86  return FALSE;
87  }
88  if ( pLDC->Flags & LDC_META_PRINT) return TRUE;
89  }
90  }
91  return FALSE;
92 #else
94  return FALSE;
95 #endif
96 }
97 
98 // NOTE: I wanna use GdiCreateLocalMetaFilePict and GdiConvertMetaFilePict
99 // functions for clipboard data conversion. --- katahiromz
100 
101 /*
102  * @implemented
103  */
104 HGLOBAL
105 WINAPI
107 {
108  HGLOBAL hMetaFilePict;
109  METAFILEPICT * pInfo;
110  HMETAFILE hMF = NULL;
111  BYTE * Buffer = NULL;
112  BYTE * BufNew = NULL;
113  HDC hDC = NULL;
114  UINT nSize, cSize;
115  DWORD iType;
116 
117  // NOTE: On Win32, there is no difference between the local heap and
118  // the global heap. GlobalAlloc and LocalAlloc have same effect.
119 
120  // allocate for METAFILEPICT
121  hMetaFilePict = GlobalAlloc(GHND | GMEM_SHARE, sizeof(METAFILEPICT));
122  pInfo = (METAFILEPICT *)GlobalLock(hMetaFilePict);
123  if (pInfo == NULL)
124  goto Exit;
125 
127 
128  // allocate buffer
130  if (Buffer == NULL)
131  goto Exit;
132 
133  // store to buffer
134  nSize = NtGdiGetServerMetaFileBits( hmo, nSize, Buffer, &iType, (PDWORD)&pInfo->mm, (PDWORD)&pInfo->xExt, (PDWORD)&pInfo->yExt );
135  if (nSize == 0)
136  goto Exit;
137 
138  if ( iType == GDITAG_TYPE_EMF ) // handle conversion to MFP
139  {
140  static const WCHAR szDisplayW[] = { 'D','I','S','P','L','A','Y','\0' };
141  HENHMETAFILE hEMF;
142  ENHMETAHEADER emh;
143 
145  if (hEMF == NULL)
146  goto Exit;
147 
148  if (!GetEnhMetaFileHeader( hEMF, sizeof(emh), &emh ))
149  {
150  DeleteEnhMetaFile(hEMF);
151  goto Exit;
152  }
153 
154  pInfo->mm = MM_ANISOTROPIC; // wine uses MM_ISOTROPIC.
155  pInfo->xExt = emh.rclFrame.right - emh.rclFrame.left; // Width
156  pInfo->yExt = emh.rclFrame.bottom - emh.rclFrame.top; // Height
157 
158  hDC = CreateDCW(szDisplayW, NULL, NULL, NULL);
159  if (hDC)
160  {
161  cSize = GetWinMetaFileBits( hEMF, 0, NULL, MM_ANISOTROPIC, hDC );
162  if (cSize)
163  {
164  BufNew = (BYTE *)LocalAlloc(LPTR, cSize);
165  if (BufNew)
166  {
167  nSize = GetWinMetaFileBits( hEMF, cSize, (LPBYTE)BufNew, MM_ANISOTROPIC, hDC );
168  if (nSize == cSize)
169  {
170  if (Buffer) LocalFree(Buffer);
171  Buffer = BufNew;
172  }
173  }
174  }
175  DeleteDC(hDC);
176  }
177  DeleteEnhMetaFile(hEMF);
178 
179  if (Buffer != BufNew)
180  goto Exit;
181  }
182 
183  // create metafile from buffer
185  if (hMF == NULL)
186  goto Exit;
187 
188  // set metafile handle
189  pInfo->hMF = hMF;
190 
191 Exit:
192  // clean up
193  if (Buffer)
194  LocalFree(Buffer);
195  if (pInfo)
196  GlobalUnlock(hMetaFilePict);
197  if (hMF == NULL)
198  {
199  // failure
200  GlobalFree(hMetaFilePict);
201  hMetaFilePict = NULL;
202  }
203 
204  return hMetaFilePict; // success if non-NULL
205 }
206 
207 /*
208  * @implemented
209  */
210 HANDLE
211 WINAPI
213 {
214  HMETAFILE hMF;
215  UINT nSize;
216  HANDLE hmo = NULL;
217  BYTE * Buffer = NULL;
218  METAFILEPICT * pInfo = NULL;
219 
220  // get METAFILEPICT pointer
221  pInfo = (METAFILEPICT *)GlobalLock(hMetaFilePict);
222  if (pInfo == NULL)
223  goto Exit;
224 
225  // get metafile handle
226  hMF = pInfo->hMF;
227 
228  // get size of buffer
229  nSize = GetMetaFileBitsEx(hMF, 0, NULL);
230  if (nSize == 0)
231  goto Exit;
232 
233  // allocate buffer
235  if (Buffer == NULL)
236  goto Exit;
237 
238  // store to buffer
240  if (nSize == 0)
241  goto Exit;
242 
243  hmo = NtGdiCreateServerMetaFile( GDITAG_TYPE_MFP, nSize, Buffer, pInfo->mm, pInfo->xExt, pInfo->yExt);
244 
245 Exit:
246  // clean up
247  if (pInfo)
248  GlobalUnlock(hMetaFilePict);
249  if (Buffer)
250  LocalFree(Buffer);
251  return hmo; // success if non-NULL
252 }
HANDLE WINAPI GdiConvertMetaFilePict(HGLOBAL hMetaFilePict)
Definition: metafile.c:212
HMETAFILE hMF
Definition: wingdi.h:2607
#define TRUE
Definition: types.h:120
HANDLE APIENTRY NtGdiCreateServerMetaFile(IN DWORD iType, IN ULONG cjData, IN PBYTE pjData, IN DWORD mm, IN DWORD xExt, IN DWORD yExt)
Definition: metafile.c:51
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
BOOL WINAPI GdiIsMetaPrintDC(HDC hDC)
Definition: metafile.c:73
ULONG APIENTRY NtGdiGetServerMetaFileBits(IN HANDLE hmo, IN ULONG cjData, OUT OPTIONAL PBYTE pjData, OUT PDWORD piType, OUT PDWORD pmm, OUT PDWORD pxExt, OUT PDWORD pyExt)
Definition: metafile.c:107
_In_ ULONG iType
Definition: winddi.h:3748
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
static HDC
Definition: imagelist.c:92
long bottom
Definition: polytest.cpp:53
HENHMETAFILE WINAPI SetEnhMetaFileBits(_In_ UINT nSize, _In_reads_bytes_(nSize) const BYTE *pb)
#define GMEM_SHARE
Definition: winbase.h:302
HGLOBAL WINAPI GdiCreateLocalMetaFilePict(HANDLE hmo)
Definition: metafile.c:106
ULONG Flags
Definition: ntgdihdl.h:278
long right
Definition: polytest.cpp:53
#define GHND
Definition: winbase.h:294
HMETAFILE WINAPI SetMetaFileBitsEx(UINT size, const BYTE *lpData)
Definition: metafile.c:1049
unsigned char * LPBYTE
Definition: typedefs.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
long top
Definition: polytest.cpp:53
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
BOOL WINAPI DeleteEnhMetaFile(_In_opt_ HENHMETAFILE)
UINT WINAPI GetMetaFileBitsEx(HMETAFILE hmf, UINT nSize, LPVOID buf)
Definition: metafile.c:1091
long left
Definition: polytest.cpp:53
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define GDITAG_TYPE_MFP
Definition: ntgdityp.h:246
PLDC FASTCALL GdiGetLDC(HDC hDC)
Definition: misc.c:785
RECTL rclFrame
Definition: wingdi.h:2322
__wchar_t WCHAR
Definition: xmlstorage.h:180
static void Exit(void)
Definition: sock.c:1331
BOOL WINAPI GdiIsPlayMetafileDC(HDC hDC)
Definition: metafile.c:20
#define WINAPI
Definition: msvc.h:6
#define LDC_META_PRINT
Definition: ntgdihdl.h:179
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define SetLastError(x)
Definition: compat.h:417
#define GDI_OBJECT_TYPE_METADC
Definition: gdi.h:57
BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
Definition: metafile.c:40
Definition: ntgdihdl.h:275
INT iType
Definition: ntgdihdl.h:279
UINT WINAPI GetEnhMetaFileHeader(_In_ HENHMETAFILE hemf, _In_ UINT nSize, _Out_writes_bytes_opt_(nSize) LPENHMETAHEADER lpEnhMetaHeader)
#define GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HDC hdc
Definition: main.c:9
#define MM_ANISOTROPIC
Definition: wingdi.h:866
unsigned char BYTE
Definition: mem.h:68
#define GDITAG_TYPE_EMF
Definition: ntgdityp.h:245
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI DeleteDC(_In_ HDC)
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
UINT WINAPI GetWinMetaFileBits(HENHMETAFILE hemf, UINT cbBuffer, LPBYTE lpbBuffer, INT map_mode, HDC hdcRef)
Definition: metafile.c:1259
unsigned int UINT
Definition: ndis.h:50
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
DWORD * PDWORD
Definition: pedump.c:68
HDC WINAPI CreateDCW(_In_opt_ LPCWSTR pszDriver, _In_opt_ LPCWSTR pszDevice, _In_opt_ LPCWSTR psz, _In_opt_ const DEVMODEW *pdmInit)
unsigned int ULONG
Definition: retypes.h:1
#define LPTR
Definition: winbase.h:362
#define UNIMPLEMENTED
Definition: debug.h:114
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
#define LDC_EMFLDC
Definition: gdi_private.h:57