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
);
55 BOOL on_disk
; /* true if metafile is on disk */
58 static const struct emr_name
{
71 X(EMR_SETWINDOWEXTEX
),
72 X(EMR_SETWINDOWORGEX
),
73 X(EMR_SETVIEWPORTEXTEX
),
74 X(EMR_SETVIEWPORTORGEX
),
78 X(EMR_SETMAPPERFLAGS
),
81 X(EMR_SETPOLYFILLMODE
),
83 X(EMR_SETSTRETCHBLTMODE
),
85 X(EMR_SETCOLORADJUSTMENT
),
91 X(EMR_EXCLUDECLIPRECT
),
92 X(EMR_INTERSECTCLIPRECT
),
93 X(EMR_SCALEVIEWPORTEXTEX
),
94 X(EMR_SCALEWINDOWEXTEX
),
97 X(EMR_SETWORLDTRANSFORM
),
98 X(EMR_MODIFYWORLDTRANSFORM
),
101 X(EMR_CREATEBRUSHINDIRECT
),
110 X(EMR_SELECTPALETTE
),
111 X(EMR_CREATEPALETTE
),
112 X(EMR_SETPALETTEENTRIES
),
113 X(EMR_RESIZEPALETTE
),
114 X(EMR_REALIZEPALETTE
),
119 X(EMR_SETARCDIRECTION
),
120 X(EMR_SETMITERLIMIT
),
125 X(EMR_STROKEANDFILLPATH
),
129 X(EMR_SELECTCLIPPATH
),
136 X(EMR_EXTSELECTCLIPRGN
),
141 X(EMR_SETDIBITSTODEVICE
),
142 X(EMR_STRETCHDIBITS
),
143 X(EMR_EXTCREATEFONTINDIRECTW
),
149 X(EMR_POLYBEZIERTO16
),
151 X(EMR_POLYPOLYLINE16
),
152 X(EMR_POLYPOLYGON16
),
154 X(EMR_CREATEMONOBRUSH
),
155 X(EMR_CREATEDIBPATTERNBRUSHPT
),
160 X(EMR_CREATECOLORSPACE
),
161 X(EMR_SETCOLORSPACE
),
162 X(EMR_DELETECOLORSPACE
),
164 X(EMR_GLSBOUNDEDRECORD
),
170 X(EMR_FORCEUFIMAPPING
),
172 X(EMR_COLORCORRECTPALETTE
),
173 X(EMR_SETICMPROFILEA
),
174 X(EMR_SETICMPROFILEW
),
177 X(EMR_TRANSPARENTBLT
),
181 X(EMR_SETTEXTJUSTIFICATION
),
182 X(EMR_COLORMATCHTOTARGETW
),
183 X(EMR_CREATECOLORSPACEW
)
187 /****************************************************************************
190 static const char *get_emr_name(DWORD type
)
193 for(i
= 0; i
< sizeof(emr_names
) / sizeof(emr_names
[0]); i
++)
194 if(type
== emr_names
[i
].type
) return emr_names
[i
].name
;
195 TRACE("Unknown record type %d\n", type
);
199 /***********************************************************************
202 * Returns whether a DIB can be converted to a monochrome DDB.
204 * A DIB can be converted if its color table contains only black and
205 * white. Black must be the first color in the color table.
207 * Note : If the first color in the color table is white followed by
208 * black, we can't convert it to a monochrome DDB with
209 * SetDIBits, because black and white would be inverted.
211 static inline BOOL
is_dib_monochrome( const BITMAPINFO
* info
)
213 if (info
->bmiHeader
.biBitCount
!= 1) return FALSE
;
215 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
217 const RGBTRIPLE
*rgb
= ((const BITMAPCOREINFO
*) info
)->bmciColors
;
219 /* Check if the first color is black */
220 if ((rgb
->rgbtRed
== 0) && (rgb
->rgbtGreen
== 0) && (rgb
->rgbtBlue
== 0))
223 /* Check if the second color is white */
224 return ((rgb
->rgbtRed
== 0xff) && (rgb
->rgbtGreen
== 0xff)
225 && (rgb
->rgbtBlue
== 0xff));
229 else /* assume BITMAPINFOHEADER */
231 const RGBQUAD
*rgb
= info
->bmiColors
;
233 /* Check if the first color is black */
234 if ((rgb
->rgbRed
== 0) && (rgb
->rgbGreen
== 0) &&
235 (rgb
->rgbBlue
== 0) && (rgb
->rgbReserved
== 0))
239 /* Check if the second color is white */
240 return ((rgb
->rgbRed
== 0xff) && (rgb
->rgbGreen
== 0xff)
241 && (rgb
->rgbBlue
== 0xff) && (rgb
->rgbReserved
== 0));
247 /****************************************************************************
248 * EMF_Create_HENHMETAFILE
250 HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, BOOL on_disk
)
253 ENHMETAFILEOBJ
*metaObj
;
255 if (emh
->iType
!= EMR_HEADER
)
257 SetLastError(ERROR_INVALID_DATA
);
260 if (emh
->dSignature
!= ENHMETA_SIGNATURE
||
261 (emh
->nBytes
& 3)) /* refuse to load unaligned EMF as Windows does */
263 WARN("Invalid emf header type 0x%08x sig 0x%08x.\n",
264 emh
->iType
, emh
->dSignature
);
268 if (!(metaObj
= HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj
) ))) return 0;
271 metaObj
->on_disk
= on_disk
;
273 if (!(hmf
= alloc_gdi_handle( &metaObj
->header
, OBJ_ENHMETAFILE
, NULL
)))
274 HeapFree( GetProcessHeap(), 0, metaObj
);
278 /****************************************************************************
279 * EMF_Delete_HENHMETAFILE
281 static BOOL
EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf
)
283 ENHMETAFILEOBJ
*metaObj
= free_gdi_handle( hmf
);
285 if(!metaObj
) return FALSE
;
288 UnmapViewOfFile( metaObj
->emh
);
290 HeapFree( GetProcessHeap(), 0, metaObj
->emh
);
291 return HeapFree( GetProcessHeap(), 0, metaObj
);
294 /******************************************************************
295 * EMF_GetEnhMetaHeader
297 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
299 static ENHMETAHEADER
*EMF_GetEnhMetaHeader( HENHMETAFILE hmf
)
301 ENHMETAHEADER
*ret
= NULL
;
302 ENHMETAFILEOBJ
*metaObj
= GDI_GetObjPtr( hmf
, OBJ_ENHMETAFILE
);
303 TRACE("hmf %p -> enhmetaObj %p\n", hmf
, metaObj
);
307 GDI_ReleaseObj( hmf
);
312 /*****************************************************************************
316 static HENHMETAFILE
EMF_GetEnhMetaFile( HANDLE hFile
)
322 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
323 emh
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, 0 );
324 CloseHandle( hMapping
);
328 hemf
= EMF_Create_HENHMETAFILE( emh
, TRUE
);
330 UnmapViewOfFile( emh
);
335 /*****************************************************************************
336 * GetEnhMetaFileA (GDI32.@)
340 HENHMETAFILE WINAPI
GetEnhMetaFileA(
341 LPCSTR lpszMetaFile
/* [in] filename of enhanced metafile */
347 hFile
= CreateFileA(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
348 OPEN_EXISTING
, 0, 0);
349 if (hFile
== INVALID_HANDLE_VALUE
) {
350 WARN("could not open %s\n", lpszMetaFile
);
353 hmf
= EMF_GetEnhMetaFile( hFile
);
354 CloseHandle( hFile
);
358 /*****************************************************************************
359 * GetEnhMetaFileW (GDI32.@)
361 HENHMETAFILE WINAPI
GetEnhMetaFileW(
362 LPCWSTR lpszMetaFile
) /* [in] filename of enhanced metafile */
367 hFile
= CreateFileW(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
368 OPEN_EXISTING
, 0, 0);
369 if (hFile
== INVALID_HANDLE_VALUE
) {
370 WARN("could not open %s\n", debugstr_w(lpszMetaFile
));
373 hmf
= EMF_GetEnhMetaFile( hFile
);
374 CloseHandle( hFile
);
378 /*****************************************************************************
379 * GetEnhMetaFileHeader (GDI32.@)
381 * Retrieves the record containing the header for the specified
382 * enhanced-format metafile.
385 * If buf is NULL, returns the size of buffer required.
386 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
389 UINT WINAPI
GetEnhMetaFileHeader(
390 HENHMETAFILE hmf
, /* [in] enhanced metafile */
391 UINT bufsize
, /* [in] size of buffer */
392 LPENHMETAHEADER buf
/* [out] buffer */
398 emh
= EMF_GetEnhMetaHeader(hmf
);
399 if(!emh
) return FALSE
;
401 if (!buf
) return size
;
402 size
= min(size
, bufsize
);
403 memmove(buf
, emh
, size
);
408 /*****************************************************************************
409 * GetEnhMetaFileDescriptionA (GDI32.@)
411 * See GetEnhMetaFileDescriptionW.
413 UINT WINAPI
GetEnhMetaFileDescriptionA(
414 HENHMETAFILE hmf
, /* [in] enhanced metafile */
415 UINT size
, /* [in] size of buf */
416 LPSTR buf
/* [out] buffer to receive description */
419 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
423 if(!emh
) return FALSE
;
424 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
425 descrW
= (WCHAR
*) ((char *) emh
+ emh
->offDescription
);
426 len
= WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, NULL
, 0, NULL
, NULL
);
428 if (!buf
|| !size
) return len
;
430 len
= min( size
, len
);
431 WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, buf
, len
, NULL
, NULL
);
435 /*****************************************************************************
436 * GetEnhMetaFileDescriptionW (GDI32.@)
438 * Copies the description string of an enhanced metafile into a buffer
442 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
443 * number of characters copied.
445 UINT WINAPI
GetEnhMetaFileDescriptionW(
446 HENHMETAFILE hmf
, /* [in] enhanced metafile */
447 UINT size
, /* [in] size of buf */
448 LPWSTR buf
/* [out] buffer to receive description */
451 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
453 if(!emh
) return FALSE
;
454 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
455 if (!buf
|| !size
) return emh
->nDescription
;
457 memmove(buf
, (char *) emh
+ emh
->offDescription
, min(size
,emh
->nDescription
)*sizeof(WCHAR
));
458 return min(size
, emh
->nDescription
);
461 /****************************************************************************
462 * SetEnhMetaFileBits (GDI32.@)
464 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
466 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
468 ENHMETAHEADER
*emh
= HeapAlloc( GetProcessHeap(), 0, bufsize
);
470 memmove(emh
, buf
, bufsize
);
471 hmf
= EMF_Create_HENHMETAFILE( emh
, FALSE
);
473 HeapFree( GetProcessHeap(), 0, emh
);
477 /*****************************************************************************
478 * GetEnhMetaFileBits (GDI32.@)
481 UINT WINAPI
GetEnhMetaFileBits(
487 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
493 if( buf
== NULL
) return size
;
495 size
= min( size
, bufsize
);
496 memmove(buf
, emh
, size
);
500 typedef struct EMF_dc_state
503 XFORM world_transform
;
512 struct EMF_dc_state
*next
;
515 typedef struct enum_emh_data
517 XFORM init_transform
;
520 EMF_dc_state
*saved_state
;
523 #define ENUM_GET_PRIVATE_DATA(ht) \
524 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
526 #define WIDTH(rect) ( (rect).right - (rect).left )
527 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
529 #define IS_WIN9X() (GetVersion()&0x80000000)
531 static void EMF_Update_MF_Xform(HDC hdc
, const enum_emh_data
*info
)
533 XFORM mapping_mode_trans
, final_trans
;
534 double scaleX
, scaleY
;
536 scaleX
= (double)info
->state
.vportExtX
/ (double)info
->state
.wndExtX
;
537 scaleY
= (double)info
->state
.vportExtY
/ (double)info
->state
.wndExtY
;
538 mapping_mode_trans
.eM11
= scaleX
;
539 mapping_mode_trans
.eM12
= 0.0;
540 mapping_mode_trans
.eM21
= 0.0;
541 mapping_mode_trans
.eM22
= scaleY
;
542 mapping_mode_trans
.eDx
= (double)info
->state
.vportOrgX
- scaleX
* (double)info
->state
.wndOrgX
;
543 mapping_mode_trans
.eDy
= (double)info
->state
.vportOrgY
- scaleY
* (double)info
->state
.wndOrgY
;
545 CombineTransform(&final_trans
, &info
->state
.world_transform
, &mapping_mode_trans
);
546 CombineTransform(&final_trans
, &final_trans
, &info
->init_transform
);
548 if (!SetWorldTransform(hdc
, &final_trans
))
550 ERR("World transform failed!\n");
554 static void EMF_RestoreDC( enum_emh_data
*info
, INT level
)
556 if (abs(level
) > info
->save_level
|| level
== 0) return;
558 if (level
< 0) level
= info
->save_level
+ level
+ 1;
560 while (info
->save_level
>= level
)
562 EMF_dc_state
*state
= info
->saved_state
;
563 info
->saved_state
= state
->next
;
565 if (--info
->save_level
< level
)
566 info
->state
= *state
;
567 HeapFree( GetProcessHeap(), 0, state
);
571 static void EMF_SaveDC( enum_emh_data
*info
)
573 EMF_dc_state
*state
= HeapAlloc( GetProcessHeap(), 0, sizeof(*state
));
576 *state
= info
->state
;
577 state
->next
= info
->saved_state
;
578 info
->saved_state
= state
;
580 TRACE("save_level %d\n", info
->save_level
);
584 static void EMF_SetMapMode(HDC hdc
, enum_emh_data
*info
)
586 INT horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
587 INT vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
588 INT horzRes
= GetDeviceCaps( hdc
, HORZRES
);
589 INT vertRes
= GetDeviceCaps( hdc
, VERTRES
);
591 TRACE("%d\n", info
->state
.mode
);
593 switch(info
->state
.mode
)
596 info
->state
.wndExtX
= 1;
597 info
->state
.wndExtY
= 1;
598 info
->state
.vportExtX
= 1;
599 info
->state
.vportExtY
= 1;
603 info
->state
.wndExtX
= horzSize
* 10;
604 info
->state
.wndExtY
= vertSize
* 10;
605 info
->state
.vportExtX
= horzRes
;
606 info
->state
.vportExtY
= -vertRes
;
609 info
->state
.wndExtX
= horzSize
* 100;
610 info
->state
.wndExtY
= vertSize
* 100;
611 info
->state
.vportExtX
= horzRes
;
612 info
->state
.vportExtY
= -vertRes
;
615 info
->state
.wndExtX
= MulDiv(1000, horzSize
, 254);
616 info
->state
.wndExtY
= MulDiv(1000, vertSize
, 254);
617 info
->state
.vportExtX
= horzRes
;
618 info
->state
.vportExtY
= -vertRes
;
621 info
->state
.wndExtX
= MulDiv(10000, horzSize
, 254);
622 info
->state
.wndExtY
= MulDiv(10000, vertSize
, 254);
623 info
->state
.vportExtX
= horzRes
;
624 info
->state
.vportExtY
= -vertRes
;
627 info
->state
.wndExtX
= MulDiv(14400, horzSize
, 254);
628 info
->state
.wndExtY
= MulDiv(14400, vertSize
, 254);
629 info
->state
.vportExtX
= horzRes
;
630 info
->state
.vportExtY
= -vertRes
;
639 /***********************************************************************
642 * Fix viewport extensions for isotropic mode.
645 static void EMF_FixIsotropic(HDC hdc
, enum_emh_data
*info
)
647 double xdim
= fabs((double)info
->state
.vportExtX
* GetDeviceCaps( hdc
, HORZSIZE
) /
648 (GetDeviceCaps( hdc
, HORZRES
) * info
->state
.wndExtX
));
649 double ydim
= fabs((double)info
->state
.vportExtY
* GetDeviceCaps( hdc
, VERTSIZE
) /
650 (GetDeviceCaps( hdc
, VERTRES
) * info
->state
.wndExtY
));
654 INT mincx
= (info
->state
.vportExtX
>= 0) ? 1 : -1;
655 info
->state
.vportExtX
= floor(info
->state
.vportExtX
* ydim
/ xdim
+ 0.5);
656 if (!info
->state
.vportExtX
) info
->state
.vportExtX
= mincx
;
660 INT mincy
= (info
->state
.vportExtY
>= 0) ? 1 : -1;
661 info
->state
.vportExtY
= floor(info
->state
.vportExtY
* xdim
/ ydim
+ 0.5);
662 if (!info
->state
.vportExtY
) info
->state
.vportExtY
= mincy
;
666 /*****************************************************************************
667 * emr_produces_output
669 * Returns TRUE if the record type writes something to the dc. Used by
670 * PlayEnhMetaFileRecord to determine whether it needs to update the
671 * dc's xform when in win9x mode.
673 * FIXME: need to test which records should be here.
675 static BOOL
emr_produces_output(int type
)
681 case EMR_POLYBEZIERTO
:
683 case EMR_POLYPOLYLINE
:
684 case EMR_POLYPOLYGON
:
687 case EMR_EXCLUDECLIPRECT
:
688 case EMR_INTERSECTCLIPRECT
:
689 case EMR_SELECTOBJECT
:
697 case EMR_EXTFLOODFILL
:
710 case EMR_SETDIBITSTODEVICE
:
711 case EMR_STRETCHDIBITS
:
712 case EMR_EXTTEXTOUTA
:
713 case EMR_EXTTEXTOUTW
:
714 case EMR_POLYBEZIER16
:
717 case EMR_POLYBEZIERTO16
:
718 case EMR_POLYLINETO16
:
719 case EMR_POLYPOLYLINE16
:
720 case EMR_POLYPOLYGON16
:
722 case EMR_POLYTEXTOUTA
:
723 case EMR_POLYTEXTOUTW
:
724 case EMR_SMALLTEXTOUT
:
726 case EMR_TRANSPARENTBLT
:
734 /*****************************************************************************
735 * PlayEnhMetaFileRecord (GDI32.@)
737 * Render a single enhanced metafile record in the device context hdc.
740 * TRUE (non zero) on success, FALSE on error.
742 * Many unimplemented records.
743 * No error handling on record play failures (ie checking return codes)
746 * WinNT actually updates the current world transform in this function
747 * whereas Win9x does not.
749 BOOL WINAPI
PlayEnhMetaFileRecord(
750 HDC hdc
, /* [in] device context in which to render EMF record */
751 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
752 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
753 UINT handles
/* [in] size of handle array */
758 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
760 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
761 hdc
, handletable
, mr
, handles
);
762 if (!mr
) return FALSE
;
766 TRACE("record %s\n", get_emr_name(type
));
775 const EMRGDICOMMENT
*lpGdiComment
= (const EMRGDICOMMENT
*)mr
;
776 /* In an enhanced metafile, there can be both public and private GDI comments */
777 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
782 const EMRSETMAPMODE
*pSetMapMode
= (const EMRSETMAPMODE
*)mr
;
784 if (info
->state
.mode
== pSetMapMode
->iMode
&&
785 (info
->state
.mode
== MM_ISOTROPIC
|| info
->state
.mode
== MM_ANISOTROPIC
))
787 info
->state
.mode
= pSetMapMode
->iMode
;
788 EMF_SetMapMode(hdc
, info
);
793 const EMRSETBKMODE
*pSetBkMode
= (const EMRSETBKMODE
*)mr
;
794 SetBkMode(hdc
, pSetBkMode
->iMode
);
799 const EMRSETBKCOLOR
*pSetBkColor
= (const EMRSETBKCOLOR
*)mr
;
800 SetBkColor(hdc
, pSetBkColor
->crColor
);
803 case EMR_SETPOLYFILLMODE
:
805 const EMRSETPOLYFILLMODE
*pSetPolyFillMode
= (const EMRSETPOLYFILLMODE
*)mr
;
806 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
811 const EMRSETROP2
*pSetROP2
= (const EMRSETROP2
*)mr
;
812 SetROP2(hdc
, pSetROP2
->iMode
);
815 case EMR_SETSTRETCHBLTMODE
:
817 const EMRSETSTRETCHBLTMODE
*pSetStretchBltMode
= (const EMRSETSTRETCHBLTMODE
*)mr
;
818 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
821 case EMR_SETTEXTALIGN
:
823 const EMRSETTEXTALIGN
*pSetTextAlign
= (const EMRSETTEXTALIGN
*)mr
;
824 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
827 case EMR_SETTEXTCOLOR
:
829 const EMRSETTEXTCOLOR
*pSetTextColor
= (const EMRSETTEXTCOLOR
*)mr
;
830 SetTextColor(hdc
, pSetTextColor
->crColor
);
841 const EMRRESTOREDC
*pRestoreDC
= (const EMRRESTOREDC
*)mr
;
842 TRACE("EMR_RESTORE: %d\n", pRestoreDC
->iRelative
);
843 if (RestoreDC( hdc
, pRestoreDC
->iRelative
))
844 EMF_RestoreDC( info
, pRestoreDC
->iRelative
);
847 case EMR_INTERSECTCLIPRECT
:
849 const EMRINTERSECTCLIPRECT
*pClipRect
= (const EMRINTERSECTCLIPRECT
*)mr
;
850 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
851 pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
852 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
853 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
854 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
857 case EMR_SELECTOBJECT
:
859 const EMRSELECTOBJECT
*pSelectObject
= (const EMRSELECTOBJECT
*)mr
;
860 if( pSelectObject
->ihObject
& 0x80000000 ) {
861 /* High order bit is set - it's a stock object
862 * Strip the high bit to get the index.
863 * See MSDN article Q142319
865 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
868 /* High order bit wasn't set - not a stock object
871 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
875 case EMR_DELETEOBJECT
:
877 const EMRDELETEOBJECT
*pDeleteObject
= (const EMRDELETEOBJECT
*)mr
;
878 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
879 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
882 case EMR_SETWINDOWORGEX
:
884 const EMRSETWINDOWORGEX
*pSetWindowOrgEx
= (const EMRSETWINDOWORGEX
*)mr
;
886 info
->state
.wndOrgX
= pSetWindowOrgEx
->ptlOrigin
.x
;
887 info
->state
.wndOrgY
= pSetWindowOrgEx
->ptlOrigin
.y
;
889 TRACE("SetWindowOrgEx: %d,%d\n", info
->state
.wndOrgX
, info
->state
.wndOrgY
);
892 case EMR_SETWINDOWEXTEX
:
894 const EMRSETWINDOWEXTEX
*pSetWindowExtEx
= (const EMRSETWINDOWEXTEX
*)mr
;
896 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
898 info
->state
.wndExtX
= pSetWindowExtEx
->szlExtent
.cx
;
899 info
->state
.wndExtY
= pSetWindowExtEx
->szlExtent
.cy
;
900 if (info
->state
.mode
== MM_ISOTROPIC
)
901 EMF_FixIsotropic(hdc
, info
);
903 TRACE("SetWindowExtEx: %d,%d\n",info
->state
.wndExtX
, info
->state
.wndExtY
);
906 case EMR_SETVIEWPORTORGEX
:
908 const EMRSETVIEWPORTORGEX
*pSetViewportOrgEx
= (const EMRSETVIEWPORTORGEX
*)mr
;
910 info
->state
.vportOrgX
= pSetViewportOrgEx
->ptlOrigin
.x
;
911 info
->state
.vportOrgY
= pSetViewportOrgEx
->ptlOrigin
.y
;
912 TRACE("SetViewportOrgEx: %d,%d\n", info
->state
.vportOrgX
, info
->state
.vportOrgY
);
915 case EMR_SETVIEWPORTEXTEX
:
917 const EMRSETVIEWPORTEXTEX
*pSetViewportExtEx
= (const EMRSETVIEWPORTEXTEX
*)mr
;
919 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
921 info
->state
.vportExtX
= pSetViewportExtEx
->szlExtent
.cx
;
922 info
->state
.vportExtY
= pSetViewportExtEx
->szlExtent
.cy
;
923 if (info
->state
.mode
== MM_ISOTROPIC
)
924 EMF_FixIsotropic(hdc
, info
);
925 TRACE("SetViewportExtEx: %d,%d\n", info
->state
.vportExtX
, info
->state
.vportExtY
);
930 const EMRCREATEPEN
*pCreatePen
= (const EMRCREATEPEN
*)mr
;
931 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
932 CreatePenIndirect(&pCreatePen
->lopn
);
935 case EMR_EXTCREATEPEN
:
937 const EMREXTCREATEPEN
*pPen
= (const EMREXTCREATEPEN
*)mr
;
939 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
940 lb
.lbColor
= pPen
->elp
.elpColor
;
941 lb
.lbHatch
= pPen
->elp
.elpHatch
;
943 if(pPen
->offBmi
|| pPen
->offBits
)
944 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
946 (handletable
->objectHandle
)[pPen
->ihPen
] =
947 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
948 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpStyleEntry
);
951 case EMR_CREATEBRUSHINDIRECT
:
953 const EMRCREATEBRUSHINDIRECT
*pBrush
= (const EMRCREATEBRUSHINDIRECT
*)mr
;
955 brush
.lbStyle
= pBrush
->lb
.lbStyle
;
956 brush
.lbColor
= pBrush
->lb
.lbColor
;
957 brush
.lbHatch
= pBrush
->lb
.lbHatch
;
958 (handletable
->objectHandle
)[pBrush
->ihBrush
] = CreateBrushIndirect(&brush
);
961 case EMR_EXTCREATEFONTINDIRECTW
:
963 const EMREXTCREATEFONTINDIRECTW
*pFont
= (const EMREXTCREATEFONTINDIRECTW
*)mr
;
964 (handletable
->objectHandle
)[pFont
->ihFont
] =
965 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
970 const EMRMOVETOEX
*pMoveToEx
= (const EMRMOVETOEX
*)mr
;
971 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
976 const EMRLINETO
*pLineTo
= (const EMRLINETO
*)mr
;
977 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
982 const EMRRECTANGLE
*pRect
= (const EMRRECTANGLE
*)mr
;
983 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
984 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
989 const EMRELLIPSE
*pEllipse
= (const EMRELLIPSE
*)mr
;
990 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
991 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
996 const EMRPOLYGON16
*pPoly
= (const EMRPOLYGON16
*)mr
;
997 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
998 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
999 pPoly
->cpts
* sizeof(POINT
) );
1001 for(i
= 0; i
< pPoly
->cpts
; i
++)
1003 pts
[i
].x
= pPoly
->apts
[i
].x
;
1004 pts
[i
].y
= pPoly
->apts
[i
].y
;
1006 Polygon(hdc
, pts
, pPoly
->cpts
);
1007 HeapFree( GetProcessHeap(), 0, pts
);
1010 case EMR_POLYLINE16
:
1012 const EMRPOLYLINE16
*pPoly
= (const EMRPOLYLINE16
*)mr
;
1013 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1014 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1015 pPoly
->cpts
* sizeof(POINT
) );
1017 for(i
= 0; i
< pPoly
->cpts
; i
++)
1019 pts
[i
].x
= pPoly
->apts
[i
].x
;
1020 pts
[i
].y
= pPoly
->apts
[i
].y
;
1022 Polyline(hdc
, pts
, pPoly
->cpts
);
1023 HeapFree( GetProcessHeap(), 0, pts
);
1026 case EMR_POLYLINETO16
:
1028 const EMRPOLYLINETO16
*pPoly
= (const EMRPOLYLINETO16
*)mr
;
1029 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1030 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1031 pPoly
->cpts
* sizeof(POINT
) );
1033 for(i
= 0; i
< pPoly
->cpts
; i
++)
1035 pts
[i
].x
= pPoly
->apts
[i
].x
;
1036 pts
[i
].y
= pPoly
->apts
[i
].y
;
1038 PolylineTo(hdc
, pts
, pPoly
->cpts
);
1039 HeapFree( GetProcessHeap(), 0, pts
);
1042 case EMR_POLYBEZIER16
:
1044 const EMRPOLYBEZIER16
*pPoly
= (const EMRPOLYBEZIER16
*)mr
;
1045 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1046 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1047 pPoly
->cpts
* sizeof(POINT
) );
1049 for(i
= 0; i
< pPoly
->cpts
; i
++)
1051 pts
[i
].x
= pPoly
->apts
[i
].x
;
1052 pts
[i
].y
= pPoly
->apts
[i
].y
;
1054 PolyBezier(hdc
, pts
, pPoly
->cpts
);
1055 HeapFree( GetProcessHeap(), 0, pts
);
1058 case EMR_POLYBEZIERTO16
:
1060 const EMRPOLYBEZIERTO16
*pPoly
= (const EMRPOLYBEZIERTO16
*)mr
;
1061 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1062 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1063 pPoly
->cpts
* sizeof(POINT
) );
1065 for(i
= 0; i
< pPoly
->cpts
; i
++)
1067 pts
[i
].x
= pPoly
->apts
[i
].x
;
1068 pts
[i
].y
= pPoly
->apts
[i
].y
;
1070 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
1071 HeapFree( GetProcessHeap(), 0, pts
);
1074 case EMR_POLYPOLYGON16
:
1076 const EMRPOLYPOLYGON16
*pPolyPoly
= (const EMRPOLYPOLYGON16
*)mr
;
1077 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1078 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1080 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1081 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1083 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1088 PolyPolygon(hdc
, pt
, (const INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1089 HeapFree( GetProcessHeap(), 0, pt
);
1092 case EMR_POLYPOLYLINE16
:
1094 const EMRPOLYPOLYLINE16
*pPolyPoly
= (const EMRPOLYPOLYLINE16
*)mr
;
1095 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1096 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1098 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1099 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1101 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1106 PolyPolyline(hdc
, pt
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1107 HeapFree( GetProcessHeap(), 0, pt
);
1111 case EMR_STRETCHDIBITS
:
1113 const EMRSTRETCHDIBITS
*pStretchDIBits
= (const EMRSTRETCHDIBITS
*)mr
;
1116 pStretchDIBits
->xDest
,
1117 pStretchDIBits
->yDest
,
1118 pStretchDIBits
->cxDest
,
1119 pStretchDIBits
->cyDest
,
1120 pStretchDIBits
->xSrc
,
1121 pStretchDIBits
->ySrc
,
1122 pStretchDIBits
->cxSrc
,
1123 pStretchDIBits
->cySrc
,
1124 (const BYTE
*)mr
+ pStretchDIBits
->offBitsSrc
,
1125 (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchDIBits
->offBmiSrc
),
1126 pStretchDIBits
->iUsageSrc
,
1127 pStretchDIBits
->dwRop
);
1131 case EMR_EXTTEXTOUTA
:
1133 const EMREXTTEXTOUTA
*pExtTextOutA
= (const EMREXTTEXTOUTA
*)mr
;
1135 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 = %d, %d - %d, %d. flags %08x\n",
1142 pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1143 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, pExtTextOutA
->emrtext
.fOptions
);
1145 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1146 * These files can be enumerated and played under Win98 just
1147 * fine, but at least Win2k chokes on them.
1149 if (pExtTextOutA
->emrtext
.offDx
)
1150 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offDx
);
1152 ExtTextOutA(hdc
, pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1153 pExtTextOutA
->emrtext
.fOptions
, &rc
,
1154 (LPCSTR
)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offString
), pExtTextOutA
->emrtext
.nChars
,
1159 case EMR_EXTTEXTOUTW
:
1161 const EMREXTTEXTOUTW
*pExtTextOutW
= (const EMREXTTEXTOUTW
*)mr
;
1163 const INT
*dx
= NULL
;
1165 rc
.left
= pExtTextOutW
->emrtext
.rcl
.left
;
1166 rc
.top
= pExtTextOutW
->emrtext
.rcl
.top
;
1167 rc
.right
= pExtTextOutW
->emrtext
.rcl
.right
;
1168 rc
.bottom
= pExtTextOutW
->emrtext
.rcl
.bottom
;
1169 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %d, %d - %d, %d. flags %08x\n",
1170 pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1171 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, pExtTextOutW
->emrtext
.fOptions
);
1173 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1174 * These files can be enumerated and played under Win98 just
1175 * fine, but at least Win2k chokes on them.
1177 if (pExtTextOutW
->emrtext
.offDx
)
1178 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offDx
);
1180 ExtTextOutW(hdc
, pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1181 pExtTextOutW
->emrtext
.fOptions
, &rc
,
1182 (LPCWSTR
)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offString
), pExtTextOutW
->emrtext
.nChars
,
1187 case EMR_CREATEPALETTE
:
1189 const EMRCREATEPALETTE
*lpCreatePal
= (const EMRCREATEPALETTE
*)mr
;
1191 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1192 CreatePalette( &lpCreatePal
->lgpl
);
1197 case EMR_SELECTPALETTE
:
1199 const EMRSELECTPALETTE
*lpSelectPal
= (const EMRSELECTPALETTE
*)mr
;
1201 if( lpSelectPal
->ihPal
& 0x80000000 ) {
1202 SelectPalette( hdc
, GetStockObject(lpSelectPal
->ihPal
& 0x7fffffff), TRUE
);
1204 SelectPalette( hdc
, (handletable
->objectHandle
)[lpSelectPal
->ihPal
], TRUE
);
1209 case EMR_REALIZEPALETTE
:
1211 RealizePalette( hdc
);
1215 case EMR_EXTSELECTCLIPRGN
:
1217 const EMREXTSELECTCLIPRGN
*lpRgn
= (const EMREXTSELECTCLIPRGN
*)mr
;
1220 if (mr
->nSize
>= sizeof(*lpRgn
) + sizeof(RGNDATAHEADER
))
1221 hRgn
= ExtCreateRegion( &info
->init_transform
, 0, (const RGNDATA
*)lpRgn
->RgnData
);
1223 ExtSelectClipRgn(hdc
, hRgn
, (INT
)(lpRgn
->iMode
));
1224 /* ExtSelectClipRgn created a copy of the region */
1229 case EMR_SETMETARGN
:
1235 case EMR_SETWORLDTRANSFORM
:
1237 const EMRSETWORLDTRANSFORM
*lpXfrm
= (const EMRSETWORLDTRANSFORM
*)mr
;
1238 info
->state
.world_transform
= lpXfrm
->xform
;
1242 case EMR_POLYBEZIER
:
1244 const EMRPOLYBEZIER
*lpPolyBez
= (const EMRPOLYBEZIER
*)mr
;
1245 PolyBezier(hdc
, (const POINT
*)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1251 const EMRPOLYGON
*lpPoly
= (const EMRPOLYGON
*)mr
;
1252 Polygon( hdc
, (const POINT
*)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1258 const EMRPOLYLINE
*lpPolyLine
= (const EMRPOLYLINE
*)mr
;
1259 Polyline(hdc
, (const POINT
*)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1263 case EMR_POLYBEZIERTO
:
1265 const EMRPOLYBEZIERTO
*lpPolyBezierTo
= (const EMRPOLYBEZIERTO
*)mr
;
1266 PolyBezierTo( hdc
, (const POINT
*)lpPolyBezierTo
->aptl
,
1267 (UINT
)lpPolyBezierTo
->cptl
);
1271 case EMR_POLYLINETO
:
1273 const EMRPOLYLINETO
*lpPolyLineTo
= (const EMRPOLYLINETO
*)mr
;
1274 PolylineTo( hdc
, (const POINT
*)lpPolyLineTo
->aptl
,
1275 (UINT
)lpPolyLineTo
->cptl
);
1279 case EMR_POLYPOLYLINE
:
1281 const EMRPOLYPOLYLINE
*pPolyPolyline
= (const EMRPOLYPOLYLINE
*)mr
;
1282 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1284 PolyPolyline(hdc
, (const POINT
*)(pPolyPolyline
->aPolyCounts
+
1285 pPolyPolyline
->nPolys
),
1286 pPolyPolyline
->aPolyCounts
,
1287 pPolyPolyline
->nPolys
);
1292 case EMR_POLYPOLYGON
:
1294 const EMRPOLYPOLYGON
*pPolyPolygon
= (const EMRPOLYPOLYGON
*)mr
;
1296 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1298 PolyPolygon(hdc
, (const POINT
*)(pPolyPolygon
->aPolyCounts
+
1299 pPolyPolygon
->nPolys
),
1300 (const INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
1304 case EMR_SETBRUSHORGEX
:
1306 const EMRSETBRUSHORGEX
*lpSetBrushOrgEx
= (const EMRSETBRUSHORGEX
*)mr
;
1309 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1310 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1318 const EMRSETPIXELV
*lpSetPixelV
= (const EMRSETPIXELV
*)mr
;
1321 (INT
)lpSetPixelV
->ptlPixel
.x
,
1322 (INT
)lpSetPixelV
->ptlPixel
.y
,
1323 lpSetPixelV
->crColor
);
1328 case EMR_SETMAPPERFLAGS
:
1330 const EMRSETMAPPERFLAGS
*lpSetMapperFlags
= (const EMRSETMAPPERFLAGS
*)mr
;
1332 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1337 case EMR_SETCOLORADJUSTMENT
:
1339 const EMRSETCOLORADJUSTMENT
*lpSetColorAdjust
= (const EMRSETCOLORADJUSTMENT
*)mr
;
1341 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1346 case EMR_OFFSETCLIPRGN
:
1348 const EMROFFSETCLIPRGN
*lpOffsetClipRgn
= (const EMROFFSETCLIPRGN
*)mr
;
1351 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1352 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1353 FIXME("OffsetClipRgn\n");
1358 case EMR_EXCLUDECLIPRECT
:
1360 const EMREXCLUDECLIPRECT
*lpExcludeClipRect
= (const EMREXCLUDECLIPRECT
*)mr
;
1362 ExcludeClipRect( hdc
,
1363 lpExcludeClipRect
->rclClip
.left
,
1364 lpExcludeClipRect
->rclClip
.top
,
1365 lpExcludeClipRect
->rclClip
.right
,
1366 lpExcludeClipRect
->rclClip
.bottom
);
1367 FIXME("ExcludeClipRect\n");
1372 case EMR_SCALEVIEWPORTEXTEX
:
1374 const EMRSCALEVIEWPORTEXTEX
*lpScaleViewportExtEx
= (const EMRSCALEVIEWPORTEXTEX
*)mr
;
1376 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1378 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1379 !lpScaleViewportExtEx
->yNum
|| !lpScaleViewportExtEx
->yDenom
)
1381 info
->state
.vportExtX
= MulDiv(info
->state
.vportExtX
, lpScaleViewportExtEx
->xNum
,
1382 lpScaleViewportExtEx
->xDenom
);
1383 info
->state
.vportExtY
= MulDiv(info
->state
.vportExtY
, lpScaleViewportExtEx
->yNum
,
1384 lpScaleViewportExtEx
->yDenom
);
1385 if (info
->state
.vportExtX
== 0) info
->state
.vportExtX
= 1;
1386 if (info
->state
.vportExtY
== 0) info
->state
.vportExtY
= 1;
1387 if (info
->state
.mode
== MM_ISOTROPIC
)
1388 EMF_FixIsotropic(hdc
, info
);
1390 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1391 lpScaleViewportExtEx
->xNum
,lpScaleViewportExtEx
->xDenom
,
1392 lpScaleViewportExtEx
->yNum
,lpScaleViewportExtEx
->yDenom
);
1397 case EMR_SCALEWINDOWEXTEX
:
1399 const EMRSCALEWINDOWEXTEX
*lpScaleWindowExtEx
= (const EMRSCALEWINDOWEXTEX
*)mr
;
1401 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1403 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1404 !lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->yDenom
)
1406 info
->state
.wndExtX
= MulDiv(info
->state
.wndExtX
, lpScaleWindowExtEx
->xNum
,
1407 lpScaleWindowExtEx
->xDenom
);
1408 info
->state
.wndExtY
= MulDiv(info
->state
.wndExtY
, lpScaleWindowExtEx
->yNum
,
1409 lpScaleWindowExtEx
->yDenom
);
1410 if (info
->state
.wndExtX
== 0) info
->state
.wndExtX
= 1;
1411 if (info
->state
.wndExtY
== 0) info
->state
.wndExtY
= 1;
1412 if (info
->state
.mode
== MM_ISOTROPIC
)
1413 EMF_FixIsotropic(hdc
, info
);
1415 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1416 lpScaleWindowExtEx
->xNum
,lpScaleWindowExtEx
->xDenom
,
1417 lpScaleWindowExtEx
->yNum
,lpScaleWindowExtEx
->yDenom
);
1422 case EMR_MODIFYWORLDTRANSFORM
:
1424 const EMRMODIFYWORLDTRANSFORM
*lpModifyWorldTrans
= (const EMRMODIFYWORLDTRANSFORM
*)mr
;
1426 switch(lpModifyWorldTrans
->iMode
) {
1428 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
1429 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
1430 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
1432 case MWT_LEFTMULTIPLY
:
1433 CombineTransform(&info
->state
.world_transform
, &lpModifyWorldTrans
->xform
,
1434 &info
->state
.world_transform
);
1436 case MWT_RIGHTMULTIPLY
:
1437 CombineTransform(&info
->state
.world_transform
, &info
->state
.world_transform
,
1438 &lpModifyWorldTrans
->xform
);
1441 FIXME("Unknown imode %d\n", lpModifyWorldTrans
->iMode
);
1449 const EMRANGLEARC
*lpAngleArc
= (const EMRANGLEARC
*)mr
;
1452 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1453 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1454 lpAngleArc
->eSweepAngle
);
1461 const EMRROUNDRECT
*lpRoundRect
= (const EMRROUNDRECT
*)mr
;
1464 lpRoundRect
->rclBox
.left
,
1465 lpRoundRect
->rclBox
.top
,
1466 lpRoundRect
->rclBox
.right
,
1467 lpRoundRect
->rclBox
.bottom
,
1468 lpRoundRect
->szlCorner
.cx
,
1469 lpRoundRect
->szlCorner
.cy
);
1476 const EMRARC
*lpArc
= (const EMRARC
*)mr
;
1479 (INT
)lpArc
->rclBox
.left
,
1480 (INT
)lpArc
->rclBox
.top
,
1481 (INT
)lpArc
->rclBox
.right
,
1482 (INT
)lpArc
->rclBox
.bottom
,
1483 (INT
)lpArc
->ptlStart
.x
,
1484 (INT
)lpArc
->ptlStart
.y
,
1485 (INT
)lpArc
->ptlEnd
.x
,
1486 (INT
)lpArc
->ptlEnd
.y
);
1493 const EMRCHORD
*lpChord
= (const EMRCHORD
*)mr
;
1496 (INT
)lpChord
->rclBox
.left
,
1497 (INT
)lpChord
->rclBox
.top
,
1498 (INT
)lpChord
->rclBox
.right
,
1499 (INT
)lpChord
->rclBox
.bottom
,
1500 (INT
)lpChord
->ptlStart
.x
,
1501 (INT
)lpChord
->ptlStart
.y
,
1502 (INT
)lpChord
->ptlEnd
.x
,
1503 (INT
)lpChord
->ptlEnd
.y
);
1510 const EMRPIE
*lpPie
= (const EMRPIE
*)mr
;
1513 (INT
)lpPie
->rclBox
.left
,
1514 (INT
)lpPie
->rclBox
.top
,
1515 (INT
)lpPie
->rclBox
.right
,
1516 (INT
)lpPie
->rclBox
.bottom
,
1517 (INT
)lpPie
->ptlStart
.x
,
1518 (INT
)lpPie
->ptlStart
.y
,
1519 (INT
)lpPie
->ptlEnd
.x
,
1520 (INT
)lpPie
->ptlEnd
.y
);
1527 const EMRARC
*lpArcTo
= (const EMRARC
*)mr
;
1530 (INT
)lpArcTo
->rclBox
.left
,
1531 (INT
)lpArcTo
->rclBox
.top
,
1532 (INT
)lpArcTo
->rclBox
.right
,
1533 (INT
)lpArcTo
->rclBox
.bottom
,
1534 (INT
)lpArcTo
->ptlStart
.x
,
1535 (INT
)lpArcTo
->ptlStart
.y
,
1536 (INT
)lpArcTo
->ptlEnd
.x
,
1537 (INT
)lpArcTo
->ptlEnd
.y
);
1542 case EMR_EXTFLOODFILL
:
1544 const EMREXTFLOODFILL
*lpExtFloodFill
= (const EMREXTFLOODFILL
*)mr
;
1547 (INT
)lpExtFloodFill
->ptlStart
.x
,
1548 (INT
)lpExtFloodFill
->ptlStart
.y
,
1549 lpExtFloodFill
->crColor
,
1550 (UINT
)lpExtFloodFill
->iMode
);
1557 const EMRPOLYDRAW
*lpPolyDraw
= (const EMRPOLYDRAW
*)mr
;
1559 (const POINT
*)lpPolyDraw
->aptl
,
1560 lpPolyDraw
->abTypes
,
1561 (INT
)lpPolyDraw
->cptl
);
1566 case EMR_SETARCDIRECTION
:
1568 const EMRSETARCDIRECTION
*lpSetArcDirection
= (const EMRSETARCDIRECTION
*)mr
;
1569 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1573 case EMR_SETMITERLIMIT
:
1575 const EMRSETMITERLIMIT
*lpSetMiterLimit
= (const EMRSETMITERLIMIT
*)mr
;
1576 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1592 case EMR_CLOSEFIGURE
:
1600 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1605 case EMR_STROKEANDFILLPATH
:
1607 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1608 StrokeAndFillPath( hdc
);
1612 case EMR_STROKEPATH
:
1614 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1619 case EMR_FLATTENPATH
:
1631 case EMR_SELECTCLIPPATH
:
1633 const EMRSELECTCLIPPATH
*lpSelectClipPath
= (const EMRSELECTCLIPPATH
*)mr
;
1634 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1644 case EMR_CREATECOLORSPACE
:
1646 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1647 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1648 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1652 case EMR_SETCOLORSPACE
:
1654 const EMRSETCOLORSPACE
*lpSetColorSpace
= (const EMRSETCOLORSPACE
*)mr
;
1656 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1660 case EMR_DELETECOLORSPACE
:
1662 const EMRDELETECOLORSPACE
*lpDeleteColorSpace
= (const EMRDELETECOLORSPACE
*)mr
;
1663 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1667 case EMR_SETICMMODE
:
1669 const EMRSETICMMODE
*lpSetICMMode
= (const EMRSETICMMODE
*)mr
;
1670 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1674 case EMR_PIXELFORMAT
:
1677 const EMRPIXELFORMAT
*lpPixelFormat
= (const EMRPIXELFORMAT
*)mr
;
1679 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1680 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1685 case EMR_SETPALETTEENTRIES
:
1687 const EMRSETPALETTEENTRIES
*lpSetPaletteEntries
= (const EMRSETPALETTEENTRIES
*)mr
;
1689 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1690 (UINT
)lpSetPaletteEntries
->iStart
,
1691 (UINT
)lpSetPaletteEntries
->cEntries
,
1692 lpSetPaletteEntries
->aPalEntries
);
1697 case EMR_RESIZEPALETTE
:
1699 const EMRRESIZEPALETTE
*lpResizePalette
= (const EMRRESIZEPALETTE
*)mr
;
1701 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1702 (UINT
)lpResizePalette
->cEntries
);
1707 case EMR_CREATEDIBPATTERNBRUSHPT
:
1709 const EMRCREATEDIBPATTERNBRUSHPT
*lpCreate
= (const EMRCREATEDIBPATTERNBRUSHPT
*)mr
;
1710 LPVOID lpPackedStruct
;
1712 /* Check that offsets and data are contained within the record
1713 * (including checking for wrap-arounds).
1715 if ( lpCreate
->offBmi
+ lpCreate
->cbBmi
> mr
->nSize
1716 || lpCreate
->offBits
+ lpCreate
->cbBits
> mr
->nSize
1717 || lpCreate
->offBmi
+ lpCreate
->cbBmi
< lpCreate
->offBmi
1718 || lpCreate
->offBits
+ lpCreate
->cbBits
< lpCreate
->offBits
)
1720 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1724 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1725 lpPackedStruct
= HeapAlloc( GetProcessHeap(), 0,
1726 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1729 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1733 /* Now pack this structure */
1734 memcpy( lpPackedStruct
,
1735 ((const BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1737 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1738 ((const BYTE
*)lpCreate
) + lpCreate
->offBits
,
1741 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1742 CreateDIBPatternBrushPt( lpPackedStruct
,
1743 (UINT
)lpCreate
->iUsage
);
1745 HeapFree(GetProcessHeap(), 0, lpPackedStruct
);
1749 case EMR_CREATEMONOBRUSH
:
1751 const EMRCREATEMONOBRUSH
*pCreateMonoBrush
= (const EMRCREATEMONOBRUSH
*)mr
;
1752 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
1755 /* Need to check if the bitmap is monochrome, and if the
1756 two colors are really black and white */
1757 if (pCreateMonoBrush
->iUsage
== DIB_PAL_MONO
)
1761 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1762 * aligned to 32 rather than 16 bits.
1765 bm
.bmWidth
= pbi
->bmiHeader
.biWidth
;
1766 bm
.bmHeight
= abs(pbi
->bmiHeader
.biHeight
);
1767 bm
.bmWidthBytes
= 4 * ((pbi
->bmiHeader
.biWidth
+ 31) / 32);
1768 bm
.bmPlanes
= pbi
->bmiHeader
.biPlanes
;
1769 bm
.bmBitsPixel
= pbi
->bmiHeader
.biBitCount
;
1770 bm
.bmBits
= (BYTE
*)mr
+ pCreateMonoBrush
->offBits
;
1771 hBmp
= CreateBitmapIndirect(&bm
);
1773 else if (is_dib_monochrome(pbi
))
1775 /* Top-down DIBs have a negative height */
1776 LONG height
= pbi
->bmiHeader
.biHeight
;
1778 hBmp
= CreateBitmap(pbi
->bmiHeader
.biWidth
, abs(height
), 1, 1, NULL
);
1779 SetDIBits(hdc
, hBmp
, 0, pbi
->bmiHeader
.biHeight
,
1780 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1784 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1785 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1788 (handletable
->objectHandle
)[pCreateMonoBrush
->ihBrush
] = CreatePatternBrush(hBmp
);
1790 /* CreatePatternBrush created a copy of the bitmap */
1797 const EMRBITBLT
*pBitBlt
= (const EMRBITBLT
*)mr
;
1799 if(pBitBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1800 PatBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1802 } else { /* BitBlt */
1803 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1804 HBRUSH hBrush
, hBrushOld
;
1805 HBITMAP hBmp
= 0, hBmpOld
= 0;
1806 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pBitBlt
->offBmiSrc
);
1808 SetWorldTransform(hdcSrc
, &pBitBlt
->xformSrc
);
1810 hBrush
= CreateSolidBrush(pBitBlt
->crBkColorSrc
);
1811 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1812 PatBlt(hdcSrc
, pBitBlt
->rclBounds
.left
, pBitBlt
->rclBounds
.top
,
1813 pBitBlt
->rclBounds
.right
- pBitBlt
->rclBounds
.left
,
1814 pBitBlt
->rclBounds
.bottom
- pBitBlt
->rclBounds
.top
, PATCOPY
);
1815 SelectObject(hdcSrc
, hBrushOld
);
1816 DeleteObject(hBrush
);
1818 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1819 (const BYTE
*)mr
+ pBitBlt
->offBitsSrc
, pbi
, pBitBlt
->iUsageSrc
);
1820 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1822 BitBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1823 hdcSrc
, pBitBlt
->xSrc
, pBitBlt
->ySrc
, pBitBlt
->dwRop
);
1825 SelectObject(hdcSrc
, hBmpOld
);
1832 case EMR_STRETCHBLT
:
1834 const EMRSTRETCHBLT
*pStretchBlt
= (const EMRSTRETCHBLT
*)mr
;
1836 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1837 pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1838 pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1839 pStretchBlt
->dwRop
, pStretchBlt
->offBitsSrc
);
1841 if(pStretchBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1842 PatBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1843 pStretchBlt
->dwRop
);
1844 } else { /* StretchBlt */
1845 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1846 HBRUSH hBrush
, hBrushOld
;
1847 HBITMAP hBmp
= 0, hBmpOld
= 0;
1848 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchBlt
->offBmiSrc
);
1850 SetWorldTransform(hdcSrc
, &pStretchBlt
->xformSrc
);
1852 hBrush
= CreateSolidBrush(pStretchBlt
->crBkColorSrc
);
1853 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1854 PatBlt(hdcSrc
, pStretchBlt
->rclBounds
.left
, pStretchBlt
->rclBounds
.top
,
1855 pStretchBlt
->rclBounds
.right
- pStretchBlt
->rclBounds
.left
,
1856 pStretchBlt
->rclBounds
.bottom
- pStretchBlt
->rclBounds
.top
, PATCOPY
);
1857 SelectObject(hdcSrc
, hBrushOld
);
1858 DeleteObject(hBrush
);
1860 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1861 (const BYTE
*)mr
+ pStretchBlt
->offBitsSrc
, pbi
, pStretchBlt
->iUsageSrc
);
1862 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1864 StretchBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1865 hdcSrc
, pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1866 pStretchBlt
->dwRop
);
1868 SelectObject(hdcSrc
, hBmpOld
);
1875 case EMR_ALPHABLEND
:
1877 const EMRALPHABLEND
*pAlphaBlend
= (const EMRALPHABLEND
*)mr
;
1879 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1880 pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1881 pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1882 pAlphaBlend
->dwRop
, pAlphaBlend
->offBitsSrc
);
1884 if(pAlphaBlend
->offBmiSrc
== 0) {
1885 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1887 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1888 HBITMAP hBmp
= 0, hBmpOld
= 0;
1889 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pAlphaBlend
->offBmiSrc
);
1890 BLENDFUNCTION blendfn
;
1893 SetWorldTransform(hdcSrc
, &pAlphaBlend
->xformSrc
);
1895 hBmp
= CreateDIBSection(hdc
, pbi
, pAlphaBlend
->iUsageSrc
, &bits
, NULL
, 0);
1896 memcpy(bits
, (const BYTE
*)mr
+ pAlphaBlend
->offBitsSrc
, pAlphaBlend
->cbBitsSrc
);
1897 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1899 blendfn
.BlendOp
= (pAlphaBlend
->dwRop
>> 24) & 0xff;
1900 blendfn
.BlendFlags
= (pAlphaBlend
->dwRop
>> 16) & 0xff;
1901 blendfn
.SourceConstantAlpha
= (pAlphaBlend
->dwRop
>> 8) & 0xff;
1902 blendfn
.AlphaFormat
= (pAlphaBlend
->dwRop
) & 0xff;
1904 GdiAlphaBlend(hdc
, pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1905 hdcSrc
, pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1908 SelectObject(hdcSrc
, hBmpOld
);
1917 const EMRMASKBLT
*pMaskBlt
= (const EMRMASKBLT
*)mr
;
1918 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1919 HBRUSH hBrush
, hBrushOld
;
1920 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1921 const BITMAPINFO
*pbi
;
1923 SetWorldTransform(hdcSrc
, &pMaskBlt
->xformSrc
);
1925 hBrush
= CreateSolidBrush(pMaskBlt
->crBkColorSrc
);
1926 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1927 PatBlt(hdcSrc
, pMaskBlt
->rclBounds
.left
, pMaskBlt
->rclBounds
.top
,
1928 pMaskBlt
->rclBounds
.right
- pMaskBlt
->rclBounds
.left
,
1929 pMaskBlt
->rclBounds
.bottom
- pMaskBlt
->rclBounds
.top
, PATCOPY
);
1930 SelectObject(hdcSrc
, hBrushOld
);
1931 DeleteObject(hBrush
);
1933 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiMask
);
1934 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
1936 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
1937 (const BYTE
*)mr
+ pMaskBlt
->offBitsMask
, pbi
, pMaskBlt
->iUsageMask
);
1939 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiSrc
);
1940 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1941 (const BYTE
*)mr
+ pMaskBlt
->offBitsSrc
, pbi
, pMaskBlt
->iUsageSrc
);
1942 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1955 SelectObject(hdcSrc
, hBmpOld
);
1957 DeleteObject(hBmpMask
);
1964 const EMRPLGBLT
*pPlgBlt
= (const EMRPLGBLT
*)mr
;
1965 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1966 HBRUSH hBrush
, hBrushOld
;
1967 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1968 const BITMAPINFO
*pbi
;
1971 SetWorldTransform(hdcSrc
, &pPlgBlt
->xformSrc
);
1973 pts
[0].x
= pPlgBlt
->aptlDest
[0].x
; pts
[0].y
= pPlgBlt
->aptlDest
[0].y
;
1974 pts
[1].x
= pPlgBlt
->aptlDest
[1].x
; pts
[1].y
= pPlgBlt
->aptlDest
[1].y
;
1975 pts
[2].x
= pPlgBlt
->aptlDest
[2].x
; pts
[2].y
= pPlgBlt
->aptlDest
[2].y
;
1977 hBrush
= CreateSolidBrush(pPlgBlt
->crBkColorSrc
);
1978 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1979 PatBlt(hdcSrc
, pPlgBlt
->rclBounds
.left
, pPlgBlt
->rclBounds
.top
,
1980 pPlgBlt
->rclBounds
.right
- pPlgBlt
->rclBounds
.left
,
1981 pPlgBlt
->rclBounds
.bottom
- pPlgBlt
->rclBounds
.top
, PATCOPY
);
1982 SelectObject(hdcSrc
, hBrushOld
);
1983 DeleteObject(hBrush
);
1985 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiMask
);
1986 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
1988 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
1989 (const BYTE
*)mr
+ pPlgBlt
->offBitsMask
, pbi
, pPlgBlt
->iUsageMask
);
1991 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiSrc
);
1992 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1993 (const BYTE
*)mr
+ pPlgBlt
->offBitsSrc
, pbi
, pPlgBlt
->iUsageSrc
);
1994 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2005 SelectObject(hdcSrc
, hBmpOld
);
2007 DeleteObject(hBmpMask
);
2012 case EMR_SETDIBITSTODEVICE
:
2014 const EMRSETDIBITSTODEVICE
*pSetDIBitsToDevice
= (const EMRSETDIBITSTODEVICE
*)mr
;
2016 SetDIBitsToDevice(hdc
,
2017 pSetDIBitsToDevice
->xDest
,
2018 pSetDIBitsToDevice
->yDest
,
2019 pSetDIBitsToDevice
->cxSrc
,
2020 pSetDIBitsToDevice
->cySrc
,
2021 pSetDIBitsToDevice
->xSrc
,
2022 pSetDIBitsToDevice
->ySrc
,
2023 pSetDIBitsToDevice
->iStartScan
,
2024 pSetDIBitsToDevice
->cScans
,
2025 (const BYTE
*)mr
+ pSetDIBitsToDevice
->offBitsSrc
,
2026 (const BITMAPINFO
*)((const BYTE
*)mr
+ pSetDIBitsToDevice
->offBmiSrc
),
2027 pSetDIBitsToDevice
->iUsageSrc
);
2031 case EMR_POLYTEXTOUTA
:
2033 const EMRPOLYTEXTOUTA
*pPolyTextOutA
= (const EMRPOLYTEXTOUTA
*)mr
;
2034 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
2036 XFORM xform
, xformOld
;
2039 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
2040 GetWorldTransform(hdc
, &xformOld
);
2042 xform
.eM11
= pPolyTextOutA
->exScale
;
2045 xform
.eM22
= pPolyTextOutA
->eyScale
;
2048 SetWorldTransform(hdc
, &xform
);
2050 /* Set up POLYTEXTA structures */
2051 for(i
= 0; i
< pPolyTextOutA
->cStrings
; i
++)
2053 polytextA
[i
].x
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.x
;
2054 polytextA
[i
].y
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.y
;
2055 polytextA
[i
].n
= pPolyTextOutA
->aemrtext
[i
].nChars
;
2056 polytextA
[i
].lpstr
= (LPCSTR
)((const BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offString
);
2057 polytextA
[i
].uiFlags
= pPolyTextOutA
->aemrtext
[i
].fOptions
;
2058 polytextA
[i
].rcl
.left
= pPolyTextOutA
->aemrtext
[i
].rcl
.left
;
2059 polytextA
[i
].rcl
.right
= pPolyTextOutA
->aemrtext
[i
].rcl
.right
;
2060 polytextA
[i
].rcl
.top
= pPolyTextOutA
->aemrtext
[i
].rcl
.top
;
2061 polytextA
[i
].rcl
.bottom
= pPolyTextOutA
->aemrtext
[i
].rcl
.bottom
;
2062 polytextA
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offDx
);
2064 PolyTextOutA(hdc
, polytextA
, pPolyTextOutA
->cStrings
);
2065 HeapFree(GetProcessHeap(), 0, polytextA
);
2067 SetWorldTransform(hdc
, &xformOld
);
2068 SetGraphicsMode(hdc
, gModeOld
);
2072 case EMR_POLYTEXTOUTW
:
2074 const EMRPOLYTEXTOUTW
*pPolyTextOutW
= (const EMRPOLYTEXTOUTW
*)mr
;
2075 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
2077 XFORM xform
, xformOld
;
2080 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
2081 GetWorldTransform(hdc
, &xformOld
);
2083 xform
.eM11
= pPolyTextOutW
->exScale
;
2086 xform
.eM22
= pPolyTextOutW
->eyScale
;
2089 SetWorldTransform(hdc
, &xform
);
2091 /* Set up POLYTEXTW structures */
2092 for(i
= 0; i
< pPolyTextOutW
->cStrings
; i
++)
2094 polytextW
[i
].x
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.x
;
2095 polytextW
[i
].y
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.y
;
2096 polytextW
[i
].n
= pPolyTextOutW
->aemrtext
[i
].nChars
;
2097 polytextW
[i
].lpstr
= (LPCWSTR
)((const BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offString
);
2098 polytextW
[i
].uiFlags
= pPolyTextOutW
->aemrtext
[i
].fOptions
;
2099 polytextW
[i
].rcl
.left
= pPolyTextOutW
->aemrtext
[i
].rcl
.left
;
2100 polytextW
[i
].rcl
.right
= pPolyTextOutW
->aemrtext
[i
].rcl
.right
;
2101 polytextW
[i
].rcl
.top
= pPolyTextOutW
->aemrtext
[i
].rcl
.top
;
2102 polytextW
[i
].rcl
.bottom
= pPolyTextOutW
->aemrtext
[i
].rcl
.bottom
;
2103 polytextW
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offDx
);
2105 PolyTextOutW(hdc
, polytextW
, pPolyTextOutW
->cStrings
);
2106 HeapFree(GetProcessHeap(), 0, polytextW
);
2108 SetWorldTransform(hdc
, &xformOld
);
2109 SetGraphicsMode(hdc
, gModeOld
);
2115 const EMRFILLRGN
*pFillRgn
= (const EMRFILLRGN
*)mr
;
2116 HRGN hRgn
= ExtCreateRegion(NULL
, pFillRgn
->cbRgnData
, (const RGNDATA
*)pFillRgn
->RgnData
);
2119 (handletable
->objectHandle
)[pFillRgn
->ihBrush
]);
2126 const EMRFRAMERGN
*pFrameRgn
= (const EMRFRAMERGN
*)mr
;
2127 HRGN hRgn
= ExtCreateRegion(NULL
, pFrameRgn
->cbRgnData
, (const RGNDATA
*)pFrameRgn
->RgnData
);
2130 (handletable
->objectHandle
)[pFrameRgn
->ihBrush
],
2131 pFrameRgn
->szlStroke
.cx
,
2132 pFrameRgn
->szlStroke
.cy
);
2139 const EMRINVERTRGN
*pInvertRgn
= (const EMRINVERTRGN
*)mr
;
2140 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (const RGNDATA
*)pInvertRgn
->RgnData
);
2141 InvertRgn(hdc
, hRgn
);
2148 const EMRPAINTRGN
*pPaintRgn
= (const EMRPAINTRGN
*)mr
;
2149 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (const RGNDATA
*)pPaintRgn
->RgnData
);
2150 PaintRgn(hdc
, hRgn
);
2155 case EMR_SETTEXTJUSTIFICATION
:
2157 const EMRSETTEXTJUSTIFICATION
*pSetTextJust
= (const EMRSETTEXTJUSTIFICATION
*)mr
;
2158 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
2164 const EMRSETLAYOUT
*pSetLayout
= (const EMRSETLAYOUT
*)mr
;
2165 SetLayout(hdc
, pSetLayout
->iMode
);
2169 case EMR_POLYDRAW16
:
2171 case EMR_GLSBOUNDEDRECORD
:
2172 case EMR_DRAWESCAPE
:
2175 case EMR_SMALLTEXTOUT
:
2176 case EMR_FORCEUFIMAPPING
:
2177 case EMR_NAMEDESCAPE
:
2178 case EMR_COLORCORRECTPALETTE
:
2179 case EMR_SETICMPROFILEA
:
2180 case EMR_SETICMPROFILEW
:
2181 case EMR_TRANSPARENTBLT
:
2182 case EMR_GRADIENTFILL
:
2183 case EMR_SETLINKEDUFI
:
2184 case EMR_COLORMATCHTOTARGETW
:
2185 case EMR_CREATECOLORSPACEW
:
2188 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2189 record then ignore and return TRUE. */
2190 FIXME("type %d is unimplemented\n", type
);
2193 tmprc
.left
= tmprc
.top
= 0;
2194 tmprc
.right
= tmprc
.bottom
= 1000;
2195 LPtoDP(hdc
, (POINT
*)&tmprc
, 2);
2196 TRACE("L:0,0 - 1000,1000 -> D:%d,%d - %d,%d\n", tmprc
.left
,
2197 tmprc
.top
, tmprc
.right
, tmprc
.bottom
);
2203 /*****************************************************************************
2205 * EnumEnhMetaFile (GDI32.@)
2207 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2209 * record. Returns when either every record has been used or
2210 * when _EnhMetaFunc_ returns FALSE.
2214 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2221 * This function behaves differently in Win9x and WinNT.
2223 * In WinNT, the DC's world transform is updated as the EMF changes
2224 * the Window/Viewport Extent and Origin or it's world transform.
2225 * The actual Window/Viewport Extent and Origin are left untouched.
2227 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2228 * updates the scaling itself but only just before a record that
2229 * writes anything to the DC.
2231 * I'm not sure where the data (enum_emh_data) is stored in either
2232 * version. For this implementation, it is stored before the handle
2233 * table, but it could be stored in the DC, in the EMF handle or in
2237 BOOL WINAPI
EnumEnhMetaFile(
2238 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
2239 HENHMETAFILE hmf
, /* [in] EMF to walk */
2240 ENHMFENUMPROC callback
, /* [in] callback function */
2241 LPVOID data
, /* [in] optional data for callback function */
2242 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
2254 HBRUSH hBrush
= NULL
;
2257 enum_emh_data
*info
;
2258 SIZE vp_size
, win_size
;
2259 POINT vp_org
, win_org
;
2260 INT mapMode
= MM_TEXT
, old_align
= 0, old_rop2
= 0, old_arcdir
= 0, old_polyfill
= 0, old_stretchblt
= 0;
2261 COLORREF old_text_color
= 0, old_bk_color
= 0;
2265 SetLastError(ERROR_INVALID_PARAMETER
);
2269 emh
= EMF_GetEnhMetaHeader(hmf
);
2271 SetLastError(ERROR_INVALID_HANDLE
);
2275 info
= HeapAlloc( GetProcessHeap(), 0,
2276 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2279 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2282 info
->state
.wndOrgX
= 0;
2283 info
->state
.wndOrgY
= 0;
2284 info
->state
.wndExtX
= 1;
2285 info
->state
.wndExtY
= 1;
2286 info
->state
.vportOrgX
= 0;
2287 info
->state
.vportOrgY
= 0;
2288 info
->state
.vportExtX
= 1;
2289 info
->state
.vportExtY
= 1;
2290 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
2291 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
2292 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
2294 info
->state
.next
= NULL
;
2295 info
->save_level
= 0;
2296 info
->saved_state
= NULL
;
2298 ht
= (HANDLETABLE
*) &info
[1];
2299 ht
->objectHandle
[0] = hmf
;
2300 for(i
= 1; i
< emh
->nHandles
; i
++)
2301 ht
->objectHandle
[i
] = NULL
;
2305 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
2306 GetWorldTransform(hdc
, &savedXform
);
2307 GetViewportExtEx(hdc
, &vp_size
);
2308 GetWindowExtEx(hdc
, &win_size
);
2309 GetViewportOrgEx(hdc
, &vp_org
);
2310 GetWindowOrgEx(hdc
, &win_org
);
2311 mapMode
= GetMapMode(hdc
);
2314 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
2315 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
2316 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
2318 hRgn
= CreateRectRgn(0, 0, 0, 0);
2319 if (!GetClipRgn(hdc
, hRgn
))
2325 old_text_color
= SetTextColor(hdc
, RGB(0,0,0));
2326 old_bk_color
= SetBkColor(hdc
, RGB(0xff, 0xff, 0xff));
2327 old_align
= SetTextAlign(hdc
, 0);
2328 old_rop2
= SetROP2(hdc
, R2_COPYPEN
);
2329 old_arcdir
= SetArcDirection(hdc
, AD_COUNTERCLOCKWISE
);
2330 old_polyfill
= SetPolyFillMode(hdc
, ALTERNATE
);
2331 old_stretchblt
= SetStretchBltMode(hdc
, BLACKONWHITE
);
2334 info
->state
.mode
= MM_TEXT
;
2338 /* Win95 leaves the vp/win ext/org info alone */
2339 info
->init_transform
.eM11
= 1.0;
2340 info
->init_transform
.eM12
= 0.0;
2341 info
->init_transform
.eM21
= 0.0;
2342 info
->init_transform
.eM22
= 1.0;
2343 info
->init_transform
.eDx
= 0.0;
2344 info
->init_transform
.eDy
= 0.0;
2348 /* WinNT combines the vp/win ext/org info into a transform */
2349 double xscale
, yscale
;
2350 xscale
= (double)vp_size
.cx
/ (double)win_size
.cx
;
2351 yscale
= (double)vp_size
.cy
/ (double)win_size
.cy
;
2352 info
->init_transform
.eM11
= xscale
;
2353 info
->init_transform
.eM12
= 0.0;
2354 info
->init_transform
.eM21
= 0.0;
2355 info
->init_transform
.eM22
= yscale
;
2356 info
->init_transform
.eDx
= (double)vp_org
.x
- xscale
* (double)win_org
.x
;
2357 info
->init_transform
.eDy
= (double)vp_org
.y
- yscale
* (double)win_org
.y
;
2359 CombineTransform(&info
->init_transform
, &savedXform
, &info
->init_transform
);
2362 if ( lpRect
&& WIDTH(emh
->rclFrame
) && HEIGHT(emh
->rclFrame
) )
2364 double xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
2367 TRACE("rect: %d,%d - %d,%d. rclFrame: %d,%d - %d,%d\n",
2368 lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
,
2369 emh
->rclFrame
.left
, emh
->rclFrame
.top
, emh
->rclFrame
.right
,
2370 emh
->rclFrame
.bottom
);
2372 xSrcPixSize
= (double) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
2373 ySrcPixSize
= (double) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
2374 xscale
= (double) WIDTH(*lpRect
) * 100.0 /
2375 WIDTH(emh
->rclFrame
) * xSrcPixSize
;
2376 yscale
= (double) HEIGHT(*lpRect
) * 100.0 /
2377 HEIGHT(emh
->rclFrame
) * ySrcPixSize
;
2378 TRACE("xscale = %f, yscale = %f\n", xscale
, yscale
);
2380 xform
.eM11
= xscale
;
2383 xform
.eM22
= yscale
;
2384 xform
.eDx
= (double) lpRect
->left
- (double) WIDTH(*lpRect
) / WIDTH(emh
->rclFrame
) * emh
->rclFrame
.left
;
2385 xform
.eDy
= (double) lpRect
->top
- (double) HEIGHT(*lpRect
) / HEIGHT(emh
->rclFrame
) * emh
->rclFrame
.top
;
2387 CombineTransform(&info
->init_transform
, &xform
, &info
->init_transform
);
2390 /* WinNT resets the current vp/win org/ext */
2391 if ( !IS_WIN9X() && hdc
)
2393 SetMapMode(hdc
, MM_TEXT
);
2394 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2395 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2396 EMF_Update_MF_Xform(hdc
, info
);
2401 while(ret
&& offset
< emh
->nBytes
)
2403 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
2405 /* In Win9x mode we update the xform if the record will produce output */
2406 if (hdc
&& IS_WIN9X() && emr_produces_output(emr
->iType
))
2407 EMF_Update_MF_Xform(hdc
, info
);
2409 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr
->iType
), emr
->nSize
);
2410 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nHandles
, (LPARAM
)data
);
2411 offset
+= emr
->nSize
;
2413 /* WinNT - update the transform (win9x updates when the next graphics
2414 output record is played). */
2415 if (hdc
&& !IS_WIN9X())
2416 EMF_Update_MF_Xform(hdc
, info
);
2421 SetStretchBltMode(hdc
, old_stretchblt
);
2422 SetPolyFillMode(hdc
, old_polyfill
);
2423 SetArcDirection(hdc
, old_arcdir
);
2424 SetROP2(hdc
, old_rop2
);
2425 SetTextAlign(hdc
, old_align
);
2426 SetBkColor(hdc
, old_bk_color
);
2427 SetTextColor(hdc
, old_text_color
);
2430 SelectObject(hdc
, hBrush
);
2431 SelectObject(hdc
, hPen
);
2432 SelectObject(hdc
, hFont
);
2433 ExtSelectClipRgn(hdc
, hRgn
, RGN_COPY
);
2436 SetWorldTransform(hdc
, &savedXform
);
2438 SetGraphicsMode(hdc
, savedMode
);
2439 SetMapMode(hdc
, mapMode
);
2440 SetWindowOrgEx(hdc
, win_org
.x
, win_org
.y
, NULL
);
2441 SetWindowExtEx(hdc
, win_size
.cx
, win_size
.cy
, NULL
);
2442 SetViewportOrgEx(hdc
, vp_org
.x
, vp_org
.y
, NULL
);
2443 SetViewportExtEx(hdc
, vp_size
.cx
, vp_size
.cy
, NULL
);
2446 for(i
= 1; i
< emh
->nHandles
; i
++) /* Don't delete element 0 (hmf) */
2447 if( (ht
->objectHandle
)[i
] )
2448 DeleteObject( (ht
->objectHandle
)[i
] );
2450 while (info
->saved_state
)
2452 EMF_dc_state
*state
= info
->saved_state
;
2453 info
->saved_state
= info
->saved_state
->next
;
2454 HeapFree( GetProcessHeap(), 0, state
);
2456 HeapFree( GetProcessHeap(), 0, info
);
2460 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
2461 const ENHMETARECORD
*emr
,
2462 INT handles
, LPARAM data
)
2464 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
2467 /**************************************************************************
2468 * PlayEnhMetaFile (GDI32.@)
2470 * Renders an enhanced metafile into a specified rectangle *lpRect
2471 * in device context hdc.
2477 BOOL WINAPI
PlayEnhMetaFile(
2478 HDC hdc
, /* [in] DC to render into */
2479 HENHMETAFILE hmf
, /* [in] metafile to render */
2480 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
2483 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
2487 /*****************************************************************************
2488 * DeleteEnhMetaFile (GDI32.@)
2490 * Deletes an enhanced metafile and frees the associated storage.
2492 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
2494 return EMF_Delete_HENHMETAFILE( hmf
);
2497 /*****************************************************************************
2498 * CopyEnhMetaFileA (GDI32.@)
2500 * Duplicate an enhanced metafile.
2504 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
2505 HENHMETAFILE hmfSrc
,
2508 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2509 HENHMETAFILE hmfDst
;
2511 if(!emrSrc
) return FALSE
;
2513 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2514 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2515 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, FALSE
);
2517 HeapFree( GetProcessHeap(), 0, emrDst
);
2521 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2522 NULL
, CREATE_ALWAYS
, 0, 0);
2523 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2524 CloseHandle( hFile
);
2525 /* Reopen file for reading only, so that apps can share
2526 read access to the file while hmf is still valid */
2527 hFile
= CreateFileA( file
, GENERIC_READ
, FILE_SHARE_READ
,
2528 NULL
, OPEN_EXISTING
, 0, 0);
2529 if(hFile
== INVALID_HANDLE_VALUE
) {
2530 ERR("Can't reopen emf for reading\n");
2533 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2534 CloseHandle( hFile
);
2539 /*****************************************************************************
2540 * CopyEnhMetaFileW (GDI32.@)
2542 * See CopyEnhMetaFileA.
2546 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2547 HENHMETAFILE hmfSrc
,
2550 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2551 HENHMETAFILE hmfDst
;
2553 if(!emrSrc
) return FALSE
;
2555 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2556 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2557 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, FALSE
);
2559 HeapFree( GetProcessHeap(), 0, emrDst
);
2563 hFile
= CreateFileW( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2564 NULL
, CREATE_ALWAYS
, 0, 0);
2565 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2566 CloseHandle( hFile
);
2567 /* Reopen file for reading only, so that apps can share
2568 read access to the file while hmf is still valid */
2569 hFile
= CreateFileW( file
, GENERIC_READ
, FILE_SHARE_READ
,
2570 NULL
, OPEN_EXISTING
, 0, 0);
2571 if(hFile
== INVALID_HANDLE_VALUE
) {
2572 ERR("Can't reopen emf for reading\n");
2575 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2576 CloseHandle( hFile
);
2582 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2583 typedef struct tagEMF_PaletteCopy
2586 LPPALETTEENTRY lpPe
;
2589 /***************************************************************
2590 * Find the EMR_EOF record and then use it to find the
2591 * palette entries for this enhanced metafile.
2592 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2593 * which contains the max number of elements to copy and where
2596 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2598 static INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2600 const ENHMETARECORD
*lpEMR
,
2605 if ( lpEMR
->iType
== EMR_EOF
)
2607 const EMREOF
*lpEof
= (const EMREOF
*)lpEMR
;
2608 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
2609 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
2611 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy
);
2613 memcpy( info
->lpPe
, (LPCSTR
)lpEof
+ lpEof
->offPalEntries
,
2614 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
2616 /* Update the passed data as a return code */
2617 info
->lpPe
= NULL
; /* Palettes were copied! */
2618 info
->cEntries
= dwNumPalToCopy
;
2620 return FALSE
; /* That's all we need */
2626 /*****************************************************************************
2627 * GetEnhMetaFilePaletteEntries (GDI32.@)
2629 * Copy the palette and report size
2631 * BUGS: Error codes (SetLastError) are not set on failures
2633 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
2635 LPPALETTEENTRY lpPe
)
2637 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
2638 EMF_PaletteCopy infoForCallBack
;
2640 TRACE( "(%p,%d,%p)\n", hEmf
, cEntries
, lpPe
);
2642 if (!enhHeader
) return 0;
2644 /* First check if there are any palettes associated with
2646 if ( enhHeader
->nPalEntries
== 0 ) return 0;
2648 /* Is the user requesting the number of palettes? */
2649 if ( lpPe
== NULL
) return enhHeader
->nPalEntries
;
2651 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2652 infoForCallBack
.cEntries
= cEntries
;
2653 infoForCallBack
.lpPe
= lpPe
;
2655 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
2656 &infoForCallBack
, 0 ) )
2659 /* Verify that the callback executed correctly */
2660 if ( infoForCallBack
.lpPe
!= NULL
)
2662 /* Callback proc had error! */
2663 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2667 return infoForCallBack
.cEntries
;
2670 typedef struct gdi_mf_comment
2677 DWORD cbWinMetaFile
;
2680 /******************************************************************
2681 * SetWinMetaFileBits (GDI32.@)
2683 * Translate from old style to new style.
2686 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
,
2687 CONST BYTE
*lpbBuffer
,
2689 CONST METAFILEPICT
*lpmfp
2692 static const WCHAR szDisplayW
[] = { 'D','I','S','P','L','A','Y','\0' };
2693 HMETAFILE hmf
= NULL
;
2694 HENHMETAFILE ret
= NULL
;
2695 HDC hdc
= NULL
, hdcdisp
= NULL
;
2696 RECT rc
, *prcFrame
= NULL
;
2697 LONG mm
, xExt
, yExt
;
2698 INT horzsize
, vertsize
, horzres
, vertres
;
2700 TRACE("(%d, %p, %p, %p)\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
2702 hmf
= SetMetaFileBitsEx(cbBuffer
, lpbBuffer
);
2705 WARN("SetMetaFileBitsEx failed\n");
2710 hdcRef
= hdcdisp
= CreateDCW(szDisplayW
, NULL
, NULL
, NULL
);
2714 TRACE("mm = %d %dx%d\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2722 TRACE("lpmfp == NULL\n");
2724 /* Use the whole device surface */
2725 mm
= MM_ANISOTROPIC
;
2730 if (mm
== MM_ISOTROPIC
|| mm
== MM_ANISOTROPIC
)
2732 if (xExt
< 0 || yExt
< 0)
2734 /* Use the whole device surface */
2739 /* Use the x and y extents as the frame box */
2742 rc
.left
= rc
.top
= 0;
2749 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
)))
2751 ERR("CreateEnhMetaFile failed\n");
2756 * Write the original METAFILE into the enhanced metafile.
2757 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2761 gdi_mf_comment
*mfcomment
;
2762 UINT mfcomment_size
;
2764 mfcomment_size
= sizeof (gdi_mf_comment
) + cbBuffer
;
2765 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
2768 mfcomment
->ident
= GDICOMMENT_IDENTIFIER
;
2769 mfcomment
->iComment
= GDICOMMENT_WINDOWS_METAFILE
;
2770 mfcomment
->nVersion
= 0x00000300;
2771 mfcomment
->nChecksum
= 0; /* FIXME */
2772 mfcomment
->fFlags
= 0;
2773 mfcomment
->cbWinMetaFile
= cbBuffer
;
2774 memcpy(&mfcomment
[1], lpbBuffer
, cbBuffer
);
2775 GdiComment(hdc
, mfcomment_size
, (BYTE
*) mfcomment
);
2776 HeapFree(GetProcessHeap(), 0, mfcomment
);
2778 SetMapMode(hdc
, mm
);
2782 horzsize
= GetDeviceCaps(hdcRef
, HORZSIZE
);
2783 vertsize
= GetDeviceCaps(hdcRef
, VERTSIZE
);
2784 horzres
= GetDeviceCaps(hdcRef
, HORZRES
);
2785 vertres
= GetDeviceCaps(hdcRef
, VERTRES
);
2789 /* Use the whole device surface */
2795 xExt
= MulDiv(xExt
, horzres
, 100 * horzsize
);
2796 yExt
= MulDiv(yExt
, vertres
, 100 * vertsize
);
2799 /* set the initial viewport:window ratio as 1:1 */
2800 SetViewportExtEx(hdc
, xExt
, yExt
, NULL
);
2801 SetWindowExtEx(hdc
, xExt
, yExt
, NULL
);
2803 PlayMetaFile(hdc
, hmf
);
2805 ret
= CloseEnhMetaFile(hdc
);
2807 if (hdcdisp
) DeleteDC(hdcdisp
);
2808 DeleteMetaFile(hmf
);