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
)
252 HENHMETAFILE hmf
= 0;
253 ENHMETAFILEOBJ
*metaObj
;
255 if (emh
->iType
!= EMR_HEADER
|| emh
->dSignature
!= ENHMETA_SIGNATURE
||
256 (emh
->nBytes
& 3)) /* refuse to load unaligned EMF as Windows does */
258 WARN("Invalid emf header type 0x%08x sig 0x%08x.\n",
259 emh
->iType
, emh
->dSignature
);
260 SetLastError(ERROR_INVALID_DATA
);
264 metaObj
= GDI_AllocObject( sizeof(ENHMETAFILEOBJ
),
266 (HGDIOBJ
*)&hmf
, NULL
);
270 metaObj
->on_disk
= on_disk
;
271 GDI_ReleaseObj( hmf
);
276 /****************************************************************************
277 * EMF_Delete_HENHMETAFILE
279 static BOOL
EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf
)
281 ENHMETAFILEOBJ
*metaObj
= GDI_GetObjPtr( hmf
, ENHMETAFILE_MAGIC
);
283 if(!metaObj
) return FALSE
;
286 UnmapViewOfFile( metaObj
->emh
);
288 HeapFree( GetProcessHeap(), 0, metaObj
->emh
);
289 return GDI_FreeObject( hmf
, metaObj
);
292 /******************************************************************
293 * EMF_GetEnhMetaHeader
295 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
297 static ENHMETAHEADER
*EMF_GetEnhMetaHeader( HENHMETAFILE hmf
)
299 ENHMETAHEADER
*ret
= NULL
;
300 ENHMETAFILEOBJ
*metaObj
= GDI_GetObjPtr( hmf
, ENHMETAFILE_MAGIC
);
301 TRACE("hmf %p -> enhmetaObj %p\n", hmf
, metaObj
);
305 GDI_ReleaseObj( hmf
);
310 /*****************************************************************************
314 static HENHMETAFILE
EMF_GetEnhMetaFile( HANDLE hFile
)
320 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
321 emh
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, 0 );
322 CloseHandle( hMapping
);
326 hemf
= EMF_Create_HENHMETAFILE( emh
, TRUE
);
328 UnmapViewOfFile( emh
);
333 /*****************************************************************************
334 * GetEnhMetaFileA (GDI32.@)
338 HENHMETAFILE WINAPI
GetEnhMetaFileA(
339 LPCSTR lpszMetaFile
/* [in] filename of enhanced metafile */
345 hFile
= CreateFileA(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
346 OPEN_EXISTING
, 0, 0);
347 if (hFile
== INVALID_HANDLE_VALUE
) {
348 WARN("could not open %s\n", lpszMetaFile
);
351 hmf
= EMF_GetEnhMetaFile( hFile
);
352 CloseHandle( hFile
);
356 /*****************************************************************************
357 * GetEnhMetaFileW (GDI32.@)
359 HENHMETAFILE WINAPI
GetEnhMetaFileW(
360 LPCWSTR lpszMetaFile
) /* [in] filename of enhanced metafile */
365 hFile
= CreateFileW(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
366 OPEN_EXISTING
, 0, 0);
367 if (hFile
== INVALID_HANDLE_VALUE
) {
368 WARN("could not open %s\n", debugstr_w(lpszMetaFile
));
371 hmf
= EMF_GetEnhMetaFile( hFile
);
372 CloseHandle( hFile
);
376 /*****************************************************************************
377 * GetEnhMetaFileHeader (GDI32.@)
379 * Retrieves the record containing the header for the specified
380 * enhanced-format metafile.
383 * If buf is NULL, returns the size of buffer required.
384 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
387 UINT WINAPI
GetEnhMetaFileHeader(
388 HENHMETAFILE hmf
, /* [in] enhanced metafile */
389 UINT bufsize
, /* [in] size of buffer */
390 LPENHMETAHEADER buf
/* [out] buffer */
396 emh
= EMF_GetEnhMetaHeader(hmf
);
397 if(!emh
) return FALSE
;
399 if (!buf
) return size
;
400 size
= min(size
, bufsize
);
401 memmove(buf
, emh
, size
);
406 /*****************************************************************************
407 * GetEnhMetaFileDescriptionA (GDI32.@)
409 * See GetEnhMetaFileDescriptionW.
411 UINT WINAPI
GetEnhMetaFileDescriptionA(
412 HENHMETAFILE hmf
, /* [in] enhanced metafile */
413 UINT size
, /* [in] size of buf */
414 LPSTR buf
/* [out] buffer to receive description */
417 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
421 if(!emh
) return FALSE
;
422 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
423 descrW
= (WCHAR
*) ((char *) emh
+ emh
->offDescription
);
424 len
= WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, NULL
, 0, NULL
, NULL
);
426 if (!buf
|| !size
) return len
;
428 len
= min( size
, len
);
429 WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, buf
, len
, NULL
, NULL
);
433 /*****************************************************************************
434 * GetEnhMetaFileDescriptionW (GDI32.@)
436 * Copies the description string of an enhanced metafile into a buffer
440 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
441 * number of characters copied.
443 UINT WINAPI
GetEnhMetaFileDescriptionW(
444 HENHMETAFILE hmf
, /* [in] enhanced metafile */
445 UINT size
, /* [in] size of buf */
446 LPWSTR buf
/* [out] buffer to receive description */
449 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
451 if(!emh
) return FALSE
;
452 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
453 if (!buf
|| !size
) return emh
->nDescription
;
455 memmove(buf
, (char *) emh
+ emh
->offDescription
, min(size
,emh
->nDescription
)*sizeof(WCHAR
));
456 return min(size
, emh
->nDescription
);
459 /****************************************************************************
460 * SetEnhMetaFileBits (GDI32.@)
462 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
464 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
466 ENHMETAHEADER
*emh
= HeapAlloc( GetProcessHeap(), 0, bufsize
);
467 memmove(emh
, buf
, bufsize
);
468 return EMF_Create_HENHMETAFILE( emh
, FALSE
);
471 /*****************************************************************************
472 * GetEnhMetaFileBits (GDI32.@)
475 UINT WINAPI
GetEnhMetaFileBits(
481 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
487 if( buf
== NULL
) return size
;
489 size
= min( size
, bufsize
);
490 memmove(buf
, emh
, size
);
494 typedef struct EMF_dc_state
497 XFORM world_transform
;
506 struct EMF_dc_state
*next
;
509 typedef struct enum_emh_data
511 XFORM init_transform
;
514 EMF_dc_state
*saved_state
;
517 #define ENUM_GET_PRIVATE_DATA(ht) \
518 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
520 #define WIDTH(rect) ( (rect).right - (rect).left )
521 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
523 #define IS_WIN9X() (GetVersion()&0x80000000)
525 static void EMF_Update_MF_Xform(HDC hdc
, const enum_emh_data
*info
)
527 XFORM mapping_mode_trans
, final_trans
;
528 double scaleX
, scaleY
;
530 scaleX
= (double)info
->state
.vportExtX
/ (double)info
->state
.wndExtX
;
531 scaleY
= (double)info
->state
.vportExtY
/ (double)info
->state
.wndExtY
;
532 mapping_mode_trans
.eM11
= scaleX
;
533 mapping_mode_trans
.eM12
= 0.0;
534 mapping_mode_trans
.eM21
= 0.0;
535 mapping_mode_trans
.eM22
= scaleY
;
536 mapping_mode_trans
.eDx
= (double)info
->state
.vportOrgX
- scaleX
* (double)info
->state
.wndOrgX
;
537 mapping_mode_trans
.eDy
= (double)info
->state
.vportOrgY
- scaleY
* (double)info
->state
.wndOrgY
;
539 CombineTransform(&final_trans
, &info
->state
.world_transform
, &mapping_mode_trans
);
540 CombineTransform(&final_trans
, &final_trans
, &info
->init_transform
);
542 if (!SetWorldTransform(hdc
, &final_trans
))
544 ERR("World transform failed!\n");
548 static void EMF_RestoreDC( enum_emh_data
*info
, INT level
)
550 if (abs(level
) > info
->save_level
|| level
== 0) return;
552 if (level
< 0) level
= info
->save_level
+ level
+ 1;
554 while (info
->save_level
>= level
)
556 EMF_dc_state
*state
= info
->saved_state
;
557 info
->saved_state
= state
->next
;
559 if (--info
->save_level
< level
)
560 info
->state
= *state
;
561 HeapFree( GetProcessHeap(), 0, state
);
565 static void EMF_SaveDC( enum_emh_data
*info
)
567 EMF_dc_state
*state
= HeapAlloc( GetProcessHeap(), 0, sizeof(*state
));
570 *state
= info
->state
;
571 state
->next
= info
->saved_state
;
572 info
->saved_state
= state
;
574 TRACE("save_level %d\n", info
->save_level
);
578 static void EMF_SetMapMode(HDC hdc
, enum_emh_data
*info
)
580 INT horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
581 INT vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
582 INT horzRes
= GetDeviceCaps( hdc
, HORZRES
);
583 INT vertRes
= GetDeviceCaps( hdc
, VERTRES
);
585 TRACE("%d\n", info
->state
.mode
);
587 switch(info
->state
.mode
)
590 info
->state
.wndExtX
= 1;
591 info
->state
.wndExtY
= 1;
592 info
->state
.vportExtX
= 1;
593 info
->state
.vportExtY
= 1;
597 info
->state
.wndExtX
= horzSize
* 10;
598 info
->state
.wndExtY
= vertSize
* 10;
599 info
->state
.vportExtX
= horzRes
;
600 info
->state
.vportExtY
= -vertRes
;
603 info
->state
.wndExtX
= horzSize
* 100;
604 info
->state
.wndExtY
= vertSize
* 100;
605 info
->state
.vportExtX
= horzRes
;
606 info
->state
.vportExtY
= -vertRes
;
609 info
->state
.wndExtX
= MulDiv(1000, horzSize
, 254);
610 info
->state
.wndExtY
= MulDiv(1000, vertSize
, 254);
611 info
->state
.vportExtX
= horzRes
;
612 info
->state
.vportExtY
= -vertRes
;
615 info
->state
.wndExtX
= MulDiv(10000, horzSize
, 254);
616 info
->state
.wndExtY
= MulDiv(10000, vertSize
, 254);
617 info
->state
.vportExtX
= horzRes
;
618 info
->state
.vportExtY
= -vertRes
;
621 info
->state
.wndExtX
= MulDiv(14400, horzSize
, 254);
622 info
->state
.wndExtY
= MulDiv(14400, vertSize
, 254);
623 info
->state
.vportExtX
= horzRes
;
624 info
->state
.vportExtY
= -vertRes
;
633 /***********************************************************************
636 * Fix viewport extensions for isotropic mode.
639 static void EMF_FixIsotropic(HDC hdc
, enum_emh_data
*info
)
641 double xdim
= fabs((double)info
->state
.vportExtX
* GetDeviceCaps( hdc
, HORZSIZE
) /
642 (GetDeviceCaps( hdc
, HORZRES
) * info
->state
.wndExtX
));
643 double ydim
= fabs((double)info
->state
.vportExtY
* GetDeviceCaps( hdc
, VERTSIZE
) /
644 (GetDeviceCaps( hdc
, VERTRES
) * info
->state
.wndExtY
));
648 INT mincx
= (info
->state
.vportExtX
>= 0) ? 1 : -1;
649 info
->state
.vportExtX
= floor(info
->state
.vportExtX
* ydim
/ xdim
+ 0.5);
650 if (!info
->state
.vportExtX
) info
->state
.vportExtX
= mincx
;
654 INT mincy
= (info
->state
.vportExtY
>= 0) ? 1 : -1;
655 info
->state
.vportExtY
= floor(info
->state
.vportExtY
* xdim
/ ydim
+ 0.5);
656 if (!info
->state
.vportExtY
) info
->state
.vportExtY
= mincy
;
660 /*****************************************************************************
661 * emr_produces_output
663 * Returns TRUE if the record type writes something to the dc. Used by
664 * PlayEnhMetaFileRecord to determine whether it needs to update the
665 * dc's xform when in win9x mode.
667 * FIXME: need to test which records should be here.
669 static BOOL
emr_produces_output(int type
)
675 case EMR_POLYBEZIERTO
:
677 case EMR_POLYPOLYLINE
:
678 case EMR_POLYPOLYGON
:
681 case EMR_EXCLUDECLIPRECT
:
682 case EMR_INTERSECTCLIPRECT
:
683 case EMR_SELECTOBJECT
:
691 case EMR_EXTFLOODFILL
:
704 case EMR_SETDIBITSTODEVICE
:
705 case EMR_STRETCHDIBITS
:
706 case EMR_EXTTEXTOUTA
:
707 case EMR_EXTTEXTOUTW
:
708 case EMR_POLYBEZIER16
:
711 case EMR_POLYBEZIERTO16
:
712 case EMR_POLYLINETO16
:
713 case EMR_POLYPOLYLINE16
:
714 case EMR_POLYPOLYGON16
:
716 case EMR_POLYTEXTOUTA
:
717 case EMR_POLYTEXTOUTW
:
718 case EMR_SMALLTEXTOUT
:
720 case EMR_TRANSPARENTBLT
:
728 /*****************************************************************************
729 * PlayEnhMetaFileRecord (GDI32.@)
731 * Render a single enhanced metafile record in the device context hdc.
734 * TRUE (non zero) on success, FALSE on error.
736 * Many unimplemented records.
737 * No error handling on record play failures (ie checking return codes)
740 * WinNT actually updates the current world transform in this function
741 * whereas Win9x does not.
743 BOOL WINAPI
PlayEnhMetaFileRecord(
744 HDC hdc
, /* [in] device context in which to render EMF record */
745 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
746 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
747 UINT handles
/* [in] size of handle array */
752 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
754 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
755 hdc
, handletable
, mr
, handles
);
756 if (!mr
) return FALSE
;
760 TRACE("record %s\n", get_emr_name(type
));
769 const EMRGDICOMMENT
*lpGdiComment
= (const EMRGDICOMMENT
*)mr
;
770 /* In an enhanced metafile, there can be both public and private GDI comments */
771 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
776 const EMRSETMAPMODE
*pSetMapMode
= (const EMRSETMAPMODE
*)mr
;
778 if (info
->state
.mode
== pSetMapMode
->iMode
&&
779 (info
->state
.mode
== MM_ISOTROPIC
|| info
->state
.mode
== MM_ANISOTROPIC
))
781 info
->state
.mode
= pSetMapMode
->iMode
;
782 EMF_SetMapMode(hdc
, info
);
787 const EMRSETBKMODE
*pSetBkMode
= (const EMRSETBKMODE
*)mr
;
788 SetBkMode(hdc
, pSetBkMode
->iMode
);
793 const EMRSETBKCOLOR
*pSetBkColor
= (const EMRSETBKCOLOR
*)mr
;
794 SetBkColor(hdc
, pSetBkColor
->crColor
);
797 case EMR_SETPOLYFILLMODE
:
799 const EMRSETPOLYFILLMODE
*pSetPolyFillMode
= (const EMRSETPOLYFILLMODE
*)mr
;
800 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
805 const EMRSETROP2
*pSetROP2
= (const EMRSETROP2
*)mr
;
806 SetROP2(hdc
, pSetROP2
->iMode
);
809 case EMR_SETSTRETCHBLTMODE
:
811 const EMRSETSTRETCHBLTMODE
*pSetStretchBltMode
= (const EMRSETSTRETCHBLTMODE
*)mr
;
812 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
815 case EMR_SETTEXTALIGN
:
817 const EMRSETTEXTALIGN
*pSetTextAlign
= (const EMRSETTEXTALIGN
*)mr
;
818 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
821 case EMR_SETTEXTCOLOR
:
823 const EMRSETTEXTCOLOR
*pSetTextColor
= (const EMRSETTEXTCOLOR
*)mr
;
824 SetTextColor(hdc
, pSetTextColor
->crColor
);
835 const EMRRESTOREDC
*pRestoreDC
= (const EMRRESTOREDC
*)mr
;
836 TRACE("EMR_RESTORE: %d\n", pRestoreDC
->iRelative
);
837 if (RestoreDC( hdc
, pRestoreDC
->iRelative
))
838 EMF_RestoreDC( info
, pRestoreDC
->iRelative
);
841 case EMR_INTERSECTCLIPRECT
:
843 const EMRINTERSECTCLIPRECT
*pClipRect
= (const EMRINTERSECTCLIPRECT
*)mr
;
844 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
845 pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
846 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
847 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
848 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
851 case EMR_SELECTOBJECT
:
853 const EMRSELECTOBJECT
*pSelectObject
= (const EMRSELECTOBJECT
*)mr
;
854 if( pSelectObject
->ihObject
& 0x80000000 ) {
855 /* High order bit is set - it's a stock object
856 * Strip the high bit to get the index.
857 * See MSDN article Q142319
859 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
862 /* High order bit wasn't set - not a stock object
865 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
869 case EMR_DELETEOBJECT
:
871 const EMRDELETEOBJECT
*pDeleteObject
= (const EMRDELETEOBJECT
*)mr
;
872 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
873 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
876 case EMR_SETWINDOWORGEX
:
878 const EMRSETWINDOWORGEX
*pSetWindowOrgEx
= (const EMRSETWINDOWORGEX
*)mr
;
880 info
->state
.wndOrgX
= pSetWindowOrgEx
->ptlOrigin
.x
;
881 info
->state
.wndOrgY
= pSetWindowOrgEx
->ptlOrigin
.y
;
883 TRACE("SetWindowOrgEx: %d,%d\n", info
->state
.wndOrgX
, info
->state
.wndOrgY
);
886 case EMR_SETWINDOWEXTEX
:
888 const EMRSETWINDOWEXTEX
*pSetWindowExtEx
= (const EMRSETWINDOWEXTEX
*)mr
;
890 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
892 info
->state
.wndExtX
= pSetWindowExtEx
->szlExtent
.cx
;
893 info
->state
.wndExtY
= pSetWindowExtEx
->szlExtent
.cy
;
894 if (info
->state
.mode
== MM_ISOTROPIC
)
895 EMF_FixIsotropic(hdc
, info
);
897 TRACE("SetWindowExtEx: %d,%d\n",info
->state
.wndExtX
, info
->state
.wndExtY
);
900 case EMR_SETVIEWPORTORGEX
:
902 const EMRSETVIEWPORTORGEX
*pSetViewportOrgEx
= (const EMRSETVIEWPORTORGEX
*)mr
;
904 info
->state
.vportOrgX
= pSetViewportOrgEx
->ptlOrigin
.x
;
905 info
->state
.vportOrgY
= pSetViewportOrgEx
->ptlOrigin
.y
;
906 TRACE("SetViewportOrgEx: %d,%d\n", info
->state
.vportOrgX
, info
->state
.vportOrgY
);
909 case EMR_SETVIEWPORTEXTEX
:
911 const EMRSETVIEWPORTEXTEX
*pSetViewportExtEx
= (const EMRSETVIEWPORTEXTEX
*)mr
;
913 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
915 info
->state
.vportExtX
= pSetViewportExtEx
->szlExtent
.cx
;
916 info
->state
.vportExtY
= pSetViewportExtEx
->szlExtent
.cy
;
917 if (info
->state
.mode
== MM_ISOTROPIC
)
918 EMF_FixIsotropic(hdc
, info
);
919 TRACE("SetViewportExtEx: %d,%d\n", info
->state
.vportExtX
, info
->state
.vportExtY
);
924 const EMRCREATEPEN
*pCreatePen
= (const EMRCREATEPEN
*)mr
;
925 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
926 CreatePenIndirect(&pCreatePen
->lopn
);
929 case EMR_EXTCREATEPEN
:
931 const EMREXTCREATEPEN
*pPen
= (const EMREXTCREATEPEN
*)mr
;
933 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
934 lb
.lbColor
= pPen
->elp
.elpColor
;
935 lb
.lbHatch
= pPen
->elp
.elpHatch
;
937 if(pPen
->offBmi
|| pPen
->offBits
)
938 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
940 (handletable
->objectHandle
)[pPen
->ihPen
] =
941 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
942 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpStyleEntry
);
945 case EMR_CREATEBRUSHINDIRECT
:
947 const EMRCREATEBRUSHINDIRECT
*pBrush
= (const EMRCREATEBRUSHINDIRECT
*)mr
;
949 brush
.lbStyle
= pBrush
->lb
.lbStyle
;
950 brush
.lbColor
= pBrush
->lb
.lbColor
;
951 brush
.lbHatch
= pBrush
->lb
.lbHatch
;
952 (handletable
->objectHandle
)[pBrush
->ihBrush
] = CreateBrushIndirect(&brush
);
955 case EMR_EXTCREATEFONTINDIRECTW
:
957 const EMREXTCREATEFONTINDIRECTW
*pFont
= (const EMREXTCREATEFONTINDIRECTW
*)mr
;
958 (handletable
->objectHandle
)[pFont
->ihFont
] =
959 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
964 const EMRMOVETOEX
*pMoveToEx
= (const EMRMOVETOEX
*)mr
;
965 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
970 const EMRLINETO
*pLineTo
= (const EMRLINETO
*)mr
;
971 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
976 const EMRRECTANGLE
*pRect
= (const EMRRECTANGLE
*)mr
;
977 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
978 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
983 const EMRELLIPSE
*pEllipse
= (const EMRELLIPSE
*)mr
;
984 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
985 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
990 const EMRPOLYGON16
*pPoly
= (const EMRPOLYGON16
*)mr
;
991 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
992 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
993 pPoly
->cpts
* sizeof(POINT
) );
995 for(i
= 0; i
< pPoly
->cpts
; i
++)
997 pts
[i
].x
= pPoly
->apts
[i
].x
;
998 pts
[i
].y
= pPoly
->apts
[i
].y
;
1000 Polygon(hdc
, pts
, pPoly
->cpts
);
1001 HeapFree( GetProcessHeap(), 0, pts
);
1004 case EMR_POLYLINE16
:
1006 const EMRPOLYLINE16
*pPoly
= (const EMRPOLYLINE16
*)mr
;
1007 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1008 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1009 pPoly
->cpts
* sizeof(POINT
) );
1011 for(i
= 0; i
< pPoly
->cpts
; i
++)
1013 pts
[i
].x
= pPoly
->apts
[i
].x
;
1014 pts
[i
].y
= pPoly
->apts
[i
].y
;
1016 Polyline(hdc
, pts
, pPoly
->cpts
);
1017 HeapFree( GetProcessHeap(), 0, pts
);
1020 case EMR_POLYLINETO16
:
1022 const EMRPOLYLINETO16
*pPoly
= (const EMRPOLYLINETO16
*)mr
;
1023 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1024 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1025 pPoly
->cpts
* sizeof(POINT
) );
1027 for(i
= 0; i
< pPoly
->cpts
; i
++)
1029 pts
[i
].x
= pPoly
->apts
[i
].x
;
1030 pts
[i
].y
= pPoly
->apts
[i
].y
;
1032 PolylineTo(hdc
, pts
, pPoly
->cpts
);
1033 HeapFree( GetProcessHeap(), 0, pts
);
1036 case EMR_POLYBEZIER16
:
1038 const EMRPOLYBEZIER16
*pPoly
= (const EMRPOLYBEZIER16
*)mr
;
1039 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1040 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1041 pPoly
->cpts
* sizeof(POINT
) );
1043 for(i
= 0; i
< pPoly
->cpts
; i
++)
1045 pts
[i
].x
= pPoly
->apts
[i
].x
;
1046 pts
[i
].y
= pPoly
->apts
[i
].y
;
1048 PolyBezier(hdc
, pts
, pPoly
->cpts
);
1049 HeapFree( GetProcessHeap(), 0, pts
);
1052 case EMR_POLYBEZIERTO16
:
1054 const EMRPOLYBEZIERTO16
*pPoly
= (const EMRPOLYBEZIERTO16
*)mr
;
1055 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1056 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1057 pPoly
->cpts
* sizeof(POINT
) );
1059 for(i
= 0; i
< pPoly
->cpts
; i
++)
1061 pts
[i
].x
= pPoly
->apts
[i
].x
;
1062 pts
[i
].y
= pPoly
->apts
[i
].y
;
1064 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
1065 HeapFree( GetProcessHeap(), 0, pts
);
1068 case EMR_POLYPOLYGON16
:
1070 const EMRPOLYPOLYGON16
*pPolyPoly
= (const EMRPOLYPOLYGON16
*)mr
;
1071 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1072 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1074 POINT16
*pts16
= (POINT16
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1075 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1077 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1079 pts
[i
].x
= pts16
[i
].x
;
1080 pts
[i
].y
= pts16
[i
].y
;
1082 PolyPolygon(hdc
, pts
, (INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1083 HeapFree( GetProcessHeap(), 0, pts
);
1086 case EMR_POLYPOLYLINE16
:
1088 const EMRPOLYPOLYLINE16
*pPolyPoly
= (const EMRPOLYPOLYLINE16
*)mr
;
1089 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1090 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1092 POINT16
*pts16
= (POINT16
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1093 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1095 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1097 pts
[i
].x
= pts16
[i
].x
;
1098 pts
[i
].y
= pts16
[i
].y
;
1100 PolyPolyline(hdc
, pts
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1101 HeapFree( GetProcessHeap(), 0, pts
);
1105 case EMR_STRETCHDIBITS
:
1107 const EMRSTRETCHDIBITS
*pStretchDIBits
= (const EMRSTRETCHDIBITS
*)mr
;
1110 pStretchDIBits
->xDest
,
1111 pStretchDIBits
->yDest
,
1112 pStretchDIBits
->cxDest
,
1113 pStretchDIBits
->cyDest
,
1114 pStretchDIBits
->xSrc
,
1115 pStretchDIBits
->ySrc
,
1116 pStretchDIBits
->cxSrc
,
1117 pStretchDIBits
->cySrc
,
1118 (const BYTE
*)mr
+ pStretchDIBits
->offBitsSrc
,
1119 (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchDIBits
->offBmiSrc
),
1120 pStretchDIBits
->iUsageSrc
,
1121 pStretchDIBits
->dwRop
);
1125 case EMR_EXTTEXTOUTA
:
1127 const EMREXTTEXTOUTA
*pExtTextOutA
= (const EMREXTTEXTOUTA
*)mr
;
1129 const INT
*dx
= NULL
;
1131 rc
.left
= pExtTextOutA
->emrtext
.rcl
.left
;
1132 rc
.top
= pExtTextOutA
->emrtext
.rcl
.top
;
1133 rc
.right
= pExtTextOutA
->emrtext
.rcl
.right
;
1134 rc
.bottom
= pExtTextOutA
->emrtext
.rcl
.bottom
;
1135 TRACE("EMR_EXTTEXTOUTA: x,y = %d, %d. rect = %d, %d - %d, %d. flags %08x\n",
1136 pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1137 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, pExtTextOutA
->emrtext
.fOptions
);
1139 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1140 * These files can be enumerated and played under Win98 just
1141 * fine, but at least Win2k chokes on them.
1143 if (pExtTextOutA
->emrtext
.offDx
)
1144 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offDx
);
1146 ExtTextOutA(hdc
, pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1147 pExtTextOutA
->emrtext
.fOptions
, &rc
,
1148 (LPCSTR
)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offString
), pExtTextOutA
->emrtext
.nChars
,
1153 case EMR_EXTTEXTOUTW
:
1155 const EMREXTTEXTOUTW
*pExtTextOutW
= (const EMREXTTEXTOUTW
*)mr
;
1157 const INT
*dx
= NULL
;
1159 rc
.left
= pExtTextOutW
->emrtext
.rcl
.left
;
1160 rc
.top
= pExtTextOutW
->emrtext
.rcl
.top
;
1161 rc
.right
= pExtTextOutW
->emrtext
.rcl
.right
;
1162 rc
.bottom
= pExtTextOutW
->emrtext
.rcl
.bottom
;
1163 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %d, %d - %d, %d. flags %08x\n",
1164 pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1165 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, pExtTextOutW
->emrtext
.fOptions
);
1167 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1168 * These files can be enumerated and played under Win98 just
1169 * fine, but at least Win2k chokes on them.
1171 if (pExtTextOutW
->emrtext
.offDx
)
1172 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offDx
);
1174 ExtTextOutW(hdc
, pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1175 pExtTextOutW
->emrtext
.fOptions
, &rc
,
1176 (LPCWSTR
)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offString
), pExtTextOutW
->emrtext
.nChars
,
1181 case EMR_CREATEPALETTE
:
1183 const EMRCREATEPALETTE
*lpCreatePal
= (const EMRCREATEPALETTE
*)mr
;
1185 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1186 CreatePalette( &lpCreatePal
->lgpl
);
1191 case EMR_SELECTPALETTE
:
1193 const EMRSELECTPALETTE
*lpSelectPal
= (const EMRSELECTPALETTE
*)mr
;
1195 if( lpSelectPal
->ihPal
& 0x80000000 ) {
1196 SelectPalette( hdc
, GetStockObject(lpSelectPal
->ihPal
& 0x7fffffff), TRUE
);
1198 SelectPalette( hdc
, (handletable
->objectHandle
)[lpSelectPal
->ihPal
], TRUE
);
1203 case EMR_REALIZEPALETTE
:
1205 RealizePalette( hdc
);
1209 case EMR_EXTSELECTCLIPRGN
:
1211 const EMREXTSELECTCLIPRGN
*lpRgn
= (const EMREXTSELECTCLIPRGN
*)mr
;
1214 if (mr
->nSize
>= sizeof(*lpRgn
) + sizeof(RGNDATAHEADER
))
1215 hRgn
= ExtCreateRegion( &info
->init_transform
, 0, (RGNDATA
*)lpRgn
->RgnData
);
1217 ExtSelectClipRgn(hdc
, hRgn
, (INT
)(lpRgn
->iMode
));
1218 /* ExtSelectClipRgn created a copy of the region */
1223 case EMR_SETMETARGN
:
1229 case EMR_SETWORLDTRANSFORM
:
1231 const EMRSETWORLDTRANSFORM
*lpXfrm
= (const EMRSETWORLDTRANSFORM
*)mr
;
1232 info
->state
.world_transform
= lpXfrm
->xform
;
1236 case EMR_POLYBEZIER
:
1238 const EMRPOLYBEZIER
*lpPolyBez
= (const EMRPOLYBEZIER
*)mr
;
1239 PolyBezier(hdc
, (const POINT
*)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1245 const EMRPOLYGON
*lpPoly
= (const EMRPOLYGON
*)mr
;
1246 Polygon( hdc
, (const POINT
*)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1252 const EMRPOLYLINE
*lpPolyLine
= (const EMRPOLYLINE
*)mr
;
1253 Polyline(hdc
, (const POINT
*)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1257 case EMR_POLYBEZIERTO
:
1259 const EMRPOLYBEZIERTO
*lpPolyBezierTo
= (const EMRPOLYBEZIERTO
*)mr
;
1260 PolyBezierTo( hdc
, (const POINT
*)lpPolyBezierTo
->aptl
,
1261 (UINT
)lpPolyBezierTo
->cptl
);
1265 case EMR_POLYLINETO
:
1267 const EMRPOLYLINETO
*lpPolyLineTo
= (const EMRPOLYLINETO
*)mr
;
1268 PolylineTo( hdc
, (const POINT
*)lpPolyLineTo
->aptl
,
1269 (UINT
)lpPolyLineTo
->cptl
);
1273 case EMR_POLYPOLYLINE
:
1275 const EMRPOLYPOLYLINE
*pPolyPolyline
= (const EMRPOLYPOLYLINE
*)mr
;
1276 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1278 PolyPolyline(hdc
, (LPPOINT
)(pPolyPolyline
->aPolyCounts
+
1279 pPolyPolyline
->nPolys
),
1280 pPolyPolyline
->aPolyCounts
,
1281 pPolyPolyline
->nPolys
);
1286 case EMR_POLYPOLYGON
:
1288 const EMRPOLYPOLYGON
*pPolyPolygon
= (const EMRPOLYPOLYGON
*)mr
;
1290 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1292 PolyPolygon(hdc
, (LPPOINT
)(pPolyPolygon
->aPolyCounts
+
1293 pPolyPolygon
->nPolys
),
1294 (INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
1298 case EMR_SETBRUSHORGEX
:
1300 const EMRSETBRUSHORGEX
*lpSetBrushOrgEx
= (const EMRSETBRUSHORGEX
*)mr
;
1303 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1304 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1312 const EMRSETPIXELV
*lpSetPixelV
= (const EMRSETPIXELV
*)mr
;
1315 (INT
)lpSetPixelV
->ptlPixel
.x
,
1316 (INT
)lpSetPixelV
->ptlPixel
.y
,
1317 lpSetPixelV
->crColor
);
1322 case EMR_SETMAPPERFLAGS
:
1324 const EMRSETMAPPERFLAGS
*lpSetMapperFlags
= (const EMRSETMAPPERFLAGS
*)mr
;
1326 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1331 case EMR_SETCOLORADJUSTMENT
:
1333 const EMRSETCOLORADJUSTMENT
*lpSetColorAdjust
= (const EMRSETCOLORADJUSTMENT
*)mr
;
1335 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1340 case EMR_OFFSETCLIPRGN
:
1342 const EMROFFSETCLIPRGN
*lpOffsetClipRgn
= (const EMROFFSETCLIPRGN
*)mr
;
1345 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1346 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1347 FIXME("OffsetClipRgn\n");
1352 case EMR_EXCLUDECLIPRECT
:
1354 const EMREXCLUDECLIPRECT
*lpExcludeClipRect
= (const EMREXCLUDECLIPRECT
*)mr
;
1356 ExcludeClipRect( hdc
,
1357 lpExcludeClipRect
->rclClip
.left
,
1358 lpExcludeClipRect
->rclClip
.top
,
1359 lpExcludeClipRect
->rclClip
.right
,
1360 lpExcludeClipRect
->rclClip
.bottom
);
1361 FIXME("ExcludeClipRect\n");
1366 case EMR_SCALEVIEWPORTEXTEX
:
1368 const EMRSCALEVIEWPORTEXTEX
*lpScaleViewportExtEx
= (const EMRSCALEVIEWPORTEXTEX
*)mr
;
1370 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1372 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1373 !lpScaleViewportExtEx
->yNum
|| !lpScaleViewportExtEx
->yDenom
)
1375 info
->state
.vportExtX
= MulDiv(info
->state
.vportExtX
, lpScaleViewportExtEx
->xNum
,
1376 lpScaleViewportExtEx
->xDenom
);
1377 info
->state
.vportExtY
= MulDiv(info
->state
.vportExtY
, lpScaleViewportExtEx
->yNum
,
1378 lpScaleViewportExtEx
->yDenom
);
1379 if (info
->state
.vportExtX
== 0) info
->state
.vportExtX
= 1;
1380 if (info
->state
.vportExtY
== 0) info
->state
.vportExtY
= 1;
1381 if (info
->state
.mode
== MM_ISOTROPIC
)
1382 EMF_FixIsotropic(hdc
, info
);
1384 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1385 lpScaleViewportExtEx
->xNum
,lpScaleViewportExtEx
->xDenom
,
1386 lpScaleViewportExtEx
->yNum
,lpScaleViewportExtEx
->yDenom
);
1391 case EMR_SCALEWINDOWEXTEX
:
1393 const EMRSCALEWINDOWEXTEX
*lpScaleWindowExtEx
= (const EMRSCALEWINDOWEXTEX
*)mr
;
1395 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1397 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1398 !lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->yDenom
)
1400 info
->state
.wndExtX
= MulDiv(info
->state
.wndExtX
, lpScaleWindowExtEx
->xNum
,
1401 lpScaleWindowExtEx
->xDenom
);
1402 info
->state
.wndExtY
= MulDiv(info
->state
.wndExtY
, lpScaleWindowExtEx
->yNum
,
1403 lpScaleWindowExtEx
->yDenom
);
1404 if (info
->state
.wndExtX
== 0) info
->state
.wndExtX
= 1;
1405 if (info
->state
.wndExtY
== 0) info
->state
.wndExtY
= 1;
1406 if (info
->state
.mode
== MM_ISOTROPIC
)
1407 EMF_FixIsotropic(hdc
, info
);
1409 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1410 lpScaleWindowExtEx
->xNum
,lpScaleWindowExtEx
->xDenom
,
1411 lpScaleWindowExtEx
->yNum
,lpScaleWindowExtEx
->yDenom
);
1416 case EMR_MODIFYWORLDTRANSFORM
:
1418 const EMRMODIFYWORLDTRANSFORM
*lpModifyWorldTrans
= (const EMRMODIFYWORLDTRANSFORM
*)mr
;
1420 switch(lpModifyWorldTrans
->iMode
) {
1422 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
1423 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
1424 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
1426 case MWT_LEFTMULTIPLY
:
1427 CombineTransform(&info
->state
.world_transform
, &lpModifyWorldTrans
->xform
,
1428 &info
->state
.world_transform
);
1430 case MWT_RIGHTMULTIPLY
:
1431 CombineTransform(&info
->state
.world_transform
, &info
->state
.world_transform
,
1432 &lpModifyWorldTrans
->xform
);
1435 FIXME("Unknown imode %d\n", lpModifyWorldTrans
->iMode
);
1443 const EMRANGLEARC
*lpAngleArc
= (const EMRANGLEARC
*)mr
;
1446 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1447 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1448 lpAngleArc
->eSweepAngle
);
1455 const EMRROUNDRECT
*lpRoundRect
= (const EMRROUNDRECT
*)mr
;
1458 lpRoundRect
->rclBox
.left
,
1459 lpRoundRect
->rclBox
.top
,
1460 lpRoundRect
->rclBox
.right
,
1461 lpRoundRect
->rclBox
.bottom
,
1462 lpRoundRect
->szlCorner
.cx
,
1463 lpRoundRect
->szlCorner
.cy
);
1470 const EMRARC
*lpArc
= (const EMRARC
*)mr
;
1473 (INT
)lpArc
->rclBox
.left
,
1474 (INT
)lpArc
->rclBox
.top
,
1475 (INT
)lpArc
->rclBox
.right
,
1476 (INT
)lpArc
->rclBox
.bottom
,
1477 (INT
)lpArc
->ptlStart
.x
,
1478 (INT
)lpArc
->ptlStart
.y
,
1479 (INT
)lpArc
->ptlEnd
.x
,
1480 (INT
)lpArc
->ptlEnd
.y
);
1487 const EMRCHORD
*lpChord
= (const EMRCHORD
*)mr
;
1490 (INT
)lpChord
->rclBox
.left
,
1491 (INT
)lpChord
->rclBox
.top
,
1492 (INT
)lpChord
->rclBox
.right
,
1493 (INT
)lpChord
->rclBox
.bottom
,
1494 (INT
)lpChord
->ptlStart
.x
,
1495 (INT
)lpChord
->ptlStart
.y
,
1496 (INT
)lpChord
->ptlEnd
.x
,
1497 (INT
)lpChord
->ptlEnd
.y
);
1504 const EMRPIE
*lpPie
= (const EMRPIE
*)mr
;
1507 (INT
)lpPie
->rclBox
.left
,
1508 (INT
)lpPie
->rclBox
.top
,
1509 (INT
)lpPie
->rclBox
.right
,
1510 (INT
)lpPie
->rclBox
.bottom
,
1511 (INT
)lpPie
->ptlStart
.x
,
1512 (INT
)lpPie
->ptlStart
.y
,
1513 (INT
)lpPie
->ptlEnd
.x
,
1514 (INT
)lpPie
->ptlEnd
.y
);
1521 const EMRARC
*lpArcTo
= (const EMRARC
*)mr
;
1524 (INT
)lpArcTo
->rclBox
.left
,
1525 (INT
)lpArcTo
->rclBox
.top
,
1526 (INT
)lpArcTo
->rclBox
.right
,
1527 (INT
)lpArcTo
->rclBox
.bottom
,
1528 (INT
)lpArcTo
->ptlStart
.x
,
1529 (INT
)lpArcTo
->ptlStart
.y
,
1530 (INT
)lpArcTo
->ptlEnd
.x
,
1531 (INT
)lpArcTo
->ptlEnd
.y
);
1536 case EMR_EXTFLOODFILL
:
1538 const EMREXTFLOODFILL
*lpExtFloodFill
= (const EMREXTFLOODFILL
*)mr
;
1541 (INT
)lpExtFloodFill
->ptlStart
.x
,
1542 (INT
)lpExtFloodFill
->ptlStart
.y
,
1543 lpExtFloodFill
->crColor
,
1544 (UINT
)lpExtFloodFill
->iMode
);
1551 const EMRPOLYDRAW
*lpPolyDraw
= (const EMRPOLYDRAW
*)mr
;
1553 (const POINT
*)lpPolyDraw
->aptl
,
1554 lpPolyDraw
->abTypes
,
1555 (INT
)lpPolyDraw
->cptl
);
1560 case EMR_SETARCDIRECTION
:
1562 const EMRSETARCDIRECTION
*lpSetArcDirection
= (const EMRSETARCDIRECTION
*)mr
;
1563 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1567 case EMR_SETMITERLIMIT
:
1569 const EMRSETMITERLIMIT
*lpSetMiterLimit
= (const EMRSETMITERLIMIT
*)mr
;
1570 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1586 case EMR_CLOSEFIGURE
:
1594 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1599 case EMR_STROKEANDFILLPATH
:
1601 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1602 StrokeAndFillPath( hdc
);
1606 case EMR_STROKEPATH
:
1608 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1613 case EMR_FLATTENPATH
:
1625 case EMR_SELECTCLIPPATH
:
1627 const EMRSELECTCLIPPATH
*lpSelectClipPath
= (const EMRSELECTCLIPPATH
*)mr
;
1628 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1638 case EMR_CREATECOLORSPACE
:
1640 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1641 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1642 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1646 case EMR_SETCOLORSPACE
:
1648 const EMRSETCOLORSPACE
*lpSetColorSpace
= (const EMRSETCOLORSPACE
*)mr
;
1650 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1654 case EMR_DELETECOLORSPACE
:
1656 const EMRDELETECOLORSPACE
*lpDeleteColorSpace
= (const EMRDELETECOLORSPACE
*)mr
;
1657 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1661 case EMR_SETICMMODE
:
1663 const EMRSETICMMODE
*lpSetICMMode
= (const EMRSETICMMODE
*)mr
;
1664 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1668 case EMR_PIXELFORMAT
:
1671 const EMRPIXELFORMAT
*lpPixelFormat
= (const EMRPIXELFORMAT
*)mr
;
1673 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1674 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1679 case EMR_SETPALETTEENTRIES
:
1681 const EMRSETPALETTEENTRIES
*lpSetPaletteEntries
= (const EMRSETPALETTEENTRIES
*)mr
;
1683 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1684 (UINT
)lpSetPaletteEntries
->iStart
,
1685 (UINT
)lpSetPaletteEntries
->cEntries
,
1686 lpSetPaletteEntries
->aPalEntries
);
1691 case EMR_RESIZEPALETTE
:
1693 const EMRRESIZEPALETTE
*lpResizePalette
= (const EMRRESIZEPALETTE
*)mr
;
1695 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1696 (UINT
)lpResizePalette
->cEntries
);
1701 case EMR_CREATEDIBPATTERNBRUSHPT
:
1703 const EMRCREATEDIBPATTERNBRUSHPT
*lpCreate
= (const EMRCREATEDIBPATTERNBRUSHPT
*)mr
;
1704 LPVOID lpPackedStruct
;
1706 /* Check that offsets and data are contained within the record
1707 * (including checking for wrap-arounds).
1709 if ( lpCreate
->offBmi
+ lpCreate
->cbBmi
> mr
->nSize
1710 || lpCreate
->offBits
+ lpCreate
->cbBits
> mr
->nSize
1711 || lpCreate
->offBmi
+ lpCreate
->cbBmi
< lpCreate
->offBmi
1712 || lpCreate
->offBits
+ lpCreate
->cbBits
< lpCreate
->offBits
)
1714 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1718 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1719 lpPackedStruct
= HeapAlloc( GetProcessHeap(), 0,
1720 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1723 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1727 /* Now pack this structure */
1728 memcpy( lpPackedStruct
,
1729 ((const BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1731 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1732 ((const BYTE
*)lpCreate
) + lpCreate
->offBits
,
1735 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1736 CreateDIBPatternBrushPt( lpPackedStruct
,
1737 (UINT
)lpCreate
->iUsage
);
1739 HeapFree(GetProcessHeap(), 0, lpPackedStruct
);
1743 case EMR_CREATEMONOBRUSH
:
1745 const EMRCREATEMONOBRUSH
*pCreateMonoBrush
= (const EMRCREATEMONOBRUSH
*)mr
;
1746 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
1749 /* Need to check if the bitmap is monochrome, and if the
1750 two colors are really black and white */
1751 if (pCreateMonoBrush
->iUsage
== DIB_PAL_MONO
)
1755 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1756 * aligned to 32 rather than 16 bits.
1759 bm
.bmWidth
= pbi
->bmiHeader
.biWidth
;
1760 bm
.bmHeight
= abs(pbi
->bmiHeader
.biHeight
);
1761 bm
.bmWidthBytes
= 4 * ((pbi
->bmiHeader
.biWidth
+ 31) / 32);
1762 bm
.bmPlanes
= pbi
->bmiHeader
.biPlanes
;
1763 bm
.bmBitsPixel
= pbi
->bmiHeader
.biBitCount
;
1764 bm
.bmBits
= (BYTE
*)mr
+ pCreateMonoBrush
->offBits
;
1765 hBmp
= CreateBitmapIndirect(&bm
);
1767 else if (is_dib_monochrome(pbi
))
1769 /* Top-down DIBs have a negative height */
1770 LONG height
= pbi
->bmiHeader
.biHeight
;
1772 hBmp
= CreateBitmap(pbi
->bmiHeader
.biWidth
, abs(height
), 1, 1, NULL
);
1773 SetDIBits(hdc
, hBmp
, 0, pbi
->bmiHeader
.biHeight
,
1774 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1778 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1779 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1782 (handletable
->objectHandle
)[pCreateMonoBrush
->ihBrush
] = CreatePatternBrush(hBmp
);
1784 /* CreatePatternBrush created a copy of the bitmap */
1791 const EMRBITBLT
*pBitBlt
= (const EMRBITBLT
*)mr
;
1793 if(pBitBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1794 PatBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1796 } else { /* BitBlt */
1797 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1798 HBRUSH hBrush
, hBrushOld
;
1799 HBITMAP hBmp
= 0, hBmpOld
= 0;
1800 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pBitBlt
->offBmiSrc
);
1802 SetWorldTransform(hdcSrc
, &pBitBlt
->xformSrc
);
1804 hBrush
= CreateSolidBrush(pBitBlt
->crBkColorSrc
);
1805 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1806 PatBlt(hdcSrc
, pBitBlt
->rclBounds
.left
, pBitBlt
->rclBounds
.top
,
1807 pBitBlt
->rclBounds
.right
- pBitBlt
->rclBounds
.left
,
1808 pBitBlt
->rclBounds
.bottom
- pBitBlt
->rclBounds
.top
, PATCOPY
);
1809 SelectObject(hdcSrc
, hBrushOld
);
1810 DeleteObject(hBrush
);
1812 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1813 (const BYTE
*)mr
+ pBitBlt
->offBitsSrc
, pbi
, pBitBlt
->iUsageSrc
);
1814 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1816 BitBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1817 hdcSrc
, pBitBlt
->xSrc
, pBitBlt
->ySrc
, pBitBlt
->dwRop
);
1819 SelectObject(hdcSrc
, hBmpOld
);
1826 case EMR_STRETCHBLT
:
1828 const EMRSTRETCHBLT
*pStretchBlt
= (const EMRSTRETCHBLT
*)mr
;
1830 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1831 pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1832 pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1833 pStretchBlt
->dwRop
, pStretchBlt
->offBitsSrc
);
1835 if(pStretchBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1836 PatBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1837 pStretchBlt
->dwRop
);
1838 } else { /* StretchBlt */
1839 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1840 HBRUSH hBrush
, hBrushOld
;
1841 HBITMAP hBmp
= 0, hBmpOld
= 0;
1842 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchBlt
->offBmiSrc
);
1844 SetWorldTransform(hdcSrc
, &pStretchBlt
->xformSrc
);
1846 hBrush
= CreateSolidBrush(pStretchBlt
->crBkColorSrc
);
1847 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1848 PatBlt(hdcSrc
, pStretchBlt
->rclBounds
.left
, pStretchBlt
->rclBounds
.top
,
1849 pStretchBlt
->rclBounds
.right
- pStretchBlt
->rclBounds
.left
,
1850 pStretchBlt
->rclBounds
.bottom
- pStretchBlt
->rclBounds
.top
, PATCOPY
);
1851 SelectObject(hdcSrc
, hBrushOld
);
1852 DeleteObject(hBrush
);
1854 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1855 (const BYTE
*)mr
+ pStretchBlt
->offBitsSrc
, pbi
, pStretchBlt
->iUsageSrc
);
1856 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1858 StretchBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1859 hdcSrc
, pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1860 pStretchBlt
->dwRop
);
1862 SelectObject(hdcSrc
, hBmpOld
);
1869 case EMR_ALPHABLEND
:
1871 const EMRALPHABLEND
*pAlphaBlend
= (const EMRALPHABLEND
*)mr
;
1873 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1874 pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1875 pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1876 pAlphaBlend
->dwRop
, pAlphaBlend
->offBitsSrc
);
1878 if(pAlphaBlend
->offBmiSrc
== 0) {
1879 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1881 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1882 HBITMAP hBmp
= 0, hBmpOld
= 0;
1883 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pAlphaBlend
->offBmiSrc
);
1884 BLENDFUNCTION blendfn
;
1887 SetWorldTransform(hdcSrc
, &pAlphaBlend
->xformSrc
);
1889 hBmp
= CreateDIBSection(hdc
, pbi
, pAlphaBlend
->iUsageSrc
, &bits
, NULL
, 0);
1890 memcpy(bits
, (const BYTE
*)mr
+ pAlphaBlend
->offBitsSrc
, pAlphaBlend
->cbBitsSrc
);
1891 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1893 blendfn
.BlendOp
= (pAlphaBlend
->dwRop
>> 24) & 0xff;
1894 blendfn
.BlendFlags
= (pAlphaBlend
->dwRop
>> 16) & 0xff;
1895 blendfn
.SourceConstantAlpha
= (pAlphaBlend
->dwRop
>> 8) & 0xff;
1896 blendfn
.AlphaFormat
= (pAlphaBlend
->dwRop
) & 0xff;
1898 GdiAlphaBlend(hdc
, pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1899 hdcSrc
, pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1902 SelectObject(hdcSrc
, hBmpOld
);
1911 const EMRMASKBLT
*pMaskBlt
= (const EMRMASKBLT
*)mr
;
1912 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1913 HBRUSH hBrush
, hBrushOld
;
1914 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1915 const BITMAPINFO
*pbi
;
1917 SetWorldTransform(hdcSrc
, &pMaskBlt
->xformSrc
);
1919 hBrush
= CreateSolidBrush(pMaskBlt
->crBkColorSrc
);
1920 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1921 PatBlt(hdcSrc
, pMaskBlt
->rclBounds
.left
, pMaskBlt
->rclBounds
.top
,
1922 pMaskBlt
->rclBounds
.right
- pMaskBlt
->rclBounds
.left
,
1923 pMaskBlt
->rclBounds
.bottom
- pMaskBlt
->rclBounds
.top
, PATCOPY
);
1924 SelectObject(hdcSrc
, hBrushOld
);
1925 DeleteObject(hBrush
);
1927 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiMask
);
1928 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
1930 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
1931 (const BYTE
*)mr
+ pMaskBlt
->offBitsMask
, pbi
, pMaskBlt
->iUsageMask
);
1933 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiSrc
);
1934 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1935 (const BYTE
*)mr
+ pMaskBlt
->offBitsSrc
, pbi
, pMaskBlt
->iUsageSrc
);
1936 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1949 SelectObject(hdcSrc
, hBmpOld
);
1951 DeleteObject(hBmpMask
);
1958 const EMRPLGBLT
*pPlgBlt
= (const EMRPLGBLT
*)mr
;
1959 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1960 HBRUSH hBrush
, hBrushOld
;
1961 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1962 const BITMAPINFO
*pbi
;
1965 SetWorldTransform(hdcSrc
, &pPlgBlt
->xformSrc
);
1967 pts
[0].x
= pPlgBlt
->aptlDest
[0].x
; pts
[0].y
= pPlgBlt
->aptlDest
[0].y
;
1968 pts
[1].x
= pPlgBlt
->aptlDest
[1].x
; pts
[1].y
= pPlgBlt
->aptlDest
[1].y
;
1969 pts
[2].x
= pPlgBlt
->aptlDest
[2].x
; pts
[2].y
= pPlgBlt
->aptlDest
[2].y
;
1971 hBrush
= CreateSolidBrush(pPlgBlt
->crBkColorSrc
);
1972 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1973 PatBlt(hdcSrc
, pPlgBlt
->rclBounds
.left
, pPlgBlt
->rclBounds
.top
,
1974 pPlgBlt
->rclBounds
.right
- pPlgBlt
->rclBounds
.left
,
1975 pPlgBlt
->rclBounds
.bottom
- pPlgBlt
->rclBounds
.top
, PATCOPY
);
1976 SelectObject(hdcSrc
, hBrushOld
);
1977 DeleteObject(hBrush
);
1979 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiMask
);
1980 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
1982 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
1983 (const BYTE
*)mr
+ pPlgBlt
->offBitsMask
, pbi
, pPlgBlt
->iUsageMask
);
1985 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiSrc
);
1986 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1987 (const BYTE
*)mr
+ pPlgBlt
->offBitsSrc
, pbi
, pPlgBlt
->iUsageSrc
);
1988 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1999 SelectObject(hdcSrc
, hBmpOld
);
2001 DeleteObject(hBmpMask
);
2006 case EMR_SETDIBITSTODEVICE
:
2008 const EMRSETDIBITSTODEVICE
*pSetDIBitsToDevice
= (const EMRSETDIBITSTODEVICE
*)mr
;
2010 SetDIBitsToDevice(hdc
,
2011 pSetDIBitsToDevice
->xDest
,
2012 pSetDIBitsToDevice
->yDest
,
2013 pSetDIBitsToDevice
->cxSrc
,
2014 pSetDIBitsToDevice
->cySrc
,
2015 pSetDIBitsToDevice
->xSrc
,
2016 pSetDIBitsToDevice
->ySrc
,
2017 pSetDIBitsToDevice
->iStartScan
,
2018 pSetDIBitsToDevice
->cScans
,
2019 (const BYTE
*)mr
+ pSetDIBitsToDevice
->offBitsSrc
,
2020 (const BITMAPINFO
*)((const BYTE
*)mr
+ pSetDIBitsToDevice
->offBmiSrc
),
2021 pSetDIBitsToDevice
->iUsageSrc
);
2025 case EMR_POLYTEXTOUTA
:
2027 const EMRPOLYTEXTOUTA
*pPolyTextOutA
= (const EMRPOLYTEXTOUTA
*)mr
;
2028 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
2030 XFORM xform
, xformOld
;
2033 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
2034 GetWorldTransform(hdc
, &xformOld
);
2036 xform
.eM11
= pPolyTextOutA
->exScale
;
2039 xform
.eM22
= pPolyTextOutA
->eyScale
;
2042 SetWorldTransform(hdc
, &xform
);
2044 /* Set up POLYTEXTA structures */
2045 for(i
= 0; i
< pPolyTextOutA
->cStrings
; i
++)
2047 polytextA
[i
].x
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.x
;
2048 polytextA
[i
].y
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.y
;
2049 polytextA
[i
].n
= pPolyTextOutA
->aemrtext
[i
].nChars
;
2050 polytextA
[i
].lpstr
= (LPCSTR
)((const BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offString
);
2051 polytextA
[i
].uiFlags
= pPolyTextOutA
->aemrtext
[i
].fOptions
;
2052 polytextA
[i
].rcl
.left
= pPolyTextOutA
->aemrtext
[i
].rcl
.left
;
2053 polytextA
[i
].rcl
.right
= pPolyTextOutA
->aemrtext
[i
].rcl
.right
;
2054 polytextA
[i
].rcl
.top
= pPolyTextOutA
->aemrtext
[i
].rcl
.top
;
2055 polytextA
[i
].rcl
.bottom
= pPolyTextOutA
->aemrtext
[i
].rcl
.bottom
;
2056 polytextA
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offDx
);
2058 PolyTextOutA(hdc
, polytextA
, pPolyTextOutA
->cStrings
);
2059 HeapFree(GetProcessHeap(), 0, polytextA
);
2061 SetWorldTransform(hdc
, &xformOld
);
2062 SetGraphicsMode(hdc
, gModeOld
);
2066 case EMR_POLYTEXTOUTW
:
2068 const EMRPOLYTEXTOUTW
*pPolyTextOutW
= (const EMRPOLYTEXTOUTW
*)mr
;
2069 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
2071 XFORM xform
, xformOld
;
2074 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
2075 GetWorldTransform(hdc
, &xformOld
);
2077 xform
.eM11
= pPolyTextOutW
->exScale
;
2080 xform
.eM22
= pPolyTextOutW
->eyScale
;
2083 SetWorldTransform(hdc
, &xform
);
2085 /* Set up POLYTEXTW structures */
2086 for(i
= 0; i
< pPolyTextOutW
->cStrings
; i
++)
2088 polytextW
[i
].x
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.x
;
2089 polytextW
[i
].y
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.y
;
2090 polytextW
[i
].n
= pPolyTextOutW
->aemrtext
[i
].nChars
;
2091 polytextW
[i
].lpstr
= (LPCWSTR
)((const BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offString
);
2092 polytextW
[i
].uiFlags
= pPolyTextOutW
->aemrtext
[i
].fOptions
;
2093 polytextW
[i
].rcl
.left
= pPolyTextOutW
->aemrtext
[i
].rcl
.left
;
2094 polytextW
[i
].rcl
.right
= pPolyTextOutW
->aemrtext
[i
].rcl
.right
;
2095 polytextW
[i
].rcl
.top
= pPolyTextOutW
->aemrtext
[i
].rcl
.top
;
2096 polytextW
[i
].rcl
.bottom
= pPolyTextOutW
->aemrtext
[i
].rcl
.bottom
;
2097 polytextW
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offDx
);
2099 PolyTextOutW(hdc
, polytextW
, pPolyTextOutW
->cStrings
);
2100 HeapFree(GetProcessHeap(), 0, polytextW
);
2102 SetWorldTransform(hdc
, &xformOld
);
2103 SetGraphicsMode(hdc
, gModeOld
);
2109 const EMRFILLRGN
*pFillRgn
= (const EMRFILLRGN
*)mr
;
2110 HRGN hRgn
= ExtCreateRegion(NULL
, pFillRgn
->cbRgnData
, (RGNDATA
*)pFillRgn
->RgnData
);
2113 (handletable
->objectHandle
)[pFillRgn
->ihBrush
]);
2120 const EMRFRAMERGN
*pFrameRgn
= (const EMRFRAMERGN
*)mr
;
2121 HRGN hRgn
= ExtCreateRegion(NULL
, pFrameRgn
->cbRgnData
, (RGNDATA
*)pFrameRgn
->RgnData
);
2124 (handletable
->objectHandle
)[pFrameRgn
->ihBrush
],
2125 pFrameRgn
->szlStroke
.cx
,
2126 pFrameRgn
->szlStroke
.cy
);
2133 const EMRINVERTRGN
*pInvertRgn
= (const EMRINVERTRGN
*)mr
;
2134 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (RGNDATA
*)pInvertRgn
->RgnData
);
2135 InvertRgn(hdc
, hRgn
);
2142 const EMRPAINTRGN
*pPaintRgn
= (const EMRPAINTRGN
*)mr
;
2143 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (RGNDATA
*)pPaintRgn
->RgnData
);
2144 PaintRgn(hdc
, hRgn
);
2149 case EMR_SETTEXTJUSTIFICATION
:
2151 const EMRSETTEXTJUSTIFICATION
*pSetTextJust
= (const EMRSETTEXTJUSTIFICATION
*)mr
;
2152 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
2158 const EMRSETLAYOUT
*pSetLayout
= (const EMRSETLAYOUT
*)mr
;
2159 SetLayout(hdc
, pSetLayout
->iMode
);
2163 case EMR_POLYDRAW16
:
2165 case EMR_GLSBOUNDEDRECORD
:
2166 case EMR_DRAWESCAPE
:
2169 case EMR_SMALLTEXTOUT
:
2170 case EMR_FORCEUFIMAPPING
:
2171 case EMR_NAMEDESCAPE
:
2172 case EMR_COLORCORRECTPALETTE
:
2173 case EMR_SETICMPROFILEA
:
2174 case EMR_SETICMPROFILEW
:
2175 case EMR_TRANSPARENTBLT
:
2176 case EMR_GRADIENTFILL
:
2177 case EMR_SETLINKEDUFI
:
2178 case EMR_COLORMATCHTOTARGETW
:
2179 case EMR_CREATECOLORSPACEW
:
2182 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2183 record then ignore and return TRUE. */
2184 FIXME("type %d is unimplemented\n", type
);
2187 tmprc
.left
= tmprc
.top
= 0;
2188 tmprc
.right
= tmprc
.bottom
= 1000;
2189 LPtoDP(hdc
, (POINT
*)&tmprc
, 2);
2190 TRACE("L:0,0 - 1000,1000 -> D:%d,%d - %d,%d\n", tmprc
.left
,
2191 tmprc
.top
, tmprc
.right
, tmprc
.bottom
);
2197 /*****************************************************************************
2199 * EnumEnhMetaFile (GDI32.@)
2201 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2203 * record. Returns when either every record has been used or
2204 * when _EnhMetaFunc_ returns FALSE.
2208 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2215 * This function behaves differently in Win9x and WinNT.
2217 * In WinNT, the DC's world transform is updated as the EMF changes
2218 * the Window/Viewport Extent and Origin or it's world transform.
2219 * The actual Window/Viewport Extent and Origin are left untouched.
2221 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2222 * updates the scaling itself but only just before a record that
2223 * writes anything to the DC.
2225 * I'm not sure where the data (enum_emh_data) is stored in either
2226 * version. For this implementation, it is stored before the handle
2227 * table, but it could be stored in the DC, in the EMF handle or in
2231 BOOL WINAPI
EnumEnhMetaFile(
2232 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
2233 HENHMETAFILE hmf
, /* [in] EMF to walk */
2234 ENHMFENUMPROC callback
, /* [in] callback function */
2235 LPVOID data
, /* [in] optional data for callback function */
2236 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
2248 HBRUSH hBrush
= NULL
;
2251 enum_emh_data
*info
;
2252 SIZE vp_size
, win_size
;
2253 POINT vp_org
, win_org
;
2254 INT mapMode
= MM_TEXT
, old_align
= 0, old_rop2
= 0, old_arcdir
= 0, old_polyfill
= 0, old_stretchblt
= 0;
2255 COLORREF old_text_color
= 0, old_bk_color
= 0;
2259 SetLastError(ERROR_INVALID_PARAMETER
);
2263 emh
= EMF_GetEnhMetaHeader(hmf
);
2265 SetLastError(ERROR_INVALID_HANDLE
);
2269 info
= HeapAlloc( GetProcessHeap(), 0,
2270 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2273 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2276 info
->state
.wndOrgX
= 0;
2277 info
->state
.wndOrgY
= 0;
2278 info
->state
.wndExtX
= 1;
2279 info
->state
.wndExtY
= 1;
2280 info
->state
.vportOrgX
= 0;
2281 info
->state
.vportOrgY
= 0;
2282 info
->state
.vportExtX
= 1;
2283 info
->state
.vportExtY
= 1;
2284 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
2285 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
2286 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
2288 info
->state
.next
= NULL
;
2289 info
->save_level
= 0;
2290 info
->saved_state
= NULL
;
2292 ht
= (HANDLETABLE
*) &info
[1];
2293 ht
->objectHandle
[0] = hmf
;
2294 for(i
= 1; i
< emh
->nHandles
; i
++)
2295 ht
->objectHandle
[i
] = NULL
;
2299 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
2300 GetWorldTransform(hdc
, &savedXform
);
2301 GetViewportExtEx(hdc
, &vp_size
);
2302 GetWindowExtEx(hdc
, &win_size
);
2303 GetViewportOrgEx(hdc
, &vp_org
);
2304 GetWindowOrgEx(hdc
, &win_org
);
2305 mapMode
= GetMapMode(hdc
);
2308 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
2309 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
2310 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
2312 hRgn
= CreateRectRgn(0, 0, 0, 0);
2313 if (!GetClipRgn(hdc
, hRgn
))
2319 old_text_color
= SetTextColor(hdc
, RGB(0,0,0));
2320 old_bk_color
= SetBkColor(hdc
, RGB(0xff, 0xff, 0xff));
2321 old_align
= SetTextAlign(hdc
, 0);
2322 old_rop2
= SetROP2(hdc
, R2_COPYPEN
);
2323 old_arcdir
= SetArcDirection(hdc
, AD_COUNTERCLOCKWISE
);
2324 old_polyfill
= SetPolyFillMode(hdc
, ALTERNATE
);
2325 old_stretchblt
= SetStretchBltMode(hdc
, BLACKONWHITE
);
2328 info
->state
.mode
= MM_TEXT
;
2332 /* Win95 leaves the vp/win ext/org info alone */
2333 info
->init_transform
.eM11
= 1.0;
2334 info
->init_transform
.eM12
= 0.0;
2335 info
->init_transform
.eM21
= 0.0;
2336 info
->init_transform
.eM22
= 1.0;
2337 info
->init_transform
.eDx
= 0.0;
2338 info
->init_transform
.eDy
= 0.0;
2342 /* WinNT combines the vp/win ext/org info into a transform */
2343 double xscale
, yscale
;
2344 xscale
= (double)vp_size
.cx
/ (double)win_size
.cx
;
2345 yscale
= (double)vp_size
.cy
/ (double)win_size
.cy
;
2346 info
->init_transform
.eM11
= xscale
;
2347 info
->init_transform
.eM12
= 0.0;
2348 info
->init_transform
.eM21
= 0.0;
2349 info
->init_transform
.eM22
= yscale
;
2350 info
->init_transform
.eDx
= (double)vp_org
.x
- xscale
* (double)win_org
.x
;
2351 info
->init_transform
.eDy
= (double)vp_org
.y
- yscale
* (double)win_org
.y
;
2353 CombineTransform(&info
->init_transform
, &savedXform
, &info
->init_transform
);
2356 if ( lpRect
&& WIDTH(emh
->rclFrame
) && HEIGHT(emh
->rclFrame
) )
2358 double xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
2361 TRACE("rect: %d,%d - %d,%d. rclFrame: %d,%d - %d,%d\n",
2362 lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
,
2363 emh
->rclFrame
.left
, emh
->rclFrame
.top
, emh
->rclFrame
.right
,
2364 emh
->rclFrame
.bottom
);
2366 xSrcPixSize
= (double) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
2367 ySrcPixSize
= (double) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
2368 xscale
= (double) WIDTH(*lpRect
) * 100.0 /
2369 WIDTH(emh
->rclFrame
) * xSrcPixSize
;
2370 yscale
= (double) HEIGHT(*lpRect
) * 100.0 /
2371 HEIGHT(emh
->rclFrame
) * ySrcPixSize
;
2372 TRACE("xscale = %f, yscale = %f\n", xscale
, yscale
);
2374 xform
.eM11
= xscale
;
2377 xform
.eM22
= yscale
;
2378 xform
.eDx
= (double) lpRect
->left
- (double) WIDTH(*lpRect
) / WIDTH(emh
->rclFrame
) * emh
->rclFrame
.left
;
2379 xform
.eDy
= (double) lpRect
->top
- (double) HEIGHT(*lpRect
) / HEIGHT(emh
->rclFrame
) * emh
->rclFrame
.top
;
2381 CombineTransform(&info
->init_transform
, &xform
, &info
->init_transform
);
2384 /* WinNT resets the current vp/win org/ext */
2385 if ( !IS_WIN9X() && hdc
)
2387 SetMapMode(hdc
, MM_TEXT
);
2388 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2389 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2390 EMF_Update_MF_Xform(hdc
, info
);
2395 while(ret
&& offset
< emh
->nBytes
)
2397 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
2399 /* In Win9x mode we update the xform if the record will produce output */
2400 if (hdc
&& IS_WIN9X() && emr_produces_output(emr
->iType
))
2401 EMF_Update_MF_Xform(hdc
, info
);
2403 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr
->iType
), emr
->nSize
);
2404 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nHandles
, (LPARAM
)data
);
2405 offset
+= emr
->nSize
;
2407 /* WinNT - update the transform (win9x updates when the next graphics
2408 output record is played). */
2409 if (hdc
&& !IS_WIN9X())
2410 EMF_Update_MF_Xform(hdc
, info
);
2415 SetStretchBltMode(hdc
, old_stretchblt
);
2416 SetPolyFillMode(hdc
, old_polyfill
);
2417 SetArcDirection(hdc
, old_arcdir
);
2418 SetROP2(hdc
, old_rop2
);
2419 SetTextAlign(hdc
, old_align
);
2420 SetBkColor(hdc
, old_bk_color
);
2421 SetTextColor(hdc
, old_text_color
);
2424 SelectObject(hdc
, hBrush
);
2425 SelectObject(hdc
, hPen
);
2426 SelectObject(hdc
, hFont
);
2427 ExtSelectClipRgn(hdc
, hRgn
, RGN_COPY
);
2430 SetWorldTransform(hdc
, &savedXform
);
2432 SetGraphicsMode(hdc
, savedMode
);
2433 SetMapMode(hdc
, mapMode
);
2434 SetWindowOrgEx(hdc
, win_org
.x
, win_org
.y
, NULL
);
2435 SetWindowExtEx(hdc
, win_size
.cx
, win_size
.cy
, NULL
);
2436 SetViewportOrgEx(hdc
, vp_org
.x
, vp_org
.y
, NULL
);
2437 SetViewportExtEx(hdc
, vp_size
.cx
, vp_size
.cy
, NULL
);
2440 for(i
= 1; i
< emh
->nHandles
; i
++) /* Don't delete element 0 (hmf) */
2441 if( (ht
->objectHandle
)[i
] )
2442 DeleteObject( (ht
->objectHandle
)[i
] );
2444 while (info
->saved_state
)
2446 EMF_dc_state
*state
= info
->saved_state
;
2447 info
->saved_state
= info
->saved_state
->next
;
2448 HeapFree( GetProcessHeap(), 0, state
);
2450 HeapFree( GetProcessHeap(), 0, info
);
2454 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
2455 const ENHMETARECORD
*emr
,
2456 INT handles
, LPARAM data
)
2458 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
2461 /**************************************************************************
2462 * PlayEnhMetaFile (GDI32.@)
2464 * Renders an enhanced metafile into a specified rectangle *lpRect
2465 * in device context hdc.
2471 BOOL WINAPI
PlayEnhMetaFile(
2472 HDC hdc
, /* [in] DC to render into */
2473 HENHMETAFILE hmf
, /* [in] metafile to render */
2474 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
2477 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
2481 /*****************************************************************************
2482 * DeleteEnhMetaFile (GDI32.@)
2484 * Deletes an enhanced metafile and frees the associated storage.
2486 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
2488 return EMF_Delete_HENHMETAFILE( hmf
);
2491 /*****************************************************************************
2492 * CopyEnhMetaFileA (GDI32.@)
2494 * Duplicate an enhanced metafile.
2498 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
2499 HENHMETAFILE hmfSrc
,
2502 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2503 HENHMETAFILE hmfDst
;
2505 if(!emrSrc
) return FALSE
;
2507 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2508 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2509 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, FALSE
);
2513 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2514 NULL
, CREATE_ALWAYS
, 0, 0);
2515 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2516 CloseHandle( hFile
);
2517 /* Reopen file for reading only, so that apps can share
2518 read access to the file while hmf is still valid */
2519 hFile
= CreateFileA( file
, GENERIC_READ
, FILE_SHARE_READ
,
2520 NULL
, OPEN_EXISTING
, 0, 0);
2521 if(hFile
== INVALID_HANDLE_VALUE
) {
2522 ERR("Can't reopen emf for reading\n");
2525 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2526 CloseHandle( hFile
);
2531 /*****************************************************************************
2532 * CopyEnhMetaFileW (GDI32.@)
2534 * See CopyEnhMetaFileA.
2538 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2539 HENHMETAFILE hmfSrc
,
2542 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2543 HENHMETAFILE hmfDst
;
2545 if(!emrSrc
) return FALSE
;
2547 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2548 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2549 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, FALSE
);
2553 hFile
= CreateFileW( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2554 NULL
, CREATE_ALWAYS
, 0, 0);
2555 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2556 CloseHandle( hFile
);
2557 /* Reopen file for reading only, so that apps can share
2558 read access to the file while hmf is still valid */
2559 hFile
= CreateFileW( file
, GENERIC_READ
, FILE_SHARE_READ
,
2560 NULL
, OPEN_EXISTING
, 0, 0);
2561 if(hFile
== INVALID_HANDLE_VALUE
) {
2562 ERR("Can't reopen emf for reading\n");
2565 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2566 CloseHandle( hFile
);
2572 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2573 typedef struct tagEMF_PaletteCopy
2576 LPPALETTEENTRY lpPe
;
2579 /***************************************************************
2580 * Find the EMR_EOF record and then use it to find the
2581 * palette entries for this enhanced metafile.
2582 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2583 * which contains the max number of elements to copy and where
2586 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2588 static INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2590 const ENHMETARECORD
*lpEMR
,
2595 if ( lpEMR
->iType
== EMR_EOF
)
2597 const EMREOF
*lpEof
= (const EMREOF
*)lpEMR
;
2598 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
2599 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
2601 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy
);
2603 memcpy( (LPVOID
)info
->lpPe
,
2604 (LPCVOID
)(((LPCSTR
)lpEof
) + lpEof
->offPalEntries
),
2605 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
2607 /* Update the passed data as a return code */
2608 info
->lpPe
= NULL
; /* Palettes were copied! */
2609 info
->cEntries
= dwNumPalToCopy
;
2611 return FALSE
; /* That's all we need */
2617 /*****************************************************************************
2618 * GetEnhMetaFilePaletteEntries (GDI32.@)
2620 * Copy the palette and report size
2622 * BUGS: Error codes (SetLastError) are not set on failures
2624 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
2626 LPPALETTEENTRY lpPe
)
2628 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
2629 EMF_PaletteCopy infoForCallBack
;
2631 TRACE( "(%p,%d,%p)\n", hEmf
, cEntries
, lpPe
);
2633 if (!enhHeader
) return 0;
2635 /* First check if there are any palettes associated with
2637 if ( enhHeader
->nPalEntries
== 0 ) return 0;
2639 /* Is the user requesting the number of palettes? */
2640 if ( lpPe
== NULL
) return enhHeader
->nPalEntries
;
2642 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2643 infoForCallBack
.cEntries
= cEntries
;
2644 infoForCallBack
.lpPe
= lpPe
;
2646 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
2647 &infoForCallBack
, 0 ) )
2650 /* Verify that the callback executed correctly */
2651 if ( infoForCallBack
.lpPe
!= NULL
)
2653 /* Callback proc had error! */
2654 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2658 return infoForCallBack
.cEntries
;
2661 typedef struct gdi_mf_comment
2668 DWORD cbWinMetaFile
;
2671 /******************************************************************
2672 * SetWinMetaFileBits (GDI32.@)
2674 * Translate from old style to new style.
2677 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
,
2678 CONST BYTE
*lpbBuffer
,
2680 CONST METAFILEPICT
*lpmfp
2683 static const WCHAR szDisplayW
[] = { 'D','I','S','P','L','A','Y','\0' };
2684 HMETAFILE hmf
= NULL
;
2685 HENHMETAFILE ret
= NULL
;
2686 HDC hdc
= NULL
, hdcdisp
= NULL
;
2687 RECT rc
, *prcFrame
= NULL
;
2688 LONG mm
, xExt
, yExt
;
2689 INT horzsize
, vertsize
, horzres
, vertres
;
2691 TRACE("(%d, %p, %p, %p)\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
2693 hmf
= SetMetaFileBitsEx(cbBuffer
, lpbBuffer
);
2696 WARN("SetMetaFileBitsEx failed\n");
2701 hdcRef
= hdcdisp
= CreateDCW(szDisplayW
, NULL
, NULL
, NULL
);
2705 TRACE("mm = %d %dx%d\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2713 TRACE("lpmfp == NULL\n");
2715 /* Use the whole device surface */
2716 mm
= MM_ANISOTROPIC
;
2721 if (mm
== MM_ISOTROPIC
|| mm
== MM_ANISOTROPIC
)
2723 if (xExt
< 0 || yExt
< 0)
2725 /* Use the whole device surface */
2730 /* Use the x and y extents as the frame box */
2733 rc
.left
= rc
.top
= 0;
2740 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
)))
2742 ERR("CreateEnhMetaFile failed\n");
2747 * Write the original METAFILE into the enhanced metafile.
2748 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2752 gdi_mf_comment
*mfcomment
;
2753 UINT mfcomment_size
;
2755 mfcomment_size
= sizeof (gdi_mf_comment
) + cbBuffer
;
2756 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
2759 mfcomment
->ident
= GDICOMMENT_IDENTIFIER
;
2760 mfcomment
->iComment
= GDICOMMENT_WINDOWS_METAFILE
;
2761 mfcomment
->nVersion
= 0x00000300;
2762 mfcomment
->nChecksum
= 0; /* FIXME */
2763 mfcomment
->fFlags
= 0;
2764 mfcomment
->cbWinMetaFile
= cbBuffer
;
2765 memcpy(&mfcomment
[1], lpbBuffer
, cbBuffer
);
2766 GdiComment(hdc
, mfcomment_size
, (BYTE
*) mfcomment
);
2767 HeapFree(GetProcessHeap(), 0, mfcomment
);
2769 SetMapMode(hdc
, mm
);
2773 horzsize
= GetDeviceCaps(hdcRef
, HORZSIZE
);
2774 vertsize
= GetDeviceCaps(hdcRef
, VERTSIZE
);
2775 horzres
= GetDeviceCaps(hdcRef
, HORZRES
);
2776 vertres
= GetDeviceCaps(hdcRef
, VERTRES
);
2780 /* Use the whole device surface */
2786 xExt
= MulDiv(xExt
, horzres
, 100 * horzsize
);
2787 yExt
= MulDiv(yExt
, vertres
, 100 * vertsize
);
2790 /* set the initial viewport:window ratio as 1:1 */
2791 SetViewportExtEx(hdc
, xExt
, yExt
, NULL
);
2792 SetWindowExtEx(hdc
, xExt
, yExt
, NULL
);
2794 PlayMetaFile(hdc
, hmf
);
2796 ret
= CloseEnhMetaFile(hdc
);
2798 if (hdcdisp
) DeleteDC(hdcdisp
);
2799 DeleteMetaFile(hmf
);