~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/gdi32/metafile.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Metafile functions
  3  *
  4  * Copyright  David W. Metcalfe, 1994
  5  * Copyright  Niels de Carpentier, 1996
  6  * Copyright  Albrecht Kleine, 1996
  7  * Copyright  Huw Davies, 1996
  8  *
  9  * This library is free software; you can redistribute it and/or
 10  * modify it under the terms of the GNU Lesser General Public
 11  * License as published by the Free Software Foundation; either
 12  * version 2.1 of the License, or (at your option) any later version.
 13  *
 14  * This library is distributed in the hope that it will be useful,
 15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17  * Lesser General Public License for more details.
 18  *
 19  * You should have received a copy of the GNU Lesser General Public
 20  * License along with this library; if not, write to the Free Software
 21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 22  *
 23  * NOTES
 24  *
 25  * These functions are primarily involved with metafile playback or anything
 26  * that touches a HMETAFILE.
 27  * For recording of metafiles look in graphics/metafiledrv/
 28  *
 29  * Note that (32 bit) HMETAFILEs are GDI objects, while HMETAFILE16s are
 30  * global memory handles so these cannot be interchanged.
 31  *
 32  * Memory-based metafiles are just stored as a continuous block of memory with
 33  * a METAHEADER at the head with METARECORDs appended to it.  mtType is
 34  * METAFILE_MEMORY (1).  Note this is identical to the disk image of a
 35  * disk-based metafile - even mtType is METAFILE_MEMORY.
 36  * 16bit HMETAFILE16s are global handles to this block
 37  * 32bit HMETAFILEs are GDI handles METAFILEOBJs, which contains a ptr to
 38  * the memory.
 39  * Disk-based metafiles are rather different. HMETAFILE16s point to a
 40  * METAHEADER which has mtType equal to METAFILE_DISK (2).  Following the 9
 41  * WORDs of the METAHEADER there are a further 3 WORDs of 0, 1 of 0x117, 1
 42  * more 0, then 2 which may be a time stamp of the file and then the path of
 43  * the file (METAHEADERDISK). I've copied this for 16bit compatibility.
 44  *
 45  * HDMD - 14/4/1999
 46  */
 47 
 48 #include "config.h"
 49 
 50 #include <stdarg.h>
 51 #include <string.h>
 52 #include <fcntl.h>
 53 
 54 #include "windef.h"
 55 #include "winbase.h"
 56 #include "wingdi.h"
 57 #include "winreg.h"
 58 #include "winternl.h"
 59 #include "gdi_private.h"
 60 #include "wine/debug.h"
 61 
 62 WINE_DEFAULT_DEBUG_CHANNEL(metafile);
 63 
 64 #include "pshpack1.h"
 65 typedef struct
 66 {
 67     DWORD dw1, dw2, dw3;
 68     WORD w4;
 69     CHAR filename[0x100];
 70 } METAHEADERDISK;
 71 #include "poppack.h"
 72 
 73 typedef struct
 74 {
 75     GDIOBJHDR   header;
 76     METAHEADER  *mh;
 77 } METAFILEOBJ;
 78 
 79 
 80 /******************************************************************
 81  *         MF_AddHandle
 82  *
 83  *    Add a handle to an external handle table and return the index
 84  */
 85 static int MF_AddHandle(HANDLETABLE *ht, UINT htlen, HGDIOBJ hobj)
 86 {
 87     int i;
 88 
 89     for (i = 0; i < htlen; i++)
 90     {
 91         if (*(ht->objectHandle + i) == 0)
 92         {
 93             *(ht->objectHandle + i) = hobj;
 94             return i;
 95         }
 96     }
 97     return -1;
 98 }
 99 
100 
101 /******************************************************************
102  *         MF_Create_HMETATFILE
103  *
104  * Creates a (32 bit) HMETAFILE object from a METAHEADER
105  *
106  * HMETAFILEs are GDI objects.
107  */
108 HMETAFILE MF_Create_HMETAFILE(METAHEADER *mh)
109 {
110     HMETAFILE hmf;
111     METAFILEOBJ *metaObj;
112 
113     if (!(metaObj = HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj) ))) return 0;
114     metaObj->mh = mh;
115     if (!(hmf = alloc_gdi_handle( &metaObj->header, OBJ_METAFILE, NULL )))
116         HeapFree( GetProcessHeap(), 0, metaObj );
117     return hmf;
118 }
119 
120 /******************************************************************
121  *         MF_GetMetaHeader
122  *
123  * Returns ptr to METAHEADER associated with HMETAFILE
124  */
125 static METAHEADER *MF_GetMetaHeader( HMETAFILE hmf )
126 {
127     METAHEADER *ret = NULL;
128     METAFILEOBJ * metaObj = GDI_GetObjPtr( hmf, OBJ_METAFILE );
129     if (metaObj)
130     {
131         ret = metaObj->mh;
132         GDI_ReleaseObj( hmf );
133     }
134     return ret;
135 }
136 
137 /******************************************************************
138  *         convert_points
139  *
140  * Convert an array of POINT16 to an array of POINT.
141  * Result must be freed by caller.
142  */
143 static POINT *convert_points( UINT count, POINT16 *pt16 )
144 {
145     UINT i;
146     POINT *ret = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*ret) );
147     if (ret)
148     {
149         for (i = 0; i < count; i++)
150         {
151             ret[i].x = pt16[i].x;
152             ret[i].y = pt16[i].y;
153         }
154     }
155     return ret;
156 }
157 
158 /******************************************************************
159  *          DeleteMetaFile  (GDI32.@)
160  *
161  *  Delete a memory-based metafile.
162  */
163 
164 BOOL WINAPI DeleteMetaFile( HMETAFILE hmf )
165 {
166     METAFILEOBJ * metaObj = free_gdi_handle( hmf );
167     if (!metaObj) return FALSE;
168     HeapFree( GetProcessHeap(), 0, metaObj->mh );
169     return HeapFree( GetProcessHeap(), 0, metaObj );
170 }
171 
172 /******************************************************************
173  *         MF_ReadMetaFile
174  *
175  * Returns a pointer to a memory based METAHEADER read in from file HFILE
176  *
177  */
178 METAHEADER *MF_ReadMetaFile(HANDLE hfile)
179 {
180     METAHEADER *mh;
181     DWORD BytesRead, size;
182 
183     size = sizeof(METAHEADER);
184     mh = HeapAlloc( GetProcessHeap(), 0, size );
185     if(!mh) return NULL;
186     if(ReadFile( hfile, mh, size, &BytesRead, NULL) == 0 ||
187        BytesRead != size) {
188         HeapFree( GetProcessHeap(), 0, mh );
189         return NULL;
190     }
191     if (mh->mtType != METAFILE_MEMORY || mh->mtVersion != MFVERSION ||
192         mh->mtHeaderSize != size / 2)
193     {
194         HeapFree( GetProcessHeap(), 0, mh );
195         return NULL;
196     }
197     size = mh->mtSize * 2;
198     mh = HeapReAlloc( GetProcessHeap(), 0, mh, size );
199     if(!mh) return NULL;
200     size -= sizeof(METAHEADER);
201     if(ReadFile( hfile, (char *)mh + sizeof(METAHEADER), size, &BytesRead,
202                  NULL) == 0 ||
203        BytesRead != size) {
204         HeapFree( GetProcessHeap(), 0, mh );
205         return NULL;
206     }
207 
208     if (mh->mtType != METAFILE_MEMORY) {
209         WARN("Disk metafile had mtType = %04x\n", mh->mtType);
210         mh->mtType = METAFILE_MEMORY;
211     }
212     return mh;
213 }
214 
215 /******************************************************************
216  *         GetMetaFileA   (GDI32.@)
217  *
218  *  Read a metafile from a file. Returns handle to a memory-based metafile.
219  */
220 HMETAFILE WINAPI GetMetaFileA( LPCSTR lpFilename )
221 {
222     METAHEADER *mh;
223     HANDLE hFile;
224 
225     TRACE("%s\n", lpFilename);
226 
227     if(!lpFilename)
228         return 0;
229 
230     if((hFile = CreateFileA(lpFilename, GENERIC_READ, FILE_SHARE_READ, NULL,
231                             OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
232         return 0;
233 
234     mh = MF_ReadMetaFile(hFile);
235     CloseHandle(hFile);
236     if(!mh) return 0;
237     return MF_Create_HMETAFILE( mh );
238 }
239 
240 /******************************************************************
241  *         GetMetaFileW   (GDI32.@)
242  */
243 HMETAFILE WINAPI GetMetaFileW( LPCWSTR lpFilename )
244 {
245     METAHEADER *mh;
246     HANDLE hFile;
247 
248     TRACE("%s\n", debugstr_w(lpFilename));
249 
250     if(!lpFilename)
251         return 0;
252 
253     if((hFile = CreateFileW(lpFilename, GENERIC_READ, FILE_SHARE_READ, NULL,
254                             OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
255         return 0;
256 
257     mh = MF_ReadMetaFile(hFile);
258     CloseHandle(hFile);
259     if(!mh) return 0;
260     return MF_Create_HMETAFILE( mh );
261 }
262 
263 
264 /******************************************************************
265  *         MF_LoadDiskBasedMetaFile
266  *
267  * Creates a new memory-based metafile from a disk-based one.
268  */
269 METAHEADER *MF_LoadDiskBasedMetaFile(METAHEADER *mh)
270 {
271     METAHEADERDISK *mhd;
272     HANDLE hfile;
273     METAHEADER *mh2;
274 
275     if(mh->mtType != METAFILE_DISK) {
276         ERR("Not a disk based metafile\n");
277         return NULL;
278     }
279     mhd = (METAHEADERDISK *)((char *)mh + sizeof(METAHEADER));
280 
281     if((hfile = CreateFileA(mhd->filename, GENERIC_READ, FILE_SHARE_READ, NULL,
282                             OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) {
283         WARN("Can't open file of disk based metafile\n");
284         return NULL;
285     }
286     mh2 = MF_ReadMetaFile(hfile);
287     CloseHandle(hfile);
288     return mh2;
289 }
290 
291 /******************************************************************
292  *         MF_CreateMetaHeaderDisk
293  *
294  * Take a memory based METAHEADER and change it to a disk based METAHEADER
295  * associated with filename.  Note: Trashes contents of old one.
296  */
297 METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mh, LPCVOID filename, BOOL uni )
298 {
299     METAHEADERDISK *mhd;
300 
301     mh = HeapReAlloc( GetProcessHeap(), 0, mh,
302                       sizeof(METAHEADER) + sizeof(METAHEADERDISK));
303     mh->mtType = METAFILE_DISK;
304     mhd = (METAHEADERDISK *)((char *)mh + sizeof(METAHEADER));
305 
306     if( uni )
307         WideCharToMultiByte(CP_ACP, 0, filename, -1, 
308                    mhd->filename, sizeof mhd->filename, NULL, NULL);
309     else
310         lstrcpynA( mhd->filename, filename, sizeof mhd->filename );
311     return mh;
312 }
313 
314 /******************************************************************
315  *         CopyMetaFileW   (GDI32.@)
316  *
317  *  Copies the metafile corresponding to hSrcMetaFile to either
318  *  a disk file, if a filename is given, or to a new memory based
319  *  metafile, if lpFileName is NULL.
320  *
321  * PARAMS
322  *  hSrcMetaFile [I] handle of metafile to copy
323  *  lpFilename   [I] filename if copying to a file
324  *
325  * RETURNS
326  *  Handle to metafile copy on success, NULL on failure.
327  *
328  * BUGS
329  *  Copying to disk returns NULL even if successful.
330  */
331 HMETAFILE WINAPI CopyMetaFileW( HMETAFILE hSrcMetaFile, LPCWSTR lpFilename )
332 {
333     METAHEADER *mh = MF_GetMetaHeader( hSrcMetaFile );
334     METAHEADER *mh2 = NULL;
335     HANDLE hFile;
336 
337     TRACE("(%p,%s)\n", hSrcMetaFile, debugstr_w(lpFilename));
338 
339     if(!mh) return 0;
340 
341     if(mh->mtType == METAFILE_DISK)
342         mh2 = MF_LoadDiskBasedMetaFile(mh);
343     else {
344         mh2 = HeapAlloc( GetProcessHeap(), 0, mh->mtSize * 2 );
345         memcpy( mh2, mh, mh->mtSize * 2 );
346     }
347 
348     if(lpFilename) {         /* disk based metafile */
349         DWORD w;
350         if((hFile = CreateFileW(lpFilename, GENERIC_WRITE, 0, NULL,
351                                 CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) {
352             HeapFree( GetProcessHeap(), 0, mh2 );
353             return 0;
354         }
355         WriteFile(hFile, mh2, mh2->mtSize * 2, &w, NULL);
356         CloseHandle(hFile);
357     }
358 
359     return MF_Create_HMETAFILE( mh2 );
360 }
361 
362 
363 /******************************************************************
364  *         CopyMetaFileA   (GDI32.@)
365  *
366  * See CopyMetaFileW.
367  */
368 HMETAFILE WINAPI CopyMetaFileA( HMETAFILE hSrcMetaFile, LPCSTR lpFilename )
369 {
370     UNICODE_STRING lpFilenameW;
371     HMETAFILE ret = 0;
372 
373     if (lpFilename) RtlCreateUnicodeStringFromAsciiz(&lpFilenameW, lpFilename);
374     else lpFilenameW.Buffer = NULL;
375 
376     ret = CopyMetaFileW( hSrcMetaFile, lpFilenameW.Buffer );
377     if (lpFilenameW.Buffer)
378         RtlFreeUnicodeString(&lpFilenameW);
379     return ret;
380 }
381 
382 /*******************************************************************
383  *         MF_PlayMetaFile
384  *
385  * Helper for PlayMetaFile
386  */
387 BOOL MF_PlayMetaFile( HDC hdc, METAHEADER *mh)
388 {
389 
390     METARECORD *mr;
391     HANDLETABLE *ht;
392     unsigned int offset = 0;
393     WORD i;
394     HPEN hPen;
395     HBRUSH hBrush;
396     HFONT hFont;
397     HPALETTE hPal;
398     HRGN hRgn;
399     BOOL loaded = FALSE;
400 
401     if (!mh) return FALSE;
402     if(mh->mtType == METAFILE_DISK) { /* Create a memory-based copy */
403         mh = MF_LoadDiskBasedMetaFile(mh);
404         if(!mh) return FALSE;
405         loaded = TRUE;
406     }
407 
408     /* save DC */
409     hPen = GetCurrentObject(hdc, OBJ_PEN);
410     hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
411     hFont = GetCurrentObject(hdc, OBJ_FONT);
412     hPal = GetCurrentObject(hdc, OBJ_PAL);
413 
414     hRgn = CreateRectRgn(0, 0, 0, 0);
415     if (!GetClipRgn(hdc, hRgn))
416     {
417         DeleteObject(hRgn);
418         hRgn = 0;
419     }
420 
421     /* create the handle table */
422     ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
423                     sizeof(HANDLETABLE) * mh->mtNoObjects);
424     if(!ht) return FALSE;
425 
426     /* loop through metafile playing records */
427     offset = mh->mtHeaderSize * 2;
428     while (offset < mh->mtSize * 2)
429     {
430         mr = (METARECORD *)((char *)mh + offset);
431         TRACE("offset=%04x,size=%08x\n",
432             offset, mr->rdSize);
433         if (mr->rdSize < 3) { /* catch illegal record sizes */
434             TRACE("Entry got size %d at offset %d, total mf length is %d\n",
435                   mr->rdSize,offset,mh->mtSize*2);
436             break;
437         }
438 
439         offset += mr->rdSize * 2;
440         if (mr->rdFunction == META_EOF) {
441             TRACE("Got META_EOF so stopping\n");
442             break;
443         }
444         PlayMetaFileRecord( hdc, ht, mr, mh->mtNoObjects );
445     }
446 
447     /* restore DC */
448     SelectObject(hdc, hPen);
449     SelectObject(hdc, hBrush);
450     SelectPalette(hdc, hPal, FALSE);
451     ExtSelectClipRgn(hdc, hRgn, RGN_COPY);
452     DeleteObject(hRgn);
453 
454     /* free objects in handle table */
455     for(i = 0; i < mh->mtNoObjects; i++)
456       if(*(ht->objectHandle + i) != 0)
457         DeleteObject(*(ht->objectHandle + i));
458 
459     /* free handle table */
460     HeapFree( GetProcessHeap(), 0, ht );
461     if(loaded)
462         HeapFree( GetProcessHeap(), 0, mh );
463     return TRUE;
464 }
465 
466 /******************************************************************
467  *         PlayMetaFile   (GDI32.@)
468  *
469  *  Renders the metafile specified by hmf in the DC specified by
470  *  hdc. Returns FALSE on failure, TRUE on success.
471  *
472  * PARAMS
473  *  hdc [I] handle of DC to render in
474  *  hmf [I] handle of metafile to render
475  *
476  * RETURNS
477  *  Success: TRUE
478  *  Failure: FALSE
479  */
480 BOOL WINAPI PlayMetaFile( HDC hdc, HMETAFILE hmf )
481 {
482     METAHEADER *mh = MF_GetMetaHeader( hmf );
483     return MF_PlayMetaFile( hdc, mh );
484 }
485 
486 /******************************************************************
487  *            EnumMetaFile   (GDI32.@)
488  *
489  *  Loop through the metafile records in hmf, calling the user-specified
490  *  function for each one, stopping when the user's function returns FALSE
491  *  (which is considered to be failure)
492  *  or when no records are left (which is considered to be success).
493  *
494  * RETURNS
495  *  TRUE on success, FALSE on failure.
496  */
497 BOOL WINAPI EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC lpEnumFunc, LPARAM lpData)
498 {
499     METAHEADER *mhTemp = NULL, *mh = MF_GetMetaHeader(hmf);
500     METARECORD *mr;
501     HANDLETABLE *ht;
502     BOOL result = TRUE;
503     int i;
504     unsigned int offset = 0;
505     HPEN hPen;
506     HBRUSH hBrush;
507     HFONT hFont;
508 
509     TRACE("(%p,%p,%p,%p)\n", hdc, hmf, lpEnumFunc, (void*)lpData);
510     if (!mh) return 0;
511     if(mh->mtType == METAFILE_DISK)
512     {
513         /* Create a memory-based copy */
514         if (!(mhTemp = MF_LoadDiskBasedMetaFile(mh))) return FALSE;
515         mh = mhTemp;
516     }
517 
518     /* save the current pen, brush and font */
519     hPen = GetCurrentObject(hdc, OBJ_PEN);
520     hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
521     hFont = GetCurrentObject(hdc, OBJ_FONT);
522 
523     ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
524                             sizeof(HANDLETABLE) * mh->mtNoObjects);
525 
526     /* loop through metafile records */
527     offset = mh->mtHeaderSize * 2;
528 
529     while (offset < (mh->mtSize * 2))
530     {
531         mr = (METARECORD *)((char *)mh + offset);
532         if(mr->rdFunction == META_EOF) {
533             TRACE("Got META_EOF so stopping\n");
534             break;
535         }
536         TRACE("Calling EnumFunc with record type %x\n",
537               mr->rdFunction);
538         if (!lpEnumFunc( hdc, ht, mr, mh->mtNoObjects, (LONG)lpData ))
539         {
540             result = FALSE;
541             break;
542         }
543 
544         offset += (mr->rdSize * 2);
545     }
546 
547     /* restore pen, brush and font */
548     SelectObject(hdc, hBrush);
549     SelectObject(hdc, hPen);
550     SelectObject(hdc, hFont);
551 
552     /* free objects in handle table */
553     for(i = 0; i < mh->mtNoObjects; i++)
554       if(*(ht->objectHandle + i) != 0)
555         DeleteObject(*(ht->objectHandle + i));
556 
557     /* free handle table */
558     HeapFree( GetProcessHeap(), 0, ht);
559     /* free a copy of metafile */
560     HeapFree( GetProcessHeap(), 0, mhTemp );
561     return result;
562 }
563 
564 static BOOL MF_Play_MetaCreateRegion( METARECORD *mr, HRGN hrgn );
565 static BOOL MF_Play_MetaExtTextOut(HDC hdc, METARECORD *mr);
566 /******************************************************************
567  *         PlayMetaFileRecord   (GDI32.@)
568  *
569  *   Render a single metafile record specified by *mr in the DC hdc, while
570  *   using the handle table *ht, of length handles,
571  *   to store metafile objects.
572  *
573  * BUGS
574  *  The following metafile records are unimplemented:
575  *
576  *  DRAWTEXT, ANIMATEPALETTE, SETPALENTRIES,
577  *  RESIZEPALETTE, EXTFLOODFILL, RESETDC, STARTDOC, STARTPAGE, ENDPAGE,
578  *  ABORTDOC, ENDDOC, CREATEBRUSH, CREATEBITMAPINDIRECT, and CREATEBITMAP.
579  */
580 BOOL WINAPI PlayMetaFileRecord( HDC hdc,  HANDLETABLE *ht, METARECORD *mr, UINT handles )
581 {
582     short s1;
583     POINT *pt;
584     BITMAPINFOHEADER *infohdr;
585 
586     TRACE("(%p %p %p %u) function %04x\n", hdc, ht, mr, handles, mr->rdFunction);
587 
588     switch (mr->rdFunction)
589     {
590     case META_EOF:
591         break;
592 
593     case META_DELETEOBJECT:
594         DeleteObject(*(ht->objectHandle + mr->rdParm[0]));
595         *(ht->objectHandle + mr->rdParm[0]) = 0;
596         break;
597 
598     case META_SETBKCOLOR:
599         SetBkColor(hdc, MAKELONG(mr->rdParm[0], mr->rdParm[1]));
600         break;
601 
602     case META_SETBKMODE:
603         SetBkMode(hdc, mr->rdParm[0]);
604         break;
605 
606     case META_SETMAPMODE:
607         SetMapMode(hdc, mr->rdParm[0]);
608         break;
609 
610     case META_SETROP2:
611         SetROP2(hdc, mr->rdParm[0]);
612         break;
613 
614     case META_SETRELABS:
615         SetRelAbs(hdc, mr->rdParm[0]);
616         break;
617 
618     case META_SETPOLYFILLMODE:
619         SetPolyFillMode(hdc, mr->rdParm[0]);
620         break;
621 
622     case META_SETSTRETCHBLTMODE:
623         SetStretchBltMode(hdc, mr->rdParm[0]);
624         break;
625 
626     case META_SETTEXTCOLOR:
627         SetTextColor(hdc, MAKELONG(mr->rdParm[0], mr->rdParm[1]));
628         break;
629 
630     case META_SETWINDOWORG:
631         SetWindowOrgEx(hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0], NULL);
632         break;
633 
634     case META_SETWINDOWEXT:
635         SetWindowExtEx(hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0], NULL);
636         break;
637 
638     case META_SETVIEWPORTORG:
639         SetViewportOrgEx(hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0], NULL);
640         break;
641 
642     case META_SETVIEWPORTEXT:
643         SetViewportExtEx(hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0], NULL);
644         break;
645 
646     case META_OFFSETWINDOWORG:
647         OffsetWindowOrgEx(hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0], NULL);
648         break;
649 
650     case META_SCALEWINDOWEXT:
651         ScaleWindowExtEx(hdc, (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
652                               (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0], NULL);
653         break;
654 
655     case META_OFFSETVIEWPORTORG:
656         OffsetViewportOrgEx(hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0], NULL);
657         break;
658 
659     case META_SCALEVIEWPORTEXT:
660         ScaleViewportExtEx(hdc, (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
661                                 (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0], NULL);
662         break;
663 
664     case META_LINETO:
665         LineTo(hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0]);
666         break;
667 
668     case META_MOVETO:
669         MoveToEx(hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0], NULL);
670         break;
671 
672     case META_EXCLUDECLIPRECT:
673         ExcludeClipRect( hdc, (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
674                               (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0] );
675         break;
676 
677     case META_INTERSECTCLIPRECT:
678         IntersectClipRect( hdc, (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
679                                 (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0] );
680         break;
681 
682     case META_ARC:
683         Arc(hdc, (SHORT)mr->rdParm[7], (SHORT)mr->rdParm[6],
684                  (SHORT)mr->rdParm[5], (SHORT)mr->rdParm[4],
685                  (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
686                  (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0]);
687         break;
688 
689     case META_ELLIPSE:
690         Ellipse(hdc, (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
691                      (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0]);
692         break;
693 
694     case META_FLOODFILL:
695         FloodFill(hdc, (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
696                     MAKELONG(mr->rdParm[0], mr->rdParm[1]));
697         break;
698 
699     case META_PIE:
700         Pie(hdc, (SHORT)mr->rdParm[7], (SHORT)mr->rdParm[6],
701                  (SHORT)mr->rdParm[5], (SHORT)mr->rdParm[4],
702                  (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
703                  (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0]);
704         break;
705 
706     case META_RECTANGLE:
707         Rectangle(hdc, (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
708                        (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0]);
709         break;
710 
711     case META_ROUNDRECT:
712         RoundRect(hdc, (SHORT)mr->rdParm[5], (SHORT)mr->rdParm[4],
713                        (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
714                        (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0]);
715         break;
716 
717     case META_PATBLT:
718         PatBlt(hdc, (SHORT)mr->rdParm[5], (SHORT)mr->rdParm[4],
719                     (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
720                     MAKELONG(mr->rdParm[0], mr->rdParm[1]));
721         break;
722 
723     case META_SAVEDC:
724         SaveDC(hdc);
725         break;
726 
727     case META_SETPIXEL:
728         SetPixel(hdc, (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
729                  MAKELONG(mr->rdParm[0], mr->rdParm[1]));
730         break;
731 
732     case META_OFFSETCLIPRGN:
733         OffsetClipRgn( hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0] );
734         break;
735 
736     case META_TEXTOUT:
737         s1 = mr->rdParm[0];
738         TextOutA(hdc, (SHORT)mr->rdParm[((s1 + 1) >> 1) + 2],
739                  (SHORT)mr->rdParm[((s1 + 1) >> 1) + 1],
740                  (char *)(mr->rdParm + 1), s1);
741         break;
742 
743     case META_POLYGON:
744         if ((pt = convert_points( mr->rdParm[0], (LPPOINT16)(mr->rdParm + 1))))
745         {
746             Polygon(hdc, pt, mr->rdParm[0]);
747             HeapFree( GetProcessHeap(), 0, pt );
748         }
749         break;
750 
751     case META_POLYPOLYGON:
752         {
753             UINT i, total;
754             SHORT *counts = (SHORT *)(mr->rdParm + 1);
755 
756             for (i = total = 0; i < mr->rdParm[0]; i++) total += counts[i];
757             pt = convert_points( total, (LPPOINT16)(counts + mr->rdParm[0]) );
758             if (pt)
759             {
760                 INT *cnt32 = HeapAlloc( GetProcessHeap(), 0, mr->rdParm[0] * sizeof(*cnt32) );
761                 if (cnt32)
762                 {
763                     for (i = 0; i < mr->rdParm[0]; i++) cnt32[i] = counts[i];
764                     PolyPolygon( hdc, pt, cnt32, mr->rdParm[0]);
765                     HeapFree( GetProcessHeap(), 0, cnt32 );
766                 }
767             }
768             HeapFree( GetProcessHeap(), 0, pt );
769         }
770         break;
771 
772     case META_POLYLINE:
773         if ((pt = convert_points( mr->rdParm[0], (LPPOINT16)(mr->rdParm + 1))))
774         {
775             Polyline( hdc, pt, mr->rdParm[0] );
776             HeapFree( GetProcessHeap(), 0, pt );
777         }
778         break;
779 
780     case META_RESTOREDC:
781         RestoreDC(hdc, (SHORT)mr->rdParm[0]);
782         break;
783 
784     case META_SELECTOBJECT:
785         SelectObject(hdc, *(ht->objectHandle + mr->rdParm[0]));
786         break;
787 
788     case META_CHORD:
789         Chord(hdc, (SHORT)mr->rdParm[7], (SHORT)mr->rdParm[6],
790                    (SHORT)mr->rdParm[5], (SHORT)mr->rdParm[4],
791                    (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
792                    (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0]);
793         break;
794 
795     case META_CREATEPATTERNBRUSH:
796         switch (mr->rdParm[0])
797         {
798         case BS_PATTERN:
799             infohdr = (BITMAPINFOHEADER *)(mr->rdParm + 2);
800             MF_AddHandle(ht, handles,
801                          CreatePatternBrush(CreateBitmap(infohdr->biWidth,
802                                       infohdr->biHeight,
803                                       infohdr->biPlanes,
804                                       infohdr->biBitCount,
805                                       mr->rdParm +
806                                       (sizeof(BITMAPINFOHEADER) / 2) + 4)));
807             break;
808 
809         case BS_DIBPATTERN:
810             infohdr = (BITMAPINFOHEADER *)(mr->rdParm + 2);
811             MF_AddHandle(ht, handles, CreateDIBPatternBrushPt( infohdr, mr->rdParm[1] ));
812             break;
813 
814         default:
815             ERR("META_CREATEPATTERNBRUSH: Unknown pattern type %d\n",
816                 mr->rdParm[0]);
817             break;
818         }
819         break;
820 
821     case META_CREATEPENINDIRECT:
822         {
823             LOGPEN pen;
824             pen.lopnStyle = mr->rdParm[0];
825             pen.lopnWidth.x = (SHORT)mr->rdParm[1];
826             pen.lopnWidth.y = (SHORT)mr->rdParm[2];
827             pen.lopnColor = MAKELONG( mr->rdParm[3], mr->rdParm[4] );
828             MF_AddHandle(ht, handles, CreatePenIndirect( &pen ));
829         }
830         break;
831 
832     case META_CREATEFONTINDIRECT:
833         {
834             LOGFONTA font;
835             font.lfHeight         = (SHORT)mr->rdParm[0];
836             font.lfWidth          = (SHORT)mr->rdParm[1];
837             font.lfEscapement     = (SHORT)mr->rdParm[2];
838             font.lfOrientation    = (SHORT)mr->rdParm[3];
839             font.lfWeight         = (SHORT)mr->rdParm[4];
840             font.lfItalic         = LOBYTE(mr->rdParm[5]);
841             font.lfUnderline      = HIBYTE(mr->rdParm[5]);
842             font.lfStrikeOut      = LOBYTE(mr->rdParm[6]);
843             font.lfCharSet        = HIBYTE(mr->rdParm[6]);
844             font.lfOutPrecision   = LOBYTE(mr->rdParm[7]);
845             font.lfClipPrecision  = HIBYTE(mr->rdParm[7]);
846             font.lfQuality        = LOBYTE(mr->rdParm[8]);
847             font.lfPitchAndFamily = HIBYTE(mr->rdParm[8]);
848             memcpy( font.lfFaceName, mr->rdParm + 9, LF_FACESIZE );
849             MF_AddHandle(ht, handles, CreateFontIndirectA( &font ));
850         }
851         break;
852 
853     case META_CREATEBRUSHINDIRECT:
854         {
855             LOGBRUSH brush;
856             brush.lbStyle = mr->rdParm[0];
857             brush.lbColor = MAKELONG( mr->rdParm[1], mr->rdParm[2] );
858             brush.lbHatch = mr->rdParm[3];
859             MF_AddHandle(ht, handles, CreateBrushIndirect( &brush ));
860         }
861         break;
862 
863     case META_CREATEPALETTE:
864         MF_AddHandle(ht, handles, CreatePalette((LPLOGPALETTE)mr->rdParm));
865         break;
866 
867     case META_SETTEXTALIGN:
868         SetTextAlign(hdc, mr->rdParm[0]);
869         break;
870 
871     case META_SELECTPALETTE:
872         GDISelectPalette(hdc, *(ht->objectHandle + mr->rdParm[1]), mr->rdParm[0]);
873         break;
874 
875     case META_SETMAPPERFLAGS:
876         SetMapperFlags(hdc, MAKELONG(mr->rdParm[0],mr->rdParm[1]));
877         break;
878 
879     case META_REALIZEPALETTE:
880         GDIRealizePalette(hdc);
881         break;
882 
883     case META_ESCAPE:
884         switch (mr->rdParm[0]) {
885         case GETSCALINGFACTOR: /* get function ... would just NULL dereference */
886         case GETPHYSPAGESIZE:
887         case GETPRINTINGOFFSET:
888              return FALSE;
889         case SETABORTPROC:
890              FIXME("Filtering Escape(SETABORTPROC), possible virus?\n");
891              return FALSE;
892         }
893         Escape(hdc, mr->rdParm[0], mr->rdParm[1], (LPCSTR)&mr->rdParm[2], NULL);
894         break;
895 
896     case META_EXTTEXTOUT:
897         MF_Play_MetaExtTextOut( hdc, mr );
898         break;
899 
900     case META_STRETCHDIB:
901       {
902         LPBITMAPINFO info = (LPBITMAPINFO) &(mr->rdParm[11]);
903         LPSTR bits = (LPSTR)info + bitmap_info_size( info, mr->rdParm[2] );
904         StretchDIBits( hdc, (SHORT)mr->rdParm[10], (SHORT)mr->rdParm[9], (SHORT)mr->rdParm[8],
905                        (SHORT)mr->rdParm[7], (SHORT)mr->rdParm[6], (SHORT)mr->rdParm[5],
906                        (SHORT)mr->rdParm[4], (SHORT)mr->rdParm[3], bits, info,
907                        mr->rdParm[2],MAKELONG(mr->rdParm[0],mr->rdParm[1]));
908       }
909       break;
910 
911     case META_DIBSTRETCHBLT:
912       {
913         LPBITMAPINFO info = (LPBITMAPINFO) &(mr->rdParm[10]);
914         LPSTR bits = (LPSTR)info + bitmap_info_size( info, DIB_RGB_COLORS );
915         StretchDIBits( hdc, (SHORT)mr->rdParm[9], (SHORT)mr->rdParm[8], (SHORT)mr->rdParm[7],
916                        (SHORT)mr->rdParm[6], (SHORT)mr->rdParm[5], (SHORT)mr->rdParm[4],
917                        (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2], bits, info,
918                        DIB_RGB_COLORS,MAKELONG(mr->rdParm[0],mr->rdParm[1]));
919       }
920       break;
921 
922     case META_STRETCHBLT:
923       {
924         HDC hdcSrc = CreateCompatibleDC(hdc);
925         HBITMAP hbitmap = CreateBitmap(mr->rdParm[10], /*Width */
926                                        mr->rdParm[11], /*Height*/
927                                        mr->rdParm[13], /*Planes*/
928                                        mr->rdParm[14], /*BitsPixel*/
929                                        &mr->rdParm[15]); /*bits*/
930         SelectObject(hdcSrc,hbitmap);
931         StretchBlt(hdc, (SHORT)mr->rdParm[9], (SHORT)mr->rdParm[8],
932                    (SHORT)mr->rdParm[7], (SHORT)mr->rdParm[6],
933                    hdcSrc, (SHORT)mr->rdParm[5], (SHORT)mr->rdParm[4],
934                    (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
935                    MAKELONG(mr->rdParm[0],mr->rdParm[1]));
936         DeleteDC(hdcSrc);
937       }
938       break;
939 
940     case META_BITBLT:
941       {
942         HDC hdcSrc = CreateCompatibleDC(hdc);
943         HBITMAP hbitmap = CreateBitmap(mr->rdParm[7]/*Width */,
944                                         mr->rdParm[8]/*Height*/,
945                                         mr->rdParm[10]/*Planes*/,
946                                         mr->rdParm[11]/*BitsPixel*/,
947                                         &mr->rdParm[12]/*bits*/);
948         SelectObject(hdcSrc,hbitmap);
949         BitBlt(hdc,(SHORT)mr->rdParm[6],(SHORT)mr->rdParm[5],
950                 (SHORT)mr->rdParm[4],(SHORT)mr->rdParm[3],
951                 hdcSrc, (SHORT)mr->rdParm[2],(SHORT)mr->rdParm[1],
952                 MAKELONG(0,mr->rdParm[0]));
953         DeleteDC(hdcSrc);
954       }
955       break;
956 
957     case META_CREATEREGION:
958       {
959         HRGN hrgn = CreateRectRgn(0,0,0,0);
960 
961         MF_Play_MetaCreateRegion(mr, hrgn);
962         MF_AddHandle(ht, handles, hrgn);
963       }
964       break;
965 
966     case META_FILLREGION:
967         FillRgn(hdc, *(ht->objectHandle + mr->rdParm[1]),
968                 *(ht->objectHandle + mr->rdParm[0]));
969         break;
970 
971     case META_FRAMEREGION:
972         FrameRgn(hdc, *(ht->objectHandle + mr->rdParm[3]),
973                  *(ht->objectHandle + mr->rdParm[2]),
974                  (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0]);
975         break;
976 
977     case META_INVERTREGION:
978         InvertRgn(hdc, *(ht->objectHandle + mr->rdParm[0]));
979         break;
980 
981     case META_PAINTREGION:
982         PaintRgn(hdc, *(ht->objectHandle + mr->rdParm[0]));
983         break;
984 
985     case META_SELECTCLIPREGION:
986         {
987             HRGN hrgn = 0;
988 
989             if (mr->rdParm[0]) hrgn = *(ht->objectHandle + mr->rdParm[0]);
990             SelectClipRgn(hdc, hrgn);
991         }
992         break;
993 
994     case META_DIBCREATEPATTERNBRUSH:
995         /*  mr->rdParm[0] may be BS_PATTERN or BS_DIBPATTERN:
996             but there's no difference */
997         MF_AddHandle(ht, handles, CreateDIBPatternBrushPt( mr->rdParm + 2, mr->rdParm[1] ));
998         break;
999 
1000     case META_DIBBITBLT:
1001       /* In practice I've found that there are two layouts for
1002          META_DIBBITBLT, one (the first here) is the usual one when a src
1003          dc is actually passed to it, the second occurs when the src dc is
1004          passed in as NULL to the creating BitBlt. As the second case has
1005          no dib, a size check will suffice to distinguish.
1006 
1007          Caolan.McNamara@ul.ie */
1008 
1009         if (mr->rdSize > 12) {
1010             LPBITMAPINFO info = (LPBITMAPINFO) &(mr->rdParm[8]);
1011             LPSTR bits = (LPSTR)info + bitmap_info_size(info, mr->rdParm[0]);
1012 
1013             StretchDIBits(hdc, (SHORT)mr->rdParm[7], (SHORT)mr->rdParm[6], (SHORT)mr->rdParm[5],
1014                           (SHORT)mr->rdParm[4], (SHORT)mr->rdParm[3], (SHORT)mr->rdParm[2],
1015                           (SHORT)mr->rdParm[5], (SHORT)mr->rdParm[4], bits, info,
1016                           DIB_RGB_COLORS, MAKELONG(mr->rdParm[0], mr->rdParm[1]));
1017         }
1018         else /* equivalent to a PatBlt */
1019             PatBlt(hdc, (SHORT)mr->rdParm[8], (SHORT)mr->rdParm[7],
1020                    (SHORT)mr->rdParm[6], (SHORT)mr->rdParm[5],
1021                    MAKELONG(mr->rdParm[0], mr->rdParm[1]));
1022         break;
1023 
1024     case META_SETTEXTCHAREXTRA:
1025         SetTextCharacterExtra(hdc, (SHORT)mr->rdParm[0]);
1026         break;
1027 
1028     case META_SETTEXTJUSTIFICATION:
1029         SetTextJustification(hdc, (SHORT)mr->rdParm[1], (SHORT)mr->rdParm[0]);
1030         break;
1031 
1032     case META_EXTFLOODFILL:
1033         ExtFloodFill(hdc, (SHORT)mr->rdParm[4], (SHORT)mr->rdParm[3],
1034                      MAKELONG(mr->rdParm[1], mr->rdParm[2]),
1035                      mr->rdParm[0]);
1036         break;
1037 
1038     case META_SETDIBTODEV:
1039         {
1040             BITMAPINFO *info = (BITMAPINFO *) &(mr->rdParm[9]);
1041             char *bits = (char *)info + bitmap_info_size( info, mr->rdParm[0] );
1042             SetDIBitsToDevice(hdc, (SHORT)mr->rdParm[8], (SHORT)mr->rdParm[7],
1043                               (SHORT)mr->rdParm[6], (SHORT)mr->rdParm[5],
1044                               (SHORT)mr->rdParm[4], (SHORT)mr->rdParm[3],
1045                               mr->rdParm[2], mr->rdParm[1], bits, info,
1046                               mr->rdParm[0]);
1047             break;
1048         }
1049 
1050 #define META_UNIMP(x) case x: \
1051 FIXME("PlayMetaFileRecord:record type "#x" not implemented.\n"); \
1052 break;
1053     META_UNIMP(META_DRAWTEXT)
1054     META_UNIMP(META_ANIMATEPALETTE)
1055     META_UNIMP(META_SETPALENTRIES)
1056     META_UNIMP(META_RESIZEPALETTE)
1057     META_UNIMP(META_RESETDC)
1058     META_UNIMP(META_STARTDOC)
1059     META_UNIMP(META_STARTPAGE)
1060     META_UNIMP(META_ENDPAGE)
1061     META_UNIMP(META_ABORTDOC)
1062     META_UNIMP(META_ENDDOC)
1063     META_UNIMP(META_CREATEBRUSH)
1064     META_UNIMP(META_CREATEBITMAPINDIRECT)
1065     META_UNIMP(META_CREATEBITMAP)
1066 #undef META_UNIMP
1067 
1068     default:
1069         WARN("PlayMetaFileRecord: Unknown record type %x\n", mr->rdFunction);
1070         return FALSE;
1071     }
1072     return TRUE;
1073 }
1074 
1075 /******************************************************************
1076  *         SetMetaFileBitsEx    (GDI32.@)
1077  *
1078  *  Create a metafile from raw data. No checking of the data is performed.
1079  *  Use GetMetaFileBitsEx() to get raw data from a metafile.
1080  *
1081  * PARAMS
1082  *  size   [I] size of metafile, in bytes
1083  *  lpData [I] pointer to metafile data
1084  *
1085  * RETURNS
1086  *  Success: Handle to metafile.
1087  *  Failure: NULL.
1088  */
1089 HMETAFILE WINAPI SetMetaFileBitsEx( UINT size, const BYTE *lpData )
1090 {
1091     const METAHEADER *mh_in = (const METAHEADER *)lpData;
1092     METAHEADER *mh_out;
1093 
1094     if (size & 1) return 0;
1095 
1096     if (!size || mh_in->mtType != METAFILE_MEMORY || mh_in->mtVersion != MFVERSION ||
1097         mh_in->mtHeaderSize != sizeof(METAHEADER) / 2)
1098     {
1099         SetLastError(ERROR_INVALID_DATA);
1100         return 0;
1101     }
1102 
1103     mh_out = HeapAlloc( GetProcessHeap(), 0, size );
1104     if (!mh_out)
1105     {
1106         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1107         return 0;
1108     }
1109 
1110     memcpy(mh_out, mh_in, size);
1111     mh_out->mtSize = size / 2;
1112     return MF_Create_HMETAFILE(mh_out);
1113 }
1114 
1115 /*****************************************************************
1116  *  GetMetaFileBitsEx     (GDI32.@)
1117  *
1118  * Get raw metafile data.
1119  *
1120  *  Copies the data from metafile _hmf_ into the buffer _buf_.
1121  *
1122  * PARAMS
1123  *  hmf   [I] metafile
1124  *  nSize [I] size of buf
1125  *  buf   [O] buffer to receive raw metafile data
1126  *
1127  * RETURNS
1128  *  If _buf_ is zero, returns size of buffer required. Otherwise,
1129  *  returns number of bytes copied.
1130  */
1131 UINT WINAPI GetMetaFileBitsEx( HMETAFILE hmf, UINT nSize, LPVOID buf )
1132 {
1133     METAHEADER *mh = MF_GetMetaHeader(hmf);
1134     UINT mfSize;
1135 
1136     TRACE("(%p,%d,%p)\n", hmf, nSize, buf);
1137     if (!mh) return 0;  /* FIXME: error code */
1138     if(mh->mtType == METAFILE_DISK)
1139         FIXME("Disk-based metafile?\n");
1140     mfSize = mh->mtSize * 2;
1141     if (!buf) {
1142         TRACE("returning size %d\n", mfSize);
1143         return mfSize;
1144     }
1145     if(mfSize > nSize) mfSize = nSize;
1146     memmove(buf, mh, mfSize);
1147     return mfSize;
1148 }
1149 
1150 /******************************************************************
1151  *         GetWinMetaFileBits [GDI32.@]
1152  */
1153 UINT WINAPI GetWinMetaFileBits(HENHMETAFILE hemf,
1154                                 UINT cbBuffer, LPBYTE lpbBuffer,
1155                                 INT fnMapMode, HDC hdcRef)
1156 {
1157     HDC hdcmf;
1158     HMETAFILE hmf;
1159     UINT ret;
1160     RECT rc;
1161     INT oldMapMode;
1162 
1163     GetClipBox(hdcRef, &rc);
1164     oldMapMode = SetMapMode(hdcRef, fnMapMode);
1165 
1166     TRACE("(%p,%d,%p,%d,%p) rc=%s\n", hemf, cbBuffer, lpbBuffer,
1167         fnMapMode, hdcRef, wine_dbgstr_rect(&rc));
1168 
1169     hdcmf = CreateMetaFileA(NULL);
1170     PlayEnhMetaFile(hdcmf, hemf, &rc);
1171     hmf = CloseMetaFile(hdcmf);
1172     ret = GetMetaFileBitsEx(hmf, cbBuffer, lpbBuffer);
1173     DeleteMetaFile(hmf);
1174 
1175     SetMapMode(hdcRef, oldMapMode);
1176 
1177     return ret;
1178 }
1179 
1180 /******************************************************************
1181  *         MF_Play_MetaCreateRegion
1182  *
1183  *  Handles META_CREATEREGION for PlayMetaFileRecord().
1184  *
1185  *      The layout of the record looks something like this:
1186  *
1187  *       rdParm meaning
1188  *       0              Always 0?
1189  *       1              Always 6?
1190  *       2              Looks like a handle? - not constant
1191  *       3              0 or 1 ??
1192  *       4              Total number of bytes
1193  *       5              No. of separate bands = n [see below]
1194  *       6              Largest number of x co-ords in a band
1195  *       7-10           Bounding box x1 y1 x2 y2
1196  *       11-...         n bands
1197  *
1198  *       Regions are divided into bands that are uniform in the
1199  *       y-direction. Each band consists of pairs of on/off x-coords and is
1200  *       written as
1201  *              m y0 y1 x1 x2 x3 ... xm m
1202  *       into successive rdParm[]s.
1203  *
1204  *       This is probably just a dump of the internal RGNOBJ?
1205  *
1206  *       HDMD - 18/12/97
1207  *
1208  */
1209 
1210 static BOOL MF_Play_MetaCreateRegion( METARECORD *mr, HRGN hrgn )
1211 {
1212     WORD band, pair;
1213     WORD *start, *end;
1214     INT16 y0, y1;
1215     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
1216 
1217     for(band  = 0, start = &(mr->rdParm[11]); band < mr->rdParm[5];
1218                                                 band++, start = end + 1) {
1219         if(*start / 2 != (*start + 1) / 2) {
1220             WARN("Delimiter not even.\n");
1221             DeleteObject( hrgn2 );
1222             return FALSE;
1223         }
1224 
1225         end = start + *start + 3;
1226         if(end > (WORD *)mr + mr->rdSize) {
1227             WARN("End points outside record.\n");
1228             DeleteObject( hrgn2 );
1229             return FALSE;
1230         }
1231 
1232         if(*start != *end) {
1233             WARN("Mismatched delimiters.\n");
1234             DeleteObject( hrgn2 );
1235             return FALSE;
1236         }
1237 
1238         y0 = *(INT16 *)(start + 1);
1239         y1 = *(INT16 *)(start + 2);
1240         for(pair = 0; pair < *start / 2; pair++) {
1241             SetRectRgn( hrgn2, *(INT16 *)(start + 3 + 2*pair), y0,
1242                                  *(INT16 *)(start + 4 + 2*pair), y1 );
1243             CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
1244         }
1245     }
1246     DeleteObject( hrgn2 );
1247     return TRUE;
1248  }
1249 
1250 
1251 /******************************************************************
1252  *         MF_Play_MetaExtTextOut
1253  *
1254  *  Handles META_EXTTEXTOUT for PlayMetaFileRecord().
1255  */
1256 
1257 static BOOL MF_Play_MetaExtTextOut(HDC hdc, METARECORD *mr)
1258 {
1259     INT *dx = NULL;
1260     int i;
1261     LPINT16 dxx;
1262     LPSTR sot;
1263     DWORD len;
1264     WORD s1;
1265     RECT rect;
1266     BOOL isrect = mr->rdParm[3] & (ETO_OPAQUE | ETO_CLIPPED);
1267 
1268     s1 = mr->rdParm[2];                              /* String length */
1269     len = sizeof(METARECORD) + (((s1 + 1) >> 1) * 2) + 2 * sizeof(short)
1270       + sizeof(UINT16) + (isrect ? sizeof(RECT16) : 0);
1271                                            /* rec len without dx array */
1272 
1273     sot = (LPSTR)&mr->rdParm[4];                      /* start_of_text */
1274     if (isrect)
1275     {
1276         rect.left   = (SHORT)mr->rdParm[4];
1277         rect.top    = (SHORT)mr->rdParm[5];
1278         rect.right  = (SHORT)mr->rdParm[6];
1279         rect.bottom = (SHORT)mr->rdParm[7];
1280         sot += sizeof(RECT16);  /* there is a rectangle, so add offset */
1281     }
1282 
1283     if (mr->rdSize == len / 2)
1284         dxx = NULL;                      /* determine if array is present */
1285     else
1286         if (mr->rdSize == (len + s1 * sizeof(INT16)) / 2)
1287         {
1288             dxx = (LPINT16)(sot+(((s1+1)>>1)*2));
1289             dx = HeapAlloc( GetProcessHeap(), 0, s1*sizeof(INT));
1290             if (dx) for (i = 0; i < s1; i++) dx[i] = dxx[i];
1291         }
1292         else {
1293             TRACE("%s  len: %d\n",  sot, mr->rdSize);
1294             WARN("Please report: ExtTextOut len=%d slen=%d rdSize=%d opt=%04x\n",
1295                  len, s1, mr->rdSize, mr->rdParm[3]);
1296             dxx = NULL; /* shouldn't happen -- but if, we continue with NULL */
1297         }
1298     ExtTextOutA( hdc,
1299                  (SHORT)mr->rdParm[1],       /* X position */
1300                  (SHORT)mr->rdParm[0],       /* Y position */
1301                  mr->rdParm[3],              /* options */
1302                  &rect,                      /* rectangle */
1303                  sot,                        /* string */
1304                  s1, dx);                    /* length, dx array */
1305     if (dx)
1306     {
1307         TRACE("%s  len: %d  dx0: %d\n", sot, mr->rdSize, dx[0]);
1308         HeapFree( GetProcessHeap(), 0, dx );
1309     }
1310     return TRUE;
1311 }
1312 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.