imagehlp: Use the IMAGE_FIRST_SECTION helper macro.
[wine.git] / dlls / gdi32 / enhmetafile.c
blob12449ecfdf01fa2bd2ea5bc66d2e594ed8ca986b
1 /*
2 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
4 * 1999 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * NOTES:
22 * The enhanced format consists of the following elements:
24 * A header
25 * A table of handles to GDI objects
26 * An array of metafile records
27 * A private palette
30 * The standard format consists of a header and an array of metafile records.
34 #include <stdarg.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <assert.h>
38 #include <math.h>
40 #include "windef.h"
41 #include "winbase.h"
42 #include "wingdi.h"
43 #include "winnls.h"
44 #include "winerror.h"
45 #include "gdi_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
52 static CRITICAL_SECTION enhmetafile_cs;
53 static CRITICAL_SECTION_DEBUG critsect_debug =
55 0, 0, &enhmetafile_cs,
56 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
57 0, 0, { (DWORD_PTR)(__FILE__ ": enhmetafile_cs") }
59 static CRITICAL_SECTION enhmetafile_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
61 typedef struct
63 ENHMETAHEADER *emh;
64 BOOL on_disk; /* true if metafile is on disk */
65 } ENHMETAFILEOBJ;
67 static const struct emr_name {
68 DWORD type;
69 const char *name;
70 } emr_names[] = {
71 #define X(p) {p, #p}
72 X(EMR_HEADER),
73 X(EMR_POLYBEZIER),
74 X(EMR_POLYGON),
75 X(EMR_POLYLINE),
76 X(EMR_POLYBEZIERTO),
77 X(EMR_POLYLINETO),
78 X(EMR_POLYPOLYLINE),
79 X(EMR_POLYPOLYGON),
80 X(EMR_SETWINDOWEXTEX),
81 X(EMR_SETWINDOWORGEX),
82 X(EMR_SETVIEWPORTEXTEX),
83 X(EMR_SETVIEWPORTORGEX),
84 X(EMR_SETBRUSHORGEX),
85 X(EMR_EOF),
86 X(EMR_SETPIXELV),
87 X(EMR_SETMAPPERFLAGS),
88 X(EMR_SETMAPMODE),
89 X(EMR_SETBKMODE),
90 X(EMR_SETPOLYFILLMODE),
91 X(EMR_SETROP2),
92 X(EMR_SETSTRETCHBLTMODE),
93 X(EMR_SETTEXTALIGN),
94 X(EMR_SETCOLORADJUSTMENT),
95 X(EMR_SETTEXTCOLOR),
96 X(EMR_SETBKCOLOR),
97 X(EMR_OFFSETCLIPRGN),
98 X(EMR_MOVETOEX),
99 X(EMR_SETMETARGN),
100 X(EMR_EXCLUDECLIPRECT),
101 X(EMR_INTERSECTCLIPRECT),
102 X(EMR_SCALEVIEWPORTEXTEX),
103 X(EMR_SCALEWINDOWEXTEX),
104 X(EMR_SAVEDC),
105 X(EMR_RESTOREDC),
106 X(EMR_SETWORLDTRANSFORM),
107 X(EMR_MODIFYWORLDTRANSFORM),
108 X(EMR_SELECTOBJECT),
109 X(EMR_CREATEPEN),
110 X(EMR_CREATEBRUSHINDIRECT),
111 X(EMR_DELETEOBJECT),
112 X(EMR_ANGLEARC),
113 X(EMR_ELLIPSE),
114 X(EMR_RECTANGLE),
115 X(EMR_ROUNDRECT),
116 X(EMR_ARC),
117 X(EMR_CHORD),
118 X(EMR_PIE),
119 X(EMR_SELECTPALETTE),
120 X(EMR_CREATEPALETTE),
121 X(EMR_SETPALETTEENTRIES),
122 X(EMR_RESIZEPALETTE),
123 X(EMR_REALIZEPALETTE),
124 X(EMR_EXTFLOODFILL),
125 X(EMR_LINETO),
126 X(EMR_ARCTO),
127 X(EMR_POLYDRAW),
128 X(EMR_SETARCDIRECTION),
129 X(EMR_SETMITERLIMIT),
130 X(EMR_BEGINPATH),
131 X(EMR_ENDPATH),
132 X(EMR_CLOSEFIGURE),
133 X(EMR_FILLPATH),
134 X(EMR_STROKEANDFILLPATH),
135 X(EMR_STROKEPATH),
136 X(EMR_FLATTENPATH),
137 X(EMR_WIDENPATH),
138 X(EMR_SELECTCLIPPATH),
139 X(EMR_ABORTPATH),
140 X(EMR_GDICOMMENT),
141 X(EMR_FILLRGN),
142 X(EMR_FRAMERGN),
143 X(EMR_INVERTRGN),
144 X(EMR_PAINTRGN),
145 X(EMR_EXTSELECTCLIPRGN),
146 X(EMR_BITBLT),
147 X(EMR_STRETCHBLT),
148 X(EMR_MASKBLT),
149 X(EMR_PLGBLT),
150 X(EMR_SETDIBITSTODEVICE),
151 X(EMR_STRETCHDIBITS),
152 X(EMR_EXTCREATEFONTINDIRECTW),
153 X(EMR_EXTTEXTOUTA),
154 X(EMR_EXTTEXTOUTW),
155 X(EMR_POLYBEZIER16),
156 X(EMR_POLYGON16),
157 X(EMR_POLYLINE16),
158 X(EMR_POLYBEZIERTO16),
159 X(EMR_POLYLINETO16),
160 X(EMR_POLYPOLYLINE16),
161 X(EMR_POLYPOLYGON16),
162 X(EMR_POLYDRAW16),
163 X(EMR_CREATEMONOBRUSH),
164 X(EMR_CREATEDIBPATTERNBRUSHPT),
165 X(EMR_EXTCREATEPEN),
166 X(EMR_POLYTEXTOUTA),
167 X(EMR_POLYTEXTOUTW),
168 X(EMR_SETICMMODE),
169 X(EMR_CREATECOLORSPACE),
170 X(EMR_SETCOLORSPACE),
171 X(EMR_DELETECOLORSPACE),
172 X(EMR_GLSRECORD),
173 X(EMR_GLSBOUNDEDRECORD),
174 X(EMR_PIXELFORMAT),
175 X(EMR_DRAWESCAPE),
176 X(EMR_EXTESCAPE),
177 X(EMR_STARTDOC),
178 X(EMR_SMALLTEXTOUT),
179 X(EMR_FORCEUFIMAPPING),
180 X(EMR_NAMEDESCAPE),
181 X(EMR_COLORCORRECTPALETTE),
182 X(EMR_SETICMPROFILEA),
183 X(EMR_SETICMPROFILEW),
184 X(EMR_ALPHABLEND),
185 X(EMR_SETLAYOUT),
186 X(EMR_TRANSPARENTBLT),
187 X(EMR_RESERVED_117),
188 X(EMR_GRADIENTFILL),
189 X(EMR_SETLINKEDUFI),
190 X(EMR_SETTEXTJUSTIFICATION),
191 X(EMR_COLORMATCHTOTARGETW),
192 X(EMR_CREATECOLORSPACEW)
193 #undef X
196 /****************************************************************************
197 * get_emr_name
199 static const char *get_emr_name(DWORD type)
201 unsigned int i;
202 for(i = 0; i < ARRAY_SIZE(emr_names); i++)
203 if(type == emr_names[i].type) return emr_names[i].name;
204 TRACE("Unknown record type %ld\n", type);
205 return NULL;
208 /***********************************************************************
209 * is_dib_monochrome
211 * Returns whether a DIB can be converted to a monochrome DDB.
213 * A DIB can be converted if its color table contains only black and
214 * white. Black must be the first color in the color table.
216 * Note : If the first color in the color table is white followed by
217 * black, we can't convert it to a monochrome DDB with
218 * SetDIBits, because black and white would be inverted.
220 static inline BOOL is_dib_monochrome( const BITMAPINFO* info )
222 if (info->bmiHeader.biBitCount != 1) return FALSE;
224 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
226 const RGBTRIPLE *rgb = ((const BITMAPCOREINFO *) info)->bmciColors;
228 /* Check if the first color is black */
229 if ((rgb->rgbtRed == 0) && (rgb->rgbtGreen == 0) && (rgb->rgbtBlue == 0))
231 rgb++;
232 /* Check if the second color is white */
233 return ((rgb->rgbtRed == 0xff) && (rgb->rgbtGreen == 0xff)
234 && (rgb->rgbtBlue == 0xff));
236 else return FALSE;
238 else /* assume BITMAPINFOHEADER */
240 const RGBQUAD *rgb = info->bmiColors;
242 /* Check if the first color is black */
243 if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) &&
244 (rgb->rgbBlue == 0) && (rgb->rgbReserved == 0))
246 rgb++;
248 /* Check if the second color is white */
249 return ((rgb->rgbRed == 0xff) && (rgb->rgbGreen == 0xff)
250 && (rgb->rgbBlue == 0xff) && (rgb->rgbReserved == 0));
252 else return FALSE;
256 /****************************************************************************
257 * EMF_Create_HENHMETAFILE
259 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, DWORD filesize, BOOL on_disk )
261 HENHMETAFILE hmf;
262 ENHMETAFILEOBJ *metaObj;
264 if (filesize < sizeof(*emh))
266 WARN("File too small for emf header\n");
267 return 0;
269 if (emh->iType != EMR_HEADER)
271 SetLastError(ERROR_INVALID_DATA);
272 return 0;
274 if (emh->dSignature != ENHMETA_SIGNATURE ||
275 (emh->nBytes & 3)) /* refuse to load unaligned EMF as Windows does */
277 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
278 emh->iType, emh->dSignature);
279 return 0;
281 if (filesize < emh->nBytes)
283 WARN("File truncated (got %lu bytes, header says %lu)\n", emh->nBytes, filesize);
284 return 0;
287 if (!(metaObj = HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj) ))) return 0;
289 metaObj->emh = emh;
290 metaObj->on_disk = on_disk;
292 if ((hmf = NtGdiCreateClientObj( NTGDI_OBJ_ENHMETAFILE )))
293 set_gdi_client_ptr( hmf, metaObj );
294 else
295 HeapFree( GetProcessHeap(), 0, metaObj );
296 return hmf;
299 /****************************************************************************
300 * EMF_Delete_HENHMETAFILE
302 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
304 ENHMETAFILEOBJ *metafile;
306 EnterCriticalSection( &enhmetafile_cs );
307 if (!(metafile = get_gdi_client_ptr( hmf, NTGDI_OBJ_ENHMETAFILE )) ||
308 !NtGdiDeleteClientObj( hmf ))
310 LeaveCriticalSection( &enhmetafile_cs );
311 SetLastError( ERROR_INVALID_HANDLE );
312 return FALSE;
315 if (metafile->on_disk)
316 UnmapViewOfFile( metafile->emh );
317 else
318 HeapFree( GetProcessHeap(), 0, metafile->emh );
319 HeapFree( GetProcessHeap(), 0, metafile );
320 LeaveCriticalSection( &enhmetafile_cs );
321 return TRUE;
324 /******************************************************************
325 * EMF_GetEnhMetaHeader
327 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
329 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
331 ENHMETAHEADER *ret = NULL;
332 ENHMETAFILEOBJ *metafile;
334 EnterCriticalSection( &enhmetafile_cs );
335 if ((metafile = get_gdi_client_ptr( hmf, NTGDI_OBJ_ENHMETAFILE )))
337 TRACE( "hmf %p -> enhmetafile %p\n", hmf, metafile );
338 ret = metafile->emh;
340 else SetLastError( ERROR_INVALID_HANDLE );
341 LeaveCriticalSection( &enhmetafile_cs );
342 return ret;
345 /*****************************************************************************
346 * EMF_GetEnhMetaFile
349 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
351 ENHMETAHEADER *emh;
352 HANDLE hMapping;
353 HENHMETAFILE hemf;
354 DWORD filesize;
356 filesize = GetFileSize( hFile, NULL );
358 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
359 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, filesize );
360 CloseHandle( hMapping );
362 if (!emh) return 0;
364 hemf = EMF_Create_HENHMETAFILE( emh, filesize, TRUE );
365 if (!hemf)
366 UnmapViewOfFile( emh );
367 return hemf;
371 /*****************************************************************************
372 * GetEnhMetaFileA (GDI32.@)
376 HENHMETAFILE WINAPI GetEnhMetaFileA(
377 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
380 HENHMETAFILE hmf;
381 HANDLE hFile;
383 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
384 OPEN_EXISTING, 0, 0);
385 if (hFile == INVALID_HANDLE_VALUE) {
386 WARN("could not open %s\n", lpszMetaFile);
387 return 0;
389 hmf = EMF_GetEnhMetaFile( hFile );
390 CloseHandle( hFile );
391 return hmf;
394 /*****************************************************************************
395 * GetEnhMetaFileW (GDI32.@)
397 HENHMETAFILE WINAPI GetEnhMetaFileW(
398 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
400 HENHMETAFILE hmf;
401 HANDLE hFile;
403 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
404 OPEN_EXISTING, 0, 0);
405 if (hFile == INVALID_HANDLE_VALUE) {
406 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
407 return 0;
409 hmf = EMF_GetEnhMetaFile( hFile );
410 CloseHandle( hFile );
411 return hmf;
414 /*****************************************************************************
415 * GetEnhMetaFileHeader (GDI32.@)
417 * Retrieves the record containing the header for the specified
418 * enhanced-format metafile.
420 * RETURNS
421 * If buf is NULL, returns the size of buffer required.
422 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
423 * buf.
425 UINT WINAPI GetEnhMetaFileHeader(
426 HENHMETAFILE hmf, /* [in] enhanced metafile */
427 UINT bufsize, /* [in] size of buffer */
428 LPENHMETAHEADER buf /* [out] buffer */
431 LPENHMETAHEADER emh;
432 UINT size;
434 emh = EMF_GetEnhMetaHeader(hmf);
435 if(!emh) return FALSE;
436 size = emh->nSize;
437 if (!buf) return size;
438 size = min(size, bufsize);
439 memmove(buf, emh, size);
440 return size;
444 /*****************************************************************************
445 * GetEnhMetaFileDescriptionA (GDI32.@)
447 * See GetEnhMetaFileDescriptionW.
449 UINT WINAPI GetEnhMetaFileDescriptionA(
450 HENHMETAFILE hmf, /* [in] enhanced metafile */
451 UINT size, /* [in] size of buf */
452 LPSTR buf /* [out] buffer to receive description */
455 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
456 DWORD len;
457 WCHAR *descrW;
459 if(!emh) return FALSE;
460 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
461 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
462 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
464 if (!buf || !size ) return len;
466 len = min( size, len );
467 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
468 return len;
471 /*****************************************************************************
472 * GetEnhMetaFileDescriptionW (GDI32.@)
474 * Copies the description string of an enhanced metafile into a buffer
475 * _buf_.
477 * RETURNS
478 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
479 * number of characters copied.
481 UINT WINAPI GetEnhMetaFileDescriptionW(
482 HENHMETAFILE hmf, /* [in] enhanced metafile */
483 UINT size, /* [in] size of buf */
484 LPWSTR buf /* [out] buffer to receive description */
487 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
489 if(!emh) return FALSE;
490 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
491 if (!buf || !size ) return emh->nDescription;
493 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
494 return min(size, emh->nDescription);
497 /****************************************************************************
498 * SetEnhMetaFileBits (GDI32.@)
500 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
502 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
504 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
505 HENHMETAFILE hmf;
507 if (!emh) return 0;
508 memcpy(emh, buf, bufsize);
509 hmf = EMF_Create_HENHMETAFILE( emh, bufsize, FALSE );
510 if (!hmf)
511 HeapFree( GetProcessHeap(), 0, emh );
512 return hmf;
515 /*****************************************************************************
516 * GetEnhMetaFileBits (GDI32.@)
519 UINT WINAPI GetEnhMetaFileBits(
520 HENHMETAFILE hmf,
521 UINT bufsize,
522 LPBYTE buf
525 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
526 UINT size;
528 if(!emh) return 0;
530 size = emh->nBytes;
531 if( buf == NULL ) return size;
533 size = min( size, bufsize );
534 memmove(buf, emh, size);
535 return size;
538 typedef struct EMF_dc_state
540 INT mode;
541 XFORM world_transform;
542 INT wndOrgX;
543 INT wndOrgY;
544 INT wndExtX;
545 INT wndExtY;
546 INT vportOrgX;
547 INT vportOrgY;
548 INT vportExtX;
549 INT vportExtY;
550 struct EMF_dc_state *next;
551 } EMF_dc_state;
553 typedef struct enum_emh_data
555 XFORM init_transform;
556 EMF_dc_state state;
557 INT save_level;
558 EMF_dc_state *saved_state;
559 } enum_emh_data;
561 #define ENUM_GET_PRIVATE_DATA(ht) \
562 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
564 #define WIDTH(rect) ( (rect).right - (rect).left )
565 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
567 #define IS_WIN9X() (GetVersion()&0x80000000)
569 static void EMF_Update_MF_Xform(HDC hdc, const enum_emh_data *info)
571 XFORM mapping_mode_trans, final_trans;
572 double scaleX, scaleY;
574 scaleX = (double)info->state.vportExtX / (double)info->state.wndExtX;
575 scaleY = (double)info->state.vportExtY / (double)info->state.wndExtY;
576 mapping_mode_trans.eM11 = scaleX;
577 mapping_mode_trans.eM12 = 0.0;
578 mapping_mode_trans.eM21 = 0.0;
579 mapping_mode_trans.eM22 = scaleY;
580 mapping_mode_trans.eDx = (double)info->state.vportOrgX - scaleX * (double)info->state.wndOrgX;
581 mapping_mode_trans.eDy = (double)info->state.vportOrgY - scaleY * (double)info->state.wndOrgY;
583 CombineTransform(&final_trans, &info->state.world_transform, &mapping_mode_trans);
584 CombineTransform(&final_trans, &final_trans, &info->init_transform);
586 if (!SetWorldTransform(hdc, &final_trans))
588 ERR("World transform failed!\n");
592 static void EMF_RestoreDC( enum_emh_data *info, INT level )
594 if (abs(level) > info->save_level || level == 0) return;
596 if (level < 0) level = info->save_level + level + 1;
598 while (info->save_level >= level)
600 EMF_dc_state *state = info->saved_state;
601 info->saved_state = state->next;
602 state->next = NULL;
603 if (--info->save_level < level)
604 info->state = *state;
605 HeapFree( GetProcessHeap(), 0, state );
609 static void EMF_SaveDC( enum_emh_data *info )
611 EMF_dc_state *state = HeapAlloc( GetProcessHeap(), 0, sizeof(*state));
612 if (state)
614 *state = info->state;
615 state->next = info->saved_state;
616 info->saved_state = state;
617 info->save_level++;
618 TRACE("save_level %d\n", info->save_level);
622 static void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
624 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
625 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
626 INT horzRes = GetDeviceCaps( hdc, HORZRES );
627 INT vertRes = GetDeviceCaps( hdc, VERTRES );
629 TRACE("%d\n", info->state.mode);
631 switch(info->state.mode)
633 case MM_TEXT:
634 info->state.wndExtX = 1;
635 info->state.wndExtY = 1;
636 info->state.vportExtX = 1;
637 info->state.vportExtY = 1;
638 break;
639 case MM_LOMETRIC:
640 case MM_ISOTROPIC:
641 info->state.wndExtX = horzSize * 10;
642 info->state.wndExtY = vertSize * 10;
643 info->state.vportExtX = horzRes;
644 info->state.vportExtY = -vertRes;
645 break;
646 case MM_HIMETRIC:
647 info->state.wndExtX = horzSize * 100;
648 info->state.wndExtY = vertSize * 100;
649 info->state.vportExtX = horzRes;
650 info->state.vportExtY = -vertRes;
651 break;
652 case MM_LOENGLISH:
653 info->state.wndExtX = MulDiv(1000, horzSize, 254);
654 info->state.wndExtY = MulDiv(1000, vertSize, 254);
655 info->state.vportExtX = horzRes;
656 info->state.vportExtY = -vertRes;
657 break;
658 case MM_HIENGLISH:
659 info->state.wndExtX = MulDiv(10000, horzSize, 254);
660 info->state.wndExtY = MulDiv(10000, vertSize, 254);
661 info->state.vportExtX = horzRes;
662 info->state.vportExtY = -vertRes;
663 break;
664 case MM_TWIPS:
665 info->state.wndExtX = MulDiv(14400, horzSize, 254);
666 info->state.wndExtY = MulDiv(14400, vertSize, 254);
667 info->state.vportExtX = horzRes;
668 info->state.vportExtY = -vertRes;
669 break;
670 case MM_ANISOTROPIC:
671 break;
672 default:
673 return;
677 /***********************************************************************
678 * EMF_FixIsotropic
680 * Fix viewport extensions for isotropic mode.
683 static void EMF_FixIsotropic(HDC hdc, enum_emh_data *info)
685 double xdim = fabs((double)info->state.vportExtX * GetDeviceCaps( hdc, HORZSIZE ) /
686 (GetDeviceCaps( hdc, HORZRES ) * info->state.wndExtX));
687 double ydim = fabs((double)info->state.vportExtY * GetDeviceCaps( hdc, VERTSIZE ) /
688 (GetDeviceCaps( hdc, VERTRES ) * info->state.wndExtY));
690 if (xdim > ydim)
692 INT mincx = (info->state.vportExtX >= 0) ? 1 : -1;
693 info->state.vportExtX = floor(info->state.vportExtX * ydim / xdim + 0.5);
694 if (!info->state.vportExtX) info->state.vportExtX = mincx;
696 else
698 INT mincy = (info->state.vportExtY >= 0) ? 1 : -1;
699 info->state.vportExtY = floor(info->state.vportExtY * xdim / ydim + 0.5);
700 if (!info->state.vportExtY) info->state.vportExtY = mincy;
704 /*****************************************************************************
705 * emr_produces_output
707 * Returns TRUE if the record type writes something to the dc. Used by
708 * PlayEnhMetaFileRecord to determine whether it needs to update the
709 * dc's xform when in win9x mode.
711 * FIXME: need to test which records should be here.
713 static BOOL emr_produces_output(int type)
715 switch(type) {
716 case EMR_POLYBEZIER:
717 case EMR_POLYGON:
718 case EMR_POLYLINE:
719 case EMR_POLYBEZIERTO:
720 case EMR_POLYLINETO:
721 case EMR_POLYPOLYLINE:
722 case EMR_POLYPOLYGON:
723 case EMR_SETPIXELV:
724 case EMR_MOVETOEX:
725 case EMR_EXCLUDECLIPRECT:
726 case EMR_INTERSECTCLIPRECT:
727 case EMR_SELECTOBJECT:
728 case EMR_ANGLEARC:
729 case EMR_ELLIPSE:
730 case EMR_RECTANGLE:
731 case EMR_ROUNDRECT:
732 case EMR_ARC:
733 case EMR_CHORD:
734 case EMR_PIE:
735 case EMR_EXTFLOODFILL:
736 case EMR_LINETO:
737 case EMR_ARCTO:
738 case EMR_POLYDRAW:
739 case EMR_GDICOMMENT:
740 case EMR_FILLRGN:
741 case EMR_FRAMERGN:
742 case EMR_INVERTRGN:
743 case EMR_PAINTRGN:
744 case EMR_BITBLT:
745 case EMR_STRETCHBLT:
746 case EMR_MASKBLT:
747 case EMR_PLGBLT:
748 case EMR_SETDIBITSTODEVICE:
749 case EMR_STRETCHDIBITS:
750 case EMR_EXTTEXTOUTA:
751 case EMR_EXTTEXTOUTW:
752 case EMR_POLYBEZIER16:
753 case EMR_POLYGON16:
754 case EMR_POLYLINE16:
755 case EMR_POLYBEZIERTO16:
756 case EMR_POLYLINETO16:
757 case EMR_POLYPOLYLINE16:
758 case EMR_POLYPOLYGON16:
759 case EMR_POLYDRAW16:
760 case EMR_POLYTEXTOUTA:
761 case EMR_POLYTEXTOUTW:
762 case EMR_SMALLTEXTOUT:
763 case EMR_ALPHABLEND:
764 case EMR_TRANSPARENTBLT:
765 return TRUE;
766 default:
767 return FALSE;
771 static HGDIOBJ get_object_handle(HANDLETABLE *handletable, DWORD i)
773 if (i & 0x80000000)
774 return GetStockObject( i & 0x7fffffff );
775 return handletable->objectHandle[i];
778 /*****************************************************************************
779 * PlayEnhMetaFileRecord (GDI32.@)
781 * Render a single enhanced metafile record in the device context hdc.
783 * RETURNS
784 * TRUE (non zero) on success, FALSE on error.
785 * BUGS
786 * Many unimplemented records.
787 * No error handling on record play failures (ie checking return codes)
789 * NOTES
790 * WinNT actually updates the current world transform in this function
791 * whereas Win9x does not.
793 BOOL WINAPI PlayEnhMetaFileRecord(
794 HDC hdc, /* [in] device context in which to render EMF record */
795 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
796 const ENHMETARECORD *mr, /* [in] EMF record to render */
797 UINT handles /* [in] size of handle array */
800 int type;
801 RECT tmprc;
802 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
804 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
805 hdc, handletable, mr, handles);
806 if (!mr) return FALSE;
808 type = mr->iType;
810 TRACE("record %s\n", get_emr_name(type));
811 switch(type)
813 case EMR_HEADER:
814 break;
815 case EMR_EOF:
816 break;
817 case EMR_GDICOMMENT:
819 const EMRGDICOMMENT *lpGdiComment = (const EMRGDICOMMENT *)mr;
820 /* In an enhanced metafile, there can be both public and private GDI comments */
821 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
822 break;
824 case EMR_SETMAPMODE:
826 const EMRSETMAPMODE *pSetMapMode = (const EMRSETMAPMODE *)mr;
828 if (info->state.mode == pSetMapMode->iMode &&
829 (info->state.mode == MM_ISOTROPIC || info->state.mode == MM_ANISOTROPIC))
830 break;
831 info->state.mode = pSetMapMode->iMode;
832 EMF_SetMapMode(hdc, info);
834 if (!IS_WIN9X())
835 EMF_Update_MF_Xform(hdc, info);
837 break;
839 case EMR_SETBKMODE:
841 const EMRSETBKMODE *pSetBkMode = (const EMRSETBKMODE *)mr;
842 SetBkMode(hdc, pSetBkMode->iMode);
843 break;
845 case EMR_SETBKCOLOR:
847 const EMRSETBKCOLOR *pSetBkColor = (const EMRSETBKCOLOR *)mr;
848 SetBkColor(hdc, pSetBkColor->crColor);
849 break;
851 case EMR_SETPOLYFILLMODE:
853 const EMRSETPOLYFILLMODE *pSetPolyFillMode = (const EMRSETPOLYFILLMODE *)mr;
854 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
855 break;
857 case EMR_SETROP2:
859 const EMRSETROP2 *pSetROP2 = (const EMRSETROP2 *)mr;
860 SetROP2(hdc, pSetROP2->iMode);
861 break;
863 case EMR_SETSTRETCHBLTMODE:
865 const EMRSETSTRETCHBLTMODE *pSetStretchBltMode = (const EMRSETSTRETCHBLTMODE *)mr;
866 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
867 break;
869 case EMR_SETTEXTALIGN:
871 const EMRSETTEXTALIGN *pSetTextAlign = (const EMRSETTEXTALIGN *)mr;
872 SetTextAlign(hdc, pSetTextAlign->iMode);
873 break;
875 case EMR_SETTEXTCOLOR:
877 const EMRSETTEXTCOLOR *pSetTextColor = (const EMRSETTEXTCOLOR *)mr;
878 SetTextColor(hdc, pSetTextColor->crColor);
879 break;
881 case EMR_SAVEDC:
883 if (SaveDC( hdc ))
884 EMF_SaveDC( info );
885 break;
887 case EMR_RESTOREDC:
889 const EMRRESTOREDC *pRestoreDC = (const EMRRESTOREDC *)mr;
890 TRACE("EMR_RESTORE: %ld\n", pRestoreDC->iRelative);
891 if (RestoreDC( hdc, pRestoreDC->iRelative ))
892 EMF_RestoreDC( info, pRestoreDC->iRelative );
893 break;
895 case EMR_INTERSECTCLIPRECT:
897 const EMRINTERSECTCLIPRECT *pClipRect = (const EMRINTERSECTCLIPRECT *)mr;
898 TRACE("EMR_INTERSECTCLIPRECT: rect %ld,%ld - %ld, %ld\n",
899 pClipRect->rclClip.left, pClipRect->rclClip.top,
900 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
901 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
902 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
903 break;
905 case EMR_SELECTOBJECT:
907 const EMRSELECTOBJECT *pSelectObject = (const EMRSELECTOBJECT *)mr;
908 SelectObject( hdc, get_object_handle(handletable, pSelectObject->ihObject) );
909 break;
911 case EMR_DELETEOBJECT:
913 const EMRDELETEOBJECT *pDeleteObject = (const EMRDELETEOBJECT *)mr;
914 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
915 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
916 break;
918 case EMR_SETWINDOWORGEX:
920 const EMRSETWINDOWORGEX *pSetWindowOrgEx = (const EMRSETWINDOWORGEX *)mr;
922 info->state.wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
923 info->state.wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
925 TRACE("SetWindowOrgEx: %d,%d\n", info->state.wndOrgX, info->state.wndOrgY);
927 if (!IS_WIN9X())
928 EMF_Update_MF_Xform(hdc, info);
930 break;
932 case EMR_SETWINDOWEXTEX:
934 const EMRSETWINDOWEXTEX *pSetWindowExtEx = (const EMRSETWINDOWEXTEX *)mr;
936 if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
937 break;
938 info->state.wndExtX = pSetWindowExtEx->szlExtent.cx;
939 info->state.wndExtY = pSetWindowExtEx->szlExtent.cy;
940 if (info->state.mode == MM_ISOTROPIC)
941 EMF_FixIsotropic(hdc, info);
943 TRACE("SetWindowExtEx: %d,%d\n",info->state.wndExtX, info->state.wndExtY);
945 if (!IS_WIN9X())
946 EMF_Update_MF_Xform(hdc, info);
948 break;
950 case EMR_SETVIEWPORTORGEX:
952 const EMRSETVIEWPORTORGEX *pSetViewportOrgEx = (const EMRSETVIEWPORTORGEX *)mr;
954 info->state.vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
955 info->state.vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
956 TRACE("SetViewportOrgEx: %d,%d\n", info->state.vportOrgX, info->state.vportOrgY);
958 if (!IS_WIN9X())
959 EMF_Update_MF_Xform(hdc, info);
961 break;
963 case EMR_SETVIEWPORTEXTEX:
965 const EMRSETVIEWPORTEXTEX *pSetViewportExtEx = (const EMRSETVIEWPORTEXTEX *)mr;
967 if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
968 break;
969 info->state.vportExtX = pSetViewportExtEx->szlExtent.cx;
970 info->state.vportExtY = pSetViewportExtEx->szlExtent.cy;
971 if (info->state.mode == MM_ISOTROPIC)
972 EMF_FixIsotropic(hdc, info);
973 TRACE("SetViewportExtEx: %d,%d\n", info->state.vportExtX, info->state.vportExtY);
975 if (!IS_WIN9X())
976 EMF_Update_MF_Xform(hdc, info);
978 break;
980 case EMR_CREATEPEN:
982 const EMRCREATEPEN *pCreatePen = (const EMRCREATEPEN *)mr;
983 (handletable->objectHandle)[pCreatePen->ihPen] =
984 CreatePenIndirect(&pCreatePen->lopn);
985 break;
987 case EMR_EXTCREATEPEN:
989 const EMREXTCREATEPEN *pPen = (const EMREXTCREATEPEN *)mr;
990 LOGBRUSH lb;
991 lb.lbStyle = pPen->elp.elpBrushStyle;
992 lb.lbColor = pPen->elp.elpColor;
993 lb.lbHatch = pPen->elp.elpHatch;
995 if(pPen->offBmi || pPen->offBits)
996 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
998 (handletable->objectHandle)[pPen->ihPen] =
999 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
1000 pPen->elp.elpNumEntries, pPen->elp.elpNumEntries ? pPen->elp.elpStyleEntry : NULL);
1001 break;
1003 case EMR_CREATEBRUSHINDIRECT:
1005 const EMRCREATEBRUSHINDIRECT *pBrush = (const EMRCREATEBRUSHINDIRECT *)mr;
1006 LOGBRUSH brush;
1007 brush.lbStyle = pBrush->lb.lbStyle;
1008 brush.lbColor = pBrush->lb.lbColor;
1009 brush.lbHatch = pBrush->lb.lbHatch;
1010 (handletable->objectHandle)[pBrush->ihBrush] = CreateBrushIndirect(&brush);
1011 break;
1013 case EMR_EXTCREATEFONTINDIRECTW:
1015 const EMREXTCREATEFONTINDIRECTW *pFont = (const EMREXTCREATEFONTINDIRECTW *)mr;
1016 (handletable->objectHandle)[pFont->ihFont] =
1017 CreateFontIndirectW(&pFont->elfw.elfLogFont);
1018 break;
1020 case EMR_MOVETOEX:
1022 const EMRMOVETOEX *pMoveToEx = (const EMRMOVETOEX *)mr;
1023 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
1024 break;
1026 case EMR_LINETO:
1028 const EMRLINETO *pLineTo = (const EMRLINETO *)mr;
1029 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
1030 break;
1032 case EMR_RECTANGLE:
1034 const EMRRECTANGLE *pRect = (const EMRRECTANGLE *)mr;
1035 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
1036 pRect->rclBox.right, pRect->rclBox.bottom);
1037 break;
1039 case EMR_ELLIPSE:
1041 const EMRELLIPSE *pEllipse = (const EMRELLIPSE *)mr;
1042 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
1043 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
1044 break;
1046 case EMR_POLYGON16:
1048 const EMRPOLYGON16 *pPoly = (const EMRPOLYGON16 *)mr;
1049 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
1050 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1051 pPoly->cpts * sizeof(POINT) );
1052 DWORD i;
1053 for(i = 0; i < pPoly->cpts; i++)
1055 pts[i].x = pPoly->apts[i].x;
1056 pts[i].y = pPoly->apts[i].y;
1058 Polygon(hdc, pts, pPoly->cpts);
1059 HeapFree( GetProcessHeap(), 0, pts );
1060 break;
1062 case EMR_POLYLINE16:
1064 const EMRPOLYLINE16 *pPoly = (const EMRPOLYLINE16 *)mr;
1065 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1066 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1067 pPoly->cpts * sizeof(POINT) );
1068 DWORD i;
1069 for(i = 0; i < pPoly->cpts; i++)
1071 pts[i].x = pPoly->apts[i].x;
1072 pts[i].y = pPoly->apts[i].y;
1074 Polyline(hdc, pts, pPoly->cpts);
1075 HeapFree( GetProcessHeap(), 0, pts );
1076 break;
1078 case EMR_POLYLINETO16:
1080 const EMRPOLYLINETO16 *pPoly = (const EMRPOLYLINETO16 *)mr;
1081 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1082 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1083 pPoly->cpts * sizeof(POINT) );
1084 DWORD i;
1085 for(i = 0; i < pPoly->cpts; i++)
1087 pts[i].x = pPoly->apts[i].x;
1088 pts[i].y = pPoly->apts[i].y;
1090 PolylineTo(hdc, pts, pPoly->cpts);
1091 HeapFree( GetProcessHeap(), 0, pts );
1092 break;
1094 case EMR_POLYBEZIER16:
1096 const EMRPOLYBEZIER16 *pPoly = (const EMRPOLYBEZIER16 *)mr;
1097 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1098 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1099 pPoly->cpts * sizeof(POINT) );
1100 DWORD i;
1101 for(i = 0; i < pPoly->cpts; i++)
1103 pts[i].x = pPoly->apts[i].x;
1104 pts[i].y = pPoly->apts[i].y;
1106 PolyBezier(hdc, pts, pPoly->cpts);
1107 HeapFree( GetProcessHeap(), 0, pts );
1108 break;
1110 case EMR_POLYBEZIERTO16:
1112 const EMRPOLYBEZIERTO16 *pPoly = (const EMRPOLYBEZIERTO16 *)mr;
1113 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1114 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1115 pPoly->cpts * sizeof(POINT) );
1116 DWORD i;
1117 for(i = 0; i < pPoly->cpts; i++)
1119 pts[i].x = pPoly->apts[i].x;
1120 pts[i].y = pPoly->apts[i].y;
1122 PolyBezierTo(hdc, pts, pPoly->cpts);
1123 HeapFree( GetProcessHeap(), 0, pts );
1124 break;
1126 case EMR_POLYPOLYGON16:
1128 const EMRPOLYPOLYGON16 *pPolyPoly = (const EMRPOLYPOLYGON16 *)mr;
1129 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1130 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1132 const POINTS *pts = (const POINTS *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1133 POINT *pt = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1134 DWORD i;
1135 for(i = 0; i < pPolyPoly->cpts; i++)
1137 pt[i].x = pts[i].x;
1138 pt[i].y = pts[i].y;
1140 PolyPolygon(hdc, pt, (const INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1141 HeapFree( GetProcessHeap(), 0, pt );
1142 break;
1144 case EMR_POLYPOLYLINE16:
1146 const EMRPOLYPOLYLINE16 *pPolyPoly = (const EMRPOLYPOLYLINE16 *)mr;
1147 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1148 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1150 const POINTS *pts = (const POINTS *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1151 POINT *pt = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1152 DWORD i;
1153 for(i = 0; i < pPolyPoly->cpts; i++)
1155 pt[i].x = pts[i].x;
1156 pt[i].y = pts[i].y;
1158 PolyPolyline(hdc, pt, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1159 HeapFree( GetProcessHeap(), 0, pt );
1160 break;
1163 case EMR_POLYDRAW16:
1165 const EMRPOLYDRAW16 *pPolyDraw16 = (const EMRPOLYDRAW16 *)mr;
1166 const POINTS *ptl = pPolyDraw16->apts;
1167 POINT *pts = HeapAlloc(GetProcessHeap(), 0, pPolyDraw16->cpts * sizeof(POINT));
1168 DWORD i;
1170 /* NB abTypes array doesn't start at pPolyDraw16->abTypes. It's actually
1171 pPolyDraw16->apts + pPolyDraw16->cpts. */
1172 const BYTE *types = (BYTE*)(pPolyDraw16->apts + pPolyDraw16->cpts);
1174 if (!pts)
1175 break;
1177 for (i = 0; i < pPolyDraw16->cpts; ++i)
1179 pts[i].x = ptl[i].x;
1180 pts[i].y = ptl[i].y;
1183 PolyDraw(hdc, pts, types, pPolyDraw16->cpts);
1184 HeapFree(GetProcessHeap(), 0, pts);
1185 break;
1188 case EMR_STRETCHDIBITS:
1190 const EMRSTRETCHDIBITS *pStretchDIBits = (const EMRSTRETCHDIBITS *)mr;
1192 StretchDIBits(hdc,
1193 pStretchDIBits->xDest,
1194 pStretchDIBits->yDest,
1195 pStretchDIBits->cxDest,
1196 pStretchDIBits->cyDest,
1197 pStretchDIBits->xSrc,
1198 pStretchDIBits->ySrc,
1199 pStretchDIBits->cxSrc,
1200 pStretchDIBits->cySrc,
1201 (const BYTE *)mr + pStretchDIBits->offBitsSrc,
1202 (const BITMAPINFO *)((const BYTE *)mr + pStretchDIBits->offBmiSrc),
1203 pStretchDIBits->iUsageSrc,
1204 pStretchDIBits->dwRop);
1205 break;
1208 case EMR_EXTTEXTOUTA:
1210 const EMREXTTEXTOUTA *pExtTextOutA = (const EMREXTTEXTOUTA *)mr;
1211 RECT rc;
1212 const INT *dx = NULL;
1213 int old_mode;
1215 rc.left = pExtTextOutA->emrtext.rcl.left;
1216 rc.top = pExtTextOutA->emrtext.rcl.top;
1217 rc.right = pExtTextOutA->emrtext.rcl.right;
1218 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
1219 TRACE("EMR_EXTTEXTOUTA: x,y = %ld, %ld. rect = %s. flags %08lx\n",
1220 pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1221 wine_dbgstr_rect(&rc), pExtTextOutA->emrtext.fOptions);
1223 old_mode = SetGraphicsMode(hdc, pExtTextOutA->iGraphicsMode);
1224 /* Reselect the font back into the dc so that the transformation
1225 gets updated. */
1226 SelectObject(hdc, GetCurrentObject(hdc, OBJ_FONT));
1228 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1229 * These files can be enumerated and played under Win98 just
1230 * fine, but at least Win2k chokes on them.
1232 if (pExtTextOutA->emrtext.offDx)
1233 dx = (const INT *)((const BYTE *)mr + pExtTextOutA->emrtext.offDx);
1235 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1236 pExtTextOutA->emrtext.fOptions, &rc,
1237 (LPCSTR)((const BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
1238 dx);
1240 SetGraphicsMode(hdc, old_mode);
1241 break;
1244 case EMR_EXTTEXTOUTW:
1246 const EMREXTTEXTOUTW *pExtTextOutW = (const EMREXTTEXTOUTW *)mr;
1247 RECT rc;
1248 const INT *dx = NULL;
1249 int old_mode;
1251 rc.left = pExtTextOutW->emrtext.rcl.left;
1252 rc.top = pExtTextOutW->emrtext.rcl.top;
1253 rc.right = pExtTextOutW->emrtext.rcl.right;
1254 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
1255 TRACE("EMR_EXTTEXTOUTW: x,y = %ld, %ld. rect = %s. flags %08lx\n",
1256 pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1257 wine_dbgstr_rect(&rc), pExtTextOutW->emrtext.fOptions);
1259 old_mode = SetGraphicsMode(hdc, pExtTextOutW->iGraphicsMode);
1260 /* Reselect the font back into the dc so that the transformation
1261 gets updated. */
1262 SelectObject(hdc, GetCurrentObject(hdc, OBJ_FONT));
1264 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1265 * These files can be enumerated and played under Win98 just
1266 * fine, but at least Win2k chokes on them.
1268 if (pExtTextOutW->emrtext.offDx)
1269 dx = (const INT *)((const BYTE *)mr + pExtTextOutW->emrtext.offDx);
1271 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1272 pExtTextOutW->emrtext.fOptions, &rc,
1273 (LPCWSTR)((const BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
1274 dx);
1276 SetGraphicsMode(hdc, old_mode);
1277 break;
1280 case EMR_CREATEPALETTE:
1282 const EMRCREATEPALETTE *lpCreatePal = (const EMRCREATEPALETTE *)mr;
1284 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
1285 CreatePalette( &lpCreatePal->lgpl );
1287 break;
1290 case EMR_SELECTPALETTE:
1292 const EMRSELECTPALETTE *lpSelectPal = (const EMRSELECTPALETTE *)mr;
1294 SelectPalette( hdc, get_object_handle(handletable, lpSelectPal->ihPal), TRUE );
1295 break;
1298 case EMR_REALIZEPALETTE:
1300 RealizePalette( hdc );
1301 break;
1304 case EMR_EXTSELECTCLIPRGN:
1306 const EMREXTSELECTCLIPRGN *lpRgn = (const EMREXTSELECTCLIPRGN *)mr;
1307 HRGN hRgn = 0;
1309 if (mr->nSize >= sizeof(*lpRgn) + sizeof(RGNDATAHEADER))
1310 hRgn = ExtCreateRegion( &info->init_transform, 0, (const RGNDATA *)lpRgn->RgnData );
1312 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
1313 /* ExtSelectClipRgn created a copy of the region */
1314 DeleteObject(hRgn);
1315 break;
1318 case EMR_SETMETARGN:
1320 SetMetaRgn( hdc );
1321 break;
1324 case EMR_SETWORLDTRANSFORM:
1326 const EMRSETWORLDTRANSFORM *lpXfrm = (const EMRSETWORLDTRANSFORM *)mr;
1327 info->state.world_transform = lpXfrm->xform;
1329 if (!IS_WIN9X())
1330 EMF_Update_MF_Xform(hdc, info);
1332 break;
1335 case EMR_POLYBEZIER:
1337 const EMRPOLYBEZIER *lpPolyBez = (const EMRPOLYBEZIER *)mr;
1338 PolyBezier(hdc, (const POINT*)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
1339 break;
1342 case EMR_POLYGON:
1344 const EMRPOLYGON *lpPoly = (const EMRPOLYGON *)mr;
1345 Polygon( hdc, (const POINT*)lpPoly->aptl, (UINT)lpPoly->cptl );
1346 break;
1349 case EMR_POLYLINE:
1351 const EMRPOLYLINE *lpPolyLine = (const EMRPOLYLINE *)mr;
1352 Polyline(hdc, (const POINT*)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
1353 break;
1356 case EMR_POLYBEZIERTO:
1358 const EMRPOLYBEZIERTO *lpPolyBezierTo = (const EMRPOLYBEZIERTO *)mr;
1359 PolyBezierTo( hdc, (const POINT*)lpPolyBezierTo->aptl,
1360 (UINT)lpPolyBezierTo->cptl );
1361 break;
1364 case EMR_POLYLINETO:
1366 const EMRPOLYLINETO *lpPolyLineTo = (const EMRPOLYLINETO *)mr;
1367 PolylineTo( hdc, (const POINT*)lpPolyLineTo->aptl,
1368 (UINT)lpPolyLineTo->cptl );
1369 break;
1372 case EMR_POLYPOLYLINE:
1374 const EMRPOLYPOLYLINE *pPolyPolyline = (const EMRPOLYPOLYLINE *)mr;
1375 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1377 PolyPolyline(hdc, (const POINT*)(pPolyPolyline->aPolyCounts +
1378 pPolyPolyline->nPolys),
1379 pPolyPolyline->aPolyCounts,
1380 pPolyPolyline->nPolys );
1382 break;
1385 case EMR_POLYPOLYGON:
1387 const EMRPOLYPOLYGON *pPolyPolygon = (const EMRPOLYPOLYGON *)mr;
1389 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1391 PolyPolygon(hdc, (const POINT*)(pPolyPolygon->aPolyCounts +
1392 pPolyPolygon->nPolys),
1393 (const INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
1394 break;
1397 case EMR_SETBRUSHORGEX:
1399 const EMRSETBRUSHORGEX *lpSetBrushOrgEx = (const EMRSETBRUSHORGEX *)mr;
1401 SetBrushOrgEx( hdc,
1402 (INT)lpSetBrushOrgEx->ptlOrigin.x,
1403 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1404 NULL );
1406 break;
1409 case EMR_SETPIXELV:
1411 const EMRSETPIXELV *lpSetPixelV = (const EMRSETPIXELV *)mr;
1413 SetPixelV( hdc,
1414 (INT)lpSetPixelV->ptlPixel.x,
1415 (INT)lpSetPixelV->ptlPixel.y,
1416 lpSetPixelV->crColor );
1418 break;
1421 case EMR_SETMAPPERFLAGS:
1423 const EMRSETMAPPERFLAGS *lpSetMapperFlags = (const EMRSETMAPPERFLAGS *)mr;
1425 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1427 break;
1430 case EMR_SETCOLORADJUSTMENT:
1432 const EMRSETCOLORADJUSTMENT *lpSetColorAdjust = (const EMRSETCOLORADJUSTMENT *)mr;
1434 NtGdiSetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1436 break;
1439 case EMR_OFFSETCLIPRGN:
1441 const EMROFFSETCLIPRGN *lpOffsetClipRgn = (const EMROFFSETCLIPRGN *)mr;
1443 OffsetClipRgn( hdc,
1444 (INT)lpOffsetClipRgn->ptlOffset.x,
1445 (INT)lpOffsetClipRgn->ptlOffset.y );
1446 FIXME("OffsetClipRgn\n");
1448 break;
1451 case EMR_EXCLUDECLIPRECT:
1453 const EMREXCLUDECLIPRECT *lpExcludeClipRect = (const EMREXCLUDECLIPRECT *)mr;
1455 ExcludeClipRect( hdc,
1456 lpExcludeClipRect->rclClip.left,
1457 lpExcludeClipRect->rclClip.top,
1458 lpExcludeClipRect->rclClip.right,
1459 lpExcludeClipRect->rclClip.bottom );
1460 FIXME("ExcludeClipRect\n");
1462 break;
1465 case EMR_SCALEVIEWPORTEXTEX:
1467 const EMRSCALEVIEWPORTEXTEX *lpScaleViewportExtEx = (const EMRSCALEVIEWPORTEXTEX *)mr;
1469 if ((info->state.mode != MM_ISOTROPIC) && (info->state.mode != MM_ANISOTROPIC))
1470 break;
1471 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1472 !lpScaleViewportExtEx->yNum || !lpScaleViewportExtEx->yDenom)
1473 break;
1474 info->state.vportExtX = MulDiv(info->state.vportExtX, lpScaleViewportExtEx->xNum,
1475 lpScaleViewportExtEx->xDenom);
1476 info->state.vportExtY = MulDiv(info->state.vportExtY, lpScaleViewportExtEx->yNum,
1477 lpScaleViewportExtEx->yDenom);
1478 if (info->state.vportExtX == 0) info->state.vportExtX = 1;
1479 if (info->state.vportExtY == 0) info->state.vportExtY = 1;
1480 if (info->state.mode == MM_ISOTROPIC)
1481 EMF_FixIsotropic(hdc, info);
1483 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1484 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1485 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1487 if (!IS_WIN9X())
1488 EMF_Update_MF_Xform(hdc, info);
1490 break;
1493 case EMR_SCALEWINDOWEXTEX:
1495 const EMRSCALEWINDOWEXTEX *lpScaleWindowExtEx = (const EMRSCALEWINDOWEXTEX *)mr;
1497 if ((info->state.mode != MM_ISOTROPIC) && (info->state.mode != MM_ANISOTROPIC))
1498 break;
1499 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1500 !lpScaleWindowExtEx->yNum || !lpScaleWindowExtEx->yDenom)
1501 break;
1502 info->state.wndExtX = MulDiv(info->state.wndExtX, lpScaleWindowExtEx->xNum,
1503 lpScaleWindowExtEx->xDenom);
1504 info->state.wndExtY = MulDiv(info->state.wndExtY, lpScaleWindowExtEx->yNum,
1505 lpScaleWindowExtEx->yDenom);
1506 if (info->state.wndExtX == 0) info->state.wndExtX = 1;
1507 if (info->state.wndExtY == 0) info->state.wndExtY = 1;
1508 if (info->state.mode == MM_ISOTROPIC)
1509 EMF_FixIsotropic(hdc, info);
1511 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1512 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1513 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1515 if (!IS_WIN9X())
1516 EMF_Update_MF_Xform(hdc, info);
1518 break;
1521 case EMR_MODIFYWORLDTRANSFORM:
1523 const EMRMODIFYWORLDTRANSFORM *lpModifyWorldTrans = (const EMRMODIFYWORLDTRANSFORM *)mr;
1525 switch(lpModifyWorldTrans->iMode) {
1526 case MWT_IDENTITY:
1527 info->state.world_transform.eM11 = info->state.world_transform.eM22 = 1;
1528 info->state.world_transform.eM12 = info->state.world_transform.eM21 = 0;
1529 info->state.world_transform.eDx = info->state.world_transform.eDy = 0;
1530 if (!IS_WIN9X())
1531 EMF_Update_MF_Xform(hdc, info);
1532 break;
1533 case MWT_LEFTMULTIPLY:
1534 CombineTransform(&info->state.world_transform, &lpModifyWorldTrans->xform,
1535 &info->state.world_transform);
1536 if (!IS_WIN9X())
1537 ModifyWorldTransform(hdc, &lpModifyWorldTrans->xform, MWT_LEFTMULTIPLY);
1538 break;
1539 case MWT_RIGHTMULTIPLY:
1540 CombineTransform(&info->state.world_transform, &info->state.world_transform,
1541 &lpModifyWorldTrans->xform);
1542 if (!IS_WIN9X())
1543 EMF_Update_MF_Xform(hdc, info);
1544 break;
1545 default:
1546 FIXME("Unknown imode %ld\n", lpModifyWorldTrans->iMode);
1547 break;
1549 break;
1552 case EMR_ANGLEARC:
1554 const EMRANGLEARC *lpAngleArc = (const EMRANGLEARC *)mr;
1556 AngleArc( hdc,
1557 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1558 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1559 lpAngleArc->eSweepAngle );
1561 break;
1564 case EMR_ROUNDRECT:
1566 const EMRROUNDRECT *lpRoundRect = (const EMRROUNDRECT *)mr;
1568 RoundRect( hdc,
1569 lpRoundRect->rclBox.left,
1570 lpRoundRect->rclBox.top,
1571 lpRoundRect->rclBox.right,
1572 lpRoundRect->rclBox.bottom,
1573 lpRoundRect->szlCorner.cx,
1574 lpRoundRect->szlCorner.cy );
1576 break;
1579 case EMR_ARC:
1581 const EMRARC *lpArc = (const EMRARC *)mr;
1583 Arc( hdc,
1584 (INT)lpArc->rclBox.left,
1585 (INT)lpArc->rclBox.top,
1586 (INT)lpArc->rclBox.right,
1587 (INT)lpArc->rclBox.bottom,
1588 (INT)lpArc->ptlStart.x,
1589 (INT)lpArc->ptlStart.y,
1590 (INT)lpArc->ptlEnd.x,
1591 (INT)lpArc->ptlEnd.y );
1593 break;
1596 case EMR_CHORD:
1598 const EMRCHORD *lpChord = (const EMRCHORD *)mr;
1600 Chord( hdc,
1601 (INT)lpChord->rclBox.left,
1602 (INT)lpChord->rclBox.top,
1603 (INT)lpChord->rclBox.right,
1604 (INT)lpChord->rclBox.bottom,
1605 (INT)lpChord->ptlStart.x,
1606 (INT)lpChord->ptlStart.y,
1607 (INT)lpChord->ptlEnd.x,
1608 (INT)lpChord->ptlEnd.y );
1610 break;
1613 case EMR_PIE:
1615 const EMRPIE *lpPie = (const EMRPIE *)mr;
1617 Pie( hdc,
1618 (INT)lpPie->rclBox.left,
1619 (INT)lpPie->rclBox.top,
1620 (INT)lpPie->rclBox.right,
1621 (INT)lpPie->rclBox.bottom,
1622 (INT)lpPie->ptlStart.x,
1623 (INT)lpPie->ptlStart.y,
1624 (INT)lpPie->ptlEnd.x,
1625 (INT)lpPie->ptlEnd.y );
1627 break;
1630 case EMR_ARCTO:
1632 const EMRARC *lpArcTo = (const EMRARC *)mr;
1634 ArcTo( hdc,
1635 (INT)lpArcTo->rclBox.left,
1636 (INT)lpArcTo->rclBox.top,
1637 (INT)lpArcTo->rclBox.right,
1638 (INT)lpArcTo->rclBox.bottom,
1639 (INT)lpArcTo->ptlStart.x,
1640 (INT)lpArcTo->ptlStart.y,
1641 (INT)lpArcTo->ptlEnd.x,
1642 (INT)lpArcTo->ptlEnd.y );
1644 break;
1647 case EMR_EXTFLOODFILL:
1649 const EMREXTFLOODFILL *lpExtFloodFill = (const EMREXTFLOODFILL *)mr;
1651 ExtFloodFill( hdc,
1652 (INT)lpExtFloodFill->ptlStart.x,
1653 (INT)lpExtFloodFill->ptlStart.y,
1654 lpExtFloodFill->crColor,
1655 (UINT)lpExtFloodFill->iMode );
1657 break;
1660 case EMR_POLYDRAW:
1662 const EMRPOLYDRAW *lpPolyDraw = (const EMRPOLYDRAW *)mr;
1664 /* NB abTypes array doesn't start at lpPolyDraw->abTypes. It's actually
1665 lpPolyDraw->aptl + lpPolyDraw->cptl. */
1666 PolyDraw( hdc,
1667 (const POINT*)lpPolyDraw->aptl,
1668 (BYTE*)(lpPolyDraw->aptl + lpPolyDraw->cptl),
1669 (INT)lpPolyDraw->cptl );
1671 break;
1674 case EMR_SETARCDIRECTION:
1676 const EMRSETARCDIRECTION *lpSetArcDirection = (const EMRSETARCDIRECTION *)mr;
1677 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1678 break;
1681 case EMR_SETMITERLIMIT:
1683 const EMRSETMITERLIMIT *lpSetMiterLimit = (const EMRSETMITERLIMIT *)mr;
1684 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1685 break;
1688 case EMR_BEGINPATH:
1690 BeginPath( hdc );
1691 break;
1694 case EMR_ENDPATH:
1696 EndPath( hdc );
1697 break;
1700 case EMR_CLOSEFIGURE:
1702 CloseFigure( hdc );
1703 break;
1706 case EMR_FILLPATH:
1708 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1709 FillPath( hdc );
1710 break;
1713 case EMR_STROKEANDFILLPATH:
1715 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1716 StrokeAndFillPath( hdc );
1717 break;
1720 case EMR_STROKEPATH:
1722 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1723 StrokePath( hdc );
1724 break;
1727 case EMR_FLATTENPATH:
1729 FlattenPath( hdc );
1730 break;
1733 case EMR_WIDENPATH:
1735 WidenPath( hdc );
1736 break;
1739 case EMR_SELECTCLIPPATH:
1741 const EMRSELECTCLIPPATH *lpSelectClipPath = (const EMRSELECTCLIPPATH *)mr;
1742 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1743 break;
1746 case EMR_ABORTPATH:
1748 AbortPath( hdc );
1749 break;
1752 case EMR_CREATECOLORSPACE:
1754 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1755 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1756 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1757 break;
1760 case EMR_SETCOLORSPACE:
1762 const EMRSETCOLORSPACE *lpSetColorSpace = (const EMRSETCOLORSPACE *)mr;
1763 SetColorSpace( hdc,
1764 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1765 break;
1768 case EMR_DELETECOLORSPACE:
1770 const EMRDELETECOLORSPACE *lpDeleteColorSpace = (const EMRDELETECOLORSPACE *)mr;
1771 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1772 break;
1775 case EMR_SETICMMODE:
1777 const EMRSETICMMODE *lpSetICMMode = (const EMRSETICMMODE *)mr;
1778 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1779 break;
1782 case EMR_PIXELFORMAT:
1784 INT iPixelFormat;
1785 const EMRPIXELFORMAT *lpPixelFormat = (const EMRPIXELFORMAT *)mr;
1787 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1788 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1790 break;
1793 case EMR_SETPALETTEENTRIES:
1795 const EMRSETPALETTEENTRIES *lpSetPaletteEntries = (const EMRSETPALETTEENTRIES *)mr;
1797 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1798 (UINT)lpSetPaletteEntries->iStart,
1799 (UINT)lpSetPaletteEntries->cEntries,
1800 lpSetPaletteEntries->aPalEntries );
1802 break;
1805 case EMR_RESIZEPALETTE:
1807 const EMRRESIZEPALETTE *lpResizePalette = (const EMRRESIZEPALETTE *)mr;
1809 NtGdiResizePalette( handletable->objectHandle[lpResizePalette->ihPal],
1810 lpResizePalette->cEntries );
1812 break;
1815 case EMR_CREATEDIBPATTERNBRUSHPT:
1817 const EMRCREATEDIBPATTERNBRUSHPT *lpCreate = (const EMRCREATEDIBPATTERNBRUSHPT *)mr;
1819 /* Check that offsets and data are contained within the record
1820 * (including checking for wrap-arounds).
1822 if ( lpCreate->offBmi + lpCreate->cbBmi > mr->nSize
1823 || lpCreate->offBits + lpCreate->cbBits > mr->nSize
1824 || lpCreate->offBmi + lpCreate->cbBmi < lpCreate->offBmi
1825 || lpCreate->offBits + lpCreate->cbBits < lpCreate->offBits )
1827 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1828 break;
1831 if (lpCreate->offBmi + lpCreate->cbBmi != lpCreate->offBits)
1833 ERR("Invalid data in EMR_CREATEDIBPATTERNBRUSHPT record\n");
1834 break;
1837 (handletable->objectHandle)[lpCreate->ihBrush] =
1838 CreateDIBPatternBrushPt( (const BYTE *)lpCreate + lpCreate->offBmi,
1839 (UINT)lpCreate->iUsage );
1840 break;
1843 case EMR_CREATEMONOBRUSH:
1845 const EMRCREATEMONOBRUSH *pCreateMonoBrush = (const EMRCREATEMONOBRUSH *)mr;
1846 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pCreateMonoBrush->offBmi);
1847 HBITMAP hBmp;
1849 /* Need to check if the bitmap is monochrome, and if the
1850 two colors are really black and white */
1851 if (pCreateMonoBrush->iUsage == DIB_PAL_INDICES || is_dib_monochrome(pbi))
1853 /* Top-down DIBs have a negative height */
1854 LONG height = pbi->bmiHeader.biHeight;
1856 hBmp = CreateBitmap(pbi->bmiHeader.biWidth, abs(height), 1, 1, NULL);
1857 SetDIBits(hdc, hBmp, 0, pbi->bmiHeader.biHeight,
1858 (const BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1860 else
1862 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1863 (const BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1866 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1868 /* CreatePatternBrush created a copy of the bitmap */
1869 DeleteObject(hBmp);
1870 break;
1873 case EMR_BITBLT:
1875 const EMRBITBLT *pBitBlt = (const EMRBITBLT *)mr;
1877 if(pBitBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1878 PatBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1879 pBitBlt->dwRop);
1880 } else { /* BitBlt */
1881 HDC hdcSrc = NtGdiCreateCompatibleDC( hdc );
1882 HBRUSH hBrush, hBrushOld;
1883 HBITMAP hBmp = 0, hBmpOld = 0;
1884 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pBitBlt->offBmiSrc);
1886 SetGraphicsMode(hdcSrc, GM_ADVANCED);
1887 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1889 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1890 hBrushOld = SelectObject(hdcSrc, hBrush);
1891 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1892 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1893 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1894 SelectObject(hdcSrc, hBrushOld);
1895 DeleteObject(hBrush);
1897 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1898 (const BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1899 hBmpOld = SelectObject(hdcSrc, hBmp);
1901 BitBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1902 hdcSrc, pBitBlt->xSrc, pBitBlt->ySrc, pBitBlt->dwRop);
1904 SelectObject(hdcSrc, hBmpOld);
1905 DeleteObject(hBmp);
1906 DeleteDC(hdcSrc);
1908 break;
1911 case EMR_STRETCHBLT:
1913 const EMRSTRETCHBLT *pStretchBlt = (const EMRSTRETCHBLT *)mr;
1915 TRACE("EMR_STRETCHBLT: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. rop %08lx offBitsSrc %ld\n",
1916 pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1917 pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1918 pStretchBlt->dwRop, pStretchBlt->offBitsSrc);
1920 if(pStretchBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1921 PatBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1922 pStretchBlt->dwRop);
1923 } else { /* StretchBlt */
1924 HDC hdcSrc = NtGdiCreateCompatibleDC( hdc );
1925 HBRUSH hBrush, hBrushOld;
1926 HBITMAP hBmp = 0, hBmpOld = 0;
1927 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pStretchBlt->offBmiSrc);
1929 SetGraphicsMode(hdcSrc, GM_ADVANCED);
1930 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1932 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1933 hBrushOld = SelectObject(hdcSrc, hBrush);
1934 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1935 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1936 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1937 SelectObject(hdcSrc, hBrushOld);
1938 DeleteObject(hBrush);
1940 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1941 (const BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1942 hBmpOld = SelectObject(hdcSrc, hBmp);
1944 StretchBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1945 hdcSrc, pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1946 pStretchBlt->dwRop);
1948 SelectObject(hdcSrc, hBmpOld);
1949 DeleteObject(hBmp);
1950 DeleteDC(hdcSrc);
1952 break;
1955 case EMR_ALPHABLEND:
1957 const EMRALPHABLEND *pAlphaBlend = (const EMRALPHABLEND *)mr;
1959 TRACE("EMR_ALPHABLEND: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. blendfn %08lx offBitsSrc %ld\n",
1960 pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1961 pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1962 pAlphaBlend->dwRop, pAlphaBlend->offBitsSrc);
1964 if(pAlphaBlend->offBmiSrc == 0) {
1965 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1966 } else {
1967 HDC hdcSrc = NtGdiCreateCompatibleDC( hdc );
1968 HBITMAP hBmp = 0, hBmpOld = 0;
1969 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pAlphaBlend->offBmiSrc);
1970 void *bits;
1972 SetGraphicsMode(hdcSrc, GM_ADVANCED);
1973 SetWorldTransform(hdcSrc, &pAlphaBlend->xformSrc);
1975 hBmp = CreateDIBSection(hdc, pbi, pAlphaBlend->iUsageSrc, &bits, NULL, 0);
1976 memcpy(bits, (const BYTE *)mr + pAlphaBlend->offBitsSrc, pAlphaBlend->cbBitsSrc);
1977 hBmpOld = SelectObject(hdcSrc, hBmp);
1979 GdiAlphaBlend(hdc, pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1980 hdcSrc, pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1981 *(BLENDFUNCTION *)&pAlphaBlend->dwRop);
1983 SelectObject(hdcSrc, hBmpOld);
1984 DeleteObject(hBmp);
1985 DeleteDC(hdcSrc);
1987 break;
1990 case EMR_MASKBLT:
1992 const EMRMASKBLT *pMaskBlt = (const EMRMASKBLT *)mr;
1993 HDC hdcSrc = NtGdiCreateCompatibleDC( hdc );
1994 HBRUSH hBrush, hBrushOld;
1995 HBITMAP hBmp, hBmpOld, hBmpMask;
1996 const BITMAPINFO *pbi;
1998 SetGraphicsMode(hdcSrc, GM_ADVANCED);
1999 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
2001 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
2002 hBrushOld = SelectObject(hdcSrc, hBrush);
2003 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
2004 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
2005 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
2006 SelectObject(hdcSrc, hBrushOld);
2007 DeleteObject(hBrush);
2009 pbi = (const BITMAPINFO *)((const BYTE *)mr + pMaskBlt->offBmiMask);
2010 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
2011 1, 1, NULL);
2012 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
2013 (const BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
2015 pbi = (const BITMAPINFO *)((const BYTE *)mr + pMaskBlt->offBmiSrc);
2016 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
2017 (const BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
2018 hBmpOld = SelectObject(hdcSrc, hBmp);
2019 MaskBlt(hdc,
2020 pMaskBlt->xDest,
2021 pMaskBlt->yDest,
2022 pMaskBlt->cxDest,
2023 pMaskBlt->cyDest,
2024 hdcSrc,
2025 pMaskBlt->xSrc,
2026 pMaskBlt->ySrc,
2027 hBmpMask,
2028 pMaskBlt->xMask,
2029 pMaskBlt->yMask,
2030 pMaskBlt->dwRop);
2031 SelectObject(hdcSrc, hBmpOld);
2032 DeleteObject(hBmp);
2033 DeleteObject(hBmpMask);
2034 DeleteDC(hdcSrc);
2035 break;
2038 case EMR_PLGBLT:
2040 const EMRPLGBLT *pPlgBlt = (const EMRPLGBLT *)mr;
2041 HDC hdcSrc = NtGdiCreateCompatibleDC( hdc );
2042 HBRUSH hBrush, hBrushOld;
2043 HBITMAP hBmp, hBmpOld, hBmpMask;
2044 const BITMAPINFO *pbi;
2045 POINT pts[3];
2047 SetGraphicsMode(hdcSrc, GM_ADVANCED);
2048 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
2050 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
2051 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
2052 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
2054 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
2055 hBrushOld = SelectObject(hdcSrc, hBrush);
2056 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
2057 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
2058 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
2059 SelectObject(hdcSrc, hBrushOld);
2060 DeleteObject(hBrush);
2062 pbi = (const BITMAPINFO *)((const BYTE *)mr + pPlgBlt->offBmiMask);
2063 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
2064 1, 1, NULL);
2065 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
2066 (const BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
2068 pbi = (const BITMAPINFO *)((const BYTE *)mr + pPlgBlt->offBmiSrc);
2069 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
2070 (const BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
2071 hBmpOld = SelectObject(hdcSrc, hBmp);
2072 PlgBlt(hdc,
2073 pts,
2074 hdcSrc,
2075 pPlgBlt->xSrc,
2076 pPlgBlt->ySrc,
2077 pPlgBlt->cxSrc,
2078 pPlgBlt->cySrc,
2079 hBmpMask,
2080 pPlgBlt->xMask,
2081 pPlgBlt->yMask);
2082 SelectObject(hdcSrc, hBmpOld);
2083 DeleteObject(hBmp);
2084 DeleteObject(hBmpMask);
2085 DeleteDC(hdcSrc);
2086 break;
2089 case EMR_SETDIBITSTODEVICE:
2091 const EMRSETDIBITSTODEVICE *pSetDIBitsToDevice = (const EMRSETDIBITSTODEVICE *)mr;
2093 SetDIBitsToDevice(hdc,
2094 pSetDIBitsToDevice->xDest,
2095 pSetDIBitsToDevice->yDest,
2096 pSetDIBitsToDevice->cxSrc,
2097 pSetDIBitsToDevice->cySrc,
2098 pSetDIBitsToDevice->xSrc,
2099 pSetDIBitsToDevice->ySrc,
2100 pSetDIBitsToDevice->iStartScan,
2101 pSetDIBitsToDevice->cScans,
2102 (const BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
2103 (const BITMAPINFO *)((const BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
2104 pSetDIBitsToDevice->iUsageSrc);
2105 break;
2108 case EMR_POLYTEXTOUTA:
2110 const EMRPOLYTEXTOUTA *pPolyTextOutA = (const EMRPOLYTEXTOUTA *)mr;
2111 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
2112 LONG i;
2113 XFORM xform, xformOld;
2114 int gModeOld;
2116 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
2117 GetWorldTransform(hdc, &xformOld);
2119 xform.eM11 = pPolyTextOutA->exScale;
2120 xform.eM12 = 0.0;
2121 xform.eM21 = 0.0;
2122 xform.eM22 = pPolyTextOutA->eyScale;
2123 xform.eDx = 0.0;
2124 xform.eDy = 0.0;
2125 SetWorldTransform(hdc, &xform);
2127 /* Set up POLYTEXTA structures */
2128 for(i = 0; i < pPolyTextOutA->cStrings; i++)
2130 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
2131 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
2132 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
2133 polytextA[i].lpstr = (LPCSTR)((const BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
2134 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
2135 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
2136 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
2137 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
2138 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
2139 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
2141 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
2142 HeapFree(GetProcessHeap(), 0, polytextA);
2144 SetWorldTransform(hdc, &xformOld);
2145 SetGraphicsMode(hdc, gModeOld);
2146 break;
2149 case EMR_POLYTEXTOUTW:
2151 const EMRPOLYTEXTOUTW *pPolyTextOutW = (const EMRPOLYTEXTOUTW *)mr;
2152 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
2153 LONG i;
2154 XFORM xform, xformOld;
2155 int gModeOld;
2157 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
2158 GetWorldTransform(hdc, &xformOld);
2160 xform.eM11 = pPolyTextOutW->exScale;
2161 xform.eM12 = 0.0;
2162 xform.eM21 = 0.0;
2163 xform.eM22 = pPolyTextOutW->eyScale;
2164 xform.eDx = 0.0;
2165 xform.eDy = 0.0;
2166 SetWorldTransform(hdc, &xform);
2168 /* Set up POLYTEXTW structures */
2169 for(i = 0; i < pPolyTextOutW->cStrings; i++)
2171 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
2172 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
2173 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
2174 polytextW[i].lpstr = (LPCWSTR)((const BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
2175 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
2176 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
2177 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
2178 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
2179 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
2180 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
2182 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
2183 HeapFree(GetProcessHeap(), 0, polytextW);
2185 SetWorldTransform(hdc, &xformOld);
2186 SetGraphicsMode(hdc, gModeOld);
2187 break;
2190 case EMR_FILLRGN:
2192 const EMRFILLRGN *pFillRgn = (const EMRFILLRGN *)mr;
2193 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (const RGNDATA *)pFillRgn->RgnData);
2194 FillRgn(hdc, hRgn, get_object_handle(handletable, pFillRgn->ihBrush));
2195 DeleteObject(hRgn);
2196 break;
2199 case EMR_FRAMERGN:
2201 const EMRFRAMERGN *pFrameRgn = (const EMRFRAMERGN *)mr;
2202 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (const RGNDATA *)pFrameRgn->RgnData);
2203 FrameRgn(hdc, hRgn, get_object_handle(handletable, pFrameRgn->ihBrush),
2204 pFrameRgn->szlStroke.cx, pFrameRgn->szlStroke.cy);
2205 DeleteObject(hRgn);
2206 break;
2209 case EMR_INVERTRGN:
2211 const EMRINVERTRGN *pInvertRgn = (const EMRINVERTRGN *)mr;
2212 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (const RGNDATA *)pInvertRgn->RgnData);
2213 InvertRgn(hdc, hRgn);
2214 DeleteObject(hRgn);
2215 break;
2218 case EMR_PAINTRGN:
2220 const EMRPAINTRGN *pPaintRgn = (const EMRPAINTRGN *)mr;
2221 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (const RGNDATA *)pPaintRgn->RgnData);
2222 PaintRgn(hdc, hRgn);
2223 DeleteObject(hRgn);
2224 break;
2227 case EMR_SETTEXTJUSTIFICATION:
2229 const EMRSETTEXTJUSTIFICATION *pSetTextJust = (const EMRSETTEXTJUSTIFICATION *)mr;
2230 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
2231 break;
2234 case EMR_SETLAYOUT:
2236 const EMRSETLAYOUT *pSetLayout = (const EMRSETLAYOUT *)mr;
2237 SetLayout(hdc, pSetLayout->iMode);
2238 break;
2241 case EMR_TRANSPARENTBLT:
2243 const EMRTRANSPARENTBLT *pTransparentBlt = (const EMRTRANSPARENTBLT *)mr;
2245 TRACE("EMR_TRANSPARENTBLT: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld color %08lx offBitsSrc %ld\n",
2246 pTransparentBlt->xSrc, pTransparentBlt->ySrc, pTransparentBlt->cxSrc,
2247 pTransparentBlt->cySrc, pTransparentBlt->xDest, pTransparentBlt->yDest,
2248 pTransparentBlt->cxDest, pTransparentBlt->cyDest,
2249 pTransparentBlt->dwRop, pTransparentBlt->offBitsSrc);
2251 if(pTransparentBlt->offBmiSrc == 0) {
2252 FIXME("EMR_TRANSPARENTBLT: offBmiSrc == 0\n");
2253 } else {
2254 HDC hdcSrc = NtGdiCreateCompatibleDC( hdc );
2255 HBRUSH hBrush, hBrushOld;
2256 HBITMAP hBmp = 0, hBmpOld = 0;
2257 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pTransparentBlt->offBmiSrc);
2259 SetGraphicsMode(hdcSrc, GM_ADVANCED);
2260 SetWorldTransform(hdcSrc, &pTransparentBlt->xformSrc);
2262 hBrush = CreateSolidBrush(pTransparentBlt->crBkColorSrc);
2263 hBrushOld = SelectObject(hdcSrc, hBrush);
2264 PatBlt(hdcSrc, pTransparentBlt->rclBounds.left, pTransparentBlt->rclBounds.top,
2265 pTransparentBlt->rclBounds.right - pTransparentBlt->rclBounds.left,
2266 pTransparentBlt->rclBounds.bottom - pTransparentBlt->rclBounds.top, PATCOPY);
2267 SelectObject(hdcSrc, hBrushOld);
2268 DeleteObject(hBrush);
2270 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
2271 (const BYTE *)mr + pTransparentBlt->offBitsSrc,
2272 pbi, pTransparentBlt->iUsageSrc);
2273 hBmpOld = SelectObject(hdcSrc, hBmp);
2275 GdiTransparentBlt(hdc, pTransparentBlt->xDest, pTransparentBlt->yDest,
2276 pTransparentBlt->cxDest, pTransparentBlt->cyDest,
2277 hdcSrc, pTransparentBlt->xSrc, pTransparentBlt->ySrc,
2278 pTransparentBlt->cxSrc, pTransparentBlt->cySrc,
2279 pTransparentBlt->dwRop);
2281 SelectObject(hdcSrc, hBmpOld);
2282 DeleteObject(hBmp);
2283 DeleteDC(hdcSrc);
2285 break;
2288 case EMR_GRADIENTFILL:
2290 EMRGRADIENTFILL *grad = (EMRGRADIENTFILL *)mr;
2291 GdiGradientFill( hdc, grad->Ver, grad->nVer, grad->Ver + grad->nVer,
2292 grad->nTri, grad->ulMode );
2293 break;
2296 case EMR_GLSRECORD:
2297 case EMR_GLSBOUNDEDRECORD:
2298 case EMR_DRAWESCAPE:
2299 case EMR_EXTESCAPE:
2300 case EMR_STARTDOC:
2301 case EMR_SMALLTEXTOUT:
2302 case EMR_FORCEUFIMAPPING:
2303 case EMR_NAMEDESCAPE:
2304 case EMR_COLORCORRECTPALETTE:
2305 case EMR_SETICMPROFILEA:
2306 case EMR_SETICMPROFILEW:
2307 case EMR_SETLINKEDUFI:
2308 case EMR_COLORMATCHTOTARGETW:
2309 case EMR_CREATECOLORSPACEW:
2311 default:
2312 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2313 record then ignore and return TRUE. */
2314 FIXME("type %d is unimplemented\n", type);
2315 break;
2317 tmprc.left = tmprc.top = 0;
2318 tmprc.right = tmprc.bottom = 1000;
2319 LPtoDP(hdc, (POINT*)&tmprc, 2);
2320 TRACE("L:0,0 - 1000,1000 -> D:%s\n", wine_dbgstr_rect(&tmprc));
2322 return TRUE;
2326 /*****************************************************************************
2328 * EnumEnhMetaFile (GDI32.@)
2330 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2331 * for each
2332 * record. Returns when either every record has been used or
2333 * when _EnhMetaFunc_ returns FALSE.
2336 * RETURNS
2337 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2338 * returns FALSE.
2340 * BUGS
2341 * Ignores rect.
2343 * NOTES
2344 * This function behaves differently in Win9x and WinNT.
2346 * In WinNT, the DC's world transform is updated as the EMF changes
2347 * the Window/Viewport Extent and Origin or its world transform.
2348 * The actual Window/Viewport Extent and Origin are left untouched.
2350 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2351 * updates the scaling itself but only just before a record that
2352 * writes anything to the DC.
2354 * I'm not sure where the data (enum_emh_data) is stored in either
2355 * version. For this implementation, it is stored before the handle
2356 * table, but it could be stored in the DC, in the EMF handle or in
2357 * TLS.
2358 * MJM 5 Oct 2002
2360 BOOL WINAPI EnumEnhMetaFile(
2361 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
2362 HENHMETAFILE hmf, /* [in] EMF to walk */
2363 ENHMFENUMPROC callback, /* [in] callback function */
2364 LPVOID data, /* [in] optional data for callback function */
2365 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
2368 BOOL ret;
2369 ENHMETAHEADER *emh;
2370 ENHMETARECORD *emr;
2371 DWORD offset;
2372 UINT i;
2373 HANDLETABLE *ht;
2374 INT savedMode = 0;
2375 XFORM savedXform;
2376 HPEN hPen = NULL;
2377 HBRUSH hBrush = NULL;
2378 HFONT hFont = NULL;
2379 HRGN hRgn = NULL;
2380 enum_emh_data *info;
2381 SIZE vp_size, win_size;
2382 POINT vp_org, win_org;
2383 INT mapMode = MM_TEXT, old_align = 0, old_rop2 = 0, old_arcdir = 0, old_polyfill = 0, old_stretchblt = 0;
2384 COLORREF old_text_color = 0, old_bk_color = 0;
2386 if(!lpRect && hdc)
2388 SetLastError(ERROR_INVALID_PARAMETER);
2389 return FALSE;
2392 emh = EMF_GetEnhMetaHeader(hmf);
2393 if(!emh) {
2394 SetLastError(ERROR_INVALID_HANDLE);
2395 return FALSE;
2398 info = HeapAlloc( GetProcessHeap(), 0,
2399 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
2400 if(!info)
2402 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2403 return FALSE;
2405 info->state.mode = MM_TEXT;
2406 info->state.wndOrgX = 0;
2407 info->state.wndOrgY = 0;
2408 info->state.wndExtX = 1;
2409 info->state.wndExtY = 1;
2410 info->state.vportOrgX = 0;
2411 info->state.vportOrgY = 0;
2412 info->state.vportExtX = 1;
2413 info->state.vportExtY = 1;
2414 info->state.world_transform.eM11 = info->state.world_transform.eM22 = 1;
2415 info->state.world_transform.eM12 = info->state.world_transform.eM21 = 0;
2416 info->state.world_transform.eDx = info->state.world_transform.eDy = 0;
2418 info->state.next = NULL;
2419 info->save_level = 0;
2420 info->saved_state = NULL;
2421 info->init_transform = info->state.world_transform;
2423 ht = (HANDLETABLE*) &info[1];
2424 ht->objectHandle[0] = hmf;
2425 for(i = 1; i < emh->nHandles; i++)
2426 ht->objectHandle[i] = NULL;
2428 if (hdc && !is_meta_dc( hdc ))
2430 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
2431 GetWorldTransform(hdc, &savedXform);
2432 GetViewportExtEx(hdc, &vp_size);
2433 GetWindowExtEx(hdc, &win_size);
2434 GetViewportOrgEx(hdc, &vp_org);
2435 GetWindowOrgEx(hdc, &win_org);
2436 mapMode = GetMapMode(hdc);
2438 /* save DC */
2439 hPen = GetCurrentObject(hdc, OBJ_PEN);
2440 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
2441 hFont = GetCurrentObject(hdc, OBJ_FONT);
2443 hRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
2444 if (!GetClipRgn(hdc, hRgn))
2446 DeleteObject(hRgn);
2447 hRgn = 0;
2450 old_text_color = SetTextColor(hdc, RGB(0,0,0));
2451 old_bk_color = SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
2452 old_align = SetTextAlign(hdc, 0);
2453 old_rop2 = SetROP2(hdc, R2_COPYPEN);
2454 old_arcdir = SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
2455 old_polyfill = SetPolyFillMode(hdc, ALTERNATE);
2456 old_stretchblt = SetStretchBltMode(hdc, BLACKONWHITE);
2458 if (!IS_WIN9X())
2460 /* WinNT combines the vp/win ext/org info into a transform */
2461 double xscale, yscale;
2462 xscale = (double)vp_size.cx / (double)win_size.cx;
2463 yscale = (double)vp_size.cy / (double)win_size.cy;
2464 info->init_transform.eM11 = xscale;
2465 info->init_transform.eM12 = 0.0;
2466 info->init_transform.eM21 = 0.0;
2467 info->init_transform.eM22 = yscale;
2468 info->init_transform.eDx = (double)vp_org.x - xscale * (double)win_org.x;
2469 info->init_transform.eDy = (double)vp_org.y - yscale * (double)win_org.y;
2471 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
2474 if ( lpRect && WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
2476 double xSrcPixSize, ySrcPixSize, xscale, yscale;
2477 XFORM xform;
2479 TRACE("rect: %s. rclFrame: (%ld,%ld)-(%ld,%ld)\n", wine_dbgstr_rect(lpRect),
2480 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
2481 emh->rclFrame.bottom);
2483 xSrcPixSize = (double) emh->szlMillimeters.cx / emh->szlDevice.cx;
2484 ySrcPixSize = (double) emh->szlMillimeters.cy / emh->szlDevice.cy;
2485 xscale = (double) WIDTH(*lpRect) * 100.0 /
2486 WIDTH(emh->rclFrame) * xSrcPixSize;
2487 yscale = (double) HEIGHT(*lpRect) * 100.0 /
2488 HEIGHT(emh->rclFrame) * ySrcPixSize;
2489 TRACE("xscale = %f, yscale = %f\n", xscale, yscale);
2491 xform.eM11 = xscale;
2492 xform.eM12 = 0;
2493 xform.eM21 = 0;
2494 xform.eM22 = yscale;
2495 xform.eDx = (double) lpRect->left - (double) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
2496 xform.eDy = (double) lpRect->top - (double) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
2498 CombineTransform(&info->init_transform, &xform, &info->init_transform);
2501 /* WinNT resets the current vp/win org/ext */
2502 if (!IS_WIN9X())
2504 SetMapMode(hdc, MM_TEXT);
2505 SetWindowOrgEx(hdc, 0, 0, NULL);
2506 SetViewportOrgEx(hdc, 0, 0, NULL);
2507 EMF_Update_MF_Xform(hdc, info);
2511 ret = TRUE;
2512 offset = 0;
2513 while(ret && offset < emh->nBytes)
2515 emr = (ENHMETARECORD *)((char *)emh + offset);
2517 if (offset + 8 > emh->nBytes ||
2518 offset > offset + emr->nSize ||
2519 offset + emr->nSize > emh->nBytes)
2521 WARN("record truncated\n");
2522 break;
2525 /* In Win9x mode we update the xform if the record will produce output */
2526 if (hdc && IS_WIN9X() && emr_produces_output(emr->iType))
2527 EMF_Update_MF_Xform(hdc, info);
2529 TRACE("Calling EnumFunc with record %s, size %ld\n", get_emr_name(emr->iType), emr->nSize);
2530 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2531 offset += emr->nSize;
2534 if (hdc && !is_meta_dc( hdc ))
2536 SetStretchBltMode(hdc, old_stretchblt);
2537 SetPolyFillMode(hdc, old_polyfill);
2538 SetArcDirection(hdc, old_arcdir);
2539 SetROP2(hdc, old_rop2);
2540 SetTextAlign(hdc, old_align);
2541 SetBkColor(hdc, old_bk_color);
2542 SetTextColor(hdc, old_text_color);
2544 /* restore DC */
2545 SelectObject(hdc, hBrush);
2546 SelectObject(hdc, hPen);
2547 SelectObject(hdc, hFont);
2548 ExtSelectClipRgn(hdc, hRgn, RGN_COPY);
2549 DeleteObject(hRgn);
2551 SetWorldTransform(hdc, &savedXform);
2552 if (savedMode)
2553 SetGraphicsMode(hdc, savedMode);
2554 SetMapMode(hdc, mapMode);
2555 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2556 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2557 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2558 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2561 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2562 if( (ht->objectHandle)[i] )
2563 DeleteObject( (ht->objectHandle)[i] );
2565 while (info->saved_state)
2567 EMF_dc_state *state = info->saved_state;
2568 info->saved_state = info->saved_state->next;
2569 HeapFree( GetProcessHeap(), 0, state );
2571 HeapFree( GetProcessHeap(), 0, info );
2572 return ret;
2575 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2576 const ENHMETARECORD *emr,
2577 INT handles, LPARAM data)
2579 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2582 /**************************************************************************
2583 * PlayEnhMetaFile (GDI32.@)
2585 * Renders an enhanced metafile into a specified rectangle *lpRect
2586 * in device context hdc.
2588 * RETURNS
2589 * Success: TRUE
2590 * Failure: FALSE
2592 BOOL WINAPI PlayEnhMetaFile(
2593 HDC hdc, /* [in] DC to render into */
2594 HENHMETAFILE hmf, /* [in] metafile to render */
2595 const RECT *lpRect /* [in] rectangle to place metafile inside */
2598 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2599 lpRect);
2602 /*****************************************************************************
2603 * DeleteEnhMetaFile (GDI32.@)
2605 * Deletes an enhanced metafile and frees the associated storage.
2607 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2609 return EMF_Delete_HENHMETAFILE( hmf );
2612 /*****************************************************************************
2613 * CopyEnhMetaFileA (GDI32.@)
2615 * Duplicate an enhanced metafile.
2619 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2620 HENHMETAFILE hmfSrc,
2621 LPCSTR file)
2623 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2624 HENHMETAFILE hmfDst;
2626 if(!emrSrc) return FALSE;
2627 if (!file) {
2628 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2629 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2630 hmfDst = EMF_Create_HENHMETAFILE( emrDst, emrSrc->nBytes, FALSE );
2631 if (!hmfDst)
2632 HeapFree( GetProcessHeap(), 0, emrDst );
2633 } else {
2634 HANDLE hFile;
2635 DWORD w;
2636 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2637 NULL, CREATE_ALWAYS, 0, 0);
2638 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2639 CloseHandle( hFile );
2640 /* Reopen file for reading only, so that apps can share
2641 read access to the file while hmf is still valid */
2642 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2643 NULL, OPEN_EXISTING, 0, 0);
2644 if(hFile == INVALID_HANDLE_VALUE) {
2645 ERR("Can't reopen emf for reading\n");
2646 return 0;
2648 hmfDst = EMF_GetEnhMetaFile( hFile );
2649 CloseHandle( hFile );
2651 return hmfDst;
2654 /*****************************************************************************
2655 * CopyEnhMetaFileW (GDI32.@)
2657 * See CopyEnhMetaFileA.
2661 HENHMETAFILE WINAPI CopyEnhMetaFileW(
2662 HENHMETAFILE hmfSrc,
2663 LPCWSTR file)
2665 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2666 HENHMETAFILE hmfDst;
2668 if(!emrSrc) return FALSE;
2669 if (!file) {
2670 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2671 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2672 hmfDst = EMF_Create_HENHMETAFILE( emrDst, emrSrc->nBytes, FALSE );
2673 if (!hmfDst)
2674 HeapFree( GetProcessHeap(), 0, emrDst );
2675 } else {
2676 HANDLE hFile;
2677 DWORD w;
2678 hFile = CreateFileW( file, GENERIC_WRITE | GENERIC_READ, 0,
2679 NULL, CREATE_ALWAYS, 0, 0);
2680 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2681 CloseHandle( hFile );
2682 /* Reopen file for reading only, so that apps can share
2683 read access to the file while hmf is still valid */
2684 hFile = CreateFileW( file, GENERIC_READ, FILE_SHARE_READ,
2685 NULL, OPEN_EXISTING, 0, 0);
2686 if(hFile == INVALID_HANDLE_VALUE) {
2687 ERR("Can't reopen emf for reading\n");
2688 return 0;
2690 hmfDst = EMF_GetEnhMetaFile( hFile );
2691 CloseHandle( hFile );
2693 return hmfDst;
2697 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2698 typedef struct tagEMF_PaletteCopy
2700 UINT cEntries;
2701 LPPALETTEENTRY lpPe;
2702 } EMF_PaletteCopy;
2704 /***************************************************************
2705 * Find the EMR_EOF record and then use it to find the
2706 * palette entries for this enhanced metafile.
2707 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2708 * which contains the max number of elements to copy and where
2709 * to copy them to.
2711 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2713 static INT CALLBACK cbEnhPaletteCopy( HDC a,
2714 HANDLETABLE *b,
2715 const ENHMETARECORD *lpEMR,
2716 INT c,
2717 LPARAM lpData )
2720 if ( lpEMR->iType == EMR_EOF )
2722 const EMREOF *lpEof = (const EMREOF *)lpEMR;
2723 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2724 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2726 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
2728 memcpy( info->lpPe, (LPCSTR)lpEof + lpEof->offPalEntries,
2729 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2731 /* Update the passed data as a return code */
2732 info->lpPe = NULL; /* Palettes were copied! */
2733 info->cEntries = dwNumPalToCopy;
2735 return FALSE; /* That's all we need */
2738 return TRUE;
2741 /*****************************************************************************
2742 * GetEnhMetaFilePaletteEntries (GDI32.@)
2744 * Copy the palette and report size
2746 * BUGS: Error codes (SetLastError) are not set on failures
2748 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2749 UINT cEntries,
2750 LPPALETTEENTRY lpPe )
2752 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2753 EMF_PaletteCopy infoForCallBack;
2755 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2757 if (!enhHeader) return 0;
2759 /* First check if there are any palettes associated with
2760 this metafile. */
2761 if ( enhHeader->nPalEntries == 0 ) return 0;
2763 /* Is the user requesting the number of palettes? */
2764 if ( lpPe == NULL ) return enhHeader->nPalEntries;
2766 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2767 infoForCallBack.cEntries = cEntries;
2768 infoForCallBack.lpPe = lpPe;
2770 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2771 &infoForCallBack, 0 ) )
2772 return GDI_ERROR;
2774 /* Verify that the callback executed correctly */
2775 if ( infoForCallBack.lpPe != NULL )
2777 /* Callback proc had error! */
2778 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2779 return GDI_ERROR;
2782 return infoForCallBack.cEntries;
2785 /******************************************************************
2786 * extract_emf_from_comment
2788 * If the WMF was created by GetWinMetaFileBits, then extract the
2789 * original EMF that is stored in MFCOMMENT chunks.
2791 static HENHMETAFILE extract_emf_from_comment( const BYTE *buf, UINT mf_size )
2793 METAHEADER *mh = (METAHEADER *)buf;
2794 METARECORD *mr;
2795 emf_in_wmf_comment *chunk;
2796 WORD checksum = 0;
2797 DWORD size = 0, remaining, chunks;
2798 BYTE *emf_bits = NULL, *ptr;
2799 UINT offset;
2800 HENHMETAFILE emf = NULL;
2802 if (mf_size < sizeof(*mh)) return NULL;
2804 for (offset = mh->mtHeaderSize * 2; offset < mf_size; offset += (mr->rdSize * 2))
2806 mr = (METARECORD *)((char *)mh + offset);
2807 chunk = (emf_in_wmf_comment *)(mr->rdParm + 2);
2809 if (mr->rdFunction != META_ESCAPE || mr->rdParm[0] != MFCOMMENT) goto done;
2810 if (chunk->comment_id != WMFC_MAGIC) goto done;
2812 if (!emf_bits)
2814 size = remaining = chunk->emf_size;
2815 chunks = chunk->num_chunks;
2816 emf_bits = ptr = HeapAlloc( GetProcessHeap(), 0, size );
2817 if (!emf_bits) goto done;
2819 if (chunk->chunk_size > remaining) goto done;
2820 remaining -= chunk->chunk_size;
2821 if (chunk->remaining_size != remaining) goto done;
2822 memcpy( ptr, chunk->emf_data, chunk->chunk_size );
2823 ptr += chunk->chunk_size;
2824 if (--chunks == 0) break;
2827 for (offset = 0; offset < mf_size / 2; offset++)
2828 checksum += *((WORD *)buf + offset);
2829 if (checksum) goto done;
2831 emf = SetEnhMetaFileBits( size, emf_bits );
2833 done:
2834 HeapFree( GetProcessHeap(), 0, emf_bits );
2835 return emf;
2838 typedef struct wmf_in_emf_comment
2840 DWORD ident;
2841 DWORD iComment;
2842 DWORD nVersion;
2843 DWORD nChecksum;
2844 DWORD fFlags;
2845 DWORD cbWinMetaFile;
2846 } wmf_in_emf_comment;
2848 /******************************************************************
2849 * SetWinMetaFileBits (GDI32.@)
2851 * Translate from old style to new style.
2854 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer, const BYTE *lpbBuffer, HDC hdcRef,
2855 const METAFILEPICT *lpmfp)
2857 HMETAFILE hmf = NULL;
2858 HENHMETAFILE ret = NULL;
2859 HDC hdc = NULL, hdcdisp = NULL;
2860 RECT rc, *prcFrame = NULL;
2861 LONG mm, xExt, yExt;
2862 INT horzsize, vertsize, horzres, vertres;
2864 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2866 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2867 if(!hmf)
2869 WARN("SetMetaFileBitsEx failed\n");
2870 return NULL;
2873 ret = extract_emf_from_comment( lpbBuffer, cbBuffer );
2874 if (ret) return ret;
2876 if(!hdcRef)
2877 hdcRef = hdcdisp = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
2879 if (lpmfp)
2881 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2883 mm = lpmfp->mm;
2884 xExt = lpmfp->xExt;
2885 yExt = lpmfp->yExt;
2887 else
2889 TRACE("lpmfp == NULL\n");
2891 /* Use the whole device surface */
2892 mm = MM_ANISOTROPIC;
2893 xExt = 0;
2894 yExt = 0;
2897 if (mm == MM_ISOTROPIC || mm == MM_ANISOTROPIC)
2899 if (xExt < 0 || yExt < 0)
2901 /* Use the whole device surface */
2902 xExt = 0;
2903 yExt = 0;
2906 /* Use the x and y extents as the frame box */
2907 if (xExt && yExt)
2909 rc.left = rc.top = 0;
2910 rc.right = xExt;
2911 rc.bottom = yExt;
2912 prcFrame = &rc;
2916 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL)))
2918 ERR("CreateEnhMetaFile failed\n");
2919 goto end;
2923 * Write the original METAFILE into the enhanced metafile.
2924 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2926 if (mm != MM_TEXT)
2928 wmf_in_emf_comment *mfcomment;
2929 UINT mfcomment_size;
2931 mfcomment_size = sizeof (*mfcomment) + cbBuffer;
2932 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2933 if (mfcomment)
2935 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2936 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2937 mfcomment->nVersion = 0x00000300;
2938 mfcomment->nChecksum = 0; /* FIXME */
2939 mfcomment->fFlags = 0;
2940 mfcomment->cbWinMetaFile = cbBuffer;
2941 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2942 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2943 HeapFree(GetProcessHeap(), 0, mfcomment);
2945 SetMapMode(hdc, mm);
2949 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2950 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2951 horzres = GetDeviceCaps(hdcRef, HORZRES);
2952 vertres = GetDeviceCaps(hdcRef, VERTRES);
2954 if (!xExt || !yExt)
2956 /* Use the whole device surface */
2957 xExt = horzres;
2958 yExt = vertres;
2960 else
2962 xExt = MulDiv(xExt, horzres, 100 * horzsize);
2963 yExt = MulDiv(yExt, vertres, 100 * vertsize);
2966 /* set the initial viewport:window ratio as 1:1 */
2967 SetViewportExtEx(hdc, xExt, yExt, NULL);
2968 SetWindowExtEx(hdc, xExt, yExt, NULL);
2970 PlayMetaFile(hdc, hmf);
2972 ret = CloseEnhMetaFile(hdc);
2973 end:
2974 if (hdcdisp) DeleteDC(hdcdisp);
2975 DeleteMetaFile(hmf);
2976 return ret;