blob: 60000a0e3f0988228d9cd6325b38954b31eb7de7 [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{
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 */
96static HENHMETAFILE EMF_GetEnhMetaFile( HFILE hFile )
97{
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(
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000121 LPCSTR lpszMetaFile /* filename of enhanced metafile */
122 )
123{
Huw D M Davies585c8461999-05-02 09:23:51 +0000124 HENHMETAFILE hmf;
125 HFILE hFile;
126
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(
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +0000143 LPCWSTR lpszMetaFile) /* filename of enhanced metafile */
144{
Huw D M Davies585c8461999-05-02 09:23:51 +0000145 HENHMETAFILE hmf;
146 HFILE hFile;
147
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(
168 HENHMETAFILE hmf, /* enhanced metafile */
169 UINT bufsize, /* size of buffer */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000170 LPENHMETAHEADER buf /* buffer */
171 )
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(
194 HENHMETAFILE hmf, /* enhanced metafile */
195 UINT size, /* size of buf */
Alexandre Julliard54c27111998-03-29 19:44:57 +0000196 LPSTR buf /* 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);
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000200 INT first, first_A;
Huw D M Davies585c8461999-05-02 09:23:51 +0000201
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000202 if(!emh) return FALSE;
Huw D M Davies585c8461999-05-02 09:23:51 +0000203 if(emh->nDescription == 0 || emh->offDescription == 0) {
204 EMF_ReleaseEnhMetaHeader(hmf);
205 return 0;
206 }
207 if (!buf || !size ) {
208 EMF_ReleaseEnhMetaHeader(hmf);
209 return emh->nDescription;
210 }
211
Patrik Stridvall896889f1999-05-08 12:50:36 +0000212 first = lstrlenW( (WCHAR *) ((char *) emh + emh->offDescription));
Huw D M Davies585c8461999-05-02 09:23:51 +0000213
Patrik Stridvall896889f1999-05-08 12:50:36 +0000214 lstrcpynWtoA(buf, (WCHAR *) ((char *) emh + emh->offDescription), size);
Alexandre Julliardcb10fda2000-08-06 02:41:16 +0000215 first_A = strlen( buf );
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000216 buf += first_A + 1;
Patrik Stridvall896889f1999-05-08 12:50:36 +0000217 lstrcpynWtoA(buf, (WCHAR *) ((char *) emh + emh->offDescription+2*(first+1)),
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000218 size - first_A - 1); /* i18n ready */
Alexandre Julliardcb10fda2000-08-06 02:41:16 +0000219 first_A += strlen(buf) + 1;
Huw D M Davies585c8461999-05-02 09:23:51 +0000220
221 EMF_ReleaseEnhMetaHeader(hmf);
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000222 return min(size, first_A);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000223}
224
225/*****************************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000226 * GetEnhMetaFileDescriptionW (GDI32.177)
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000227 *
228 * Copies the description string of an enhanced metafile into a buffer
229 * _buf_.
230 *
231 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
232 * number of characters copied.
233 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000234UINT WINAPI GetEnhMetaFileDescriptionW(
235 HENHMETAFILE hmf, /* enhanced metafile */
236 UINT size, /* size of buf */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000237 LPWSTR buf /* buffer to receive description */
238 )
239{
Huw D M Davies585c8461999-05-02 09:23:51 +0000240 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
Huw D M Davies0ae4e091999-06-12 06:49:52 +0000241
242 if(!emh) return FALSE;
Huw D M Davies585c8461999-05-02 09:23:51 +0000243 if(emh->nDescription == 0 || emh->offDescription == 0) {
244 EMF_ReleaseEnhMetaHeader(hmf);
245 return 0;
246 }
247 if (!buf || !size ) {
248 EMF_ReleaseEnhMetaHeader(hmf);
249 return emh->nDescription;
250 }
251
Patrik Stridvall896889f1999-05-08 12:50:36 +0000252 memmove(buf, (char *) emh + emh->offDescription,
Francois Gouget6d77d3a2000-03-25 21:44:35 +0000253 min(size,emh->nDescription));
Huw D M Davies585c8461999-05-02 09:23:51 +0000254 EMF_ReleaseEnhMetaHeader(hmf);
Francois Gouget6d77d3a2000-03-25 21:44:35 +0000255 return min(size, emh->nDescription);
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000256}
257
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000258/****************************************************************************
259 * SetEnhMetaFileBits (GDI32.315)
260 *
261 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
262 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000263HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000264{
Alexandre Julliard90476d62000-02-16 22:47:24 +0000265 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
Huw D M Davies585c8461999-05-02 09:23:51 +0000266 memmove(emh, buf, bufsize);
267 return EMF_Create_HENHMETAFILE( emh, 0, 0 );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000268}
269
270/*****************************************************************************
271 * GetEnhMetaFileBits (GDI32.175)
272 *
273 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000274UINT WINAPI GetEnhMetaFileBits(
275 HENHMETAFILE hmf,
276 UINT bufsize,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000277 LPBYTE buf
Peter Hunnisettc821a751999-12-04 03:56:53 +0000278)
279{
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000280 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
281 UINT size;
Peter Hunnisettc821a751999-12-04 03:56:53 +0000282
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000283 if(!emh) return 0;
Peter Hunnisettc821a751999-12-04 03:56:53 +0000284
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000285 size = emh->nBytes;
286 if( buf == NULL ) {
287 EMF_ReleaseEnhMetaHeader( hmf );
288 return size;
289 }
Peter Hunnisettc821a751999-12-04 03:56:53 +0000290
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000291 size = min( size, bufsize );
292 memmove(buf, emh, size);
Peter Hunnisettc821a751999-12-04 03:56:53 +0000293
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +0000294 EMF_ReleaseEnhMetaHeader( hmf );
295 return size;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000296}
297
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000298/*****************************************************************************
299 * PlayEnhMetaFileRecord (GDI32.264)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000300 *
301 * Render a single enhanced metafile record in the device context hdc.
302 *
303 * RETURNS
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000304 * TRUE (non zero) on success, FALSE on error.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000305 * BUGS
Alexandre Julliard54c27111998-03-29 19:44:57 +0000306 * Many unimplemented records.
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000307 * No error handling on record play failures (ie checking return codes)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000308 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000309BOOL WINAPI PlayEnhMetaFileRecord(
310 HDC hdc, /* device context in which to render EMF record */
311 LPHANDLETABLE handletable, /* array of handles to be used in rendering record */
Alexandre Julliard54c27111998-03-29 19:44:57 +0000312 const ENHMETARECORD *mr, /* EMF record to render */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000313 UINT handles /* size of handle array */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000314 )
315{
316 int type;
Alexandre Julliard15657091999-05-23 10:25:25 +0000317 TRACE(
Alexandre Julliard54c27111998-03-29 19:44:57 +0000318 "hdc = %08x, handletable = %p, record = %p, numHandles = %d\n",
319 hdc, handletable, mr, handles);
320 if (!mr) return FALSE;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000321
Alexandre Julliard54c27111998-03-29 19:44:57 +0000322 type = mr->iType;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000323
Alexandre Julliard15657091999-05-23 10:25:25 +0000324 TRACE(" type=%d\n", type);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000325 switch(type)
326 {
327 case EMR_HEADER:
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000328 break;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000329 case EMR_EOF:
Alexandre Julliard54c27111998-03-29 19:44:57 +0000330 break;
Alexandre Julliard54c27111998-03-29 19:44:57 +0000331 case EMR_GDICOMMENT:
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000332 {
333 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
334 /* In an enhanced metafile, there can be both public and private GDI comments */
335 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
336 break;
337 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000338 case EMR_SETMAPMODE:
339 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000340 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
341 SetMapMode(hdc, pSetMapMode->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000342 break;
343 }
344 case EMR_SETBKMODE:
345 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000346 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
347 SetBkMode(hdc, pSetBkMode->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000348 break;
349 }
350 case EMR_SETBKCOLOR:
351 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000352 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
353 SetBkColor(hdc, pSetBkColor->crColor);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000354 break;
355 }
356 case EMR_SETPOLYFILLMODE:
357 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000358 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
359 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000360 break;
361 }
362 case EMR_SETROP2:
363 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000364 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
365 SetROP2(hdc, pSetROP2->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000366 break;
367 }
368 case EMR_SETSTRETCHBLTMODE:
369 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000370 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
371 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000372 break;
373 }
374 case EMR_SETTEXTALIGN:
375 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000376 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
377 SetTextAlign(hdc, pSetTextAlign->iMode);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000378 break;
379 }
380 case EMR_SETTEXTCOLOR:
381 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000382 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
383 SetTextColor(hdc, pSetTextColor->crColor);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000384 break;
385 }
386 case EMR_SAVEDC:
387 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000388 SaveDC(hdc);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000389 break;
390 }
391 case EMR_RESTOREDC:
392 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000393 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
394 RestoreDC(hdc, pRestoreDC->iRelative);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000395 break;
396 }
397 case EMR_INTERSECTCLIPRECT:
398 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000399 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
400 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
401 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000402 break;
403 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000404 case EMR_SELECTOBJECT:
405 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000406 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
407 if( pSelectObject->ihObject & 0x80000000 ) {
408 /* High order bit is set - it's a stock object
409 * Strip the high bit to get the index.
410 * See MSDN article Q142319
411 */
412 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
413 0x7fffffff ) );
414 } else {
415 /* High order bit wasn't set - not a stock object
416 */
417 SelectObject( hdc,
418 (handletable->objectHandle)[pSelectObject->ihObject] );
419 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000420 break;
421 }
422 case EMR_DELETEOBJECT:
423 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000424 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
425 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
426 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
Alexandre Julliard54c27111998-03-29 19:44:57 +0000427 break;
428 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000429 case EMR_SETWINDOWORGEX:
430 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000431 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
432 SetWindowOrgEx(hdc, pSetWindowOrgEx->ptlOrigin.x,
433 pSetWindowOrgEx->ptlOrigin.y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000434 break;
435 }
436 case EMR_SETWINDOWEXTEX:
437 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000438 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
439 SetWindowExtEx(hdc, pSetWindowExtEx->szlExtent.cx,
440 pSetWindowExtEx->szlExtent.cy, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000441 break;
442 }
443 case EMR_SETVIEWPORTORGEX:
444 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000445 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
446 SetViewportOrgEx(hdc, pSetViewportOrgEx->ptlOrigin.x,
447 pSetViewportOrgEx->ptlOrigin.y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000448 break;
449 }
450 case EMR_SETVIEWPORTEXTEX:
451 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000452 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
453 SetViewportExtEx(hdc, pSetViewportExtEx->szlExtent.cx,
454 pSetViewportExtEx->szlExtent.cy, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000455 break;
456 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000457 case EMR_CREATEPEN:
458 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000459 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
460 (handletable->objectHandle)[pCreatePen->ihPen] =
461 CreatePenIndirect(&pCreatePen->lopn);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000462 break;
463 }
464 case EMR_EXTCREATEPEN:
465 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000466 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
467 LOGBRUSH lb;
468 lb.lbStyle = pPen->elp.elpBrushStyle;
469 lb.lbColor = pPen->elp.elpColor;
470 lb.lbHatch = pPen->elp.elpHatch;
471
472 if(pPen->offBmi || pPen->offBits)
473 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
474
475 (handletable->objectHandle)[pPen->ihPen] =
476 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
477 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000478 break;
479 }
480 case EMR_CREATEBRUSHINDIRECT:
481 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000482 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
483 (handletable->objectHandle)[pBrush->ihBrush] =
484 CreateBrushIndirect(&pBrush->lb);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000485 break;
486 }
487 case EMR_EXTCREATEFONTINDIRECTW:
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000488 {
489 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
490 (handletable->objectHandle)[pFont->ihFont] =
491 CreateFontIndirectW(&pFont->elfw.elfLogFont);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000492 break;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000493 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000494 case EMR_MOVETOEX:
495 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000496 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
497 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000498 break;
499 }
500 case EMR_LINETO:
501 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000502 PEMRLINETO pLineTo = (PEMRLINETO) mr;
503 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000504 break;
505 }
506 case EMR_RECTANGLE:
507 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000508 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
509 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
510 pRect->rclBox.right, pRect->rclBox.bottom);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000511 break;
512 }
513 case EMR_ELLIPSE:
514 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000515 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
516 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
517 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
Alexandre Julliard54c27111998-03-29 19:44:57 +0000518 break;
519 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000520 case EMR_POLYGON16:
521 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000522 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
523 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
524 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
525 pPoly->cpts * sizeof(POINT) );
526 DWORD i;
527 for(i = 0; i < pPoly->cpts; i++)
528 CONV_POINT16TO32(pPoly->apts + i, pts + i);
529 Polygon(hdc, pts, pPoly->cpts);
530 HeapFree( GetProcessHeap(), 0, pts );
Alexandre Julliard54c27111998-03-29 19:44:57 +0000531 break;
532 }
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000533 case EMR_POLYLINE16:
534 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000535 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
536 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
537 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
538 pPoly->cpts * sizeof(POINT) );
539 DWORD i;
540 for(i = 0; i < pPoly->cpts; i++)
541 CONV_POINT16TO32(pPoly->apts + i, pts + i);
542 Polyline(hdc, pts, pPoly->cpts);
543 HeapFree( GetProcessHeap(), 0, pts );
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000544 break;
545 }
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000546
Alexandre Julliard54c27111998-03-29 19:44:57 +0000547 case EMR_POLYPOLYGON16:
548 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000549 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
550 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
551 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000552
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000553 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
554 pPolyPoly->cpts * sizeof(POINT) );
555 DWORD i;
556 for(i = 0; i < pPolyPoly->cpts; i++)
557 CONV_POINT16TO32((POINTS*) (pPolyPoly->aPolyCounts +
558 pPolyPoly->nPolys) + i, pts + i);
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000559
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000560 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
561 HeapFree( GetProcessHeap(), 0, pts );
Alexandre Julliard54c27111998-03-29 19:44:57 +0000562 break;
563 }
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000564
Jason McMullane113b091999-02-09 14:08:57 +0000565 case EMR_STRETCHDIBITS:
566 {
567 LONG xDest = mr->dParm[4];
568 LONG yDest = mr->dParm[5];
569 LONG xSrc = mr->dParm[6];
570 LONG ySrc = mr->dParm[7];
571 LONG cxSrc = mr->dParm[8];
572 LONG cySrc = mr->dParm[9];
573 DWORD offBmiSrc = mr->dParm[10];
574 DWORD offBitsSrc = mr->dParm[12];
575 DWORD iUsageSrc = mr->dParm[14];
576 DWORD dwRop = mr->dParm[15];
577 LONG cxDest = mr->dParm[16];
578 LONG cyDest = mr->dParm[17];
579
Alexandre Julliarda3960291999-02-26 11:11:13 +0000580 StretchDIBits(hdc,xDest,yDest,cxDest,cyDest,
Jason McMullane113b091999-02-09 14:08:57 +0000581 xSrc,ySrc,cxSrc,cySrc,
582 ((char *)mr)+offBitsSrc,
583 (const BITMAPINFO *)(((char *)mr)+offBmiSrc),
584 iUsageSrc,dwRop);
585 break;
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000586 }
Alexandre Julliard54c27111998-03-29 19:44:57 +0000587 case EMR_EXTTEXTOUTW:
588 {
589 /* 0-3: ??? */
590 DWORD flags = mr->dParm[4];
591 /* 5, 6: ??? */
592 DWORD x = mr->dParm[7], y = mr->dParm[8];
593 DWORD count = mr->dParm[9];
594 /* 10-16: ??? */
595 LPWSTR str = (LPWSTR)& mr->dParm[17];
596 /* trailing info: dx array? */
Alexandre Julliard15657091999-05-23 10:25:25 +0000597 FIXME("Many ExtTextOut args not handled\n");
Alexandre Julliarda3960291999-02-26 11:11:13 +0000598 ExtTextOutW(hdc, x, y, flags, /* lpRect */ NULL,
Alexandre Julliard54c27111998-03-29 19:44:57 +0000599 str, count, /* lpDx */ NULL);
600 break;
601 }
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000602
603 case EMR_CREATEPALETTE:
604 {
605 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
Alexandre Julliard54c27111998-03-29 19:44:57 +0000606
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000607 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
608 CreatePalette( &lpCreatePal->lgpl );
609
610 break;
611 }
612
613 case EMR_SELECTPALETTE:
614 {
615 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
616
617 /* FIXME: Should this be forcing background mode? */
618 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
619 SelectPalette( hdc, lpSelectPal->ihPal, FALSE );
620 break;
621 }
622
623 case EMR_REALIZEPALETTE:
624 {
625 RealizePalette( hdc );
626 break;
627 }
628
629#if 0
630 case EMR_EXTSELECTCLIPRGN:
631 {
632 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
633
634 /* Need to make a region out of the RGNDATA we have */
635 ExtSelectClipRgn( hdc, ..., (INT)(lpRgn->iMode) );
636
637 }
638#endif
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000639
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000640 case EMR_SETMETARGN:
641 {
642 SetMetaRgn( hdc );
643 break;
644 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000645
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000646 case EMR_SETWORLDTRANSFORM:
647 {
648 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000649
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000650 SetWorldTransform( hdc, &lpXfrm->xform );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000651
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000652 break;
653 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000654
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000655 case EMR_POLYBEZIER:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000656 {
657 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000658 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000659 break;
660 }
661
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000662 case EMR_POLYGON:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000663 {
664 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000665 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000666 break;
667 }
668
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000669 case EMR_POLYLINE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000670 {
671 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000672 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000673 break;
674 }
675
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000676 case EMR_POLYBEZIERTO:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000677 {
678 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000679 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
680 (UINT)lpPolyBezierTo->cptl );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000681 break;
682 }
683
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000684 case EMR_POLYLINETO:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000685 {
686 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000687 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
688 (UINT)lpPolyLineTo->cptl );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000689 break;
690 }
691
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000692 case EMR_POLYPOLYLINE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000693 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000694 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
695 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000696
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000697 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
698 pPolyPolyline->nPolys),
699 pPolyPolyline->aPolyCounts,
700 pPolyPolyline->nPolys );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000701
702 break;
703 }
704
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000705 case EMR_POLYPOLYGON:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000706 {
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000707 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000708
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000709 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000710
Huw D M Daviesc9315fe2000-04-18 11:52:58 +0000711 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
712 pPolyPolygon->nPolys),
713 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000714 break;
715 }
716
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000717 case EMR_SETBRUSHORGEX:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000718 {
719 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
720
721 SetBrushOrgEx( hdc,
722 (INT)lpSetBrushOrgEx->ptlOrigin.x,
723 (INT)lpSetBrushOrgEx->ptlOrigin.y,
724 NULL );
725
726 break;
727 }
728
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000729 case EMR_SETPIXELV:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000730 {
731 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
732
733 SetPixelV( hdc,
734 (INT)lpSetPixelV->ptlPixel.x,
735 (INT)lpSetPixelV->ptlPixel.y,
736 lpSetPixelV->crColor );
737
738 break;
739 }
740
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000741 case EMR_SETMAPPERFLAGS:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000742 {
743 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
744
745 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
746
747 break;
748 }
749
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000750 case EMR_SETCOLORADJUSTMENT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000751 {
752 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
753
754 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
755
756 break;
757 }
758
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000759 case EMR_OFFSETCLIPRGN:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000760 {
761 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
762
763 OffsetClipRgn( hdc,
764 (INT)lpOffsetClipRgn->ptlOffset.x,
765 (INT)lpOffsetClipRgn->ptlOffset.y );
766
767 break;
768 }
769
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000770 case EMR_EXCLUDECLIPRECT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000771 {
772 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
773
774 ExcludeClipRect( hdc,
775 lpExcludeClipRect->rclClip.left,
776 lpExcludeClipRect->rclClip.top,
777 lpExcludeClipRect->rclClip.right,
778 lpExcludeClipRect->rclClip.bottom );
779
780 break;
781 }
782
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000783 case EMR_SCALEVIEWPORTEXTEX:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000784 {
785 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
786
787 ScaleViewportExtEx( hdc,
788 lpScaleViewportExtEx->xNum,
789 lpScaleViewportExtEx->xDenom,
790 lpScaleViewportExtEx->yNum,
791 lpScaleViewportExtEx->yDenom,
792 NULL );
793
794 break;
795 }
796
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000797 case EMR_SCALEWINDOWEXTEX:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000798 {
799 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
800
801 ScaleWindowExtEx( hdc,
802 lpScaleWindowExtEx->xNum,
803 lpScaleWindowExtEx->xDenom,
804 lpScaleWindowExtEx->yNum,
805 lpScaleWindowExtEx->yDenom,
806 NULL );
807
808 break;
809 }
810
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000811 case EMR_MODIFYWORLDTRANSFORM:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000812 {
813 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
814
815 ModifyWorldTransform( hdc, &lpModifyWorldTrans->xform,
816 lpModifyWorldTrans->iMode );
817
818 break;
819 }
820
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000821 case EMR_ANGLEARC:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000822 {
823 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
824
825 AngleArc( hdc,
826 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
827 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
828 lpAngleArc->eSweepAngle );
829
830 break;
831 }
832
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000833 case EMR_ROUNDRECT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000834 {
835 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
836
837 RoundRect( hdc,
838 lpRoundRect->rclBox.left,
839 lpRoundRect->rclBox.top,
840 lpRoundRect->rclBox.right,
841 lpRoundRect->rclBox.bottom,
842 lpRoundRect->szlCorner.cx,
843 lpRoundRect->szlCorner.cy );
844
845 break;
846 }
847
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000848 case EMR_ARC:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000849 {
850 PEMRARC lpArc = (PEMRARC)mr;
851
852 Arc( hdc,
853 (INT)lpArc->rclBox.left,
854 (INT)lpArc->rclBox.top,
855 (INT)lpArc->rclBox.right,
856 (INT)lpArc->rclBox.bottom,
857 (INT)lpArc->ptlStart.x,
858 (INT)lpArc->ptlStart.y,
859 (INT)lpArc->ptlEnd.x,
860 (INT)lpArc->ptlEnd.y );
861
862 break;
863 }
864
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000865 case EMR_CHORD:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000866 {
867 PEMRCHORD lpChord = (PEMRCHORD)mr;
868
869 Chord( hdc,
870 (INT)lpChord->rclBox.left,
871 (INT)lpChord->rclBox.top,
872 (INT)lpChord->rclBox.right,
873 (INT)lpChord->rclBox.bottom,
874 (INT)lpChord->ptlStart.x,
875 (INT)lpChord->ptlStart.y,
876 (INT)lpChord->ptlEnd.x,
877 (INT)lpChord->ptlEnd.y );
878
879 break;
880 }
881
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000882 case EMR_PIE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000883 {
884 PEMRPIE lpPie = (PEMRPIE)mr;
885
886 Pie( hdc,
887 (INT)lpPie->rclBox.left,
888 (INT)lpPie->rclBox.top,
889 (INT)lpPie->rclBox.right,
890 (INT)lpPie->rclBox.bottom,
891 (INT)lpPie->ptlStart.x,
892 (INT)lpPie->ptlStart.y,
893 (INT)lpPie->ptlEnd.x,
894 (INT)lpPie->ptlEnd.y );
895
896 break;
897 }
898
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000899 case EMR_ARCTO:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000900 {
901 PEMRARC lpArcTo = (PEMRARC)mr;
902
903 ArcTo( hdc,
904 (INT)lpArcTo->rclBox.left,
905 (INT)lpArcTo->rclBox.top,
906 (INT)lpArcTo->rclBox.right,
907 (INT)lpArcTo->rclBox.bottom,
908 (INT)lpArcTo->ptlStart.x,
909 (INT)lpArcTo->ptlStart.y,
910 (INT)lpArcTo->ptlEnd.x,
911 (INT)lpArcTo->ptlEnd.y );
912
913 break;
914 }
915
916 case EMR_EXTFLOODFILL:
917 {
918 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
919
920 ExtFloodFill( hdc,
921 (INT)lpExtFloodFill->ptlStart.x,
922 (INT)lpExtFloodFill->ptlStart.y,
923 lpExtFloodFill->crColor,
924 (UINT)lpExtFloodFill->iMode );
925
926 break;
927 }
928
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000929 case EMR_POLYDRAW:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000930 {
931 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000932 PolyDraw( hdc,
933 (const LPPOINT)lpPolyDraw->aptl,
934 lpPolyDraw->abTypes,
935 (INT)lpPolyDraw->cptl );
936
937 break;
938 }
939
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000940 case EMR_SETARCDIRECTION:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000941 {
942 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000943 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000944 break;
945 }
946
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000947 case EMR_SETMITERLIMIT:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000948 {
949 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000950 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000951 break;
952 }
953
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000954 case EMR_BEGINPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000955 {
956 BeginPath( hdc );
957 break;
958 }
959
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000960 case EMR_ENDPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000961 {
962 EndPath( hdc );
963 break;
964 }
965
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000966 case EMR_CLOSEFIGURE:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000967 {
968 CloseFigure( hdc );
969 break;
970 }
971
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000972 case EMR_FILLPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000973 {
974 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000975 FillPath( hdc );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000976 break;
977 }
978
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000979 case EMR_STROKEANDFILLPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000980 {
981 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000982 StrokeAndFillPath( hdc );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000983 break;
984 }
985
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000986 case EMR_STROKEPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000987 {
988 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000989 StrokePath( hdc );
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000990 break;
991 }
992
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000993 case EMR_FLATTENPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +0000994 {
995 FlattenPath( hdc );
996 break;
997 }
998
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +0000999 case EMR_WIDENPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001000 {
1001 WidenPath( hdc );
1002 break;
1003 }
1004
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001005 case EMR_SELECTCLIPPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001006 {
1007 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001008 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001009 break;
1010 }
1011
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001012 case EMR_ABORTPATH:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001013 {
1014 AbortPath( hdc );
1015 break;
1016 }
1017
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001018 case EMR_CREATECOLORSPACE:
1019 {
1020 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001021 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1022 CreateColorSpaceA( &lpCreateColorSpace->lcs );
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001023 break;
1024 }
1025
1026 case EMR_SETCOLORSPACE:
1027 {
1028 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001029 SetColorSpace( hdc,
1030 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001031 break;
1032 }
1033
1034 case EMR_DELETECOLORSPACE:
1035 {
1036 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001037 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001038 break;
1039 }
1040
1041 case EMR_SETICMMODE:
1042 {
1043 PERMSETICMMODE lpSetICMMode = (PERMSETICMMODE)mr;
Huw D M Daviesc9315fe2000-04-18 11:52:58 +00001044 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001045 break;
1046 }
1047
1048 case EMR_PIXELFORMAT:
1049 {
1050 INT iPixelFormat;
1051 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1052
1053 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1054 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1055
1056 break;
1057 }
1058
1059 case EMR_SETPALETTEENTRIES:
1060 {
1061 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1062
1063 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1064 (UINT)lpSetPaletteEntries->iStart,
1065 (UINT)lpSetPaletteEntries->cEntries,
1066 lpSetPaletteEntries->aPalEntries );
1067
1068 break;
1069 }
1070
1071 case EMR_RESIZEPALETTE:
1072 {
1073 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1074
1075 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1076 (UINT)lpResizePalette->cEntries );
1077
1078 break;
1079 }
1080
1081 case EMR_CREATEDIBPATTERNBRUSHPT:
1082 {
1083 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1084
1085 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1086 LPVOID lpPackedStruct = HeapAlloc( GetProcessHeap(),
1087 0,
1088 lpCreate->cbBmi + lpCreate->cbBits );
1089 /* Now pack this structure */
1090 memcpy( lpPackedStruct,
1091 ((BYTE*)lpCreate) + lpCreate->offBmi,
1092 lpCreate->cbBmi );
1093 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1094 ((BYTE*)lpCreate) + lpCreate->offBits,
1095 lpCreate->cbBits );
1096
1097 (handletable->objectHandle)[lpCreate->ihBrush] =
1098 CreateDIBPatternBrushPt( lpPackedStruct,
1099 (UINT)lpCreate->iUsage );
1100
1101 break;
1102 }
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001103
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001104 case EMR_BITBLT:
1105 case EMR_STRETCHBLT:
1106 case EMR_MASKBLT:
1107 case EMR_PLGBLT:
1108 case EMR_SETDIBITSTODEVICE:
1109 case EMR_EXTTEXTOUTA:
1110 case EMR_POLYBEZIER16:
1111 case EMR_POLYBEZIERTO16:
1112 case EMR_POLYLINETO16:
1113 case EMR_POLYPOLYLINE16:
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001114 case EMR_POLYDRAW16:
1115 case EMR_CREATEMONOBRUSH:
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001116 case EMR_POLYTEXTOUTA:
1117 case EMR_POLYTEXTOUTW:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001118 case EMR_FILLRGN:
1119 case EMR_FRAMERGN:
1120 case EMR_INVERTRGN:
1121 case EMR_PAINTRGN:
Peter Hunnisettf2b84922000-01-15 22:17:49 +00001122 case EMR_GLSRECORD:
1123 case EMR_GLSBOUNDEDRECORD:
Alexandre Julliard54c27111998-03-29 19:44:57 +00001124 default:
Peter Hunnisett27548ee1999-12-25 22:58:59 +00001125 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1126 record then ignore and return TRUE. */
Alexandre Julliard15657091999-05-23 10:25:25 +00001127 FIXME("type %d is unimplemented\n", type);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001128 break;
1129 }
Alexandre Julliard54c27111998-03-29 19:44:57 +00001130 return TRUE;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001131}
1132
1133
1134/*****************************************************************************
1135 *
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001136 * EnumEnhMetaFile (GDI32.79)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001137 *
1138 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1139 * for each
1140 * record. Returns when either every record has been used or
1141 * when _EnhMetaFunc_ returns FALSE.
1142 *
1143 *
1144 * RETURNS
1145 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1146 * returns FALSE.
1147 *
1148 * BUGS
Alexandre Julliard54c27111998-03-29 19:44:57 +00001149 * Ignores rect.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001150 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001151BOOL WINAPI EnumEnhMetaFile(
1152 HDC hdc, /* device context to pass to _EnhMetaFunc_ */
1153 HENHMETAFILE hmf, /* EMF to walk */
1154 ENHMFENUMPROC callback, /* callback function */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001155 LPVOID data, /* optional data for callback function */
Huw D M Davies280aeb92000-03-30 20:22:41 +00001156 const RECT *lpRect /* bounding rectangle for rendered metafile */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001157 )
1158{
Huw D M Davies585c8461999-05-02 09:23:51 +00001159 BOOL ret = TRUE;
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001160 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
Huw D M Davies280aeb92000-03-30 20:22:41 +00001161 INT count, i;
Huw D M Davies0ae4e091999-06-12 06:49:52 +00001162 HANDLETABLE *ht;
Huw D M Davies585c8461999-05-02 09:23:51 +00001163 INT savedMode = 0;
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001164 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1165 XFORM savedXform, xform;
Huw D M Davies0ae4e091999-06-12 06:49:52 +00001166
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001167 if(!emh) {
1168 SetLastError(ERROR_INVALID_HANDLE);
1169 return FALSE;
1170 }
1171 if(!lpRect) {
1172 SetLastError(ERROR_INVALID_PARAMETER);
1173 return FALSE;
1174 }
1175 count = emh->nHandles;
Huw D M Davies280aeb92000-03-30 20:22:41 +00001176 ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1177 sizeof(HANDLETABLE) * count );
1178 ht->objectHandle[0] = hmf;
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001179
1180 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
1181 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
1182 xscale = (FLOAT)(lpRect->right - lpRect->left) * 100.0 /
1183 (emh->rclFrame.right - emh->rclFrame.left) * xSrcPixSize;
1184 yscale = (FLOAT)(lpRect->bottom - lpRect->top) * 100.0 /
1185 (emh->rclFrame.bottom - emh->rclFrame.top) * ySrcPixSize;
1186
1187 xform.eM11 = xscale;
1188 xform.eM12 = 0;
1189 xform.eM21 = 0;
1190 xform.eM22 = yscale;
1191 if(emh->rclFrame.left || emh->rclFrame.top)
1192 FIXME("Can't cope with nonzero rclFrame origin yet\n");
1193 /* eDx = lpRect->left - (lpRect width) / (rclFrame width) * rclFrame.left ? */
1194 xform.eDx = lpRect->left;
1195 xform.eDy = lpRect->top;
1196 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1197 GetWorldTransform(hdc, &savedXform);
1198 if (!ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY)) {
1199 ERR("World transform failed!\n");
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001200 }
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001201
Huw D M Davies280aeb92000-03-30 20:22:41 +00001202 while (ret) {
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001203 ret = (*callback)(hdc, ht, (LPENHMETARECORD) emh, count, data);
1204 if (emh->iType == EMR_EOF) break;
1205 emh = (LPENHMETAHEADER) ((char *) emh + emh->nSize);
Huw D M Davies585c8461999-05-02 09:23:51 +00001206 }
Huw D M Davies280aeb92000-03-30 20:22:41 +00001207 for(i = 1; i < count; i++) /* Don't delete element 0 (hmf) */
1208 if( (ht->objectHandle)[i] )
1209 DeleteObject( (ht->objectHandle)[i] );
Huw D M Davies585c8461999-05-02 09:23:51 +00001210 HeapFree( GetProcessHeap(), 0, ht );
1211 EMF_ReleaseEnhMetaHeader(hmf);
Huw D M Davies2cf4ebc2000-04-13 15:57:34 +00001212 SetWorldTransform(hdc, &savedXform);
Huw D M Davies585c8461999-05-02 09:23:51 +00001213 if (savedMode) SetGraphicsMode(hdc, savedMode);
Huw D M Davies585c8461999-05-02 09:23:51 +00001214 return ret;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001215}
1216
Huw D M Davies280aeb92000-03-30 20:22:41 +00001217static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
1218 ENHMETARECORD *emr,
1219 INT handles, LPVOID data)
1220{
1221 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
1222}
1223
1224/**************************************************************************
1225 * PlayEnhMetaFile (GDI32.263)
1226 *
1227 * Renders an enhanced metafile into a specified rectangle *lpRect
1228 * in device context hdc.
1229 *
1230 */
1231BOOL WINAPI PlayEnhMetaFile(
1232 HDC hdc, /* DC to render into */
1233 HENHMETAFILE hmf, /* metafile to render */
1234 const RECT *lpRect /* rectangle to place metafile inside */
1235 )
1236{
1237 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
1238 lpRect);
1239}
1240
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001241/*****************************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00001242 * DeleteEnhMetaFile (GDI32.68)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001243 *
1244 * Deletes an enhanced metafile and frees the associated storage.
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001245 */
Huw D M Davies585c8461999-05-02 09:23:51 +00001246BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
1247{
1248 return EMF_Delete_HENHMETAFILE( hmf );
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001249}
1250
1251/*****************************************************************************
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001252 * CopyEnhMetaFileA (GDI32.21) Duplicate an enhanced metafile
1253 *
1254 *
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001255 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001256HENHMETAFILE WINAPI CopyEnhMetaFileA(
Huw D M Davies585c8461999-05-02 09:23:51 +00001257 HENHMETAFILE hmfSrc,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001258 LPCSTR file)
1259{
Huw D M Davies585c8461999-05-02 09:23:51 +00001260 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
1261 HENHMETAFILE hmfDst;
1262
Huw D M Davies0ae4e091999-06-12 06:49:52 +00001263 if(!emrSrc) return FALSE;
Huw D M Davies585c8461999-05-02 09:23:51 +00001264 if (!file) {
Alexandre Julliard90476d62000-02-16 22:47:24 +00001265 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
Huw D M Davies585c8461999-05-02 09:23:51 +00001266 memcpy( emrDst, emrSrc, emrSrc->nBytes );
1267 hmfDst = EMF_Create_HENHMETAFILE( emrDst, 0, 0 );
1268 } else {
1269 HFILE hFile;
1270 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0, NULL,
1271 CREATE_ALWAYS, 0, -1);
1272 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
1273 hmfDst = EMF_GetEnhMetaFile( hFile );
1274 }
1275 EMF_ReleaseEnhMetaHeader( hmfSrc );
1276 return hmfDst;
Alexandre Julliard54c27111998-03-29 19:44:57 +00001277}
1278
Huw D M Davies585c8461999-05-02 09:23:51 +00001279
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001280/* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1281typedef struct tagEMF_PaletteCopy
1282{
1283 UINT cEntries;
1284 LPPALETTEENTRY lpPe;
1285} EMF_PaletteCopy;
1286
1287/***************************************************************
1288 * Find the EMR_EOF record and then use it to find the
1289 * palette entries for this enhanced metafile.
1290 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1291 * which contains the max number of elements to copy and where
1292 * to copy them to.
1293 *
1294 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1295 */
1296INT CALLBACK cbEnhPaletteCopy( HDC a,
1297 LPHANDLETABLE b,
1298 LPENHMETARECORD lpEMR,
1299 INT c,
1300 LPVOID lpData )
1301{
1302
1303 if ( lpEMR->iType == EMR_EOF )
1304 {
1305 PEMREOF lpEof = (PEMREOF)lpEMR;
1306 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
Francois Gouget6d77d3a2000-03-25 21:44:35 +00001307 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001308
1309 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
1310
1311 memcpy( (LPVOID)info->lpPe,
1312 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
1313 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
1314
1315 /* Update the passed data as a return code */
1316 info->lpPe = NULL; /* Palettes were copied! */
1317 info->cEntries = (UINT)dwNumPalToCopy;
1318
1319 return FALSE; /* That's all we need */
1320 }
1321
1322 return TRUE;
1323}
1324
Charles Suprin41043011998-11-07 12:56:31 +00001325/*****************************************************************************
1326 * GetEnhMetaFilePaletteEntries (GDI32.179)
1327 *
1328 * Copy the palette and report size
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001329 *
1330 * BUGS: Error codes (SetLastError) are not set on failures
Charles Suprin41043011998-11-07 12:56:31 +00001331 */
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001332UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
1333 UINT cEntries,
1334 LPPALETTEENTRY lpPe )
Charles Suprin41043011998-11-07 12:56:31 +00001335{
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001336 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
1337 UINT uReturnValue = GDI_ERROR;
1338 EMF_PaletteCopy infoForCallBack;
1339
1340 TRACE( "(%04x,%d,%p)\n", hEmf, cEntries, lpPe );
1341
1342 /* First check if there are any palettes associated with
1343 this metafile. */
1344 if ( enhHeader->nPalEntries == 0 )
1345 {
1346 /* No palette associated with this enhanced metafile */
1347 uReturnValue = 0;
1348 goto done;
1349 }
1350
1351 /* Is the user requesting the number of palettes? */
1352 if ( lpPe == NULL )
1353 {
1354 uReturnValue = (UINT)enhHeader->nPalEntries;
1355 goto done;
1356 }
1357
1358 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1359 infoForCallBack.cEntries = cEntries;
1360 infoForCallBack.lpPe = lpPe;
1361
1362 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
1363 &infoForCallBack, NULL ) )
1364 {
1365 goto done;
1366 }
1367
1368 /* Verify that the callback executed correctly */
1369 if ( infoForCallBack.lpPe != NULL )
1370 {
1371 /* Callback proc had error! */
1372 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1373 goto done;
1374 }
1375
1376 uReturnValue = infoForCallBack.cEntries;
1377
1378done:
1379
1380 EMF_ReleaseEnhMetaHeader( hEmf );
1381
1382 return uReturnValue;
Charles Suprin41043011998-11-07 12:56:31 +00001383}
1384
Charles Suprin41043011998-11-07 12:56:31 +00001385/******************************************************************
1386 * SetWinMetaFileBits (GDI32.343)
1387 *
1388 * Translate from old style to new style.
Peter Hunnisettc821a751999-12-04 03:56:53 +00001389 *
1390 * BUGS: - This doesn't take the DC and scaling into account
1391 * - Most record conversions aren't implemented
1392 * - Handle slot assignement is primative and most likely doesn't work
Charles Suprin41043011998-11-07 12:56:31 +00001393 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001394HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
Charles Suprin41043011998-11-07 12:56:31 +00001395 CONST BYTE *lpbBuffer,
Alexandre Julliarda3960291999-02-26 11:11:13 +00001396 HDC hdcRef,
1397 CONST METAFILEPICT *lpmfp
Charles Suprin41043011998-11-07 12:56:31 +00001398 )
1399{
Peter Hunnisettc821a751999-12-04 03:56:53 +00001400 HENHMETAFILE hMf;
1401 LPVOID lpNewEnhMetaFileBuffer = NULL;
1402 UINT uNewEnhMetaFileBufferSize = 0;
1403 BOOL bFoundEOF = FALSE;
Charles Suprin41043011998-11-07 12:56:31 +00001404
Peter Hunnisettc821a751999-12-04 03:56:53 +00001405 FIXME( "(%d,%p,%04x,%p):stub\n", cbBuffer, lpbBuffer, hdcRef, lpmfp );
1406
1407 /* 1. Get the header - skip over this and get straight to the records */
1408
1409 uNewEnhMetaFileBufferSize = sizeof( ENHMETAHEADER );
Alexandre Julliard90476d62000-02-16 22:47:24 +00001410 lpNewEnhMetaFileBuffer = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
Peter Hunnisettc821a751999-12-04 03:56:53 +00001411 uNewEnhMetaFileBufferSize );
1412
1413 if( lpNewEnhMetaFileBuffer == NULL )
1414 {
1415 goto error;
1416 }
1417
1418 /* Fill in the header record */
1419 {
1420 LPENHMETAHEADER lpNewEnhMetaFileHeader = (LPENHMETAHEADER)lpNewEnhMetaFileBuffer;
1421
1422 lpNewEnhMetaFileHeader->iType = EMR_HEADER;
1423 lpNewEnhMetaFileHeader->nSize = sizeof( ENHMETAHEADER );
1424
1425 /* FIXME: Not right. Must be able to get this from the DC */
1426 lpNewEnhMetaFileHeader->rclBounds.left = 0;
1427 lpNewEnhMetaFileHeader->rclBounds.right = 0;
1428 lpNewEnhMetaFileHeader->rclBounds.top = 0;
1429 lpNewEnhMetaFileHeader->rclBounds.bottom = 0;
1430
1431 /* FIXME: Not right. Must be able to get this from the DC */
1432 lpNewEnhMetaFileHeader->rclFrame.left = 0;
1433 lpNewEnhMetaFileHeader->rclFrame.right = 0;
1434 lpNewEnhMetaFileHeader->rclFrame.top = 0;
1435 lpNewEnhMetaFileHeader->rclFrame.bottom = 0;
1436
1437 lpNewEnhMetaFileHeader->nHandles = 0; /* No handles yet */
1438
1439 /* FIXME: Add in the rest of the fields to the header */
1440 /* dSignature
1441 nVersion
1442 nRecords
1443 sReserved
1444 nDescription
1445 offDescription
1446 nPalEntries
1447 szlDevice
1448 szlMillimeters
1449 cbPixelFormat
1450 offPixelFormat,
1451 bOpenGL */
1452 }
1453
1454 (char*)lpbBuffer += ((METAHEADER*)lpbBuffer)->mtHeaderSize * 2; /* Point past the header - FIXME: metafile quirk? */
1455
1456 /* 2. Enum over individual records and convert them to the new type of records */
1457 while( !bFoundEOF )
1458 {
1459
1460 LPMETARECORD lpMetaRecord = (LPMETARECORD)lpbBuffer;
1461
1462#define EMF_ReAllocAndAdjustPointers( a , b ) \
1463 { \
1464 LPVOID lpTmp; \
Alexandre Julliard90476d62000-02-16 22:47:24 +00001465 lpTmp = HeapReAlloc( GetProcessHeap(), 0, \
Peter Hunnisettc821a751999-12-04 03:56:53 +00001466 lpNewEnhMetaFileBuffer, \
1467 uNewEnhMetaFileBufferSize + (b) ); \
1468 if( lpTmp == NULL ) { ERR( "No memory!\n" ); goto error; } \
1469 lpNewEnhMetaFileBuffer = lpTmp; \
1470 lpRecord = (a)( (char*)lpNewEnhMetaFileBuffer + uNewEnhMetaFileBufferSize ); \
1471 uNewEnhMetaFileBufferSize += (b); \
1472 }
1473
1474 switch( lpMetaRecord->rdFunction )
1475 {
1476 case META_EOF:
1477 {
1478 PEMREOF lpRecord;
1479 size_t uRecord = sizeof(*lpRecord);
1480
1481 EMF_ReAllocAndAdjustPointers(PEMREOF,uRecord);
1482
1483 /* Fill the new record - FIXME: This is not right */
1484 lpRecord->emr.iType = EMR_EOF;
1485 lpRecord->emr.nSize = sizeof( *lpRecord );
1486 lpRecord->nPalEntries = 0; /* FIXME */
1487 lpRecord->offPalEntries = 0; /* FIXME */
1488 lpRecord->nSizeLast = 0; /* FIXME */
1489
1490 /* No more records after this one */
1491 bFoundEOF = TRUE;
1492
1493 FIXME( "META_EOF conversion not correct\n" );
1494 break;
1495 }
1496
1497 case META_SETMAPMODE:
1498 {
1499 PEMRSETMAPMODE lpRecord;
1500 size_t uRecord = sizeof(*lpRecord);
1501
1502 EMF_ReAllocAndAdjustPointers(PEMRSETMAPMODE,uRecord);
1503
1504 lpRecord->emr.iType = EMR_SETMAPMODE;
1505 lpRecord->emr.nSize = sizeof( *lpRecord );
1506
1507 lpRecord->iMode = lpMetaRecord->rdParm[0];
1508
1509 break;
1510 }
1511
1512 case META_DELETEOBJECT: /* Select and Delete structures are the same */
1513 case META_SELECTOBJECT:
1514 {
1515 PEMRDELETEOBJECT lpRecord;
1516 size_t uRecord = sizeof(*lpRecord);
1517
1518 EMF_ReAllocAndAdjustPointers(PEMRDELETEOBJECT,uRecord);
1519
1520 if( lpMetaRecord->rdFunction == META_DELETEOBJECT )
1521 {
1522 lpRecord->emr.iType = EMR_DELETEOBJECT;
1523 }
1524 else
1525 {
1526 lpRecord->emr.iType = EMR_SELECTOBJECT;
1527 }
1528 lpRecord->emr.nSize = sizeof( *lpRecord );
1529
1530 lpRecord->ihObject = lpMetaRecord->rdParm[0]; /* FIXME: Handle */
1531
1532 break;
1533 }
1534
1535 case META_POLYGON: /* This is just plain busted. I don't know what I'm doing */
1536 {
1537 PEMRPOLYGON16 lpRecord; /* FIXME: Should it be a poly or poly16? */
1538 size_t uRecord = sizeof(*lpRecord);
1539
1540 EMF_ReAllocAndAdjustPointers(PEMRPOLYGON16,uRecord);
1541
1542 /* FIXME: This is mostly all wrong */
Peter Hunnisett0cdc4d91999-12-11 23:18:10 +00001543 lpRecord->emr.iType = EMR_POLYGON16;
Peter Hunnisettc821a751999-12-04 03:56:53 +00001544 lpRecord->emr.nSize = sizeof( *lpRecord );
1545
1546 lpRecord->rclBounds.left = 0;
1547 lpRecord->rclBounds.right = 0;
1548 lpRecord->rclBounds.top = 0;
1549 lpRecord->rclBounds.bottom = 0;
1550
1551 lpRecord->cpts = 0;
1552 lpRecord->apts[0].x = 0;
1553 lpRecord->apts[0].y = 0;
1554
1555 FIXME( "META_POLYGON conversion not correct\n" );
1556
1557 break;
1558 }
1559
1560 case META_SETPOLYFILLMODE:
1561 {
1562 PEMRSETPOLYFILLMODE lpRecord;
1563 size_t uRecord = sizeof(*lpRecord);
1564
1565 EMF_ReAllocAndAdjustPointers(PEMRSETPOLYFILLMODE,uRecord);
1566
1567 lpRecord->emr.iType = EMR_SETPOLYFILLMODE;
1568 lpRecord->emr.nSize = sizeof( *lpRecord );
1569
1570 lpRecord->iMode = lpMetaRecord->rdParm[0];
1571
1572 break;
1573 }
1574
1575 case META_SETWINDOWORG:
1576 {
1577 PEMRSETWINDOWORGEX lpRecord; /* Seems to be the closest thing */
1578 size_t uRecord = sizeof(*lpRecord);
1579
1580 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWORGEX,uRecord);
1581
1582 lpRecord->emr.iType = EMR_SETWINDOWORGEX;
1583 lpRecord->emr.nSize = sizeof( *lpRecord );
1584
1585 lpRecord->ptlOrigin.x = lpMetaRecord->rdParm[1];
1586 lpRecord->ptlOrigin.y = lpMetaRecord->rdParm[0];
1587
1588 break;
1589 }
1590
1591 case META_SETWINDOWEXT: /* Structure is the same for SETWINDOWEXT & SETVIEWPORTEXT */
1592 case META_SETVIEWPORTEXT:
1593 {
1594 PEMRSETWINDOWEXTEX lpRecord;
1595 size_t uRecord = sizeof(*lpRecord);
1596
1597 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWEXTEX,uRecord);
1598
1599 if ( lpMetaRecord->rdFunction == META_SETWINDOWEXT )
1600 {
1601 lpRecord->emr.iType = EMR_SETWINDOWORGEX;
1602 }
1603 else
1604 {
1605 lpRecord->emr.iType = EMR_SETVIEWPORTEXTEX;
1606 }
1607 lpRecord->emr.nSize = sizeof( *lpRecord );
1608
1609 lpRecord->szlExtent.cx = lpMetaRecord->rdParm[1];
1610 lpRecord->szlExtent.cy = lpMetaRecord->rdParm[0];
1611
1612 break;
1613 }
1614
1615 case META_CREATEBRUSHINDIRECT:
1616 {
1617 PEMRCREATEBRUSHINDIRECT lpRecord;
1618 size_t uRecord = sizeof(*lpRecord);
1619
1620 EMF_ReAllocAndAdjustPointers(PEMRCREATEBRUSHINDIRECT,uRecord);
1621
1622 lpRecord->emr.iType = EMR_CREATEBRUSHINDIRECT;
1623 lpRecord->emr.nSize = sizeof( *lpRecord );
1624
1625 lpRecord->ihBrush = ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nHandles;
1626 lpRecord->lb.lbStyle = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbStyle;
1627 lpRecord->lb.lbColor = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbColor;
1628 lpRecord->lb.lbHatch = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbHatch;
1629
1630 ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nHandles += 1; /* New handle */
1631
1632 break;
1633 }
1634
1635
1636 /* These are all unimplemented and as such are intended to fall through to the default case */
1637 case META_SETBKCOLOR:
1638 case META_SETBKMODE:
1639 case META_SETROP2:
1640 case META_SETRELABS:
1641 case META_SETSTRETCHBLTMODE:
1642 case META_SETTEXTCOLOR:
1643 case META_SETVIEWPORTORG:
1644 case META_OFFSETWINDOWORG:
1645 case META_SCALEWINDOWEXT:
1646 case META_OFFSETVIEWPORTORG:
1647 case META_SCALEVIEWPORTEXT:
1648 case META_LINETO:
1649 case META_MOVETO:
1650 case META_EXCLUDECLIPRECT:
1651 case META_INTERSECTCLIPRECT:
1652 case META_ARC:
1653 case META_ELLIPSE:
1654 case META_FLOODFILL:
1655 case META_PIE:
1656 case META_RECTANGLE:
1657 case META_ROUNDRECT:
1658 case META_PATBLT:
1659 case META_SAVEDC:
1660 case META_SETPIXEL:
1661 case META_OFFSETCLIPRGN:
1662 case META_TEXTOUT:
1663 case META_POLYPOLYGON:
1664 case META_POLYLINE:
1665 case META_RESTOREDC:
1666 case META_CHORD:
1667 case META_CREATEPATTERNBRUSH:
1668 case META_CREATEPENINDIRECT:
1669 case META_CREATEFONTINDIRECT:
1670 case META_CREATEPALETTE:
1671 case META_SETTEXTALIGN:
1672 case META_SELECTPALETTE:
1673 case META_SETMAPPERFLAGS:
1674 case META_REALIZEPALETTE:
1675 case META_ESCAPE:
1676 case META_EXTTEXTOUT:
1677 case META_STRETCHDIB:
1678 case META_DIBSTRETCHBLT:
1679 case META_STRETCHBLT:
1680 case META_BITBLT:
1681 case META_CREATEREGION:
1682 case META_FILLREGION:
1683 case META_FRAMEREGION:
1684 case META_INVERTREGION:
1685 case META_PAINTREGION:
1686 case META_SELECTCLIPREGION:
1687 case META_DIBCREATEPATTERNBRUSH:
1688 case META_DIBBITBLT:
1689 case META_SETTEXTCHAREXTRA:
1690 case META_SETTEXTJUSTIFICATION:
1691 case META_EXTFLOODFILL:
1692 case META_SETDIBTODEV:
1693 case META_DRAWTEXT:
1694 case META_ANIMATEPALETTE:
1695 case META_SETPALENTRIES:
1696 case META_RESIZEPALETTE:
1697 case META_RESETDC:
1698 case META_STARTDOC:
1699 case META_STARTPAGE:
1700 case META_ENDPAGE:
1701 case META_ABORTDOC:
1702 case META_ENDDOC:
1703 case META_CREATEBRUSH:
1704 case META_CREATEBITMAPINDIRECT:
1705 case META_CREATEBITMAP:
1706 /* Fall through to unimplemented */
1707 default:
1708 {
1709 /* Not implemented yet */
1710 FIXME( "Conversion of record type 0x%x not implemented.\n", lpMetaRecord->rdFunction );
1711 break;
1712 }
1713 }
1714
1715 /* Move to the next record */
1716 (char*)lpbBuffer += ((LPMETARECORD)lpbBuffer)->rdSize * 2; /* FIXME: Seem to be doing this in metafile.c */
1717
1718#undef ReAllocAndAdjustPointers
1719 }
1720
1721 /* We know the last of the header information now */
1722 ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nBytes = uNewEnhMetaFileBufferSize;
1723
1724 /* Create the enhanced metafile */
1725 hMf = SetEnhMetaFileBits( uNewEnhMetaFileBufferSize, (const BYTE*)lpNewEnhMetaFileBuffer );
1726
1727 if( !hMf )
1728 ERR( "Problem creating metafile. Did the conversion fail somewhere?\n" );
1729
1730 return hMf;
1731
1732error:
1733 /* Free the data associated with our copy since it's been copied */
Alexandre Julliard90476d62000-02-16 22:47:24 +00001734 HeapFree( GetProcessHeap(), 0, lpNewEnhMetaFileBuffer );
Peter Hunnisettc821a751999-12-04 03:56:53 +00001735
1736 return 0;
1737}
Charles Suprin41043011998-11-07 12:56:31 +00001738
1739
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001740