blob: eaa982aff9129537de957f9ec0c0f027bf720350 [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 Julliarda69b88b1998-03-15 20:29:56 +000021#include "winbase.h"
Marcus Meissner6b9dd2e1999-03-18 17:39:57 +000022#include "wingdi.h"
Marcus Meissner61afa331999-02-22 10:16:00 +000023#include "wine/winestring.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
Huw D M Davies585c8461999-05-02 09:23:51 +000030DEFAULT_DEBUG_CHANNEL(enhmetafile)
31
32/****************************************************************************
33 * EMF_Create_HENHMETAFILE
34 */
35HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, HFILE hFile, HANDLE
36 hMapping )
37{
38 HENHMETAFILE hmf = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
39 ENHMETAFILE_MAGIC );
40 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_HEAP_LOCK( hmf );
41 metaObj->emh = emh;
42 metaObj->hFile = hFile;
43 metaObj->hMapping = hMapping;
44 GDI_HEAP_UNLOCK( hmf );
45 return hmf;
46}
47
48/****************************************************************************
49 * EMF_Delete_HENHMETAFILE
50 */
51static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
52{
53 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
54 ENHMETAFILE_MAGIC );
55 if(!metaObj) return FALSE;
56 if(metaObj->hMapping) {
57 UnmapViewOfFile( metaObj->emh );
58 CloseHandle( metaObj->hMapping );
59 CloseHandle( metaObj->hFile );
60 } else
Alexandre Julliard90476d62000-02-16 22:47:24 +000061 HeapFree( GetProcessHeap(), 0, metaObj->emh );
Huw D M Davies585c8461999-05-02 09:23:51 +000062 return GDI_FreeObject( hmf );
63}
64
65/******************************************************************
66 * EMF_GetEnhMetaHeader
67 *
68 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
69 * Should be followed by call to EMF_ReleaseEnhMetaHeader
70 */
71static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
72{
73 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
74 ENHMETAFILE_MAGIC );
Alexandre Julliard15657091999-05-23 10:25:25 +000075 TRACE("hmf %04x -> enhmetaObj %p\n", hmf, metaObj);
Huw D M Davies0ae4e091999-06-12 06:49:52 +000076 return metaObj ? metaObj->emh : NULL;
Huw D M Davies585c8461999-05-02 09:23:51 +000077}
78
79/******************************************************************
80 * EMF_ReleaseEnhMetaHeader
81 *
82 * Releases ENHMETAHEADER associated with HENHMETAFILE
83 */
84static BOOL EMF_ReleaseEnhMetaHeader( HENHMETAFILE hmf )
85{
86 return GDI_HEAP_UNLOCK( hmf );
87}
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000088
Alexandre Julliarda69b88b1998-03-15 20:29:56 +000089/*****************************************************************************
Huw D M Davies585c8461999-05-02 09:23:51 +000090 * EMF_GetEnhMetaFile
91 *
92 */
93static HENHMETAFILE EMF_GetEnhMetaFile( HFILE hFile )
94{
95 ENHMETAHEADER *emh;
96 HANDLE hMapping;
97
98 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
99 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
100
101 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
Alexandre Julliard15657091999-05-23 10:25:25 +0000102 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
Huw D M Davies585c8461999-05-02 09:23:51 +0000103 emh->iType, emh->dSignature);
104 UnmapViewOfFile( emh );
105 CloseHandle( hMapping );
106 return 0;
107 }
108 return EMF_Create_HENHMETAFILE( emh, hFile, hMapping );
109}
110
111
112/*****************************************************************************
113 * GetEnhMetaFileA (GDI32.174)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000114 *
115 *
116 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000117HENHMETAFILE WINAPI GetEnhMetaFileA(
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000118 LPCSTR lpszMetaFile /* filename of enhanced metafile */
119 )
120{
Huw D M Davies585c8461999-05-02 09:23:51 +0000121 HENHMETAFILE hmf;
122 HFILE hFile;
123
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000124 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
125 OPEN_EXISTING, 0, 0);
Huw D M Davies585c8461999-05-02 09:23:51 +0000126 if (hFile == INVALID_HANDLE_VALUE) {
Alexandre Julliard15657091999-05-23 10:25:25 +0000127 WARN("could not open %s\n", lpszMetaFile);
Huw D M Davies585c8461999-05-02 09:23:51 +0000128 return 0;
129 }
130 hmf = EMF_GetEnhMetaFile( hFile );
131 if(!hmf)
132 CloseHandle( hFile );
133 return hmf;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000134}
135
136/*****************************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000137 * GetEnhMetaFileW (GDI32.180)
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +0000138 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000139HENHMETAFILE WINAPI GetEnhMetaFileW(
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +0000140 LPCWSTR lpszMetaFile) /* filename of enhanced metafile */
141{
Huw D M Davies585c8461999-05-02 09:23:51 +0000142 HENHMETAFILE hmf;
143 HFILE hFile;
144
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000145 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
146 OPEN_EXISTING, 0, 0);
Huw D M Davies585c8461999-05-02 09:23:51 +0000147 if (hFile == INVALID_HANDLE_VALUE) {
Alexandre Julliard15657091999-05-23 10:25:25 +0000148 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
Huw D M Davies585c8461999-05-02 09:23:51 +0000149 return 0;
150 }
151 hmf = EMF_GetEnhMetaFile( hFile );
152 if(!hmf)
153 CloseHandle( hFile );
154 return hmf;
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +0000155}
156
157/*****************************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000158 * GetEnhMetaFileHeader (GDI32.178)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000159 *
160 * If _buf_ is NULL, returns the size of buffer required.
161 * Otherwise, copy up to _bufsize_ bytes of enhanced metafile header into
162 * _buf.
163 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000164UINT WINAPI GetEnhMetaFileHeader(
165 HENHMETAFILE hmf, /* enhanced metafile */
166 UINT bufsize, /* size of buffer */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000167 LPENHMETAHEADER buf /* buffer */
168 )
169{
Huw D M Davies585c8461999-05-02 09:23:51 +0000170 LPENHMETAHEADER emh;
171
172 if (!buf) return sizeof(ENHMETAHEADER);
173 emh = EMF_GetEnhMetaHeader(hmf);
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000174 if(!emh) return FALSE;
Francois Gouget6d77d3a2000-03-25 21:44:35 +0000175 memmove(buf, emh, min(sizeof(ENHMETAHEADER), bufsize));
Huw D M Davies585c8461999-05-02 09:23:51 +0000176 EMF_ReleaseEnhMetaHeader(hmf);
Francois Gouget6d77d3a2000-03-25 21:44:35 +0000177 return min(sizeof(ENHMETAHEADER), bufsize);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000178}
179
180
181/*****************************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000182 * GetEnhMetaFileDescriptionA (GDI32.176)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000183 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000184UINT WINAPI GetEnhMetaFileDescriptionA(
185 HENHMETAFILE hmf, /* enhanced metafile */
186 UINT size, /* size of buf */
Alexandre Julliard54c27111998-03-29 19:44:57 +0000187 LPSTR buf /* buffer to receive description */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000188 )
189{
Huw D M Davies585c8461999-05-02 09:23:51 +0000190 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000191 INT first, first_A;
Huw D M Davies585c8461999-05-02 09:23:51 +0000192
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000193 if(!emh) return FALSE;
Huw D M Davies585c8461999-05-02 09:23:51 +0000194 if(emh->nDescription == 0 || emh->offDescription == 0) {
195 EMF_ReleaseEnhMetaHeader(hmf);
196 return 0;
197 }
198 if (!buf || !size ) {
199 EMF_ReleaseEnhMetaHeader(hmf);
200 return emh->nDescription;
201 }
202
Patrik Stridvall896889f1999-05-08 12:50:36 +0000203 first = lstrlenW( (WCHAR *) ((char *) emh + emh->offDescription));
Huw D M Davies585c8461999-05-02 09:23:51 +0000204
Patrik Stridvall896889f1999-05-08 12:50:36 +0000205 lstrcpynWtoA(buf, (WCHAR *) ((char *) emh + emh->offDescription), size);
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000206 first_A = lstrlenA( buf );
207 buf += first_A + 1;
Patrik Stridvall896889f1999-05-08 12:50:36 +0000208 lstrcpynWtoA(buf, (WCHAR *) ((char *) emh + emh->offDescription+2*(first+1)),
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000209 size - first_A - 1); /* i18n ready */
210 first_A += lstrlenA(buf) + 1;
Huw D M Davies585c8461999-05-02 09:23:51 +0000211
212 EMF_ReleaseEnhMetaHeader(hmf);
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000213 return min(size, first_A);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000214}
215
216/*****************************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000217 * GetEnhMetaFileDescriptionW (GDI32.177)
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000218 *
219 * Copies the description string of an enhanced metafile into a buffer
220 * _buf_.
221 *
222 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
223 * number of characters copied.
224 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000225UINT WINAPI GetEnhMetaFileDescriptionW(
226 HENHMETAFILE hmf, /* enhanced metafile */
227 UINT size, /* size of buf */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000228 LPWSTR buf /* buffer to receive description */
229 )
230{
Huw D M Davies585c8461999-05-02 09:23:51 +0000231 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000232
233 if(!emh) return FALSE;
Huw D M Davies585c8461999-05-02 09:23:51 +0000234 if(emh->nDescription == 0 || emh->offDescription == 0) {
235 EMF_ReleaseEnhMetaHeader(hmf);
236 return 0;
237 }
238 if (!buf || !size ) {
239 EMF_ReleaseEnhMetaHeader(hmf);
240 return emh->nDescription;
241 }
242
Patrik Stridvall896889f1999-05-08 12:50:36 +0000243 memmove(buf, (char *) emh + emh->offDescription,
Francois Gouget6d77d3a2000-03-25 21:44:35 +0000244 min(size,emh->nDescription));
Huw D M Davies585c8461999-05-02 09:23:51 +0000245 EMF_ReleaseEnhMetaHeader(hmf);
Francois Gouget6d77d3a2000-03-25 21:44:35 +0000246 return min(size, emh->nDescription);
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000247}
248
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000249/****************************************************************************
250 * SetEnhMetaFileBits (GDI32.315)
251 *
252 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
253 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000254HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000255{
Alexandre Julliard90476d62000-02-16 22:47:24 +0000256 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
Huw D M Davies585c8461999-05-02 09:23:51 +0000257 memmove(emh, buf, bufsize);
258 return EMF_Create_HENHMETAFILE( emh, 0, 0 );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000259}
260
Peter Hunnisettc821a751999-12-04 03:56:53 +0000261INT CALLBACK cbCountSizeOfEnhMetaFile( HDC a,
262 LPHANDLETABLE b,
263 LPENHMETARECORD lpEMR,
264 INT c,
265 LPVOID lpData )
266{
267 LPUINT uSizeOfRecordData = (LPUINT)lpData;
268
Alexandre Julliard09f8a752000-03-04 19:18:23 +0000269 *uSizeOfRecordData += lpEMR->nSize;
Peter Hunnisettc821a751999-12-04 03:56:53 +0000270
271 return TRUE;
272}
273
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000274/*****************************************************************************
275 * GetEnhMetaFileBits (GDI32.175)
276 *
277 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000278UINT WINAPI GetEnhMetaFileBits(
279 HENHMETAFILE hmf,
280 UINT bufsize,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000281 LPBYTE buf
Peter Hunnisettc821a751999-12-04 03:56:53 +0000282)
283{
284 LPENHMETAHEADER lpEnhMetaFile;
285 UINT uEnhMetaFileSize = 0;
286
287 FIXME( "(%04x,%u,%p): untested\n", hmf, bufsize, buf );
288
289 /* Determine the required buffer size */
290 /* Enumerate all records and count their size */
291 if( !EnumEnhMetaFile( 0, hmf, cbCountSizeOfEnhMetaFile, &uEnhMetaFileSize, NULL ) )
292 {
293 ERR( "Unable to enumerate enhanced metafile!\n" );
294 return 0;
295 }
296
297 if( buf == NULL )
298 {
299 return uEnhMetaFileSize;
300 }
301
302 /* Copy the lesser of the two byte counts */
Francois Gouget6d77d3a2000-03-25 21:44:35 +0000303 uEnhMetaFileSize = min( uEnhMetaFileSize, bufsize );
Peter Hunnisettc821a751999-12-04 03:56:53 +0000304
305 /* Copy everything */
306 lpEnhMetaFile = EMF_GetEnhMetaHeader( hmf );
307
308 if( lpEnhMetaFile == NULL )
309 {
310 return 0;
311 }
312
313 /* Use memmove just in case they overlap */
314 memmove(buf, lpEnhMetaFile, bufsize);
315
316 EMF_ReleaseEnhMetaHeader( hmf );
317
318 return bufsize;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000319}
320
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000321/*****************************************************************************
322 * PlayEnhMetaFileRecord (GDI32.264)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000323 *
324 * Render a single enhanced metafile record in the device context hdc.
325 *
326 * RETURNS
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000327 * TRUE (non zero) on success, FALSE on error.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000328 * BUGS
Alexandre Julliard54c27111998-03-29 19:44:57 +0000329 * Many unimplemented records.
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000330 * No error handling on record play failures (ie checking return codes)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000331 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000332BOOL WINAPI PlayEnhMetaFileRecord(
333 HDC hdc, /* device context in which to render EMF record */
334 LPHANDLETABLE handletable, /* array of handles to be used in rendering record */
Alexandre Julliard54c27111998-03-29 19:44:57 +0000335 const ENHMETARECORD *mr, /* EMF record to render */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000336 UINT handles /* size of handle array */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000337 )
338{
339 int type;
Alexandre Julliard15657091999-05-23 10:25:25 +0000340 TRACE(
Alexandre Julliard54c27111998-03-29 19:44:57 +0000341 "hdc = %08x, handletable = %p, record = %p, numHandles = %d\n",
342 hdc, handletable, mr, handles);
343 if (!mr) return FALSE;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000344
Alexandre Julliard54c27111998-03-29 19:44:57 +0000345 type = mr->iType;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000346
Alexandre Julliard15657091999-05-23 10:25:25 +0000347 TRACE(" type=%d\n", type);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000348 switch(type)
349 {
350 case EMR_HEADER:
Alexandre Julliard54c27111998-03-29 19:44:57 +0000351 {
Peter Hunnisettf2b84922000-01-15 22:17:49 +0000352#if 0
353 ENHMETAHEADER* h = (LPENHMETAHEADER)mr;
354 XFORM dcTransform;
355
356 /* Scale the enhanced metafile according to the reference hdc
357 it was created with */
358 if( h->szlDevice.cx )
359 {
360 dcTransform.eM11 = (FLOAT)( (DOUBLE)GetDeviceCaps( hdc, HORZRES ) /
361 (DOUBLE)h->szlDevice.cx );
362 }
363 else
364 {
365 ERR( "Invalid szlDevice.cx in header\n" );
366 dcTransform.eM11 = (FLOAT)1.0;
367 }
368
369 if( h->szlDevice.cy )
370 {
371 dcTransform.eM22 = (FLOAT)( (DOUBLE)GetDeviceCaps( hdc, VERTRES ) /
372 (DOUBLE)h->szlDevice.cy );
373 }
374 else
375 {
376 ERR( "Invalid szlDevice.cy in header\n" );
377 dcTransform.eM22 = (FLOAT)1.0;
378 }
379
380 dcTransform.eM12 = dcTransform.eM21 = (FLOAT)0;
381 dcTransform.eDx = dcTransform.eDy = (FLOAT)0;
382
383 ModifyWorldTransform( hdc, &dcTransform, MWT_RIGHTMULTIPLY );
384#endif
Alexandre Julliard54c27111998-03-29 19:44:57 +0000385 break;
386 }
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000387 case EMR_EOF:
Alexandre Julliard54c27111998-03-29 19:44:57 +0000388 break;
Alexandre Julliard54c27111998-03-29 19:44:57 +0000389 case EMR_GDICOMMENT:
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000390 {
391 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
392 /* In an enhanced metafile, there can be both public and private GDI comments */
393 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
394 break;
395 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000396 case EMR_SETMAPMODE:
397 {
398 DWORD mode = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000399 SetMapMode(hdc, mode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000400 break;
401 }
402 case EMR_SETBKMODE:
403 {
404 DWORD mode = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000405 SetBkMode(hdc, mode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000406 break;
407 }
408 case EMR_SETBKCOLOR:
409 {
410 DWORD mode = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000411 SetBkColor(hdc, mode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000412 break;
413 }
414 case EMR_SETPOLYFILLMODE:
415 {
416 DWORD mode = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000417 SetPolyFillMode(hdc, mode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000418 break;
419 }
420 case EMR_SETROP2:
421 {
422 DWORD mode = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000423 SetROP2(hdc, mode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000424 break;
425 }
426 case EMR_SETSTRETCHBLTMODE:
427 {
428 DWORD mode = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000429 SetStretchBltMode(hdc, mode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000430 break;
431 }
432 case EMR_SETTEXTALIGN:
433 {
434 DWORD align = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000435 SetTextAlign(hdc, align);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000436 break;
437 }
438 case EMR_SETTEXTCOLOR:
439 {
440 DWORD color = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000441 SetTextColor(hdc, color);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000442 break;
443 }
444 case EMR_SAVEDC:
445 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000446 SaveDC(hdc);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000447 break;
448 }
449 case EMR_RESTOREDC:
450 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000451 RestoreDC(hdc, mr->dParm[0]);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000452 break;
453 }
454 case EMR_INTERSECTCLIPRECT:
455 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000456 INT left = mr->dParm[0], top = mr->dParm[1], right = mr->dParm[2],
Alexandre Julliard54c27111998-03-29 19:44:57 +0000457 bottom = mr->dParm[3];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000458 IntersectClipRect(hdc, left, top, right, bottom);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000459 break;
460 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000461 case EMR_SELECTOBJECT:
462 {
463 DWORD obj = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000464 SelectObject(hdc, (handletable->objectHandle)[obj]);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000465 break;
466 }
467 case EMR_DELETEOBJECT:
468 {
469 DWORD obj = mr->dParm[0];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000470 DeleteObject( (handletable->objectHandle)[obj]);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000471 (handletable->objectHandle)[obj] = 0;
472 break;
473 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000474 case EMR_SETWINDOWORGEX:
475 {
476 DWORD x = mr->dParm[0], y = mr->dParm[1];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000477 SetWindowOrgEx(hdc, x, y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000478 break;
479 }
480 case EMR_SETWINDOWEXTEX:
481 {
482 DWORD x = mr->dParm[0], y = mr->dParm[1];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000483 SetWindowExtEx(hdc, x, y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000484 break;
485 }
486 case EMR_SETVIEWPORTORGEX:
487 {
488 DWORD x = mr->dParm[0], y = mr->dParm[1];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000489 SetViewportOrgEx(hdc, x, y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000490 break;
491 }
492 case EMR_SETVIEWPORTEXTEX:
493 {
494 DWORD x = mr->dParm[0], y = mr->dParm[1];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000495 SetViewportExtEx(hdc, x, y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000496 break;
497 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000498 case EMR_CREATEPEN:
499 {
500 DWORD obj = mr->dParm[0];
501 (handletable->objectHandle)[obj] =
Alexandre Julliarda3960291999-02-26 11:11:13 +0000502 CreatePenIndirect((LOGPEN *) &(mr->dParm[1]));
Alexandre Julliard54c27111998-03-29 19:44:57 +0000503 break;
504 }
505 case EMR_EXTCREATEPEN:
506 {
507 DWORD obj = mr->dParm[0];
508 DWORD style = mr->dParm[1], brush = mr->dParm[2];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000509 LOGBRUSH *b = (LOGBRUSH *) &mr->dParm[3];
Alexandre Julliard15657091999-05-23 10:25:25 +0000510 FIXME("Some ExtCreatePen args not handled\n");
Alexandre Julliard54c27111998-03-29 19:44:57 +0000511 (handletable->objectHandle)[obj] =
Alexandre Julliarda3960291999-02-26 11:11:13 +0000512 ExtCreatePen(style, brush, b, 0, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000513 break;
514 }
515 case EMR_CREATEBRUSHINDIRECT:
516 {
517 DWORD obj = mr->dParm[0];
518 (handletable->objectHandle)[obj] =
Alexandre Julliarda3960291999-02-26 11:11:13 +0000519 CreateBrushIndirect((LOGBRUSH *) &(mr->dParm[1]));
Alexandre Julliard54c27111998-03-29 19:44:57 +0000520 break;
521 }
522 case EMR_EXTCREATEFONTINDIRECTW:
523 {
524 DWORD obj = mr->dParm[0];
525 (handletable->objectHandle)[obj] =
Alexandre Julliarda3960291999-02-26 11:11:13 +0000526 CreateFontIndirectW((LOGFONTW *) &(mr->dParm[1]));
Alexandre Julliard54c27111998-03-29 19:44:57 +0000527 break;
528 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000529 case EMR_MOVETOEX:
530 {
531 DWORD x = mr->dParm[0], y = mr->dParm[1];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000532 MoveToEx(hdc, x, y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000533 break;
534 }
535 case EMR_LINETO:
536 {
537 DWORD x = mr->dParm[0], y = mr->dParm[1];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000538 LineTo(hdc, x, y);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000539 break;
540 }
541 case EMR_RECTANGLE:
542 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000543 INT left = mr->dParm[0], top = mr->dParm[1], right = mr->dParm[2],
Alexandre Julliard54c27111998-03-29 19:44:57 +0000544 bottom = mr->dParm[3];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000545 Rectangle(hdc, left, top, right, bottom);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000546 break;
547 }
548 case EMR_ELLIPSE:
549 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000550 INT left = mr->dParm[0], top = mr->dParm[1], right = mr->dParm[2],
Alexandre Julliard54c27111998-03-29 19:44:57 +0000551 bottom = mr->dParm[3];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000552 Ellipse(hdc, left, top, right, bottom);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000553 break;
554 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000555 case EMR_POLYGON16:
556 {
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000557 /* 0-3 : a bounding rectangle? */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000558 INT count = mr->dParm[4];
Alexandre Julliard15657091999-05-23 10:25:25 +0000559 FIXME("Some Polygon16 args not handled\n");
Alexandre Julliard54c27111998-03-29 19:44:57 +0000560 Polygon16(hdc, (POINT16 *)&mr->dParm[5], count);
561 break;
562 }
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000563 case EMR_POLYLINE16:
564 {
565 /* 0-3 : a bounding rectangle? */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000566 INT count = mr->dParm[4];
Alexandre Julliard15657091999-05-23 10:25:25 +0000567 FIXME("Some Polyline16 args not handled\n");
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000568 Polyline16(hdc, (POINT16 *)&mr->dParm[5], count);
569 break;
570 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000571#if 0
572 case EMR_POLYPOLYGON16:
573 {
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000574 PEMRPOLYPOLYGON16 lpPolyPoly16 = (PEMRPOLYPOLYGON16)mr;
575
576 PolyPolygon16( hdc,
577 lpPolyPoly16->apts,
578 lpPolyPoly16->aPolyCounts,
579 lpPolyPoly16->nPolys );
580
Alexandre Julliard54c27111998-03-29 19:44:57 +0000581 break;
582 }
583#endif
Jason McMullane113b091999-02-09 14:08:57 +0000584 case EMR_STRETCHDIBITS:
585 {
586 LONG xDest = mr->dParm[4];
587 LONG yDest = mr->dParm[5];
588 LONG xSrc = mr->dParm[6];
589 LONG ySrc = mr->dParm[7];
590 LONG cxSrc = mr->dParm[8];
591 LONG cySrc = mr->dParm[9];
592 DWORD offBmiSrc = mr->dParm[10];
593 DWORD offBitsSrc = mr->dParm[12];
594 DWORD iUsageSrc = mr->dParm[14];
595 DWORD dwRop = mr->dParm[15];
596 LONG cxDest = mr->dParm[16];
597 LONG cyDest = mr->dParm[17];
598
Alexandre Julliarda3960291999-02-26 11:11:13 +0000599 StretchDIBits(hdc,xDest,yDest,cxDest,cyDest,
Jason McMullane113b091999-02-09 14:08:57 +0000600 xSrc,ySrc,cxSrc,cySrc,
601 ((char *)mr)+offBitsSrc,
602 (const BITMAPINFO *)(((char *)mr)+offBmiSrc),
603 iUsageSrc,dwRop);
604 break;
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000605 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000606 case EMR_EXTTEXTOUTW:
607 {
608 /* 0-3: ??? */
609 DWORD flags = mr->dParm[4];
610 /* 5, 6: ??? */
611 DWORD x = mr->dParm[7], y = mr->dParm[8];
612 DWORD count = mr->dParm[9];
613 /* 10-16: ??? */
614 LPWSTR str = (LPWSTR)& mr->dParm[17];
615 /* trailing info: dx array? */
Alexandre Julliard15657091999-05-23 10:25:25 +0000616 FIXME("Many ExtTextOut args not handled\n");
Alexandre Julliarda3960291999-02-26 11:11:13 +0000617 ExtTextOutW(hdc, x, y, flags, /* lpRect */ NULL,
Alexandre Julliard54c27111998-03-29 19:44:57 +0000618 str, count, /* lpDx */ NULL);
619 break;
620 }
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000621
622 case EMR_CREATEPALETTE:
623 {
624 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
Alexandre Julliard54c27111998-03-29 19:44:57 +0000625
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000626 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
627 CreatePalette( &lpCreatePal->lgpl );
628
629 break;
630 }
631
632 case EMR_SELECTPALETTE:
633 {
634 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
635
636 /* FIXME: Should this be forcing background mode? */
637 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
638 SelectPalette( hdc, lpSelectPal->ihPal, FALSE );
639 break;
640 }
641
642 case EMR_REALIZEPALETTE:
643 {
644 RealizePalette( hdc );
645 break;
646 }
647
648#if 0
649 case EMR_EXTSELECTCLIPRGN:
650 {
651 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
652
653 /* Need to make a region out of the RGNDATA we have */
654 ExtSelectClipRgn( hdc, ..., (INT)(lpRgn->iMode) );
655
656 }
657#endif
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000658
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000659 case EMR_SETMETARGN:
660 {
661 SetMetaRgn( hdc );
662 break;
663 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000664
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000665 case EMR_SETWORLDTRANSFORM:
666 {
667 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000668
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000669 SetWorldTransform( hdc, &lpXfrm->xform );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000670
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000671 break;
672 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000673
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000674 case EMR_POLYBEZIER:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000675 {
676 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
677
678 FIXME( "Bounding rectangle ignored for EMR_POLYBEZIER\n" );
679 PolyBezier( hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl );
680
681 break;
682 }
683
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000684 case EMR_POLYGON:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000685 {
686 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
687
688 FIXME( "Bounding rectangle ignored for EMR_POLYGON\n" );
689 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
690
691 break;
692 }
693
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000694 case EMR_POLYLINE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000695 {
696 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
697
698 FIXME( "Bounding rectangle ignored for EMR_POLYLINE\n" );
699 Polyline( hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl );
700
701 break;
702 }
703
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000704 case EMR_POLYBEZIERTO:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000705 {
706 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
707
708 FIXME( "Bounding rectangle ignored for EMR_POLYBEZIERTO\n" );
709 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl, (UINT)lpPolyBezierTo->cptl );
710
711 break;
712 }
713
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000714 case EMR_POLYLINETO:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000715 {
716 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
717
718 FIXME( "Bounding rectangle ignored for EMR_POLYLINETO\n" );
719 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl, (UINT)lpPolyLineTo->cptl );
720
721 break;
722 }
723
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000724 case EMR_POLYPOLYLINE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000725 {
726 PEMRPOLYPOLYLINE lpPolyPolyLine = (PEMRPOLYPOLYLINE)mr;
727
728 FIXME( "Bounding rectangle ignored for EMR_POLYPOLYLINE\n" );
729 PolyPolyline( hdc,
730 (const LPPOINT)lpPolyPolyLine->aptl,
731 lpPolyPolyLine->aPolyCounts,
732 lpPolyPolyLine->nPolys );
733
734 break;
735 }
736
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000737 case EMR_POLYPOLYGON:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000738 {
739 PEMRPOLYPOLYGON lpPolyPolygon = (PEMRPOLYPOLYGON)mr;
740 INT* lpPolyCounts;
741 UINT i;
742
743 /* We get the polygon point counts in a dword struct. Transform
744 this into an INT struct */
745 lpPolyCounts = (INT*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
746 sizeof(INT)*lpPolyPolygon->cptl );
747
748 for( i=0; i<lpPolyPolygon->cptl; i++ )
749 {
750 lpPolyCounts[i] = (INT)lpPolyPolygon->aPolyCounts[i];
751 }
752
753 FIXME( "Bounding rectangle ignored for EMR_POLYPOLYGON\n" );
754 PolyPolygon( hdc, (const LPPOINT)lpPolyPolygon->aptl,
755 lpPolyCounts, lpPolyPolygon->nPolys );
756
757 HeapFree( GetProcessHeap(), 0, lpPolyCounts );
758
759 break;
760 }
761
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000762 case EMR_SETBRUSHORGEX:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000763 {
764 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
765
766 SetBrushOrgEx( hdc,
767 (INT)lpSetBrushOrgEx->ptlOrigin.x,
768 (INT)lpSetBrushOrgEx->ptlOrigin.y,
769 NULL );
770
771 break;
772 }
773
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000774 case EMR_SETPIXELV:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000775 {
776 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
777
778 SetPixelV( hdc,
779 (INT)lpSetPixelV->ptlPixel.x,
780 (INT)lpSetPixelV->ptlPixel.y,
781 lpSetPixelV->crColor );
782
783 break;
784 }
785
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000786 case EMR_SETMAPPERFLAGS:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000787 {
788 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
789
790 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
791
792 break;
793 }
794
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000795 case EMR_SETCOLORADJUSTMENT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000796 {
797 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
798
799 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
800
801 break;
802 }
803
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000804 case EMR_OFFSETCLIPRGN:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000805 {
806 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
807
808 OffsetClipRgn( hdc,
809 (INT)lpOffsetClipRgn->ptlOffset.x,
810 (INT)lpOffsetClipRgn->ptlOffset.y );
811
812 break;
813 }
814
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000815 case EMR_EXCLUDECLIPRECT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000816 {
817 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
818
819 ExcludeClipRect( hdc,
820 lpExcludeClipRect->rclClip.left,
821 lpExcludeClipRect->rclClip.top,
822 lpExcludeClipRect->rclClip.right,
823 lpExcludeClipRect->rclClip.bottom );
824
825 break;
826 }
827
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000828 case EMR_SCALEVIEWPORTEXTEX:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000829 {
830 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
831
832 ScaleViewportExtEx( hdc,
833 lpScaleViewportExtEx->xNum,
834 lpScaleViewportExtEx->xDenom,
835 lpScaleViewportExtEx->yNum,
836 lpScaleViewportExtEx->yDenom,
837 NULL );
838
839 break;
840 }
841
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000842 case EMR_SCALEWINDOWEXTEX:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000843 {
844 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
845
846 ScaleWindowExtEx( hdc,
847 lpScaleWindowExtEx->xNum,
848 lpScaleWindowExtEx->xDenom,
849 lpScaleWindowExtEx->yNum,
850 lpScaleWindowExtEx->yDenom,
851 NULL );
852
853 break;
854 }
855
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000856 case EMR_MODIFYWORLDTRANSFORM:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000857 {
858 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
859
860 ModifyWorldTransform( hdc, &lpModifyWorldTrans->xform,
861 lpModifyWorldTrans->iMode );
862
863 break;
864 }
865
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000866 case EMR_ANGLEARC:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000867 {
868 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
869
870 AngleArc( hdc,
871 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
872 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
873 lpAngleArc->eSweepAngle );
874
875 break;
876 }
877
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000878 case EMR_ROUNDRECT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000879 {
880 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
881
882 RoundRect( hdc,
883 lpRoundRect->rclBox.left,
884 lpRoundRect->rclBox.top,
885 lpRoundRect->rclBox.right,
886 lpRoundRect->rclBox.bottom,
887 lpRoundRect->szlCorner.cx,
888 lpRoundRect->szlCorner.cy );
889
890 break;
891 }
892
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000893 case EMR_ARC:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000894 {
895 PEMRARC lpArc = (PEMRARC)mr;
896
897 Arc( hdc,
898 (INT)lpArc->rclBox.left,
899 (INT)lpArc->rclBox.top,
900 (INT)lpArc->rclBox.right,
901 (INT)lpArc->rclBox.bottom,
902 (INT)lpArc->ptlStart.x,
903 (INT)lpArc->ptlStart.y,
904 (INT)lpArc->ptlEnd.x,
905 (INT)lpArc->ptlEnd.y );
906
907 break;
908 }
909
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000910 case EMR_CHORD:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000911 {
912 PEMRCHORD lpChord = (PEMRCHORD)mr;
913
914 Chord( hdc,
915 (INT)lpChord->rclBox.left,
916 (INT)lpChord->rclBox.top,
917 (INT)lpChord->rclBox.right,
918 (INT)lpChord->rclBox.bottom,
919 (INT)lpChord->ptlStart.x,
920 (INT)lpChord->ptlStart.y,
921 (INT)lpChord->ptlEnd.x,
922 (INT)lpChord->ptlEnd.y );
923
924 break;
925 }
926
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000927 case EMR_PIE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000928 {
929 PEMRPIE lpPie = (PEMRPIE)mr;
930
931 Pie( hdc,
932 (INT)lpPie->rclBox.left,
933 (INT)lpPie->rclBox.top,
934 (INT)lpPie->rclBox.right,
935 (INT)lpPie->rclBox.bottom,
936 (INT)lpPie->ptlStart.x,
937 (INT)lpPie->ptlStart.y,
938 (INT)lpPie->ptlEnd.x,
939 (INT)lpPie->ptlEnd.y );
940
941 break;
942 }
943
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000944 case EMR_ARCTO:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000945 {
946 PEMRARC lpArcTo = (PEMRARC)mr;
947
948 ArcTo( hdc,
949 (INT)lpArcTo->rclBox.left,
950 (INT)lpArcTo->rclBox.top,
951 (INT)lpArcTo->rclBox.right,
952 (INT)lpArcTo->rclBox.bottom,
953 (INT)lpArcTo->ptlStart.x,
954 (INT)lpArcTo->ptlStart.y,
955 (INT)lpArcTo->ptlEnd.x,
956 (INT)lpArcTo->ptlEnd.y );
957
958 break;
959 }
960
961 case EMR_EXTFLOODFILL:
962 {
963 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
964
965 ExtFloodFill( hdc,
966 (INT)lpExtFloodFill->ptlStart.x,
967 (INT)lpExtFloodFill->ptlStart.y,
968 lpExtFloodFill->crColor,
969 (UINT)lpExtFloodFill->iMode );
970
971 break;
972 }
973
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000974 case EMR_POLYDRAW:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000975 {
976 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
977
978 FIXME( "Bounding rectangle ignored for EMR_POLYDRAW\n" );
979 PolyDraw( hdc,
980 (const LPPOINT)lpPolyDraw->aptl,
981 lpPolyDraw->abTypes,
982 (INT)lpPolyDraw->cptl );
983
984 break;
985 }
986
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000987 case EMR_SETARCDIRECTION:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000988 {
989 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
990
991 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
992
993 break;
994 }
995
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000996 case EMR_SETMITERLIMIT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000997 {
998 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
999
1000 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1001
1002 break;
1003 }
1004
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001005 case EMR_BEGINPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001006 {
1007 BeginPath( hdc );
1008 break;
1009 }
1010
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001011 case EMR_ENDPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001012 {
1013 EndPath( hdc );
1014 break;
1015 }
1016
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001017 case EMR_CLOSEFIGURE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001018 {
1019 CloseFigure( hdc );
1020 break;
1021 }
1022
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001023 case EMR_FILLPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001024 {
1025 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1026
1027 FIXME( "Bounding rectangle ignored for EMR_FILLPATH\n" );
1028 FillPath( hdc );
1029
1030 break;
1031 }
1032
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001033 case EMR_STROKEANDFILLPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001034 {
1035 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1036
1037 FIXME( "Bounding rectangle ignored for EMR_STROKEANDFILLPATH\n" );
1038 StrokeAndFillPath( hdc );
1039
1040 break;
1041 }
1042
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001043 case EMR_STROKEPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001044 {
1045 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1046
1047 FIXME( "Bounding rectangle ignored for EMR_STROKEPATH\n" );
1048 StrokePath( hdc );
1049
1050 break;
1051 }
1052
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001053 case EMR_FLATTENPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001054 {
1055 FlattenPath( hdc );
1056 break;
1057 }
1058
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001059 case EMR_WIDENPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001060 {
1061 WidenPath( hdc );
1062 break;
1063 }
1064
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001065 case EMR_SELECTCLIPPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001066 {
1067 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1068
1069 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1070
1071 break;
1072 }
1073
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001074 case EMR_ABORTPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001075 {
1076 AbortPath( hdc );
1077 break;
1078 }
1079
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001080 case EMR_CREATECOLORSPACE:
1081 {
1082 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1083
1084 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1085 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1086
1087 break;
1088 }
1089
1090 case EMR_SETCOLORSPACE:
1091 {
1092 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1093
1094 SetColorSpace( hdc,
1095 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1096
1097 break;
1098 }
1099
1100 case EMR_DELETECOLORSPACE:
1101 {
1102 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1103
1104 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1105
1106 break;
1107 }
1108
1109 case EMR_SETICMMODE:
1110 {
1111 PERMSETICMMODE lpSetICMMode = (PERMSETICMMODE)mr;
1112
1113 SetICMMode( hdc,
1114 (INT)lpSetICMMode->iMode );
1115
1116 break;
1117 }
1118
1119 case EMR_PIXELFORMAT:
1120 {
1121 INT iPixelFormat;
1122 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1123
1124 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1125 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1126
1127 break;
1128 }
1129
1130 case EMR_SETPALETTEENTRIES:
1131 {
1132 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1133
1134 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1135 (UINT)lpSetPaletteEntries->iStart,
1136 (UINT)lpSetPaletteEntries->cEntries,
1137 lpSetPaletteEntries->aPalEntries );
1138
1139 break;
1140 }
1141
1142 case EMR_RESIZEPALETTE:
1143 {
1144 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1145
1146 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1147 (UINT)lpResizePalette->cEntries );
1148
1149 break;
1150 }
1151
1152 case EMR_CREATEDIBPATTERNBRUSHPT:
1153 {
1154 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1155
1156 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1157 LPVOID lpPackedStruct = HeapAlloc( GetProcessHeap(),
1158 0,
1159 lpCreate->cbBmi + lpCreate->cbBits );
1160 /* Now pack this structure */
1161 memcpy( lpPackedStruct,
1162 ((BYTE*)lpCreate) + lpCreate->offBmi,
1163 lpCreate->cbBmi );
1164 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1165 ((BYTE*)lpCreate) + lpCreate->offBits,
1166 lpCreate->cbBits );
1167
1168 (handletable->objectHandle)[lpCreate->ihBrush] =
1169 CreateDIBPatternBrushPt( lpPackedStruct,
1170 (UINT)lpCreate->iUsage );
1171
1172 break;
1173 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001174
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001175 case EMR_BITBLT:
1176 case EMR_STRETCHBLT:
1177 case EMR_MASKBLT:
1178 case EMR_PLGBLT:
1179 case EMR_SETDIBITSTODEVICE:
1180 case EMR_EXTTEXTOUTA:
1181 case EMR_POLYBEZIER16:
1182 case EMR_POLYBEZIERTO16:
1183 case EMR_POLYLINETO16:
1184 case EMR_POLYPOLYLINE16:
1185 case EMR_POLYPOLYGON16:
1186 case EMR_POLYDRAW16:
1187 case EMR_CREATEMONOBRUSH:
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001188 case EMR_POLYTEXTOUTA:
1189 case EMR_POLYTEXTOUTW:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001190 case EMR_FILLRGN:
1191 case EMR_FRAMERGN:
1192 case EMR_INVERTRGN:
1193 case EMR_PAINTRGN:
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001194 case EMR_GLSRECORD:
1195 case EMR_GLSBOUNDEDRECORD:
Alexandre Julliard54c27111998-03-29 19:44:57 +00001196 default:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001197 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1198 record then ignore and return TRUE. */
Alexandre Julliard15657091999-05-23 10:25:25 +00001199 FIXME("type %d is unimplemented\n", type);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001200 break;
1201 }
Alexandre Julliard54c27111998-03-29 19:44:57 +00001202 return TRUE;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001203}
1204
1205
1206/*****************************************************************************
1207 *
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001208 * EnumEnhMetaFile (GDI32.79)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001209 *
1210 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1211 * for each
1212 * record. Returns when either every record has been used or
1213 * when _EnhMetaFunc_ returns FALSE.
1214 *
1215 *
1216 * RETURNS
1217 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1218 * returns FALSE.
1219 *
1220 * BUGS
Alexandre Julliard54c27111998-03-29 19:44:57 +00001221 * Ignores rect.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001222 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001223BOOL WINAPI EnumEnhMetaFile(
1224 HDC hdc, /* device context to pass to _EnhMetaFunc_ */
1225 HENHMETAFILE hmf, /* EMF to walk */
1226 ENHMFENUMPROC callback, /* callback function */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001227 LPVOID data, /* optional data for callback function */
Huw D M Davies280aeb92000-03-30 20:22:41 +00001228 const RECT *lpRect /* bounding rectangle for rendered metafile */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001229 )
1230{
Huw D M Davies585c8461999-05-02 09:23:51 +00001231 BOOL ret = TRUE;
1232 LPENHMETARECORD p = (LPENHMETARECORD) EMF_GetEnhMetaHeader(hmf);
Huw D M Davies280aeb92000-03-30 20:22:41 +00001233 INT count, i;
Huw D M Davies0ae4e091999-06-12 06:49:52 +00001234 HANDLETABLE *ht;
Huw D M Davies585c8461999-05-02 09:23:51 +00001235 INT savedMode = 0;
Huw D M Davies0ae4e091999-06-12 06:49:52 +00001236
1237 if(!p) return FALSE;
1238 count = ((LPENHMETAHEADER) p)->nHandles;
Huw D M Davies280aeb92000-03-30 20:22:41 +00001239 ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1240 sizeof(HANDLETABLE) * count );
1241 ht->objectHandle[0] = hmf;
Huw D M Davies585c8461999-05-02 09:23:51 +00001242 if (lpRect) {
1243 LPENHMETAHEADER h = (LPENHMETAHEADER) p;
1244 FLOAT xscale = (h->rclBounds.right - h->rclBounds.left) /
1245 (lpRect->right - lpRect->left);
1246 FLOAT yscale = (h->rclBounds.bottom - h->rclBounds.top) /
1247 (lpRect->bottom - lpRect->top);
Patrik Stridvall896889f1999-05-08 12:50:36 +00001248 XFORM xform;
1249 xform.eM11 = xscale;
1250 xform.eM12 = 0;
1251 xform.eM21 = 0;
1252 xform.eM22 = yscale;
Huw D M Davies585c8461999-05-02 09:23:51 +00001253 xform.eDx = lpRect->left;
1254 xform.eDy = lpRect->top;
Alexandre Julliard15657091999-05-23 10:25:25 +00001255 FIXME("play into rect doesn't work\n");
Huw D M Davies585c8461999-05-02 09:23:51 +00001256 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1257 if (!SetWorldTransform(hdc, &xform)) {
Alexandre Julliard15657091999-05-23 10:25:25 +00001258 WARN("World transform failed!\n");
Huw D M Davies585c8461999-05-02 09:23:51 +00001259 }
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001260 }
Huw D M Davies280aeb92000-03-30 20:22:41 +00001261 while (ret) {
1262 ret = (*callback)(hdc, ht, p, count, data);
Huw D M Davies585c8461999-05-02 09:23:51 +00001263 if (p->iType == EMR_EOF) break;
Huw D M Davies280aeb92000-03-30 20:22:41 +00001264 p = (LPENHMETARECORD) ((char *) p + p->nSize);
Huw D M Davies585c8461999-05-02 09:23:51 +00001265 }
Huw D M Davies280aeb92000-03-30 20:22:41 +00001266 for(i = 1; i < count; i++) /* Don't delete element 0 (hmf) */
1267 if( (ht->objectHandle)[i] )
1268 DeleteObject( (ht->objectHandle)[i] );
Huw D M Davies585c8461999-05-02 09:23:51 +00001269 HeapFree( GetProcessHeap(), 0, ht );
1270 EMF_ReleaseEnhMetaHeader(hmf);
1271 if (savedMode) SetGraphicsMode(hdc, savedMode);
Huw D M Davies585c8461999-05-02 09:23:51 +00001272 return ret;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001273}
1274
Huw D M Davies280aeb92000-03-30 20:22:41 +00001275static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
1276 ENHMETARECORD *emr,
1277 INT handles, LPVOID data)
1278{
1279 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
1280}
1281
1282/**************************************************************************
1283 * PlayEnhMetaFile (GDI32.263)
1284 *
1285 * Renders an enhanced metafile into a specified rectangle *lpRect
1286 * in device context hdc.
1287 *
1288 */
1289BOOL WINAPI PlayEnhMetaFile(
1290 HDC hdc, /* DC to render into */
1291 HENHMETAFILE hmf, /* metafile to render */
1292 const RECT *lpRect /* rectangle to place metafile inside */
1293 )
1294{
1295 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
1296 lpRect);
1297}
1298
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001299/*****************************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00001300 * DeleteEnhMetaFile (GDI32.68)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001301 *
1302 * Deletes an enhanced metafile and frees the associated storage.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001303 */
Huw D M Davies585c8461999-05-02 09:23:51 +00001304BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
1305{
1306 return EMF_Delete_HENHMETAFILE( hmf );
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001307}
1308
1309/*****************************************************************************
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001310 * CopyEnhMetaFileA (GDI32.21) Duplicate an enhanced metafile
1311 *
1312 *
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001313 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001314HENHMETAFILE WINAPI CopyEnhMetaFileA(
Huw D M Davies585c8461999-05-02 09:23:51 +00001315 HENHMETAFILE hmfSrc,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001316 LPCSTR file)
1317{
Huw D M Davies585c8461999-05-02 09:23:51 +00001318 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
1319 HENHMETAFILE hmfDst;
1320
Huw D M Davies0ae4e091999-06-12 06:49:52 +00001321 if(!emrSrc) return FALSE;
Huw D M Davies585c8461999-05-02 09:23:51 +00001322 if (!file) {
Alexandre Julliard90476d62000-02-16 22:47:24 +00001323 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
Huw D M Davies585c8461999-05-02 09:23:51 +00001324 memcpy( emrDst, emrSrc, emrSrc->nBytes );
1325 hmfDst = EMF_Create_HENHMETAFILE( emrDst, 0, 0 );
1326 } else {
1327 HFILE hFile;
1328 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0, NULL,
1329 CREATE_ALWAYS, 0, -1);
1330 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
1331 hmfDst = EMF_GetEnhMetaFile( hFile );
1332 }
1333 EMF_ReleaseEnhMetaHeader( hmfSrc );
1334 return hmfDst;
Alexandre Julliard54c27111998-03-29 19:44:57 +00001335}
1336
Huw D M Davies585c8461999-05-02 09:23:51 +00001337
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001338/* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1339typedef struct tagEMF_PaletteCopy
1340{
1341 UINT cEntries;
1342 LPPALETTEENTRY lpPe;
1343} EMF_PaletteCopy;
1344
1345/***************************************************************
1346 * Find the EMR_EOF record and then use it to find the
1347 * palette entries for this enhanced metafile.
1348 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1349 * which contains the max number of elements to copy and where
1350 * to copy them to.
1351 *
1352 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1353 */
1354INT CALLBACK cbEnhPaletteCopy( HDC a,
1355 LPHANDLETABLE b,
1356 LPENHMETARECORD lpEMR,
1357 INT c,
1358 LPVOID lpData )
1359{
1360
1361 if ( lpEMR->iType == EMR_EOF )
1362 {
1363 PEMREOF lpEof = (PEMREOF)lpEMR;
1364 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
Francois Gouget6d77d3a2000-03-25 21:44:35 +00001365 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001366
1367 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
1368
1369 memcpy( (LPVOID)info->lpPe,
1370 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
1371 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
1372
1373 /* Update the passed data as a return code */
1374 info->lpPe = NULL; /* Palettes were copied! */
1375 info->cEntries = (UINT)dwNumPalToCopy;
1376
1377 return FALSE; /* That's all we need */
1378 }
1379
1380 return TRUE;
1381}
1382
Charles Suprin41043011998-11-07 12:56:31 +00001383/*****************************************************************************
1384 * GetEnhMetaFilePaletteEntries (GDI32.179)
1385 *
1386 * Copy the palette and report size
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001387 *
1388 * BUGS: Error codes (SetLastError) are not set on failures
Charles Suprin41043011998-11-07 12:56:31 +00001389 */
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001390UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
1391 UINT cEntries,
1392 LPPALETTEENTRY lpPe )
Charles Suprin41043011998-11-07 12:56:31 +00001393{
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001394 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
1395 UINT uReturnValue = GDI_ERROR;
1396 EMF_PaletteCopy infoForCallBack;
1397
1398 TRACE( "(%04x,%d,%p)\n", hEmf, cEntries, lpPe );
1399
1400 /* First check if there are any palettes associated with
1401 this metafile. */
1402 if ( enhHeader->nPalEntries == 0 )
1403 {
1404 /* No palette associated with this enhanced metafile */
1405 uReturnValue = 0;
1406 goto done;
1407 }
1408
1409 /* Is the user requesting the number of palettes? */
1410 if ( lpPe == NULL )
1411 {
1412 uReturnValue = (UINT)enhHeader->nPalEntries;
1413 goto done;
1414 }
1415
1416 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1417 infoForCallBack.cEntries = cEntries;
1418 infoForCallBack.lpPe = lpPe;
1419
1420 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
1421 &infoForCallBack, NULL ) )
1422 {
1423 goto done;
1424 }
1425
1426 /* Verify that the callback executed correctly */
1427 if ( infoForCallBack.lpPe != NULL )
1428 {
1429 /* Callback proc had error! */
1430 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1431 goto done;
1432 }
1433
1434 uReturnValue = infoForCallBack.cEntries;
1435
1436done:
1437
1438 EMF_ReleaseEnhMetaHeader( hEmf );
1439
1440 return uReturnValue;
Charles Suprin41043011998-11-07 12:56:31 +00001441}
1442
Charles Suprin41043011998-11-07 12:56:31 +00001443/******************************************************************
1444 * SetWinMetaFileBits (GDI32.343)
1445 *
1446 * Translate from old style to new style.
Peter Hunnisettc821a751999-12-04 03:56:53 +00001447 *
1448 * BUGS: - This doesn't take the DC and scaling into account
1449 * - Most record conversions aren't implemented
1450 * - Handle slot assignement is primative and most likely doesn't work
Charles Suprin41043011998-11-07 12:56:31 +00001451 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001452HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
Charles Suprin41043011998-11-07 12:56:31 +00001453 CONST BYTE *lpbBuffer,
Alexandre Julliarda3960291999-02-26 11:11:13 +00001454 HDC hdcRef,
1455 CONST METAFILEPICT *lpmfp
Charles Suprin41043011998-11-07 12:56:31 +00001456 )
1457{
Peter Hunnisettc821a751999-12-04 03:56:53 +00001458 HENHMETAFILE hMf;
1459 LPVOID lpNewEnhMetaFileBuffer = NULL;
1460 UINT uNewEnhMetaFileBufferSize = 0;
1461 BOOL bFoundEOF = FALSE;
Charles Suprin41043011998-11-07 12:56:31 +00001462
Peter Hunnisettc821a751999-12-04 03:56:53 +00001463 FIXME( "(%d,%p,%04x,%p):stub\n", cbBuffer, lpbBuffer, hdcRef, lpmfp );
1464
1465 /* 1. Get the header - skip over this and get straight to the records */
1466
1467 uNewEnhMetaFileBufferSize = sizeof( ENHMETAHEADER );
Alexandre Julliard90476d62000-02-16 22:47:24 +00001468 lpNewEnhMetaFileBuffer = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
Peter Hunnisettc821a751999-12-04 03:56:53 +00001469 uNewEnhMetaFileBufferSize );
1470
1471 if( lpNewEnhMetaFileBuffer == NULL )
1472 {
1473 goto error;
1474 }
1475
1476 /* Fill in the header record */
1477 {
1478 LPENHMETAHEADER lpNewEnhMetaFileHeader = (LPENHMETAHEADER)lpNewEnhMetaFileBuffer;
1479
1480 lpNewEnhMetaFileHeader->iType = EMR_HEADER;
1481 lpNewEnhMetaFileHeader->nSize = sizeof( ENHMETAHEADER );
1482
1483 /* FIXME: Not right. Must be able to get this from the DC */
1484 lpNewEnhMetaFileHeader->rclBounds.left = 0;
1485 lpNewEnhMetaFileHeader->rclBounds.right = 0;
1486 lpNewEnhMetaFileHeader->rclBounds.top = 0;
1487 lpNewEnhMetaFileHeader->rclBounds.bottom = 0;
1488
1489 /* FIXME: Not right. Must be able to get this from the DC */
1490 lpNewEnhMetaFileHeader->rclFrame.left = 0;
1491 lpNewEnhMetaFileHeader->rclFrame.right = 0;
1492 lpNewEnhMetaFileHeader->rclFrame.top = 0;
1493 lpNewEnhMetaFileHeader->rclFrame.bottom = 0;
1494
1495 lpNewEnhMetaFileHeader->nHandles = 0; /* No handles yet */
1496
1497 /* FIXME: Add in the rest of the fields to the header */
1498 /* dSignature
1499 nVersion
1500 nRecords
1501 sReserved
1502 nDescription
1503 offDescription
1504 nPalEntries
1505 szlDevice
1506 szlMillimeters
1507 cbPixelFormat
1508 offPixelFormat,
1509 bOpenGL */
1510 }
1511
1512 (char*)lpbBuffer += ((METAHEADER*)lpbBuffer)->mtHeaderSize * 2; /* Point past the header - FIXME: metafile quirk? */
1513
1514 /* 2. Enum over individual records and convert them to the new type of records */
1515 while( !bFoundEOF )
1516 {
1517
1518 LPMETARECORD lpMetaRecord = (LPMETARECORD)lpbBuffer;
1519
1520#define EMF_ReAllocAndAdjustPointers( a , b ) \
1521 { \
1522 LPVOID lpTmp; \
Alexandre Julliard90476d62000-02-16 22:47:24 +00001523 lpTmp = HeapReAlloc( GetProcessHeap(), 0, \
Peter Hunnisettc821a751999-12-04 03:56:53 +00001524 lpNewEnhMetaFileBuffer, \
1525 uNewEnhMetaFileBufferSize + (b) ); \
1526 if( lpTmp == NULL ) { ERR( "No memory!\n" ); goto error; } \
1527 lpNewEnhMetaFileBuffer = lpTmp; \
1528 lpRecord = (a)( (char*)lpNewEnhMetaFileBuffer + uNewEnhMetaFileBufferSize ); \
1529 uNewEnhMetaFileBufferSize += (b); \
1530 }
1531
1532 switch( lpMetaRecord->rdFunction )
1533 {
1534 case META_EOF:
1535 {
1536 PEMREOF lpRecord;
1537 size_t uRecord = sizeof(*lpRecord);
1538
1539 EMF_ReAllocAndAdjustPointers(PEMREOF,uRecord);
1540
1541 /* Fill the new record - FIXME: This is not right */
1542 lpRecord->emr.iType = EMR_EOF;
1543 lpRecord->emr.nSize = sizeof( *lpRecord );
1544 lpRecord->nPalEntries = 0; /* FIXME */
1545 lpRecord->offPalEntries = 0; /* FIXME */
1546 lpRecord->nSizeLast = 0; /* FIXME */
1547
1548 /* No more records after this one */
1549 bFoundEOF = TRUE;
1550
1551 FIXME( "META_EOF conversion not correct\n" );
1552 break;
1553 }
1554
1555 case META_SETMAPMODE:
1556 {
1557 PEMRSETMAPMODE lpRecord;
1558 size_t uRecord = sizeof(*lpRecord);
1559
1560 EMF_ReAllocAndAdjustPointers(PEMRSETMAPMODE,uRecord);
1561
1562 lpRecord->emr.iType = EMR_SETMAPMODE;
1563 lpRecord->emr.nSize = sizeof( *lpRecord );
1564
1565 lpRecord->iMode = lpMetaRecord->rdParm[0];
1566
1567 break;
1568 }
1569
1570 case META_DELETEOBJECT: /* Select and Delete structures are the same */
1571 case META_SELECTOBJECT:
1572 {
1573 PEMRDELETEOBJECT lpRecord;
1574 size_t uRecord = sizeof(*lpRecord);
1575
1576 EMF_ReAllocAndAdjustPointers(PEMRDELETEOBJECT,uRecord);
1577
1578 if( lpMetaRecord->rdFunction == META_DELETEOBJECT )
1579 {
1580 lpRecord->emr.iType = EMR_DELETEOBJECT;
1581 }
1582 else
1583 {
1584 lpRecord->emr.iType = EMR_SELECTOBJECT;
1585 }
1586 lpRecord->emr.nSize = sizeof( *lpRecord );
1587
1588 lpRecord->ihObject = lpMetaRecord->rdParm[0]; /* FIXME: Handle */
1589
1590 break;
1591 }
1592
1593 case META_POLYGON: /* This is just plain busted. I don't know what I'm doing */
1594 {
1595 PEMRPOLYGON16 lpRecord; /* FIXME: Should it be a poly or poly16? */
1596 size_t uRecord = sizeof(*lpRecord);
1597
1598 EMF_ReAllocAndAdjustPointers(PEMRPOLYGON16,uRecord);
1599
1600 /* FIXME: This is mostly all wrong */
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001601 lpRecord->emr.iType = EMR_POLYGON16;
Peter Hunnisettc821a751999-12-04 03:56:53 +00001602 lpRecord->emr.nSize = sizeof( *lpRecord );
1603
1604 lpRecord->rclBounds.left = 0;
1605 lpRecord->rclBounds.right = 0;
1606 lpRecord->rclBounds.top = 0;
1607 lpRecord->rclBounds.bottom = 0;
1608
1609 lpRecord->cpts = 0;
1610 lpRecord->apts[0].x = 0;
1611 lpRecord->apts[0].y = 0;
1612
1613 FIXME( "META_POLYGON conversion not correct\n" );
1614
1615 break;
1616 }
1617
1618 case META_SETPOLYFILLMODE:
1619 {
1620 PEMRSETPOLYFILLMODE lpRecord;
1621 size_t uRecord = sizeof(*lpRecord);
1622
1623 EMF_ReAllocAndAdjustPointers(PEMRSETPOLYFILLMODE,uRecord);
1624
1625 lpRecord->emr.iType = EMR_SETPOLYFILLMODE;
1626 lpRecord->emr.nSize = sizeof( *lpRecord );
1627
1628 lpRecord->iMode = lpMetaRecord->rdParm[0];
1629
1630 break;
1631 }
1632
1633 case META_SETWINDOWORG:
1634 {
1635 PEMRSETWINDOWORGEX lpRecord; /* Seems to be the closest thing */
1636 size_t uRecord = sizeof(*lpRecord);
1637
1638 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWORGEX,uRecord);
1639
1640 lpRecord->emr.iType = EMR_SETWINDOWORGEX;
1641 lpRecord->emr.nSize = sizeof( *lpRecord );
1642
1643 lpRecord->ptlOrigin.x = lpMetaRecord->rdParm[1];
1644 lpRecord->ptlOrigin.y = lpMetaRecord->rdParm[0];
1645
1646 break;
1647 }
1648
1649 case META_SETWINDOWEXT: /* Structure is the same for SETWINDOWEXT & SETVIEWPORTEXT */
1650 case META_SETVIEWPORTEXT:
1651 {
1652 PEMRSETWINDOWEXTEX lpRecord;
1653 size_t uRecord = sizeof(*lpRecord);
1654
1655 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWEXTEX,uRecord);
1656
1657 if ( lpMetaRecord->rdFunction == META_SETWINDOWEXT )
1658 {
1659 lpRecord->emr.iType = EMR_SETWINDOWORGEX;
1660 }
1661 else
1662 {
1663 lpRecord->emr.iType = EMR_SETVIEWPORTEXTEX;
1664 }
1665 lpRecord->emr.nSize = sizeof( *lpRecord );
1666
1667 lpRecord->szlExtent.cx = lpMetaRecord->rdParm[1];
1668 lpRecord->szlExtent.cy = lpMetaRecord->rdParm[0];
1669
1670 break;
1671 }
1672
1673 case META_CREATEBRUSHINDIRECT:
1674 {
1675 PEMRCREATEBRUSHINDIRECT lpRecord;
1676 size_t uRecord = sizeof(*lpRecord);
1677
1678 EMF_ReAllocAndAdjustPointers(PEMRCREATEBRUSHINDIRECT,uRecord);
1679
1680 lpRecord->emr.iType = EMR_CREATEBRUSHINDIRECT;
1681 lpRecord->emr.nSize = sizeof( *lpRecord );
1682
1683 lpRecord->ihBrush = ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nHandles;
1684 lpRecord->lb.lbStyle = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbStyle;
1685 lpRecord->lb.lbColor = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbColor;
1686 lpRecord->lb.lbHatch = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbHatch;
1687
1688 ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nHandles += 1; /* New handle */
1689
1690 break;
1691 }
1692
1693
1694 /* These are all unimplemented and as such are intended to fall through to the default case */
1695 case META_SETBKCOLOR:
1696 case META_SETBKMODE:
1697 case META_SETROP2:
1698 case META_SETRELABS:
1699 case META_SETSTRETCHBLTMODE:
1700 case META_SETTEXTCOLOR:
1701 case META_SETVIEWPORTORG:
1702 case META_OFFSETWINDOWORG:
1703 case META_SCALEWINDOWEXT:
1704 case META_OFFSETVIEWPORTORG:
1705 case META_SCALEVIEWPORTEXT:
1706 case META_LINETO:
1707 case META_MOVETO:
1708 case META_EXCLUDECLIPRECT:
1709 case META_INTERSECTCLIPRECT:
1710 case META_ARC:
1711 case META_ELLIPSE:
1712 case META_FLOODFILL:
1713 case META_PIE:
1714 case META_RECTANGLE:
1715 case META_ROUNDRECT:
1716 case META_PATBLT:
1717 case META_SAVEDC:
1718 case META_SETPIXEL:
1719 case META_OFFSETCLIPRGN:
1720 case META_TEXTOUT:
1721 case META_POLYPOLYGON:
1722 case META_POLYLINE:
1723 case META_RESTOREDC:
1724 case META_CHORD:
1725 case META_CREATEPATTERNBRUSH:
1726 case META_CREATEPENINDIRECT:
1727 case META_CREATEFONTINDIRECT:
1728 case META_CREATEPALETTE:
1729 case META_SETTEXTALIGN:
1730 case META_SELECTPALETTE:
1731 case META_SETMAPPERFLAGS:
1732 case META_REALIZEPALETTE:
1733 case META_ESCAPE:
1734 case META_EXTTEXTOUT:
1735 case META_STRETCHDIB:
1736 case META_DIBSTRETCHBLT:
1737 case META_STRETCHBLT:
1738 case META_BITBLT:
1739 case META_CREATEREGION:
1740 case META_FILLREGION:
1741 case META_FRAMEREGION:
1742 case META_INVERTREGION:
1743 case META_PAINTREGION:
1744 case META_SELECTCLIPREGION:
1745 case META_DIBCREATEPATTERNBRUSH:
1746 case META_DIBBITBLT:
1747 case META_SETTEXTCHAREXTRA:
1748 case META_SETTEXTJUSTIFICATION:
1749 case META_EXTFLOODFILL:
1750 case META_SETDIBTODEV:
1751 case META_DRAWTEXT:
1752 case META_ANIMATEPALETTE:
1753 case META_SETPALENTRIES:
1754 case META_RESIZEPALETTE:
1755 case META_RESETDC:
1756 case META_STARTDOC:
1757 case META_STARTPAGE:
1758 case META_ENDPAGE:
1759 case META_ABORTDOC:
1760 case META_ENDDOC:
1761 case META_CREATEBRUSH:
1762 case META_CREATEBITMAPINDIRECT:
1763 case META_CREATEBITMAP:
1764 /* Fall through to unimplemented */
1765 default:
1766 {
1767 /* Not implemented yet */
1768 FIXME( "Conversion of record type 0x%x not implemented.\n", lpMetaRecord->rdFunction );
1769 break;
1770 }
1771 }
1772
1773 /* Move to the next record */
1774 (char*)lpbBuffer += ((LPMETARECORD)lpbBuffer)->rdSize * 2; /* FIXME: Seem to be doing this in metafile.c */
1775
1776#undef ReAllocAndAdjustPointers
1777 }
1778
1779 /* We know the last of the header information now */
1780 ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nBytes = uNewEnhMetaFileBufferSize;
1781
1782 /* Create the enhanced metafile */
1783 hMf = SetEnhMetaFileBits( uNewEnhMetaFileBufferSize, (const BYTE*)lpNewEnhMetaFileBuffer );
1784
1785 if( !hMf )
1786 ERR( "Problem creating metafile. Did the conversion fail somewhere?\n" );
1787
1788 return hMf;
1789
1790error:
1791 /* Free the data associated with our copy since it's been copied */
Alexandre Julliard90476d62000-02-16 22:47:24 +00001792 HeapFree( GetProcessHeap(), 0, lpNewEnhMetaFileBuffer );
Peter Hunnisettc821a751999-12-04 03:56:53 +00001793
1794 return 0;
1795}
Charles Suprin41043011998-11-07 12:56:31 +00001796
1797
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001798