2 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
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
22 * The enhanced format consists of the following elements:
25 * A table of handles to GDI objects
26 * An array of metafile records
30 * The standard format consists of a header and an array of metafile records.
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 };
64 BOOL on_disk
; /* true if metafile is on disk */
67 static const struct emr_name
{
80 X(EMR_SETWINDOWEXTEX
),
81 X(EMR_SETWINDOWORGEX
),
82 X(EMR_SETVIEWPORTEXTEX
),
83 X(EMR_SETVIEWPORTORGEX
),
87 X(EMR_SETMAPPERFLAGS
),
90 X(EMR_SETPOLYFILLMODE
),
92 X(EMR_SETSTRETCHBLTMODE
),
94 X(EMR_SETCOLORADJUSTMENT
),
100 X(EMR_EXCLUDECLIPRECT
),
101 X(EMR_INTERSECTCLIPRECT
),
102 X(EMR_SCALEVIEWPORTEXTEX
),
103 X(EMR_SCALEWINDOWEXTEX
),
106 X(EMR_SETWORLDTRANSFORM
),
107 X(EMR_MODIFYWORLDTRANSFORM
),
110 X(EMR_CREATEBRUSHINDIRECT
),
119 X(EMR_SELECTPALETTE
),
120 X(EMR_CREATEPALETTE
),
121 X(EMR_SETPALETTEENTRIES
),
122 X(EMR_RESIZEPALETTE
),
123 X(EMR_REALIZEPALETTE
),
128 X(EMR_SETARCDIRECTION
),
129 X(EMR_SETMITERLIMIT
),
134 X(EMR_STROKEANDFILLPATH
),
138 X(EMR_SELECTCLIPPATH
),
145 X(EMR_EXTSELECTCLIPRGN
),
150 X(EMR_SETDIBITSTODEVICE
),
151 X(EMR_STRETCHDIBITS
),
152 X(EMR_EXTCREATEFONTINDIRECTW
),
158 X(EMR_POLYBEZIERTO16
),
160 X(EMR_POLYPOLYLINE16
),
161 X(EMR_POLYPOLYGON16
),
163 X(EMR_CREATEMONOBRUSH
),
164 X(EMR_CREATEDIBPATTERNBRUSHPT
),
169 X(EMR_CREATECOLORSPACE
),
170 X(EMR_SETCOLORSPACE
),
171 X(EMR_DELETECOLORSPACE
),
173 X(EMR_GLSBOUNDEDRECORD
),
179 X(EMR_FORCEUFIMAPPING
),
181 X(EMR_COLORCORRECTPALETTE
),
182 X(EMR_SETICMPROFILEA
),
183 X(EMR_SETICMPROFILEW
),
186 X(EMR_TRANSPARENTBLT
),
190 X(EMR_SETTEXTJUSTIFICATION
),
191 X(EMR_COLORMATCHTOTARGETW
),
192 X(EMR_CREATECOLORSPACEW
)
196 /****************************************************************************
199 static const char *get_emr_name(DWORD type
)
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
);
208 /***********************************************************************
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))
232 /* Check if the second color is white */
233 return ((rgb
->rgbtRed
== 0xff) && (rgb
->rgbtGreen
== 0xff)
234 && (rgb
->rgbtBlue
== 0xff));
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))
248 /* Check if the second color is white */
249 return ((rgb
->rgbRed
== 0xff) && (rgb
->rgbGreen
== 0xff)
250 && (rgb
->rgbBlue
== 0xff) && (rgb
->rgbReserved
== 0));
256 /****************************************************************************
257 * EMF_Create_HENHMETAFILE
259 HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, DWORD filesize
, BOOL on_disk
)
262 ENHMETAFILEOBJ
*metaObj
;
264 if (filesize
< sizeof(*emh
))
266 WARN("File too small for emf header\n");
269 if (emh
->iType
!= EMR_HEADER
)
271 SetLastError(ERROR_INVALID_DATA
);
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
);
281 if (filesize
< emh
->nBytes
)
283 WARN("File truncated (got %lu bytes, header says %lu)\n", emh
->nBytes
, filesize
);
287 if (!(metaObj
= HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj
) ))) return 0;
290 metaObj
->on_disk
= on_disk
;
292 if ((hmf
= NtGdiCreateClientObj( NTGDI_OBJ_ENHMETAFILE
)))
293 set_gdi_client_ptr( hmf
, metaObj
);
295 HeapFree( GetProcessHeap(), 0, metaObj
);
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
);
315 if (metafile
->on_disk
)
316 UnmapViewOfFile( metafile
->emh
);
318 HeapFree( GetProcessHeap(), 0, metafile
->emh
);
319 HeapFree( GetProcessHeap(), 0, metafile
);
320 LeaveCriticalSection( &enhmetafile_cs
);
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
);
340 else SetLastError( ERROR_INVALID_HANDLE
);
341 LeaveCriticalSection( &enhmetafile_cs
);
345 /*****************************************************************************
349 static HENHMETAFILE
EMF_GetEnhMetaFile( HANDLE hFile
)
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
);
364 hemf
= EMF_Create_HENHMETAFILE( emh
, filesize
, TRUE
);
366 UnmapViewOfFile( emh
);
371 /*****************************************************************************
372 * GetEnhMetaFileA (GDI32.@)
376 HENHMETAFILE WINAPI
GetEnhMetaFileA(
377 LPCSTR lpszMetaFile
/* [in] filename of enhanced metafile */
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
);
389 hmf
= EMF_GetEnhMetaFile( hFile
);
390 CloseHandle( hFile
);
394 /*****************************************************************************
395 * GetEnhMetaFileW (GDI32.@)
397 HENHMETAFILE WINAPI
GetEnhMetaFileW(
398 LPCWSTR lpszMetaFile
) /* [in] filename of enhanced metafile */
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
));
409 hmf
= EMF_GetEnhMetaFile( hFile
);
410 CloseHandle( hFile
);
414 /*****************************************************************************
415 * GetEnhMetaFileHeader (GDI32.@)
417 * Retrieves the record containing the header for the specified
418 * enhanced-format metafile.
421 * If buf is NULL, returns the size of buffer required.
422 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
425 UINT WINAPI
GetEnhMetaFileHeader(
426 HENHMETAFILE hmf
, /* [in] enhanced metafile */
427 UINT bufsize
, /* [in] size of buffer */
428 LPENHMETAHEADER buf
/* [out] buffer */
434 emh
= EMF_GetEnhMetaHeader(hmf
);
435 if(!emh
) return FALSE
;
437 if (!buf
) return size
;
438 size
= min(size
, bufsize
);
439 memmove(buf
, emh
, 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
);
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
);
471 /*****************************************************************************
472 * GetEnhMetaFileDescriptionW (GDI32.@)
474 * Copies the description string of an enhanced metafile into a buffer
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
);
508 memcpy(emh
, buf
, bufsize
);
509 hmf
= EMF_Create_HENHMETAFILE( emh
, bufsize
, FALSE
);
511 HeapFree( GetProcessHeap(), 0, emh
);
515 /*****************************************************************************
516 * GetEnhMetaFileBits (GDI32.@)
519 UINT WINAPI
GetEnhMetaFileBits(
525 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
531 if( buf
== NULL
) return size
;
533 size
= min( size
, bufsize
);
534 memmove(buf
, emh
, size
);
538 typedef struct EMF_dc_state
541 XFORM world_transform
;
550 struct EMF_dc_state
*next
;
553 typedef struct enum_emh_data
555 XFORM init_transform
;
558 EMF_dc_state
*saved_state
;
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
;
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
));
614 *state
= info
->state
;
615 state
->next
= info
->saved_state
;
616 info
->saved_state
= state
;
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
)
634 info
->state
.wndExtX
= 1;
635 info
->state
.wndExtY
= 1;
636 info
->state
.vportExtX
= 1;
637 info
->state
.vportExtY
= 1;
641 info
->state
.wndExtX
= horzSize
* 10;
642 info
->state
.wndExtY
= vertSize
* 10;
643 info
->state
.vportExtX
= horzRes
;
644 info
->state
.vportExtY
= -vertRes
;
647 info
->state
.wndExtX
= horzSize
* 100;
648 info
->state
.wndExtY
= vertSize
* 100;
649 info
->state
.vportExtX
= horzRes
;
650 info
->state
.vportExtY
= -vertRes
;
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
;
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
;
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
;
677 /***********************************************************************
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
));
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
;
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
)
719 case EMR_POLYBEZIERTO
:
721 case EMR_POLYPOLYLINE
:
722 case EMR_POLYPOLYGON
:
725 case EMR_EXCLUDECLIPRECT
:
726 case EMR_INTERSECTCLIPRECT
:
727 case EMR_SELECTOBJECT
:
735 case EMR_EXTFLOODFILL
:
748 case EMR_SETDIBITSTODEVICE
:
749 case EMR_STRETCHDIBITS
:
750 case EMR_EXTTEXTOUTA
:
751 case EMR_EXTTEXTOUTW
:
752 case EMR_POLYBEZIER16
:
755 case EMR_POLYBEZIERTO16
:
756 case EMR_POLYLINETO16
:
757 case EMR_POLYPOLYLINE16
:
758 case EMR_POLYPOLYGON16
:
760 case EMR_POLYTEXTOUTA
:
761 case EMR_POLYTEXTOUTW
:
762 case EMR_SMALLTEXTOUT
:
764 case EMR_TRANSPARENTBLT
:
772 /*****************************************************************************
773 * PlayEnhMetaFileRecord (GDI32.@)
775 * Render a single enhanced metafile record in the device context hdc.
778 * TRUE (non zero) on success, FALSE on error.
780 * Many unimplemented records.
781 * No error handling on record play failures (ie checking return codes)
784 * WinNT actually updates the current world transform in this function
785 * whereas Win9x does not.
787 BOOL WINAPI
PlayEnhMetaFileRecord(
788 HDC hdc
, /* [in] device context in which to render EMF record */
789 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
790 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
791 UINT handles
/* [in] size of handle array */
796 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
798 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
799 hdc
, handletable
, mr
, handles
);
800 if (!mr
) return FALSE
;
804 TRACE("record %s\n", get_emr_name(type
));
813 const EMRGDICOMMENT
*lpGdiComment
= (const EMRGDICOMMENT
*)mr
;
814 /* In an enhanced metafile, there can be both public and private GDI comments */
815 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
820 const EMRSETMAPMODE
*pSetMapMode
= (const EMRSETMAPMODE
*)mr
;
822 if (info
->state
.mode
== pSetMapMode
->iMode
&&
823 (info
->state
.mode
== MM_ISOTROPIC
|| info
->state
.mode
== MM_ANISOTROPIC
))
825 info
->state
.mode
= pSetMapMode
->iMode
;
826 EMF_SetMapMode(hdc
, info
);
829 EMF_Update_MF_Xform(hdc
, info
);
835 const EMRSETBKMODE
*pSetBkMode
= (const EMRSETBKMODE
*)mr
;
836 SetBkMode(hdc
, pSetBkMode
->iMode
);
841 const EMRSETBKCOLOR
*pSetBkColor
= (const EMRSETBKCOLOR
*)mr
;
842 SetBkColor(hdc
, pSetBkColor
->crColor
);
845 case EMR_SETPOLYFILLMODE
:
847 const EMRSETPOLYFILLMODE
*pSetPolyFillMode
= (const EMRSETPOLYFILLMODE
*)mr
;
848 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
853 const EMRSETROP2
*pSetROP2
= (const EMRSETROP2
*)mr
;
854 SetROP2(hdc
, pSetROP2
->iMode
);
857 case EMR_SETSTRETCHBLTMODE
:
859 const EMRSETSTRETCHBLTMODE
*pSetStretchBltMode
= (const EMRSETSTRETCHBLTMODE
*)mr
;
860 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
863 case EMR_SETTEXTALIGN
:
865 const EMRSETTEXTALIGN
*pSetTextAlign
= (const EMRSETTEXTALIGN
*)mr
;
866 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
869 case EMR_SETTEXTCOLOR
:
871 const EMRSETTEXTCOLOR
*pSetTextColor
= (const EMRSETTEXTCOLOR
*)mr
;
872 SetTextColor(hdc
, pSetTextColor
->crColor
);
883 const EMRRESTOREDC
*pRestoreDC
= (const EMRRESTOREDC
*)mr
;
884 TRACE("EMR_RESTORE: %ld\n", pRestoreDC
->iRelative
);
885 if (RestoreDC( hdc
, pRestoreDC
->iRelative
))
886 EMF_RestoreDC( info
, pRestoreDC
->iRelative
);
889 case EMR_INTERSECTCLIPRECT
:
891 const EMRINTERSECTCLIPRECT
*pClipRect
= (const EMRINTERSECTCLIPRECT
*)mr
;
892 TRACE("EMR_INTERSECTCLIPRECT: rect %ld,%ld - %ld, %ld\n",
893 pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
894 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
895 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
896 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
899 case EMR_SELECTOBJECT
:
901 const EMRSELECTOBJECT
*pSelectObject
= (const EMRSELECTOBJECT
*)mr
;
902 if( pSelectObject
->ihObject
& 0x80000000 ) {
903 /* High order bit is set - it's a stock object
904 * Strip the high bit to get the index.
905 * See MSDN article Q142319
907 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
910 /* High order bit wasn't set - not a stock object
913 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
917 case EMR_DELETEOBJECT
:
919 const EMRDELETEOBJECT
*pDeleteObject
= (const EMRDELETEOBJECT
*)mr
;
920 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
921 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
924 case EMR_SETWINDOWORGEX
:
926 const EMRSETWINDOWORGEX
*pSetWindowOrgEx
= (const EMRSETWINDOWORGEX
*)mr
;
928 info
->state
.wndOrgX
= pSetWindowOrgEx
->ptlOrigin
.x
;
929 info
->state
.wndOrgY
= pSetWindowOrgEx
->ptlOrigin
.y
;
931 TRACE("SetWindowOrgEx: %d,%d\n", info
->state
.wndOrgX
, info
->state
.wndOrgY
);
934 EMF_Update_MF_Xform(hdc
, info
);
938 case EMR_SETWINDOWEXTEX
:
940 const EMRSETWINDOWEXTEX
*pSetWindowExtEx
= (const EMRSETWINDOWEXTEX
*)mr
;
942 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
944 info
->state
.wndExtX
= pSetWindowExtEx
->szlExtent
.cx
;
945 info
->state
.wndExtY
= pSetWindowExtEx
->szlExtent
.cy
;
946 if (info
->state
.mode
== MM_ISOTROPIC
)
947 EMF_FixIsotropic(hdc
, info
);
949 TRACE("SetWindowExtEx: %d,%d\n",info
->state
.wndExtX
, info
->state
.wndExtY
);
952 EMF_Update_MF_Xform(hdc
, info
);
956 case EMR_SETVIEWPORTORGEX
:
958 const EMRSETVIEWPORTORGEX
*pSetViewportOrgEx
= (const EMRSETVIEWPORTORGEX
*)mr
;
960 info
->state
.vportOrgX
= pSetViewportOrgEx
->ptlOrigin
.x
;
961 info
->state
.vportOrgY
= pSetViewportOrgEx
->ptlOrigin
.y
;
962 TRACE("SetViewportOrgEx: %d,%d\n", info
->state
.vportOrgX
, info
->state
.vportOrgY
);
965 EMF_Update_MF_Xform(hdc
, info
);
969 case EMR_SETVIEWPORTEXTEX
:
971 const EMRSETVIEWPORTEXTEX
*pSetViewportExtEx
= (const EMRSETVIEWPORTEXTEX
*)mr
;
973 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
975 info
->state
.vportExtX
= pSetViewportExtEx
->szlExtent
.cx
;
976 info
->state
.vportExtY
= pSetViewportExtEx
->szlExtent
.cy
;
977 if (info
->state
.mode
== MM_ISOTROPIC
)
978 EMF_FixIsotropic(hdc
, info
);
979 TRACE("SetViewportExtEx: %d,%d\n", info
->state
.vportExtX
, info
->state
.vportExtY
);
982 EMF_Update_MF_Xform(hdc
, info
);
988 const EMRCREATEPEN
*pCreatePen
= (const EMRCREATEPEN
*)mr
;
989 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
990 CreatePenIndirect(&pCreatePen
->lopn
);
993 case EMR_EXTCREATEPEN
:
995 const EMREXTCREATEPEN
*pPen
= (const EMREXTCREATEPEN
*)mr
;
997 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
998 lb
.lbColor
= pPen
->elp
.elpColor
;
999 lb
.lbHatch
= pPen
->elp
.elpHatch
;
1001 if(pPen
->offBmi
|| pPen
->offBits
)
1002 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
1004 (handletable
->objectHandle
)[pPen
->ihPen
] =
1005 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
1006 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpNumEntries
? pPen
->elp
.elpStyleEntry
: NULL
);
1009 case EMR_CREATEBRUSHINDIRECT
:
1011 const EMRCREATEBRUSHINDIRECT
*pBrush
= (const EMRCREATEBRUSHINDIRECT
*)mr
;
1013 brush
.lbStyle
= pBrush
->lb
.lbStyle
;
1014 brush
.lbColor
= pBrush
->lb
.lbColor
;
1015 brush
.lbHatch
= pBrush
->lb
.lbHatch
;
1016 (handletable
->objectHandle
)[pBrush
->ihBrush
] = CreateBrushIndirect(&brush
);
1019 case EMR_EXTCREATEFONTINDIRECTW
:
1021 const EMREXTCREATEFONTINDIRECTW
*pFont
= (const EMREXTCREATEFONTINDIRECTW
*)mr
;
1022 (handletable
->objectHandle
)[pFont
->ihFont
] =
1023 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
1028 const EMRMOVETOEX
*pMoveToEx
= (const EMRMOVETOEX
*)mr
;
1029 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
1034 const EMRLINETO
*pLineTo
= (const EMRLINETO
*)mr
;
1035 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
1040 const EMRRECTANGLE
*pRect
= (const EMRRECTANGLE
*)mr
;
1041 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
1042 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
1047 const EMRELLIPSE
*pEllipse
= (const EMRELLIPSE
*)mr
;
1048 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
1049 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
1054 const EMRPOLYGON16
*pPoly
= (const EMRPOLYGON16
*)mr
;
1055 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
1056 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1057 pPoly
->cpts
* sizeof(POINT
) );
1059 for(i
= 0; i
< pPoly
->cpts
; i
++)
1061 pts
[i
].x
= pPoly
->apts
[i
].x
;
1062 pts
[i
].y
= pPoly
->apts
[i
].y
;
1064 Polygon(hdc
, pts
, pPoly
->cpts
);
1065 HeapFree( GetProcessHeap(), 0, pts
);
1068 case EMR_POLYLINE16
:
1070 const EMRPOLYLINE16
*pPoly
= (const EMRPOLYLINE16
*)mr
;
1071 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1072 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1073 pPoly
->cpts
* sizeof(POINT
) );
1075 for(i
= 0; i
< pPoly
->cpts
; i
++)
1077 pts
[i
].x
= pPoly
->apts
[i
].x
;
1078 pts
[i
].y
= pPoly
->apts
[i
].y
;
1080 Polyline(hdc
, pts
, pPoly
->cpts
);
1081 HeapFree( GetProcessHeap(), 0, pts
);
1084 case EMR_POLYLINETO16
:
1086 const EMRPOLYLINETO16
*pPoly
= (const EMRPOLYLINETO16
*)mr
;
1087 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1088 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1089 pPoly
->cpts
* sizeof(POINT
) );
1091 for(i
= 0; i
< pPoly
->cpts
; i
++)
1093 pts
[i
].x
= pPoly
->apts
[i
].x
;
1094 pts
[i
].y
= pPoly
->apts
[i
].y
;
1096 PolylineTo(hdc
, pts
, pPoly
->cpts
);
1097 HeapFree( GetProcessHeap(), 0, pts
);
1100 case EMR_POLYBEZIER16
:
1102 const EMRPOLYBEZIER16
*pPoly
= (const EMRPOLYBEZIER16
*)mr
;
1103 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1104 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1105 pPoly
->cpts
* sizeof(POINT
) );
1107 for(i
= 0; i
< pPoly
->cpts
; i
++)
1109 pts
[i
].x
= pPoly
->apts
[i
].x
;
1110 pts
[i
].y
= pPoly
->apts
[i
].y
;
1112 PolyBezier(hdc
, pts
, pPoly
->cpts
);
1113 HeapFree( GetProcessHeap(), 0, pts
);
1116 case EMR_POLYBEZIERTO16
:
1118 const EMRPOLYBEZIERTO16
*pPoly
= (const EMRPOLYBEZIERTO16
*)mr
;
1119 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1120 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1121 pPoly
->cpts
* sizeof(POINT
) );
1123 for(i
= 0; i
< pPoly
->cpts
; i
++)
1125 pts
[i
].x
= pPoly
->apts
[i
].x
;
1126 pts
[i
].y
= pPoly
->apts
[i
].y
;
1128 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
1129 HeapFree( GetProcessHeap(), 0, pts
);
1132 case EMR_POLYPOLYGON16
:
1134 const EMRPOLYPOLYGON16
*pPolyPoly
= (const EMRPOLYPOLYGON16
*)mr
;
1135 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1136 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1138 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1139 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1141 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1146 PolyPolygon(hdc
, pt
, (const INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1147 HeapFree( GetProcessHeap(), 0, pt
);
1150 case EMR_POLYPOLYLINE16
:
1152 const EMRPOLYPOLYLINE16
*pPolyPoly
= (const EMRPOLYPOLYLINE16
*)mr
;
1153 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1154 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1156 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1157 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1159 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1164 PolyPolyline(hdc
, pt
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1165 HeapFree( GetProcessHeap(), 0, pt
);
1169 case EMR_POLYDRAW16
:
1171 const EMRPOLYDRAW16
*pPolyDraw16
= (const EMRPOLYDRAW16
*)mr
;
1172 const POINTS
*ptl
= pPolyDraw16
->apts
;
1173 POINT
*pts
= HeapAlloc(GetProcessHeap(), 0, pPolyDraw16
->cpts
* sizeof(POINT
));
1176 /* NB abTypes array doesn't start at pPolyDraw16->abTypes. It's actually
1177 pPolyDraw16->apts + pPolyDraw16->cpts. */
1178 const BYTE
*types
= (BYTE
*)(pPolyDraw16
->apts
+ pPolyDraw16
->cpts
);
1183 for (i
= 0; i
< pPolyDraw16
->cpts
; ++i
)
1185 pts
[i
].x
= ptl
[i
].x
;
1186 pts
[i
].y
= ptl
[i
].y
;
1189 PolyDraw(hdc
, pts
, types
, pPolyDraw16
->cpts
);
1190 HeapFree(GetProcessHeap(), 0, pts
);
1194 case EMR_STRETCHDIBITS
:
1196 const EMRSTRETCHDIBITS
*pStretchDIBits
= (const EMRSTRETCHDIBITS
*)mr
;
1199 pStretchDIBits
->xDest
,
1200 pStretchDIBits
->yDest
,
1201 pStretchDIBits
->cxDest
,
1202 pStretchDIBits
->cyDest
,
1203 pStretchDIBits
->xSrc
,
1204 pStretchDIBits
->ySrc
,
1205 pStretchDIBits
->cxSrc
,
1206 pStretchDIBits
->cySrc
,
1207 (const BYTE
*)mr
+ pStretchDIBits
->offBitsSrc
,
1208 (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchDIBits
->offBmiSrc
),
1209 pStretchDIBits
->iUsageSrc
,
1210 pStretchDIBits
->dwRop
);
1214 case EMR_EXTTEXTOUTA
:
1216 const EMREXTTEXTOUTA
*pExtTextOutA
= (const EMREXTTEXTOUTA
*)mr
;
1218 const INT
*dx
= NULL
;
1221 rc
.left
= pExtTextOutA
->emrtext
.rcl
.left
;
1222 rc
.top
= pExtTextOutA
->emrtext
.rcl
.top
;
1223 rc
.right
= pExtTextOutA
->emrtext
.rcl
.right
;
1224 rc
.bottom
= pExtTextOutA
->emrtext
.rcl
.bottom
;
1225 TRACE("EMR_EXTTEXTOUTA: x,y = %ld, %ld. rect = %s. flags %08lx\n",
1226 pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1227 wine_dbgstr_rect(&rc
), pExtTextOutA
->emrtext
.fOptions
);
1229 old_mode
= SetGraphicsMode(hdc
, pExtTextOutA
->iGraphicsMode
);
1230 /* Reselect the font back into the dc so that the transformation
1232 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1234 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1235 * These files can be enumerated and played under Win98 just
1236 * fine, but at least Win2k chokes on them.
1238 if (pExtTextOutA
->emrtext
.offDx
)
1239 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offDx
);
1241 ExtTextOutA(hdc
, pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1242 pExtTextOutA
->emrtext
.fOptions
, &rc
,
1243 (LPCSTR
)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offString
), pExtTextOutA
->emrtext
.nChars
,
1246 SetGraphicsMode(hdc
, old_mode
);
1250 case EMR_EXTTEXTOUTW
:
1252 const EMREXTTEXTOUTW
*pExtTextOutW
= (const EMREXTTEXTOUTW
*)mr
;
1254 const INT
*dx
= NULL
;
1257 rc
.left
= pExtTextOutW
->emrtext
.rcl
.left
;
1258 rc
.top
= pExtTextOutW
->emrtext
.rcl
.top
;
1259 rc
.right
= pExtTextOutW
->emrtext
.rcl
.right
;
1260 rc
.bottom
= pExtTextOutW
->emrtext
.rcl
.bottom
;
1261 TRACE("EMR_EXTTEXTOUTW: x,y = %ld, %ld. rect = %s. flags %08lx\n",
1262 pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1263 wine_dbgstr_rect(&rc
), pExtTextOutW
->emrtext
.fOptions
);
1265 old_mode
= SetGraphicsMode(hdc
, pExtTextOutW
->iGraphicsMode
);
1266 /* Reselect the font back into the dc so that the transformation
1268 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1270 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1271 * These files can be enumerated and played under Win98 just
1272 * fine, but at least Win2k chokes on them.
1274 if (pExtTextOutW
->emrtext
.offDx
)
1275 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offDx
);
1277 ExtTextOutW(hdc
, pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1278 pExtTextOutW
->emrtext
.fOptions
, &rc
,
1279 (LPCWSTR
)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offString
), pExtTextOutW
->emrtext
.nChars
,
1282 SetGraphicsMode(hdc
, old_mode
);
1286 case EMR_CREATEPALETTE
:
1288 const EMRCREATEPALETTE
*lpCreatePal
= (const EMRCREATEPALETTE
*)mr
;
1290 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1291 CreatePalette( &lpCreatePal
->lgpl
);
1296 case EMR_SELECTPALETTE
:
1298 const EMRSELECTPALETTE
*lpSelectPal
= (const EMRSELECTPALETTE
*)mr
;
1300 if( lpSelectPal
->ihPal
& 0x80000000 ) {
1301 SelectPalette( hdc
, GetStockObject(lpSelectPal
->ihPal
& 0x7fffffff), TRUE
);
1303 SelectPalette( hdc
, (handletable
->objectHandle
)[lpSelectPal
->ihPal
], TRUE
);
1308 case EMR_REALIZEPALETTE
:
1310 RealizePalette( hdc
);
1314 case EMR_EXTSELECTCLIPRGN
:
1316 const EMREXTSELECTCLIPRGN
*lpRgn
= (const EMREXTSELECTCLIPRGN
*)mr
;
1319 if (mr
->nSize
>= sizeof(*lpRgn
) + sizeof(RGNDATAHEADER
))
1320 hRgn
= ExtCreateRegion( &info
->init_transform
, 0, (const RGNDATA
*)lpRgn
->RgnData
);
1322 ExtSelectClipRgn(hdc
, hRgn
, (INT
)(lpRgn
->iMode
));
1323 /* ExtSelectClipRgn created a copy of the region */
1328 case EMR_SETMETARGN
:
1334 case EMR_SETWORLDTRANSFORM
:
1336 const EMRSETWORLDTRANSFORM
*lpXfrm
= (const EMRSETWORLDTRANSFORM
*)mr
;
1337 info
->state
.world_transform
= lpXfrm
->xform
;
1340 EMF_Update_MF_Xform(hdc
, info
);
1345 case EMR_POLYBEZIER
:
1347 const EMRPOLYBEZIER
*lpPolyBez
= (const EMRPOLYBEZIER
*)mr
;
1348 PolyBezier(hdc
, (const POINT
*)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1354 const EMRPOLYGON
*lpPoly
= (const EMRPOLYGON
*)mr
;
1355 Polygon( hdc
, (const POINT
*)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1361 const EMRPOLYLINE
*lpPolyLine
= (const EMRPOLYLINE
*)mr
;
1362 Polyline(hdc
, (const POINT
*)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1366 case EMR_POLYBEZIERTO
:
1368 const EMRPOLYBEZIERTO
*lpPolyBezierTo
= (const EMRPOLYBEZIERTO
*)mr
;
1369 PolyBezierTo( hdc
, (const POINT
*)lpPolyBezierTo
->aptl
,
1370 (UINT
)lpPolyBezierTo
->cptl
);
1374 case EMR_POLYLINETO
:
1376 const EMRPOLYLINETO
*lpPolyLineTo
= (const EMRPOLYLINETO
*)mr
;
1377 PolylineTo( hdc
, (const POINT
*)lpPolyLineTo
->aptl
,
1378 (UINT
)lpPolyLineTo
->cptl
);
1382 case EMR_POLYPOLYLINE
:
1384 const EMRPOLYPOLYLINE
*pPolyPolyline
= (const EMRPOLYPOLYLINE
*)mr
;
1385 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1387 PolyPolyline(hdc
, (const POINT
*)(pPolyPolyline
->aPolyCounts
+
1388 pPolyPolyline
->nPolys
),
1389 pPolyPolyline
->aPolyCounts
,
1390 pPolyPolyline
->nPolys
);
1395 case EMR_POLYPOLYGON
:
1397 const EMRPOLYPOLYGON
*pPolyPolygon
= (const EMRPOLYPOLYGON
*)mr
;
1399 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1401 PolyPolygon(hdc
, (const POINT
*)(pPolyPolygon
->aPolyCounts
+
1402 pPolyPolygon
->nPolys
),
1403 (const INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
1407 case EMR_SETBRUSHORGEX
:
1409 const EMRSETBRUSHORGEX
*lpSetBrushOrgEx
= (const EMRSETBRUSHORGEX
*)mr
;
1412 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1413 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1421 const EMRSETPIXELV
*lpSetPixelV
= (const EMRSETPIXELV
*)mr
;
1424 (INT
)lpSetPixelV
->ptlPixel
.x
,
1425 (INT
)lpSetPixelV
->ptlPixel
.y
,
1426 lpSetPixelV
->crColor
);
1431 case EMR_SETMAPPERFLAGS
:
1433 const EMRSETMAPPERFLAGS
*lpSetMapperFlags
= (const EMRSETMAPPERFLAGS
*)mr
;
1435 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1440 case EMR_SETCOLORADJUSTMENT
:
1442 const EMRSETCOLORADJUSTMENT
*lpSetColorAdjust
= (const EMRSETCOLORADJUSTMENT
*)mr
;
1444 NtGdiSetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1449 case EMR_OFFSETCLIPRGN
:
1451 const EMROFFSETCLIPRGN
*lpOffsetClipRgn
= (const EMROFFSETCLIPRGN
*)mr
;
1454 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1455 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1456 FIXME("OffsetClipRgn\n");
1461 case EMR_EXCLUDECLIPRECT
:
1463 const EMREXCLUDECLIPRECT
*lpExcludeClipRect
= (const EMREXCLUDECLIPRECT
*)mr
;
1465 ExcludeClipRect( hdc
,
1466 lpExcludeClipRect
->rclClip
.left
,
1467 lpExcludeClipRect
->rclClip
.top
,
1468 lpExcludeClipRect
->rclClip
.right
,
1469 lpExcludeClipRect
->rclClip
.bottom
);
1470 FIXME("ExcludeClipRect\n");
1475 case EMR_SCALEVIEWPORTEXTEX
:
1477 const EMRSCALEVIEWPORTEXTEX
*lpScaleViewportExtEx
= (const EMRSCALEVIEWPORTEXTEX
*)mr
;
1479 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1481 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1482 !lpScaleViewportExtEx
->yNum
|| !lpScaleViewportExtEx
->yDenom
)
1484 info
->state
.vportExtX
= MulDiv(info
->state
.vportExtX
, lpScaleViewportExtEx
->xNum
,
1485 lpScaleViewportExtEx
->xDenom
);
1486 info
->state
.vportExtY
= MulDiv(info
->state
.vportExtY
, lpScaleViewportExtEx
->yNum
,
1487 lpScaleViewportExtEx
->yDenom
);
1488 if (info
->state
.vportExtX
== 0) info
->state
.vportExtX
= 1;
1489 if (info
->state
.vportExtY
== 0) info
->state
.vportExtY
= 1;
1490 if (info
->state
.mode
== MM_ISOTROPIC
)
1491 EMF_FixIsotropic(hdc
, info
);
1493 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1494 lpScaleViewportExtEx
->xNum
,lpScaleViewportExtEx
->xDenom
,
1495 lpScaleViewportExtEx
->yNum
,lpScaleViewportExtEx
->yDenom
);
1498 EMF_Update_MF_Xform(hdc
, info
);
1503 case EMR_SCALEWINDOWEXTEX
:
1505 const EMRSCALEWINDOWEXTEX
*lpScaleWindowExtEx
= (const EMRSCALEWINDOWEXTEX
*)mr
;
1507 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1509 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1510 !lpScaleWindowExtEx
->yNum
|| !lpScaleWindowExtEx
->yDenom
)
1512 info
->state
.wndExtX
= MulDiv(info
->state
.wndExtX
, lpScaleWindowExtEx
->xNum
,
1513 lpScaleWindowExtEx
->xDenom
);
1514 info
->state
.wndExtY
= MulDiv(info
->state
.wndExtY
, lpScaleWindowExtEx
->yNum
,
1515 lpScaleWindowExtEx
->yDenom
);
1516 if (info
->state
.wndExtX
== 0) info
->state
.wndExtX
= 1;
1517 if (info
->state
.wndExtY
== 0) info
->state
.wndExtY
= 1;
1518 if (info
->state
.mode
== MM_ISOTROPIC
)
1519 EMF_FixIsotropic(hdc
, info
);
1521 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1522 lpScaleWindowExtEx
->xNum
,lpScaleWindowExtEx
->xDenom
,
1523 lpScaleWindowExtEx
->yNum
,lpScaleWindowExtEx
->yDenom
);
1526 EMF_Update_MF_Xform(hdc
, info
);
1531 case EMR_MODIFYWORLDTRANSFORM
:
1533 const EMRMODIFYWORLDTRANSFORM
*lpModifyWorldTrans
= (const EMRMODIFYWORLDTRANSFORM
*)mr
;
1535 switch(lpModifyWorldTrans
->iMode
) {
1537 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
1538 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
1539 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
1541 EMF_Update_MF_Xform(hdc
, info
);
1543 case MWT_LEFTMULTIPLY
:
1544 CombineTransform(&info
->state
.world_transform
, &lpModifyWorldTrans
->xform
,
1545 &info
->state
.world_transform
);
1547 ModifyWorldTransform(hdc
, &lpModifyWorldTrans
->xform
, MWT_LEFTMULTIPLY
);
1549 case MWT_RIGHTMULTIPLY
:
1550 CombineTransform(&info
->state
.world_transform
, &info
->state
.world_transform
,
1551 &lpModifyWorldTrans
->xform
);
1553 EMF_Update_MF_Xform(hdc
, info
);
1556 FIXME("Unknown imode %ld\n", lpModifyWorldTrans
->iMode
);
1564 const EMRANGLEARC
*lpAngleArc
= (const EMRANGLEARC
*)mr
;
1567 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1568 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1569 lpAngleArc
->eSweepAngle
);
1576 const EMRROUNDRECT
*lpRoundRect
= (const EMRROUNDRECT
*)mr
;
1579 lpRoundRect
->rclBox
.left
,
1580 lpRoundRect
->rclBox
.top
,
1581 lpRoundRect
->rclBox
.right
,
1582 lpRoundRect
->rclBox
.bottom
,
1583 lpRoundRect
->szlCorner
.cx
,
1584 lpRoundRect
->szlCorner
.cy
);
1591 const EMRARC
*lpArc
= (const EMRARC
*)mr
;
1594 (INT
)lpArc
->rclBox
.left
,
1595 (INT
)lpArc
->rclBox
.top
,
1596 (INT
)lpArc
->rclBox
.right
,
1597 (INT
)lpArc
->rclBox
.bottom
,
1598 (INT
)lpArc
->ptlStart
.x
,
1599 (INT
)lpArc
->ptlStart
.y
,
1600 (INT
)lpArc
->ptlEnd
.x
,
1601 (INT
)lpArc
->ptlEnd
.y
);
1608 const EMRCHORD
*lpChord
= (const EMRCHORD
*)mr
;
1611 (INT
)lpChord
->rclBox
.left
,
1612 (INT
)lpChord
->rclBox
.top
,
1613 (INT
)lpChord
->rclBox
.right
,
1614 (INT
)lpChord
->rclBox
.bottom
,
1615 (INT
)lpChord
->ptlStart
.x
,
1616 (INT
)lpChord
->ptlStart
.y
,
1617 (INT
)lpChord
->ptlEnd
.x
,
1618 (INT
)lpChord
->ptlEnd
.y
);
1625 const EMRPIE
*lpPie
= (const EMRPIE
*)mr
;
1628 (INT
)lpPie
->rclBox
.left
,
1629 (INT
)lpPie
->rclBox
.top
,
1630 (INT
)lpPie
->rclBox
.right
,
1631 (INT
)lpPie
->rclBox
.bottom
,
1632 (INT
)lpPie
->ptlStart
.x
,
1633 (INT
)lpPie
->ptlStart
.y
,
1634 (INT
)lpPie
->ptlEnd
.x
,
1635 (INT
)lpPie
->ptlEnd
.y
);
1642 const EMRARC
*lpArcTo
= (const EMRARC
*)mr
;
1645 (INT
)lpArcTo
->rclBox
.left
,
1646 (INT
)lpArcTo
->rclBox
.top
,
1647 (INT
)lpArcTo
->rclBox
.right
,
1648 (INT
)lpArcTo
->rclBox
.bottom
,
1649 (INT
)lpArcTo
->ptlStart
.x
,
1650 (INT
)lpArcTo
->ptlStart
.y
,
1651 (INT
)lpArcTo
->ptlEnd
.x
,
1652 (INT
)lpArcTo
->ptlEnd
.y
);
1657 case EMR_EXTFLOODFILL
:
1659 const EMREXTFLOODFILL
*lpExtFloodFill
= (const EMREXTFLOODFILL
*)mr
;
1662 (INT
)lpExtFloodFill
->ptlStart
.x
,
1663 (INT
)lpExtFloodFill
->ptlStart
.y
,
1664 lpExtFloodFill
->crColor
,
1665 (UINT
)lpExtFloodFill
->iMode
);
1672 const EMRPOLYDRAW
*lpPolyDraw
= (const EMRPOLYDRAW
*)mr
;
1674 /* NB abTypes array doesn't start at lpPolyDraw->abTypes. It's actually
1675 lpPolyDraw->aptl + lpPolyDraw->cptl. */
1677 (const POINT
*)lpPolyDraw
->aptl
,
1678 (BYTE
*)(lpPolyDraw
->aptl
+ lpPolyDraw
->cptl
),
1679 (INT
)lpPolyDraw
->cptl
);
1684 case EMR_SETARCDIRECTION
:
1686 const EMRSETARCDIRECTION
*lpSetArcDirection
= (const EMRSETARCDIRECTION
*)mr
;
1687 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1691 case EMR_SETMITERLIMIT
:
1693 const EMRSETMITERLIMIT
*lpSetMiterLimit
= (const EMRSETMITERLIMIT
*)mr
;
1694 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1710 case EMR_CLOSEFIGURE
:
1718 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1723 case EMR_STROKEANDFILLPATH
:
1725 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1726 StrokeAndFillPath( hdc
);
1730 case EMR_STROKEPATH
:
1732 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1737 case EMR_FLATTENPATH
:
1749 case EMR_SELECTCLIPPATH
:
1751 const EMRSELECTCLIPPATH
*lpSelectClipPath
= (const EMRSELECTCLIPPATH
*)mr
;
1752 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1762 case EMR_CREATECOLORSPACE
:
1764 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1765 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1766 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1770 case EMR_SETCOLORSPACE
:
1772 const EMRSETCOLORSPACE
*lpSetColorSpace
= (const EMRSETCOLORSPACE
*)mr
;
1774 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1778 case EMR_DELETECOLORSPACE
:
1780 const EMRDELETECOLORSPACE
*lpDeleteColorSpace
= (const EMRDELETECOLORSPACE
*)mr
;
1781 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1785 case EMR_SETICMMODE
:
1787 const EMRSETICMMODE
*lpSetICMMode
= (const EMRSETICMMODE
*)mr
;
1788 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1792 case EMR_PIXELFORMAT
:
1795 const EMRPIXELFORMAT
*lpPixelFormat
= (const EMRPIXELFORMAT
*)mr
;
1797 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1798 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1803 case EMR_SETPALETTEENTRIES
:
1805 const EMRSETPALETTEENTRIES
*lpSetPaletteEntries
= (const EMRSETPALETTEENTRIES
*)mr
;
1807 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1808 (UINT
)lpSetPaletteEntries
->iStart
,
1809 (UINT
)lpSetPaletteEntries
->cEntries
,
1810 lpSetPaletteEntries
->aPalEntries
);
1815 case EMR_RESIZEPALETTE
:
1817 const EMRRESIZEPALETTE
*lpResizePalette
= (const EMRRESIZEPALETTE
*)mr
;
1819 NtGdiResizePalette( handletable
->objectHandle
[lpResizePalette
->ihPal
],
1820 lpResizePalette
->cEntries
);
1825 case EMR_CREATEDIBPATTERNBRUSHPT
:
1827 const EMRCREATEDIBPATTERNBRUSHPT
*lpCreate
= (const EMRCREATEDIBPATTERNBRUSHPT
*)mr
;
1828 LPVOID lpPackedStruct
;
1830 /* Check that offsets and data are contained within the record
1831 * (including checking for wrap-arounds).
1833 if ( lpCreate
->offBmi
+ lpCreate
->cbBmi
> mr
->nSize
1834 || lpCreate
->offBits
+ lpCreate
->cbBits
> mr
->nSize
1835 || lpCreate
->offBmi
+ lpCreate
->cbBmi
< lpCreate
->offBmi
1836 || lpCreate
->offBits
+ lpCreate
->cbBits
< lpCreate
->offBits
)
1838 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1842 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1843 lpPackedStruct
= HeapAlloc( GetProcessHeap(), 0,
1844 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1847 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1851 /* Now pack this structure */
1852 memcpy( lpPackedStruct
,
1853 ((const BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1855 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1856 ((const BYTE
*)lpCreate
) + lpCreate
->offBits
,
1859 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1860 CreateDIBPatternBrushPt( lpPackedStruct
,
1861 (UINT
)lpCreate
->iUsage
);
1863 HeapFree(GetProcessHeap(), 0, lpPackedStruct
);
1867 case EMR_CREATEMONOBRUSH
:
1869 const EMRCREATEMONOBRUSH
*pCreateMonoBrush
= (const EMRCREATEMONOBRUSH
*)mr
;
1870 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
1873 /* Need to check if the bitmap is monochrome, and if the
1874 two colors are really black and white */
1875 if (pCreateMonoBrush
->iUsage
== DIB_PAL_MONO
)
1879 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1880 * aligned to 32 rather than 16 bits.
1883 bm
.bmWidth
= pbi
->bmiHeader
.biWidth
;
1884 bm
.bmHeight
= abs(pbi
->bmiHeader
.biHeight
);
1885 bm
.bmWidthBytes
= 4 * ((pbi
->bmiHeader
.biWidth
+ 31) / 32);
1886 bm
.bmPlanes
= pbi
->bmiHeader
.biPlanes
;
1887 bm
.bmBitsPixel
= pbi
->bmiHeader
.biBitCount
;
1888 bm
.bmBits
= (BYTE
*)mr
+ pCreateMonoBrush
->offBits
;
1889 hBmp
= CreateBitmapIndirect(&bm
);
1891 else if (is_dib_monochrome(pbi
))
1893 /* Top-down DIBs have a negative height */
1894 LONG height
= pbi
->bmiHeader
.biHeight
;
1896 hBmp
= CreateBitmap(pbi
->bmiHeader
.biWidth
, abs(height
), 1, 1, NULL
);
1897 SetDIBits(hdc
, hBmp
, 0, pbi
->bmiHeader
.biHeight
,
1898 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1902 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1903 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1906 (handletable
->objectHandle
)[pCreateMonoBrush
->ihBrush
] = CreatePatternBrush(hBmp
);
1908 /* CreatePatternBrush created a copy of the bitmap */
1915 const EMRBITBLT
*pBitBlt
= (const EMRBITBLT
*)mr
;
1917 if(pBitBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1918 PatBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1920 } else { /* BitBlt */
1921 HDC hdcSrc
= NtGdiCreateCompatibleDC( hdc
);
1922 HBRUSH hBrush
, hBrushOld
;
1923 HBITMAP hBmp
= 0, hBmpOld
= 0;
1924 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pBitBlt
->offBmiSrc
);
1926 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1927 SetWorldTransform(hdcSrc
, &pBitBlt
->xformSrc
);
1929 hBrush
= CreateSolidBrush(pBitBlt
->crBkColorSrc
);
1930 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1931 PatBlt(hdcSrc
, pBitBlt
->rclBounds
.left
, pBitBlt
->rclBounds
.top
,
1932 pBitBlt
->rclBounds
.right
- pBitBlt
->rclBounds
.left
,
1933 pBitBlt
->rclBounds
.bottom
- pBitBlt
->rclBounds
.top
, PATCOPY
);
1934 SelectObject(hdcSrc
, hBrushOld
);
1935 DeleteObject(hBrush
);
1937 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1938 (const BYTE
*)mr
+ pBitBlt
->offBitsSrc
, pbi
, pBitBlt
->iUsageSrc
);
1939 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1941 BitBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1942 hdcSrc
, pBitBlt
->xSrc
, pBitBlt
->ySrc
, pBitBlt
->dwRop
);
1944 SelectObject(hdcSrc
, hBmpOld
);
1951 case EMR_STRETCHBLT
:
1953 const EMRSTRETCHBLT
*pStretchBlt
= (const EMRSTRETCHBLT
*)mr
;
1955 TRACE("EMR_STRETCHBLT: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. rop %08lx offBitsSrc %ld\n",
1956 pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1957 pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1958 pStretchBlt
->dwRop
, pStretchBlt
->offBitsSrc
);
1960 if(pStretchBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1961 PatBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1962 pStretchBlt
->dwRop
);
1963 } else { /* StretchBlt */
1964 HDC hdcSrc
= NtGdiCreateCompatibleDC( hdc
);
1965 HBRUSH hBrush
, hBrushOld
;
1966 HBITMAP hBmp
= 0, hBmpOld
= 0;
1967 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchBlt
->offBmiSrc
);
1969 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1970 SetWorldTransform(hdcSrc
, &pStretchBlt
->xformSrc
);
1972 hBrush
= CreateSolidBrush(pStretchBlt
->crBkColorSrc
);
1973 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1974 PatBlt(hdcSrc
, pStretchBlt
->rclBounds
.left
, pStretchBlt
->rclBounds
.top
,
1975 pStretchBlt
->rclBounds
.right
- pStretchBlt
->rclBounds
.left
,
1976 pStretchBlt
->rclBounds
.bottom
- pStretchBlt
->rclBounds
.top
, PATCOPY
);
1977 SelectObject(hdcSrc
, hBrushOld
);
1978 DeleteObject(hBrush
);
1980 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1981 (const BYTE
*)mr
+ pStretchBlt
->offBitsSrc
, pbi
, pStretchBlt
->iUsageSrc
);
1982 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1984 StretchBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1985 hdcSrc
, pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1986 pStretchBlt
->dwRop
);
1988 SelectObject(hdcSrc
, hBmpOld
);
1995 case EMR_ALPHABLEND
:
1997 const EMRALPHABLEND
*pAlphaBlend
= (const EMRALPHABLEND
*)mr
;
1999 TRACE("EMR_ALPHABLEND: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. blendfn %08lx offBitsSrc %ld\n",
2000 pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
2001 pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
2002 pAlphaBlend
->dwRop
, pAlphaBlend
->offBitsSrc
);
2004 if(pAlphaBlend
->offBmiSrc
== 0) {
2005 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
2007 HDC hdcSrc
= NtGdiCreateCompatibleDC( hdc
);
2008 HBITMAP hBmp
= 0, hBmpOld
= 0;
2009 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pAlphaBlend
->offBmiSrc
);
2012 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
2013 SetWorldTransform(hdcSrc
, &pAlphaBlend
->xformSrc
);
2015 hBmp
= CreateDIBSection(hdc
, pbi
, pAlphaBlend
->iUsageSrc
, &bits
, NULL
, 0);
2016 memcpy(bits
, (const BYTE
*)mr
+ pAlphaBlend
->offBitsSrc
, pAlphaBlend
->cbBitsSrc
);
2017 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2019 GdiAlphaBlend(hdc
, pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
2020 hdcSrc
, pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
2021 *(BLENDFUNCTION
*)&pAlphaBlend
->dwRop
);
2023 SelectObject(hdcSrc
, hBmpOld
);
2032 const EMRMASKBLT
*pMaskBlt
= (const EMRMASKBLT
*)mr
;
2033 HDC hdcSrc
= NtGdiCreateCompatibleDC( hdc
);
2034 HBRUSH hBrush
, hBrushOld
;
2035 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
2036 const BITMAPINFO
*pbi
;
2038 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
2039 SetWorldTransform(hdcSrc
, &pMaskBlt
->xformSrc
);
2041 hBrush
= CreateSolidBrush(pMaskBlt
->crBkColorSrc
);
2042 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
2043 PatBlt(hdcSrc
, pMaskBlt
->rclBounds
.left
, pMaskBlt
->rclBounds
.top
,
2044 pMaskBlt
->rclBounds
.right
- pMaskBlt
->rclBounds
.left
,
2045 pMaskBlt
->rclBounds
.bottom
- pMaskBlt
->rclBounds
.top
, PATCOPY
);
2046 SelectObject(hdcSrc
, hBrushOld
);
2047 DeleteObject(hBrush
);
2049 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiMask
);
2050 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2052 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2053 (const BYTE
*)mr
+ pMaskBlt
->offBitsMask
, pbi
, pMaskBlt
->iUsageMask
);
2055 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiSrc
);
2056 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2057 (const BYTE
*)mr
+ pMaskBlt
->offBitsSrc
, pbi
, pMaskBlt
->iUsageSrc
);
2058 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2071 SelectObject(hdcSrc
, hBmpOld
);
2073 DeleteObject(hBmpMask
);
2080 const EMRPLGBLT
*pPlgBlt
= (const EMRPLGBLT
*)mr
;
2081 HDC hdcSrc
= NtGdiCreateCompatibleDC( hdc
);
2082 HBRUSH hBrush
, hBrushOld
;
2083 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
2084 const BITMAPINFO
*pbi
;
2087 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
2088 SetWorldTransform(hdcSrc
, &pPlgBlt
->xformSrc
);
2090 pts
[0].x
= pPlgBlt
->aptlDest
[0].x
; pts
[0].y
= pPlgBlt
->aptlDest
[0].y
;
2091 pts
[1].x
= pPlgBlt
->aptlDest
[1].x
; pts
[1].y
= pPlgBlt
->aptlDest
[1].y
;
2092 pts
[2].x
= pPlgBlt
->aptlDest
[2].x
; pts
[2].y
= pPlgBlt
->aptlDest
[2].y
;
2094 hBrush
= CreateSolidBrush(pPlgBlt
->crBkColorSrc
);
2095 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
2096 PatBlt(hdcSrc
, pPlgBlt
->rclBounds
.left
, pPlgBlt
->rclBounds
.top
,
2097 pPlgBlt
->rclBounds
.right
- pPlgBlt
->rclBounds
.left
,
2098 pPlgBlt
->rclBounds
.bottom
- pPlgBlt
->rclBounds
.top
, PATCOPY
);
2099 SelectObject(hdcSrc
, hBrushOld
);
2100 DeleteObject(hBrush
);
2102 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiMask
);
2103 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2105 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2106 (const BYTE
*)mr
+ pPlgBlt
->offBitsMask
, pbi
, pPlgBlt
->iUsageMask
);
2108 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiSrc
);
2109 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2110 (const BYTE
*)mr
+ pPlgBlt
->offBitsSrc
, pbi
, pPlgBlt
->iUsageSrc
);
2111 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2122 SelectObject(hdcSrc
, hBmpOld
);
2124 DeleteObject(hBmpMask
);
2129 case EMR_SETDIBITSTODEVICE
:
2131 const EMRSETDIBITSTODEVICE
*pSetDIBitsToDevice
= (const EMRSETDIBITSTODEVICE
*)mr
;
2133 SetDIBitsToDevice(hdc
,
2134 pSetDIBitsToDevice
->xDest
,
2135 pSetDIBitsToDevice
->yDest
,
2136 pSetDIBitsToDevice
->cxSrc
,
2137 pSetDIBitsToDevice
->cySrc
,
2138 pSetDIBitsToDevice
->xSrc
,
2139 pSetDIBitsToDevice
->ySrc
,
2140 pSetDIBitsToDevice
->iStartScan
,
2141 pSetDIBitsToDevice
->cScans
,
2142 (const BYTE
*)mr
+ pSetDIBitsToDevice
->offBitsSrc
,
2143 (const BITMAPINFO
*)((const BYTE
*)mr
+ pSetDIBitsToDevice
->offBmiSrc
),
2144 pSetDIBitsToDevice
->iUsageSrc
);
2148 case EMR_POLYTEXTOUTA
:
2150 const EMRPOLYTEXTOUTA
*pPolyTextOutA
= (const EMRPOLYTEXTOUTA
*)mr
;
2151 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
2153 XFORM xform
, xformOld
;
2156 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
2157 GetWorldTransform(hdc
, &xformOld
);
2159 xform
.eM11
= pPolyTextOutA
->exScale
;
2162 xform
.eM22
= pPolyTextOutA
->eyScale
;
2165 SetWorldTransform(hdc
, &xform
);
2167 /* Set up POLYTEXTA structures */
2168 for(i
= 0; i
< pPolyTextOutA
->cStrings
; i
++)
2170 polytextA
[i
].x
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.x
;
2171 polytextA
[i
].y
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.y
;
2172 polytextA
[i
].n
= pPolyTextOutA
->aemrtext
[i
].nChars
;
2173 polytextA
[i
].lpstr
= (LPCSTR
)((const BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offString
);
2174 polytextA
[i
].uiFlags
= pPolyTextOutA
->aemrtext
[i
].fOptions
;
2175 polytextA
[i
].rcl
.left
= pPolyTextOutA
->aemrtext
[i
].rcl
.left
;
2176 polytextA
[i
].rcl
.right
= pPolyTextOutA
->aemrtext
[i
].rcl
.right
;
2177 polytextA
[i
].rcl
.top
= pPolyTextOutA
->aemrtext
[i
].rcl
.top
;
2178 polytextA
[i
].rcl
.bottom
= pPolyTextOutA
->aemrtext
[i
].rcl
.bottom
;
2179 polytextA
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offDx
);
2181 PolyTextOutA(hdc
, polytextA
, pPolyTextOutA
->cStrings
);
2182 HeapFree(GetProcessHeap(), 0, polytextA
);
2184 SetWorldTransform(hdc
, &xformOld
);
2185 SetGraphicsMode(hdc
, gModeOld
);
2189 case EMR_POLYTEXTOUTW
:
2191 const EMRPOLYTEXTOUTW
*pPolyTextOutW
= (const EMRPOLYTEXTOUTW
*)mr
;
2192 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
2194 XFORM xform
, xformOld
;
2197 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
2198 GetWorldTransform(hdc
, &xformOld
);
2200 xform
.eM11
= pPolyTextOutW
->exScale
;
2203 xform
.eM22
= pPolyTextOutW
->eyScale
;
2206 SetWorldTransform(hdc
, &xform
);
2208 /* Set up POLYTEXTW structures */
2209 for(i
= 0; i
< pPolyTextOutW
->cStrings
; i
++)
2211 polytextW
[i
].x
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.x
;
2212 polytextW
[i
].y
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.y
;
2213 polytextW
[i
].n
= pPolyTextOutW
->aemrtext
[i
].nChars
;
2214 polytextW
[i
].lpstr
= (LPCWSTR
)((const BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offString
);
2215 polytextW
[i
].uiFlags
= pPolyTextOutW
->aemrtext
[i
].fOptions
;
2216 polytextW
[i
].rcl
.left
= pPolyTextOutW
->aemrtext
[i
].rcl
.left
;
2217 polytextW
[i
].rcl
.right
= pPolyTextOutW
->aemrtext
[i
].rcl
.right
;
2218 polytextW
[i
].rcl
.top
= pPolyTextOutW
->aemrtext
[i
].rcl
.top
;
2219 polytextW
[i
].rcl
.bottom
= pPolyTextOutW
->aemrtext
[i
].rcl
.bottom
;
2220 polytextW
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offDx
);
2222 PolyTextOutW(hdc
, polytextW
, pPolyTextOutW
->cStrings
);
2223 HeapFree(GetProcessHeap(), 0, polytextW
);
2225 SetWorldTransform(hdc
, &xformOld
);
2226 SetGraphicsMode(hdc
, gModeOld
);
2232 const EMRFILLRGN
*pFillRgn
= (const EMRFILLRGN
*)mr
;
2233 HRGN hRgn
= ExtCreateRegion(NULL
, pFillRgn
->cbRgnData
, (const RGNDATA
*)pFillRgn
->RgnData
);
2236 (handletable
->objectHandle
)[pFillRgn
->ihBrush
]);
2243 const EMRFRAMERGN
*pFrameRgn
= (const EMRFRAMERGN
*)mr
;
2244 HRGN hRgn
= ExtCreateRegion(NULL
, pFrameRgn
->cbRgnData
, (const RGNDATA
*)pFrameRgn
->RgnData
);
2247 (handletable
->objectHandle
)[pFrameRgn
->ihBrush
],
2248 pFrameRgn
->szlStroke
.cx
,
2249 pFrameRgn
->szlStroke
.cy
);
2256 const EMRINVERTRGN
*pInvertRgn
= (const EMRINVERTRGN
*)mr
;
2257 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (const RGNDATA
*)pInvertRgn
->RgnData
);
2258 InvertRgn(hdc
, hRgn
);
2265 const EMRPAINTRGN
*pPaintRgn
= (const EMRPAINTRGN
*)mr
;
2266 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (const RGNDATA
*)pPaintRgn
->RgnData
);
2267 PaintRgn(hdc
, hRgn
);
2272 case EMR_SETTEXTJUSTIFICATION
:
2274 const EMRSETTEXTJUSTIFICATION
*pSetTextJust
= (const EMRSETTEXTJUSTIFICATION
*)mr
;
2275 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
2281 const EMRSETLAYOUT
*pSetLayout
= (const EMRSETLAYOUT
*)mr
;
2282 SetLayout(hdc
, pSetLayout
->iMode
);
2286 case EMR_GRADIENTFILL
:
2288 EMRGRADIENTFILL
*grad
= (EMRGRADIENTFILL
*)mr
;
2289 GdiGradientFill( hdc
, grad
->Ver
, grad
->nVer
, grad
->Ver
+ grad
->nVer
,
2290 grad
->nTri
, grad
->ulMode
);
2295 case EMR_GLSBOUNDEDRECORD
:
2296 case EMR_DRAWESCAPE
:
2299 case EMR_SMALLTEXTOUT
:
2300 case EMR_FORCEUFIMAPPING
:
2301 case EMR_NAMEDESCAPE
:
2302 case EMR_COLORCORRECTPALETTE
:
2303 case EMR_SETICMPROFILEA
:
2304 case EMR_SETICMPROFILEW
:
2305 case EMR_TRANSPARENTBLT
:
2306 case EMR_SETLINKEDUFI
:
2307 case EMR_COLORMATCHTOTARGETW
:
2308 case EMR_CREATECOLORSPACEW
:
2311 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2312 record then ignore and return TRUE. */
2313 FIXME("type %d is unimplemented\n", type
);
2316 tmprc
.left
= tmprc
.top
= 0;
2317 tmprc
.right
= tmprc
.bottom
= 1000;
2318 LPtoDP(hdc
, (POINT
*)&tmprc
, 2);
2319 TRACE("L:0,0 - 1000,1000 -> D:%s\n", wine_dbgstr_rect(&tmprc
));
2325 /*****************************************************************************
2327 * EnumEnhMetaFile (GDI32.@)
2329 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2331 * record. Returns when either every record has been used or
2332 * when _EnhMetaFunc_ returns FALSE.
2336 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2343 * This function behaves differently in Win9x and WinNT.
2345 * In WinNT, the DC's world transform is updated as the EMF changes
2346 * the Window/Viewport Extent and Origin or its world transform.
2347 * The actual Window/Viewport Extent and Origin are left untouched.
2349 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2350 * updates the scaling itself but only just before a record that
2351 * writes anything to the DC.
2353 * I'm not sure where the data (enum_emh_data) is stored in either
2354 * version. For this implementation, it is stored before the handle
2355 * table, but it could be stored in the DC, in the EMF handle or in
2359 BOOL WINAPI
EnumEnhMetaFile(
2360 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
2361 HENHMETAFILE hmf
, /* [in] EMF to walk */
2362 ENHMFENUMPROC callback
, /* [in] callback function */
2363 LPVOID data
, /* [in] optional data for callback function */
2364 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
2376 HBRUSH hBrush
= NULL
;
2379 enum_emh_data
*info
;
2380 SIZE vp_size
, win_size
;
2381 POINT vp_org
, win_org
;
2382 INT mapMode
= MM_TEXT
, old_align
= 0, old_rop2
= 0, old_arcdir
= 0, old_polyfill
= 0, old_stretchblt
= 0;
2383 COLORREF old_text_color
= 0, old_bk_color
= 0;
2387 SetLastError(ERROR_INVALID_PARAMETER
);
2391 emh
= EMF_GetEnhMetaHeader(hmf
);
2393 SetLastError(ERROR_INVALID_HANDLE
);
2397 info
= HeapAlloc( GetProcessHeap(), 0,
2398 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2401 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2404 info
->state
.mode
= MM_TEXT
;
2405 info
->state
.wndOrgX
= 0;
2406 info
->state
.wndOrgY
= 0;
2407 info
->state
.wndExtX
= 1;
2408 info
->state
.wndExtY
= 1;
2409 info
->state
.vportOrgX
= 0;
2410 info
->state
.vportOrgY
= 0;
2411 info
->state
.vportExtX
= 1;
2412 info
->state
.vportExtY
= 1;
2413 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
2414 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
2415 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
2417 info
->state
.next
= NULL
;
2418 info
->save_level
= 0;
2419 info
->saved_state
= NULL
;
2420 info
->init_transform
= info
->state
.world_transform
;
2422 ht
= (HANDLETABLE
*) &info
[1];
2423 ht
->objectHandle
[0] = hmf
;
2424 for(i
= 1; i
< emh
->nHandles
; i
++)
2425 ht
->objectHandle
[i
] = NULL
;
2427 if (hdc
&& !is_meta_dc( hdc
))
2429 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
2430 GetWorldTransform(hdc
, &savedXform
);
2431 GetViewportExtEx(hdc
, &vp_size
);
2432 GetWindowExtEx(hdc
, &win_size
);
2433 GetViewportOrgEx(hdc
, &vp_org
);
2434 GetWindowOrgEx(hdc
, &win_org
);
2435 mapMode
= GetMapMode(hdc
);
2438 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
2439 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
2440 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
2442 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
2443 if (!GetClipRgn(hdc
, hRgn
))
2449 old_text_color
= SetTextColor(hdc
, RGB(0,0,0));
2450 old_bk_color
= SetBkColor(hdc
, RGB(0xff, 0xff, 0xff));
2451 old_align
= SetTextAlign(hdc
, 0);
2452 old_rop2
= SetROP2(hdc
, R2_COPYPEN
);
2453 old_arcdir
= SetArcDirection(hdc
, AD_COUNTERCLOCKWISE
);
2454 old_polyfill
= SetPolyFillMode(hdc
, ALTERNATE
);
2455 old_stretchblt
= SetStretchBltMode(hdc
, BLACKONWHITE
);
2459 /* WinNT combines the vp/win ext/org info into a transform */
2460 double xscale
, yscale
;
2461 xscale
= (double)vp_size
.cx
/ (double)win_size
.cx
;
2462 yscale
= (double)vp_size
.cy
/ (double)win_size
.cy
;
2463 info
->init_transform
.eM11
= xscale
;
2464 info
->init_transform
.eM12
= 0.0;
2465 info
->init_transform
.eM21
= 0.0;
2466 info
->init_transform
.eM22
= yscale
;
2467 info
->init_transform
.eDx
= (double)vp_org
.x
- xscale
* (double)win_org
.x
;
2468 info
->init_transform
.eDy
= (double)vp_org
.y
- yscale
* (double)win_org
.y
;
2470 CombineTransform(&info
->init_transform
, &savedXform
, &info
->init_transform
);
2473 if ( lpRect
&& WIDTH(emh
->rclFrame
) && HEIGHT(emh
->rclFrame
) )
2475 double xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
2478 TRACE("rect: %s. rclFrame: (%ld,%ld)-(%ld,%ld)\n", wine_dbgstr_rect(lpRect
),
2479 emh
->rclFrame
.left
, emh
->rclFrame
.top
, emh
->rclFrame
.right
,
2480 emh
->rclFrame
.bottom
);
2482 xSrcPixSize
= (double) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
2483 ySrcPixSize
= (double) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
2484 xscale
= (double) WIDTH(*lpRect
) * 100.0 /
2485 WIDTH(emh
->rclFrame
) * xSrcPixSize
;
2486 yscale
= (double) HEIGHT(*lpRect
) * 100.0 /
2487 HEIGHT(emh
->rclFrame
) * ySrcPixSize
;
2488 TRACE("xscale = %f, yscale = %f\n", xscale
, yscale
);
2490 xform
.eM11
= xscale
;
2493 xform
.eM22
= yscale
;
2494 xform
.eDx
= (double) lpRect
->left
- (double) WIDTH(*lpRect
) / WIDTH(emh
->rclFrame
) * emh
->rclFrame
.left
;
2495 xform
.eDy
= (double) lpRect
->top
- (double) HEIGHT(*lpRect
) / HEIGHT(emh
->rclFrame
) * emh
->rclFrame
.top
;
2497 CombineTransform(&info
->init_transform
, &xform
, &info
->init_transform
);
2500 /* WinNT resets the current vp/win org/ext */
2503 SetMapMode(hdc
, MM_TEXT
);
2504 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2505 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2506 EMF_Update_MF_Xform(hdc
, info
);
2512 while(ret
&& offset
< emh
->nBytes
)
2514 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
2516 if (offset
+ 8 > emh
->nBytes
||
2517 offset
> offset
+ emr
->nSize
||
2518 offset
+ emr
->nSize
> emh
->nBytes
)
2520 WARN("record truncated\n");
2524 /* In Win9x mode we update the xform if the record will produce output */
2525 if (hdc
&& IS_WIN9X() && emr_produces_output(emr
->iType
))
2526 EMF_Update_MF_Xform(hdc
, info
);
2528 TRACE("Calling EnumFunc with record %s, size %ld\n", get_emr_name(emr
->iType
), emr
->nSize
);
2529 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nHandles
, (LPARAM
)data
);
2530 offset
+= emr
->nSize
;
2533 if (hdc
&& !is_meta_dc( hdc
))
2535 SetStretchBltMode(hdc
, old_stretchblt
);
2536 SetPolyFillMode(hdc
, old_polyfill
);
2537 SetArcDirection(hdc
, old_arcdir
);
2538 SetROP2(hdc
, old_rop2
);
2539 SetTextAlign(hdc
, old_align
);
2540 SetBkColor(hdc
, old_bk_color
);
2541 SetTextColor(hdc
, old_text_color
);
2544 SelectObject(hdc
, hBrush
);
2545 SelectObject(hdc
, hPen
);
2546 SelectObject(hdc
, hFont
);
2547 ExtSelectClipRgn(hdc
, hRgn
, RGN_COPY
);
2550 SetWorldTransform(hdc
, &savedXform
);
2552 SetGraphicsMode(hdc
, savedMode
);
2553 SetMapMode(hdc
, mapMode
);
2554 SetWindowOrgEx(hdc
, win_org
.x
, win_org
.y
, NULL
);
2555 SetWindowExtEx(hdc
, win_size
.cx
, win_size
.cy
, NULL
);
2556 SetViewportOrgEx(hdc
, vp_org
.x
, vp_org
.y
, NULL
);
2557 SetViewportExtEx(hdc
, vp_size
.cx
, vp_size
.cy
, NULL
);
2560 for(i
= 1; i
< emh
->nHandles
; i
++) /* Don't delete element 0 (hmf) */
2561 if( (ht
->objectHandle
)[i
] )
2562 DeleteObject( (ht
->objectHandle
)[i
] );
2564 while (info
->saved_state
)
2566 EMF_dc_state
*state
= info
->saved_state
;
2567 info
->saved_state
= info
->saved_state
->next
;
2568 HeapFree( GetProcessHeap(), 0, state
);
2570 HeapFree( GetProcessHeap(), 0, info
);
2574 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
2575 const ENHMETARECORD
*emr
,
2576 INT handles
, LPARAM data
)
2578 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
2581 /**************************************************************************
2582 * PlayEnhMetaFile (GDI32.@)
2584 * Renders an enhanced metafile into a specified rectangle *lpRect
2585 * in device context hdc.
2591 BOOL WINAPI
PlayEnhMetaFile(
2592 HDC hdc
, /* [in] DC to render into */
2593 HENHMETAFILE hmf
, /* [in] metafile to render */
2594 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
2597 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
2601 /*****************************************************************************
2602 * DeleteEnhMetaFile (GDI32.@)
2604 * Deletes an enhanced metafile and frees the associated storage.
2606 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
2608 return EMF_Delete_HENHMETAFILE( hmf
);
2611 /*****************************************************************************
2612 * CopyEnhMetaFileA (GDI32.@)
2614 * Duplicate an enhanced metafile.
2618 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
2619 HENHMETAFILE hmfSrc
,
2622 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2623 HENHMETAFILE hmfDst
;
2625 if(!emrSrc
) return FALSE
;
2627 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2628 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2629 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2631 HeapFree( GetProcessHeap(), 0, emrDst
);
2635 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2636 NULL
, CREATE_ALWAYS
, 0, 0);
2637 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2638 CloseHandle( hFile
);
2639 /* Reopen file for reading only, so that apps can share
2640 read access to the file while hmf is still valid */
2641 hFile
= CreateFileA( file
, GENERIC_READ
, FILE_SHARE_READ
,
2642 NULL
, OPEN_EXISTING
, 0, 0);
2643 if(hFile
== INVALID_HANDLE_VALUE
) {
2644 ERR("Can't reopen emf for reading\n");
2647 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2648 CloseHandle( hFile
);
2653 /*****************************************************************************
2654 * CopyEnhMetaFileW (GDI32.@)
2656 * See CopyEnhMetaFileA.
2660 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2661 HENHMETAFILE hmfSrc
,
2664 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2665 HENHMETAFILE hmfDst
;
2667 if(!emrSrc
) return FALSE
;
2669 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2670 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2671 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2673 HeapFree( GetProcessHeap(), 0, emrDst
);
2677 hFile
= CreateFileW( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2678 NULL
, CREATE_ALWAYS
, 0, 0);
2679 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2680 CloseHandle( hFile
);
2681 /* Reopen file for reading only, so that apps can share
2682 read access to the file while hmf is still valid */
2683 hFile
= CreateFileW( file
, GENERIC_READ
, FILE_SHARE_READ
,
2684 NULL
, OPEN_EXISTING
, 0, 0);
2685 if(hFile
== INVALID_HANDLE_VALUE
) {
2686 ERR("Can't reopen emf for reading\n");
2689 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2690 CloseHandle( hFile
);
2696 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2697 typedef struct tagEMF_PaletteCopy
2700 LPPALETTEENTRY lpPe
;
2703 /***************************************************************
2704 * Find the EMR_EOF record and then use it to find the
2705 * palette entries for this enhanced metafile.
2706 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2707 * which contains the max number of elements to copy and where
2710 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2712 static INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2714 const ENHMETARECORD
*lpEMR
,
2719 if ( lpEMR
->iType
== EMR_EOF
)
2721 const EMREOF
*lpEof
= (const EMREOF
*)lpEMR
;
2722 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
2723 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
2725 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy
);
2727 memcpy( info
->lpPe
, (LPCSTR
)lpEof
+ lpEof
->offPalEntries
,
2728 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
2730 /* Update the passed data as a return code */
2731 info
->lpPe
= NULL
; /* Palettes were copied! */
2732 info
->cEntries
= dwNumPalToCopy
;
2734 return FALSE
; /* That's all we need */
2740 /*****************************************************************************
2741 * GetEnhMetaFilePaletteEntries (GDI32.@)
2743 * Copy the palette and report size
2745 * BUGS: Error codes (SetLastError) are not set on failures
2747 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
2749 LPPALETTEENTRY lpPe
)
2751 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
2752 EMF_PaletteCopy infoForCallBack
;
2754 TRACE( "(%p,%d,%p)\n", hEmf
, cEntries
, lpPe
);
2756 if (!enhHeader
) return 0;
2758 /* First check if there are any palettes associated with
2760 if ( enhHeader
->nPalEntries
== 0 ) return 0;
2762 /* Is the user requesting the number of palettes? */
2763 if ( lpPe
== NULL
) return enhHeader
->nPalEntries
;
2765 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2766 infoForCallBack
.cEntries
= cEntries
;
2767 infoForCallBack
.lpPe
= lpPe
;
2769 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
2770 &infoForCallBack
, 0 ) )
2773 /* Verify that the callback executed correctly */
2774 if ( infoForCallBack
.lpPe
!= NULL
)
2776 /* Callback proc had error! */
2777 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2781 return infoForCallBack
.cEntries
;
2784 /******************************************************************
2785 * extract_emf_from_comment
2787 * If the WMF was created by GetWinMetaFileBits, then extract the
2788 * original EMF that is stored in MFCOMMENT chunks.
2790 static HENHMETAFILE
extract_emf_from_comment( const BYTE
*buf
, UINT mf_size
)
2792 METAHEADER
*mh
= (METAHEADER
*)buf
;
2794 emf_in_wmf_comment
*chunk
;
2796 DWORD size
= 0, remaining
, chunks
;
2797 BYTE
*emf_bits
= NULL
, *ptr
;
2799 HENHMETAFILE emf
= NULL
;
2801 if (mf_size
< sizeof(*mh
)) return NULL
;
2803 for (offset
= mh
->mtHeaderSize
* 2; offset
< mf_size
; offset
+= (mr
->rdSize
* 2))
2805 mr
= (METARECORD
*)((char *)mh
+ offset
);
2806 chunk
= (emf_in_wmf_comment
*)(mr
->rdParm
+ 2);
2808 if (mr
->rdFunction
!= META_ESCAPE
|| mr
->rdParm
[0] != MFCOMMENT
) goto done
;
2809 if (chunk
->comment_id
!= WMFC_MAGIC
) goto done
;
2813 size
= remaining
= chunk
->emf_size
;
2814 chunks
= chunk
->num_chunks
;
2815 emf_bits
= ptr
= HeapAlloc( GetProcessHeap(), 0, size
);
2816 if (!emf_bits
) goto done
;
2818 if (chunk
->chunk_size
> remaining
) goto done
;
2819 remaining
-= chunk
->chunk_size
;
2820 if (chunk
->remaining_size
!= remaining
) goto done
;
2821 memcpy( ptr
, chunk
->emf_data
, chunk
->chunk_size
);
2822 ptr
+= chunk
->chunk_size
;
2823 if (--chunks
== 0) break;
2826 for (offset
= 0; offset
< mf_size
/ 2; offset
++)
2827 checksum
+= *((WORD
*)buf
+ offset
);
2828 if (checksum
) goto done
;
2830 emf
= SetEnhMetaFileBits( size
, emf_bits
);
2833 HeapFree( GetProcessHeap(), 0, emf_bits
);
2837 typedef struct wmf_in_emf_comment
2844 DWORD cbWinMetaFile
;
2845 } wmf_in_emf_comment
;
2847 /******************************************************************
2848 * SetWinMetaFileBits (GDI32.@)
2850 * Translate from old style to new style.
2853 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
, const BYTE
*lpbBuffer
, HDC hdcRef
,
2854 const METAFILEPICT
*lpmfp
)
2856 HMETAFILE hmf
= NULL
;
2857 HENHMETAFILE ret
= NULL
;
2858 HDC hdc
= NULL
, hdcdisp
= NULL
;
2859 RECT rc
, *prcFrame
= NULL
;
2860 LONG mm
, xExt
, yExt
;
2861 INT horzsize
, vertsize
, horzres
, vertres
;
2863 TRACE("(%d, %p, %p, %p)\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
2865 hmf
= SetMetaFileBitsEx(cbBuffer
, lpbBuffer
);
2868 WARN("SetMetaFileBitsEx failed\n");
2872 ret
= extract_emf_from_comment( lpbBuffer
, cbBuffer
);
2873 if (ret
) return ret
;
2876 hdcRef
= hdcdisp
= CreateDCW(L
"DISPLAY", NULL
, NULL
, NULL
);
2880 TRACE("mm = %ld %ldx%ld\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2888 TRACE("lpmfp == NULL\n");
2890 /* Use the whole device surface */
2891 mm
= MM_ANISOTROPIC
;
2896 if (mm
== MM_ISOTROPIC
|| mm
== MM_ANISOTROPIC
)
2898 if (xExt
< 0 || yExt
< 0)
2900 /* Use the whole device surface */
2905 /* Use the x and y extents as the frame box */
2908 rc
.left
= rc
.top
= 0;
2915 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
)))
2917 ERR("CreateEnhMetaFile failed\n");
2922 * Write the original METAFILE into the enhanced metafile.
2923 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2927 wmf_in_emf_comment
*mfcomment
;
2928 UINT mfcomment_size
;
2930 mfcomment_size
= sizeof (*mfcomment
) + cbBuffer
;
2931 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
2934 mfcomment
->ident
= GDICOMMENT_IDENTIFIER
;
2935 mfcomment
->iComment
= GDICOMMENT_WINDOWS_METAFILE
;
2936 mfcomment
->nVersion
= 0x00000300;
2937 mfcomment
->nChecksum
= 0; /* FIXME */
2938 mfcomment
->fFlags
= 0;
2939 mfcomment
->cbWinMetaFile
= cbBuffer
;
2940 memcpy(&mfcomment
[1], lpbBuffer
, cbBuffer
);
2941 GdiComment(hdc
, mfcomment_size
, (BYTE
*) mfcomment
);
2942 HeapFree(GetProcessHeap(), 0, mfcomment
);
2944 SetMapMode(hdc
, mm
);
2948 horzsize
= GetDeviceCaps(hdcRef
, HORZSIZE
);
2949 vertsize
= GetDeviceCaps(hdcRef
, VERTSIZE
);
2950 horzres
= GetDeviceCaps(hdcRef
, HORZRES
);
2951 vertres
= GetDeviceCaps(hdcRef
, VERTRES
);
2955 /* Use the whole device surface */
2961 xExt
= MulDiv(xExt
, horzres
, 100 * horzsize
);
2962 yExt
= MulDiv(yExt
, vertres
, 100 * vertsize
);
2965 /* set the initial viewport:window ratio as 1:1 */
2966 SetViewportExtEx(hdc
, xExt
, yExt
, NULL
);
2967 SetWindowExtEx(hdc
, xExt
, yExt
, NULL
);
2969 PlayMetaFile(hdc
, hmf
);
2971 ret
= CloseEnhMetaFile(hdc
);
2973 if (hdcdisp
) DeleteDC(hdcdisp
);
2974 DeleteMetaFile(hmf
);