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
< sizeof(emr_names
) / sizeof(emr_names
[0]); 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
, BOOL on_disk
)
252 ENHMETAFILEOBJ
*metaObj
;
254 if (emh
->iType
!= EMR_HEADER
)
256 SetLastError(ERROR_INVALID_DATA
);
259 if (emh
->dSignature
!= ENHMETA_SIGNATURE
||
260 (emh
->nBytes
& 3)) /* refuse to load unaligned EMF as Windows does */
262 WARN("Invalid emf header type 0x%08x sig 0x%08x.\n",
263 emh
->iType
, emh
->dSignature
);
267 if (!(metaObj
= HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj
) ))) return 0;
270 metaObj
->on_disk
= on_disk
;
272 if (!(hmf
= alloc_gdi_handle( metaObj
, OBJ_ENHMETAFILE
, NULL
)))
273 HeapFree( GetProcessHeap(), 0, metaObj
);
277 /****************************************************************************
278 * EMF_Delete_HENHMETAFILE
280 static BOOL
EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf
)
282 ENHMETAFILEOBJ
*metaObj
= free_gdi_handle( hmf
);
284 if(!metaObj
) return FALSE
;
287 UnmapViewOfFile( metaObj
->emh
);
289 HeapFree( GetProcessHeap(), 0, metaObj
->emh
);
290 return HeapFree( GetProcessHeap(), 0, metaObj
);
293 /******************************************************************
294 * EMF_GetEnhMetaHeader
296 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
298 static ENHMETAHEADER
*EMF_GetEnhMetaHeader( HENHMETAFILE hmf
)
300 ENHMETAHEADER
*ret
= NULL
;
301 ENHMETAFILEOBJ
*metaObj
= GDI_GetObjPtr( hmf
, OBJ_ENHMETAFILE
);
302 TRACE("hmf %p -> enhmetaObj %p\n", hmf
, metaObj
);
306 GDI_ReleaseObj( hmf
);
311 /*****************************************************************************
315 static HENHMETAFILE
EMF_GetEnhMetaFile( HANDLE hFile
)
321 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
322 emh
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, 0 );
323 CloseHandle( hMapping
);
327 hemf
= EMF_Create_HENHMETAFILE( emh
, TRUE
);
329 UnmapViewOfFile( emh
);
334 /*****************************************************************************
335 * GetEnhMetaFileA (GDI32.@)
339 HENHMETAFILE WINAPI
GetEnhMetaFileA(
340 LPCSTR lpszMetaFile
/* [in] filename of enhanced metafile */
346 hFile
= CreateFileA(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
347 OPEN_EXISTING
, 0, 0);
348 if (hFile
== INVALID_HANDLE_VALUE
) {
349 WARN("could not open %s\n", lpszMetaFile
);
352 hmf
= EMF_GetEnhMetaFile( hFile
);
353 CloseHandle( hFile
);
357 /*****************************************************************************
358 * GetEnhMetaFileW (GDI32.@)
360 HENHMETAFILE WINAPI
GetEnhMetaFileW(
361 LPCWSTR lpszMetaFile
) /* [in] filename of enhanced metafile */
366 hFile
= CreateFileW(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
367 OPEN_EXISTING
, 0, 0);
368 if (hFile
== INVALID_HANDLE_VALUE
) {
369 WARN("could not open %s\n", debugstr_w(lpszMetaFile
));
372 hmf
= EMF_GetEnhMetaFile( hFile
);
373 CloseHandle( hFile
);
377 /*****************************************************************************
378 * GetEnhMetaFileHeader (GDI32.@)
380 * Retrieves the record containing the header for the specified
381 * enhanced-format metafile.
384 * If buf is NULL, returns the size of buffer required.
385 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
388 UINT WINAPI
GetEnhMetaFileHeader(
389 HENHMETAFILE hmf
, /* [in] enhanced metafile */
390 UINT bufsize
, /* [in] size of buffer */
391 LPENHMETAHEADER buf
/* [out] buffer */
397 emh
= EMF_GetEnhMetaHeader(hmf
);
398 if(!emh
) return FALSE
;
400 if (!buf
) return size
;
401 size
= min(size
, bufsize
);
402 memmove(buf
, emh
, size
);
407 /*****************************************************************************
408 * GetEnhMetaFileDescriptionA (GDI32.@)
410 * See GetEnhMetaFileDescriptionW.
412 UINT WINAPI
GetEnhMetaFileDescriptionA(
413 HENHMETAFILE hmf
, /* [in] enhanced metafile */
414 UINT size
, /* [in] size of buf */
415 LPSTR buf
/* [out] buffer to receive description */
418 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
422 if(!emh
) return FALSE
;
423 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
424 descrW
= (WCHAR
*) ((char *) emh
+ emh
->offDescription
);
425 len
= WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, NULL
, 0, NULL
, NULL
);
427 if (!buf
|| !size
) return len
;
429 len
= min( size
, len
);
430 WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, buf
, len
, NULL
, NULL
);
434 /*****************************************************************************
435 * GetEnhMetaFileDescriptionW (GDI32.@)
437 * Copies the description string of an enhanced metafile into a buffer
441 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
442 * number of characters copied.
444 UINT WINAPI
GetEnhMetaFileDescriptionW(
445 HENHMETAFILE hmf
, /* [in] enhanced metafile */
446 UINT size
, /* [in] size of buf */
447 LPWSTR buf
/* [out] buffer to receive description */
450 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
452 if(!emh
) return FALSE
;
453 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
454 if (!buf
|| !size
) return emh
->nDescription
;
456 memmove(buf
, (char *) emh
+ emh
->offDescription
, min(size
,emh
->nDescription
)*sizeof(WCHAR
));
457 return min(size
, emh
->nDescription
);
460 /****************************************************************************
461 * SetEnhMetaFileBits (GDI32.@)
463 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
465 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
467 ENHMETAHEADER
*emh
= HeapAlloc( GetProcessHeap(), 0, bufsize
);
469 memmove(emh
, buf
, bufsize
);
470 hmf
= EMF_Create_HENHMETAFILE( emh
, FALSE
);
472 HeapFree( GetProcessHeap(), 0, emh
);
476 /*****************************************************************************
477 * GetEnhMetaFileBits (GDI32.@)
480 UINT WINAPI
GetEnhMetaFileBits(
486 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
492 if( buf
== NULL
) return size
;
494 size
= min( size
, bufsize
);
495 memmove(buf
, emh
, size
);
499 typedef struct EMF_dc_state
502 XFORM world_transform
;
511 struct EMF_dc_state
*next
;
514 typedef struct enum_emh_data
516 XFORM init_transform
;
519 EMF_dc_state
*saved_state
;
522 #define ENUM_GET_PRIVATE_DATA(ht) \
523 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
525 #define WIDTH(rect) ( (rect).right - (rect).left )
526 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
528 #define IS_WIN9X() (GetVersion()&0x80000000)
530 static void EMF_Update_MF_Xform(HDC hdc
, const enum_emh_data
*info
)
532 XFORM mapping_mode_trans
, final_trans
;
533 double scaleX
, scaleY
;
535 scaleX
= (double)info
->state
.vportExtX
/ (double)info
->state
.wndExtX
;
536 scaleY
= (double)info
->state
.vportExtY
/ (double)info
->state
.wndExtY
;
537 mapping_mode_trans
.eM11
= scaleX
;
538 mapping_mode_trans
.eM12
= 0.0;
539 mapping_mode_trans
.eM21
= 0.0;
540 mapping_mode_trans
.eM22
= scaleY
;
541 mapping_mode_trans
.eDx
= (double)info
->state
.vportOrgX
- scaleX
* (double)info
->state
.wndOrgX
;
542 mapping_mode_trans
.eDy
= (double)info
->state
.vportOrgY
- scaleY
* (double)info
->state
.wndOrgY
;
544 CombineTransform(&final_trans
, &info
->state
.world_transform
, &mapping_mode_trans
);
545 CombineTransform(&final_trans
, &final_trans
, &info
->init_transform
);
547 if (!SetWorldTransform(hdc
, &final_trans
))
549 ERR("World transform failed!\n");
553 static void EMF_RestoreDC( enum_emh_data
*info
, INT level
)
555 if (abs(level
) > info
->save_level
|| level
== 0) return;
557 if (level
< 0) level
= info
->save_level
+ level
+ 1;
559 while (info
->save_level
>= level
)
561 EMF_dc_state
*state
= info
->saved_state
;
562 info
->saved_state
= state
->next
;
564 if (--info
->save_level
< level
)
565 info
->state
= *state
;
566 HeapFree( GetProcessHeap(), 0, state
);
570 static void EMF_SaveDC( enum_emh_data
*info
)
572 EMF_dc_state
*state
= HeapAlloc( GetProcessHeap(), 0, sizeof(*state
));
575 *state
= info
->state
;
576 state
->next
= info
->saved_state
;
577 info
->saved_state
= state
;
579 TRACE("save_level %d\n", info
->save_level
);
583 static void EMF_SetMapMode(HDC hdc
, enum_emh_data
*info
)
585 INT horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
586 INT vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
587 INT horzRes
= GetDeviceCaps( hdc
, HORZRES
);
588 INT vertRes
= GetDeviceCaps( hdc
, VERTRES
);
590 TRACE("%d\n", info
->state
.mode
);
592 switch(info
->state
.mode
)
595 info
->state
.wndExtX
= 1;
596 info
->state
.wndExtY
= 1;
597 info
->state
.vportExtX
= 1;
598 info
->state
.vportExtY
= 1;
602 info
->state
.wndExtX
= horzSize
* 10;
603 info
->state
.wndExtY
= vertSize
* 10;
604 info
->state
.vportExtX
= horzRes
;
605 info
->state
.vportExtY
= -vertRes
;
608 info
->state
.wndExtX
= horzSize
* 100;
609 info
->state
.wndExtY
= vertSize
* 100;
610 info
->state
.vportExtX
= horzRes
;
611 info
->state
.vportExtY
= -vertRes
;
614 info
->state
.wndExtX
= MulDiv(1000, horzSize
, 254);
615 info
->state
.wndExtY
= MulDiv(1000, vertSize
, 254);
616 info
->state
.vportExtX
= horzRes
;
617 info
->state
.vportExtY
= -vertRes
;
620 info
->state
.wndExtX
= MulDiv(10000, horzSize
, 254);
621 info
->state
.wndExtY
= MulDiv(10000, vertSize
, 254);
622 info
->state
.vportExtX
= horzRes
;
623 info
->state
.vportExtY
= -vertRes
;
626 info
->state
.wndExtX
= MulDiv(14400, horzSize
, 254);
627 info
->state
.wndExtY
= MulDiv(14400, vertSize
, 254);
628 info
->state
.vportExtX
= horzRes
;
629 info
->state
.vportExtY
= -vertRes
;
638 /***********************************************************************
641 * Fix viewport extensions for isotropic mode.
644 static void EMF_FixIsotropic(HDC hdc
, enum_emh_data
*info
)
646 double xdim
= fabs((double)info
->state
.vportExtX
* GetDeviceCaps( hdc
, HORZSIZE
) /
647 (GetDeviceCaps( hdc
, HORZRES
) * info
->state
.wndExtX
));
648 double ydim
= fabs((double)info
->state
.vportExtY
* GetDeviceCaps( hdc
, VERTSIZE
) /
649 (GetDeviceCaps( hdc
, VERTRES
) * info
->state
.wndExtY
));
653 INT mincx
= (info
->state
.vportExtX
>= 0) ? 1 : -1;
654 info
->state
.vportExtX
= floor(info
->state
.vportExtX
* ydim
/ xdim
+ 0.5);
655 if (!info
->state
.vportExtX
) info
->state
.vportExtX
= mincx
;
659 INT mincy
= (info
->state
.vportExtY
>= 0) ? 1 : -1;
660 info
->state
.vportExtY
= floor(info
->state
.vportExtY
* xdim
/ ydim
+ 0.5);
661 if (!info
->state
.vportExtY
) info
->state
.vportExtY
= mincy
;
665 /*****************************************************************************
666 * emr_produces_output
668 * Returns TRUE if the record type writes something to the dc. Used by
669 * PlayEnhMetaFileRecord to determine whether it needs to update the
670 * dc's xform when in win9x mode.
672 * FIXME: need to test which records should be here.
674 static BOOL
emr_produces_output(int type
)
680 case EMR_POLYBEZIERTO
:
682 case EMR_POLYPOLYLINE
:
683 case EMR_POLYPOLYGON
:
686 case EMR_EXCLUDECLIPRECT
:
687 case EMR_INTERSECTCLIPRECT
:
688 case EMR_SELECTOBJECT
:
696 case EMR_EXTFLOODFILL
:
709 case EMR_SETDIBITSTODEVICE
:
710 case EMR_STRETCHDIBITS
:
711 case EMR_EXTTEXTOUTA
:
712 case EMR_EXTTEXTOUTW
:
713 case EMR_POLYBEZIER16
:
716 case EMR_POLYBEZIERTO16
:
717 case EMR_POLYLINETO16
:
718 case EMR_POLYPOLYLINE16
:
719 case EMR_POLYPOLYGON16
:
721 case EMR_POLYTEXTOUTA
:
722 case EMR_POLYTEXTOUTW
:
723 case EMR_SMALLTEXTOUT
:
725 case EMR_TRANSPARENTBLT
:
733 /*****************************************************************************
734 * PlayEnhMetaFileRecord (GDI32.@)
736 * Render a single enhanced metafile record in the device context hdc.
739 * TRUE (non zero) on success, FALSE on error.
741 * Many unimplemented records.
742 * No error handling on record play failures (ie checking return codes)
745 * WinNT actually updates the current world transform in this function
746 * whereas Win9x does not.
748 BOOL WINAPI
PlayEnhMetaFileRecord(
749 HDC hdc
, /* [in] device context in which to render EMF record */
750 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
751 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
752 UINT handles
/* [in] size of handle array */
757 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
759 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
760 hdc
, handletable
, mr
, handles
);
761 if (!mr
) return FALSE
;
765 TRACE("record %s\n", get_emr_name(type
));
774 const EMRGDICOMMENT
*lpGdiComment
= (const EMRGDICOMMENT
*)mr
;
775 /* In an enhanced metafile, there can be both public and private GDI comments */
776 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
781 const EMRSETMAPMODE
*pSetMapMode
= (const EMRSETMAPMODE
*)mr
;
783 if (info
->state
.mode
== pSetMapMode
->iMode
&&
784 (info
->state
.mode
== MM_ISOTROPIC
|| info
->state
.mode
== MM_ANISOTROPIC
))
786 info
->state
.mode
= pSetMapMode
->iMode
;
787 EMF_SetMapMode(hdc
, info
);
792 const EMRSETBKMODE
*pSetBkMode
= (const EMRSETBKMODE
*)mr
;
793 SetBkMode(hdc
, pSetBkMode
->iMode
);
798 const EMRSETBKCOLOR
*pSetBkColor
= (const EMRSETBKCOLOR
*)mr
;
799 SetBkColor(hdc
, pSetBkColor
->crColor
);
802 case EMR_SETPOLYFILLMODE
:
804 const EMRSETPOLYFILLMODE
*pSetPolyFillMode
= (const EMRSETPOLYFILLMODE
*)mr
;
805 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
810 const EMRSETROP2
*pSetROP2
= (const EMRSETROP2
*)mr
;
811 SetROP2(hdc
, pSetROP2
->iMode
);
814 case EMR_SETSTRETCHBLTMODE
:
816 const EMRSETSTRETCHBLTMODE
*pSetStretchBltMode
= (const EMRSETSTRETCHBLTMODE
*)mr
;
817 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
820 case EMR_SETTEXTALIGN
:
822 const EMRSETTEXTALIGN
*pSetTextAlign
= (const EMRSETTEXTALIGN
*)mr
;
823 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
826 case EMR_SETTEXTCOLOR
:
828 const EMRSETTEXTCOLOR
*pSetTextColor
= (const EMRSETTEXTCOLOR
*)mr
;
829 SetTextColor(hdc
, pSetTextColor
->crColor
);
840 const EMRRESTOREDC
*pRestoreDC
= (const EMRRESTOREDC
*)mr
;
841 TRACE("EMR_RESTORE: %d\n", pRestoreDC
->iRelative
);
842 if (RestoreDC( hdc
, pRestoreDC
->iRelative
))
843 EMF_RestoreDC( info
, pRestoreDC
->iRelative
);
846 case EMR_INTERSECTCLIPRECT
:
848 const EMRINTERSECTCLIPRECT
*pClipRect
= (const EMRINTERSECTCLIPRECT
*)mr
;
849 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
850 pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
851 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
852 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
853 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
856 case EMR_SELECTOBJECT
:
858 const EMRSELECTOBJECT
*pSelectObject
= (const EMRSELECTOBJECT
*)mr
;
859 if( pSelectObject
->ihObject
& 0x80000000 ) {
860 /* High order bit is set - it's a stock object
861 * Strip the high bit to get the index.
862 * See MSDN article Q142319
864 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
867 /* High order bit wasn't set - not a stock object
870 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
874 case EMR_DELETEOBJECT
:
876 const EMRDELETEOBJECT
*pDeleteObject
= (const EMRDELETEOBJECT
*)mr
;
877 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
878 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
881 case EMR_SETWINDOWORGEX
:
883 const EMRSETWINDOWORGEX
*pSetWindowOrgEx
= (const EMRSETWINDOWORGEX
*)mr
;
885 info
->state
.wndOrgX
= pSetWindowOrgEx
->ptlOrigin
.x
;
886 info
->state
.wndOrgY
= pSetWindowOrgEx
->ptlOrigin
.y
;
888 TRACE("SetWindowOrgEx: %d,%d\n", info
->state
.wndOrgX
, info
->state
.wndOrgY
);
891 case EMR_SETWINDOWEXTEX
:
893 const EMRSETWINDOWEXTEX
*pSetWindowExtEx
= (const EMRSETWINDOWEXTEX
*)mr
;
895 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
897 info
->state
.wndExtX
= pSetWindowExtEx
->szlExtent
.cx
;
898 info
->state
.wndExtY
= pSetWindowExtEx
->szlExtent
.cy
;
899 if (info
->state
.mode
== MM_ISOTROPIC
)
900 EMF_FixIsotropic(hdc
, info
);
902 TRACE("SetWindowExtEx: %d,%d\n",info
->state
.wndExtX
, info
->state
.wndExtY
);
905 case EMR_SETVIEWPORTORGEX
:
907 const EMRSETVIEWPORTORGEX
*pSetViewportOrgEx
= (const EMRSETVIEWPORTORGEX
*)mr
;
909 info
->state
.vportOrgX
= pSetViewportOrgEx
->ptlOrigin
.x
;
910 info
->state
.vportOrgY
= pSetViewportOrgEx
->ptlOrigin
.y
;
911 TRACE("SetViewportOrgEx: %d,%d\n", info
->state
.vportOrgX
, info
->state
.vportOrgY
);
914 case EMR_SETVIEWPORTEXTEX
:
916 const EMRSETVIEWPORTEXTEX
*pSetViewportExtEx
= (const EMRSETVIEWPORTEXTEX
*)mr
;
918 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
920 info
->state
.vportExtX
= pSetViewportExtEx
->szlExtent
.cx
;
921 info
->state
.vportExtY
= pSetViewportExtEx
->szlExtent
.cy
;
922 if (info
->state
.mode
== MM_ISOTROPIC
)
923 EMF_FixIsotropic(hdc
, info
);
924 TRACE("SetViewportExtEx: %d,%d\n", info
->state
.vportExtX
, info
->state
.vportExtY
);
929 const EMRCREATEPEN
*pCreatePen
= (const EMRCREATEPEN
*)mr
;
930 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
931 CreatePenIndirect(&pCreatePen
->lopn
);
934 case EMR_EXTCREATEPEN
:
936 const EMREXTCREATEPEN
*pPen
= (const EMREXTCREATEPEN
*)mr
;
938 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
939 lb
.lbColor
= pPen
->elp
.elpColor
;
940 lb
.lbHatch
= pPen
->elp
.elpHatch
;
942 if(pPen
->offBmi
|| pPen
->offBits
)
943 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
945 (handletable
->objectHandle
)[pPen
->ihPen
] =
946 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
947 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpNumEntries
? pPen
->elp
.elpStyleEntry
: NULL
);
950 case EMR_CREATEBRUSHINDIRECT
:
952 const EMRCREATEBRUSHINDIRECT
*pBrush
= (const EMRCREATEBRUSHINDIRECT
*)mr
;
954 brush
.lbStyle
= pBrush
->lb
.lbStyle
;
955 brush
.lbColor
= pBrush
->lb
.lbColor
;
956 brush
.lbHatch
= pBrush
->lb
.lbHatch
;
957 (handletable
->objectHandle
)[pBrush
->ihBrush
] = CreateBrushIndirect(&brush
);
960 case EMR_EXTCREATEFONTINDIRECTW
:
962 const EMREXTCREATEFONTINDIRECTW
*pFont
= (const EMREXTCREATEFONTINDIRECTW
*)mr
;
963 (handletable
->objectHandle
)[pFont
->ihFont
] =
964 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
969 const EMRMOVETOEX
*pMoveToEx
= (const EMRMOVETOEX
*)mr
;
970 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
975 const EMRLINETO
*pLineTo
= (const EMRLINETO
*)mr
;
976 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
981 const EMRRECTANGLE
*pRect
= (const EMRRECTANGLE
*)mr
;
982 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
983 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
988 const EMRELLIPSE
*pEllipse
= (const EMRELLIPSE
*)mr
;
989 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
990 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
995 const EMRPOLYGON16
*pPoly
= (const EMRPOLYGON16
*)mr
;
996 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
997 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
998 pPoly
->cpts
* sizeof(POINT
) );
1000 for(i
= 0; i
< pPoly
->cpts
; i
++)
1002 pts
[i
].x
= pPoly
->apts
[i
].x
;
1003 pts
[i
].y
= pPoly
->apts
[i
].y
;
1005 Polygon(hdc
, pts
, pPoly
->cpts
);
1006 HeapFree( GetProcessHeap(), 0, pts
);
1009 case EMR_POLYLINE16
:
1011 const EMRPOLYLINE16
*pPoly
= (const EMRPOLYLINE16
*)mr
;
1012 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1013 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1014 pPoly
->cpts
* sizeof(POINT
) );
1016 for(i
= 0; i
< pPoly
->cpts
; i
++)
1018 pts
[i
].x
= pPoly
->apts
[i
].x
;
1019 pts
[i
].y
= pPoly
->apts
[i
].y
;
1021 Polyline(hdc
, pts
, pPoly
->cpts
);
1022 HeapFree( GetProcessHeap(), 0, pts
);
1025 case EMR_POLYLINETO16
:
1027 const EMRPOLYLINETO16
*pPoly
= (const EMRPOLYLINETO16
*)mr
;
1028 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1029 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1030 pPoly
->cpts
* sizeof(POINT
) );
1032 for(i
= 0; i
< pPoly
->cpts
; i
++)
1034 pts
[i
].x
= pPoly
->apts
[i
].x
;
1035 pts
[i
].y
= pPoly
->apts
[i
].y
;
1037 PolylineTo(hdc
, pts
, pPoly
->cpts
);
1038 HeapFree( GetProcessHeap(), 0, pts
);
1041 case EMR_POLYBEZIER16
:
1043 const EMRPOLYBEZIER16
*pPoly
= (const EMRPOLYBEZIER16
*)mr
;
1044 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1045 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1046 pPoly
->cpts
* sizeof(POINT
) );
1048 for(i
= 0; i
< pPoly
->cpts
; i
++)
1050 pts
[i
].x
= pPoly
->apts
[i
].x
;
1051 pts
[i
].y
= pPoly
->apts
[i
].y
;
1053 PolyBezier(hdc
, pts
, pPoly
->cpts
);
1054 HeapFree( GetProcessHeap(), 0, pts
);
1057 case EMR_POLYBEZIERTO16
:
1059 const EMRPOLYBEZIERTO16
*pPoly
= (const EMRPOLYBEZIERTO16
*)mr
;
1060 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1061 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1062 pPoly
->cpts
* sizeof(POINT
) );
1064 for(i
= 0; i
< pPoly
->cpts
; i
++)
1066 pts
[i
].x
= pPoly
->apts
[i
].x
;
1067 pts
[i
].y
= pPoly
->apts
[i
].y
;
1069 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
1070 HeapFree( GetProcessHeap(), 0, pts
);
1073 case EMR_POLYPOLYGON16
:
1075 const EMRPOLYPOLYGON16
*pPolyPoly
= (const EMRPOLYPOLYGON16
*)mr
;
1076 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1077 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1079 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1080 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1082 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1087 PolyPolygon(hdc
, pt
, (const INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1088 HeapFree( GetProcessHeap(), 0, pt
);
1091 case EMR_POLYPOLYLINE16
:
1093 const EMRPOLYPOLYLINE16
*pPolyPoly
= (const EMRPOLYPOLYLINE16
*)mr
;
1094 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1095 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1097 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1098 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1100 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1105 PolyPolyline(hdc
, pt
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1106 HeapFree( GetProcessHeap(), 0, pt
);
1110 case EMR_STRETCHDIBITS
:
1112 const EMRSTRETCHDIBITS
*pStretchDIBits
= (const EMRSTRETCHDIBITS
*)mr
;
1115 pStretchDIBits
->xDest
,
1116 pStretchDIBits
->yDest
,
1117 pStretchDIBits
->cxDest
,
1118 pStretchDIBits
->cyDest
,
1119 pStretchDIBits
->xSrc
,
1120 pStretchDIBits
->ySrc
,
1121 pStretchDIBits
->cxSrc
,
1122 pStretchDIBits
->cySrc
,
1123 (const BYTE
*)mr
+ pStretchDIBits
->offBitsSrc
,
1124 (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchDIBits
->offBmiSrc
),
1125 pStretchDIBits
->iUsageSrc
,
1126 pStretchDIBits
->dwRop
);
1130 case EMR_EXTTEXTOUTA
:
1132 const EMREXTTEXTOUTA
*pExtTextOutA
= (const EMREXTTEXTOUTA
*)mr
;
1134 const INT
*dx
= NULL
;
1137 rc
.left
= pExtTextOutA
->emrtext
.rcl
.left
;
1138 rc
.top
= pExtTextOutA
->emrtext
.rcl
.top
;
1139 rc
.right
= pExtTextOutA
->emrtext
.rcl
.right
;
1140 rc
.bottom
= pExtTextOutA
->emrtext
.rcl
.bottom
;
1141 TRACE("EMR_EXTTEXTOUTA: x,y = %d, %d. rect = %s. flags %08x\n",
1142 pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1143 wine_dbgstr_rect(&rc
), pExtTextOutA
->emrtext
.fOptions
);
1145 old_mode
= SetGraphicsMode(hdc
, pExtTextOutA
->iGraphicsMode
);
1146 /* Reselect the font back into the dc so that the transformation
1148 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1150 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1151 * These files can be enumerated and played under Win98 just
1152 * fine, but at least Win2k chokes on them.
1154 if (pExtTextOutA
->emrtext
.offDx
)
1155 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offDx
);
1157 ExtTextOutA(hdc
, pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1158 pExtTextOutA
->emrtext
.fOptions
, &rc
,
1159 (LPCSTR
)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offString
), pExtTextOutA
->emrtext
.nChars
,
1162 SetGraphicsMode(hdc
, old_mode
);
1166 case EMR_EXTTEXTOUTW
:
1168 const EMREXTTEXTOUTW
*pExtTextOutW
= (const EMREXTTEXTOUTW
*)mr
;
1170 const INT
*dx
= NULL
;
1173 rc
.left
= pExtTextOutW
->emrtext
.rcl
.left
;
1174 rc
.top
= pExtTextOutW
->emrtext
.rcl
.top
;
1175 rc
.right
= pExtTextOutW
->emrtext
.rcl
.right
;
1176 rc
.bottom
= pExtTextOutW
->emrtext
.rcl
.bottom
;
1177 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %s. flags %08x\n",
1178 pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1179 wine_dbgstr_rect(&rc
), pExtTextOutW
->emrtext
.fOptions
);
1181 old_mode
= SetGraphicsMode(hdc
, pExtTextOutW
->iGraphicsMode
);
1182 /* Reselect the font back into the dc so that the transformation
1184 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1186 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1187 * These files can be enumerated and played under Win98 just
1188 * fine, but at least Win2k chokes on them.
1190 if (pExtTextOutW
->emrtext
.offDx
)
1191 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offDx
);
1193 ExtTextOutW(hdc
, pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1194 pExtTextOutW
->emrtext
.fOptions
, &rc
,
1195 (LPCWSTR
)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offString
), pExtTextOutW
->emrtext
.nChars
,
1198 SetGraphicsMode(hdc
, old_mode
);
1202 case EMR_CREATEPALETTE
:
1204 const EMRCREATEPALETTE
*lpCreatePal
= (const EMRCREATEPALETTE
*)mr
;
1206 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1207 CreatePalette( &lpCreatePal
->lgpl
);
1212 case EMR_SELECTPALETTE
:
1214 const EMRSELECTPALETTE
*lpSelectPal
= (const EMRSELECTPALETTE
*)mr
;
1216 if( lpSelectPal
->ihPal
& 0x80000000 ) {
1217 SelectPalette( hdc
, GetStockObject(lpSelectPal
->ihPal
& 0x7fffffff), TRUE
);
1219 SelectPalette( hdc
, (handletable
->objectHandle
)[lpSelectPal
->ihPal
], TRUE
);
1224 case EMR_REALIZEPALETTE
:
1226 RealizePalette( hdc
);
1230 case EMR_EXTSELECTCLIPRGN
:
1232 const EMREXTSELECTCLIPRGN
*lpRgn
= (const EMREXTSELECTCLIPRGN
*)mr
;
1235 if (mr
->nSize
>= sizeof(*lpRgn
) + sizeof(RGNDATAHEADER
))
1236 hRgn
= ExtCreateRegion( &info
->init_transform
, 0, (const RGNDATA
*)lpRgn
->RgnData
);
1238 ExtSelectClipRgn(hdc
, hRgn
, (INT
)(lpRgn
->iMode
));
1239 /* ExtSelectClipRgn created a copy of the region */
1244 case EMR_SETMETARGN
:
1250 case EMR_SETWORLDTRANSFORM
:
1252 const EMRSETWORLDTRANSFORM
*lpXfrm
= (const EMRSETWORLDTRANSFORM
*)mr
;
1253 info
->state
.world_transform
= lpXfrm
->xform
;
1257 case EMR_POLYBEZIER
:
1259 const EMRPOLYBEZIER
*lpPolyBez
= (const EMRPOLYBEZIER
*)mr
;
1260 PolyBezier(hdc
, (const POINT
*)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1266 const EMRPOLYGON
*lpPoly
= (const EMRPOLYGON
*)mr
;
1267 Polygon( hdc
, (const POINT
*)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1273 const EMRPOLYLINE
*lpPolyLine
= (const EMRPOLYLINE
*)mr
;
1274 Polyline(hdc
, (const POINT
*)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1278 case EMR_POLYBEZIERTO
:
1280 const EMRPOLYBEZIERTO
*lpPolyBezierTo
= (const EMRPOLYBEZIERTO
*)mr
;
1281 PolyBezierTo( hdc
, (const POINT
*)lpPolyBezierTo
->aptl
,
1282 (UINT
)lpPolyBezierTo
->cptl
);
1286 case EMR_POLYLINETO
:
1288 const EMRPOLYLINETO
*lpPolyLineTo
= (const EMRPOLYLINETO
*)mr
;
1289 PolylineTo( hdc
, (const POINT
*)lpPolyLineTo
->aptl
,
1290 (UINT
)lpPolyLineTo
->cptl
);
1294 case EMR_POLYPOLYLINE
:
1296 const EMRPOLYPOLYLINE
*pPolyPolyline
= (const EMRPOLYPOLYLINE
*)mr
;
1297 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1299 PolyPolyline(hdc
, (const POINT
*)(pPolyPolyline
->aPolyCounts
+
1300 pPolyPolyline
->nPolys
),
1301 pPolyPolyline
->aPolyCounts
,
1302 pPolyPolyline
->nPolys
);
1307 case EMR_POLYPOLYGON
:
1309 const EMRPOLYPOLYGON
*pPolyPolygon
= (const EMRPOLYPOLYGON
*)mr
;
1311 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1313 PolyPolygon(hdc
, (const POINT
*)(pPolyPolygon
->aPolyCounts
+
1314 pPolyPolygon
->nPolys
),
1315 (const INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
1319 case EMR_SETBRUSHORGEX
:
1321 const EMRSETBRUSHORGEX
*lpSetBrushOrgEx
= (const EMRSETBRUSHORGEX
*)mr
;
1324 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1325 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1333 const EMRSETPIXELV
*lpSetPixelV
= (const EMRSETPIXELV
*)mr
;
1336 (INT
)lpSetPixelV
->ptlPixel
.x
,
1337 (INT
)lpSetPixelV
->ptlPixel
.y
,
1338 lpSetPixelV
->crColor
);
1343 case EMR_SETMAPPERFLAGS
:
1345 const EMRSETMAPPERFLAGS
*lpSetMapperFlags
= (const EMRSETMAPPERFLAGS
*)mr
;
1347 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1352 case EMR_SETCOLORADJUSTMENT
:
1354 const EMRSETCOLORADJUSTMENT
*lpSetColorAdjust
= (const EMRSETCOLORADJUSTMENT
*)mr
;
1356 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1361 case EMR_OFFSETCLIPRGN
:
1363 const EMROFFSETCLIPRGN
*lpOffsetClipRgn
= (const EMROFFSETCLIPRGN
*)mr
;
1366 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1367 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1368 FIXME("OffsetClipRgn\n");
1373 case EMR_EXCLUDECLIPRECT
:
1375 const EMREXCLUDECLIPRECT
*lpExcludeClipRect
= (const EMREXCLUDECLIPRECT
*)mr
;
1377 ExcludeClipRect( hdc
,
1378 lpExcludeClipRect
->rclClip
.left
,
1379 lpExcludeClipRect
->rclClip
.top
,
1380 lpExcludeClipRect
->rclClip
.right
,
1381 lpExcludeClipRect
->rclClip
.bottom
);
1382 FIXME("ExcludeClipRect\n");
1387 case EMR_SCALEVIEWPORTEXTEX
:
1389 const EMRSCALEVIEWPORTEXTEX
*lpScaleViewportExtEx
= (const EMRSCALEVIEWPORTEXTEX
*)mr
;
1391 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1393 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1394 !lpScaleViewportExtEx
->yNum
|| !lpScaleViewportExtEx
->yDenom
)
1396 info
->state
.vportExtX
= MulDiv(info
->state
.vportExtX
, lpScaleViewportExtEx
->xNum
,
1397 lpScaleViewportExtEx
->xDenom
);
1398 info
->state
.vportExtY
= MulDiv(info
->state
.vportExtY
, lpScaleViewportExtEx
->yNum
,
1399 lpScaleViewportExtEx
->yDenom
);
1400 if (info
->state
.vportExtX
== 0) info
->state
.vportExtX
= 1;
1401 if (info
->state
.vportExtY
== 0) info
->state
.vportExtY
= 1;
1402 if (info
->state
.mode
== MM_ISOTROPIC
)
1403 EMF_FixIsotropic(hdc
, info
);
1405 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1406 lpScaleViewportExtEx
->xNum
,lpScaleViewportExtEx
->xDenom
,
1407 lpScaleViewportExtEx
->yNum
,lpScaleViewportExtEx
->yDenom
);
1412 case EMR_SCALEWINDOWEXTEX
:
1414 const EMRSCALEWINDOWEXTEX
*lpScaleWindowExtEx
= (const EMRSCALEWINDOWEXTEX
*)mr
;
1416 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1418 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1419 !lpScaleWindowExtEx
->yNum
|| !lpScaleWindowExtEx
->yDenom
)
1421 info
->state
.wndExtX
= MulDiv(info
->state
.wndExtX
, lpScaleWindowExtEx
->xNum
,
1422 lpScaleWindowExtEx
->xDenom
);
1423 info
->state
.wndExtY
= MulDiv(info
->state
.wndExtY
, lpScaleWindowExtEx
->yNum
,
1424 lpScaleWindowExtEx
->yDenom
);
1425 if (info
->state
.wndExtX
== 0) info
->state
.wndExtX
= 1;
1426 if (info
->state
.wndExtY
== 0) info
->state
.wndExtY
= 1;
1427 if (info
->state
.mode
== MM_ISOTROPIC
)
1428 EMF_FixIsotropic(hdc
, info
);
1430 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1431 lpScaleWindowExtEx
->xNum
,lpScaleWindowExtEx
->xDenom
,
1432 lpScaleWindowExtEx
->yNum
,lpScaleWindowExtEx
->yDenom
);
1437 case EMR_MODIFYWORLDTRANSFORM
:
1439 const EMRMODIFYWORLDTRANSFORM
*lpModifyWorldTrans
= (const EMRMODIFYWORLDTRANSFORM
*)mr
;
1441 switch(lpModifyWorldTrans
->iMode
) {
1443 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
1444 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
1445 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
1447 case MWT_LEFTMULTIPLY
:
1448 CombineTransform(&info
->state
.world_transform
, &lpModifyWorldTrans
->xform
,
1449 &info
->state
.world_transform
);
1451 case MWT_RIGHTMULTIPLY
:
1452 CombineTransform(&info
->state
.world_transform
, &info
->state
.world_transform
,
1453 &lpModifyWorldTrans
->xform
);
1456 FIXME("Unknown imode %d\n", lpModifyWorldTrans
->iMode
);
1464 const EMRANGLEARC
*lpAngleArc
= (const EMRANGLEARC
*)mr
;
1467 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1468 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1469 lpAngleArc
->eSweepAngle
);
1476 const EMRROUNDRECT
*lpRoundRect
= (const EMRROUNDRECT
*)mr
;
1479 lpRoundRect
->rclBox
.left
,
1480 lpRoundRect
->rclBox
.top
,
1481 lpRoundRect
->rclBox
.right
,
1482 lpRoundRect
->rclBox
.bottom
,
1483 lpRoundRect
->szlCorner
.cx
,
1484 lpRoundRect
->szlCorner
.cy
);
1491 const EMRARC
*lpArc
= (const EMRARC
*)mr
;
1494 (INT
)lpArc
->rclBox
.left
,
1495 (INT
)lpArc
->rclBox
.top
,
1496 (INT
)lpArc
->rclBox
.right
,
1497 (INT
)lpArc
->rclBox
.bottom
,
1498 (INT
)lpArc
->ptlStart
.x
,
1499 (INT
)lpArc
->ptlStart
.y
,
1500 (INT
)lpArc
->ptlEnd
.x
,
1501 (INT
)lpArc
->ptlEnd
.y
);
1508 const EMRCHORD
*lpChord
= (const EMRCHORD
*)mr
;
1511 (INT
)lpChord
->rclBox
.left
,
1512 (INT
)lpChord
->rclBox
.top
,
1513 (INT
)lpChord
->rclBox
.right
,
1514 (INT
)lpChord
->rclBox
.bottom
,
1515 (INT
)lpChord
->ptlStart
.x
,
1516 (INT
)lpChord
->ptlStart
.y
,
1517 (INT
)lpChord
->ptlEnd
.x
,
1518 (INT
)lpChord
->ptlEnd
.y
);
1525 const EMRPIE
*lpPie
= (const EMRPIE
*)mr
;
1528 (INT
)lpPie
->rclBox
.left
,
1529 (INT
)lpPie
->rclBox
.top
,
1530 (INT
)lpPie
->rclBox
.right
,
1531 (INT
)lpPie
->rclBox
.bottom
,
1532 (INT
)lpPie
->ptlStart
.x
,
1533 (INT
)lpPie
->ptlStart
.y
,
1534 (INT
)lpPie
->ptlEnd
.x
,
1535 (INT
)lpPie
->ptlEnd
.y
);
1542 const EMRARC
*lpArcTo
= (const EMRARC
*)mr
;
1545 (INT
)lpArcTo
->rclBox
.left
,
1546 (INT
)lpArcTo
->rclBox
.top
,
1547 (INT
)lpArcTo
->rclBox
.right
,
1548 (INT
)lpArcTo
->rclBox
.bottom
,
1549 (INT
)lpArcTo
->ptlStart
.x
,
1550 (INT
)lpArcTo
->ptlStart
.y
,
1551 (INT
)lpArcTo
->ptlEnd
.x
,
1552 (INT
)lpArcTo
->ptlEnd
.y
);
1557 case EMR_EXTFLOODFILL
:
1559 const EMREXTFLOODFILL
*lpExtFloodFill
= (const EMREXTFLOODFILL
*)mr
;
1562 (INT
)lpExtFloodFill
->ptlStart
.x
,
1563 (INT
)lpExtFloodFill
->ptlStart
.y
,
1564 lpExtFloodFill
->crColor
,
1565 (UINT
)lpExtFloodFill
->iMode
);
1572 const EMRPOLYDRAW
*lpPolyDraw
= (const EMRPOLYDRAW
*)mr
;
1574 (const POINT
*)lpPolyDraw
->aptl
,
1575 lpPolyDraw
->abTypes
,
1576 (INT
)lpPolyDraw
->cptl
);
1581 case EMR_SETARCDIRECTION
:
1583 const EMRSETARCDIRECTION
*lpSetArcDirection
= (const EMRSETARCDIRECTION
*)mr
;
1584 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1588 case EMR_SETMITERLIMIT
:
1590 const EMRSETMITERLIMIT
*lpSetMiterLimit
= (const EMRSETMITERLIMIT
*)mr
;
1591 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1607 case EMR_CLOSEFIGURE
:
1615 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1620 case EMR_STROKEANDFILLPATH
:
1622 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1623 StrokeAndFillPath( hdc
);
1627 case EMR_STROKEPATH
:
1629 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1634 case EMR_FLATTENPATH
:
1646 case EMR_SELECTCLIPPATH
:
1648 const EMRSELECTCLIPPATH
*lpSelectClipPath
= (const EMRSELECTCLIPPATH
*)mr
;
1649 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1659 case EMR_CREATECOLORSPACE
:
1661 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1662 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1663 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1667 case EMR_SETCOLORSPACE
:
1669 const EMRSETCOLORSPACE
*lpSetColorSpace
= (const EMRSETCOLORSPACE
*)mr
;
1671 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1675 case EMR_DELETECOLORSPACE
:
1677 const EMRDELETECOLORSPACE
*lpDeleteColorSpace
= (const EMRDELETECOLORSPACE
*)mr
;
1678 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1682 case EMR_SETICMMODE
:
1684 const EMRSETICMMODE
*lpSetICMMode
= (const EMRSETICMMODE
*)mr
;
1685 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1689 case EMR_PIXELFORMAT
:
1692 const EMRPIXELFORMAT
*lpPixelFormat
= (const EMRPIXELFORMAT
*)mr
;
1694 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1695 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1700 case EMR_SETPALETTEENTRIES
:
1702 const EMRSETPALETTEENTRIES
*lpSetPaletteEntries
= (const EMRSETPALETTEENTRIES
*)mr
;
1704 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1705 (UINT
)lpSetPaletteEntries
->iStart
,
1706 (UINT
)lpSetPaletteEntries
->cEntries
,
1707 lpSetPaletteEntries
->aPalEntries
);
1712 case EMR_RESIZEPALETTE
:
1714 const EMRRESIZEPALETTE
*lpResizePalette
= (const EMRRESIZEPALETTE
*)mr
;
1716 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1717 (UINT
)lpResizePalette
->cEntries
);
1722 case EMR_CREATEDIBPATTERNBRUSHPT
:
1724 const EMRCREATEDIBPATTERNBRUSHPT
*lpCreate
= (const EMRCREATEDIBPATTERNBRUSHPT
*)mr
;
1725 LPVOID lpPackedStruct
;
1727 /* Check that offsets and data are contained within the record
1728 * (including checking for wrap-arounds).
1730 if ( lpCreate
->offBmi
+ lpCreate
->cbBmi
> mr
->nSize
1731 || lpCreate
->offBits
+ lpCreate
->cbBits
> mr
->nSize
1732 || lpCreate
->offBmi
+ lpCreate
->cbBmi
< lpCreate
->offBmi
1733 || lpCreate
->offBits
+ lpCreate
->cbBits
< lpCreate
->offBits
)
1735 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1739 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1740 lpPackedStruct
= HeapAlloc( GetProcessHeap(), 0,
1741 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1744 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1748 /* Now pack this structure */
1749 memcpy( lpPackedStruct
,
1750 ((const BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1752 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1753 ((const BYTE
*)lpCreate
) + lpCreate
->offBits
,
1756 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1757 CreateDIBPatternBrushPt( lpPackedStruct
,
1758 (UINT
)lpCreate
->iUsage
);
1760 HeapFree(GetProcessHeap(), 0, lpPackedStruct
);
1764 case EMR_CREATEMONOBRUSH
:
1766 const EMRCREATEMONOBRUSH
*pCreateMonoBrush
= (const EMRCREATEMONOBRUSH
*)mr
;
1767 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
1770 /* Need to check if the bitmap is monochrome, and if the
1771 two colors are really black and white */
1772 if (pCreateMonoBrush
->iUsage
== DIB_PAL_MONO
)
1776 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1777 * aligned to 32 rather than 16 bits.
1780 bm
.bmWidth
= pbi
->bmiHeader
.biWidth
;
1781 bm
.bmHeight
= abs(pbi
->bmiHeader
.biHeight
);
1782 bm
.bmWidthBytes
= 4 * ((pbi
->bmiHeader
.biWidth
+ 31) / 32);
1783 bm
.bmPlanes
= pbi
->bmiHeader
.biPlanes
;
1784 bm
.bmBitsPixel
= pbi
->bmiHeader
.biBitCount
;
1785 bm
.bmBits
= (BYTE
*)mr
+ pCreateMonoBrush
->offBits
;
1786 hBmp
= CreateBitmapIndirect(&bm
);
1788 else if (is_dib_monochrome(pbi
))
1790 /* Top-down DIBs have a negative height */
1791 LONG height
= pbi
->bmiHeader
.biHeight
;
1793 hBmp
= CreateBitmap(pbi
->bmiHeader
.biWidth
, abs(height
), 1, 1, NULL
);
1794 SetDIBits(hdc
, hBmp
, 0, pbi
->bmiHeader
.biHeight
,
1795 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1799 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1800 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1803 (handletable
->objectHandle
)[pCreateMonoBrush
->ihBrush
] = CreatePatternBrush(hBmp
);
1805 /* CreatePatternBrush created a copy of the bitmap */
1812 const EMRBITBLT
*pBitBlt
= (const EMRBITBLT
*)mr
;
1814 if(pBitBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1815 PatBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1817 } else { /* BitBlt */
1818 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1819 HBRUSH hBrush
, hBrushOld
;
1820 HBITMAP hBmp
= 0, hBmpOld
= 0;
1821 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pBitBlt
->offBmiSrc
);
1823 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1824 SetWorldTransform(hdcSrc
, &pBitBlt
->xformSrc
);
1826 hBrush
= CreateSolidBrush(pBitBlt
->crBkColorSrc
);
1827 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1828 PatBlt(hdcSrc
, pBitBlt
->rclBounds
.left
, pBitBlt
->rclBounds
.top
,
1829 pBitBlt
->rclBounds
.right
- pBitBlt
->rclBounds
.left
,
1830 pBitBlt
->rclBounds
.bottom
- pBitBlt
->rclBounds
.top
, PATCOPY
);
1831 SelectObject(hdcSrc
, hBrushOld
);
1832 DeleteObject(hBrush
);
1834 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1835 (const BYTE
*)mr
+ pBitBlt
->offBitsSrc
, pbi
, pBitBlt
->iUsageSrc
);
1836 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1838 BitBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1839 hdcSrc
, pBitBlt
->xSrc
, pBitBlt
->ySrc
, pBitBlt
->dwRop
);
1841 SelectObject(hdcSrc
, hBmpOld
);
1848 case EMR_STRETCHBLT
:
1850 const EMRSTRETCHBLT
*pStretchBlt
= (const EMRSTRETCHBLT
*)mr
;
1852 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1853 pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1854 pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1855 pStretchBlt
->dwRop
, pStretchBlt
->offBitsSrc
);
1857 if(pStretchBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1858 PatBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1859 pStretchBlt
->dwRop
);
1860 } else { /* StretchBlt */
1861 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1862 HBRUSH hBrush
, hBrushOld
;
1863 HBITMAP hBmp
= 0, hBmpOld
= 0;
1864 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchBlt
->offBmiSrc
);
1866 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1867 SetWorldTransform(hdcSrc
, &pStretchBlt
->xformSrc
);
1869 hBrush
= CreateSolidBrush(pStretchBlt
->crBkColorSrc
);
1870 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1871 PatBlt(hdcSrc
, pStretchBlt
->rclBounds
.left
, pStretchBlt
->rclBounds
.top
,
1872 pStretchBlt
->rclBounds
.right
- pStretchBlt
->rclBounds
.left
,
1873 pStretchBlt
->rclBounds
.bottom
- pStretchBlt
->rclBounds
.top
, PATCOPY
);
1874 SelectObject(hdcSrc
, hBrushOld
);
1875 DeleteObject(hBrush
);
1877 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1878 (const BYTE
*)mr
+ pStretchBlt
->offBitsSrc
, pbi
, pStretchBlt
->iUsageSrc
);
1879 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1881 StretchBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1882 hdcSrc
, pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1883 pStretchBlt
->dwRop
);
1885 SelectObject(hdcSrc
, hBmpOld
);
1892 case EMR_ALPHABLEND
:
1894 const EMRALPHABLEND
*pAlphaBlend
= (const EMRALPHABLEND
*)mr
;
1896 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1897 pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1898 pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1899 pAlphaBlend
->dwRop
, pAlphaBlend
->offBitsSrc
);
1901 if(pAlphaBlend
->offBmiSrc
== 0) {
1902 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1904 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1905 HBITMAP hBmp
= 0, hBmpOld
= 0;
1906 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pAlphaBlend
->offBmiSrc
);
1909 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1910 SetWorldTransform(hdcSrc
, &pAlphaBlend
->xformSrc
);
1912 hBmp
= CreateDIBSection(hdc
, pbi
, pAlphaBlend
->iUsageSrc
, &bits
, NULL
, 0);
1913 memcpy(bits
, (const BYTE
*)mr
+ pAlphaBlend
->offBitsSrc
, pAlphaBlend
->cbBitsSrc
);
1914 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1916 GdiAlphaBlend(hdc
, pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1917 hdcSrc
, pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1918 *(BLENDFUNCTION
*)&pAlphaBlend
->dwRop
);
1920 SelectObject(hdcSrc
, hBmpOld
);
1929 const EMRMASKBLT
*pMaskBlt
= (const EMRMASKBLT
*)mr
;
1930 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1931 HBRUSH hBrush
, hBrushOld
;
1932 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1933 const BITMAPINFO
*pbi
;
1935 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1936 SetWorldTransform(hdcSrc
, &pMaskBlt
->xformSrc
);
1938 hBrush
= CreateSolidBrush(pMaskBlt
->crBkColorSrc
);
1939 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1940 PatBlt(hdcSrc
, pMaskBlt
->rclBounds
.left
, pMaskBlt
->rclBounds
.top
,
1941 pMaskBlt
->rclBounds
.right
- pMaskBlt
->rclBounds
.left
,
1942 pMaskBlt
->rclBounds
.bottom
- pMaskBlt
->rclBounds
.top
, PATCOPY
);
1943 SelectObject(hdcSrc
, hBrushOld
);
1944 DeleteObject(hBrush
);
1946 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiMask
);
1947 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
1949 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
1950 (const BYTE
*)mr
+ pMaskBlt
->offBitsMask
, pbi
, pMaskBlt
->iUsageMask
);
1952 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiSrc
);
1953 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1954 (const BYTE
*)mr
+ pMaskBlt
->offBitsSrc
, pbi
, pMaskBlt
->iUsageSrc
);
1955 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1968 SelectObject(hdcSrc
, hBmpOld
);
1970 DeleteObject(hBmpMask
);
1977 const EMRPLGBLT
*pPlgBlt
= (const EMRPLGBLT
*)mr
;
1978 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1979 HBRUSH hBrush
, hBrushOld
;
1980 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1981 const BITMAPINFO
*pbi
;
1984 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1985 SetWorldTransform(hdcSrc
, &pPlgBlt
->xformSrc
);
1987 pts
[0].x
= pPlgBlt
->aptlDest
[0].x
; pts
[0].y
= pPlgBlt
->aptlDest
[0].y
;
1988 pts
[1].x
= pPlgBlt
->aptlDest
[1].x
; pts
[1].y
= pPlgBlt
->aptlDest
[1].y
;
1989 pts
[2].x
= pPlgBlt
->aptlDest
[2].x
; pts
[2].y
= pPlgBlt
->aptlDest
[2].y
;
1991 hBrush
= CreateSolidBrush(pPlgBlt
->crBkColorSrc
);
1992 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1993 PatBlt(hdcSrc
, pPlgBlt
->rclBounds
.left
, pPlgBlt
->rclBounds
.top
,
1994 pPlgBlt
->rclBounds
.right
- pPlgBlt
->rclBounds
.left
,
1995 pPlgBlt
->rclBounds
.bottom
- pPlgBlt
->rclBounds
.top
, PATCOPY
);
1996 SelectObject(hdcSrc
, hBrushOld
);
1997 DeleteObject(hBrush
);
1999 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiMask
);
2000 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2002 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2003 (const BYTE
*)mr
+ pPlgBlt
->offBitsMask
, pbi
, pPlgBlt
->iUsageMask
);
2005 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiSrc
);
2006 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2007 (const BYTE
*)mr
+ pPlgBlt
->offBitsSrc
, pbi
, pPlgBlt
->iUsageSrc
);
2008 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2019 SelectObject(hdcSrc
, hBmpOld
);
2021 DeleteObject(hBmpMask
);
2026 case EMR_SETDIBITSTODEVICE
:
2028 const EMRSETDIBITSTODEVICE
*pSetDIBitsToDevice
= (const EMRSETDIBITSTODEVICE
*)mr
;
2030 SetDIBitsToDevice(hdc
,
2031 pSetDIBitsToDevice
->xDest
,
2032 pSetDIBitsToDevice
->yDest
,
2033 pSetDIBitsToDevice
->cxSrc
,
2034 pSetDIBitsToDevice
->cySrc
,
2035 pSetDIBitsToDevice
->xSrc
,
2036 pSetDIBitsToDevice
->ySrc
,
2037 pSetDIBitsToDevice
->iStartScan
,
2038 pSetDIBitsToDevice
->cScans
,
2039 (const BYTE
*)mr
+ pSetDIBitsToDevice
->offBitsSrc
,
2040 (const BITMAPINFO
*)((const BYTE
*)mr
+ pSetDIBitsToDevice
->offBmiSrc
),
2041 pSetDIBitsToDevice
->iUsageSrc
);
2045 case EMR_POLYTEXTOUTA
:
2047 const EMRPOLYTEXTOUTA
*pPolyTextOutA
= (const EMRPOLYTEXTOUTA
*)mr
;
2048 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
2050 XFORM xform
, xformOld
;
2053 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
2054 GetWorldTransform(hdc
, &xformOld
);
2056 xform
.eM11
= pPolyTextOutA
->exScale
;
2059 xform
.eM22
= pPolyTextOutA
->eyScale
;
2062 SetWorldTransform(hdc
, &xform
);
2064 /* Set up POLYTEXTA structures */
2065 for(i
= 0; i
< pPolyTextOutA
->cStrings
; i
++)
2067 polytextA
[i
].x
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.x
;
2068 polytextA
[i
].y
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.y
;
2069 polytextA
[i
].n
= pPolyTextOutA
->aemrtext
[i
].nChars
;
2070 polytextA
[i
].lpstr
= (LPCSTR
)((const BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offString
);
2071 polytextA
[i
].uiFlags
= pPolyTextOutA
->aemrtext
[i
].fOptions
;
2072 polytextA
[i
].rcl
.left
= pPolyTextOutA
->aemrtext
[i
].rcl
.left
;
2073 polytextA
[i
].rcl
.right
= pPolyTextOutA
->aemrtext
[i
].rcl
.right
;
2074 polytextA
[i
].rcl
.top
= pPolyTextOutA
->aemrtext
[i
].rcl
.top
;
2075 polytextA
[i
].rcl
.bottom
= pPolyTextOutA
->aemrtext
[i
].rcl
.bottom
;
2076 polytextA
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offDx
);
2078 PolyTextOutA(hdc
, polytextA
, pPolyTextOutA
->cStrings
);
2079 HeapFree(GetProcessHeap(), 0, polytextA
);
2081 SetWorldTransform(hdc
, &xformOld
);
2082 SetGraphicsMode(hdc
, gModeOld
);
2086 case EMR_POLYTEXTOUTW
:
2088 const EMRPOLYTEXTOUTW
*pPolyTextOutW
= (const EMRPOLYTEXTOUTW
*)mr
;
2089 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
2091 XFORM xform
, xformOld
;
2094 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
2095 GetWorldTransform(hdc
, &xformOld
);
2097 xform
.eM11
= pPolyTextOutW
->exScale
;
2100 xform
.eM22
= pPolyTextOutW
->eyScale
;
2103 SetWorldTransform(hdc
, &xform
);
2105 /* Set up POLYTEXTW structures */
2106 for(i
= 0; i
< pPolyTextOutW
->cStrings
; i
++)
2108 polytextW
[i
].x
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.x
;
2109 polytextW
[i
].y
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.y
;
2110 polytextW
[i
].n
= pPolyTextOutW
->aemrtext
[i
].nChars
;
2111 polytextW
[i
].lpstr
= (LPCWSTR
)((const BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offString
);
2112 polytextW
[i
].uiFlags
= pPolyTextOutW
->aemrtext
[i
].fOptions
;
2113 polytextW
[i
].rcl
.left
= pPolyTextOutW
->aemrtext
[i
].rcl
.left
;
2114 polytextW
[i
].rcl
.right
= pPolyTextOutW
->aemrtext
[i
].rcl
.right
;
2115 polytextW
[i
].rcl
.top
= pPolyTextOutW
->aemrtext
[i
].rcl
.top
;
2116 polytextW
[i
].rcl
.bottom
= pPolyTextOutW
->aemrtext
[i
].rcl
.bottom
;
2117 polytextW
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offDx
);
2119 PolyTextOutW(hdc
, polytextW
, pPolyTextOutW
->cStrings
);
2120 HeapFree(GetProcessHeap(), 0, polytextW
);
2122 SetWorldTransform(hdc
, &xformOld
);
2123 SetGraphicsMode(hdc
, gModeOld
);
2129 const EMRFILLRGN
*pFillRgn
= (const EMRFILLRGN
*)mr
;
2130 HRGN hRgn
= ExtCreateRegion(NULL
, pFillRgn
->cbRgnData
, (const RGNDATA
*)pFillRgn
->RgnData
);
2133 (handletable
->objectHandle
)[pFillRgn
->ihBrush
]);
2140 const EMRFRAMERGN
*pFrameRgn
= (const EMRFRAMERGN
*)mr
;
2141 HRGN hRgn
= ExtCreateRegion(NULL
, pFrameRgn
->cbRgnData
, (const RGNDATA
*)pFrameRgn
->RgnData
);
2144 (handletable
->objectHandle
)[pFrameRgn
->ihBrush
],
2145 pFrameRgn
->szlStroke
.cx
,
2146 pFrameRgn
->szlStroke
.cy
);
2153 const EMRINVERTRGN
*pInvertRgn
= (const EMRINVERTRGN
*)mr
;
2154 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (const RGNDATA
*)pInvertRgn
->RgnData
);
2155 InvertRgn(hdc
, hRgn
);
2162 const EMRPAINTRGN
*pPaintRgn
= (const EMRPAINTRGN
*)mr
;
2163 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (const RGNDATA
*)pPaintRgn
->RgnData
);
2164 PaintRgn(hdc
, hRgn
);
2169 case EMR_SETTEXTJUSTIFICATION
:
2171 const EMRSETTEXTJUSTIFICATION
*pSetTextJust
= (const EMRSETTEXTJUSTIFICATION
*)mr
;
2172 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
2178 const EMRSETLAYOUT
*pSetLayout
= (const EMRSETLAYOUT
*)mr
;
2179 SetLayout(hdc
, pSetLayout
->iMode
);
2183 case EMR_GRADIENTFILL
:
2185 EMRGRADIENTFILL
*grad
= (EMRGRADIENTFILL
*)mr
;
2186 GdiGradientFill( hdc
, grad
->Ver
, grad
->nVer
, grad
->Ver
+ grad
->nVer
,
2187 grad
->nTri
, grad
->ulMode
);
2191 case EMR_POLYDRAW16
:
2193 case EMR_GLSBOUNDEDRECORD
:
2194 case EMR_DRAWESCAPE
:
2197 case EMR_SMALLTEXTOUT
:
2198 case EMR_FORCEUFIMAPPING
:
2199 case EMR_NAMEDESCAPE
:
2200 case EMR_COLORCORRECTPALETTE
:
2201 case EMR_SETICMPROFILEA
:
2202 case EMR_SETICMPROFILEW
:
2203 case EMR_TRANSPARENTBLT
:
2204 case EMR_SETLINKEDUFI
:
2205 case EMR_COLORMATCHTOTARGETW
:
2206 case EMR_CREATECOLORSPACEW
:
2209 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2210 record then ignore and return TRUE. */
2211 FIXME("type %d is unimplemented\n", type
);
2214 tmprc
.left
= tmprc
.top
= 0;
2215 tmprc
.right
= tmprc
.bottom
= 1000;
2216 LPtoDP(hdc
, (POINT
*)&tmprc
, 2);
2217 TRACE("L:0,0 - 1000,1000 -> D:%s\n", wine_dbgstr_rect(&tmprc
));
2223 /*****************************************************************************
2225 * EnumEnhMetaFile (GDI32.@)
2227 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2229 * record. Returns when either every record has been used or
2230 * when _EnhMetaFunc_ returns FALSE.
2234 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2241 * This function behaves differently in Win9x and WinNT.
2243 * In WinNT, the DC's world transform is updated as the EMF changes
2244 * the Window/Viewport Extent and Origin or its world transform.
2245 * The actual Window/Viewport Extent and Origin are left untouched.
2247 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2248 * updates the scaling itself but only just before a record that
2249 * writes anything to the DC.
2251 * I'm not sure where the data (enum_emh_data) is stored in either
2252 * version. For this implementation, it is stored before the handle
2253 * table, but it could be stored in the DC, in the EMF handle or in
2257 BOOL WINAPI
EnumEnhMetaFile(
2258 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
2259 HENHMETAFILE hmf
, /* [in] EMF to walk */
2260 ENHMFENUMPROC callback
, /* [in] callback function */
2261 LPVOID data
, /* [in] optional data for callback function */
2262 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
2274 HBRUSH hBrush
= NULL
;
2277 enum_emh_data
*info
;
2278 SIZE vp_size
, win_size
;
2279 POINT vp_org
, win_org
;
2280 INT mapMode
= MM_TEXT
, old_align
= 0, old_rop2
= 0, old_arcdir
= 0, old_polyfill
= 0, old_stretchblt
= 0;
2281 COLORREF old_text_color
= 0, old_bk_color
= 0;
2285 SetLastError(ERROR_INVALID_PARAMETER
);
2289 emh
= EMF_GetEnhMetaHeader(hmf
);
2291 SetLastError(ERROR_INVALID_HANDLE
);
2295 info
= HeapAlloc( GetProcessHeap(), 0,
2296 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2299 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2302 info
->state
.mode
= MM_TEXT
;
2303 info
->state
.wndOrgX
= 0;
2304 info
->state
.wndOrgY
= 0;
2305 info
->state
.wndExtX
= 1;
2306 info
->state
.wndExtY
= 1;
2307 info
->state
.vportOrgX
= 0;
2308 info
->state
.vportOrgY
= 0;
2309 info
->state
.vportExtX
= 1;
2310 info
->state
.vportExtY
= 1;
2311 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
2312 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
2313 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
2315 info
->state
.next
= NULL
;
2316 info
->save_level
= 0;
2317 info
->saved_state
= NULL
;
2319 ht
= (HANDLETABLE
*) &info
[1];
2320 ht
->objectHandle
[0] = hmf
;
2321 for(i
= 1; i
< emh
->nHandles
; i
++)
2322 ht
->objectHandle
[i
] = NULL
;
2326 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
2327 GetWorldTransform(hdc
, &savedXform
);
2328 GetViewportExtEx(hdc
, &vp_size
);
2329 GetWindowExtEx(hdc
, &win_size
);
2330 GetViewportOrgEx(hdc
, &vp_org
);
2331 GetWindowOrgEx(hdc
, &win_org
);
2332 mapMode
= GetMapMode(hdc
);
2335 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
2336 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
2337 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
2339 hRgn
= CreateRectRgn(0, 0, 0, 0);
2340 if (!GetClipRgn(hdc
, hRgn
))
2346 old_text_color
= SetTextColor(hdc
, RGB(0,0,0));
2347 old_bk_color
= SetBkColor(hdc
, RGB(0xff, 0xff, 0xff));
2348 old_align
= SetTextAlign(hdc
, 0);
2349 old_rop2
= SetROP2(hdc
, R2_COPYPEN
);
2350 old_arcdir
= SetArcDirection(hdc
, AD_COUNTERCLOCKWISE
);
2351 old_polyfill
= SetPolyFillMode(hdc
, ALTERNATE
);
2352 old_stretchblt
= SetStretchBltMode(hdc
, BLACKONWHITE
);
2356 /* Win95 leaves the vp/win ext/org info alone */
2357 info
->init_transform
.eM11
= 1.0;
2358 info
->init_transform
.eM12
= 0.0;
2359 info
->init_transform
.eM21
= 0.0;
2360 info
->init_transform
.eM22
= 1.0;
2361 info
->init_transform
.eDx
= 0.0;
2362 info
->init_transform
.eDy
= 0.0;
2366 /* WinNT combines the vp/win ext/org info into a transform */
2367 double xscale
, yscale
;
2368 xscale
= (double)vp_size
.cx
/ (double)win_size
.cx
;
2369 yscale
= (double)vp_size
.cy
/ (double)win_size
.cy
;
2370 info
->init_transform
.eM11
= xscale
;
2371 info
->init_transform
.eM12
= 0.0;
2372 info
->init_transform
.eM21
= 0.0;
2373 info
->init_transform
.eM22
= yscale
;
2374 info
->init_transform
.eDx
= (double)vp_org
.x
- xscale
* (double)win_org
.x
;
2375 info
->init_transform
.eDy
= (double)vp_org
.y
- yscale
* (double)win_org
.y
;
2377 CombineTransform(&info
->init_transform
, &savedXform
, &info
->init_transform
);
2380 if ( lpRect
&& WIDTH(emh
->rclFrame
) && HEIGHT(emh
->rclFrame
) )
2382 double xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
2385 TRACE("rect: %s. rclFrame: (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(lpRect
),
2386 emh
->rclFrame
.left
, emh
->rclFrame
.top
, emh
->rclFrame
.right
,
2387 emh
->rclFrame
.bottom
);
2389 xSrcPixSize
= (double) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
2390 ySrcPixSize
= (double) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
2391 xscale
= (double) WIDTH(*lpRect
) * 100.0 /
2392 WIDTH(emh
->rclFrame
) * xSrcPixSize
;
2393 yscale
= (double) HEIGHT(*lpRect
) * 100.0 /
2394 HEIGHT(emh
->rclFrame
) * ySrcPixSize
;
2395 TRACE("xscale = %f, yscale = %f\n", xscale
, yscale
);
2397 xform
.eM11
= xscale
;
2400 xform
.eM22
= yscale
;
2401 xform
.eDx
= (double) lpRect
->left
- (double) WIDTH(*lpRect
) / WIDTH(emh
->rclFrame
) * emh
->rclFrame
.left
;
2402 xform
.eDy
= (double) lpRect
->top
- (double) HEIGHT(*lpRect
) / HEIGHT(emh
->rclFrame
) * emh
->rclFrame
.top
;
2404 CombineTransform(&info
->init_transform
, &xform
, &info
->init_transform
);
2407 /* WinNT resets the current vp/win org/ext */
2410 SetMapMode(hdc
, MM_TEXT
);
2411 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2412 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2413 EMF_Update_MF_Xform(hdc
, info
);
2419 while(ret
&& offset
< emh
->nBytes
)
2421 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
2423 /* In Win9x mode we update the xform if the record will produce output */
2424 if (hdc
&& IS_WIN9X() && emr_produces_output(emr
->iType
))
2425 EMF_Update_MF_Xform(hdc
, info
);
2427 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr
->iType
), emr
->nSize
);
2428 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nHandles
, (LPARAM
)data
);
2429 offset
+= emr
->nSize
;
2431 /* WinNT - update the transform (win9x updates when the next graphics
2432 output record is played). */
2433 if (hdc
&& !IS_WIN9X())
2434 EMF_Update_MF_Xform(hdc
, info
);
2439 SetStretchBltMode(hdc
, old_stretchblt
);
2440 SetPolyFillMode(hdc
, old_polyfill
);
2441 SetArcDirection(hdc
, old_arcdir
);
2442 SetROP2(hdc
, old_rop2
);
2443 SetTextAlign(hdc
, old_align
);
2444 SetBkColor(hdc
, old_bk_color
);
2445 SetTextColor(hdc
, old_text_color
);
2448 SelectObject(hdc
, hBrush
);
2449 SelectObject(hdc
, hPen
);
2450 SelectObject(hdc
, hFont
);
2451 ExtSelectClipRgn(hdc
, hRgn
, RGN_COPY
);
2454 SetWorldTransform(hdc
, &savedXform
);
2456 SetGraphicsMode(hdc
, savedMode
);
2457 SetMapMode(hdc
, mapMode
);
2458 SetWindowOrgEx(hdc
, win_org
.x
, win_org
.y
, NULL
);
2459 SetWindowExtEx(hdc
, win_size
.cx
, win_size
.cy
, NULL
);
2460 SetViewportOrgEx(hdc
, vp_org
.x
, vp_org
.y
, NULL
);
2461 SetViewportExtEx(hdc
, vp_size
.cx
, vp_size
.cy
, NULL
);
2464 for(i
= 1; i
< emh
->nHandles
; i
++) /* Don't delete element 0 (hmf) */
2465 if( (ht
->objectHandle
)[i
] )
2466 DeleteObject( (ht
->objectHandle
)[i
] );
2468 while (info
->saved_state
)
2470 EMF_dc_state
*state
= info
->saved_state
;
2471 info
->saved_state
= info
->saved_state
->next
;
2472 HeapFree( GetProcessHeap(), 0, state
);
2474 HeapFree( GetProcessHeap(), 0, info
);
2478 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
2479 const ENHMETARECORD
*emr
,
2480 INT handles
, LPARAM data
)
2482 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
2485 /**************************************************************************
2486 * PlayEnhMetaFile (GDI32.@)
2488 * Renders an enhanced metafile into a specified rectangle *lpRect
2489 * in device context hdc.
2495 BOOL WINAPI
PlayEnhMetaFile(
2496 HDC hdc
, /* [in] DC to render into */
2497 HENHMETAFILE hmf
, /* [in] metafile to render */
2498 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
2501 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
2505 /*****************************************************************************
2506 * DeleteEnhMetaFile (GDI32.@)
2508 * Deletes an enhanced metafile and frees the associated storage.
2510 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
2512 return EMF_Delete_HENHMETAFILE( hmf
);
2515 /*****************************************************************************
2516 * CopyEnhMetaFileA (GDI32.@)
2518 * Duplicate an enhanced metafile.
2522 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
2523 HENHMETAFILE hmfSrc
,
2526 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2527 HENHMETAFILE hmfDst
;
2529 if(!emrSrc
) return FALSE
;
2531 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2532 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2533 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, FALSE
);
2535 HeapFree( GetProcessHeap(), 0, emrDst
);
2539 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2540 NULL
, CREATE_ALWAYS
, 0, 0);
2541 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2542 CloseHandle( hFile
);
2543 /* Reopen file for reading only, so that apps can share
2544 read access to the file while hmf is still valid */
2545 hFile
= CreateFileA( file
, GENERIC_READ
, FILE_SHARE_READ
,
2546 NULL
, OPEN_EXISTING
, 0, 0);
2547 if(hFile
== INVALID_HANDLE_VALUE
) {
2548 ERR("Can't reopen emf for reading\n");
2551 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2552 CloseHandle( hFile
);
2557 /*****************************************************************************
2558 * CopyEnhMetaFileW (GDI32.@)
2560 * See CopyEnhMetaFileA.
2564 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2565 HENHMETAFILE hmfSrc
,
2568 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2569 HENHMETAFILE hmfDst
;
2571 if(!emrSrc
) return FALSE
;
2573 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2574 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2575 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, FALSE
);
2577 HeapFree( GetProcessHeap(), 0, emrDst
);
2581 hFile
= CreateFileW( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2582 NULL
, CREATE_ALWAYS
, 0, 0);
2583 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2584 CloseHandle( hFile
);
2585 /* Reopen file for reading only, so that apps can share
2586 read access to the file while hmf is still valid */
2587 hFile
= CreateFileW( file
, GENERIC_READ
, FILE_SHARE_READ
,
2588 NULL
, OPEN_EXISTING
, 0, 0);
2589 if(hFile
== INVALID_HANDLE_VALUE
) {
2590 ERR("Can't reopen emf for reading\n");
2593 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2594 CloseHandle( hFile
);
2600 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2601 typedef struct tagEMF_PaletteCopy
2604 LPPALETTEENTRY lpPe
;
2607 /***************************************************************
2608 * Find the EMR_EOF record and then use it to find the
2609 * palette entries for this enhanced metafile.
2610 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2611 * which contains the max number of elements to copy and where
2614 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2616 static INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2618 const ENHMETARECORD
*lpEMR
,
2623 if ( lpEMR
->iType
== EMR_EOF
)
2625 const EMREOF
*lpEof
= (const EMREOF
*)lpEMR
;
2626 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
2627 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
2629 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy
);
2631 memcpy( info
->lpPe
, (LPCSTR
)lpEof
+ lpEof
->offPalEntries
,
2632 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
2634 /* Update the passed data as a return code */
2635 info
->lpPe
= NULL
; /* Palettes were copied! */
2636 info
->cEntries
= dwNumPalToCopy
;
2638 return FALSE
; /* That's all we need */
2644 /*****************************************************************************
2645 * GetEnhMetaFilePaletteEntries (GDI32.@)
2647 * Copy the palette and report size
2649 * BUGS: Error codes (SetLastError) are not set on failures
2651 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
2653 LPPALETTEENTRY lpPe
)
2655 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
2656 EMF_PaletteCopy infoForCallBack
;
2658 TRACE( "(%p,%d,%p)\n", hEmf
, cEntries
, lpPe
);
2660 if (!enhHeader
) return 0;
2662 /* First check if there are any palettes associated with
2664 if ( enhHeader
->nPalEntries
== 0 ) return 0;
2666 /* Is the user requesting the number of palettes? */
2667 if ( lpPe
== NULL
) return enhHeader
->nPalEntries
;
2669 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2670 infoForCallBack
.cEntries
= cEntries
;
2671 infoForCallBack
.lpPe
= lpPe
;
2673 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
2674 &infoForCallBack
, 0 ) )
2677 /* Verify that the callback executed correctly */
2678 if ( infoForCallBack
.lpPe
!= NULL
)
2680 /* Callback proc had error! */
2681 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2685 return infoForCallBack
.cEntries
;
2688 /******************************************************************
2689 * extract_emf_from_comment
2691 * If the WMF was created by GetWinMetaFileBits, then extract the
2692 * original EMF that is stored in MFCOMMENT chunks.
2694 static HENHMETAFILE
extract_emf_from_comment( const BYTE
*buf
, UINT mf_size
)
2696 METAHEADER
*mh
= (METAHEADER
*)buf
;
2698 emf_in_wmf_comment
*chunk
;
2700 DWORD size
= 0, remaining
, chunks
;
2701 BYTE
*emf_bits
= NULL
, *ptr
;
2703 HENHMETAFILE emf
= NULL
;
2705 if (mf_size
< sizeof(*mh
)) return NULL
;
2707 for (offset
= mh
->mtHeaderSize
* 2; offset
< mf_size
; offset
+= (mr
->rdSize
* 2))
2709 mr
= (METARECORD
*)((char *)mh
+ offset
);
2710 chunk
= (emf_in_wmf_comment
*)(mr
->rdParm
+ 2);
2712 if (mr
->rdFunction
!= META_ESCAPE
|| mr
->rdParm
[0] != MFCOMMENT
) goto done
;
2713 if (chunk
->magic
!= WMFC_MAGIC
) goto done
;
2717 size
= remaining
= chunk
->emf_size
;
2718 chunks
= chunk
->num_chunks
;
2719 emf_bits
= ptr
= HeapAlloc( GetProcessHeap(), 0, size
);
2720 if (!emf_bits
) goto done
;
2722 if (chunk
->chunk_size
> remaining
) goto done
;
2723 remaining
-= chunk
->chunk_size
;
2724 if (chunk
->remaining_size
!= remaining
) goto done
;
2725 memcpy( ptr
, chunk
->emf_data
, chunk
->chunk_size
);
2726 ptr
+= chunk
->chunk_size
;
2727 if (--chunks
== 0) break;
2730 for (offset
= 0; offset
< mf_size
/ 2; offset
++)
2731 checksum
+= *((WORD
*)buf
+ offset
);
2732 if (checksum
) goto done
;
2734 emf
= SetEnhMetaFileBits( size
, emf_bits
);
2737 HeapFree( GetProcessHeap(), 0, emf_bits
);
2741 typedef struct wmf_in_emf_comment
2748 DWORD cbWinMetaFile
;
2749 } wmf_in_emf_comment
;
2751 /******************************************************************
2752 * SetWinMetaFileBits (GDI32.@)
2754 * Translate from old style to new style.
2757 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
, const BYTE
*lpbBuffer
, HDC hdcRef
,
2758 const METAFILEPICT
*lpmfp
)
2760 static const WCHAR szDisplayW
[] = { 'D','I','S','P','L','A','Y','\0' };
2761 HMETAFILE hmf
= NULL
;
2762 HENHMETAFILE ret
= NULL
;
2763 HDC hdc
= NULL
, hdcdisp
= NULL
;
2764 RECT rc
, *prcFrame
= NULL
;
2765 LONG mm
, xExt
, yExt
;
2766 INT horzsize
, vertsize
, horzres
, vertres
;
2768 TRACE("(%d, %p, %p, %p)\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
2770 hmf
= SetMetaFileBitsEx(cbBuffer
, lpbBuffer
);
2773 WARN("SetMetaFileBitsEx failed\n");
2777 ret
= extract_emf_from_comment( lpbBuffer
, cbBuffer
);
2778 if (ret
) return ret
;
2781 hdcRef
= hdcdisp
= CreateDCW(szDisplayW
, NULL
, NULL
, NULL
);
2785 TRACE("mm = %d %dx%d\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2793 TRACE("lpmfp == NULL\n");
2795 /* Use the whole device surface */
2796 mm
= MM_ANISOTROPIC
;
2801 if (mm
== MM_ISOTROPIC
|| mm
== MM_ANISOTROPIC
)
2803 if (xExt
< 0 || yExt
< 0)
2805 /* Use the whole device surface */
2810 /* Use the x and y extents as the frame box */
2813 rc
.left
= rc
.top
= 0;
2820 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
)))
2822 ERR("CreateEnhMetaFile failed\n");
2827 * Write the original METAFILE into the enhanced metafile.
2828 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2832 wmf_in_emf_comment
*mfcomment
;
2833 UINT mfcomment_size
;
2835 mfcomment_size
= sizeof (*mfcomment
) + cbBuffer
;
2836 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
2839 mfcomment
->ident
= GDICOMMENT_IDENTIFIER
;
2840 mfcomment
->iComment
= GDICOMMENT_WINDOWS_METAFILE
;
2841 mfcomment
->nVersion
= 0x00000300;
2842 mfcomment
->nChecksum
= 0; /* FIXME */
2843 mfcomment
->fFlags
= 0;
2844 mfcomment
->cbWinMetaFile
= cbBuffer
;
2845 memcpy(&mfcomment
[1], lpbBuffer
, cbBuffer
);
2846 GdiComment(hdc
, mfcomment_size
, (BYTE
*) mfcomment
);
2847 HeapFree(GetProcessHeap(), 0, mfcomment
);
2849 SetMapMode(hdc
, mm
);
2853 horzsize
= GetDeviceCaps(hdcRef
, HORZSIZE
);
2854 vertsize
= GetDeviceCaps(hdcRef
, VERTSIZE
);
2855 horzres
= GetDeviceCaps(hdcRef
, HORZRES
);
2856 vertres
= GetDeviceCaps(hdcRef
, VERTRES
);
2860 /* Use the whole device surface */
2866 xExt
= MulDiv(xExt
, horzres
, 100 * horzsize
);
2867 yExt
= MulDiv(yExt
, vertres
, 100 * vertsize
);
2870 /* set the initial viewport:window ratio as 1:1 */
2871 SetViewportExtEx(hdc
, xExt
, yExt
, NULL
);
2872 SetWindowExtEx(hdc
, xExt
, yExt
, NULL
);
2874 PlayMetaFile(hdc
, hmf
);
2876 ret
= CloseEnhMetaFile(hdc
);
2878 if (hdcdisp
) DeleteDC(hdcdisp
);
2879 DeleteMetaFile(hmf
);