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.
43 #include "gdi_private.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile
);
51 BOOL on_disk
; /* true if metafile is on disk */
54 static const struct emr_name
{
67 X(EMR_SETWINDOWEXTEX
),
68 X(EMR_SETWINDOWORGEX
),
69 X(EMR_SETVIEWPORTEXTEX
),
70 X(EMR_SETVIEWPORTORGEX
),
74 X(EMR_SETMAPPERFLAGS
),
77 X(EMR_SETPOLYFILLMODE
),
79 X(EMR_SETSTRETCHBLTMODE
),
81 X(EMR_SETCOLORADJUSTMENT
),
87 X(EMR_EXCLUDECLIPRECT
),
88 X(EMR_INTERSECTCLIPRECT
),
89 X(EMR_SCALEVIEWPORTEXTEX
),
90 X(EMR_SCALEWINDOWEXTEX
),
93 X(EMR_SETWORLDTRANSFORM
),
94 X(EMR_MODIFYWORLDTRANSFORM
),
97 X(EMR_CREATEBRUSHINDIRECT
),
106 X(EMR_SELECTPALETTE
),
107 X(EMR_CREATEPALETTE
),
108 X(EMR_SETPALETTEENTRIES
),
109 X(EMR_RESIZEPALETTE
),
110 X(EMR_REALIZEPALETTE
),
115 X(EMR_SETARCDIRECTION
),
116 X(EMR_SETMITERLIMIT
),
121 X(EMR_STROKEANDFILLPATH
),
125 X(EMR_SELECTCLIPPATH
),
132 X(EMR_EXTSELECTCLIPRGN
),
137 X(EMR_SETDIBITSTODEVICE
),
138 X(EMR_STRETCHDIBITS
),
139 X(EMR_EXTCREATEFONTINDIRECTW
),
145 X(EMR_POLYBEZIERTO16
),
147 X(EMR_POLYPOLYLINE16
),
148 X(EMR_POLYPOLYGON16
),
150 X(EMR_CREATEMONOBRUSH
),
151 X(EMR_CREATEDIBPATTERNBRUSHPT
),
156 X(EMR_CREATECOLORSPACE
),
157 X(EMR_SETCOLORSPACE
),
158 X(EMR_DELETECOLORSPACE
),
160 X(EMR_GLSBOUNDEDRECORD
),
166 X(EMR_FORCEUFIMAPPING
),
168 X(EMR_COLORCORRECTPALETTE
),
169 X(EMR_SETICMPROFILEA
),
170 X(EMR_SETICMPROFILEW
),
173 X(EMR_TRANSPARENTBLT
),
177 X(EMR_SETTEXTJUSTIFICATION
),
178 X(EMR_COLORMATCHTOTARGETW
),
179 X(EMR_CREATECOLORSPACEW
)
183 /****************************************************************************
186 static const char *get_emr_name(DWORD type
)
189 for(i
= 0; i
< ARRAY_SIZE(emr_names
); i
++)
190 if(type
== emr_names
[i
].type
) return emr_names
[i
].name
;
191 TRACE("Unknown record type %d\n", type
);
195 /***********************************************************************
198 * Returns whether a DIB can be converted to a monochrome DDB.
200 * A DIB can be converted if its color table contains only black and
201 * white. Black must be the first color in the color table.
203 * Note : If the first color in the color table is white followed by
204 * black, we can't convert it to a monochrome DDB with
205 * SetDIBits, because black and white would be inverted.
207 static inline BOOL
is_dib_monochrome( const BITMAPINFO
* info
)
209 if (info
->bmiHeader
.biBitCount
!= 1) return FALSE
;
211 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
213 const RGBTRIPLE
*rgb
= ((const BITMAPCOREINFO
*) info
)->bmciColors
;
215 /* Check if the first color is black */
216 if ((rgb
->rgbtRed
== 0) && (rgb
->rgbtGreen
== 0) && (rgb
->rgbtBlue
== 0))
219 /* Check if the second color is white */
220 return ((rgb
->rgbtRed
== 0xff) && (rgb
->rgbtGreen
== 0xff)
221 && (rgb
->rgbtBlue
== 0xff));
225 else /* assume BITMAPINFOHEADER */
227 const RGBQUAD
*rgb
= info
->bmiColors
;
229 /* Check if the first color is black */
230 if ((rgb
->rgbRed
== 0) && (rgb
->rgbGreen
== 0) &&
231 (rgb
->rgbBlue
== 0) && (rgb
->rgbReserved
== 0))
235 /* Check if the second color is white */
236 return ((rgb
->rgbRed
== 0xff) && (rgb
->rgbGreen
== 0xff)
237 && (rgb
->rgbBlue
== 0xff) && (rgb
->rgbReserved
== 0));
243 /****************************************************************************
244 * EMF_Create_HENHMETAFILE
246 HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, DWORD filesize
, BOOL on_disk
)
249 ENHMETAFILEOBJ
*metaObj
;
251 if (filesize
< sizeof(*emh
))
253 WARN("File too small for emf header\n");
256 if (emh
->iType
!= EMR_HEADER
)
258 SetLastError(ERROR_INVALID_DATA
);
261 if (emh
->dSignature
!= ENHMETA_SIGNATURE
||
262 (emh
->nBytes
& 3)) /* refuse to load unaligned EMF as Windows does */
264 WARN("Invalid emf header type 0x%08x sig 0x%08x.\n",
265 emh
->iType
, emh
->dSignature
);
268 if (filesize
< emh
->nBytes
)
270 WARN("File truncated (got %u bytes, header says %u)\n", emh
->nBytes
, filesize
);
274 if (!(metaObj
= HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj
) ))) return 0;
277 metaObj
->on_disk
= on_disk
;
279 if (!(hmf
= alloc_gdi_handle( metaObj
, OBJ_ENHMETAFILE
, NULL
)))
280 HeapFree( GetProcessHeap(), 0, metaObj
);
284 /****************************************************************************
285 * EMF_Delete_HENHMETAFILE
287 static BOOL
EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf
)
289 ENHMETAFILEOBJ
*metaObj
= free_gdi_handle( hmf
);
291 if(!metaObj
) return FALSE
;
294 UnmapViewOfFile( metaObj
->emh
);
296 HeapFree( GetProcessHeap(), 0, metaObj
->emh
);
297 HeapFree( GetProcessHeap(), 0, metaObj
);
301 /******************************************************************
302 * EMF_GetEnhMetaHeader
304 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
306 static ENHMETAHEADER
*EMF_GetEnhMetaHeader( HENHMETAFILE hmf
)
308 ENHMETAHEADER
*ret
= NULL
;
309 ENHMETAFILEOBJ
*metaObj
= GDI_GetObjPtr( hmf
, OBJ_ENHMETAFILE
);
310 TRACE("hmf %p -> enhmetaObj %p\n", hmf
, metaObj
);
314 GDI_ReleaseObj( hmf
);
319 /*****************************************************************************
323 static HENHMETAFILE
EMF_GetEnhMetaFile( HANDLE hFile
)
330 filesize
= GetFileSize( hFile
, NULL
);
332 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
333 emh
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, filesize
);
334 CloseHandle( hMapping
);
338 hemf
= EMF_Create_HENHMETAFILE( emh
, filesize
, TRUE
);
340 UnmapViewOfFile( emh
);
345 /*****************************************************************************
346 * GetEnhMetaFileA (GDI32.@)
350 HENHMETAFILE WINAPI
GetEnhMetaFileA(
351 LPCSTR lpszMetaFile
/* [in] filename of enhanced metafile */
357 hFile
= CreateFileA(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
358 OPEN_EXISTING
, 0, 0);
359 if (hFile
== INVALID_HANDLE_VALUE
) {
360 WARN("could not open %s\n", lpszMetaFile
);
363 hmf
= EMF_GetEnhMetaFile( hFile
);
364 CloseHandle( hFile
);
368 /*****************************************************************************
369 * GetEnhMetaFileW (GDI32.@)
371 HENHMETAFILE WINAPI
GetEnhMetaFileW(
372 LPCWSTR lpszMetaFile
) /* [in] filename of enhanced metafile */
377 hFile
= CreateFileW(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
378 OPEN_EXISTING
, 0, 0);
379 if (hFile
== INVALID_HANDLE_VALUE
) {
380 WARN("could not open %s\n", debugstr_w(lpszMetaFile
));
383 hmf
= EMF_GetEnhMetaFile( hFile
);
384 CloseHandle( hFile
);
388 /*****************************************************************************
389 * GetEnhMetaFileHeader (GDI32.@)
391 * Retrieves the record containing the header for the specified
392 * enhanced-format metafile.
395 * If buf is NULL, returns the size of buffer required.
396 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
399 UINT WINAPI
GetEnhMetaFileHeader(
400 HENHMETAFILE hmf
, /* [in] enhanced metafile */
401 UINT bufsize
, /* [in] size of buffer */
402 LPENHMETAHEADER buf
/* [out] buffer */
408 emh
= EMF_GetEnhMetaHeader(hmf
);
409 if(!emh
) return FALSE
;
411 if (!buf
) return size
;
412 size
= min(size
, bufsize
);
413 memmove(buf
, emh
, size
);
418 /*****************************************************************************
419 * GetEnhMetaFileDescriptionA (GDI32.@)
421 * See GetEnhMetaFileDescriptionW.
423 UINT WINAPI
GetEnhMetaFileDescriptionA(
424 HENHMETAFILE hmf
, /* [in] enhanced metafile */
425 UINT size
, /* [in] size of buf */
426 LPSTR buf
/* [out] buffer to receive description */
429 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
433 if(!emh
) return FALSE
;
434 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
435 descrW
= (WCHAR
*) ((char *) emh
+ emh
->offDescription
);
436 len
= WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, NULL
, 0, NULL
, NULL
);
438 if (!buf
|| !size
) return len
;
440 len
= min( size
, len
);
441 WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, buf
, len
, NULL
, NULL
);
445 /*****************************************************************************
446 * GetEnhMetaFileDescriptionW (GDI32.@)
448 * Copies the description string of an enhanced metafile into a buffer
452 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
453 * number of characters copied.
455 UINT WINAPI
GetEnhMetaFileDescriptionW(
456 HENHMETAFILE hmf
, /* [in] enhanced metafile */
457 UINT size
, /* [in] size of buf */
458 LPWSTR buf
/* [out] buffer to receive description */
461 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
463 if(!emh
) return FALSE
;
464 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
465 if (!buf
|| !size
) return emh
->nDescription
;
467 memmove(buf
, (char *) emh
+ emh
->offDescription
, min(size
,emh
->nDescription
)*sizeof(WCHAR
));
468 return min(size
, emh
->nDescription
);
471 /****************************************************************************
472 * SetEnhMetaFileBits (GDI32.@)
474 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
476 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
478 ENHMETAHEADER
*emh
= HeapAlloc( GetProcessHeap(), 0, bufsize
);
482 memcpy(emh
, buf
, bufsize
);
483 hmf
= EMF_Create_HENHMETAFILE( emh
, bufsize
, FALSE
);
485 HeapFree( GetProcessHeap(), 0, emh
);
489 /*****************************************************************************
490 * GetEnhMetaFileBits (GDI32.@)
493 UINT WINAPI
GetEnhMetaFileBits(
499 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
505 if( buf
== NULL
) return size
;
507 size
= min( size
, bufsize
);
508 memmove(buf
, emh
, size
);
512 typedef struct EMF_dc_state
515 XFORM world_transform
;
524 struct EMF_dc_state
*next
;
527 typedef struct enum_emh_data
529 XFORM init_transform
;
532 EMF_dc_state
*saved_state
;
535 #define ENUM_GET_PRIVATE_DATA(ht) \
536 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
538 #define WIDTH(rect) ( (rect).right - (rect).left )
539 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
541 #define IS_WIN9X() (GetVersion()&0x80000000)
543 static void EMF_Update_MF_Xform(HDC hdc
, const enum_emh_data
*info
)
545 XFORM mapping_mode_trans
, final_trans
;
546 double scaleX
, scaleY
;
548 scaleX
= (double)info
->state
.vportExtX
/ (double)info
->state
.wndExtX
;
549 scaleY
= (double)info
->state
.vportExtY
/ (double)info
->state
.wndExtY
;
550 mapping_mode_trans
.eM11
= scaleX
;
551 mapping_mode_trans
.eM12
= 0.0;
552 mapping_mode_trans
.eM21
= 0.0;
553 mapping_mode_trans
.eM22
= scaleY
;
554 mapping_mode_trans
.eDx
= (double)info
->state
.vportOrgX
- scaleX
* (double)info
->state
.wndOrgX
;
555 mapping_mode_trans
.eDy
= (double)info
->state
.vportOrgY
- scaleY
* (double)info
->state
.wndOrgY
;
557 CombineTransform(&final_trans
, &info
->state
.world_transform
, &mapping_mode_trans
);
558 CombineTransform(&final_trans
, &final_trans
, &info
->init_transform
);
560 if (!SetWorldTransform(hdc
, &final_trans
))
562 ERR("World transform failed!\n");
566 static void EMF_RestoreDC( enum_emh_data
*info
, INT level
)
568 if (abs(level
) > info
->save_level
|| level
== 0) return;
570 if (level
< 0) level
= info
->save_level
+ level
+ 1;
572 while (info
->save_level
>= level
)
574 EMF_dc_state
*state
= info
->saved_state
;
575 info
->saved_state
= state
->next
;
577 if (--info
->save_level
< level
)
578 info
->state
= *state
;
579 HeapFree( GetProcessHeap(), 0, state
);
583 static void EMF_SaveDC( enum_emh_data
*info
)
585 EMF_dc_state
*state
= HeapAlloc( GetProcessHeap(), 0, sizeof(*state
));
588 *state
= info
->state
;
589 state
->next
= info
->saved_state
;
590 info
->saved_state
= state
;
592 TRACE("save_level %d\n", info
->save_level
);
596 static void EMF_SetMapMode(HDC hdc
, enum_emh_data
*info
)
598 INT horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
599 INT vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
600 INT horzRes
= GetDeviceCaps( hdc
, HORZRES
);
601 INT vertRes
= GetDeviceCaps( hdc
, VERTRES
);
603 TRACE("%d\n", info
->state
.mode
);
605 switch(info
->state
.mode
)
608 info
->state
.wndExtX
= 1;
609 info
->state
.wndExtY
= 1;
610 info
->state
.vportExtX
= 1;
611 info
->state
.vportExtY
= 1;
615 info
->state
.wndExtX
= horzSize
* 10;
616 info
->state
.wndExtY
= vertSize
* 10;
617 info
->state
.vportExtX
= horzRes
;
618 info
->state
.vportExtY
= -vertRes
;
621 info
->state
.wndExtX
= horzSize
* 100;
622 info
->state
.wndExtY
= vertSize
* 100;
623 info
->state
.vportExtX
= horzRes
;
624 info
->state
.vportExtY
= -vertRes
;
627 info
->state
.wndExtX
= MulDiv(1000, horzSize
, 254);
628 info
->state
.wndExtY
= MulDiv(1000, vertSize
, 254);
629 info
->state
.vportExtX
= horzRes
;
630 info
->state
.vportExtY
= -vertRes
;
633 info
->state
.wndExtX
= MulDiv(10000, horzSize
, 254);
634 info
->state
.wndExtY
= MulDiv(10000, vertSize
, 254);
635 info
->state
.vportExtX
= horzRes
;
636 info
->state
.vportExtY
= -vertRes
;
639 info
->state
.wndExtX
= MulDiv(14400, horzSize
, 254);
640 info
->state
.wndExtY
= MulDiv(14400, vertSize
, 254);
641 info
->state
.vportExtX
= horzRes
;
642 info
->state
.vportExtY
= -vertRes
;
651 /***********************************************************************
654 * Fix viewport extensions for isotropic mode.
657 static void EMF_FixIsotropic(HDC hdc
, enum_emh_data
*info
)
659 double xdim
= fabs((double)info
->state
.vportExtX
* GetDeviceCaps( hdc
, HORZSIZE
) /
660 (GetDeviceCaps( hdc
, HORZRES
) * info
->state
.wndExtX
));
661 double ydim
= fabs((double)info
->state
.vportExtY
* GetDeviceCaps( hdc
, VERTSIZE
) /
662 (GetDeviceCaps( hdc
, VERTRES
) * info
->state
.wndExtY
));
666 INT mincx
= (info
->state
.vportExtX
>= 0) ? 1 : -1;
667 info
->state
.vportExtX
= floor(info
->state
.vportExtX
* ydim
/ xdim
+ 0.5);
668 if (!info
->state
.vportExtX
) info
->state
.vportExtX
= mincx
;
672 INT mincy
= (info
->state
.vportExtY
>= 0) ? 1 : -1;
673 info
->state
.vportExtY
= floor(info
->state
.vportExtY
* xdim
/ ydim
+ 0.5);
674 if (!info
->state
.vportExtY
) info
->state
.vportExtY
= mincy
;
678 /*****************************************************************************
679 * emr_produces_output
681 * Returns TRUE if the record type writes something to the dc. Used by
682 * PlayEnhMetaFileRecord to determine whether it needs to update the
683 * dc's xform when in win9x mode.
685 * FIXME: need to test which records should be here.
687 static BOOL
emr_produces_output(int type
)
693 case EMR_POLYBEZIERTO
:
695 case EMR_POLYPOLYLINE
:
696 case EMR_POLYPOLYGON
:
699 case EMR_EXCLUDECLIPRECT
:
700 case EMR_INTERSECTCLIPRECT
:
701 case EMR_SELECTOBJECT
:
709 case EMR_EXTFLOODFILL
:
722 case EMR_SETDIBITSTODEVICE
:
723 case EMR_STRETCHDIBITS
:
724 case EMR_EXTTEXTOUTA
:
725 case EMR_EXTTEXTOUTW
:
726 case EMR_POLYBEZIER16
:
729 case EMR_POLYBEZIERTO16
:
730 case EMR_POLYLINETO16
:
731 case EMR_POLYPOLYLINE16
:
732 case EMR_POLYPOLYGON16
:
734 case EMR_POLYTEXTOUTA
:
735 case EMR_POLYTEXTOUTW
:
736 case EMR_SMALLTEXTOUT
:
738 case EMR_TRANSPARENTBLT
:
746 /*****************************************************************************
747 * PlayEnhMetaFileRecord (GDI32.@)
749 * Render a single enhanced metafile record in the device context hdc.
752 * TRUE (non zero) on success, FALSE on error.
754 * Many unimplemented records.
755 * No error handling on record play failures (ie checking return codes)
758 * WinNT actually updates the current world transform in this function
759 * whereas Win9x does not.
761 BOOL WINAPI
PlayEnhMetaFileRecord(
762 HDC hdc
, /* [in] device context in which to render EMF record */
763 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
764 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
765 UINT handles
/* [in] size of handle array */
770 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
772 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
773 hdc
, handletable
, mr
, handles
);
774 if (!mr
) return FALSE
;
778 TRACE("record %s\n", get_emr_name(type
));
787 const EMRGDICOMMENT
*lpGdiComment
= (const EMRGDICOMMENT
*)mr
;
788 /* In an enhanced metafile, there can be both public and private GDI comments */
789 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
794 const EMRSETMAPMODE
*pSetMapMode
= (const EMRSETMAPMODE
*)mr
;
796 if (info
->state
.mode
== pSetMapMode
->iMode
&&
797 (info
->state
.mode
== MM_ISOTROPIC
|| info
->state
.mode
== MM_ANISOTROPIC
))
799 info
->state
.mode
= pSetMapMode
->iMode
;
800 EMF_SetMapMode(hdc
, info
);
803 EMF_Update_MF_Xform(hdc
, info
);
809 const EMRSETBKMODE
*pSetBkMode
= (const EMRSETBKMODE
*)mr
;
810 SetBkMode(hdc
, pSetBkMode
->iMode
);
815 const EMRSETBKCOLOR
*pSetBkColor
= (const EMRSETBKCOLOR
*)mr
;
816 SetBkColor(hdc
, pSetBkColor
->crColor
);
819 case EMR_SETPOLYFILLMODE
:
821 const EMRSETPOLYFILLMODE
*pSetPolyFillMode
= (const EMRSETPOLYFILLMODE
*)mr
;
822 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
827 const EMRSETROP2
*pSetROP2
= (const EMRSETROP2
*)mr
;
828 SetROP2(hdc
, pSetROP2
->iMode
);
831 case EMR_SETSTRETCHBLTMODE
:
833 const EMRSETSTRETCHBLTMODE
*pSetStretchBltMode
= (const EMRSETSTRETCHBLTMODE
*)mr
;
834 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
837 case EMR_SETTEXTALIGN
:
839 const EMRSETTEXTALIGN
*pSetTextAlign
= (const EMRSETTEXTALIGN
*)mr
;
840 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
843 case EMR_SETTEXTCOLOR
:
845 const EMRSETTEXTCOLOR
*pSetTextColor
= (const EMRSETTEXTCOLOR
*)mr
;
846 SetTextColor(hdc
, pSetTextColor
->crColor
);
857 const EMRRESTOREDC
*pRestoreDC
= (const EMRRESTOREDC
*)mr
;
858 TRACE("EMR_RESTORE: %d\n", pRestoreDC
->iRelative
);
859 if (RestoreDC( hdc
, pRestoreDC
->iRelative
))
860 EMF_RestoreDC( info
, pRestoreDC
->iRelative
);
863 case EMR_INTERSECTCLIPRECT
:
865 const EMRINTERSECTCLIPRECT
*pClipRect
= (const EMRINTERSECTCLIPRECT
*)mr
;
866 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
867 pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
868 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
869 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
870 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
873 case EMR_SELECTOBJECT
:
875 const EMRSELECTOBJECT
*pSelectObject
= (const EMRSELECTOBJECT
*)mr
;
876 if( pSelectObject
->ihObject
& 0x80000000 ) {
877 /* High order bit is set - it's a stock object
878 * Strip the high bit to get the index.
879 * See MSDN article Q142319
881 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
884 /* High order bit wasn't set - not a stock object
887 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
891 case EMR_DELETEOBJECT
:
893 const EMRDELETEOBJECT
*pDeleteObject
= (const EMRDELETEOBJECT
*)mr
;
894 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
895 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
898 case EMR_SETWINDOWORGEX
:
900 const EMRSETWINDOWORGEX
*pSetWindowOrgEx
= (const EMRSETWINDOWORGEX
*)mr
;
902 info
->state
.wndOrgX
= pSetWindowOrgEx
->ptlOrigin
.x
;
903 info
->state
.wndOrgY
= pSetWindowOrgEx
->ptlOrigin
.y
;
905 TRACE("SetWindowOrgEx: %d,%d\n", info
->state
.wndOrgX
, info
->state
.wndOrgY
);
908 EMF_Update_MF_Xform(hdc
, info
);
912 case EMR_SETWINDOWEXTEX
:
914 const EMRSETWINDOWEXTEX
*pSetWindowExtEx
= (const EMRSETWINDOWEXTEX
*)mr
;
916 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
918 info
->state
.wndExtX
= pSetWindowExtEx
->szlExtent
.cx
;
919 info
->state
.wndExtY
= pSetWindowExtEx
->szlExtent
.cy
;
920 if (info
->state
.mode
== MM_ISOTROPIC
)
921 EMF_FixIsotropic(hdc
, info
);
923 TRACE("SetWindowExtEx: %d,%d\n",info
->state
.wndExtX
, info
->state
.wndExtY
);
926 EMF_Update_MF_Xform(hdc
, info
);
930 case EMR_SETVIEWPORTORGEX
:
932 const EMRSETVIEWPORTORGEX
*pSetViewportOrgEx
= (const EMRSETVIEWPORTORGEX
*)mr
;
934 info
->state
.vportOrgX
= pSetViewportOrgEx
->ptlOrigin
.x
;
935 info
->state
.vportOrgY
= pSetViewportOrgEx
->ptlOrigin
.y
;
936 TRACE("SetViewportOrgEx: %d,%d\n", info
->state
.vportOrgX
, info
->state
.vportOrgY
);
939 EMF_Update_MF_Xform(hdc
, info
);
943 case EMR_SETVIEWPORTEXTEX
:
945 const EMRSETVIEWPORTEXTEX
*pSetViewportExtEx
= (const EMRSETVIEWPORTEXTEX
*)mr
;
947 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
949 info
->state
.vportExtX
= pSetViewportExtEx
->szlExtent
.cx
;
950 info
->state
.vportExtY
= pSetViewportExtEx
->szlExtent
.cy
;
951 if (info
->state
.mode
== MM_ISOTROPIC
)
952 EMF_FixIsotropic(hdc
, info
);
953 TRACE("SetViewportExtEx: %d,%d\n", info
->state
.vportExtX
, info
->state
.vportExtY
);
956 EMF_Update_MF_Xform(hdc
, info
);
962 const EMRCREATEPEN
*pCreatePen
= (const EMRCREATEPEN
*)mr
;
963 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
964 CreatePenIndirect(&pCreatePen
->lopn
);
967 case EMR_EXTCREATEPEN
:
969 const EMREXTCREATEPEN
*pPen
= (const EMREXTCREATEPEN
*)mr
;
971 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
972 lb
.lbColor
= pPen
->elp
.elpColor
;
973 lb
.lbHatch
= pPen
->elp
.elpHatch
;
975 if(pPen
->offBmi
|| pPen
->offBits
)
976 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
978 (handletable
->objectHandle
)[pPen
->ihPen
] =
979 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
980 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpNumEntries
? pPen
->elp
.elpStyleEntry
: NULL
);
983 case EMR_CREATEBRUSHINDIRECT
:
985 const EMRCREATEBRUSHINDIRECT
*pBrush
= (const EMRCREATEBRUSHINDIRECT
*)mr
;
987 brush
.lbStyle
= pBrush
->lb
.lbStyle
;
988 brush
.lbColor
= pBrush
->lb
.lbColor
;
989 brush
.lbHatch
= pBrush
->lb
.lbHatch
;
990 (handletable
->objectHandle
)[pBrush
->ihBrush
] = CreateBrushIndirect(&brush
);
993 case EMR_EXTCREATEFONTINDIRECTW
:
995 const EMREXTCREATEFONTINDIRECTW
*pFont
= (const EMREXTCREATEFONTINDIRECTW
*)mr
;
996 (handletable
->objectHandle
)[pFont
->ihFont
] =
997 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
1002 const EMRMOVETOEX
*pMoveToEx
= (const EMRMOVETOEX
*)mr
;
1003 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
1008 const EMRLINETO
*pLineTo
= (const EMRLINETO
*)mr
;
1009 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
1014 const EMRRECTANGLE
*pRect
= (const EMRRECTANGLE
*)mr
;
1015 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
1016 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
1021 const EMRELLIPSE
*pEllipse
= (const EMRELLIPSE
*)mr
;
1022 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
1023 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
1028 const EMRPOLYGON16
*pPoly
= (const EMRPOLYGON16
*)mr
;
1029 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
1030 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1031 pPoly
->cpts
* sizeof(POINT
) );
1033 for(i
= 0; i
< pPoly
->cpts
; i
++)
1035 pts
[i
].x
= pPoly
->apts
[i
].x
;
1036 pts
[i
].y
= pPoly
->apts
[i
].y
;
1038 Polygon(hdc
, pts
, pPoly
->cpts
);
1039 HeapFree( GetProcessHeap(), 0, pts
);
1042 case EMR_POLYLINE16
:
1044 const EMRPOLYLINE16
*pPoly
= (const EMRPOLYLINE16
*)mr
;
1045 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1046 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1047 pPoly
->cpts
* sizeof(POINT
) );
1049 for(i
= 0; i
< pPoly
->cpts
; i
++)
1051 pts
[i
].x
= pPoly
->apts
[i
].x
;
1052 pts
[i
].y
= pPoly
->apts
[i
].y
;
1054 Polyline(hdc
, pts
, pPoly
->cpts
);
1055 HeapFree( GetProcessHeap(), 0, pts
);
1058 case EMR_POLYLINETO16
:
1060 const EMRPOLYLINETO16
*pPoly
= (const EMRPOLYLINETO16
*)mr
;
1061 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1062 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1063 pPoly
->cpts
* sizeof(POINT
) );
1065 for(i
= 0; i
< pPoly
->cpts
; i
++)
1067 pts
[i
].x
= pPoly
->apts
[i
].x
;
1068 pts
[i
].y
= pPoly
->apts
[i
].y
;
1070 PolylineTo(hdc
, pts
, pPoly
->cpts
);
1071 HeapFree( GetProcessHeap(), 0, pts
);
1074 case EMR_POLYBEZIER16
:
1076 const EMRPOLYBEZIER16
*pPoly
= (const EMRPOLYBEZIER16
*)mr
;
1077 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1078 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1079 pPoly
->cpts
* sizeof(POINT
) );
1081 for(i
= 0; i
< pPoly
->cpts
; i
++)
1083 pts
[i
].x
= pPoly
->apts
[i
].x
;
1084 pts
[i
].y
= pPoly
->apts
[i
].y
;
1086 PolyBezier(hdc
, pts
, pPoly
->cpts
);
1087 HeapFree( GetProcessHeap(), 0, pts
);
1090 case EMR_POLYBEZIERTO16
:
1092 const EMRPOLYBEZIERTO16
*pPoly
= (const EMRPOLYBEZIERTO16
*)mr
;
1093 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1094 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1095 pPoly
->cpts
* sizeof(POINT
) );
1097 for(i
= 0; i
< pPoly
->cpts
; i
++)
1099 pts
[i
].x
= pPoly
->apts
[i
].x
;
1100 pts
[i
].y
= pPoly
->apts
[i
].y
;
1102 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
1103 HeapFree( GetProcessHeap(), 0, pts
);
1106 case EMR_POLYPOLYGON16
:
1108 const EMRPOLYPOLYGON16
*pPolyPoly
= (const EMRPOLYPOLYGON16
*)mr
;
1109 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1110 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1112 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1113 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1115 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1120 PolyPolygon(hdc
, pt
, (const INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1121 HeapFree( GetProcessHeap(), 0, pt
);
1124 case EMR_POLYPOLYLINE16
:
1126 const EMRPOLYPOLYLINE16
*pPolyPoly
= (const EMRPOLYPOLYLINE16
*)mr
;
1127 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1128 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1130 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1131 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1133 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1138 PolyPolyline(hdc
, pt
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1139 HeapFree( GetProcessHeap(), 0, pt
);
1143 case EMR_POLYDRAW16
:
1145 const EMRPOLYDRAW16
*pPolyDraw16
= (const EMRPOLYDRAW16
*)mr
;
1146 const POINTS
*ptl
= pPolyDraw16
->apts
;
1147 POINT
*pts
= HeapAlloc(GetProcessHeap(), 0, pPolyDraw16
->cpts
* sizeof(POINT
));
1150 /* NB abTypes array doesn't start at pPolyDraw16->abTypes. It's actually
1151 pPolyDraw16->apts + pPolyDraw16->cpts. */
1152 const BYTE
*types
= (BYTE
*)(pPolyDraw16
->apts
+ pPolyDraw16
->cpts
);
1157 for (i
= 0; i
< pPolyDraw16
->cpts
; ++i
)
1159 pts
[i
].x
= ptl
[i
].x
;
1160 pts
[i
].y
= ptl
[i
].y
;
1163 PolyDraw(hdc
, pts
, types
, pPolyDraw16
->cpts
);
1164 HeapFree(GetProcessHeap(), 0, pts
);
1168 case EMR_STRETCHDIBITS
:
1170 const EMRSTRETCHDIBITS
*pStretchDIBits
= (const EMRSTRETCHDIBITS
*)mr
;
1173 pStretchDIBits
->xDest
,
1174 pStretchDIBits
->yDest
,
1175 pStretchDIBits
->cxDest
,
1176 pStretchDIBits
->cyDest
,
1177 pStretchDIBits
->xSrc
,
1178 pStretchDIBits
->ySrc
,
1179 pStretchDIBits
->cxSrc
,
1180 pStretchDIBits
->cySrc
,
1181 (const BYTE
*)mr
+ pStretchDIBits
->offBitsSrc
,
1182 (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchDIBits
->offBmiSrc
),
1183 pStretchDIBits
->iUsageSrc
,
1184 pStretchDIBits
->dwRop
);
1188 case EMR_EXTTEXTOUTA
:
1190 const EMREXTTEXTOUTA
*pExtTextOutA
= (const EMREXTTEXTOUTA
*)mr
;
1192 const INT
*dx
= NULL
;
1195 rc
.left
= pExtTextOutA
->emrtext
.rcl
.left
;
1196 rc
.top
= pExtTextOutA
->emrtext
.rcl
.top
;
1197 rc
.right
= pExtTextOutA
->emrtext
.rcl
.right
;
1198 rc
.bottom
= pExtTextOutA
->emrtext
.rcl
.bottom
;
1199 TRACE("EMR_EXTTEXTOUTA: x,y = %d, %d. rect = %s. flags %08x\n",
1200 pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1201 wine_dbgstr_rect(&rc
), pExtTextOutA
->emrtext
.fOptions
);
1203 old_mode
= SetGraphicsMode(hdc
, pExtTextOutA
->iGraphicsMode
);
1204 /* Reselect the font back into the dc so that the transformation
1206 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1208 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1209 * These files can be enumerated and played under Win98 just
1210 * fine, but at least Win2k chokes on them.
1212 if (pExtTextOutA
->emrtext
.offDx
)
1213 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offDx
);
1215 ExtTextOutA(hdc
, pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1216 pExtTextOutA
->emrtext
.fOptions
, &rc
,
1217 (LPCSTR
)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offString
), pExtTextOutA
->emrtext
.nChars
,
1220 SetGraphicsMode(hdc
, old_mode
);
1224 case EMR_EXTTEXTOUTW
:
1226 const EMREXTTEXTOUTW
*pExtTextOutW
= (const EMREXTTEXTOUTW
*)mr
;
1228 const INT
*dx
= NULL
;
1231 rc
.left
= pExtTextOutW
->emrtext
.rcl
.left
;
1232 rc
.top
= pExtTextOutW
->emrtext
.rcl
.top
;
1233 rc
.right
= pExtTextOutW
->emrtext
.rcl
.right
;
1234 rc
.bottom
= pExtTextOutW
->emrtext
.rcl
.bottom
;
1235 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %s. flags %08x\n",
1236 pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1237 wine_dbgstr_rect(&rc
), pExtTextOutW
->emrtext
.fOptions
);
1239 old_mode
= SetGraphicsMode(hdc
, pExtTextOutW
->iGraphicsMode
);
1240 /* Reselect the font back into the dc so that the transformation
1242 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1244 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1245 * These files can be enumerated and played under Win98 just
1246 * fine, but at least Win2k chokes on them.
1248 if (pExtTextOutW
->emrtext
.offDx
)
1249 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offDx
);
1251 ExtTextOutW(hdc
, pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1252 pExtTextOutW
->emrtext
.fOptions
, &rc
,
1253 (LPCWSTR
)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offString
), pExtTextOutW
->emrtext
.nChars
,
1256 SetGraphicsMode(hdc
, old_mode
);
1260 case EMR_CREATEPALETTE
:
1262 const EMRCREATEPALETTE
*lpCreatePal
= (const EMRCREATEPALETTE
*)mr
;
1264 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1265 CreatePalette( &lpCreatePal
->lgpl
);
1270 case EMR_SELECTPALETTE
:
1272 const EMRSELECTPALETTE
*lpSelectPal
= (const EMRSELECTPALETTE
*)mr
;
1274 if( lpSelectPal
->ihPal
& 0x80000000 ) {
1275 SelectPalette( hdc
, GetStockObject(lpSelectPal
->ihPal
& 0x7fffffff), TRUE
);
1277 SelectPalette( hdc
, (handletable
->objectHandle
)[lpSelectPal
->ihPal
], TRUE
);
1282 case EMR_REALIZEPALETTE
:
1284 RealizePalette( hdc
);
1288 case EMR_EXTSELECTCLIPRGN
:
1290 const EMREXTSELECTCLIPRGN
*lpRgn
= (const EMREXTSELECTCLIPRGN
*)mr
;
1293 if (mr
->nSize
>= sizeof(*lpRgn
) + sizeof(RGNDATAHEADER
))
1294 hRgn
= ExtCreateRegion( &info
->init_transform
, 0, (const RGNDATA
*)lpRgn
->RgnData
);
1296 ExtSelectClipRgn(hdc
, hRgn
, (INT
)(lpRgn
->iMode
));
1297 /* ExtSelectClipRgn created a copy of the region */
1302 case EMR_SETMETARGN
:
1308 case EMR_SETWORLDTRANSFORM
:
1310 const EMRSETWORLDTRANSFORM
*lpXfrm
= (const EMRSETWORLDTRANSFORM
*)mr
;
1311 info
->state
.world_transform
= lpXfrm
->xform
;
1314 EMF_Update_MF_Xform(hdc
, info
);
1319 case EMR_POLYBEZIER
:
1321 const EMRPOLYBEZIER
*lpPolyBez
= (const EMRPOLYBEZIER
*)mr
;
1322 PolyBezier(hdc
, (const POINT
*)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1328 const EMRPOLYGON
*lpPoly
= (const EMRPOLYGON
*)mr
;
1329 Polygon( hdc
, (const POINT
*)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1335 const EMRPOLYLINE
*lpPolyLine
= (const EMRPOLYLINE
*)mr
;
1336 Polyline(hdc
, (const POINT
*)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1340 case EMR_POLYBEZIERTO
:
1342 const EMRPOLYBEZIERTO
*lpPolyBezierTo
= (const EMRPOLYBEZIERTO
*)mr
;
1343 PolyBezierTo( hdc
, (const POINT
*)lpPolyBezierTo
->aptl
,
1344 (UINT
)lpPolyBezierTo
->cptl
);
1348 case EMR_POLYLINETO
:
1350 const EMRPOLYLINETO
*lpPolyLineTo
= (const EMRPOLYLINETO
*)mr
;
1351 PolylineTo( hdc
, (const POINT
*)lpPolyLineTo
->aptl
,
1352 (UINT
)lpPolyLineTo
->cptl
);
1356 case EMR_POLYPOLYLINE
:
1358 const EMRPOLYPOLYLINE
*pPolyPolyline
= (const EMRPOLYPOLYLINE
*)mr
;
1359 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1361 PolyPolyline(hdc
, (const POINT
*)(pPolyPolyline
->aPolyCounts
+
1362 pPolyPolyline
->nPolys
),
1363 pPolyPolyline
->aPolyCounts
,
1364 pPolyPolyline
->nPolys
);
1369 case EMR_POLYPOLYGON
:
1371 const EMRPOLYPOLYGON
*pPolyPolygon
= (const EMRPOLYPOLYGON
*)mr
;
1373 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1375 PolyPolygon(hdc
, (const POINT
*)(pPolyPolygon
->aPolyCounts
+
1376 pPolyPolygon
->nPolys
),
1377 (const INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
1381 case EMR_SETBRUSHORGEX
:
1383 const EMRSETBRUSHORGEX
*lpSetBrushOrgEx
= (const EMRSETBRUSHORGEX
*)mr
;
1386 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1387 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1395 const EMRSETPIXELV
*lpSetPixelV
= (const EMRSETPIXELV
*)mr
;
1398 (INT
)lpSetPixelV
->ptlPixel
.x
,
1399 (INT
)lpSetPixelV
->ptlPixel
.y
,
1400 lpSetPixelV
->crColor
);
1405 case EMR_SETMAPPERFLAGS
:
1407 const EMRSETMAPPERFLAGS
*lpSetMapperFlags
= (const EMRSETMAPPERFLAGS
*)mr
;
1409 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1414 case EMR_SETCOLORADJUSTMENT
:
1416 const EMRSETCOLORADJUSTMENT
*lpSetColorAdjust
= (const EMRSETCOLORADJUSTMENT
*)mr
;
1418 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1423 case EMR_OFFSETCLIPRGN
:
1425 const EMROFFSETCLIPRGN
*lpOffsetClipRgn
= (const EMROFFSETCLIPRGN
*)mr
;
1428 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1429 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1430 FIXME("OffsetClipRgn\n");
1435 case EMR_EXCLUDECLIPRECT
:
1437 const EMREXCLUDECLIPRECT
*lpExcludeClipRect
= (const EMREXCLUDECLIPRECT
*)mr
;
1439 ExcludeClipRect( hdc
,
1440 lpExcludeClipRect
->rclClip
.left
,
1441 lpExcludeClipRect
->rclClip
.top
,
1442 lpExcludeClipRect
->rclClip
.right
,
1443 lpExcludeClipRect
->rclClip
.bottom
);
1444 FIXME("ExcludeClipRect\n");
1449 case EMR_SCALEVIEWPORTEXTEX
:
1451 const EMRSCALEVIEWPORTEXTEX
*lpScaleViewportExtEx
= (const EMRSCALEVIEWPORTEXTEX
*)mr
;
1453 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1455 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1456 !lpScaleViewportExtEx
->yNum
|| !lpScaleViewportExtEx
->yDenom
)
1458 info
->state
.vportExtX
= MulDiv(info
->state
.vportExtX
, lpScaleViewportExtEx
->xNum
,
1459 lpScaleViewportExtEx
->xDenom
);
1460 info
->state
.vportExtY
= MulDiv(info
->state
.vportExtY
, lpScaleViewportExtEx
->yNum
,
1461 lpScaleViewportExtEx
->yDenom
);
1462 if (info
->state
.vportExtX
== 0) info
->state
.vportExtX
= 1;
1463 if (info
->state
.vportExtY
== 0) info
->state
.vportExtY
= 1;
1464 if (info
->state
.mode
== MM_ISOTROPIC
)
1465 EMF_FixIsotropic(hdc
, info
);
1467 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1468 lpScaleViewportExtEx
->xNum
,lpScaleViewportExtEx
->xDenom
,
1469 lpScaleViewportExtEx
->yNum
,lpScaleViewportExtEx
->yDenom
);
1472 EMF_Update_MF_Xform(hdc
, info
);
1477 case EMR_SCALEWINDOWEXTEX
:
1479 const EMRSCALEWINDOWEXTEX
*lpScaleWindowExtEx
= (const EMRSCALEWINDOWEXTEX
*)mr
;
1481 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1483 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1484 !lpScaleWindowExtEx
->yNum
|| !lpScaleWindowExtEx
->yDenom
)
1486 info
->state
.wndExtX
= MulDiv(info
->state
.wndExtX
, lpScaleWindowExtEx
->xNum
,
1487 lpScaleWindowExtEx
->xDenom
);
1488 info
->state
.wndExtY
= MulDiv(info
->state
.wndExtY
, lpScaleWindowExtEx
->yNum
,
1489 lpScaleWindowExtEx
->yDenom
);
1490 if (info
->state
.wndExtX
== 0) info
->state
.wndExtX
= 1;
1491 if (info
->state
.wndExtY
== 0) info
->state
.wndExtY
= 1;
1492 if (info
->state
.mode
== MM_ISOTROPIC
)
1493 EMF_FixIsotropic(hdc
, info
);
1495 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1496 lpScaleWindowExtEx
->xNum
,lpScaleWindowExtEx
->xDenom
,
1497 lpScaleWindowExtEx
->yNum
,lpScaleWindowExtEx
->yDenom
);
1500 EMF_Update_MF_Xform(hdc
, info
);
1505 case EMR_MODIFYWORLDTRANSFORM
:
1507 const EMRMODIFYWORLDTRANSFORM
*lpModifyWorldTrans
= (const EMRMODIFYWORLDTRANSFORM
*)mr
;
1509 switch(lpModifyWorldTrans
->iMode
) {
1511 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
1512 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
1513 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
1515 EMF_Update_MF_Xform(hdc
, info
);
1517 case MWT_LEFTMULTIPLY
:
1518 CombineTransform(&info
->state
.world_transform
, &lpModifyWorldTrans
->xform
,
1519 &info
->state
.world_transform
);
1521 ModifyWorldTransform(hdc
, &lpModifyWorldTrans
->xform
, MWT_LEFTMULTIPLY
);
1523 case MWT_RIGHTMULTIPLY
:
1524 CombineTransform(&info
->state
.world_transform
, &info
->state
.world_transform
,
1525 &lpModifyWorldTrans
->xform
);
1527 EMF_Update_MF_Xform(hdc
, info
);
1530 FIXME("Unknown imode %d\n", lpModifyWorldTrans
->iMode
);
1538 const EMRANGLEARC
*lpAngleArc
= (const EMRANGLEARC
*)mr
;
1541 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1542 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1543 lpAngleArc
->eSweepAngle
);
1550 const EMRROUNDRECT
*lpRoundRect
= (const EMRROUNDRECT
*)mr
;
1553 lpRoundRect
->rclBox
.left
,
1554 lpRoundRect
->rclBox
.top
,
1555 lpRoundRect
->rclBox
.right
,
1556 lpRoundRect
->rclBox
.bottom
,
1557 lpRoundRect
->szlCorner
.cx
,
1558 lpRoundRect
->szlCorner
.cy
);
1565 const EMRARC
*lpArc
= (const EMRARC
*)mr
;
1568 (INT
)lpArc
->rclBox
.left
,
1569 (INT
)lpArc
->rclBox
.top
,
1570 (INT
)lpArc
->rclBox
.right
,
1571 (INT
)lpArc
->rclBox
.bottom
,
1572 (INT
)lpArc
->ptlStart
.x
,
1573 (INT
)lpArc
->ptlStart
.y
,
1574 (INT
)lpArc
->ptlEnd
.x
,
1575 (INT
)lpArc
->ptlEnd
.y
);
1582 const EMRCHORD
*lpChord
= (const EMRCHORD
*)mr
;
1585 (INT
)lpChord
->rclBox
.left
,
1586 (INT
)lpChord
->rclBox
.top
,
1587 (INT
)lpChord
->rclBox
.right
,
1588 (INT
)lpChord
->rclBox
.bottom
,
1589 (INT
)lpChord
->ptlStart
.x
,
1590 (INT
)lpChord
->ptlStart
.y
,
1591 (INT
)lpChord
->ptlEnd
.x
,
1592 (INT
)lpChord
->ptlEnd
.y
);
1599 const EMRPIE
*lpPie
= (const EMRPIE
*)mr
;
1602 (INT
)lpPie
->rclBox
.left
,
1603 (INT
)lpPie
->rclBox
.top
,
1604 (INT
)lpPie
->rclBox
.right
,
1605 (INT
)lpPie
->rclBox
.bottom
,
1606 (INT
)lpPie
->ptlStart
.x
,
1607 (INT
)lpPie
->ptlStart
.y
,
1608 (INT
)lpPie
->ptlEnd
.x
,
1609 (INT
)lpPie
->ptlEnd
.y
);
1616 const EMRARC
*lpArcTo
= (const EMRARC
*)mr
;
1619 (INT
)lpArcTo
->rclBox
.left
,
1620 (INT
)lpArcTo
->rclBox
.top
,
1621 (INT
)lpArcTo
->rclBox
.right
,
1622 (INT
)lpArcTo
->rclBox
.bottom
,
1623 (INT
)lpArcTo
->ptlStart
.x
,
1624 (INT
)lpArcTo
->ptlStart
.y
,
1625 (INT
)lpArcTo
->ptlEnd
.x
,
1626 (INT
)lpArcTo
->ptlEnd
.y
);
1631 case EMR_EXTFLOODFILL
:
1633 const EMREXTFLOODFILL
*lpExtFloodFill
= (const EMREXTFLOODFILL
*)mr
;
1636 (INT
)lpExtFloodFill
->ptlStart
.x
,
1637 (INT
)lpExtFloodFill
->ptlStart
.y
,
1638 lpExtFloodFill
->crColor
,
1639 (UINT
)lpExtFloodFill
->iMode
);
1646 const EMRPOLYDRAW
*lpPolyDraw
= (const EMRPOLYDRAW
*)mr
;
1648 /* NB abTypes array doesn't start at lpPolyDraw->abTypes. It's actually
1649 lpPolyDraw->aptl + lpPolyDraw->cptl. */
1651 (const POINT
*)lpPolyDraw
->aptl
,
1652 (BYTE
*)(lpPolyDraw
->aptl
+ lpPolyDraw
->cptl
),
1653 (INT
)lpPolyDraw
->cptl
);
1658 case EMR_SETARCDIRECTION
:
1660 const EMRSETARCDIRECTION
*lpSetArcDirection
= (const EMRSETARCDIRECTION
*)mr
;
1661 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1665 case EMR_SETMITERLIMIT
:
1667 const EMRSETMITERLIMIT
*lpSetMiterLimit
= (const EMRSETMITERLIMIT
*)mr
;
1668 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1684 case EMR_CLOSEFIGURE
:
1692 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1697 case EMR_STROKEANDFILLPATH
:
1699 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1700 StrokeAndFillPath( hdc
);
1704 case EMR_STROKEPATH
:
1706 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1711 case EMR_FLATTENPATH
:
1723 case EMR_SELECTCLIPPATH
:
1725 const EMRSELECTCLIPPATH
*lpSelectClipPath
= (const EMRSELECTCLIPPATH
*)mr
;
1726 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1736 case EMR_CREATECOLORSPACE
:
1738 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1739 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1740 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1744 case EMR_SETCOLORSPACE
:
1746 const EMRSETCOLORSPACE
*lpSetColorSpace
= (const EMRSETCOLORSPACE
*)mr
;
1748 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1752 case EMR_DELETECOLORSPACE
:
1754 const EMRDELETECOLORSPACE
*lpDeleteColorSpace
= (const EMRDELETECOLORSPACE
*)mr
;
1755 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1759 case EMR_SETICMMODE
:
1761 const EMRSETICMMODE
*lpSetICMMode
= (const EMRSETICMMODE
*)mr
;
1762 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1766 case EMR_PIXELFORMAT
:
1769 const EMRPIXELFORMAT
*lpPixelFormat
= (const EMRPIXELFORMAT
*)mr
;
1771 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1772 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1777 case EMR_SETPALETTEENTRIES
:
1779 const EMRSETPALETTEENTRIES
*lpSetPaletteEntries
= (const EMRSETPALETTEENTRIES
*)mr
;
1781 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1782 (UINT
)lpSetPaletteEntries
->iStart
,
1783 (UINT
)lpSetPaletteEntries
->cEntries
,
1784 lpSetPaletteEntries
->aPalEntries
);
1789 case EMR_RESIZEPALETTE
:
1791 const EMRRESIZEPALETTE
*lpResizePalette
= (const EMRRESIZEPALETTE
*)mr
;
1793 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1794 (UINT
)lpResizePalette
->cEntries
);
1799 case EMR_CREATEDIBPATTERNBRUSHPT
:
1801 const EMRCREATEDIBPATTERNBRUSHPT
*lpCreate
= (const EMRCREATEDIBPATTERNBRUSHPT
*)mr
;
1802 LPVOID lpPackedStruct
;
1804 /* Check that offsets and data are contained within the record
1805 * (including checking for wrap-arounds).
1807 if ( lpCreate
->offBmi
+ lpCreate
->cbBmi
> mr
->nSize
1808 || lpCreate
->offBits
+ lpCreate
->cbBits
> mr
->nSize
1809 || lpCreate
->offBmi
+ lpCreate
->cbBmi
< lpCreate
->offBmi
1810 || lpCreate
->offBits
+ lpCreate
->cbBits
< lpCreate
->offBits
)
1812 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1816 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1817 lpPackedStruct
= HeapAlloc( GetProcessHeap(), 0,
1818 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1821 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1825 /* Now pack this structure */
1826 memcpy( lpPackedStruct
,
1827 ((const BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1829 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1830 ((const BYTE
*)lpCreate
) + lpCreate
->offBits
,
1833 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1834 CreateDIBPatternBrushPt( lpPackedStruct
,
1835 (UINT
)lpCreate
->iUsage
);
1837 HeapFree(GetProcessHeap(), 0, lpPackedStruct
);
1841 case EMR_CREATEMONOBRUSH
:
1843 const EMRCREATEMONOBRUSH
*pCreateMonoBrush
= (const EMRCREATEMONOBRUSH
*)mr
;
1844 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
1847 /* Need to check if the bitmap is monochrome, and if the
1848 two colors are really black and white */
1849 if (pCreateMonoBrush
->iUsage
== DIB_PAL_MONO
)
1853 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1854 * aligned to 32 rather than 16 bits.
1857 bm
.bmWidth
= pbi
->bmiHeader
.biWidth
;
1858 bm
.bmHeight
= abs(pbi
->bmiHeader
.biHeight
);
1859 bm
.bmWidthBytes
= 4 * ((pbi
->bmiHeader
.biWidth
+ 31) / 32);
1860 bm
.bmPlanes
= pbi
->bmiHeader
.biPlanes
;
1861 bm
.bmBitsPixel
= pbi
->bmiHeader
.biBitCount
;
1862 bm
.bmBits
= (BYTE
*)mr
+ pCreateMonoBrush
->offBits
;
1863 hBmp
= CreateBitmapIndirect(&bm
);
1865 else if (is_dib_monochrome(pbi
))
1867 /* Top-down DIBs have a negative height */
1868 LONG height
= pbi
->bmiHeader
.biHeight
;
1870 hBmp
= CreateBitmap(pbi
->bmiHeader
.biWidth
, abs(height
), 1, 1, NULL
);
1871 SetDIBits(hdc
, hBmp
, 0, pbi
->bmiHeader
.biHeight
,
1872 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1876 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1877 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1880 (handletable
->objectHandle
)[pCreateMonoBrush
->ihBrush
] = CreatePatternBrush(hBmp
);
1882 /* CreatePatternBrush created a copy of the bitmap */
1889 const EMRBITBLT
*pBitBlt
= (const EMRBITBLT
*)mr
;
1891 if(pBitBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1892 PatBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1894 } else { /* BitBlt */
1895 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1896 HBRUSH hBrush
, hBrushOld
;
1897 HBITMAP hBmp
= 0, hBmpOld
= 0;
1898 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pBitBlt
->offBmiSrc
);
1900 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1901 SetWorldTransform(hdcSrc
, &pBitBlt
->xformSrc
);
1903 hBrush
= CreateSolidBrush(pBitBlt
->crBkColorSrc
);
1904 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1905 PatBlt(hdcSrc
, pBitBlt
->rclBounds
.left
, pBitBlt
->rclBounds
.top
,
1906 pBitBlt
->rclBounds
.right
- pBitBlt
->rclBounds
.left
,
1907 pBitBlt
->rclBounds
.bottom
- pBitBlt
->rclBounds
.top
, PATCOPY
);
1908 SelectObject(hdcSrc
, hBrushOld
);
1909 DeleteObject(hBrush
);
1911 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1912 (const BYTE
*)mr
+ pBitBlt
->offBitsSrc
, pbi
, pBitBlt
->iUsageSrc
);
1913 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1915 BitBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1916 hdcSrc
, pBitBlt
->xSrc
, pBitBlt
->ySrc
, pBitBlt
->dwRop
);
1918 SelectObject(hdcSrc
, hBmpOld
);
1925 case EMR_STRETCHBLT
:
1927 const EMRSTRETCHBLT
*pStretchBlt
= (const EMRSTRETCHBLT
*)mr
;
1929 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1930 pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1931 pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1932 pStretchBlt
->dwRop
, pStretchBlt
->offBitsSrc
);
1934 if(pStretchBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1935 PatBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1936 pStretchBlt
->dwRop
);
1937 } else { /* StretchBlt */
1938 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1939 HBRUSH hBrush
, hBrushOld
;
1940 HBITMAP hBmp
= 0, hBmpOld
= 0;
1941 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchBlt
->offBmiSrc
);
1943 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1944 SetWorldTransform(hdcSrc
, &pStretchBlt
->xformSrc
);
1946 hBrush
= CreateSolidBrush(pStretchBlt
->crBkColorSrc
);
1947 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1948 PatBlt(hdcSrc
, pStretchBlt
->rclBounds
.left
, pStretchBlt
->rclBounds
.top
,
1949 pStretchBlt
->rclBounds
.right
- pStretchBlt
->rclBounds
.left
,
1950 pStretchBlt
->rclBounds
.bottom
- pStretchBlt
->rclBounds
.top
, PATCOPY
);
1951 SelectObject(hdcSrc
, hBrushOld
);
1952 DeleteObject(hBrush
);
1954 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1955 (const BYTE
*)mr
+ pStretchBlt
->offBitsSrc
, pbi
, pStretchBlt
->iUsageSrc
);
1956 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1958 StretchBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1959 hdcSrc
, pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1960 pStretchBlt
->dwRop
);
1962 SelectObject(hdcSrc
, hBmpOld
);
1969 case EMR_ALPHABLEND
:
1971 const EMRALPHABLEND
*pAlphaBlend
= (const EMRALPHABLEND
*)mr
;
1973 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1974 pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1975 pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1976 pAlphaBlend
->dwRop
, pAlphaBlend
->offBitsSrc
);
1978 if(pAlphaBlend
->offBmiSrc
== 0) {
1979 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1981 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1982 HBITMAP hBmp
= 0, hBmpOld
= 0;
1983 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pAlphaBlend
->offBmiSrc
);
1986 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1987 SetWorldTransform(hdcSrc
, &pAlphaBlend
->xformSrc
);
1989 hBmp
= CreateDIBSection(hdc
, pbi
, pAlphaBlend
->iUsageSrc
, &bits
, NULL
, 0);
1990 memcpy(bits
, (const BYTE
*)mr
+ pAlphaBlend
->offBitsSrc
, pAlphaBlend
->cbBitsSrc
);
1991 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1993 GdiAlphaBlend(hdc
, pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1994 hdcSrc
, pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1995 *(BLENDFUNCTION
*)&pAlphaBlend
->dwRop
);
1997 SelectObject(hdcSrc
, hBmpOld
);
2006 const EMRMASKBLT
*pMaskBlt
= (const EMRMASKBLT
*)mr
;
2007 HDC hdcSrc
= CreateCompatibleDC(hdc
);
2008 HBRUSH hBrush
, hBrushOld
;
2009 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
2010 const BITMAPINFO
*pbi
;
2012 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
2013 SetWorldTransform(hdcSrc
, &pMaskBlt
->xformSrc
);
2015 hBrush
= CreateSolidBrush(pMaskBlt
->crBkColorSrc
);
2016 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
2017 PatBlt(hdcSrc
, pMaskBlt
->rclBounds
.left
, pMaskBlt
->rclBounds
.top
,
2018 pMaskBlt
->rclBounds
.right
- pMaskBlt
->rclBounds
.left
,
2019 pMaskBlt
->rclBounds
.bottom
- pMaskBlt
->rclBounds
.top
, PATCOPY
);
2020 SelectObject(hdcSrc
, hBrushOld
);
2021 DeleteObject(hBrush
);
2023 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiMask
);
2024 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2026 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2027 (const BYTE
*)mr
+ pMaskBlt
->offBitsMask
, pbi
, pMaskBlt
->iUsageMask
);
2029 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiSrc
);
2030 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2031 (const BYTE
*)mr
+ pMaskBlt
->offBitsSrc
, pbi
, pMaskBlt
->iUsageSrc
);
2032 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2045 SelectObject(hdcSrc
, hBmpOld
);
2047 DeleteObject(hBmpMask
);
2054 const EMRPLGBLT
*pPlgBlt
= (const EMRPLGBLT
*)mr
;
2055 HDC hdcSrc
= CreateCompatibleDC(hdc
);
2056 HBRUSH hBrush
, hBrushOld
;
2057 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
2058 const BITMAPINFO
*pbi
;
2061 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
2062 SetWorldTransform(hdcSrc
, &pPlgBlt
->xformSrc
);
2064 pts
[0].x
= pPlgBlt
->aptlDest
[0].x
; pts
[0].y
= pPlgBlt
->aptlDest
[0].y
;
2065 pts
[1].x
= pPlgBlt
->aptlDest
[1].x
; pts
[1].y
= pPlgBlt
->aptlDest
[1].y
;
2066 pts
[2].x
= pPlgBlt
->aptlDest
[2].x
; pts
[2].y
= pPlgBlt
->aptlDest
[2].y
;
2068 hBrush
= CreateSolidBrush(pPlgBlt
->crBkColorSrc
);
2069 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
2070 PatBlt(hdcSrc
, pPlgBlt
->rclBounds
.left
, pPlgBlt
->rclBounds
.top
,
2071 pPlgBlt
->rclBounds
.right
- pPlgBlt
->rclBounds
.left
,
2072 pPlgBlt
->rclBounds
.bottom
- pPlgBlt
->rclBounds
.top
, PATCOPY
);
2073 SelectObject(hdcSrc
, hBrushOld
);
2074 DeleteObject(hBrush
);
2076 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiMask
);
2077 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2079 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2080 (const BYTE
*)mr
+ pPlgBlt
->offBitsMask
, pbi
, pPlgBlt
->iUsageMask
);
2082 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiSrc
);
2083 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2084 (const BYTE
*)mr
+ pPlgBlt
->offBitsSrc
, pbi
, pPlgBlt
->iUsageSrc
);
2085 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2096 SelectObject(hdcSrc
, hBmpOld
);
2098 DeleteObject(hBmpMask
);
2103 case EMR_SETDIBITSTODEVICE
:
2105 const EMRSETDIBITSTODEVICE
*pSetDIBitsToDevice
= (const EMRSETDIBITSTODEVICE
*)mr
;
2107 SetDIBitsToDevice(hdc
,
2108 pSetDIBitsToDevice
->xDest
,
2109 pSetDIBitsToDevice
->yDest
,
2110 pSetDIBitsToDevice
->cxSrc
,
2111 pSetDIBitsToDevice
->cySrc
,
2112 pSetDIBitsToDevice
->xSrc
,
2113 pSetDIBitsToDevice
->ySrc
,
2114 pSetDIBitsToDevice
->iStartScan
,
2115 pSetDIBitsToDevice
->cScans
,
2116 (const BYTE
*)mr
+ pSetDIBitsToDevice
->offBitsSrc
,
2117 (const BITMAPINFO
*)((const BYTE
*)mr
+ pSetDIBitsToDevice
->offBmiSrc
),
2118 pSetDIBitsToDevice
->iUsageSrc
);
2122 case EMR_POLYTEXTOUTA
:
2124 const EMRPOLYTEXTOUTA
*pPolyTextOutA
= (const EMRPOLYTEXTOUTA
*)mr
;
2125 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
2127 XFORM xform
, xformOld
;
2130 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
2131 GetWorldTransform(hdc
, &xformOld
);
2133 xform
.eM11
= pPolyTextOutA
->exScale
;
2136 xform
.eM22
= pPolyTextOutA
->eyScale
;
2139 SetWorldTransform(hdc
, &xform
);
2141 /* Set up POLYTEXTA structures */
2142 for(i
= 0; i
< pPolyTextOutA
->cStrings
; i
++)
2144 polytextA
[i
].x
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.x
;
2145 polytextA
[i
].y
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.y
;
2146 polytextA
[i
].n
= pPolyTextOutA
->aemrtext
[i
].nChars
;
2147 polytextA
[i
].lpstr
= (LPCSTR
)((const BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offString
);
2148 polytextA
[i
].uiFlags
= pPolyTextOutA
->aemrtext
[i
].fOptions
;
2149 polytextA
[i
].rcl
.left
= pPolyTextOutA
->aemrtext
[i
].rcl
.left
;
2150 polytextA
[i
].rcl
.right
= pPolyTextOutA
->aemrtext
[i
].rcl
.right
;
2151 polytextA
[i
].rcl
.top
= pPolyTextOutA
->aemrtext
[i
].rcl
.top
;
2152 polytextA
[i
].rcl
.bottom
= pPolyTextOutA
->aemrtext
[i
].rcl
.bottom
;
2153 polytextA
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offDx
);
2155 PolyTextOutA(hdc
, polytextA
, pPolyTextOutA
->cStrings
);
2156 HeapFree(GetProcessHeap(), 0, polytextA
);
2158 SetWorldTransform(hdc
, &xformOld
);
2159 SetGraphicsMode(hdc
, gModeOld
);
2163 case EMR_POLYTEXTOUTW
:
2165 const EMRPOLYTEXTOUTW
*pPolyTextOutW
= (const EMRPOLYTEXTOUTW
*)mr
;
2166 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
2168 XFORM xform
, xformOld
;
2171 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
2172 GetWorldTransform(hdc
, &xformOld
);
2174 xform
.eM11
= pPolyTextOutW
->exScale
;
2177 xform
.eM22
= pPolyTextOutW
->eyScale
;
2180 SetWorldTransform(hdc
, &xform
);
2182 /* Set up POLYTEXTW structures */
2183 for(i
= 0; i
< pPolyTextOutW
->cStrings
; i
++)
2185 polytextW
[i
].x
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.x
;
2186 polytextW
[i
].y
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.y
;
2187 polytextW
[i
].n
= pPolyTextOutW
->aemrtext
[i
].nChars
;
2188 polytextW
[i
].lpstr
= (LPCWSTR
)((const BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offString
);
2189 polytextW
[i
].uiFlags
= pPolyTextOutW
->aemrtext
[i
].fOptions
;
2190 polytextW
[i
].rcl
.left
= pPolyTextOutW
->aemrtext
[i
].rcl
.left
;
2191 polytextW
[i
].rcl
.right
= pPolyTextOutW
->aemrtext
[i
].rcl
.right
;
2192 polytextW
[i
].rcl
.top
= pPolyTextOutW
->aemrtext
[i
].rcl
.top
;
2193 polytextW
[i
].rcl
.bottom
= pPolyTextOutW
->aemrtext
[i
].rcl
.bottom
;
2194 polytextW
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offDx
);
2196 PolyTextOutW(hdc
, polytextW
, pPolyTextOutW
->cStrings
);
2197 HeapFree(GetProcessHeap(), 0, polytextW
);
2199 SetWorldTransform(hdc
, &xformOld
);
2200 SetGraphicsMode(hdc
, gModeOld
);
2206 const EMRFILLRGN
*pFillRgn
= (const EMRFILLRGN
*)mr
;
2207 HRGN hRgn
= ExtCreateRegion(NULL
, pFillRgn
->cbRgnData
, (const RGNDATA
*)pFillRgn
->RgnData
);
2210 (handletable
->objectHandle
)[pFillRgn
->ihBrush
]);
2217 const EMRFRAMERGN
*pFrameRgn
= (const EMRFRAMERGN
*)mr
;
2218 HRGN hRgn
= ExtCreateRegion(NULL
, pFrameRgn
->cbRgnData
, (const RGNDATA
*)pFrameRgn
->RgnData
);
2221 (handletable
->objectHandle
)[pFrameRgn
->ihBrush
],
2222 pFrameRgn
->szlStroke
.cx
,
2223 pFrameRgn
->szlStroke
.cy
);
2230 const EMRINVERTRGN
*pInvertRgn
= (const EMRINVERTRGN
*)mr
;
2231 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (const RGNDATA
*)pInvertRgn
->RgnData
);
2232 InvertRgn(hdc
, hRgn
);
2239 const EMRPAINTRGN
*pPaintRgn
= (const EMRPAINTRGN
*)mr
;
2240 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (const RGNDATA
*)pPaintRgn
->RgnData
);
2241 PaintRgn(hdc
, hRgn
);
2246 case EMR_SETTEXTJUSTIFICATION
:
2248 const EMRSETTEXTJUSTIFICATION
*pSetTextJust
= (const EMRSETTEXTJUSTIFICATION
*)mr
;
2249 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
2255 const EMRSETLAYOUT
*pSetLayout
= (const EMRSETLAYOUT
*)mr
;
2256 SetLayout(hdc
, pSetLayout
->iMode
);
2260 case EMR_GRADIENTFILL
:
2262 EMRGRADIENTFILL
*grad
= (EMRGRADIENTFILL
*)mr
;
2263 GdiGradientFill( hdc
, grad
->Ver
, grad
->nVer
, grad
->Ver
+ grad
->nVer
,
2264 grad
->nTri
, grad
->ulMode
);
2269 case EMR_GLSBOUNDEDRECORD
:
2270 case EMR_DRAWESCAPE
:
2273 case EMR_SMALLTEXTOUT
:
2274 case EMR_FORCEUFIMAPPING
:
2275 case EMR_NAMEDESCAPE
:
2276 case EMR_COLORCORRECTPALETTE
:
2277 case EMR_SETICMPROFILEA
:
2278 case EMR_SETICMPROFILEW
:
2279 case EMR_TRANSPARENTBLT
:
2280 case EMR_SETLINKEDUFI
:
2281 case EMR_COLORMATCHTOTARGETW
:
2282 case EMR_CREATECOLORSPACEW
:
2285 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2286 record then ignore and return TRUE. */
2287 FIXME("type %d is unimplemented\n", type
);
2290 tmprc
.left
= tmprc
.top
= 0;
2291 tmprc
.right
= tmprc
.bottom
= 1000;
2292 LPtoDP(hdc
, (POINT
*)&tmprc
, 2);
2293 TRACE("L:0,0 - 1000,1000 -> D:%s\n", wine_dbgstr_rect(&tmprc
));
2299 /*****************************************************************************
2301 * EnumEnhMetaFile (GDI32.@)
2303 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2305 * record. Returns when either every record has been used or
2306 * when _EnhMetaFunc_ returns FALSE.
2310 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2317 * This function behaves differently in Win9x and WinNT.
2319 * In WinNT, the DC's world transform is updated as the EMF changes
2320 * the Window/Viewport Extent and Origin or its world transform.
2321 * The actual Window/Viewport Extent and Origin are left untouched.
2323 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2324 * updates the scaling itself but only just before a record that
2325 * writes anything to the DC.
2327 * I'm not sure where the data (enum_emh_data) is stored in either
2328 * version. For this implementation, it is stored before the handle
2329 * table, but it could be stored in the DC, in the EMF handle or in
2333 BOOL WINAPI
EnumEnhMetaFile(
2334 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
2335 HENHMETAFILE hmf
, /* [in] EMF to walk */
2336 ENHMFENUMPROC callback
, /* [in] callback function */
2337 LPVOID data
, /* [in] optional data for callback function */
2338 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
2350 HBRUSH hBrush
= NULL
;
2353 enum_emh_data
*info
;
2354 SIZE vp_size
, win_size
;
2355 POINT vp_org
, win_org
;
2356 INT mapMode
= MM_TEXT
, old_align
= 0, old_rop2
= 0, old_arcdir
= 0, old_polyfill
= 0, old_stretchblt
= 0;
2357 COLORREF old_text_color
= 0, old_bk_color
= 0;
2361 SetLastError(ERROR_INVALID_PARAMETER
);
2365 emh
= EMF_GetEnhMetaHeader(hmf
);
2367 SetLastError(ERROR_INVALID_HANDLE
);
2371 info
= HeapAlloc( GetProcessHeap(), 0,
2372 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2375 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2378 info
->state
.mode
= MM_TEXT
;
2379 info
->state
.wndOrgX
= 0;
2380 info
->state
.wndOrgY
= 0;
2381 info
->state
.wndExtX
= 1;
2382 info
->state
.wndExtY
= 1;
2383 info
->state
.vportOrgX
= 0;
2384 info
->state
.vportOrgY
= 0;
2385 info
->state
.vportExtX
= 1;
2386 info
->state
.vportExtY
= 1;
2387 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
2388 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
2389 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
2391 info
->state
.next
= NULL
;
2392 info
->save_level
= 0;
2393 info
->saved_state
= NULL
;
2395 ht
= (HANDLETABLE
*) &info
[1];
2396 ht
->objectHandle
[0] = hmf
;
2397 for(i
= 1; i
< emh
->nHandles
; i
++)
2398 ht
->objectHandle
[i
] = NULL
;
2402 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
2403 GetWorldTransform(hdc
, &savedXform
);
2404 GetViewportExtEx(hdc
, &vp_size
);
2405 GetWindowExtEx(hdc
, &win_size
);
2406 GetViewportOrgEx(hdc
, &vp_org
);
2407 GetWindowOrgEx(hdc
, &win_org
);
2408 mapMode
= GetMapMode(hdc
);
2411 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
2412 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
2413 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
2415 hRgn
= CreateRectRgn(0, 0, 0, 0);
2416 if (!GetClipRgn(hdc
, hRgn
))
2422 old_text_color
= SetTextColor(hdc
, RGB(0,0,0));
2423 old_bk_color
= SetBkColor(hdc
, RGB(0xff, 0xff, 0xff));
2424 old_align
= SetTextAlign(hdc
, 0);
2425 old_rop2
= SetROP2(hdc
, R2_COPYPEN
);
2426 old_arcdir
= SetArcDirection(hdc
, AD_COUNTERCLOCKWISE
);
2427 old_polyfill
= SetPolyFillMode(hdc
, ALTERNATE
);
2428 old_stretchblt
= SetStretchBltMode(hdc
, BLACKONWHITE
);
2432 /* Win95 leaves the vp/win ext/org info alone */
2433 info
->init_transform
.eM11
= 1.0;
2434 info
->init_transform
.eM12
= 0.0;
2435 info
->init_transform
.eM21
= 0.0;
2436 info
->init_transform
.eM22
= 1.0;
2437 info
->init_transform
.eDx
= 0.0;
2438 info
->init_transform
.eDy
= 0.0;
2442 /* WinNT combines the vp/win ext/org info into a transform */
2443 double xscale
, yscale
;
2444 xscale
= (double)vp_size
.cx
/ (double)win_size
.cx
;
2445 yscale
= (double)vp_size
.cy
/ (double)win_size
.cy
;
2446 info
->init_transform
.eM11
= xscale
;
2447 info
->init_transform
.eM12
= 0.0;
2448 info
->init_transform
.eM21
= 0.0;
2449 info
->init_transform
.eM22
= yscale
;
2450 info
->init_transform
.eDx
= (double)vp_org
.x
- xscale
* (double)win_org
.x
;
2451 info
->init_transform
.eDy
= (double)vp_org
.y
- yscale
* (double)win_org
.y
;
2453 CombineTransform(&info
->init_transform
, &savedXform
, &info
->init_transform
);
2456 if ( lpRect
&& WIDTH(emh
->rclFrame
) && HEIGHT(emh
->rclFrame
) )
2458 double xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
2461 TRACE("rect: %s. rclFrame: (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(lpRect
),
2462 emh
->rclFrame
.left
, emh
->rclFrame
.top
, emh
->rclFrame
.right
,
2463 emh
->rclFrame
.bottom
);
2465 xSrcPixSize
= (double) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
2466 ySrcPixSize
= (double) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
2467 xscale
= (double) WIDTH(*lpRect
) * 100.0 /
2468 WIDTH(emh
->rclFrame
) * xSrcPixSize
;
2469 yscale
= (double) HEIGHT(*lpRect
) * 100.0 /
2470 HEIGHT(emh
->rclFrame
) * ySrcPixSize
;
2471 TRACE("xscale = %f, yscale = %f\n", xscale
, yscale
);
2473 xform
.eM11
= xscale
;
2476 xform
.eM22
= yscale
;
2477 xform
.eDx
= (double) lpRect
->left
- (double) WIDTH(*lpRect
) / WIDTH(emh
->rclFrame
) * emh
->rclFrame
.left
;
2478 xform
.eDy
= (double) lpRect
->top
- (double) HEIGHT(*lpRect
) / HEIGHT(emh
->rclFrame
) * emh
->rclFrame
.top
;
2480 CombineTransform(&info
->init_transform
, &xform
, &info
->init_transform
);
2483 /* WinNT resets the current vp/win org/ext */
2486 SetMapMode(hdc
, MM_TEXT
);
2487 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2488 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2489 EMF_Update_MF_Xform(hdc
, info
);
2495 while(ret
&& offset
< emh
->nBytes
)
2497 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
2499 if (offset
+ 8 > emh
->nBytes
||
2500 offset
> offset
+ emr
->nSize
||
2501 offset
+ emr
->nSize
> emh
->nBytes
)
2503 WARN("record truncated\n");
2507 /* In Win9x mode we update the xform if the record will produce output */
2508 if (hdc
&& IS_WIN9X() && emr_produces_output(emr
->iType
))
2509 EMF_Update_MF_Xform(hdc
, info
);
2511 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr
->iType
), emr
->nSize
);
2512 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nHandles
, (LPARAM
)data
);
2513 offset
+= emr
->nSize
;
2518 SetStretchBltMode(hdc
, old_stretchblt
);
2519 SetPolyFillMode(hdc
, old_polyfill
);
2520 SetArcDirection(hdc
, old_arcdir
);
2521 SetROP2(hdc
, old_rop2
);
2522 SetTextAlign(hdc
, old_align
);
2523 SetBkColor(hdc
, old_bk_color
);
2524 SetTextColor(hdc
, old_text_color
);
2527 SelectObject(hdc
, hBrush
);
2528 SelectObject(hdc
, hPen
);
2529 SelectObject(hdc
, hFont
);
2530 ExtSelectClipRgn(hdc
, hRgn
, RGN_COPY
);
2533 SetWorldTransform(hdc
, &savedXform
);
2535 SetGraphicsMode(hdc
, savedMode
);
2536 SetMapMode(hdc
, mapMode
);
2537 SetWindowOrgEx(hdc
, win_org
.x
, win_org
.y
, NULL
);
2538 SetWindowExtEx(hdc
, win_size
.cx
, win_size
.cy
, NULL
);
2539 SetViewportOrgEx(hdc
, vp_org
.x
, vp_org
.y
, NULL
);
2540 SetViewportExtEx(hdc
, vp_size
.cx
, vp_size
.cy
, NULL
);
2543 for(i
= 1; i
< emh
->nHandles
; i
++) /* Don't delete element 0 (hmf) */
2544 if( (ht
->objectHandle
)[i
] )
2545 DeleteObject( (ht
->objectHandle
)[i
] );
2547 while (info
->saved_state
)
2549 EMF_dc_state
*state
= info
->saved_state
;
2550 info
->saved_state
= info
->saved_state
->next
;
2551 HeapFree( GetProcessHeap(), 0, state
);
2553 HeapFree( GetProcessHeap(), 0, info
);
2557 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
2558 const ENHMETARECORD
*emr
,
2559 INT handles
, LPARAM data
)
2561 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
2564 /**************************************************************************
2565 * PlayEnhMetaFile (GDI32.@)
2567 * Renders an enhanced metafile into a specified rectangle *lpRect
2568 * in device context hdc.
2574 BOOL WINAPI
PlayEnhMetaFile(
2575 HDC hdc
, /* [in] DC to render into */
2576 HENHMETAFILE hmf
, /* [in] metafile to render */
2577 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
2580 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
2584 /*****************************************************************************
2585 * DeleteEnhMetaFile (GDI32.@)
2587 * Deletes an enhanced metafile and frees the associated storage.
2589 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
2591 return EMF_Delete_HENHMETAFILE( hmf
);
2594 /*****************************************************************************
2595 * CopyEnhMetaFileA (GDI32.@)
2597 * Duplicate an enhanced metafile.
2601 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
2602 HENHMETAFILE hmfSrc
,
2605 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2606 HENHMETAFILE hmfDst
;
2608 if(!emrSrc
) return FALSE
;
2610 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2611 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2612 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2614 HeapFree( GetProcessHeap(), 0, emrDst
);
2618 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2619 NULL
, CREATE_ALWAYS
, 0, 0);
2620 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2621 CloseHandle( hFile
);
2622 /* Reopen file for reading only, so that apps can share
2623 read access to the file while hmf is still valid */
2624 hFile
= CreateFileA( file
, GENERIC_READ
, FILE_SHARE_READ
,
2625 NULL
, OPEN_EXISTING
, 0, 0);
2626 if(hFile
== INVALID_HANDLE_VALUE
) {
2627 ERR("Can't reopen emf for reading\n");
2630 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2631 CloseHandle( hFile
);
2636 /*****************************************************************************
2637 * CopyEnhMetaFileW (GDI32.@)
2639 * See CopyEnhMetaFileA.
2643 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2644 HENHMETAFILE hmfSrc
,
2647 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2648 HENHMETAFILE hmfDst
;
2650 if(!emrSrc
) return FALSE
;
2652 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2653 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2654 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2656 HeapFree( GetProcessHeap(), 0, emrDst
);
2660 hFile
= CreateFileW( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2661 NULL
, CREATE_ALWAYS
, 0, 0);
2662 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2663 CloseHandle( hFile
);
2664 /* Reopen file for reading only, so that apps can share
2665 read access to the file while hmf is still valid */
2666 hFile
= CreateFileW( file
, GENERIC_READ
, FILE_SHARE_READ
,
2667 NULL
, OPEN_EXISTING
, 0, 0);
2668 if(hFile
== INVALID_HANDLE_VALUE
) {
2669 ERR("Can't reopen emf for reading\n");
2672 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2673 CloseHandle( hFile
);
2679 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2680 typedef struct tagEMF_PaletteCopy
2683 LPPALETTEENTRY lpPe
;
2686 /***************************************************************
2687 * Find the EMR_EOF record and then use it to find the
2688 * palette entries for this enhanced metafile.
2689 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2690 * which contains the max number of elements to copy and where
2693 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2695 static INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2697 const ENHMETARECORD
*lpEMR
,
2702 if ( lpEMR
->iType
== EMR_EOF
)
2704 const EMREOF
*lpEof
= (const EMREOF
*)lpEMR
;
2705 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
2706 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
2708 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy
);
2710 memcpy( info
->lpPe
, (LPCSTR
)lpEof
+ lpEof
->offPalEntries
,
2711 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
2713 /* Update the passed data as a return code */
2714 info
->lpPe
= NULL
; /* Palettes were copied! */
2715 info
->cEntries
= dwNumPalToCopy
;
2717 return FALSE
; /* That's all we need */
2723 /*****************************************************************************
2724 * GetEnhMetaFilePaletteEntries (GDI32.@)
2726 * Copy the palette and report size
2728 * BUGS: Error codes (SetLastError) are not set on failures
2730 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
2732 LPPALETTEENTRY lpPe
)
2734 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
2735 EMF_PaletteCopy infoForCallBack
;
2737 TRACE( "(%p,%d,%p)\n", hEmf
, cEntries
, lpPe
);
2739 if (!enhHeader
) return 0;
2741 /* First check if there are any palettes associated with
2743 if ( enhHeader
->nPalEntries
== 0 ) return 0;
2745 /* Is the user requesting the number of palettes? */
2746 if ( lpPe
== NULL
) return enhHeader
->nPalEntries
;
2748 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2749 infoForCallBack
.cEntries
= cEntries
;
2750 infoForCallBack
.lpPe
= lpPe
;
2752 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
2753 &infoForCallBack
, 0 ) )
2756 /* Verify that the callback executed correctly */
2757 if ( infoForCallBack
.lpPe
!= NULL
)
2759 /* Callback proc had error! */
2760 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2764 return infoForCallBack
.cEntries
;
2767 /******************************************************************
2768 * extract_emf_from_comment
2770 * If the WMF was created by GetWinMetaFileBits, then extract the
2771 * original EMF that is stored in MFCOMMENT chunks.
2773 static HENHMETAFILE
extract_emf_from_comment( const BYTE
*buf
, UINT mf_size
)
2775 METAHEADER
*mh
= (METAHEADER
*)buf
;
2777 emf_in_wmf_comment
*chunk
;
2779 DWORD size
= 0, remaining
, chunks
;
2780 BYTE
*emf_bits
= NULL
, *ptr
;
2782 HENHMETAFILE emf
= NULL
;
2784 if (mf_size
< sizeof(*mh
)) return NULL
;
2786 for (offset
= mh
->mtHeaderSize
* 2; offset
< mf_size
; offset
+= (mr
->rdSize
* 2))
2788 mr
= (METARECORD
*)((char *)mh
+ offset
);
2789 chunk
= (emf_in_wmf_comment
*)(mr
->rdParm
+ 2);
2791 if (mr
->rdFunction
!= META_ESCAPE
|| mr
->rdParm
[0] != MFCOMMENT
) goto done
;
2792 if (chunk
->magic
!= WMFC_MAGIC
) goto done
;
2796 size
= remaining
= chunk
->emf_size
;
2797 chunks
= chunk
->num_chunks
;
2798 emf_bits
= ptr
= HeapAlloc( GetProcessHeap(), 0, size
);
2799 if (!emf_bits
) goto done
;
2801 if (chunk
->chunk_size
> remaining
) goto done
;
2802 remaining
-= chunk
->chunk_size
;
2803 if (chunk
->remaining_size
!= remaining
) goto done
;
2804 memcpy( ptr
, chunk
->emf_data
, chunk
->chunk_size
);
2805 ptr
+= chunk
->chunk_size
;
2806 if (--chunks
== 0) break;
2809 for (offset
= 0; offset
< mf_size
/ 2; offset
++)
2810 checksum
+= *((WORD
*)buf
+ offset
);
2811 if (checksum
) goto done
;
2813 emf
= SetEnhMetaFileBits( size
, emf_bits
);
2816 HeapFree( GetProcessHeap(), 0, emf_bits
);
2820 typedef struct wmf_in_emf_comment
2827 DWORD cbWinMetaFile
;
2828 } wmf_in_emf_comment
;
2830 /******************************************************************
2831 * SetWinMetaFileBits (GDI32.@)
2833 * Translate from old style to new style.
2836 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
, const BYTE
*lpbBuffer
, HDC hdcRef
,
2837 const METAFILEPICT
*lpmfp
)
2839 HMETAFILE hmf
= NULL
;
2840 HENHMETAFILE ret
= NULL
;
2841 HDC hdc
= NULL
, hdcdisp
= NULL
;
2842 RECT rc
, *prcFrame
= NULL
;
2843 LONG mm
, xExt
, yExt
;
2844 INT horzsize
, vertsize
, horzres
, vertres
;
2846 TRACE("(%d, %p, %p, %p)\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
2848 hmf
= SetMetaFileBitsEx(cbBuffer
, lpbBuffer
);
2851 WARN("SetMetaFileBitsEx failed\n");
2855 ret
= extract_emf_from_comment( lpbBuffer
, cbBuffer
);
2856 if (ret
) return ret
;
2859 hdcRef
= hdcdisp
= CreateDCW(L
"DISPLAY", NULL
, NULL
, NULL
);
2863 TRACE("mm = %d %dx%d\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2871 TRACE("lpmfp == NULL\n");
2873 /* Use the whole device surface */
2874 mm
= MM_ANISOTROPIC
;
2879 if (mm
== MM_ISOTROPIC
|| mm
== MM_ANISOTROPIC
)
2881 if (xExt
< 0 || yExt
< 0)
2883 /* Use the whole device surface */
2888 /* Use the x and y extents as the frame box */
2891 rc
.left
= rc
.top
= 0;
2898 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
)))
2900 ERR("CreateEnhMetaFile failed\n");
2905 * Write the original METAFILE into the enhanced metafile.
2906 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2910 wmf_in_emf_comment
*mfcomment
;
2911 UINT mfcomment_size
;
2913 mfcomment_size
= sizeof (*mfcomment
) + cbBuffer
;
2914 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
2917 mfcomment
->ident
= GDICOMMENT_IDENTIFIER
;
2918 mfcomment
->iComment
= GDICOMMENT_WINDOWS_METAFILE
;
2919 mfcomment
->nVersion
= 0x00000300;
2920 mfcomment
->nChecksum
= 0; /* FIXME */
2921 mfcomment
->fFlags
= 0;
2922 mfcomment
->cbWinMetaFile
= cbBuffer
;
2923 memcpy(&mfcomment
[1], lpbBuffer
, cbBuffer
);
2924 GdiComment(hdc
, mfcomment_size
, (BYTE
*) mfcomment
);
2925 HeapFree(GetProcessHeap(), 0, mfcomment
);
2927 SetMapMode(hdc
, mm
);
2931 horzsize
= GetDeviceCaps(hdcRef
, HORZSIZE
);
2932 vertsize
= GetDeviceCaps(hdcRef
, VERTSIZE
);
2933 horzres
= GetDeviceCaps(hdcRef
, HORZRES
);
2934 vertres
= GetDeviceCaps(hdcRef
, VERTRES
);
2938 /* Use the whole device surface */
2944 xExt
= MulDiv(xExt
, horzres
, 100 * horzsize
);
2945 yExt
= MulDiv(yExt
, vertres
, 100 * vertsize
);
2948 /* set the initial viewport:window ratio as 1:1 */
2949 SetViewportExtEx(hdc
, xExt
, yExt
, NULL
);
2950 SetWindowExtEx(hdc
, xExt
, yExt
, NULL
);
2952 PlayMetaFile(hdc
, hmf
);
2954 ret
= CloseEnhMetaFile(hdc
);
2956 if (hdcdisp
) DeleteDC(hdcdisp
);
2957 DeleteMetaFile(hmf
);