blob: ddb25fec68a530882fcf55fdb5e2c11910c094b6 [file] [log] [blame]
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001/*
Huw D M Davies585c8461999-05-02 09:23:51 +00002 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
4 * 1999 Huw D M Davies
Peter Hunnisettc821a751999-12-04 03:56:53 +00005 *
6 *
7 * The enhanced format consists of the following elements:
8 *
9 * A header
10 * A table of handles to GDI objects
Peter Hunnisettc821a751999-12-04 03:56:53 +000011 * An array of metafile records
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +000012 * A private palette
Peter Hunnisettc821a751999-12-04 03:56:53 +000013 *
14 *
15 * The standard format consists of a header and an array of metafile records.
16 *
Huw D M Davies585c8461999-05-02 09:23:51 +000017 */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +000018
Alexandre Julliarda69b88b1998-03-15 20:29:56 +000019#include <string.h>
Marcus Meissnerae0a73d1999-01-20 14:11:07 +000020#include <assert.h>
Alexandre Julliard24a62ab2000-11-28 22:40:56 +000021#include "winnls.h"
Alexandre Julliarda69b88b1998-03-15 20:29:56 +000022#include "winbase.h"
Marcus Meissner6b9dd2e1999-03-18 17:39:57 +000023#include "wingdi.h"
Charles Suprin41043011998-11-07 12:56:31 +000024#include "winerror.h"
Huw D M Davies585c8461999-05-02 09:23:51 +000025#include "enhmetafile.h"
Alexandre Julliard15657091999-05-23 10:25:25 +000026#include "debugtools.h"
Huw D M Davies585c8461999-05-02 09:23:51 +000027#include "heap.h"
Peter Hunnisettc821a751999-12-04 03:56:53 +000028#include "metafile.h"
Alexandre Julliarda69b88b1998-03-15 20:29:56 +000029
Dimitrie O. Paun529da542000-11-27 23:54:25 +000030DEFAULT_DEBUG_CHANNEL(enhmetafile);
Huw D M Davies585c8461999-05-02 09:23:51 +000031
32/****************************************************************************
33 * EMF_Create_HENHMETAFILE
34 */
35HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, HFILE hFile, HANDLE
36 hMapping )
37{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000038 HENHMETAFILE hmf = 0;
39 ENHMETAFILEOBJ *metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
40 ENHMETAFILE_MAGIC, &hmf );
41 if (metaObj)
42 {
Huw D M Davies585c8461999-05-02 09:23:51 +000043 metaObj->emh = emh;
44 metaObj->hFile = hFile;
45 metaObj->hMapping = hMapping;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000046 GDI_ReleaseObj( hmf );
47 }
Huw D M Davies585c8461999-05-02 09:23:51 +000048 return hmf;
49}
50
51/****************************************************************************
52 * EMF_Delete_HENHMETAFILE
53 */
54static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
55{
56 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
57 ENHMETAFILE_MAGIC );
58 if(!metaObj) return FALSE;
59 if(metaObj->hMapping) {
60 UnmapViewOfFile( metaObj->emh );
61 CloseHandle( metaObj->hMapping );
62 CloseHandle( metaObj->hFile );
63 } else
Alexandre Julliard90476d62000-02-16 22:47:24 +000064 HeapFree( GetProcessHeap(), 0, metaObj->emh );
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000065 return GDI_FreeObject( hmf, metaObj );
Huw D M Davies585c8461999-05-02 09:23:51 +000066}
67
68/******************************************************************
69 * EMF_GetEnhMetaHeader
70 *
71 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
72 * Should be followed by call to EMF_ReleaseEnhMetaHeader
73 */
74static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
75{
76 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
77 ENHMETAFILE_MAGIC );
Alexandre Julliard15657091999-05-23 10:25:25 +000078 TRACE("hmf %04x -> enhmetaObj %p\n", hmf, metaObj);
Huw D M Davies0ae4e091999-06-12 06:49:52 +000079 return metaObj ? metaObj->emh : NULL;
Huw D M Davies585c8461999-05-02 09:23:51 +000080}
81
82/******************************************************************
83 * EMF_ReleaseEnhMetaHeader
84 *
85 * Releases ENHMETAHEADER associated with HENHMETAFILE
86 */
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000087static void EMF_ReleaseEnhMetaHeader( HENHMETAFILE hmf )
Huw D M Davies585c8461999-05-02 09:23:51 +000088{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000089 GDI_ReleaseObj( hmf );
Huw D M Davies585c8461999-05-02 09:23:51 +000090}
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000091
Alexandre Julliarda69b88b1998-03-15 20:29:56 +000092/*****************************************************************************
Huw D M Davies585c8461999-05-02 09:23:51 +000093 * EMF_GetEnhMetaFile
94 *
95 */
François Gougetda2b6a92001-01-06 01:29:18 +000096static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
Huw D M Davies585c8461999-05-02 09:23:51 +000097{
98 ENHMETAHEADER *emh;
99 HANDLE hMapping;
100
101 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
102 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
103
104 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
Alexandre Julliard15657091999-05-23 10:25:25 +0000105 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
Huw D M Davies585c8461999-05-02 09:23:51 +0000106 emh->iType, emh->dSignature);
107 UnmapViewOfFile( emh );
108 CloseHandle( hMapping );
109 return 0;
110 }
111 return EMF_Create_HENHMETAFILE( emh, hFile, hMapping );
112}
113
114
115/*****************************************************************************
116 * GetEnhMetaFileA (GDI32.174)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000117 *
118 *
119 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000120HENHMETAFILE WINAPI GetEnhMetaFileA(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000121 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000122 )
123{
Huw D M Davies585c8461999-05-02 09:23:51 +0000124 HENHMETAFILE hmf;
François Gougetda2b6a92001-01-06 01:29:18 +0000125 HANDLE hFile;
Huw D M Davies585c8461999-05-02 09:23:51 +0000126
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000127 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
128 OPEN_EXISTING, 0, 0);
Huw D M Davies585c8461999-05-02 09:23:51 +0000129 if (hFile == INVALID_HANDLE_VALUE) {
Alexandre Julliard15657091999-05-23 10:25:25 +0000130 WARN("could not open %s\n", lpszMetaFile);
Huw D M Davies585c8461999-05-02 09:23:51 +0000131 return 0;
132 }
133 hmf = EMF_GetEnhMetaFile( hFile );
134 if(!hmf)
135 CloseHandle( hFile );
136 return hmf;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000137}
138
139/*****************************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000140 * GetEnhMetaFileW (GDI32.180)
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +0000141 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000142HENHMETAFILE WINAPI GetEnhMetaFileW(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000143 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +0000144{
Huw D M Davies585c8461999-05-02 09:23:51 +0000145 HENHMETAFILE hmf;
François Gougetda2b6a92001-01-06 01:29:18 +0000146 HANDLE hFile;
Huw D M Davies585c8461999-05-02 09:23:51 +0000147
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000148 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
149 OPEN_EXISTING, 0, 0);
Huw D M Davies585c8461999-05-02 09:23:51 +0000150 if (hFile == INVALID_HANDLE_VALUE) {
Alexandre Julliard15657091999-05-23 10:25:25 +0000151 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
Huw D M Davies585c8461999-05-02 09:23:51 +0000152 return 0;
153 }
154 hmf = EMF_GetEnhMetaFile( hFile );
155 if(!hmf)
156 CloseHandle( hFile );
157 return hmf;
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +0000158}
159
160/*****************************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000161 * GetEnhMetaFileHeader (GDI32.178)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000162 *
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000163 * If buf is NULL, returns the size of buffer required.
164 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
165 * buf.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000166 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000167UINT WINAPI GetEnhMetaFileHeader(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000168 HENHMETAFILE hmf, /* [in] enhanced metafile */
169 UINT bufsize, /* [in] size of buffer */
170 LPENHMETAHEADER buf /* [out] buffer */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000171 )
172{
Huw D M Davies585c8461999-05-02 09:23:51 +0000173 LPENHMETAHEADER emh;
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000174 UINT size;
Huw D M Davies585c8461999-05-02 09:23:51 +0000175
Huw D M Davies585c8461999-05-02 09:23:51 +0000176 emh = EMF_GetEnhMetaHeader(hmf);
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000177 if(!emh) return FALSE;
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000178 size = emh->nSize;
179 if (!buf) {
180 EMF_ReleaseEnhMetaHeader(hmf);
181 return size;
182 }
183 size = min(size, bufsize);
184 memmove(buf, emh, size);
Huw D M Davies585c8461999-05-02 09:23:51 +0000185 EMF_ReleaseEnhMetaHeader(hmf);
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000186 return size;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000187}
188
189
190/*****************************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000191 * GetEnhMetaFileDescriptionA (GDI32.176)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000192 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000193UINT WINAPI GetEnhMetaFileDescriptionA(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000194 HENHMETAFILE hmf, /* [in] enhanced metafile */
195 UINT size, /* [in] size of buf */
196 LPSTR buf /* [out] buffer to receive description */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000197 )
198{
Huw D M Davies585c8461999-05-02 09:23:51 +0000199 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000200 DWORD len;
201 WCHAR *descrW;
202
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000203 if(!emh) return FALSE;
Huw D M Davies585c8461999-05-02 09:23:51 +0000204 if(emh->nDescription == 0 || emh->offDescription == 0) {
205 EMF_ReleaseEnhMetaHeader(hmf);
206 return 0;
207 }
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000208 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
209 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
210
Huw D M Davies585c8461999-05-02 09:23:51 +0000211 if (!buf || !size ) {
212 EMF_ReleaseEnhMetaHeader(hmf);
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000213 return len;
Huw D M Davies585c8461999-05-02 09:23:51 +0000214 }
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000215
216 len = min( size, len );
217 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
Huw D M Davies585c8461999-05-02 09:23:51 +0000218 EMF_ReleaseEnhMetaHeader(hmf);
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000219 return len;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000220}
221
222/*****************************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000223 * GetEnhMetaFileDescriptionW (GDI32.177)
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000224 *
225 * Copies the description string of an enhanced metafile into a buffer
226 * _buf_.
227 *
228 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
229 * number of characters copied.
230 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000231UINT WINAPI GetEnhMetaFileDescriptionW(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000232 HENHMETAFILE hmf, /* [in] enhanced metafile */
233 UINT size, /* [in] size of buf */
234 LPWSTR buf /* [out] buffer to receive description */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000235 )
236{
Huw D M Davies585c8461999-05-02 09:23:51 +0000237 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000238
239 if(!emh) return FALSE;
Huw D M Davies585c8461999-05-02 09:23:51 +0000240 if(emh->nDescription == 0 || emh->offDescription == 0) {
241 EMF_ReleaseEnhMetaHeader(hmf);
242 return 0;
243 }
244 if (!buf || !size ) {
245 EMF_ReleaseEnhMetaHeader(hmf);
246 return emh->nDescription;
247 }
248
Patrik Stridvall896889f1999-05-08 12:50:36 +0000249 memmove(buf, (char *) emh + emh->offDescription,
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000250 min(size,emh->nDescription)*sizeof(WCHAR));
Huw D M Davies585c8461999-05-02 09:23:51 +0000251 EMF_ReleaseEnhMetaHeader(hmf);
Francois Gouget6d77d3a2000-03-25 21:44:35 +0000252 return min(size, emh->nDescription);
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000253}
254
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000255/****************************************************************************
256 * SetEnhMetaFileBits (GDI32.315)
257 *
258 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
259 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000260HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000261{
Alexandre Julliard90476d62000-02-16 22:47:24 +0000262 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
Huw D M Davies585c8461999-05-02 09:23:51 +0000263 memmove(emh, buf, bufsize);
264 return EMF_Create_HENHMETAFILE( emh, 0, 0 );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000265}
266
267/*****************************************************************************
268 * GetEnhMetaFileBits (GDI32.175)
269 *
270 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000271UINT WINAPI GetEnhMetaFileBits(
272 HENHMETAFILE hmf,
273 UINT bufsize,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000274 LPBYTE buf
Peter Hunnisettc821a751999-12-04 03:56:53 +0000275)
276{
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000277 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
278 UINT size;
Peter Hunnisettc821a751999-12-04 03:56:53 +0000279
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000280 if(!emh) return 0;
Peter Hunnisettc821a751999-12-04 03:56:53 +0000281
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000282 size = emh->nBytes;
283 if( buf == NULL ) {
284 EMF_ReleaseEnhMetaHeader( hmf );
285 return size;
286 }
Peter Hunnisettc821a751999-12-04 03:56:53 +0000287
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000288 size = min( size, bufsize );
289 memmove(buf, emh, size);
Peter Hunnisettc821a751999-12-04 03:56:53 +0000290
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000291 EMF_ReleaseEnhMetaHeader( hmf );
292 return size;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000293}
294
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000295/*****************************************************************************
296 * PlayEnhMetaFileRecord (GDI32.264)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000297 *
298 * Render a single enhanced metafile record in the device context hdc.
299 *
300 * RETURNS
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000301 * TRUE (non zero) on success, FALSE on error.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000302 * BUGS
Alexandre Julliard54c27111998-03-29 19:44:57 +0000303 * Many unimplemented records.
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000304 * No error handling on record play failures (ie checking return codes)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000305 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000306BOOL WINAPI PlayEnhMetaFileRecord(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000307 HDC hdc, /* [in] device context in which to render EMF record */
308 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
309 const ENHMETARECORD *mr, /* [in] EMF record to render */
310 UINT handles /* [in] size of handle array */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000311 )
312{
313 int type;
Alexandre Julliard15657091999-05-23 10:25:25 +0000314 TRACE(
Alexandre Julliard54c27111998-03-29 19:44:57 +0000315 "hdc = %08x, handletable = %p, record = %p, numHandles = %d\n",
316 hdc, handletable, mr, handles);
317 if (!mr) return FALSE;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000318
Alexandre Julliard54c27111998-03-29 19:44:57 +0000319 type = mr->iType;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000320
Alexandre Julliard15657091999-05-23 10:25:25 +0000321 TRACE(" type=%d\n", type);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000322 switch(type)
323 {
324 case EMR_HEADER:
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000325 break;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000326 case EMR_EOF:
Alexandre Julliard54c27111998-03-29 19:44:57 +0000327 break;
Alexandre Julliard54c27111998-03-29 19:44:57 +0000328 case EMR_GDICOMMENT:
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000329 {
330 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
331 /* In an enhanced metafile, there can be both public and private GDI comments */
332 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
333 break;
334 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000335 case EMR_SETMAPMODE:
336 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000337 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
338 SetMapMode(hdc, pSetMapMode->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000339 break;
340 }
341 case EMR_SETBKMODE:
342 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000343 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
344 SetBkMode(hdc, pSetBkMode->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000345 break;
346 }
347 case EMR_SETBKCOLOR:
348 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000349 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
350 SetBkColor(hdc, pSetBkColor->crColor);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000351 break;
352 }
353 case EMR_SETPOLYFILLMODE:
354 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000355 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
356 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000357 break;
358 }
359 case EMR_SETROP2:
360 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000361 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
362 SetROP2(hdc, pSetROP2->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000363 break;
364 }
365 case EMR_SETSTRETCHBLTMODE:
366 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000367 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
368 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000369 break;
370 }
371 case EMR_SETTEXTALIGN:
372 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000373 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
374 SetTextAlign(hdc, pSetTextAlign->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000375 break;
376 }
377 case EMR_SETTEXTCOLOR:
378 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000379 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
380 SetTextColor(hdc, pSetTextColor->crColor);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000381 break;
382 }
383 case EMR_SAVEDC:
384 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000385 SaveDC(hdc);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000386 break;
387 }
388 case EMR_RESTOREDC:
389 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000390 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
391 RestoreDC(hdc, pRestoreDC->iRelative);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000392 break;
393 }
394 case EMR_INTERSECTCLIPRECT:
395 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000396 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
397 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
398 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000399 break;
400 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000401 case EMR_SELECTOBJECT:
402 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000403 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
404 if( pSelectObject->ihObject & 0x80000000 ) {
405 /* High order bit is set - it's a stock object
406 * Strip the high bit to get the index.
407 * See MSDN article Q142319
408 */
409 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
410 0x7fffffff ) );
411 } else {
412 /* High order bit wasn't set - not a stock object
413 */
414 SelectObject( hdc,
415 (handletable->objectHandle)[pSelectObject->ihObject] );
416 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000417 break;
418 }
419 case EMR_DELETEOBJECT:
420 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000421 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
422 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
423 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
Alexandre Julliard54c27111998-03-29 19:44:57 +0000424 break;
425 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000426 case EMR_SETWINDOWORGEX:
427 {
Eric Kohl9977e532001-01-29 00:31:31 +0000428 /*
429 * FIXME: The call to SetWindowOrgEx prevents EMFs from being scrolled
430 * by an application. This is very BAD!!!
431 */
432#if 0
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000433 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
434 SetWindowOrgEx(hdc, pSetWindowOrgEx->ptlOrigin.x,
435 pSetWindowOrgEx->ptlOrigin.y, NULL);
Eric Kohl9977e532001-01-29 00:31:31 +0000436#endif
Alexandre Julliard54c27111998-03-29 19:44:57 +0000437 break;
438 }
439 case EMR_SETWINDOWEXTEX:
440 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000441 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
442 SetWindowExtEx(hdc, pSetWindowExtEx->szlExtent.cx,
443 pSetWindowExtEx->szlExtent.cy, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000444 break;
445 }
446 case EMR_SETVIEWPORTORGEX:
447 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000448 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
449 SetViewportOrgEx(hdc, pSetViewportOrgEx->ptlOrigin.x,
450 pSetViewportOrgEx->ptlOrigin.y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000451 break;
452 }
453 case EMR_SETVIEWPORTEXTEX:
454 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000455 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
456 SetViewportExtEx(hdc, pSetViewportExtEx->szlExtent.cx,
457 pSetViewportExtEx->szlExtent.cy, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000458 break;
459 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000460 case EMR_CREATEPEN:
461 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000462 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
463 (handletable->objectHandle)[pCreatePen->ihPen] =
464 CreatePenIndirect(&pCreatePen->lopn);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000465 break;
466 }
467 case EMR_EXTCREATEPEN:
468 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000469 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
470 LOGBRUSH lb;
471 lb.lbStyle = pPen->elp.elpBrushStyle;
472 lb.lbColor = pPen->elp.elpColor;
473 lb.lbHatch = pPen->elp.elpHatch;
474
475 if(pPen->offBmi || pPen->offBits)
476 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
477
478 (handletable->objectHandle)[pPen->ihPen] =
479 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
480 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000481 break;
482 }
483 case EMR_CREATEBRUSHINDIRECT:
484 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000485 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
486 (handletable->objectHandle)[pBrush->ihBrush] =
487 CreateBrushIndirect(&pBrush->lb);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000488 break;
489 }
490 case EMR_EXTCREATEFONTINDIRECTW:
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000491 {
492 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
493 (handletable->objectHandle)[pFont->ihFont] =
494 CreateFontIndirectW(&pFont->elfw.elfLogFont);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000495 break;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000496 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000497 case EMR_MOVETOEX:
498 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000499 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
500 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000501 break;
502 }
503 case EMR_LINETO:
504 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000505 PEMRLINETO pLineTo = (PEMRLINETO) mr;
506 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000507 break;
508 }
509 case EMR_RECTANGLE:
510 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000511 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
512 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
513 pRect->rclBox.right, pRect->rclBox.bottom);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000514 break;
515 }
516 case EMR_ELLIPSE:
517 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000518 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
519 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
520 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000521 break;
522 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000523 case EMR_POLYGON16:
524 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000525 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
526 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
527 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
528 pPoly->cpts * sizeof(POINT) );
529 DWORD i;
530 for(i = 0; i < pPoly->cpts; i++)
531 CONV_POINT16TO32(pPoly->apts + i, pts + i);
532 Polygon(hdc, pts, pPoly->cpts);
533 HeapFree( GetProcessHeap(), 0, pts );
Alexandre Julliard54c27111998-03-29 19:44:57 +0000534 break;
535 }
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000536 case EMR_POLYLINE16:
537 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000538 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
539 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
540 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
541 pPoly->cpts * sizeof(POINT) );
542 DWORD i;
543 for(i = 0; i < pPoly->cpts; i++)
544 CONV_POINT16TO32(pPoly->apts + i, pts + i);
545 Polyline(hdc, pts, pPoly->cpts);
546 HeapFree( GetProcessHeap(), 0, pts );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000547 break;
548 }
Huw D M Daviesc7acd782000-08-20 03:40:04 +0000549 case EMR_POLYLINETO16:
550 {
551 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
552 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
553 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
554 pPoly->cpts * sizeof(POINT) );
555 DWORD i;
556 for(i = 0; i < pPoly->cpts; i++)
557 CONV_POINT16TO32(pPoly->apts + i, pts + i);
558 PolylineTo(hdc, pts, pPoly->cpts);
559 HeapFree( GetProcessHeap(), 0, pts );
560 break;
561 }
562 case EMR_POLYBEZIER16:
563 {
564 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
565 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
566 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
567 pPoly->cpts * sizeof(POINT) );
568 DWORD i;
569 for(i = 0; i < pPoly->cpts; i++)
570 CONV_POINT16TO32(pPoly->apts + i, pts + i);
571 PolyBezier(hdc, pts, pPoly->cpts);
572 HeapFree( GetProcessHeap(), 0, pts );
573 break;
574 }
575 case EMR_POLYBEZIERTO16:
576 {
577 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
578 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
579 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
580 pPoly->cpts * sizeof(POINT) );
581 DWORD i;
582 for(i = 0; i < pPoly->cpts; i++)
583 CONV_POINT16TO32(pPoly->apts + i, pts + i);
584 PolyBezierTo(hdc, pts, pPoly->cpts);
585 HeapFree( GetProcessHeap(), 0, pts );
586 break;
587 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000588 case EMR_POLYPOLYGON16:
589 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000590 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
591 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
592 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000593
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000594 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
595 pPolyPoly->cpts * sizeof(POINT) );
596 DWORD i;
597 for(i = 0; i < pPolyPoly->cpts; i++)
Alexandre Julliardf6168db2000-12-13 20:03:53 +0000598 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000599 pPolyPoly->nPolys) + i, pts + i);
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000600
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000601 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
602 HeapFree( GetProcessHeap(), 0, pts );
Alexandre Julliard54c27111998-03-29 19:44:57 +0000603 break;
604 }
Huw D M Daviesc7acd782000-08-20 03:40:04 +0000605 case EMR_POLYPOLYLINE16:
606 {
607 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
608 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
609 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
610
611 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
612 pPolyPoly->cpts * sizeof(POINT) );
613 DWORD i;
614 for(i = 0; i < pPolyPoly->cpts; i++)
Alexandre Julliardf6168db2000-12-13 20:03:53 +0000615 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
Huw D M Daviesc7acd782000-08-20 03:40:04 +0000616 pPolyPoly->nPolys) + i, pts + i);
617
618 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
619 HeapFree( GetProcessHeap(), 0, pts );
620 break;
621 }
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000622
Jason McMullane113b091999-02-09 14:08:57 +0000623 case EMR_STRETCHDIBITS:
624 {
Dmitry Timoshkovc2b32a72001-02-12 01:19:23 +0000625 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
Jason McMullane113b091999-02-09 14:08:57 +0000626
Dmitry Timoshkovc2b32a72001-02-12 01:19:23 +0000627 StretchDIBits(hdc,
628 pStretchDIBits->xDest,
629 pStretchDIBits->yDest,
630 pStretchDIBits->cxDest,
631 pStretchDIBits->cyDest,
632 pStretchDIBits->xSrc,
633 pStretchDIBits->ySrc,
634 pStretchDIBits->cxSrc,
635 pStretchDIBits->cySrc,
636 (BYTE *)mr + pStretchDIBits->offBitsSrc,
637 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
638 pStretchDIBits->iUsageSrc,
639 pStretchDIBits->dwRop);
Jason McMullane113b091999-02-09 14:08:57 +0000640 break;
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000641 }
Dmitry Timoshkovc2b32a72001-02-12 01:19:23 +0000642
643 case EMR_EXTTEXTOUTA:
644 {
645 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
646 RECT rc;
647
648 rc.left = pExtTextOutA->emrtext.rcl.left;
649 rc.top = pExtTextOutA->emrtext.rcl.top;
650 rc.right = pExtTextOutA->emrtext.rcl.right;
651 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
652 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
653 pExtTextOutA->emrtext.fOptions, &rc,
654 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
655 (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx));
656 break;
657 }
658
Alexandre Julliard54c27111998-03-29 19:44:57 +0000659 case EMR_EXTTEXTOUTW:
Dmitry Timoshkovc2b32a72001-02-12 01:19:23 +0000660 {
661 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
662 RECT rc;
Eric Kohld40ef6b2001-01-24 19:38:38 +0000663
Dmitry Timoshkovc2b32a72001-02-12 01:19:23 +0000664 rc.left = pExtTextOutW->emrtext.rcl.left;
665 rc.top = pExtTextOutW->emrtext.rcl.top;
666 rc.right = pExtTextOutW->emrtext.rcl.right;
667 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
668 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
669 pExtTextOutW->emrtext.fOptions, &rc,
670 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
671 (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx));
Alexandre Julliard54c27111998-03-29 19:44:57 +0000672 break;
Dmitry Timoshkovc2b32a72001-02-12 01:19:23 +0000673 }
674
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000675 case EMR_CREATEPALETTE:
676 {
677 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
Alexandre Julliard54c27111998-03-29 19:44:57 +0000678
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000679 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
680 CreatePalette( &lpCreatePal->lgpl );
681
682 break;
683 }
684
685 case EMR_SELECTPALETTE:
686 {
687 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
688
Eric Kohld40ef6b2001-01-24 19:38:38 +0000689 if( lpSelectPal->ihPal & 0x80000000 ) {
690 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
691 } else {
692 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
693 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
694 }
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000695 break;
696 }
697
698 case EMR_REALIZEPALETTE:
699 {
700 RealizePalette( hdc );
701 break;
702 }
703
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000704 case EMR_EXTSELECTCLIPRGN:
705 {
706 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
707
Eric Kohl02919df2000-12-21 20:16:56 +0000708 if ((lpRgn->cbRgnData == 0) && (lpRgn->iMode == RGN_COPY)) {
709 ExtSelectClipRgn( hdc, 0, RGN_COPY );
710 } else {
711 FIXME("EMR_EXTSELECTCLIPRGN cbRgnData %lu\n", lpRgn->cbRgnData);
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000712
Eric Kohl02919df2000-12-21 20:16:56 +0000713 /* Need to make a region out of the RGNDATA we have */
714/* ExtCreateRegion(....); */
715/* ExtSelectClipRgn( hdc, ..., (INT)(lpRgn->iMode) ); */
716 }
717
718 break;
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000719 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000720
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000721 case EMR_SETMETARGN:
722 {
723 SetMetaRgn( hdc );
724 break;
725 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000726
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000727 case EMR_SETWORLDTRANSFORM:
728 {
729 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
730 SetWorldTransform( hdc, &lpXfrm->xform );
731 break;
732 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000733
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000734 case EMR_POLYBEZIER:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000735 {
736 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000737 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000738 break;
739 }
740
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000741 case EMR_POLYGON:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000742 {
743 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000744 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000745 break;
746 }
747
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000748 case EMR_POLYLINE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000749 {
750 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000751 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000752 break;
753 }
754
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000755 case EMR_POLYBEZIERTO:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000756 {
757 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000758 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
759 (UINT)lpPolyBezierTo->cptl );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000760 break;
761 }
762
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000763 case EMR_POLYLINETO:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000764 {
765 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000766 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
767 (UINT)lpPolyLineTo->cptl );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000768 break;
769 }
770
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000771 case EMR_POLYPOLYLINE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000772 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000773 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
774 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000775
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000776 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
777 pPolyPolyline->nPolys),
778 pPolyPolyline->aPolyCounts,
779 pPolyPolyline->nPolys );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000780
781 break;
782 }
783
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000784 case EMR_POLYPOLYGON:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000785 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000786 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000787
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000788 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000789
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000790 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
791 pPolyPolygon->nPolys),
792 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000793 break;
794 }
795
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000796 case EMR_SETBRUSHORGEX:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000797 {
798 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
799
800 SetBrushOrgEx( hdc,
801 (INT)lpSetBrushOrgEx->ptlOrigin.x,
802 (INT)lpSetBrushOrgEx->ptlOrigin.y,
803 NULL );
804
805 break;
806 }
807
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000808 case EMR_SETPIXELV:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000809 {
810 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
811
812 SetPixelV( hdc,
813 (INT)lpSetPixelV->ptlPixel.x,
814 (INT)lpSetPixelV->ptlPixel.y,
815 lpSetPixelV->crColor );
816
817 break;
818 }
819
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000820 case EMR_SETMAPPERFLAGS:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000821 {
822 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
823
824 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
825
826 break;
827 }
828
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000829 case EMR_SETCOLORADJUSTMENT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000830 {
831 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
832
833 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
834
835 break;
836 }
837
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000838 case EMR_OFFSETCLIPRGN:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000839 {
840 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
841
842 OffsetClipRgn( hdc,
843 (INT)lpOffsetClipRgn->ptlOffset.x,
844 (INT)lpOffsetClipRgn->ptlOffset.y );
845
846 break;
847 }
848
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000849 case EMR_EXCLUDECLIPRECT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000850 {
851 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
852
853 ExcludeClipRect( hdc,
854 lpExcludeClipRect->rclClip.left,
855 lpExcludeClipRect->rclClip.top,
856 lpExcludeClipRect->rclClip.right,
857 lpExcludeClipRect->rclClip.bottom );
858
859 break;
860 }
861
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000862 case EMR_SCALEVIEWPORTEXTEX:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000863 {
864 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
865
866 ScaleViewportExtEx( hdc,
867 lpScaleViewportExtEx->xNum,
868 lpScaleViewportExtEx->xDenom,
869 lpScaleViewportExtEx->yNum,
870 lpScaleViewportExtEx->yDenom,
871 NULL );
872
873 break;
874 }
875
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000876 case EMR_SCALEWINDOWEXTEX:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000877 {
878 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
879
880 ScaleWindowExtEx( hdc,
881 lpScaleWindowExtEx->xNum,
882 lpScaleWindowExtEx->xDenom,
883 lpScaleWindowExtEx->yNum,
884 lpScaleWindowExtEx->yDenom,
885 NULL );
886
887 break;
888 }
889
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000890 case EMR_MODIFYWORLDTRANSFORM:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000891 {
892 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
893
Eric Kohld40ef6b2001-01-24 19:38:38 +0000894 ModifyWorldTransform( hdc, &lpModifyWorldTrans->xform,
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000895 lpModifyWorldTrans->iMode );
896
897 break;
898 }
899
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000900 case EMR_ANGLEARC:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000901 {
902 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
903
904 AngleArc( hdc,
905 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
906 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
907 lpAngleArc->eSweepAngle );
908
909 break;
910 }
911
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000912 case EMR_ROUNDRECT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000913 {
914 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
915
916 RoundRect( hdc,
917 lpRoundRect->rclBox.left,
918 lpRoundRect->rclBox.top,
919 lpRoundRect->rclBox.right,
920 lpRoundRect->rclBox.bottom,
921 lpRoundRect->szlCorner.cx,
922 lpRoundRect->szlCorner.cy );
923
924 break;
925 }
926
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000927 case EMR_ARC:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000928 {
929 PEMRARC lpArc = (PEMRARC)mr;
930
931 Arc( hdc,
932 (INT)lpArc->rclBox.left,
933 (INT)lpArc->rclBox.top,
934 (INT)lpArc->rclBox.right,
935 (INT)lpArc->rclBox.bottom,
936 (INT)lpArc->ptlStart.x,
937 (INT)lpArc->ptlStart.y,
938 (INT)lpArc->ptlEnd.x,
939 (INT)lpArc->ptlEnd.y );
940
941 break;
942 }
943
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000944 case EMR_CHORD:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000945 {
946 PEMRCHORD lpChord = (PEMRCHORD)mr;
947
948 Chord( hdc,
949 (INT)lpChord->rclBox.left,
950 (INT)lpChord->rclBox.top,
951 (INT)lpChord->rclBox.right,
952 (INT)lpChord->rclBox.bottom,
953 (INT)lpChord->ptlStart.x,
954 (INT)lpChord->ptlStart.y,
955 (INT)lpChord->ptlEnd.x,
956 (INT)lpChord->ptlEnd.y );
957
958 break;
959 }
960
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000961 case EMR_PIE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000962 {
963 PEMRPIE lpPie = (PEMRPIE)mr;
964
965 Pie( hdc,
966 (INT)lpPie->rclBox.left,
967 (INT)lpPie->rclBox.top,
968 (INT)lpPie->rclBox.right,
969 (INT)lpPie->rclBox.bottom,
970 (INT)lpPie->ptlStart.x,
971 (INT)lpPie->ptlStart.y,
972 (INT)lpPie->ptlEnd.x,
973 (INT)lpPie->ptlEnd.y );
974
975 break;
976 }
977
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000978 case EMR_ARCTO:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000979 {
980 PEMRARC lpArcTo = (PEMRARC)mr;
981
982 ArcTo( hdc,
983 (INT)lpArcTo->rclBox.left,
984 (INT)lpArcTo->rclBox.top,
985 (INT)lpArcTo->rclBox.right,
986 (INT)lpArcTo->rclBox.bottom,
987 (INT)lpArcTo->ptlStart.x,
988 (INT)lpArcTo->ptlStart.y,
989 (INT)lpArcTo->ptlEnd.x,
990 (INT)lpArcTo->ptlEnd.y );
991
992 break;
993 }
994
995 case EMR_EXTFLOODFILL:
996 {
997 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
998
999 ExtFloodFill( hdc,
1000 (INT)lpExtFloodFill->ptlStart.x,
1001 (INT)lpExtFloodFill->ptlStart.y,
1002 lpExtFloodFill->crColor,
1003 (UINT)lpExtFloodFill->iMode );
1004
1005 break;
1006 }
1007
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001008 case EMR_POLYDRAW:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001009 {
1010 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001011 PolyDraw( hdc,
1012 (const LPPOINT)lpPolyDraw->aptl,
1013 lpPolyDraw->abTypes,
1014 (INT)lpPolyDraw->cptl );
1015
1016 break;
1017 }
1018
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001019 case EMR_SETARCDIRECTION:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001020 {
1021 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001022 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001023 break;
1024 }
1025
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001026 case EMR_SETMITERLIMIT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001027 {
1028 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001029 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001030 break;
1031 }
1032
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001033 case EMR_BEGINPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001034 {
1035 BeginPath( hdc );
1036 break;
1037 }
1038
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001039 case EMR_ENDPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001040 {
1041 EndPath( hdc );
1042 break;
1043 }
1044
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001045 case EMR_CLOSEFIGURE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001046 {
1047 CloseFigure( hdc );
1048 break;
1049 }
1050
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001051 case EMR_FILLPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001052 {
1053 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001054 FillPath( hdc );
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001055 break;
1056 }
1057
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001058 case EMR_STROKEANDFILLPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001059 {
1060 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001061 StrokeAndFillPath( hdc );
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001062 break;
1063 }
1064
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001065 case EMR_STROKEPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001066 {
1067 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001068 StrokePath( hdc );
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001069 break;
1070 }
1071
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001072 case EMR_FLATTENPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001073 {
1074 FlattenPath( hdc );
1075 break;
1076 }
1077
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001078 case EMR_WIDENPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001079 {
1080 WidenPath( hdc );
1081 break;
1082 }
1083
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001084 case EMR_SELECTCLIPPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001085 {
1086 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001087 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001088 break;
1089 }
1090
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001091 case EMR_ABORTPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001092 {
1093 AbortPath( hdc );
1094 break;
1095 }
1096
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001097 case EMR_CREATECOLORSPACE:
1098 {
1099 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001100 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1101 CreateColorSpaceA( &lpCreateColorSpace->lcs );
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001102 break;
1103 }
1104
1105 case EMR_SETCOLORSPACE:
1106 {
1107 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001108 SetColorSpace( hdc,
1109 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001110 break;
1111 }
1112
1113 case EMR_DELETECOLORSPACE:
1114 {
1115 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001116 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001117 break;
1118 }
1119
1120 case EMR_SETICMMODE:
1121 {
1122 PERMSETICMMODE lpSetICMMode = (PERMSETICMMODE)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +00001123 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001124 break;
1125 }
1126
1127 case EMR_PIXELFORMAT:
1128 {
1129 INT iPixelFormat;
1130 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1131
1132 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1133 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1134
1135 break;
1136 }
1137
1138 case EMR_SETPALETTEENTRIES:
1139 {
1140 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1141
1142 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1143 (UINT)lpSetPaletteEntries->iStart,
1144 (UINT)lpSetPaletteEntries->cEntries,
1145 lpSetPaletteEntries->aPalEntries );
1146
1147 break;
1148 }
1149
1150 case EMR_RESIZEPALETTE:
1151 {
1152 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1153
1154 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1155 (UINT)lpResizePalette->cEntries );
1156
1157 break;
1158 }
1159
1160 case EMR_CREATEDIBPATTERNBRUSHPT:
1161 {
1162 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1163
1164 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1165 LPVOID lpPackedStruct = HeapAlloc( GetProcessHeap(),
1166 0,
1167 lpCreate->cbBmi + lpCreate->cbBits );
1168 /* Now pack this structure */
1169 memcpy( lpPackedStruct,
1170 ((BYTE*)lpCreate) + lpCreate->offBmi,
1171 lpCreate->cbBmi );
1172 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1173 ((BYTE*)lpCreate) + lpCreate->offBits,
1174 lpCreate->cbBits );
1175
1176 (handletable->objectHandle)[lpCreate->ihBrush] =
1177 CreateDIBPatternBrushPt( lpPackedStruct,
1178 (UINT)lpCreate->iUsage );
1179
1180 break;
1181 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001182
Dmitry Timoshkovc2b32a72001-02-12 01:19:23 +00001183 case EMR_CREATEMONOBRUSH:
1184 {
1185 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1186 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1187 HBITMAP hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1188 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, 0);
1189 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1190 /* CreatePatternBrush created a copy of the bitmap */
1191 DeleteObject(hBmp);
1192 break;
1193 }
1194
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001195 case EMR_BITBLT:
1196 case EMR_STRETCHBLT:
1197 case EMR_MASKBLT:
1198 case EMR_PLGBLT:
1199 case EMR_SETDIBITSTODEVICE:
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001200 case EMR_POLYDRAW16:
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001201 case EMR_POLYTEXTOUTA:
1202 case EMR_POLYTEXTOUTW:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001203 case EMR_FILLRGN:
1204 case EMR_FRAMERGN:
1205 case EMR_INVERTRGN:
1206 case EMR_PAINTRGN:
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001207 case EMR_GLSRECORD:
1208 case EMR_GLSBOUNDEDRECORD:
Alexandre Julliard54c27111998-03-29 19:44:57 +00001209 default:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001210 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1211 record then ignore and return TRUE. */
Alexandre Julliard15657091999-05-23 10:25:25 +00001212 FIXME("type %d is unimplemented\n", type);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001213 break;
1214 }
Alexandre Julliard54c27111998-03-29 19:44:57 +00001215 return TRUE;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001216}
1217
1218
1219/*****************************************************************************
1220 *
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001221 * EnumEnhMetaFile (GDI32.79)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001222 *
1223 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1224 * for each
1225 * record. Returns when either every record has been used or
1226 * when _EnhMetaFunc_ returns FALSE.
1227 *
1228 *
1229 * RETURNS
1230 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1231 * returns FALSE.
1232 *
1233 * BUGS
Alexandre Julliard54c27111998-03-29 19:44:57 +00001234 * Ignores rect.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001235 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001236BOOL WINAPI EnumEnhMetaFile(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +00001237 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
1238 HENHMETAFILE hmf, /* [in] EMF to walk */
1239 ENHMFENUMPROC callback, /* [in] callback function */
1240 LPVOID data, /* [in] optional data for callback function */
1241 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001242 )
1243{
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001244 BOOL ret;
1245 ENHMETAHEADER *emh, *emhTemp;
1246 ENHMETARECORD *emr;
1247 DWORD offset;
Joerg Mayer4d756402001-01-10 22:45:33 +00001248 UINT i;
Huw D M Davies0ae4e091999-06-12 06:49:52 +00001249 HANDLETABLE *ht;
Huw D M Davies585c8461999-05-02 09:23:51 +00001250 INT savedMode = 0;
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001251 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1252 XFORM savedXform, xform;
Eric Kohld40ef6b2001-01-24 19:38:38 +00001253 HPEN hPen = (HPEN)NULL;
1254 HBRUSH hBrush = (HBRUSH)NULL;
1255 HFONT hFont = (HFONT)NULL;
1256
1257 XFORM outXform;
Huw D M Davies0ae4e091999-06-12 06:49:52 +00001258
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001259 if(!lpRect)
1260 {
1261 SetLastError(ERROR_INVALID_PARAMETER);
1262 return FALSE;
1263 }
1264
1265 emh = EMF_GetEnhMetaHeader(hmf);
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001266 if(!emh) {
1267 SetLastError(ERROR_INVALID_HANDLE);
1268 return FALSE;
1269 }
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001270
1271 /* Copy the metafile into memory, because we need to avoid deadlock. */
1272 emhTemp = HeapAlloc(GetProcessHeap(), 0, emh->nSize + emh->nBytes);
1273 if(!emhTemp)
1274 {
1275 EMF_ReleaseEnhMetaHeader(hmf);
1276 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001277 return FALSE;
1278 }
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001279 memcpy(emhTemp, emh, emh->nSize + emh->nBytes);
1280 emh = emhTemp;
1281 EMF_ReleaseEnhMetaHeader(hmf);
1282
Huw D M Davies280aeb92000-03-30 20:22:41 +00001283 ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001284 sizeof(HANDLETABLE) * emh->nHandles );
1285 if(!ht)
1286 {
1287 HeapFree(GetProcessHeap(), 0, emhTemp);
1288 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1289 return FALSE;
1290 }
Huw D M Davies280aeb92000-03-30 20:22:41 +00001291 ht->objectHandle[0] = hmf;
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001292
Eric Kohld40ef6b2001-01-24 19:38:38 +00001293 if (hdc)
1294 {
1295 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
1296 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
1297 xscale = (FLOAT)(lpRect->right - lpRect->left) * 100.0 /
1298 (emh->rclFrame.right - emh->rclFrame.left) * xSrcPixSize;
1299 yscale = (FLOAT)(lpRect->bottom - lpRect->top) * 100.0 /
1300 (emh->rclFrame.bottom - emh->rclFrame.top) * ySrcPixSize;
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001301
Eric Kohld40ef6b2001-01-24 19:38:38 +00001302 xform.eM11 = xscale;
1303 xform.eM12 = 0;
1304 xform.eM21 = 0;
1305 xform.eM22 = yscale;
1306 xform.eDx = (FLOAT)lpRect->left - (xscale * emh->rclFrame.left * 0.5);
1307 xform.eDy = (FLOAT)lpRect->top - (yscale * (FLOAT)emh->rclFrame.top * 0.5);
1308
1309 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1310 GetWorldTransform(hdc, &savedXform);
1311
1312 if (!ModifyWorldTransform(hdc, &xform, MWT_RIGHTMULTIPLY)) {
1313 ERR("World transform failed!\n");
1314 }
1315
1316 GetWorldTransform(hdc, &outXform);
1317
1318 /* save the current pen, brush and font */
1319 hPen = GetCurrentObject(hdc, OBJ_PEN);
1320 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
1321 hFont = GetCurrentObject(hdc, OBJ_FONT);
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001322 }
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001323
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001324 TRACE("nSize = %ld, nBytes = %ld, nHandles = %d, nRecords = %ld, nPalEntries = %ld\n",
1325 emh->nSize, emh->nBytes, emh->nHandles, emh->nRecords, emh->nPalEntries);
1326
1327 ret = TRUE;
1328 offset = 0;
1329 while(ret && offset < emh->nBytes)
1330 {
1331 emr = (ENHMETARECORD *)((char *)emh + offset);
1332 TRACE("Calling EnumFunc with record type %ld, size %ld\n", emr->iType, emr->nSize);
Eric Kohld40ef6b2001-01-24 19:38:38 +00001333 ret = (*callback)(hdc, ht, emr, emh->nHandles, data);
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001334 offset += emr->nSize;
Huw D M Davies585c8461999-05-02 09:23:51 +00001335 }
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001336
Eric Kohld40ef6b2001-01-24 19:38:38 +00001337 if (hdc)
1338 {
1339 /* restore pen, brush and font */
1340 SelectObject(hdc, hBrush);
1341 SelectObject(hdc, hPen);
1342 SelectObject(hdc, hFont);
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001343
Eric Kohld40ef6b2001-01-24 19:38:38 +00001344 SetWorldTransform(hdc, &savedXform);
1345 if (savedMode)
1346 SetGraphicsMode(hdc, savedMode);
1347 }
1348
1349 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
Huw D M Davies280aeb92000-03-30 20:22:41 +00001350 if( (ht->objectHandle)[i] )
1351 DeleteObject( (ht->objectHandle)[i] );
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001352
Huw D M Davies585c8461999-05-02 09:23:51 +00001353 HeapFree( GetProcessHeap(), 0, ht );
Dmitry Timoshkovff59c332000-10-24 01:37:49 +00001354 HeapFree(GetProcessHeap(), 0, emhTemp);
1355
Huw D M Davies585c8461999-05-02 09:23:51 +00001356 return ret;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001357}
1358
Huw D M Davies280aeb92000-03-30 20:22:41 +00001359static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
1360 ENHMETARECORD *emr,
1361 INT handles, LPVOID data)
1362{
1363 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
1364}
1365
1366/**************************************************************************
1367 * PlayEnhMetaFile (GDI32.263)
1368 *
1369 * Renders an enhanced metafile into a specified rectangle *lpRect
1370 * in device context hdc.
1371 *
1372 */
1373BOOL WINAPI PlayEnhMetaFile(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +00001374 HDC hdc, /* [in] DC to render into */
1375 HENHMETAFILE hmf, /* [in] metafile to render */
1376 const RECT *lpRect /* [in] rectangle to place metafile inside */
Huw D M Davies280aeb92000-03-30 20:22:41 +00001377 )
1378{
1379 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
1380 lpRect);
1381}
1382
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001383/*****************************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00001384 * DeleteEnhMetaFile (GDI32.68)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001385 *
1386 * Deletes an enhanced metafile and frees the associated storage.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001387 */
Huw D M Davies585c8461999-05-02 09:23:51 +00001388BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
1389{
1390 return EMF_Delete_HENHMETAFILE( hmf );
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001391}
1392
1393/*****************************************************************************
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001394 * CopyEnhMetaFileA (GDI32.21) Duplicate an enhanced metafile
1395 *
1396 *
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001397 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001398HENHMETAFILE WINAPI CopyEnhMetaFileA(
Huw D M Davies585c8461999-05-02 09:23:51 +00001399 HENHMETAFILE hmfSrc,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001400 LPCSTR file)
1401{
Huw D M Davies585c8461999-05-02 09:23:51 +00001402 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
1403 HENHMETAFILE hmfDst;
1404
Huw D M Davies0ae4e091999-06-12 06:49:52 +00001405 if(!emrSrc) return FALSE;
Huw D M Davies585c8461999-05-02 09:23:51 +00001406 if (!file) {
Alexandre Julliard90476d62000-02-16 22:47:24 +00001407 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
Huw D M Davies585c8461999-05-02 09:23:51 +00001408 memcpy( emrDst, emrSrc, emrSrc->nBytes );
1409 hmfDst = EMF_Create_HENHMETAFILE( emrDst, 0, 0 );
1410 } else {
François Gougetda2b6a92001-01-06 01:29:18 +00001411 HANDLE hFile;
Huw D M Davies585c8461999-05-02 09:23:51 +00001412 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0, NULL,
François Gougetda2b6a92001-01-06 01:29:18 +00001413 CREATE_ALWAYS, 0, 0);
Huw D M Davies585c8461999-05-02 09:23:51 +00001414 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
1415 hmfDst = EMF_GetEnhMetaFile( hFile );
1416 }
1417 EMF_ReleaseEnhMetaHeader( hmfSrc );
1418 return hmfDst;
Alexandre Julliard54c27111998-03-29 19:44:57 +00001419}
1420
Huw D M Davies585c8461999-05-02 09:23:51 +00001421
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001422/* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1423typedef struct tagEMF_PaletteCopy
1424{
1425 UINT cEntries;
1426 LPPALETTEENTRY lpPe;
1427} EMF_PaletteCopy;
1428
1429/***************************************************************
1430 * Find the EMR_EOF record and then use it to find the
1431 * palette entries for this enhanced metafile.
1432 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1433 * which contains the max number of elements to copy and where
1434 * to copy them to.
1435 *
1436 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1437 */
1438INT CALLBACK cbEnhPaletteCopy( HDC a,
1439 LPHANDLETABLE b,
1440 LPENHMETARECORD lpEMR,
1441 INT c,
1442 LPVOID lpData )
1443{
1444
1445 if ( lpEMR->iType == EMR_EOF )
1446 {
1447 PEMREOF lpEof = (PEMREOF)lpEMR;
1448 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
Francois Gouget6d77d3a2000-03-25 21:44:35 +00001449 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001450
1451 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
1452
1453 memcpy( (LPVOID)info->lpPe,
1454 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
1455 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
1456
1457 /* Update the passed data as a return code */
1458 info->lpPe = NULL; /* Palettes were copied! */
1459 info->cEntries = (UINT)dwNumPalToCopy;
1460
1461 return FALSE; /* That's all we need */
1462 }
1463
1464 return TRUE;
1465}
1466
Charles Suprin41043011998-11-07 12:56:31 +00001467/*****************************************************************************
1468 * GetEnhMetaFilePaletteEntries (GDI32.179)
1469 *
1470 * Copy the palette and report size
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001471 *
1472 * BUGS: Error codes (SetLastError) are not set on failures
Charles Suprin41043011998-11-07 12:56:31 +00001473 */
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001474UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
1475 UINT cEntries,
1476 LPPALETTEENTRY lpPe )
Charles Suprin41043011998-11-07 12:56:31 +00001477{
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001478 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
1479 UINT uReturnValue = GDI_ERROR;
1480 EMF_PaletteCopy infoForCallBack;
1481
1482 TRACE( "(%04x,%d,%p)\n", hEmf, cEntries, lpPe );
1483
1484 /* First check if there are any palettes associated with
1485 this metafile. */
1486 if ( enhHeader->nPalEntries == 0 )
1487 {
1488 /* No palette associated with this enhanced metafile */
1489 uReturnValue = 0;
1490 goto done;
1491 }
1492
1493 /* Is the user requesting the number of palettes? */
1494 if ( lpPe == NULL )
1495 {
1496 uReturnValue = (UINT)enhHeader->nPalEntries;
1497 goto done;
1498 }
1499
1500 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1501 infoForCallBack.cEntries = cEntries;
1502 infoForCallBack.lpPe = lpPe;
1503
1504 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
1505 &infoForCallBack, NULL ) )
1506 {
1507 goto done;
1508 }
1509
1510 /* Verify that the callback executed correctly */
1511 if ( infoForCallBack.lpPe != NULL )
1512 {
1513 /* Callback proc had error! */
1514 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1515 goto done;
1516 }
1517
1518 uReturnValue = infoForCallBack.cEntries;
1519
1520done:
1521
1522 EMF_ReleaseEnhMetaHeader( hEmf );
1523
1524 return uReturnValue;
Charles Suprin41043011998-11-07 12:56:31 +00001525}
1526
Charles Suprin41043011998-11-07 12:56:31 +00001527/******************************************************************
1528 * SetWinMetaFileBits (GDI32.343)
1529 *
1530 * Translate from old style to new style.
Peter Hunnisettc821a751999-12-04 03:56:53 +00001531 *
1532 * BUGS: - This doesn't take the DC and scaling into account
1533 * - Most record conversions aren't implemented
1534 * - Handle slot assignement is primative and most likely doesn't work
Charles Suprin41043011998-11-07 12:56:31 +00001535 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001536HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
Charles Suprin41043011998-11-07 12:56:31 +00001537 CONST BYTE *lpbBuffer,
Alexandre Julliarda3960291999-02-26 11:11:13 +00001538 HDC hdcRef,
1539 CONST METAFILEPICT *lpmfp
Charles Suprin41043011998-11-07 12:56:31 +00001540 )
1541{
Peter Hunnisettc821a751999-12-04 03:56:53 +00001542 HENHMETAFILE hMf;
1543 LPVOID lpNewEnhMetaFileBuffer = NULL;
1544 UINT uNewEnhMetaFileBufferSize = 0;
1545 BOOL bFoundEOF = FALSE;
Charles Suprin41043011998-11-07 12:56:31 +00001546
Peter Hunnisettc821a751999-12-04 03:56:53 +00001547 FIXME( "(%d,%p,%04x,%p):stub\n", cbBuffer, lpbBuffer, hdcRef, lpmfp );
1548
1549 /* 1. Get the header - skip over this and get straight to the records */
1550
1551 uNewEnhMetaFileBufferSize = sizeof( ENHMETAHEADER );
Alexandre Julliard90476d62000-02-16 22:47:24 +00001552 lpNewEnhMetaFileBuffer = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
Peter Hunnisettc821a751999-12-04 03:56:53 +00001553 uNewEnhMetaFileBufferSize );
1554
1555 if( lpNewEnhMetaFileBuffer == NULL )
1556 {
1557 goto error;
1558 }
1559
1560 /* Fill in the header record */
1561 {
1562 LPENHMETAHEADER lpNewEnhMetaFileHeader = (LPENHMETAHEADER)lpNewEnhMetaFileBuffer;
1563
1564 lpNewEnhMetaFileHeader->iType = EMR_HEADER;
1565 lpNewEnhMetaFileHeader->nSize = sizeof( ENHMETAHEADER );
1566
1567 /* FIXME: Not right. Must be able to get this from the DC */
1568 lpNewEnhMetaFileHeader->rclBounds.left = 0;
1569 lpNewEnhMetaFileHeader->rclBounds.right = 0;
1570 lpNewEnhMetaFileHeader->rclBounds.top = 0;
1571 lpNewEnhMetaFileHeader->rclBounds.bottom = 0;
1572
1573 /* FIXME: Not right. Must be able to get this from the DC */
1574 lpNewEnhMetaFileHeader->rclFrame.left = 0;
1575 lpNewEnhMetaFileHeader->rclFrame.right = 0;
1576 lpNewEnhMetaFileHeader->rclFrame.top = 0;
1577 lpNewEnhMetaFileHeader->rclFrame.bottom = 0;
1578
1579 lpNewEnhMetaFileHeader->nHandles = 0; /* No handles yet */
1580
1581 /* FIXME: Add in the rest of the fields to the header */
1582 /* dSignature
1583 nVersion
1584 nRecords
1585 sReserved
1586 nDescription
1587 offDescription
1588 nPalEntries
1589 szlDevice
1590 szlMillimeters
1591 cbPixelFormat
1592 offPixelFormat,
1593 bOpenGL */
1594 }
1595
1596 (char*)lpbBuffer += ((METAHEADER*)lpbBuffer)->mtHeaderSize * 2; /* Point past the header - FIXME: metafile quirk? */
1597
1598 /* 2. Enum over individual records and convert them to the new type of records */
1599 while( !bFoundEOF )
1600 {
1601
1602 LPMETARECORD lpMetaRecord = (LPMETARECORD)lpbBuffer;
1603
1604#define EMF_ReAllocAndAdjustPointers( a , b ) \
1605 { \
1606 LPVOID lpTmp; \
Alexandre Julliard90476d62000-02-16 22:47:24 +00001607 lpTmp = HeapReAlloc( GetProcessHeap(), 0, \
Peter Hunnisettc821a751999-12-04 03:56:53 +00001608 lpNewEnhMetaFileBuffer, \
1609 uNewEnhMetaFileBufferSize + (b) ); \
1610 if( lpTmp == NULL ) { ERR( "No memory!\n" ); goto error; } \
1611 lpNewEnhMetaFileBuffer = lpTmp; \
1612 lpRecord = (a)( (char*)lpNewEnhMetaFileBuffer + uNewEnhMetaFileBufferSize ); \
1613 uNewEnhMetaFileBufferSize += (b); \
1614 }
1615
1616 switch( lpMetaRecord->rdFunction )
1617 {
1618 case META_EOF:
1619 {
1620 PEMREOF lpRecord;
1621 size_t uRecord = sizeof(*lpRecord);
1622
1623 EMF_ReAllocAndAdjustPointers(PEMREOF,uRecord);
1624
1625 /* Fill the new record - FIXME: This is not right */
1626 lpRecord->emr.iType = EMR_EOF;
1627 lpRecord->emr.nSize = sizeof( *lpRecord );
1628 lpRecord->nPalEntries = 0; /* FIXME */
1629 lpRecord->offPalEntries = 0; /* FIXME */
1630 lpRecord->nSizeLast = 0; /* FIXME */
1631
1632 /* No more records after this one */
1633 bFoundEOF = TRUE;
1634
1635 FIXME( "META_EOF conversion not correct\n" );
1636 break;
1637 }
1638
1639 case META_SETMAPMODE:
1640 {
1641 PEMRSETMAPMODE lpRecord;
1642 size_t uRecord = sizeof(*lpRecord);
1643
1644 EMF_ReAllocAndAdjustPointers(PEMRSETMAPMODE,uRecord);
1645
1646 lpRecord->emr.iType = EMR_SETMAPMODE;
1647 lpRecord->emr.nSize = sizeof( *lpRecord );
1648
1649 lpRecord->iMode = lpMetaRecord->rdParm[0];
1650
1651 break;
1652 }
1653
1654 case META_DELETEOBJECT: /* Select and Delete structures are the same */
1655 case META_SELECTOBJECT:
1656 {
1657 PEMRDELETEOBJECT lpRecord;
1658 size_t uRecord = sizeof(*lpRecord);
1659
1660 EMF_ReAllocAndAdjustPointers(PEMRDELETEOBJECT,uRecord);
1661
1662 if( lpMetaRecord->rdFunction == META_DELETEOBJECT )
1663 {
1664 lpRecord->emr.iType = EMR_DELETEOBJECT;
1665 }
1666 else
1667 {
1668 lpRecord->emr.iType = EMR_SELECTOBJECT;
1669 }
1670 lpRecord->emr.nSize = sizeof( *lpRecord );
1671
1672 lpRecord->ihObject = lpMetaRecord->rdParm[0]; /* FIXME: Handle */
1673
1674 break;
1675 }
1676
1677 case META_POLYGON: /* This is just plain busted. I don't know what I'm doing */
1678 {
1679 PEMRPOLYGON16 lpRecord; /* FIXME: Should it be a poly or poly16? */
1680 size_t uRecord = sizeof(*lpRecord);
1681
1682 EMF_ReAllocAndAdjustPointers(PEMRPOLYGON16,uRecord);
1683
1684 /* FIXME: This is mostly all wrong */
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001685 lpRecord->emr.iType = EMR_POLYGON16;
Peter Hunnisettc821a751999-12-04 03:56:53 +00001686 lpRecord->emr.nSize = sizeof( *lpRecord );
1687
1688 lpRecord->rclBounds.left = 0;
1689 lpRecord->rclBounds.right = 0;
1690 lpRecord->rclBounds.top = 0;
1691 lpRecord->rclBounds.bottom = 0;
1692
1693 lpRecord->cpts = 0;
1694 lpRecord->apts[0].x = 0;
1695 lpRecord->apts[0].y = 0;
1696
1697 FIXME( "META_POLYGON conversion not correct\n" );
1698
1699 break;
1700 }
1701
1702 case META_SETPOLYFILLMODE:
1703 {
1704 PEMRSETPOLYFILLMODE lpRecord;
1705 size_t uRecord = sizeof(*lpRecord);
1706
1707 EMF_ReAllocAndAdjustPointers(PEMRSETPOLYFILLMODE,uRecord);
1708
1709 lpRecord->emr.iType = EMR_SETPOLYFILLMODE;
1710 lpRecord->emr.nSize = sizeof( *lpRecord );
1711
1712 lpRecord->iMode = lpMetaRecord->rdParm[0];
1713
1714 break;
1715 }
1716
1717 case META_SETWINDOWORG:
1718 {
1719 PEMRSETWINDOWORGEX lpRecord; /* Seems to be the closest thing */
1720 size_t uRecord = sizeof(*lpRecord);
1721
1722 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWORGEX,uRecord);
1723
1724 lpRecord->emr.iType = EMR_SETWINDOWORGEX;
1725 lpRecord->emr.nSize = sizeof( *lpRecord );
1726
1727 lpRecord->ptlOrigin.x = lpMetaRecord->rdParm[1];
1728 lpRecord->ptlOrigin.y = lpMetaRecord->rdParm[0];
1729
1730 break;
1731 }
1732
1733 case META_SETWINDOWEXT: /* Structure is the same for SETWINDOWEXT & SETVIEWPORTEXT */
1734 case META_SETVIEWPORTEXT:
1735 {
1736 PEMRSETWINDOWEXTEX lpRecord;
1737 size_t uRecord = sizeof(*lpRecord);
1738
1739 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWEXTEX,uRecord);
1740
1741 if ( lpMetaRecord->rdFunction == META_SETWINDOWEXT )
1742 {
1743 lpRecord->emr.iType = EMR_SETWINDOWORGEX;
1744 }
1745 else
1746 {
1747 lpRecord->emr.iType = EMR_SETVIEWPORTEXTEX;
1748 }
1749 lpRecord->emr.nSize = sizeof( *lpRecord );
1750
1751 lpRecord->szlExtent.cx = lpMetaRecord->rdParm[1];
1752 lpRecord->szlExtent.cy = lpMetaRecord->rdParm[0];
1753
1754 break;
1755 }
1756
1757 case META_CREATEBRUSHINDIRECT:
1758 {
1759 PEMRCREATEBRUSHINDIRECT lpRecord;
1760 size_t uRecord = sizeof(*lpRecord);
1761
1762 EMF_ReAllocAndAdjustPointers(PEMRCREATEBRUSHINDIRECT,uRecord);
1763
1764 lpRecord->emr.iType = EMR_CREATEBRUSHINDIRECT;
1765 lpRecord->emr.nSize = sizeof( *lpRecord );
1766
1767 lpRecord->ihBrush = ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nHandles;
1768 lpRecord->lb.lbStyle = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbStyle;
1769 lpRecord->lb.lbColor = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbColor;
1770 lpRecord->lb.lbHatch = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbHatch;
1771
1772 ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nHandles += 1; /* New handle */
1773
1774 break;
1775 }
1776
1777
1778 /* These are all unimplemented and as such are intended to fall through to the default case */
1779 case META_SETBKCOLOR:
1780 case META_SETBKMODE:
1781 case META_SETROP2:
1782 case META_SETRELABS:
1783 case META_SETSTRETCHBLTMODE:
1784 case META_SETTEXTCOLOR:
1785 case META_SETVIEWPORTORG:
1786 case META_OFFSETWINDOWORG:
1787 case META_SCALEWINDOWEXT:
1788 case META_OFFSETVIEWPORTORG:
1789 case META_SCALEVIEWPORTEXT:
1790 case META_LINETO:
1791 case META_MOVETO:
1792 case META_EXCLUDECLIPRECT:
1793 case META_INTERSECTCLIPRECT:
1794 case META_ARC:
1795 case META_ELLIPSE:
1796 case META_FLOODFILL:
1797 case META_PIE:
1798 case META_RECTANGLE:
1799 case META_ROUNDRECT:
1800 case META_PATBLT:
1801 case META_SAVEDC:
1802 case META_SETPIXEL:
1803 case META_OFFSETCLIPRGN:
1804 case META_TEXTOUT:
1805 case META_POLYPOLYGON:
1806 case META_POLYLINE:
1807 case META_RESTOREDC:
1808 case META_CHORD:
1809 case META_CREATEPATTERNBRUSH:
1810 case META_CREATEPENINDIRECT:
1811 case META_CREATEFONTINDIRECT:
1812 case META_CREATEPALETTE:
1813 case META_SETTEXTALIGN:
1814 case META_SELECTPALETTE:
1815 case META_SETMAPPERFLAGS:
1816 case META_REALIZEPALETTE:
1817 case META_ESCAPE:
1818 case META_EXTTEXTOUT:
1819 case META_STRETCHDIB:
1820 case META_DIBSTRETCHBLT:
1821 case META_STRETCHBLT:
1822 case META_BITBLT:
1823 case META_CREATEREGION:
1824 case META_FILLREGION:
1825 case META_FRAMEREGION:
1826 case META_INVERTREGION:
1827 case META_PAINTREGION:
1828 case META_SELECTCLIPREGION:
1829 case META_DIBCREATEPATTERNBRUSH:
1830 case META_DIBBITBLT:
1831 case META_SETTEXTCHAREXTRA:
1832 case META_SETTEXTJUSTIFICATION:
1833 case META_EXTFLOODFILL:
1834 case META_SETDIBTODEV:
1835 case META_DRAWTEXT:
1836 case META_ANIMATEPALETTE:
1837 case META_SETPALENTRIES:
1838 case META_RESIZEPALETTE:
1839 case META_RESETDC:
1840 case META_STARTDOC:
1841 case META_STARTPAGE:
1842 case META_ENDPAGE:
1843 case META_ABORTDOC:
1844 case META_ENDDOC:
1845 case META_CREATEBRUSH:
1846 case META_CREATEBITMAPINDIRECT:
1847 case META_CREATEBITMAP:
1848 /* Fall through to unimplemented */
1849 default:
1850 {
1851 /* Not implemented yet */
1852 FIXME( "Conversion of record type 0x%x not implemented.\n", lpMetaRecord->rdFunction );
1853 break;
1854 }
1855 }
1856
1857 /* Move to the next record */
1858 (char*)lpbBuffer += ((LPMETARECORD)lpbBuffer)->rdSize * 2; /* FIXME: Seem to be doing this in metafile.c */
1859
1860#undef ReAllocAndAdjustPointers
1861 }
1862
1863 /* We know the last of the header information now */
1864 ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nBytes = uNewEnhMetaFileBufferSize;
1865
1866 /* Create the enhanced metafile */
1867 hMf = SetEnhMetaFileBits( uNewEnhMetaFileBufferSize, (const BYTE*)lpNewEnhMetaFileBuffer );
1868
1869 if( !hMf )
1870 ERR( "Problem creating metafile. Did the conversion fail somewhere?\n" );
1871
1872 return hMf;
1873
1874error:
1875 /* Free the data associated with our copy since it's been copied */
Alexandre Julliard90476d62000-02-16 22:47:24 +00001876 HeapFree( GetProcessHeap(), 0, lpNewEnhMetaFileBuffer );
Peter Hunnisettc821a751999-12-04 03:56:53 +00001877
1878 return 0;
1879}
Charles Suprin41043011998-11-07 12:56:31 +00001880
1881
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001882