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
:
771 static HGDIOBJ
get_object_handle(HANDLETABLE
*handletable
, DWORD i
)
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.
784 * TRUE (non zero) on success, FALSE on error.
786 * Many unimplemented records.
787 * No error handling on record play failures (ie checking return codes)
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 */
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
;
810 TRACE("record %s\n", get_emr_name(type
));
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
);
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
))
831 info
->state
.mode
= pSetMapMode
->iMode
;
832 EMF_SetMapMode(hdc
, info
);
835 EMF_Update_MF_Xform(hdc
, info
);
841 const EMRSETBKMODE
*pSetBkMode
= (const EMRSETBKMODE
*)mr
;
842 SetBkMode(hdc
, pSetBkMode
->iMode
);
847 const EMRSETBKCOLOR
*pSetBkColor
= (const EMRSETBKCOLOR
*)mr
;
848 SetBkColor(hdc
, pSetBkColor
->crColor
);
851 case EMR_SETPOLYFILLMODE
:
853 const EMRSETPOLYFILLMODE
*pSetPolyFillMode
= (const EMRSETPOLYFILLMODE
*)mr
;
854 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
859 const EMRSETROP2
*pSetROP2
= (const EMRSETROP2
*)mr
;
860 SetROP2(hdc
, pSetROP2
->iMode
);
863 case EMR_SETSTRETCHBLTMODE
:
865 const EMRSETSTRETCHBLTMODE
*pSetStretchBltMode
= (const EMRSETSTRETCHBLTMODE
*)mr
;
866 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
869 case EMR_SETTEXTALIGN
:
871 const EMRSETTEXTALIGN
*pSetTextAlign
= (const EMRSETTEXTALIGN
*)mr
;
872 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
875 case EMR_SETTEXTCOLOR
:
877 const EMRSETTEXTCOLOR
*pSetTextColor
= (const EMRSETTEXTCOLOR
*)mr
;
878 SetTextColor(hdc
, pSetTextColor
->crColor
);
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
);
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
);
905 case EMR_SELECTOBJECT
:
907 const EMRSELECTOBJECT
*pSelectObject
= (const EMRSELECTOBJECT
*)mr
;
908 SelectObject( hdc
, get_object_handle(handletable
, pSelectObject
->ihObject
) );
911 case EMR_DELETEOBJECT
:
913 const EMRDELETEOBJECT
*pDeleteObject
= (const EMRDELETEOBJECT
*)mr
;
914 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
915 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
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
);
928 EMF_Update_MF_Xform(hdc
, info
);
932 case EMR_SETWINDOWEXTEX
:
934 const EMRSETWINDOWEXTEX
*pSetWindowExtEx
= (const EMRSETWINDOWEXTEX
*)mr
;
936 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
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
);
946 EMF_Update_MF_Xform(hdc
, info
);
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
);
959 EMF_Update_MF_Xform(hdc
, info
);
963 case EMR_SETVIEWPORTEXTEX
:
965 const EMRSETVIEWPORTEXTEX
*pSetViewportExtEx
= (const EMRSETVIEWPORTEXTEX
*)mr
;
967 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
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
);
976 EMF_Update_MF_Xform(hdc
, info
);
982 const EMRCREATEPEN
*pCreatePen
= (const EMRCREATEPEN
*)mr
;
983 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
984 CreatePenIndirect(&pCreatePen
->lopn
);
987 case EMR_EXTCREATEPEN
:
989 const EMREXTCREATEPEN
*pPen
= (const EMREXTCREATEPEN
*)mr
;
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
);
1003 case EMR_CREATEBRUSHINDIRECT
:
1005 const EMRCREATEBRUSHINDIRECT
*pBrush
= (const EMRCREATEBRUSHINDIRECT
*)mr
;
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
);
1013 case EMR_EXTCREATEFONTINDIRECTW
:
1015 const EMREXTCREATEFONTINDIRECTW
*pFont
= (const EMREXTCREATEFONTINDIRECTW
*)mr
;
1016 (handletable
->objectHandle
)[pFont
->ihFont
] =
1017 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
1022 const EMRMOVETOEX
*pMoveToEx
= (const EMRMOVETOEX
*)mr
;
1023 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
1028 const EMRLINETO
*pLineTo
= (const EMRLINETO
*)mr
;
1029 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
1034 const EMRRECTANGLE
*pRect
= (const EMRRECTANGLE
*)mr
;
1035 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
1036 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
1041 const EMRELLIPSE
*pEllipse
= (const EMRELLIPSE
*)mr
;
1042 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
1043 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
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
) );
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
);
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
) );
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
);
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
) );
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
);
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
) );
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
);
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
) );
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
);
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
) );
1135 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1140 PolyPolygon(hdc
, pt
, (const INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1141 HeapFree( GetProcessHeap(), 0, pt
);
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
) );
1153 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1158 PolyPolyline(hdc
, pt
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1159 HeapFree( GetProcessHeap(), 0, pt
);
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
));
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
);
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
);
1188 case EMR_STRETCHDIBITS
:
1190 const EMRSTRETCHDIBITS
*pStretchDIBits
= (const EMRSTRETCHDIBITS
*)mr
;
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
);
1208 case EMR_EXTTEXTOUTA
:
1210 const EMREXTTEXTOUTA
*pExtTextOutA
= (const EMREXTTEXTOUTA
*)mr
;
1212 const INT
*dx
= NULL
;
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
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
,
1240 SetGraphicsMode(hdc
, old_mode
);
1244 case EMR_EXTTEXTOUTW
:
1246 const EMREXTTEXTOUTW
*pExtTextOutW
= (const EMREXTTEXTOUTW
*)mr
;
1248 const INT
*dx
= NULL
;
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
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
,
1276 SetGraphicsMode(hdc
, old_mode
);
1280 case EMR_CREATEPALETTE
:
1282 const EMRCREATEPALETTE
*lpCreatePal
= (const EMRCREATEPALETTE
*)mr
;
1284 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1285 CreatePalette( &lpCreatePal
->lgpl
);
1290 case EMR_SELECTPALETTE
:
1292 const EMRSELECTPALETTE
*lpSelectPal
= (const EMRSELECTPALETTE
*)mr
;
1294 SelectPalette( hdc
, get_object_handle(handletable
, lpSelectPal
->ihPal
), TRUE
);
1298 case EMR_REALIZEPALETTE
:
1300 RealizePalette( hdc
);
1304 case EMR_EXTSELECTCLIPRGN
:
1306 const EMREXTSELECTCLIPRGN
*lpRgn
= (const EMREXTSELECTCLIPRGN
*)mr
;
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 */
1318 case EMR_SETMETARGN
:
1324 case EMR_SETWORLDTRANSFORM
:
1326 const EMRSETWORLDTRANSFORM
*lpXfrm
= (const EMRSETWORLDTRANSFORM
*)mr
;
1327 info
->state
.world_transform
= lpXfrm
->xform
;
1330 EMF_Update_MF_Xform(hdc
, info
);
1335 case EMR_POLYBEZIER
:
1337 const EMRPOLYBEZIER
*lpPolyBez
= (const EMRPOLYBEZIER
*)mr
;
1338 PolyBezier(hdc
, (const POINT
*)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1344 const EMRPOLYGON
*lpPoly
= (const EMRPOLYGON
*)mr
;
1345 Polygon( hdc
, (const POINT
*)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1351 const EMRPOLYLINE
*lpPolyLine
= (const EMRPOLYLINE
*)mr
;
1352 Polyline(hdc
, (const POINT
*)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1356 case EMR_POLYBEZIERTO
:
1358 const EMRPOLYBEZIERTO
*lpPolyBezierTo
= (const EMRPOLYBEZIERTO
*)mr
;
1359 PolyBezierTo( hdc
, (const POINT
*)lpPolyBezierTo
->aptl
,
1360 (UINT
)lpPolyBezierTo
->cptl
);
1364 case EMR_POLYLINETO
:
1366 const EMRPOLYLINETO
*lpPolyLineTo
= (const EMRPOLYLINETO
*)mr
;
1367 PolylineTo( hdc
, (const POINT
*)lpPolyLineTo
->aptl
,
1368 (UINT
)lpPolyLineTo
->cptl
);
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
);
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
);
1397 case EMR_SETBRUSHORGEX
:
1399 const EMRSETBRUSHORGEX
*lpSetBrushOrgEx
= (const EMRSETBRUSHORGEX
*)mr
;
1402 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1403 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1411 const EMRSETPIXELV
*lpSetPixelV
= (const EMRSETPIXELV
*)mr
;
1414 (INT
)lpSetPixelV
->ptlPixel
.x
,
1415 (INT
)lpSetPixelV
->ptlPixel
.y
,
1416 lpSetPixelV
->crColor
);
1421 case EMR_SETMAPPERFLAGS
:
1423 const EMRSETMAPPERFLAGS
*lpSetMapperFlags
= (const EMRSETMAPPERFLAGS
*)mr
;
1425 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1430 case EMR_SETCOLORADJUSTMENT
:
1432 const EMRSETCOLORADJUSTMENT
*lpSetColorAdjust
= (const EMRSETCOLORADJUSTMENT
*)mr
;
1434 NtGdiSetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1439 case EMR_OFFSETCLIPRGN
:
1441 const EMROFFSETCLIPRGN
*lpOffsetClipRgn
= (const EMROFFSETCLIPRGN
*)mr
;
1444 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1445 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1446 FIXME("OffsetClipRgn\n");
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");
1465 case EMR_SCALEVIEWPORTEXTEX
:
1467 const EMRSCALEVIEWPORTEXTEX
*lpScaleViewportExtEx
= (const EMRSCALEVIEWPORTEXTEX
*)mr
;
1469 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1471 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1472 !lpScaleViewportExtEx
->yNum
|| !lpScaleViewportExtEx
->yDenom
)
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
);
1488 EMF_Update_MF_Xform(hdc
, info
);
1493 case EMR_SCALEWINDOWEXTEX
:
1495 const EMRSCALEWINDOWEXTEX
*lpScaleWindowExtEx
= (const EMRSCALEWINDOWEXTEX
*)mr
;
1497 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1499 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1500 !lpScaleWindowExtEx
->yNum
|| !lpScaleWindowExtEx
->yDenom
)
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
);
1516 EMF_Update_MF_Xform(hdc
, info
);
1521 case EMR_MODIFYWORLDTRANSFORM
:
1523 const EMRMODIFYWORLDTRANSFORM
*lpModifyWorldTrans
= (const EMRMODIFYWORLDTRANSFORM
*)mr
;
1525 switch(lpModifyWorldTrans
->iMode
) {
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;
1531 EMF_Update_MF_Xform(hdc
, info
);
1533 case MWT_LEFTMULTIPLY
:
1534 CombineTransform(&info
->state
.world_transform
, &lpModifyWorldTrans
->xform
,
1535 &info
->state
.world_transform
);
1537 ModifyWorldTransform(hdc
, &lpModifyWorldTrans
->xform
, MWT_LEFTMULTIPLY
);
1539 case MWT_RIGHTMULTIPLY
:
1540 CombineTransform(&info
->state
.world_transform
, &info
->state
.world_transform
,
1541 &lpModifyWorldTrans
->xform
);
1543 EMF_Update_MF_Xform(hdc
, info
);
1546 FIXME("Unknown imode %ld\n", lpModifyWorldTrans
->iMode
);
1554 const EMRANGLEARC
*lpAngleArc
= (const EMRANGLEARC
*)mr
;
1557 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1558 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1559 lpAngleArc
->eSweepAngle
);
1566 const EMRROUNDRECT
*lpRoundRect
= (const EMRROUNDRECT
*)mr
;
1569 lpRoundRect
->rclBox
.left
,
1570 lpRoundRect
->rclBox
.top
,
1571 lpRoundRect
->rclBox
.right
,
1572 lpRoundRect
->rclBox
.bottom
,
1573 lpRoundRect
->szlCorner
.cx
,
1574 lpRoundRect
->szlCorner
.cy
);
1581 const EMRARC
*lpArc
= (const EMRARC
*)mr
;
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
);
1598 const EMRCHORD
*lpChord
= (const EMRCHORD
*)mr
;
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
);
1615 const EMRPIE
*lpPie
= (const EMRPIE
*)mr
;
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
);
1632 const EMRARC
*lpArcTo
= (const EMRARC
*)mr
;
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
);
1647 case EMR_EXTFLOODFILL
:
1649 const EMREXTFLOODFILL
*lpExtFloodFill
= (const EMREXTFLOODFILL
*)mr
;
1652 (INT
)lpExtFloodFill
->ptlStart
.x
,
1653 (INT
)lpExtFloodFill
->ptlStart
.y
,
1654 lpExtFloodFill
->crColor
,
1655 (UINT
)lpExtFloodFill
->iMode
);
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. */
1667 (const POINT
*)lpPolyDraw
->aptl
,
1668 (BYTE
*)(lpPolyDraw
->aptl
+ lpPolyDraw
->cptl
),
1669 (INT
)lpPolyDraw
->cptl
);
1674 case EMR_SETARCDIRECTION
:
1676 const EMRSETARCDIRECTION
*lpSetArcDirection
= (const EMRSETARCDIRECTION
*)mr
;
1677 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1681 case EMR_SETMITERLIMIT
:
1683 const EMRSETMITERLIMIT
*lpSetMiterLimit
= (const EMRSETMITERLIMIT
*)mr
;
1684 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1700 case EMR_CLOSEFIGURE
:
1708 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1713 case EMR_STROKEANDFILLPATH
:
1715 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1716 StrokeAndFillPath( hdc
);
1720 case EMR_STROKEPATH
:
1722 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1727 case EMR_FLATTENPATH
:
1739 case EMR_SELECTCLIPPATH
:
1741 const EMRSELECTCLIPPATH
*lpSelectClipPath
= (const EMRSELECTCLIPPATH
*)mr
;
1742 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1752 case EMR_CREATECOLORSPACE
:
1754 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1755 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1756 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1760 case EMR_SETCOLORSPACE
:
1762 const EMRSETCOLORSPACE
*lpSetColorSpace
= (const EMRSETCOLORSPACE
*)mr
;
1764 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1768 case EMR_DELETECOLORSPACE
:
1770 const EMRDELETECOLORSPACE
*lpDeleteColorSpace
= (const EMRDELETECOLORSPACE
*)mr
;
1771 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1775 case EMR_SETICMMODE
:
1777 const EMRSETICMMODE
*lpSetICMMode
= (const EMRSETICMMODE
*)mr
;
1778 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1782 case EMR_PIXELFORMAT
:
1785 const EMRPIXELFORMAT
*lpPixelFormat
= (const EMRPIXELFORMAT
*)mr
;
1787 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1788 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
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
);
1805 case EMR_RESIZEPALETTE
:
1807 const EMRRESIZEPALETTE
*lpResizePalette
= (const EMRRESIZEPALETTE
*)mr
;
1809 NtGdiResizePalette( handletable
->objectHandle
[lpResizePalette
->ihPal
],
1810 lpResizePalette
->cEntries
);
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");
1831 if (lpCreate
->offBmi
+ lpCreate
->cbBmi
!= lpCreate
->offBits
)
1833 ERR("Invalid data in EMR_CREATEDIBPATTERNBRUSHPT record\n");
1837 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1838 CreateDIBPatternBrushPt( (const BYTE
*)lpCreate
+ lpCreate
->offBmi
,
1839 (UINT
)lpCreate
->iUsage
);
1843 case EMR_CREATEMONOBRUSH
:
1845 const EMRCREATEMONOBRUSH
*pCreateMonoBrush
= (const EMRCREATEMONOBRUSH
*)mr
;
1846 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
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
);
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 */
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
,
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
);
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
);
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");
1967 HDC hdcSrc
= NtGdiCreateCompatibleDC( hdc
);
1968 HBITMAP hBmp
= 0, hBmpOld
= 0;
1969 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pAlphaBlend
->offBmiSrc
);
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
);
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
,
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
);
2031 SelectObject(hdcSrc
, hBmpOld
);
2033 DeleteObject(hBmpMask
);
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
;
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
,
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
);
2082 SelectObject(hdcSrc
, hBmpOld
);
2084 DeleteObject(hBmpMask
);
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
);
2108 case EMR_POLYTEXTOUTA
:
2110 const EMRPOLYTEXTOUTA
*pPolyTextOutA
= (const EMRPOLYTEXTOUTA
*)mr
;
2111 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
2113 XFORM xform
, xformOld
;
2116 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
2117 GetWorldTransform(hdc
, &xformOld
);
2119 xform
.eM11
= pPolyTextOutA
->exScale
;
2122 xform
.eM22
= pPolyTextOutA
->eyScale
;
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
);
2149 case EMR_POLYTEXTOUTW
:
2151 const EMRPOLYTEXTOUTW
*pPolyTextOutW
= (const EMRPOLYTEXTOUTW
*)mr
;
2152 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
2154 XFORM xform
, xformOld
;
2157 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
2158 GetWorldTransform(hdc
, &xformOld
);
2160 xform
.eM11
= pPolyTextOutW
->exScale
;
2163 xform
.eM22
= pPolyTextOutW
->eyScale
;
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
);
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
));
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
);
2211 const EMRINVERTRGN
*pInvertRgn
= (const EMRINVERTRGN
*)mr
;
2212 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (const RGNDATA
*)pInvertRgn
->RgnData
);
2213 InvertRgn(hdc
, hRgn
);
2220 const EMRPAINTRGN
*pPaintRgn
= (const EMRPAINTRGN
*)mr
;
2221 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (const RGNDATA
*)pPaintRgn
->RgnData
);
2222 PaintRgn(hdc
, hRgn
);
2227 case EMR_SETTEXTJUSTIFICATION
:
2229 const EMRSETTEXTJUSTIFICATION
*pSetTextJust
= (const EMRSETTEXTJUSTIFICATION
*)mr
;
2230 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
2236 const EMRSETLAYOUT
*pSetLayout
= (const EMRSETLAYOUT
*)mr
;
2237 SetLayout(hdc
, pSetLayout
->iMode
);
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");
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
);
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
);
2297 case EMR_GLSBOUNDEDRECORD
:
2298 case EMR_DRAWESCAPE
:
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
:
2312 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2313 record then ignore and return TRUE. */
2314 FIXME("type %d is unimplemented\n", type
);
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
));
2326 /*****************************************************************************
2328 * EnumEnhMetaFile (GDI32.@)
2330 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2332 * record. Returns when either every record has been used or
2333 * when _EnhMetaFunc_ returns FALSE.
2337 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
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
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 */
2377 HBRUSH hBrush
= 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;
2388 SetLastError(ERROR_INVALID_PARAMETER
);
2392 emh
= EMF_GetEnhMetaHeader(hmf
);
2394 SetLastError(ERROR_INVALID_HANDLE
);
2398 info
= HeapAlloc( GetProcessHeap(), 0,
2399 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2402 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
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
);
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
))
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
);
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
;
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
;
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 */
2504 SetMapMode(hdc
, MM_TEXT
);
2505 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2506 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2507 EMF_Update_MF_Xform(hdc
, info
);
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");
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
);
2545 SelectObject(hdc
, hBrush
);
2546 SelectObject(hdc
, hPen
);
2547 SelectObject(hdc
, hFont
);
2548 ExtSelectClipRgn(hdc
, hRgn
, RGN_COPY
);
2551 SetWorldTransform(hdc
, &savedXform
);
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
);
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.
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
,
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
,
2623 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2624 HENHMETAFILE hmfDst
;
2626 if(!emrSrc
) return FALSE
;
2628 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2629 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2630 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2632 HeapFree( GetProcessHeap(), 0, emrDst
);
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");
2648 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2649 CloseHandle( hFile
);
2654 /*****************************************************************************
2655 * CopyEnhMetaFileW (GDI32.@)
2657 * See CopyEnhMetaFileA.
2661 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2662 HENHMETAFILE hmfSrc
,
2665 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2666 HENHMETAFILE hmfDst
;
2668 if(!emrSrc
) return FALSE
;
2670 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2671 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2672 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2674 HeapFree( GetProcessHeap(), 0, emrDst
);
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");
2690 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2691 CloseHandle( hFile
);
2697 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2698 typedef struct tagEMF_PaletteCopy
2701 LPPALETTEENTRY lpPe
;
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
2711 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2713 static INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2715 const ENHMETARECORD
*lpEMR
,
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 */
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
,
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
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 ) )
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" );
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
;
2795 emf_in_wmf_comment
*chunk
;
2797 DWORD size
= 0, remaining
, chunks
;
2798 BYTE
*emf_bits
= NULL
, *ptr
;
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
;
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
);
2834 HeapFree( GetProcessHeap(), 0, emf_bits
);
2838 typedef struct wmf_in_emf_comment
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
);
2869 WARN("SetMetaFileBitsEx failed\n");
2873 ret
= extract_emf_from_comment( lpbBuffer
, cbBuffer
);
2874 if (ret
) return ret
;
2877 hdcRef
= hdcdisp
= CreateDCW(L
"DISPLAY", NULL
, NULL
, NULL
);
2881 TRACE("mm = %ld %ldx%ld\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2889 TRACE("lpmfp == NULL\n");
2891 /* Use the whole device surface */
2892 mm
= MM_ANISOTROPIC
;
2897 if (mm
== MM_ISOTROPIC
|| mm
== MM_ANISOTROPIC
)
2899 if (xExt
< 0 || yExt
< 0)
2901 /* Use the whole device surface */
2906 /* Use the x and y extents as the frame box */
2909 rc
.left
= rc
.top
= 0;
2916 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
)))
2918 ERR("CreateEnhMetaFile failed\n");
2923 * Write the original METAFILE into the enhanced metafile.
2924 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2928 wmf_in_emf_comment
*mfcomment
;
2929 UINT mfcomment_size
;
2931 mfcomment_size
= sizeof (*mfcomment
) + cbBuffer
;
2932 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
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
);
2956 /* Use the whole device surface */
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
);
2974 if (hdcdisp
) DeleteDC(hdcdisp
);
2975 DeleteMetaFile(hmf
);