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.
35 #include "wine/port.h"
46 #include "gdi_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile
);
54 BOOL on_disk
; /* true if metafile is on disk */
57 static const struct emr_name
{
70 X(EMR_SETWINDOWEXTEX
),
71 X(EMR_SETWINDOWORGEX
),
72 X(EMR_SETVIEWPORTEXTEX
),
73 X(EMR_SETVIEWPORTORGEX
),
77 X(EMR_SETMAPPERFLAGS
),
80 X(EMR_SETPOLYFILLMODE
),
82 X(EMR_SETSTRETCHBLTMODE
),
84 X(EMR_SETCOLORADJUSTMENT
),
90 X(EMR_EXCLUDECLIPRECT
),
91 X(EMR_INTERSECTCLIPRECT
),
92 X(EMR_SCALEVIEWPORTEXTEX
),
93 X(EMR_SCALEWINDOWEXTEX
),
96 X(EMR_SETWORLDTRANSFORM
),
97 X(EMR_MODIFYWORLDTRANSFORM
),
100 X(EMR_CREATEBRUSHINDIRECT
),
109 X(EMR_SELECTPALETTE
),
110 X(EMR_CREATEPALETTE
),
111 X(EMR_SETPALETTEENTRIES
),
112 X(EMR_RESIZEPALETTE
),
113 X(EMR_REALIZEPALETTE
),
118 X(EMR_SETARCDIRECTION
),
119 X(EMR_SETMITERLIMIT
),
124 X(EMR_STROKEANDFILLPATH
),
128 X(EMR_SELECTCLIPPATH
),
135 X(EMR_EXTSELECTCLIPRGN
),
140 X(EMR_SETDIBITSTODEVICE
),
141 X(EMR_STRETCHDIBITS
),
142 X(EMR_EXTCREATEFONTINDIRECTW
),
148 X(EMR_POLYBEZIERTO16
),
150 X(EMR_POLYPOLYLINE16
),
151 X(EMR_POLYPOLYGON16
),
153 X(EMR_CREATEMONOBRUSH
),
154 X(EMR_CREATEDIBPATTERNBRUSHPT
),
159 X(EMR_CREATECOLORSPACE
),
160 X(EMR_SETCOLORSPACE
),
161 X(EMR_DELETECOLORSPACE
),
163 X(EMR_GLSBOUNDEDRECORD
),
169 X(EMR_FORCEUFIMAPPING
),
171 X(EMR_COLORCORRECTPALETTE
),
172 X(EMR_SETICMPROFILEA
),
173 X(EMR_SETICMPROFILEW
),
176 X(EMR_TRANSPARENTBLT
),
180 X(EMR_SETTEXTJUSTIFICATION
),
181 X(EMR_COLORMATCHTOTARGETW
),
182 X(EMR_CREATECOLORSPACEW
)
186 /****************************************************************************
189 static const char *get_emr_name(DWORD type
)
192 for(i
= 0; i
< ARRAY_SIZE(emr_names
); i
++)
193 if(type
== emr_names
[i
].type
) return emr_names
[i
].name
;
194 TRACE("Unknown record type %d\n", type
);
198 /***********************************************************************
201 * Returns whether a DIB can be converted to a monochrome DDB.
203 * A DIB can be converted if its color table contains only black and
204 * white. Black must be the first color in the color table.
206 * Note : If the first color in the color table is white followed by
207 * black, we can't convert it to a monochrome DDB with
208 * SetDIBits, because black and white would be inverted.
210 static inline BOOL
is_dib_monochrome( const BITMAPINFO
* info
)
212 if (info
->bmiHeader
.biBitCount
!= 1) return FALSE
;
214 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
216 const RGBTRIPLE
*rgb
= ((const BITMAPCOREINFO
*) info
)->bmciColors
;
218 /* Check if the first color is black */
219 if ((rgb
->rgbtRed
== 0) && (rgb
->rgbtGreen
== 0) && (rgb
->rgbtBlue
== 0))
222 /* Check if the second color is white */
223 return ((rgb
->rgbtRed
== 0xff) && (rgb
->rgbtGreen
== 0xff)
224 && (rgb
->rgbtBlue
== 0xff));
228 else /* assume BITMAPINFOHEADER */
230 const RGBQUAD
*rgb
= info
->bmiColors
;
232 /* Check if the first color is black */
233 if ((rgb
->rgbRed
== 0) && (rgb
->rgbGreen
== 0) &&
234 (rgb
->rgbBlue
== 0) && (rgb
->rgbReserved
== 0))
238 /* Check if the second color is white */
239 return ((rgb
->rgbRed
== 0xff) && (rgb
->rgbGreen
== 0xff)
240 && (rgb
->rgbBlue
== 0xff) && (rgb
->rgbReserved
== 0));
246 /****************************************************************************
247 * EMF_Create_HENHMETAFILE
249 HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, DWORD filesize
, BOOL on_disk
)
252 ENHMETAFILEOBJ
*metaObj
;
254 if (filesize
< sizeof(*emh
))
256 WARN("File too small for emf header\n");
259 if (emh
->iType
!= EMR_HEADER
)
261 SetLastError(ERROR_INVALID_DATA
);
264 if (emh
->dSignature
!= ENHMETA_SIGNATURE
||
265 (emh
->nBytes
& 3)) /* refuse to load unaligned EMF as Windows does */
267 WARN("Invalid emf header type 0x%08x sig 0x%08x.\n",
268 emh
->iType
, emh
->dSignature
);
271 if (filesize
< emh
->nBytes
)
273 WARN("File truncated (got %u bytes, header says %u)\n", emh
->nBytes
, filesize
);
277 if (!(metaObj
= HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj
) ))) return 0;
280 metaObj
->on_disk
= on_disk
;
282 if (!(hmf
= alloc_gdi_handle( metaObj
, OBJ_ENHMETAFILE
, NULL
)))
283 HeapFree( GetProcessHeap(), 0, metaObj
);
287 /****************************************************************************
288 * EMF_Delete_HENHMETAFILE
290 static BOOL
EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf
)
292 ENHMETAFILEOBJ
*metaObj
= free_gdi_handle( hmf
);
294 if(!metaObj
) return FALSE
;
297 UnmapViewOfFile( metaObj
->emh
);
299 HeapFree( GetProcessHeap(), 0, metaObj
->emh
);
300 HeapFree( GetProcessHeap(), 0, metaObj
);
304 /******************************************************************
305 * EMF_GetEnhMetaHeader
307 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
309 static ENHMETAHEADER
*EMF_GetEnhMetaHeader( HENHMETAFILE hmf
)
311 ENHMETAHEADER
*ret
= NULL
;
312 ENHMETAFILEOBJ
*metaObj
= GDI_GetObjPtr( hmf
, OBJ_ENHMETAFILE
);
313 TRACE("hmf %p -> enhmetaObj %p\n", hmf
, metaObj
);
317 GDI_ReleaseObj( hmf
);
322 /*****************************************************************************
326 static HENHMETAFILE
EMF_GetEnhMetaFile( HANDLE hFile
)
333 filesize
= GetFileSize( hFile
, NULL
);
335 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
336 emh
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, filesize
);
337 CloseHandle( hMapping
);
341 hemf
= EMF_Create_HENHMETAFILE( emh
, filesize
, TRUE
);
343 UnmapViewOfFile( emh
);
348 /*****************************************************************************
349 * GetEnhMetaFileA (GDI32.@)
353 HENHMETAFILE WINAPI
GetEnhMetaFileA(
354 LPCSTR lpszMetaFile
/* [in] filename of enhanced metafile */
360 hFile
= CreateFileA(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
361 OPEN_EXISTING
, 0, 0);
362 if (hFile
== INVALID_HANDLE_VALUE
) {
363 WARN("could not open %s\n", lpszMetaFile
);
366 hmf
= EMF_GetEnhMetaFile( hFile
);
367 CloseHandle( hFile
);
371 /*****************************************************************************
372 * GetEnhMetaFileW (GDI32.@)
374 HENHMETAFILE WINAPI
GetEnhMetaFileW(
375 LPCWSTR lpszMetaFile
) /* [in] filename of enhanced metafile */
380 hFile
= CreateFileW(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
381 OPEN_EXISTING
, 0, 0);
382 if (hFile
== INVALID_HANDLE_VALUE
) {
383 WARN("could not open %s\n", debugstr_w(lpszMetaFile
));
386 hmf
= EMF_GetEnhMetaFile( hFile
);
387 CloseHandle( hFile
);
391 /*****************************************************************************
392 * GetEnhMetaFileHeader (GDI32.@)
394 * Retrieves the record containing the header for the specified
395 * enhanced-format metafile.
398 * If buf is NULL, returns the size of buffer required.
399 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
402 UINT WINAPI
GetEnhMetaFileHeader(
403 HENHMETAFILE hmf
, /* [in] enhanced metafile */
404 UINT bufsize
, /* [in] size of buffer */
405 LPENHMETAHEADER buf
/* [out] buffer */
411 emh
= EMF_GetEnhMetaHeader(hmf
);
412 if(!emh
) return FALSE
;
414 if (!buf
) return size
;
415 size
= min(size
, bufsize
);
416 memmove(buf
, emh
, size
);
421 /*****************************************************************************
422 * GetEnhMetaFileDescriptionA (GDI32.@)
424 * See GetEnhMetaFileDescriptionW.
426 UINT WINAPI
GetEnhMetaFileDescriptionA(
427 HENHMETAFILE hmf
, /* [in] enhanced metafile */
428 UINT size
, /* [in] size of buf */
429 LPSTR buf
/* [out] buffer to receive description */
432 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
436 if(!emh
) return FALSE
;
437 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
438 descrW
= (WCHAR
*) ((char *) emh
+ emh
->offDescription
);
439 len
= WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, NULL
, 0, NULL
, NULL
);
441 if (!buf
|| !size
) return len
;
443 len
= min( size
, len
);
444 WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, buf
, len
, NULL
, NULL
);
448 /*****************************************************************************
449 * GetEnhMetaFileDescriptionW (GDI32.@)
451 * Copies the description string of an enhanced metafile into a buffer
455 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
456 * number of characters copied.
458 UINT WINAPI
GetEnhMetaFileDescriptionW(
459 HENHMETAFILE hmf
, /* [in] enhanced metafile */
460 UINT size
, /* [in] size of buf */
461 LPWSTR buf
/* [out] buffer to receive description */
464 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
466 if(!emh
) return FALSE
;
467 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
468 if (!buf
|| !size
) return emh
->nDescription
;
470 memmove(buf
, (char *) emh
+ emh
->offDescription
, min(size
,emh
->nDescription
)*sizeof(WCHAR
));
471 return min(size
, emh
->nDescription
);
474 /****************************************************************************
475 * SetEnhMetaFileBits (GDI32.@)
477 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
479 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
481 ENHMETAHEADER
*emh
= HeapAlloc( GetProcessHeap(), 0, bufsize
);
485 memcpy(emh
, buf
, bufsize
);
486 hmf
= EMF_Create_HENHMETAFILE( emh
, bufsize
, FALSE
);
488 HeapFree( GetProcessHeap(), 0, emh
);
492 /*****************************************************************************
493 * GetEnhMetaFileBits (GDI32.@)
496 UINT WINAPI
GetEnhMetaFileBits(
502 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
508 if( buf
== NULL
) return size
;
510 size
= min( size
, bufsize
);
511 memmove(buf
, emh
, size
);
515 typedef struct EMF_dc_state
518 XFORM world_transform
;
527 struct EMF_dc_state
*next
;
530 typedef struct enum_emh_data
532 XFORM init_transform
;
535 EMF_dc_state
*saved_state
;
538 #define ENUM_GET_PRIVATE_DATA(ht) \
539 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
541 #define WIDTH(rect) ( (rect).right - (rect).left )
542 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
544 #define IS_WIN9X() (GetVersion()&0x80000000)
546 static void EMF_Update_MF_Xform(HDC hdc
, const enum_emh_data
*info
)
548 XFORM mapping_mode_trans
, final_trans
;
549 double scaleX
, scaleY
;
551 scaleX
= (double)info
->state
.vportExtX
/ (double)info
->state
.wndExtX
;
552 scaleY
= (double)info
->state
.vportExtY
/ (double)info
->state
.wndExtY
;
553 mapping_mode_trans
.eM11
= scaleX
;
554 mapping_mode_trans
.eM12
= 0.0;
555 mapping_mode_trans
.eM21
= 0.0;
556 mapping_mode_trans
.eM22
= scaleY
;
557 mapping_mode_trans
.eDx
= (double)info
->state
.vportOrgX
- scaleX
* (double)info
->state
.wndOrgX
;
558 mapping_mode_trans
.eDy
= (double)info
->state
.vportOrgY
- scaleY
* (double)info
->state
.wndOrgY
;
560 CombineTransform(&final_trans
, &info
->state
.world_transform
, &mapping_mode_trans
);
561 CombineTransform(&final_trans
, &final_trans
, &info
->init_transform
);
563 if (!SetWorldTransform(hdc
, &final_trans
))
565 ERR("World transform failed!\n");
569 static void EMF_RestoreDC( enum_emh_data
*info
, INT level
)
571 if (abs(level
) > info
->save_level
|| level
== 0) return;
573 if (level
< 0) level
= info
->save_level
+ level
+ 1;
575 while (info
->save_level
>= level
)
577 EMF_dc_state
*state
= info
->saved_state
;
578 info
->saved_state
= state
->next
;
580 if (--info
->save_level
< level
)
581 info
->state
= *state
;
582 HeapFree( GetProcessHeap(), 0, state
);
586 static void EMF_SaveDC( enum_emh_data
*info
)
588 EMF_dc_state
*state
= HeapAlloc( GetProcessHeap(), 0, sizeof(*state
));
591 *state
= info
->state
;
592 state
->next
= info
->saved_state
;
593 info
->saved_state
= state
;
595 TRACE("save_level %d\n", info
->save_level
);
599 static void EMF_SetMapMode(HDC hdc
, enum_emh_data
*info
)
601 INT horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
602 INT vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
603 INT horzRes
= GetDeviceCaps( hdc
, HORZRES
);
604 INT vertRes
= GetDeviceCaps( hdc
, VERTRES
);
606 TRACE("%d\n", info
->state
.mode
);
608 switch(info
->state
.mode
)
611 info
->state
.wndExtX
= 1;
612 info
->state
.wndExtY
= 1;
613 info
->state
.vportExtX
= 1;
614 info
->state
.vportExtY
= 1;
618 info
->state
.wndExtX
= horzSize
* 10;
619 info
->state
.wndExtY
= vertSize
* 10;
620 info
->state
.vportExtX
= horzRes
;
621 info
->state
.vportExtY
= -vertRes
;
624 info
->state
.wndExtX
= horzSize
* 100;
625 info
->state
.wndExtY
= vertSize
* 100;
626 info
->state
.vportExtX
= horzRes
;
627 info
->state
.vportExtY
= -vertRes
;
630 info
->state
.wndExtX
= MulDiv(1000, horzSize
, 254);
631 info
->state
.wndExtY
= MulDiv(1000, vertSize
, 254);
632 info
->state
.vportExtX
= horzRes
;
633 info
->state
.vportExtY
= -vertRes
;
636 info
->state
.wndExtX
= MulDiv(10000, horzSize
, 254);
637 info
->state
.wndExtY
= MulDiv(10000, vertSize
, 254);
638 info
->state
.vportExtX
= horzRes
;
639 info
->state
.vportExtY
= -vertRes
;
642 info
->state
.wndExtX
= MulDiv(14400, horzSize
, 254);
643 info
->state
.wndExtY
= MulDiv(14400, vertSize
, 254);
644 info
->state
.vportExtX
= horzRes
;
645 info
->state
.vportExtY
= -vertRes
;
654 /***********************************************************************
657 * Fix viewport extensions for isotropic mode.
660 static void EMF_FixIsotropic(HDC hdc
, enum_emh_data
*info
)
662 double xdim
= fabs((double)info
->state
.vportExtX
* GetDeviceCaps( hdc
, HORZSIZE
) /
663 (GetDeviceCaps( hdc
, HORZRES
) * info
->state
.wndExtX
));
664 double ydim
= fabs((double)info
->state
.vportExtY
* GetDeviceCaps( hdc
, VERTSIZE
) /
665 (GetDeviceCaps( hdc
, VERTRES
) * info
->state
.wndExtY
));
669 INT mincx
= (info
->state
.vportExtX
>= 0) ? 1 : -1;
670 info
->state
.vportExtX
= floor(info
->state
.vportExtX
* ydim
/ xdim
+ 0.5);
671 if (!info
->state
.vportExtX
) info
->state
.vportExtX
= mincx
;
675 INT mincy
= (info
->state
.vportExtY
>= 0) ? 1 : -1;
676 info
->state
.vportExtY
= floor(info
->state
.vportExtY
* xdim
/ ydim
+ 0.5);
677 if (!info
->state
.vportExtY
) info
->state
.vportExtY
= mincy
;
681 /*****************************************************************************
682 * emr_produces_output
684 * Returns TRUE if the record type writes something to the dc. Used by
685 * PlayEnhMetaFileRecord to determine whether it needs to update the
686 * dc's xform when in win9x mode.
688 * FIXME: need to test which records should be here.
690 static BOOL
emr_produces_output(int type
)
696 case EMR_POLYBEZIERTO
:
698 case EMR_POLYPOLYLINE
:
699 case EMR_POLYPOLYGON
:
702 case EMR_EXCLUDECLIPRECT
:
703 case EMR_INTERSECTCLIPRECT
:
704 case EMR_SELECTOBJECT
:
712 case EMR_EXTFLOODFILL
:
725 case EMR_SETDIBITSTODEVICE
:
726 case EMR_STRETCHDIBITS
:
727 case EMR_EXTTEXTOUTA
:
728 case EMR_EXTTEXTOUTW
:
729 case EMR_POLYBEZIER16
:
732 case EMR_POLYBEZIERTO16
:
733 case EMR_POLYLINETO16
:
734 case EMR_POLYPOLYLINE16
:
735 case EMR_POLYPOLYGON16
:
737 case EMR_POLYTEXTOUTA
:
738 case EMR_POLYTEXTOUTW
:
739 case EMR_SMALLTEXTOUT
:
741 case EMR_TRANSPARENTBLT
:
749 /*****************************************************************************
750 * PlayEnhMetaFileRecord (GDI32.@)
752 * Render a single enhanced metafile record in the device context hdc.
755 * TRUE (non zero) on success, FALSE on error.
757 * Many unimplemented records.
758 * No error handling on record play failures (ie checking return codes)
761 * WinNT actually updates the current world transform in this function
762 * whereas Win9x does not.
764 BOOL WINAPI
PlayEnhMetaFileRecord(
765 HDC hdc
, /* [in] device context in which to render EMF record */
766 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
767 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
768 UINT handles
/* [in] size of handle array */
773 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
775 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
776 hdc
, handletable
, mr
, handles
);
777 if (!mr
) return FALSE
;
781 TRACE("record %s\n", get_emr_name(type
));
790 const EMRGDICOMMENT
*lpGdiComment
= (const EMRGDICOMMENT
*)mr
;
791 /* In an enhanced metafile, there can be both public and private GDI comments */
792 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
797 const EMRSETMAPMODE
*pSetMapMode
= (const EMRSETMAPMODE
*)mr
;
799 if (info
->state
.mode
== pSetMapMode
->iMode
&&
800 (info
->state
.mode
== MM_ISOTROPIC
|| info
->state
.mode
== MM_ANISOTROPIC
))
802 info
->state
.mode
= pSetMapMode
->iMode
;
803 EMF_SetMapMode(hdc
, info
);
806 EMF_Update_MF_Xform(hdc
, info
);
812 const EMRSETBKMODE
*pSetBkMode
= (const EMRSETBKMODE
*)mr
;
813 SetBkMode(hdc
, pSetBkMode
->iMode
);
818 const EMRSETBKCOLOR
*pSetBkColor
= (const EMRSETBKCOLOR
*)mr
;
819 SetBkColor(hdc
, pSetBkColor
->crColor
);
822 case EMR_SETPOLYFILLMODE
:
824 const EMRSETPOLYFILLMODE
*pSetPolyFillMode
= (const EMRSETPOLYFILLMODE
*)mr
;
825 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
830 const EMRSETROP2
*pSetROP2
= (const EMRSETROP2
*)mr
;
831 SetROP2(hdc
, pSetROP2
->iMode
);
834 case EMR_SETSTRETCHBLTMODE
:
836 const EMRSETSTRETCHBLTMODE
*pSetStretchBltMode
= (const EMRSETSTRETCHBLTMODE
*)mr
;
837 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
840 case EMR_SETTEXTALIGN
:
842 const EMRSETTEXTALIGN
*pSetTextAlign
= (const EMRSETTEXTALIGN
*)mr
;
843 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
846 case EMR_SETTEXTCOLOR
:
848 const EMRSETTEXTCOLOR
*pSetTextColor
= (const EMRSETTEXTCOLOR
*)mr
;
849 SetTextColor(hdc
, pSetTextColor
->crColor
);
860 const EMRRESTOREDC
*pRestoreDC
= (const EMRRESTOREDC
*)mr
;
861 TRACE("EMR_RESTORE: %d\n", pRestoreDC
->iRelative
);
862 if (RestoreDC( hdc
, pRestoreDC
->iRelative
))
863 EMF_RestoreDC( info
, pRestoreDC
->iRelative
);
866 case EMR_INTERSECTCLIPRECT
:
868 const EMRINTERSECTCLIPRECT
*pClipRect
= (const EMRINTERSECTCLIPRECT
*)mr
;
869 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
870 pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
871 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
872 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
873 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
876 case EMR_SELECTOBJECT
:
878 const EMRSELECTOBJECT
*pSelectObject
= (const EMRSELECTOBJECT
*)mr
;
879 if( pSelectObject
->ihObject
& 0x80000000 ) {
880 /* High order bit is set - it's a stock object
881 * Strip the high bit to get the index.
882 * See MSDN article Q142319
884 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
887 /* High order bit wasn't set - not a stock object
890 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
894 case EMR_DELETEOBJECT
:
896 const EMRDELETEOBJECT
*pDeleteObject
= (const EMRDELETEOBJECT
*)mr
;
897 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
898 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
901 case EMR_SETWINDOWORGEX
:
903 const EMRSETWINDOWORGEX
*pSetWindowOrgEx
= (const EMRSETWINDOWORGEX
*)mr
;
905 info
->state
.wndOrgX
= pSetWindowOrgEx
->ptlOrigin
.x
;
906 info
->state
.wndOrgY
= pSetWindowOrgEx
->ptlOrigin
.y
;
908 TRACE("SetWindowOrgEx: %d,%d\n", info
->state
.wndOrgX
, info
->state
.wndOrgY
);
911 EMF_Update_MF_Xform(hdc
, info
);
915 case EMR_SETWINDOWEXTEX
:
917 const EMRSETWINDOWEXTEX
*pSetWindowExtEx
= (const EMRSETWINDOWEXTEX
*)mr
;
919 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
921 info
->state
.wndExtX
= pSetWindowExtEx
->szlExtent
.cx
;
922 info
->state
.wndExtY
= pSetWindowExtEx
->szlExtent
.cy
;
923 if (info
->state
.mode
== MM_ISOTROPIC
)
924 EMF_FixIsotropic(hdc
, info
);
926 TRACE("SetWindowExtEx: %d,%d\n",info
->state
.wndExtX
, info
->state
.wndExtY
);
929 EMF_Update_MF_Xform(hdc
, info
);
933 case EMR_SETVIEWPORTORGEX
:
935 const EMRSETVIEWPORTORGEX
*pSetViewportOrgEx
= (const EMRSETVIEWPORTORGEX
*)mr
;
937 info
->state
.vportOrgX
= pSetViewportOrgEx
->ptlOrigin
.x
;
938 info
->state
.vportOrgY
= pSetViewportOrgEx
->ptlOrigin
.y
;
939 TRACE("SetViewportOrgEx: %d,%d\n", info
->state
.vportOrgX
, info
->state
.vportOrgY
);
942 EMF_Update_MF_Xform(hdc
, info
);
946 case EMR_SETVIEWPORTEXTEX
:
948 const EMRSETVIEWPORTEXTEX
*pSetViewportExtEx
= (const EMRSETVIEWPORTEXTEX
*)mr
;
950 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
952 info
->state
.vportExtX
= pSetViewportExtEx
->szlExtent
.cx
;
953 info
->state
.vportExtY
= pSetViewportExtEx
->szlExtent
.cy
;
954 if (info
->state
.mode
== MM_ISOTROPIC
)
955 EMF_FixIsotropic(hdc
, info
);
956 TRACE("SetViewportExtEx: %d,%d\n", info
->state
.vportExtX
, info
->state
.vportExtY
);
959 EMF_Update_MF_Xform(hdc
, info
);
965 const EMRCREATEPEN
*pCreatePen
= (const EMRCREATEPEN
*)mr
;
966 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
967 CreatePenIndirect(&pCreatePen
->lopn
);
970 case EMR_EXTCREATEPEN
:
972 const EMREXTCREATEPEN
*pPen
= (const EMREXTCREATEPEN
*)mr
;
974 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
975 lb
.lbColor
= pPen
->elp
.elpColor
;
976 lb
.lbHatch
= pPen
->elp
.elpHatch
;
978 if(pPen
->offBmi
|| pPen
->offBits
)
979 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
981 (handletable
->objectHandle
)[pPen
->ihPen
] =
982 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
983 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpNumEntries
? pPen
->elp
.elpStyleEntry
: NULL
);
986 case EMR_CREATEBRUSHINDIRECT
:
988 const EMRCREATEBRUSHINDIRECT
*pBrush
= (const EMRCREATEBRUSHINDIRECT
*)mr
;
990 brush
.lbStyle
= pBrush
->lb
.lbStyle
;
991 brush
.lbColor
= pBrush
->lb
.lbColor
;
992 brush
.lbHatch
= pBrush
->lb
.lbHatch
;
993 (handletable
->objectHandle
)[pBrush
->ihBrush
] = CreateBrushIndirect(&brush
);
996 case EMR_EXTCREATEFONTINDIRECTW
:
998 const EMREXTCREATEFONTINDIRECTW
*pFont
= (const EMREXTCREATEFONTINDIRECTW
*)mr
;
999 (handletable
->objectHandle
)[pFont
->ihFont
] =
1000 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
1005 const EMRMOVETOEX
*pMoveToEx
= (const EMRMOVETOEX
*)mr
;
1006 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
1011 const EMRLINETO
*pLineTo
= (const EMRLINETO
*)mr
;
1012 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
1017 const EMRRECTANGLE
*pRect
= (const EMRRECTANGLE
*)mr
;
1018 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
1019 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
1024 const EMRELLIPSE
*pEllipse
= (const EMRELLIPSE
*)mr
;
1025 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
1026 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
1031 const EMRPOLYGON16
*pPoly
= (const EMRPOLYGON16
*)mr
;
1032 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
1033 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1034 pPoly
->cpts
* sizeof(POINT
) );
1036 for(i
= 0; i
< pPoly
->cpts
; i
++)
1038 pts
[i
].x
= pPoly
->apts
[i
].x
;
1039 pts
[i
].y
= pPoly
->apts
[i
].y
;
1041 Polygon(hdc
, pts
, pPoly
->cpts
);
1042 HeapFree( GetProcessHeap(), 0, pts
);
1045 case EMR_POLYLINE16
:
1047 const EMRPOLYLINE16
*pPoly
= (const EMRPOLYLINE16
*)mr
;
1048 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1049 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1050 pPoly
->cpts
* sizeof(POINT
) );
1052 for(i
= 0; i
< pPoly
->cpts
; i
++)
1054 pts
[i
].x
= pPoly
->apts
[i
].x
;
1055 pts
[i
].y
= pPoly
->apts
[i
].y
;
1057 Polyline(hdc
, pts
, pPoly
->cpts
);
1058 HeapFree( GetProcessHeap(), 0, pts
);
1061 case EMR_POLYLINETO16
:
1063 const EMRPOLYLINETO16
*pPoly
= (const EMRPOLYLINETO16
*)mr
;
1064 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1065 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1066 pPoly
->cpts
* sizeof(POINT
) );
1068 for(i
= 0; i
< pPoly
->cpts
; i
++)
1070 pts
[i
].x
= pPoly
->apts
[i
].x
;
1071 pts
[i
].y
= pPoly
->apts
[i
].y
;
1073 PolylineTo(hdc
, pts
, pPoly
->cpts
);
1074 HeapFree( GetProcessHeap(), 0, pts
);
1077 case EMR_POLYBEZIER16
:
1079 const EMRPOLYBEZIER16
*pPoly
= (const EMRPOLYBEZIER16
*)mr
;
1080 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1081 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1082 pPoly
->cpts
* sizeof(POINT
) );
1084 for(i
= 0; i
< pPoly
->cpts
; i
++)
1086 pts
[i
].x
= pPoly
->apts
[i
].x
;
1087 pts
[i
].y
= pPoly
->apts
[i
].y
;
1089 PolyBezier(hdc
, pts
, pPoly
->cpts
);
1090 HeapFree( GetProcessHeap(), 0, pts
);
1093 case EMR_POLYBEZIERTO16
:
1095 const EMRPOLYBEZIERTO16
*pPoly
= (const EMRPOLYBEZIERTO16
*)mr
;
1096 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1097 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1098 pPoly
->cpts
* sizeof(POINT
) );
1100 for(i
= 0; i
< pPoly
->cpts
; i
++)
1102 pts
[i
].x
= pPoly
->apts
[i
].x
;
1103 pts
[i
].y
= pPoly
->apts
[i
].y
;
1105 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
1106 HeapFree( GetProcessHeap(), 0, pts
);
1109 case EMR_POLYPOLYGON16
:
1111 const EMRPOLYPOLYGON16
*pPolyPoly
= (const EMRPOLYPOLYGON16
*)mr
;
1112 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1113 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1115 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1116 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1118 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1123 PolyPolygon(hdc
, pt
, (const INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1124 HeapFree( GetProcessHeap(), 0, pt
);
1127 case EMR_POLYPOLYLINE16
:
1129 const EMRPOLYPOLYLINE16
*pPolyPoly
= (const EMRPOLYPOLYLINE16
*)mr
;
1130 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1131 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1133 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1134 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1136 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1141 PolyPolyline(hdc
, pt
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1142 HeapFree( GetProcessHeap(), 0, pt
);
1146 case EMR_POLYDRAW16
:
1148 const EMRPOLYDRAW16
*pPolyDraw16
= (const EMRPOLYDRAW16
*)mr
;
1149 const POINTS
*ptl
= pPolyDraw16
->apts
;
1150 POINT
*pts
= HeapAlloc(GetProcessHeap(), 0, pPolyDraw16
->cpts
* sizeof(POINT
));
1153 /* NB abTypes array doesn't start at pPolyDraw16->abTypes. It's actually
1154 pPolyDraw16->apts + pPolyDraw16->cpts. */
1155 const BYTE
*types
= (BYTE
*)(pPolyDraw16
->apts
+ pPolyDraw16
->cpts
);
1160 for (i
= 0; i
< pPolyDraw16
->cpts
; ++i
)
1162 pts
[i
].x
= ptl
[i
].x
;
1163 pts
[i
].y
= ptl
[i
].y
;
1166 PolyDraw(hdc
, pts
, types
, pPolyDraw16
->cpts
);
1167 HeapFree(GetProcessHeap(), 0, pts
);
1171 case EMR_STRETCHDIBITS
:
1173 const EMRSTRETCHDIBITS
*pStretchDIBits
= (const EMRSTRETCHDIBITS
*)mr
;
1176 pStretchDIBits
->xDest
,
1177 pStretchDIBits
->yDest
,
1178 pStretchDIBits
->cxDest
,
1179 pStretchDIBits
->cyDest
,
1180 pStretchDIBits
->xSrc
,
1181 pStretchDIBits
->ySrc
,
1182 pStretchDIBits
->cxSrc
,
1183 pStretchDIBits
->cySrc
,
1184 (const BYTE
*)mr
+ pStretchDIBits
->offBitsSrc
,
1185 (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchDIBits
->offBmiSrc
),
1186 pStretchDIBits
->iUsageSrc
,
1187 pStretchDIBits
->dwRop
);
1191 case EMR_EXTTEXTOUTA
:
1193 const EMREXTTEXTOUTA
*pExtTextOutA
= (const EMREXTTEXTOUTA
*)mr
;
1195 const INT
*dx
= NULL
;
1198 rc
.left
= pExtTextOutA
->emrtext
.rcl
.left
;
1199 rc
.top
= pExtTextOutA
->emrtext
.rcl
.top
;
1200 rc
.right
= pExtTextOutA
->emrtext
.rcl
.right
;
1201 rc
.bottom
= pExtTextOutA
->emrtext
.rcl
.bottom
;
1202 TRACE("EMR_EXTTEXTOUTA: x,y = %d, %d. rect = %s. flags %08x\n",
1203 pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1204 wine_dbgstr_rect(&rc
), pExtTextOutA
->emrtext
.fOptions
);
1206 old_mode
= SetGraphicsMode(hdc
, pExtTextOutA
->iGraphicsMode
);
1207 /* Reselect the font back into the dc so that the transformation
1209 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1211 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1212 * These files can be enumerated and played under Win98 just
1213 * fine, but at least Win2k chokes on them.
1215 if (pExtTextOutA
->emrtext
.offDx
)
1216 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offDx
);
1218 ExtTextOutA(hdc
, pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1219 pExtTextOutA
->emrtext
.fOptions
, &rc
,
1220 (LPCSTR
)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offString
), pExtTextOutA
->emrtext
.nChars
,
1223 SetGraphicsMode(hdc
, old_mode
);
1227 case EMR_EXTTEXTOUTW
:
1229 const EMREXTTEXTOUTW
*pExtTextOutW
= (const EMREXTTEXTOUTW
*)mr
;
1231 const INT
*dx
= NULL
;
1234 rc
.left
= pExtTextOutW
->emrtext
.rcl
.left
;
1235 rc
.top
= pExtTextOutW
->emrtext
.rcl
.top
;
1236 rc
.right
= pExtTextOutW
->emrtext
.rcl
.right
;
1237 rc
.bottom
= pExtTextOutW
->emrtext
.rcl
.bottom
;
1238 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %s. flags %08x\n",
1239 pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1240 wine_dbgstr_rect(&rc
), pExtTextOutW
->emrtext
.fOptions
);
1242 old_mode
= SetGraphicsMode(hdc
, pExtTextOutW
->iGraphicsMode
);
1243 /* Reselect the font back into the dc so that the transformation
1245 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1247 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1248 * These files can be enumerated and played under Win98 just
1249 * fine, but at least Win2k chokes on them.
1251 if (pExtTextOutW
->emrtext
.offDx
)
1252 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offDx
);
1254 ExtTextOutW(hdc
, pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1255 pExtTextOutW
->emrtext
.fOptions
, &rc
,
1256 (LPCWSTR
)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offString
), pExtTextOutW
->emrtext
.nChars
,
1259 SetGraphicsMode(hdc
, old_mode
);
1263 case EMR_CREATEPALETTE
:
1265 const EMRCREATEPALETTE
*lpCreatePal
= (const EMRCREATEPALETTE
*)mr
;
1267 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1268 CreatePalette( &lpCreatePal
->lgpl
);
1273 case EMR_SELECTPALETTE
:
1275 const EMRSELECTPALETTE
*lpSelectPal
= (const EMRSELECTPALETTE
*)mr
;
1277 if( lpSelectPal
->ihPal
& 0x80000000 ) {
1278 SelectPalette( hdc
, GetStockObject(lpSelectPal
->ihPal
& 0x7fffffff), TRUE
);
1280 SelectPalette( hdc
, (handletable
->objectHandle
)[lpSelectPal
->ihPal
], TRUE
);
1285 case EMR_REALIZEPALETTE
:
1287 RealizePalette( hdc
);
1291 case EMR_EXTSELECTCLIPRGN
:
1293 const EMREXTSELECTCLIPRGN
*lpRgn
= (const EMREXTSELECTCLIPRGN
*)mr
;
1296 if (mr
->nSize
>= sizeof(*lpRgn
) + sizeof(RGNDATAHEADER
))
1297 hRgn
= ExtCreateRegion( &info
->init_transform
, 0, (const RGNDATA
*)lpRgn
->RgnData
);
1299 ExtSelectClipRgn(hdc
, hRgn
, (INT
)(lpRgn
->iMode
));
1300 /* ExtSelectClipRgn created a copy of the region */
1305 case EMR_SETMETARGN
:
1311 case EMR_SETWORLDTRANSFORM
:
1313 const EMRSETWORLDTRANSFORM
*lpXfrm
= (const EMRSETWORLDTRANSFORM
*)mr
;
1314 info
->state
.world_transform
= lpXfrm
->xform
;
1317 EMF_Update_MF_Xform(hdc
, info
);
1322 case EMR_POLYBEZIER
:
1324 const EMRPOLYBEZIER
*lpPolyBez
= (const EMRPOLYBEZIER
*)mr
;
1325 PolyBezier(hdc
, (const POINT
*)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1331 const EMRPOLYGON
*lpPoly
= (const EMRPOLYGON
*)mr
;
1332 Polygon( hdc
, (const POINT
*)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1338 const EMRPOLYLINE
*lpPolyLine
= (const EMRPOLYLINE
*)mr
;
1339 Polyline(hdc
, (const POINT
*)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1343 case EMR_POLYBEZIERTO
:
1345 const EMRPOLYBEZIERTO
*lpPolyBezierTo
= (const EMRPOLYBEZIERTO
*)mr
;
1346 PolyBezierTo( hdc
, (const POINT
*)lpPolyBezierTo
->aptl
,
1347 (UINT
)lpPolyBezierTo
->cptl
);
1351 case EMR_POLYLINETO
:
1353 const EMRPOLYLINETO
*lpPolyLineTo
= (const EMRPOLYLINETO
*)mr
;
1354 PolylineTo( hdc
, (const POINT
*)lpPolyLineTo
->aptl
,
1355 (UINT
)lpPolyLineTo
->cptl
);
1359 case EMR_POLYPOLYLINE
:
1361 const EMRPOLYPOLYLINE
*pPolyPolyline
= (const EMRPOLYPOLYLINE
*)mr
;
1362 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1364 PolyPolyline(hdc
, (const POINT
*)(pPolyPolyline
->aPolyCounts
+
1365 pPolyPolyline
->nPolys
),
1366 pPolyPolyline
->aPolyCounts
,
1367 pPolyPolyline
->nPolys
);
1372 case EMR_POLYPOLYGON
:
1374 const EMRPOLYPOLYGON
*pPolyPolygon
= (const EMRPOLYPOLYGON
*)mr
;
1376 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1378 PolyPolygon(hdc
, (const POINT
*)(pPolyPolygon
->aPolyCounts
+
1379 pPolyPolygon
->nPolys
),
1380 (const INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
1384 case EMR_SETBRUSHORGEX
:
1386 const EMRSETBRUSHORGEX
*lpSetBrushOrgEx
= (const EMRSETBRUSHORGEX
*)mr
;
1389 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1390 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1398 const EMRSETPIXELV
*lpSetPixelV
= (const EMRSETPIXELV
*)mr
;
1401 (INT
)lpSetPixelV
->ptlPixel
.x
,
1402 (INT
)lpSetPixelV
->ptlPixel
.y
,
1403 lpSetPixelV
->crColor
);
1408 case EMR_SETMAPPERFLAGS
:
1410 const EMRSETMAPPERFLAGS
*lpSetMapperFlags
= (const EMRSETMAPPERFLAGS
*)mr
;
1412 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1417 case EMR_SETCOLORADJUSTMENT
:
1419 const EMRSETCOLORADJUSTMENT
*lpSetColorAdjust
= (const EMRSETCOLORADJUSTMENT
*)mr
;
1421 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1426 case EMR_OFFSETCLIPRGN
:
1428 const EMROFFSETCLIPRGN
*lpOffsetClipRgn
= (const EMROFFSETCLIPRGN
*)mr
;
1431 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1432 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1433 FIXME("OffsetClipRgn\n");
1438 case EMR_EXCLUDECLIPRECT
:
1440 const EMREXCLUDECLIPRECT
*lpExcludeClipRect
= (const EMREXCLUDECLIPRECT
*)mr
;
1442 ExcludeClipRect( hdc
,
1443 lpExcludeClipRect
->rclClip
.left
,
1444 lpExcludeClipRect
->rclClip
.top
,
1445 lpExcludeClipRect
->rclClip
.right
,
1446 lpExcludeClipRect
->rclClip
.bottom
);
1447 FIXME("ExcludeClipRect\n");
1452 case EMR_SCALEVIEWPORTEXTEX
:
1454 const EMRSCALEVIEWPORTEXTEX
*lpScaleViewportExtEx
= (const EMRSCALEVIEWPORTEXTEX
*)mr
;
1456 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1458 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1459 !lpScaleViewportExtEx
->yNum
|| !lpScaleViewportExtEx
->yDenom
)
1461 info
->state
.vportExtX
= MulDiv(info
->state
.vportExtX
, lpScaleViewportExtEx
->xNum
,
1462 lpScaleViewportExtEx
->xDenom
);
1463 info
->state
.vportExtY
= MulDiv(info
->state
.vportExtY
, lpScaleViewportExtEx
->yNum
,
1464 lpScaleViewportExtEx
->yDenom
);
1465 if (info
->state
.vportExtX
== 0) info
->state
.vportExtX
= 1;
1466 if (info
->state
.vportExtY
== 0) info
->state
.vportExtY
= 1;
1467 if (info
->state
.mode
== MM_ISOTROPIC
)
1468 EMF_FixIsotropic(hdc
, info
);
1470 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1471 lpScaleViewportExtEx
->xNum
,lpScaleViewportExtEx
->xDenom
,
1472 lpScaleViewportExtEx
->yNum
,lpScaleViewportExtEx
->yDenom
);
1475 EMF_Update_MF_Xform(hdc
, info
);
1480 case EMR_SCALEWINDOWEXTEX
:
1482 const EMRSCALEWINDOWEXTEX
*lpScaleWindowExtEx
= (const EMRSCALEWINDOWEXTEX
*)mr
;
1484 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1486 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1487 !lpScaleWindowExtEx
->yNum
|| !lpScaleWindowExtEx
->yDenom
)
1489 info
->state
.wndExtX
= MulDiv(info
->state
.wndExtX
, lpScaleWindowExtEx
->xNum
,
1490 lpScaleWindowExtEx
->xDenom
);
1491 info
->state
.wndExtY
= MulDiv(info
->state
.wndExtY
, lpScaleWindowExtEx
->yNum
,
1492 lpScaleWindowExtEx
->yDenom
);
1493 if (info
->state
.wndExtX
== 0) info
->state
.wndExtX
= 1;
1494 if (info
->state
.wndExtY
== 0) info
->state
.wndExtY
= 1;
1495 if (info
->state
.mode
== MM_ISOTROPIC
)
1496 EMF_FixIsotropic(hdc
, info
);
1498 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1499 lpScaleWindowExtEx
->xNum
,lpScaleWindowExtEx
->xDenom
,
1500 lpScaleWindowExtEx
->yNum
,lpScaleWindowExtEx
->yDenom
);
1503 EMF_Update_MF_Xform(hdc
, info
);
1508 case EMR_MODIFYWORLDTRANSFORM
:
1510 const EMRMODIFYWORLDTRANSFORM
*lpModifyWorldTrans
= (const EMRMODIFYWORLDTRANSFORM
*)mr
;
1512 switch(lpModifyWorldTrans
->iMode
) {
1514 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
1515 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
1516 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
1518 EMF_Update_MF_Xform(hdc
, info
);
1520 case MWT_LEFTMULTIPLY
:
1521 CombineTransform(&info
->state
.world_transform
, &lpModifyWorldTrans
->xform
,
1522 &info
->state
.world_transform
);
1524 ModifyWorldTransform(hdc
, &lpModifyWorldTrans
->xform
, MWT_LEFTMULTIPLY
);
1526 case MWT_RIGHTMULTIPLY
:
1527 CombineTransform(&info
->state
.world_transform
, &info
->state
.world_transform
,
1528 &lpModifyWorldTrans
->xform
);
1530 EMF_Update_MF_Xform(hdc
, info
);
1533 FIXME("Unknown imode %d\n", lpModifyWorldTrans
->iMode
);
1541 const EMRANGLEARC
*lpAngleArc
= (const EMRANGLEARC
*)mr
;
1544 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1545 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1546 lpAngleArc
->eSweepAngle
);
1553 const EMRROUNDRECT
*lpRoundRect
= (const EMRROUNDRECT
*)mr
;
1556 lpRoundRect
->rclBox
.left
,
1557 lpRoundRect
->rclBox
.top
,
1558 lpRoundRect
->rclBox
.right
,
1559 lpRoundRect
->rclBox
.bottom
,
1560 lpRoundRect
->szlCorner
.cx
,
1561 lpRoundRect
->szlCorner
.cy
);
1568 const EMRARC
*lpArc
= (const EMRARC
*)mr
;
1571 (INT
)lpArc
->rclBox
.left
,
1572 (INT
)lpArc
->rclBox
.top
,
1573 (INT
)lpArc
->rclBox
.right
,
1574 (INT
)lpArc
->rclBox
.bottom
,
1575 (INT
)lpArc
->ptlStart
.x
,
1576 (INT
)lpArc
->ptlStart
.y
,
1577 (INT
)lpArc
->ptlEnd
.x
,
1578 (INT
)lpArc
->ptlEnd
.y
);
1585 const EMRCHORD
*lpChord
= (const EMRCHORD
*)mr
;
1588 (INT
)lpChord
->rclBox
.left
,
1589 (INT
)lpChord
->rclBox
.top
,
1590 (INT
)lpChord
->rclBox
.right
,
1591 (INT
)lpChord
->rclBox
.bottom
,
1592 (INT
)lpChord
->ptlStart
.x
,
1593 (INT
)lpChord
->ptlStart
.y
,
1594 (INT
)lpChord
->ptlEnd
.x
,
1595 (INT
)lpChord
->ptlEnd
.y
);
1602 const EMRPIE
*lpPie
= (const EMRPIE
*)mr
;
1605 (INT
)lpPie
->rclBox
.left
,
1606 (INT
)lpPie
->rclBox
.top
,
1607 (INT
)lpPie
->rclBox
.right
,
1608 (INT
)lpPie
->rclBox
.bottom
,
1609 (INT
)lpPie
->ptlStart
.x
,
1610 (INT
)lpPie
->ptlStart
.y
,
1611 (INT
)lpPie
->ptlEnd
.x
,
1612 (INT
)lpPie
->ptlEnd
.y
);
1619 const EMRARC
*lpArcTo
= (const EMRARC
*)mr
;
1622 (INT
)lpArcTo
->rclBox
.left
,
1623 (INT
)lpArcTo
->rclBox
.top
,
1624 (INT
)lpArcTo
->rclBox
.right
,
1625 (INT
)lpArcTo
->rclBox
.bottom
,
1626 (INT
)lpArcTo
->ptlStart
.x
,
1627 (INT
)lpArcTo
->ptlStart
.y
,
1628 (INT
)lpArcTo
->ptlEnd
.x
,
1629 (INT
)lpArcTo
->ptlEnd
.y
);
1634 case EMR_EXTFLOODFILL
:
1636 const EMREXTFLOODFILL
*lpExtFloodFill
= (const EMREXTFLOODFILL
*)mr
;
1639 (INT
)lpExtFloodFill
->ptlStart
.x
,
1640 (INT
)lpExtFloodFill
->ptlStart
.y
,
1641 lpExtFloodFill
->crColor
,
1642 (UINT
)lpExtFloodFill
->iMode
);
1649 const EMRPOLYDRAW
*lpPolyDraw
= (const EMRPOLYDRAW
*)mr
;
1651 /* NB abTypes array doesn't start at lpPolyDraw->abTypes. It's actually
1652 lpPolyDraw->aptl + lpPolyDraw->cptl. */
1654 (const POINT
*)lpPolyDraw
->aptl
,
1655 (BYTE
*)(lpPolyDraw
->aptl
+ lpPolyDraw
->cptl
),
1656 (INT
)lpPolyDraw
->cptl
);
1661 case EMR_SETARCDIRECTION
:
1663 const EMRSETARCDIRECTION
*lpSetArcDirection
= (const EMRSETARCDIRECTION
*)mr
;
1664 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1668 case EMR_SETMITERLIMIT
:
1670 const EMRSETMITERLIMIT
*lpSetMiterLimit
= (const EMRSETMITERLIMIT
*)mr
;
1671 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1687 case EMR_CLOSEFIGURE
:
1695 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1700 case EMR_STROKEANDFILLPATH
:
1702 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1703 StrokeAndFillPath( hdc
);
1707 case EMR_STROKEPATH
:
1709 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1714 case EMR_FLATTENPATH
:
1726 case EMR_SELECTCLIPPATH
:
1728 const EMRSELECTCLIPPATH
*lpSelectClipPath
= (const EMRSELECTCLIPPATH
*)mr
;
1729 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1739 case EMR_CREATECOLORSPACE
:
1741 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1742 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1743 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1747 case EMR_SETCOLORSPACE
:
1749 const EMRSETCOLORSPACE
*lpSetColorSpace
= (const EMRSETCOLORSPACE
*)mr
;
1751 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1755 case EMR_DELETECOLORSPACE
:
1757 const EMRDELETECOLORSPACE
*lpDeleteColorSpace
= (const EMRDELETECOLORSPACE
*)mr
;
1758 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1762 case EMR_SETICMMODE
:
1764 const EMRSETICMMODE
*lpSetICMMode
= (const EMRSETICMMODE
*)mr
;
1765 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1769 case EMR_PIXELFORMAT
:
1772 const EMRPIXELFORMAT
*lpPixelFormat
= (const EMRPIXELFORMAT
*)mr
;
1774 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1775 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1780 case EMR_SETPALETTEENTRIES
:
1782 const EMRSETPALETTEENTRIES
*lpSetPaletteEntries
= (const EMRSETPALETTEENTRIES
*)mr
;
1784 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1785 (UINT
)lpSetPaletteEntries
->iStart
,
1786 (UINT
)lpSetPaletteEntries
->cEntries
,
1787 lpSetPaletteEntries
->aPalEntries
);
1792 case EMR_RESIZEPALETTE
:
1794 const EMRRESIZEPALETTE
*lpResizePalette
= (const EMRRESIZEPALETTE
*)mr
;
1796 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1797 (UINT
)lpResizePalette
->cEntries
);
1802 case EMR_CREATEDIBPATTERNBRUSHPT
:
1804 const EMRCREATEDIBPATTERNBRUSHPT
*lpCreate
= (const EMRCREATEDIBPATTERNBRUSHPT
*)mr
;
1805 LPVOID lpPackedStruct
;
1807 /* Check that offsets and data are contained within the record
1808 * (including checking for wrap-arounds).
1810 if ( lpCreate
->offBmi
+ lpCreate
->cbBmi
> mr
->nSize
1811 || lpCreate
->offBits
+ lpCreate
->cbBits
> mr
->nSize
1812 || lpCreate
->offBmi
+ lpCreate
->cbBmi
< lpCreate
->offBmi
1813 || lpCreate
->offBits
+ lpCreate
->cbBits
< lpCreate
->offBits
)
1815 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1819 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1820 lpPackedStruct
= HeapAlloc( GetProcessHeap(), 0,
1821 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1824 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1828 /* Now pack this structure */
1829 memcpy( lpPackedStruct
,
1830 ((const BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1832 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1833 ((const BYTE
*)lpCreate
) + lpCreate
->offBits
,
1836 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1837 CreateDIBPatternBrushPt( lpPackedStruct
,
1838 (UINT
)lpCreate
->iUsage
);
1840 HeapFree(GetProcessHeap(), 0, lpPackedStruct
);
1844 case EMR_CREATEMONOBRUSH
:
1846 const EMRCREATEMONOBRUSH
*pCreateMonoBrush
= (const EMRCREATEMONOBRUSH
*)mr
;
1847 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
1850 /* Need to check if the bitmap is monochrome, and if the
1851 two colors are really black and white */
1852 if (pCreateMonoBrush
->iUsage
== DIB_PAL_MONO
)
1856 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1857 * aligned to 32 rather than 16 bits.
1860 bm
.bmWidth
= pbi
->bmiHeader
.biWidth
;
1861 bm
.bmHeight
= abs(pbi
->bmiHeader
.biHeight
);
1862 bm
.bmWidthBytes
= 4 * ((pbi
->bmiHeader
.biWidth
+ 31) / 32);
1863 bm
.bmPlanes
= pbi
->bmiHeader
.biPlanes
;
1864 bm
.bmBitsPixel
= pbi
->bmiHeader
.biBitCount
;
1865 bm
.bmBits
= (BYTE
*)mr
+ pCreateMonoBrush
->offBits
;
1866 hBmp
= CreateBitmapIndirect(&bm
);
1868 else if (is_dib_monochrome(pbi
))
1870 /* Top-down DIBs have a negative height */
1871 LONG height
= pbi
->bmiHeader
.biHeight
;
1873 hBmp
= CreateBitmap(pbi
->bmiHeader
.biWidth
, abs(height
), 1, 1, NULL
);
1874 SetDIBits(hdc
, hBmp
, 0, pbi
->bmiHeader
.biHeight
,
1875 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1879 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1880 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1883 (handletable
->objectHandle
)[pCreateMonoBrush
->ihBrush
] = CreatePatternBrush(hBmp
);
1885 /* CreatePatternBrush created a copy of the bitmap */
1892 const EMRBITBLT
*pBitBlt
= (const EMRBITBLT
*)mr
;
1894 if(pBitBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1895 PatBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1897 } else { /* BitBlt */
1898 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1899 HBRUSH hBrush
, hBrushOld
;
1900 HBITMAP hBmp
= 0, hBmpOld
= 0;
1901 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pBitBlt
->offBmiSrc
);
1903 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1904 SetWorldTransform(hdcSrc
, &pBitBlt
->xformSrc
);
1906 hBrush
= CreateSolidBrush(pBitBlt
->crBkColorSrc
);
1907 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1908 PatBlt(hdcSrc
, pBitBlt
->rclBounds
.left
, pBitBlt
->rclBounds
.top
,
1909 pBitBlt
->rclBounds
.right
- pBitBlt
->rclBounds
.left
,
1910 pBitBlt
->rclBounds
.bottom
- pBitBlt
->rclBounds
.top
, PATCOPY
);
1911 SelectObject(hdcSrc
, hBrushOld
);
1912 DeleteObject(hBrush
);
1914 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1915 (const BYTE
*)mr
+ pBitBlt
->offBitsSrc
, pbi
, pBitBlt
->iUsageSrc
);
1916 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1918 BitBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1919 hdcSrc
, pBitBlt
->xSrc
, pBitBlt
->ySrc
, pBitBlt
->dwRop
);
1921 SelectObject(hdcSrc
, hBmpOld
);
1928 case EMR_STRETCHBLT
:
1930 const EMRSTRETCHBLT
*pStretchBlt
= (const EMRSTRETCHBLT
*)mr
;
1932 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1933 pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1934 pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1935 pStretchBlt
->dwRop
, pStretchBlt
->offBitsSrc
);
1937 if(pStretchBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1938 PatBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1939 pStretchBlt
->dwRop
);
1940 } else { /* StretchBlt */
1941 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1942 HBRUSH hBrush
, hBrushOld
;
1943 HBITMAP hBmp
= 0, hBmpOld
= 0;
1944 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchBlt
->offBmiSrc
);
1946 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1947 SetWorldTransform(hdcSrc
, &pStretchBlt
->xformSrc
);
1949 hBrush
= CreateSolidBrush(pStretchBlt
->crBkColorSrc
);
1950 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1951 PatBlt(hdcSrc
, pStretchBlt
->rclBounds
.left
, pStretchBlt
->rclBounds
.top
,
1952 pStretchBlt
->rclBounds
.right
- pStretchBlt
->rclBounds
.left
,
1953 pStretchBlt
->rclBounds
.bottom
- pStretchBlt
->rclBounds
.top
, PATCOPY
);
1954 SelectObject(hdcSrc
, hBrushOld
);
1955 DeleteObject(hBrush
);
1957 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1958 (const BYTE
*)mr
+ pStretchBlt
->offBitsSrc
, pbi
, pStretchBlt
->iUsageSrc
);
1959 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1961 StretchBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1962 hdcSrc
, pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1963 pStretchBlt
->dwRop
);
1965 SelectObject(hdcSrc
, hBmpOld
);
1972 case EMR_ALPHABLEND
:
1974 const EMRALPHABLEND
*pAlphaBlend
= (const EMRALPHABLEND
*)mr
;
1976 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1977 pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1978 pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1979 pAlphaBlend
->dwRop
, pAlphaBlend
->offBitsSrc
);
1981 if(pAlphaBlend
->offBmiSrc
== 0) {
1982 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1984 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1985 HBITMAP hBmp
= 0, hBmpOld
= 0;
1986 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pAlphaBlend
->offBmiSrc
);
1989 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1990 SetWorldTransform(hdcSrc
, &pAlphaBlend
->xformSrc
);
1992 hBmp
= CreateDIBSection(hdc
, pbi
, pAlphaBlend
->iUsageSrc
, &bits
, NULL
, 0);
1993 memcpy(bits
, (const BYTE
*)mr
+ pAlphaBlend
->offBitsSrc
, pAlphaBlend
->cbBitsSrc
);
1994 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1996 GdiAlphaBlend(hdc
, pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1997 hdcSrc
, pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1998 *(BLENDFUNCTION
*)&pAlphaBlend
->dwRop
);
2000 SelectObject(hdcSrc
, hBmpOld
);
2009 const EMRMASKBLT
*pMaskBlt
= (const EMRMASKBLT
*)mr
;
2010 HDC hdcSrc
= CreateCompatibleDC(hdc
);
2011 HBRUSH hBrush
, hBrushOld
;
2012 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
2013 const BITMAPINFO
*pbi
;
2015 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
2016 SetWorldTransform(hdcSrc
, &pMaskBlt
->xformSrc
);
2018 hBrush
= CreateSolidBrush(pMaskBlt
->crBkColorSrc
);
2019 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
2020 PatBlt(hdcSrc
, pMaskBlt
->rclBounds
.left
, pMaskBlt
->rclBounds
.top
,
2021 pMaskBlt
->rclBounds
.right
- pMaskBlt
->rclBounds
.left
,
2022 pMaskBlt
->rclBounds
.bottom
- pMaskBlt
->rclBounds
.top
, PATCOPY
);
2023 SelectObject(hdcSrc
, hBrushOld
);
2024 DeleteObject(hBrush
);
2026 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiMask
);
2027 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2029 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2030 (const BYTE
*)mr
+ pMaskBlt
->offBitsMask
, pbi
, pMaskBlt
->iUsageMask
);
2032 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiSrc
);
2033 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2034 (const BYTE
*)mr
+ pMaskBlt
->offBitsSrc
, pbi
, pMaskBlt
->iUsageSrc
);
2035 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2048 SelectObject(hdcSrc
, hBmpOld
);
2050 DeleteObject(hBmpMask
);
2057 const EMRPLGBLT
*pPlgBlt
= (const EMRPLGBLT
*)mr
;
2058 HDC hdcSrc
= CreateCompatibleDC(hdc
);
2059 HBRUSH hBrush
, hBrushOld
;
2060 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
2061 const BITMAPINFO
*pbi
;
2064 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
2065 SetWorldTransform(hdcSrc
, &pPlgBlt
->xformSrc
);
2067 pts
[0].x
= pPlgBlt
->aptlDest
[0].x
; pts
[0].y
= pPlgBlt
->aptlDest
[0].y
;
2068 pts
[1].x
= pPlgBlt
->aptlDest
[1].x
; pts
[1].y
= pPlgBlt
->aptlDest
[1].y
;
2069 pts
[2].x
= pPlgBlt
->aptlDest
[2].x
; pts
[2].y
= pPlgBlt
->aptlDest
[2].y
;
2071 hBrush
= CreateSolidBrush(pPlgBlt
->crBkColorSrc
);
2072 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
2073 PatBlt(hdcSrc
, pPlgBlt
->rclBounds
.left
, pPlgBlt
->rclBounds
.top
,
2074 pPlgBlt
->rclBounds
.right
- pPlgBlt
->rclBounds
.left
,
2075 pPlgBlt
->rclBounds
.bottom
- pPlgBlt
->rclBounds
.top
, PATCOPY
);
2076 SelectObject(hdcSrc
, hBrushOld
);
2077 DeleteObject(hBrush
);
2079 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiMask
);
2080 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2082 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2083 (const BYTE
*)mr
+ pPlgBlt
->offBitsMask
, pbi
, pPlgBlt
->iUsageMask
);
2085 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiSrc
);
2086 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2087 (const BYTE
*)mr
+ pPlgBlt
->offBitsSrc
, pbi
, pPlgBlt
->iUsageSrc
);
2088 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2099 SelectObject(hdcSrc
, hBmpOld
);
2101 DeleteObject(hBmpMask
);
2106 case EMR_SETDIBITSTODEVICE
:
2108 const EMRSETDIBITSTODEVICE
*pSetDIBitsToDevice
= (const EMRSETDIBITSTODEVICE
*)mr
;
2110 SetDIBitsToDevice(hdc
,
2111 pSetDIBitsToDevice
->xDest
,
2112 pSetDIBitsToDevice
->yDest
,
2113 pSetDIBitsToDevice
->cxSrc
,
2114 pSetDIBitsToDevice
->cySrc
,
2115 pSetDIBitsToDevice
->xSrc
,
2116 pSetDIBitsToDevice
->ySrc
,
2117 pSetDIBitsToDevice
->iStartScan
,
2118 pSetDIBitsToDevice
->cScans
,
2119 (const BYTE
*)mr
+ pSetDIBitsToDevice
->offBitsSrc
,
2120 (const BITMAPINFO
*)((const BYTE
*)mr
+ pSetDIBitsToDevice
->offBmiSrc
),
2121 pSetDIBitsToDevice
->iUsageSrc
);
2125 case EMR_POLYTEXTOUTA
:
2127 const EMRPOLYTEXTOUTA
*pPolyTextOutA
= (const EMRPOLYTEXTOUTA
*)mr
;
2128 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
2130 XFORM xform
, xformOld
;
2133 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
2134 GetWorldTransform(hdc
, &xformOld
);
2136 xform
.eM11
= pPolyTextOutA
->exScale
;
2139 xform
.eM22
= pPolyTextOutA
->eyScale
;
2142 SetWorldTransform(hdc
, &xform
);
2144 /* Set up POLYTEXTA structures */
2145 for(i
= 0; i
< pPolyTextOutA
->cStrings
; i
++)
2147 polytextA
[i
].x
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.x
;
2148 polytextA
[i
].y
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.y
;
2149 polytextA
[i
].n
= pPolyTextOutA
->aemrtext
[i
].nChars
;
2150 polytextA
[i
].lpstr
= (LPCSTR
)((const BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offString
);
2151 polytextA
[i
].uiFlags
= pPolyTextOutA
->aemrtext
[i
].fOptions
;
2152 polytextA
[i
].rcl
.left
= pPolyTextOutA
->aemrtext
[i
].rcl
.left
;
2153 polytextA
[i
].rcl
.right
= pPolyTextOutA
->aemrtext
[i
].rcl
.right
;
2154 polytextA
[i
].rcl
.top
= pPolyTextOutA
->aemrtext
[i
].rcl
.top
;
2155 polytextA
[i
].rcl
.bottom
= pPolyTextOutA
->aemrtext
[i
].rcl
.bottom
;
2156 polytextA
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offDx
);
2158 PolyTextOutA(hdc
, polytextA
, pPolyTextOutA
->cStrings
);
2159 HeapFree(GetProcessHeap(), 0, polytextA
);
2161 SetWorldTransform(hdc
, &xformOld
);
2162 SetGraphicsMode(hdc
, gModeOld
);
2166 case EMR_POLYTEXTOUTW
:
2168 const EMRPOLYTEXTOUTW
*pPolyTextOutW
= (const EMRPOLYTEXTOUTW
*)mr
;
2169 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
2171 XFORM xform
, xformOld
;
2174 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
2175 GetWorldTransform(hdc
, &xformOld
);
2177 xform
.eM11
= pPolyTextOutW
->exScale
;
2180 xform
.eM22
= pPolyTextOutW
->eyScale
;
2183 SetWorldTransform(hdc
, &xform
);
2185 /* Set up POLYTEXTW structures */
2186 for(i
= 0; i
< pPolyTextOutW
->cStrings
; i
++)
2188 polytextW
[i
].x
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.x
;
2189 polytextW
[i
].y
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.y
;
2190 polytextW
[i
].n
= pPolyTextOutW
->aemrtext
[i
].nChars
;
2191 polytextW
[i
].lpstr
= (LPCWSTR
)((const BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offString
);
2192 polytextW
[i
].uiFlags
= pPolyTextOutW
->aemrtext
[i
].fOptions
;
2193 polytextW
[i
].rcl
.left
= pPolyTextOutW
->aemrtext
[i
].rcl
.left
;
2194 polytextW
[i
].rcl
.right
= pPolyTextOutW
->aemrtext
[i
].rcl
.right
;
2195 polytextW
[i
].rcl
.top
= pPolyTextOutW
->aemrtext
[i
].rcl
.top
;
2196 polytextW
[i
].rcl
.bottom
= pPolyTextOutW
->aemrtext
[i
].rcl
.bottom
;
2197 polytextW
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offDx
);
2199 PolyTextOutW(hdc
, polytextW
, pPolyTextOutW
->cStrings
);
2200 HeapFree(GetProcessHeap(), 0, polytextW
);
2202 SetWorldTransform(hdc
, &xformOld
);
2203 SetGraphicsMode(hdc
, gModeOld
);
2209 const EMRFILLRGN
*pFillRgn
= (const EMRFILLRGN
*)mr
;
2210 HRGN hRgn
= ExtCreateRegion(NULL
, pFillRgn
->cbRgnData
, (const RGNDATA
*)pFillRgn
->RgnData
);
2213 (handletable
->objectHandle
)[pFillRgn
->ihBrush
]);
2220 const EMRFRAMERGN
*pFrameRgn
= (const EMRFRAMERGN
*)mr
;
2221 HRGN hRgn
= ExtCreateRegion(NULL
, pFrameRgn
->cbRgnData
, (const RGNDATA
*)pFrameRgn
->RgnData
);
2224 (handletable
->objectHandle
)[pFrameRgn
->ihBrush
],
2225 pFrameRgn
->szlStroke
.cx
,
2226 pFrameRgn
->szlStroke
.cy
);
2233 const EMRINVERTRGN
*pInvertRgn
= (const EMRINVERTRGN
*)mr
;
2234 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (const RGNDATA
*)pInvertRgn
->RgnData
);
2235 InvertRgn(hdc
, hRgn
);
2242 const EMRPAINTRGN
*pPaintRgn
= (const EMRPAINTRGN
*)mr
;
2243 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (const RGNDATA
*)pPaintRgn
->RgnData
);
2244 PaintRgn(hdc
, hRgn
);
2249 case EMR_SETTEXTJUSTIFICATION
:
2251 const EMRSETTEXTJUSTIFICATION
*pSetTextJust
= (const EMRSETTEXTJUSTIFICATION
*)mr
;
2252 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
2258 const EMRSETLAYOUT
*pSetLayout
= (const EMRSETLAYOUT
*)mr
;
2259 SetLayout(hdc
, pSetLayout
->iMode
);
2263 case EMR_GRADIENTFILL
:
2265 EMRGRADIENTFILL
*grad
= (EMRGRADIENTFILL
*)mr
;
2266 GdiGradientFill( hdc
, grad
->Ver
, grad
->nVer
, grad
->Ver
+ grad
->nVer
,
2267 grad
->nTri
, grad
->ulMode
);
2272 case EMR_GLSBOUNDEDRECORD
:
2273 case EMR_DRAWESCAPE
:
2276 case EMR_SMALLTEXTOUT
:
2277 case EMR_FORCEUFIMAPPING
:
2278 case EMR_NAMEDESCAPE
:
2279 case EMR_COLORCORRECTPALETTE
:
2280 case EMR_SETICMPROFILEA
:
2281 case EMR_SETICMPROFILEW
:
2282 case EMR_TRANSPARENTBLT
:
2283 case EMR_SETLINKEDUFI
:
2284 case EMR_COLORMATCHTOTARGETW
:
2285 case EMR_CREATECOLORSPACEW
:
2288 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2289 record then ignore and return TRUE. */
2290 FIXME("type %d is unimplemented\n", type
);
2293 tmprc
.left
= tmprc
.top
= 0;
2294 tmprc
.right
= tmprc
.bottom
= 1000;
2295 LPtoDP(hdc
, (POINT
*)&tmprc
, 2);
2296 TRACE("L:0,0 - 1000,1000 -> D:%s\n", wine_dbgstr_rect(&tmprc
));
2302 /*****************************************************************************
2304 * EnumEnhMetaFile (GDI32.@)
2306 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2308 * record. Returns when either every record has been used or
2309 * when _EnhMetaFunc_ returns FALSE.
2313 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2320 * This function behaves differently in Win9x and WinNT.
2322 * In WinNT, the DC's world transform is updated as the EMF changes
2323 * the Window/Viewport Extent and Origin or its world transform.
2324 * The actual Window/Viewport Extent and Origin are left untouched.
2326 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2327 * updates the scaling itself but only just before a record that
2328 * writes anything to the DC.
2330 * I'm not sure where the data (enum_emh_data) is stored in either
2331 * version. For this implementation, it is stored before the handle
2332 * table, but it could be stored in the DC, in the EMF handle or in
2336 BOOL WINAPI
EnumEnhMetaFile(
2337 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
2338 HENHMETAFILE hmf
, /* [in] EMF to walk */
2339 ENHMFENUMPROC callback
, /* [in] callback function */
2340 LPVOID data
, /* [in] optional data for callback function */
2341 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
2353 HBRUSH hBrush
= NULL
;
2356 enum_emh_data
*info
;
2357 SIZE vp_size
, win_size
;
2358 POINT vp_org
, win_org
;
2359 INT mapMode
= MM_TEXT
, old_align
= 0, old_rop2
= 0, old_arcdir
= 0, old_polyfill
= 0, old_stretchblt
= 0;
2360 COLORREF old_text_color
= 0, old_bk_color
= 0;
2364 SetLastError(ERROR_INVALID_PARAMETER
);
2368 emh
= EMF_GetEnhMetaHeader(hmf
);
2370 SetLastError(ERROR_INVALID_HANDLE
);
2374 info
= HeapAlloc( GetProcessHeap(), 0,
2375 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2378 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2381 info
->state
.mode
= MM_TEXT
;
2382 info
->state
.wndOrgX
= 0;
2383 info
->state
.wndOrgY
= 0;
2384 info
->state
.wndExtX
= 1;
2385 info
->state
.wndExtY
= 1;
2386 info
->state
.vportOrgX
= 0;
2387 info
->state
.vportOrgY
= 0;
2388 info
->state
.vportExtX
= 1;
2389 info
->state
.vportExtY
= 1;
2390 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
2391 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
2392 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
2394 info
->state
.next
= NULL
;
2395 info
->save_level
= 0;
2396 info
->saved_state
= NULL
;
2398 ht
= (HANDLETABLE
*) &info
[1];
2399 ht
->objectHandle
[0] = hmf
;
2400 for(i
= 1; i
< emh
->nHandles
; i
++)
2401 ht
->objectHandle
[i
] = NULL
;
2405 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
2406 GetWorldTransform(hdc
, &savedXform
);
2407 GetViewportExtEx(hdc
, &vp_size
);
2408 GetWindowExtEx(hdc
, &win_size
);
2409 GetViewportOrgEx(hdc
, &vp_org
);
2410 GetWindowOrgEx(hdc
, &win_org
);
2411 mapMode
= GetMapMode(hdc
);
2414 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
2415 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
2416 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
2418 hRgn
= CreateRectRgn(0, 0, 0, 0);
2419 if (!GetClipRgn(hdc
, hRgn
))
2425 old_text_color
= SetTextColor(hdc
, RGB(0,0,0));
2426 old_bk_color
= SetBkColor(hdc
, RGB(0xff, 0xff, 0xff));
2427 old_align
= SetTextAlign(hdc
, 0);
2428 old_rop2
= SetROP2(hdc
, R2_COPYPEN
);
2429 old_arcdir
= SetArcDirection(hdc
, AD_COUNTERCLOCKWISE
);
2430 old_polyfill
= SetPolyFillMode(hdc
, ALTERNATE
);
2431 old_stretchblt
= SetStretchBltMode(hdc
, BLACKONWHITE
);
2435 /* Win95 leaves the vp/win ext/org info alone */
2436 info
->init_transform
.eM11
= 1.0;
2437 info
->init_transform
.eM12
= 0.0;
2438 info
->init_transform
.eM21
= 0.0;
2439 info
->init_transform
.eM22
= 1.0;
2440 info
->init_transform
.eDx
= 0.0;
2441 info
->init_transform
.eDy
= 0.0;
2445 /* WinNT combines the vp/win ext/org info into a transform */
2446 double xscale
, yscale
;
2447 xscale
= (double)vp_size
.cx
/ (double)win_size
.cx
;
2448 yscale
= (double)vp_size
.cy
/ (double)win_size
.cy
;
2449 info
->init_transform
.eM11
= xscale
;
2450 info
->init_transform
.eM12
= 0.0;
2451 info
->init_transform
.eM21
= 0.0;
2452 info
->init_transform
.eM22
= yscale
;
2453 info
->init_transform
.eDx
= (double)vp_org
.x
- xscale
* (double)win_org
.x
;
2454 info
->init_transform
.eDy
= (double)vp_org
.y
- yscale
* (double)win_org
.y
;
2456 CombineTransform(&info
->init_transform
, &savedXform
, &info
->init_transform
);
2459 if ( lpRect
&& WIDTH(emh
->rclFrame
) && HEIGHT(emh
->rclFrame
) )
2461 double xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
2464 TRACE("rect: %s. rclFrame: (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(lpRect
),
2465 emh
->rclFrame
.left
, emh
->rclFrame
.top
, emh
->rclFrame
.right
,
2466 emh
->rclFrame
.bottom
);
2468 xSrcPixSize
= (double) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
2469 ySrcPixSize
= (double) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
2470 xscale
= (double) WIDTH(*lpRect
) * 100.0 /
2471 WIDTH(emh
->rclFrame
) * xSrcPixSize
;
2472 yscale
= (double) HEIGHT(*lpRect
) * 100.0 /
2473 HEIGHT(emh
->rclFrame
) * ySrcPixSize
;
2474 TRACE("xscale = %f, yscale = %f\n", xscale
, yscale
);
2476 xform
.eM11
= xscale
;
2479 xform
.eM22
= yscale
;
2480 xform
.eDx
= (double) lpRect
->left
- (double) WIDTH(*lpRect
) / WIDTH(emh
->rclFrame
) * emh
->rclFrame
.left
;
2481 xform
.eDy
= (double) lpRect
->top
- (double) HEIGHT(*lpRect
) / HEIGHT(emh
->rclFrame
) * emh
->rclFrame
.top
;
2483 CombineTransform(&info
->init_transform
, &xform
, &info
->init_transform
);
2486 /* WinNT resets the current vp/win org/ext */
2489 SetMapMode(hdc
, MM_TEXT
);
2490 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2491 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2492 EMF_Update_MF_Xform(hdc
, info
);
2498 while(ret
&& offset
< emh
->nBytes
)
2500 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
2502 if (offset
+ 8 > emh
->nBytes
||
2503 offset
> offset
+ emr
->nSize
||
2504 offset
+ emr
->nSize
> emh
->nBytes
)
2506 WARN("record truncated\n");
2510 /* In Win9x mode we update the xform if the record will produce output */
2511 if (hdc
&& IS_WIN9X() && emr_produces_output(emr
->iType
))
2512 EMF_Update_MF_Xform(hdc
, info
);
2514 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr
->iType
), emr
->nSize
);
2515 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nHandles
, (LPARAM
)data
);
2516 offset
+= emr
->nSize
;
2521 SetStretchBltMode(hdc
, old_stretchblt
);
2522 SetPolyFillMode(hdc
, old_polyfill
);
2523 SetArcDirection(hdc
, old_arcdir
);
2524 SetROP2(hdc
, old_rop2
);
2525 SetTextAlign(hdc
, old_align
);
2526 SetBkColor(hdc
, old_bk_color
);
2527 SetTextColor(hdc
, old_text_color
);
2530 SelectObject(hdc
, hBrush
);
2531 SelectObject(hdc
, hPen
);
2532 SelectObject(hdc
, hFont
);
2533 ExtSelectClipRgn(hdc
, hRgn
, RGN_COPY
);
2536 SetWorldTransform(hdc
, &savedXform
);
2538 SetGraphicsMode(hdc
, savedMode
);
2539 SetMapMode(hdc
, mapMode
);
2540 SetWindowOrgEx(hdc
, win_org
.x
, win_org
.y
, NULL
);
2541 SetWindowExtEx(hdc
, win_size
.cx
, win_size
.cy
, NULL
);
2542 SetViewportOrgEx(hdc
, vp_org
.x
, vp_org
.y
, NULL
);
2543 SetViewportExtEx(hdc
, vp_size
.cx
, vp_size
.cy
, NULL
);
2546 for(i
= 1; i
< emh
->nHandles
; i
++) /* Don't delete element 0 (hmf) */
2547 if( (ht
->objectHandle
)[i
] )
2548 DeleteObject( (ht
->objectHandle
)[i
] );
2550 while (info
->saved_state
)
2552 EMF_dc_state
*state
= info
->saved_state
;
2553 info
->saved_state
= info
->saved_state
->next
;
2554 HeapFree( GetProcessHeap(), 0, state
);
2556 HeapFree( GetProcessHeap(), 0, info
);
2560 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
2561 const ENHMETARECORD
*emr
,
2562 INT handles
, LPARAM data
)
2564 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
2567 /**************************************************************************
2568 * PlayEnhMetaFile (GDI32.@)
2570 * Renders an enhanced metafile into a specified rectangle *lpRect
2571 * in device context hdc.
2577 BOOL WINAPI
PlayEnhMetaFile(
2578 HDC hdc
, /* [in] DC to render into */
2579 HENHMETAFILE hmf
, /* [in] metafile to render */
2580 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
2583 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
2587 /*****************************************************************************
2588 * DeleteEnhMetaFile (GDI32.@)
2590 * Deletes an enhanced metafile and frees the associated storage.
2592 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
2594 return EMF_Delete_HENHMETAFILE( hmf
);
2597 /*****************************************************************************
2598 * CopyEnhMetaFileA (GDI32.@)
2600 * Duplicate an enhanced metafile.
2604 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
2605 HENHMETAFILE hmfSrc
,
2608 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2609 HENHMETAFILE hmfDst
;
2611 if(!emrSrc
) return FALSE
;
2613 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2614 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2615 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2617 HeapFree( GetProcessHeap(), 0, emrDst
);
2621 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2622 NULL
, CREATE_ALWAYS
, 0, 0);
2623 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2624 CloseHandle( hFile
);
2625 /* Reopen file for reading only, so that apps can share
2626 read access to the file while hmf is still valid */
2627 hFile
= CreateFileA( file
, GENERIC_READ
, FILE_SHARE_READ
,
2628 NULL
, OPEN_EXISTING
, 0, 0);
2629 if(hFile
== INVALID_HANDLE_VALUE
) {
2630 ERR("Can't reopen emf for reading\n");
2633 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2634 CloseHandle( hFile
);
2639 /*****************************************************************************
2640 * CopyEnhMetaFileW (GDI32.@)
2642 * See CopyEnhMetaFileA.
2646 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2647 HENHMETAFILE hmfSrc
,
2650 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2651 HENHMETAFILE hmfDst
;
2653 if(!emrSrc
) return FALSE
;
2655 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2656 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2657 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2659 HeapFree( GetProcessHeap(), 0, emrDst
);
2663 hFile
= CreateFileW( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2664 NULL
, CREATE_ALWAYS
, 0, 0);
2665 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2666 CloseHandle( hFile
);
2667 /* Reopen file for reading only, so that apps can share
2668 read access to the file while hmf is still valid */
2669 hFile
= CreateFileW( file
, GENERIC_READ
, FILE_SHARE_READ
,
2670 NULL
, OPEN_EXISTING
, 0, 0);
2671 if(hFile
== INVALID_HANDLE_VALUE
) {
2672 ERR("Can't reopen emf for reading\n");
2675 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2676 CloseHandle( hFile
);
2682 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2683 typedef struct tagEMF_PaletteCopy
2686 LPPALETTEENTRY lpPe
;
2689 /***************************************************************
2690 * Find the EMR_EOF record and then use it to find the
2691 * palette entries for this enhanced metafile.
2692 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2693 * which contains the max number of elements to copy and where
2696 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2698 static INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2700 const ENHMETARECORD
*lpEMR
,
2705 if ( lpEMR
->iType
== EMR_EOF
)
2707 const EMREOF
*lpEof
= (const EMREOF
*)lpEMR
;
2708 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
2709 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
2711 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy
);
2713 memcpy( info
->lpPe
, (LPCSTR
)lpEof
+ lpEof
->offPalEntries
,
2714 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
2716 /* Update the passed data as a return code */
2717 info
->lpPe
= NULL
; /* Palettes were copied! */
2718 info
->cEntries
= dwNumPalToCopy
;
2720 return FALSE
; /* That's all we need */
2726 /*****************************************************************************
2727 * GetEnhMetaFilePaletteEntries (GDI32.@)
2729 * Copy the palette and report size
2731 * BUGS: Error codes (SetLastError) are not set on failures
2733 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
2735 LPPALETTEENTRY lpPe
)
2737 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
2738 EMF_PaletteCopy infoForCallBack
;
2740 TRACE( "(%p,%d,%p)\n", hEmf
, cEntries
, lpPe
);
2742 if (!enhHeader
) return 0;
2744 /* First check if there are any palettes associated with
2746 if ( enhHeader
->nPalEntries
== 0 ) return 0;
2748 /* Is the user requesting the number of palettes? */
2749 if ( lpPe
== NULL
) return enhHeader
->nPalEntries
;
2751 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2752 infoForCallBack
.cEntries
= cEntries
;
2753 infoForCallBack
.lpPe
= lpPe
;
2755 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
2756 &infoForCallBack
, 0 ) )
2759 /* Verify that the callback executed correctly */
2760 if ( infoForCallBack
.lpPe
!= NULL
)
2762 /* Callback proc had error! */
2763 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2767 return infoForCallBack
.cEntries
;
2770 /******************************************************************
2771 * extract_emf_from_comment
2773 * If the WMF was created by GetWinMetaFileBits, then extract the
2774 * original EMF that is stored in MFCOMMENT chunks.
2776 static HENHMETAFILE
extract_emf_from_comment( const BYTE
*buf
, UINT mf_size
)
2778 METAHEADER
*mh
= (METAHEADER
*)buf
;
2780 emf_in_wmf_comment
*chunk
;
2782 DWORD size
= 0, remaining
, chunks
;
2783 BYTE
*emf_bits
= NULL
, *ptr
;
2785 HENHMETAFILE emf
= NULL
;
2787 if (mf_size
< sizeof(*mh
)) return NULL
;
2789 for (offset
= mh
->mtHeaderSize
* 2; offset
< mf_size
; offset
+= (mr
->rdSize
* 2))
2791 mr
= (METARECORD
*)((char *)mh
+ offset
);
2792 chunk
= (emf_in_wmf_comment
*)(mr
->rdParm
+ 2);
2794 if (mr
->rdFunction
!= META_ESCAPE
|| mr
->rdParm
[0] != MFCOMMENT
) goto done
;
2795 if (chunk
->magic
!= WMFC_MAGIC
) goto done
;
2799 size
= remaining
= chunk
->emf_size
;
2800 chunks
= chunk
->num_chunks
;
2801 emf_bits
= ptr
= HeapAlloc( GetProcessHeap(), 0, size
);
2802 if (!emf_bits
) goto done
;
2804 if (chunk
->chunk_size
> remaining
) goto done
;
2805 remaining
-= chunk
->chunk_size
;
2806 if (chunk
->remaining_size
!= remaining
) goto done
;
2807 memcpy( ptr
, chunk
->emf_data
, chunk
->chunk_size
);
2808 ptr
+= chunk
->chunk_size
;
2809 if (--chunks
== 0) break;
2812 for (offset
= 0; offset
< mf_size
/ 2; offset
++)
2813 checksum
+= *((WORD
*)buf
+ offset
);
2814 if (checksum
) goto done
;
2816 emf
= SetEnhMetaFileBits( size
, emf_bits
);
2819 HeapFree( GetProcessHeap(), 0, emf_bits
);
2823 typedef struct wmf_in_emf_comment
2830 DWORD cbWinMetaFile
;
2831 } wmf_in_emf_comment
;
2833 /******************************************************************
2834 * SetWinMetaFileBits (GDI32.@)
2836 * Translate from old style to new style.
2839 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
, const BYTE
*lpbBuffer
, HDC hdcRef
,
2840 const METAFILEPICT
*lpmfp
)
2842 static const WCHAR szDisplayW
[] = { 'D','I','S','P','L','A','Y','\0' };
2843 HMETAFILE hmf
= NULL
;
2844 HENHMETAFILE ret
= NULL
;
2845 HDC hdc
= NULL
, hdcdisp
= NULL
;
2846 RECT rc
, *prcFrame
= NULL
;
2847 LONG mm
, xExt
, yExt
;
2848 INT horzsize
, vertsize
, horzres
, vertres
;
2850 TRACE("(%d, %p, %p, %p)\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
2852 hmf
= SetMetaFileBitsEx(cbBuffer
, lpbBuffer
);
2855 WARN("SetMetaFileBitsEx failed\n");
2859 ret
= extract_emf_from_comment( lpbBuffer
, cbBuffer
);
2860 if (ret
) return ret
;
2863 hdcRef
= hdcdisp
= CreateDCW(szDisplayW
, NULL
, NULL
, NULL
);
2867 TRACE("mm = %d %dx%d\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2875 TRACE("lpmfp == NULL\n");
2877 /* Use the whole device surface */
2878 mm
= MM_ANISOTROPIC
;
2883 if (mm
== MM_ISOTROPIC
|| mm
== MM_ANISOTROPIC
)
2885 if (xExt
< 0 || yExt
< 0)
2887 /* Use the whole device surface */
2892 /* Use the x and y extents as the frame box */
2895 rc
.left
= rc
.top
= 0;
2902 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
)))
2904 ERR("CreateEnhMetaFile failed\n");
2909 * Write the original METAFILE into the enhanced metafile.
2910 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2914 wmf_in_emf_comment
*mfcomment
;
2915 UINT mfcomment_size
;
2917 mfcomment_size
= sizeof (*mfcomment
) + cbBuffer
;
2918 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
2921 mfcomment
->ident
= GDICOMMENT_IDENTIFIER
;
2922 mfcomment
->iComment
= GDICOMMENT_WINDOWS_METAFILE
;
2923 mfcomment
->nVersion
= 0x00000300;
2924 mfcomment
->nChecksum
= 0; /* FIXME */
2925 mfcomment
->fFlags
= 0;
2926 mfcomment
->cbWinMetaFile
= cbBuffer
;
2927 memcpy(&mfcomment
[1], lpbBuffer
, cbBuffer
);
2928 GdiComment(hdc
, mfcomment_size
, (BYTE
*) mfcomment
);
2929 HeapFree(GetProcessHeap(), 0, mfcomment
);
2931 SetMapMode(hdc
, mm
);
2935 horzsize
= GetDeviceCaps(hdcRef
, HORZSIZE
);
2936 vertsize
= GetDeviceCaps(hdcRef
, VERTSIZE
);
2937 horzres
= GetDeviceCaps(hdcRef
, HORZRES
);
2938 vertres
= GetDeviceCaps(hdcRef
, VERTRES
);
2942 /* Use the whole device surface */
2948 xExt
= MulDiv(xExt
, horzres
, 100 * horzsize
);
2949 yExt
= MulDiv(yExt
, vertres
, 100 * vertsize
);
2952 /* set the initial viewport:window ratio as 1:1 */
2953 SetViewportExtEx(hdc
, xExt
, yExt
, NULL
);
2954 SetWindowExtEx(hdc
, xExt
, yExt
, NULL
);
2956 PlayMetaFile(hdc
, hmf
);
2958 ret
= CloseEnhMetaFile(hdc
);
2960 if (hdcdisp
) DeleteDC(hdcdisp
);
2961 DeleteMetaFile(hmf
);