2 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * The enhanced format consists of the following elements:
25 * A table of handles to GDI objects
26 * An array of metafile records
30 * The standard format consists of a header and an array of metafile records.
35 #include "wine/port.h"
46 #include "gdi_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile
);
54 BOOL on_disk
; /* true if metafile is on disk */
57 static const struct emr_name
{
70 X(EMR_SETWINDOWEXTEX
),
71 X(EMR_SETWINDOWORGEX
),
72 X(EMR_SETVIEWPORTEXTEX
),
73 X(EMR_SETVIEWPORTORGEX
),
77 X(EMR_SETMAPPERFLAGS
),
80 X(EMR_SETPOLYFILLMODE
),
82 X(EMR_SETSTRETCHBLTMODE
),
84 X(EMR_SETCOLORADJUSTMENT
),
90 X(EMR_EXCLUDECLIPRECT
),
91 X(EMR_INTERSECTCLIPRECT
),
92 X(EMR_SCALEVIEWPORTEXTEX
),
93 X(EMR_SCALEWINDOWEXTEX
),
96 X(EMR_SETWORLDTRANSFORM
),
97 X(EMR_MODIFYWORLDTRANSFORM
),
100 X(EMR_CREATEBRUSHINDIRECT
),
109 X(EMR_SELECTPALETTE
),
110 X(EMR_CREATEPALETTE
),
111 X(EMR_SETPALETTEENTRIES
),
112 X(EMR_RESIZEPALETTE
),
113 X(EMR_REALIZEPALETTE
),
118 X(EMR_SETARCDIRECTION
),
119 X(EMR_SETMITERLIMIT
),
124 X(EMR_STROKEANDFILLPATH
),
128 X(EMR_SELECTCLIPPATH
),
135 X(EMR_EXTSELECTCLIPRGN
),
140 X(EMR_SETDIBITSTODEVICE
),
141 X(EMR_STRETCHDIBITS
),
142 X(EMR_EXTCREATEFONTINDIRECTW
),
148 X(EMR_POLYBEZIERTO16
),
150 X(EMR_POLYPOLYLINE16
),
151 X(EMR_POLYPOLYGON16
),
153 X(EMR_CREATEMONOBRUSH
),
154 X(EMR_CREATEDIBPATTERNBRUSHPT
),
159 X(EMR_CREATECOLORSPACE
),
160 X(EMR_SETCOLORSPACE
),
161 X(EMR_DELETECOLORSPACE
),
163 X(EMR_GLSBOUNDEDRECORD
),
169 X(EMR_FORCEUFIMAPPING
),
171 X(EMR_COLORCORRECTPALETTE
),
172 X(EMR_SETICMPROFILEA
),
173 X(EMR_SETICMPROFILEW
),
176 X(EMR_TRANSPARENTBLT
),
180 X(EMR_SETTEXTJUSTIFICATION
),
181 X(EMR_COLORMATCHTOTARGETW
),
182 X(EMR_CREATECOLORSPACEW
)
186 /****************************************************************************
189 static const char *get_emr_name(DWORD type
)
192 for(i
= 0; i
< ARRAY_SIZE(emr_names
); i
++)
193 if(type
== emr_names
[i
].type
) return emr_names
[i
].name
;
194 TRACE("Unknown record type %d\n", type
);
198 /***********************************************************************
201 * Returns whether a DIB can be converted to a monochrome DDB.
203 * A DIB can be converted if its color table contains only black and
204 * white. Black must be the first color in the color table.
206 * Note : If the first color in the color table is white followed by
207 * black, we can't convert it to a monochrome DDB with
208 * SetDIBits, because black and white would be inverted.
210 static inline BOOL
is_dib_monochrome( const BITMAPINFO
* info
)
212 if (info
->bmiHeader
.biBitCount
!= 1) return FALSE
;
214 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
216 const RGBTRIPLE
*rgb
= ((const BITMAPCOREINFO
*) info
)->bmciColors
;
218 /* Check if the first color is black */
219 if ((rgb
->rgbtRed
== 0) && (rgb
->rgbtGreen
== 0) && (rgb
->rgbtBlue
== 0))
222 /* Check if the second color is white */
223 return ((rgb
->rgbtRed
== 0xff) && (rgb
->rgbtGreen
== 0xff)
224 && (rgb
->rgbtBlue
== 0xff));
228 else /* assume BITMAPINFOHEADER */
230 const RGBQUAD
*rgb
= info
->bmiColors
;
232 /* Check if the first color is black */
233 if ((rgb
->rgbRed
== 0) && (rgb
->rgbGreen
== 0) &&
234 (rgb
->rgbBlue
== 0) && (rgb
->rgbReserved
== 0))
238 /* Check if the second color is white */
239 return ((rgb
->rgbRed
== 0xff) && (rgb
->rgbGreen
== 0xff)
240 && (rgb
->rgbBlue
== 0xff) && (rgb
->rgbReserved
== 0));
246 /****************************************************************************
247 * EMF_Create_HENHMETAFILE
249 HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, DWORD filesize
, BOOL on_disk
)
252 ENHMETAFILEOBJ
*metaObj
;
254 if (filesize
< sizeof(*emh
))
256 WARN("File too small for emf header\n");
259 if (emh
->iType
!= EMR_HEADER
)
261 SetLastError(ERROR_INVALID_DATA
);
264 if (emh
->dSignature
!= ENHMETA_SIGNATURE
||
265 (emh
->nBytes
& 3)) /* refuse to load unaligned EMF as Windows does */
267 WARN("Invalid emf header type 0x%08x sig 0x%08x.\n",
268 emh
->iType
, emh
->dSignature
);
271 if (filesize
< emh
->nBytes
)
273 WARN("File truncated (got %u bytes, header says %u)\n", emh
->nBytes
, filesize
);
277 if (!(metaObj
= HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj
) ))) return 0;
280 metaObj
->on_disk
= on_disk
;
282 if (!(hmf
= alloc_gdi_handle( metaObj
, OBJ_ENHMETAFILE
, NULL
)))
283 HeapFree( GetProcessHeap(), 0, metaObj
);
287 /****************************************************************************
288 * EMF_Delete_HENHMETAFILE
290 static BOOL
EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf
)
292 ENHMETAFILEOBJ
*metaObj
= free_gdi_handle( hmf
);
294 if(!metaObj
) return FALSE
;
297 UnmapViewOfFile( metaObj
->emh
);
299 HeapFree( GetProcessHeap(), 0, metaObj
->emh
);
300 HeapFree( GetProcessHeap(), 0, metaObj
);
304 /******************************************************************
305 * EMF_GetEnhMetaHeader
307 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
309 static ENHMETAHEADER
*EMF_GetEnhMetaHeader( HENHMETAFILE hmf
)
311 ENHMETAHEADER
*ret
= NULL
;
312 ENHMETAFILEOBJ
*metaObj
= GDI_GetObjPtr( hmf
, OBJ_ENHMETAFILE
);
313 TRACE("hmf %p -> enhmetaObj %p\n", hmf
, metaObj
);
317 GDI_ReleaseObj( hmf
);
322 /*****************************************************************************
326 static HENHMETAFILE
EMF_GetEnhMetaFile( HANDLE hFile
)
333 filesize
= GetFileSize( hFile
, NULL
);
335 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
336 emh
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, filesize
);
337 CloseHandle( hMapping
);
341 hemf
= EMF_Create_HENHMETAFILE( emh
, filesize
, TRUE
);
343 UnmapViewOfFile( emh
);
348 /*****************************************************************************
349 * GetEnhMetaFileA (GDI32.@)
353 HENHMETAFILE WINAPI
GetEnhMetaFileA(
354 LPCSTR lpszMetaFile
/* [in] filename of enhanced metafile */
360 hFile
= CreateFileA(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
361 OPEN_EXISTING
, 0, 0);
362 if (hFile
== INVALID_HANDLE_VALUE
) {
363 WARN("could not open %s\n", lpszMetaFile
);
366 hmf
= EMF_GetEnhMetaFile( hFile
);
367 CloseHandle( hFile
);
371 /*****************************************************************************
372 * GetEnhMetaFileW (GDI32.@)
374 HENHMETAFILE WINAPI
GetEnhMetaFileW(
375 LPCWSTR lpszMetaFile
) /* [in] filename of enhanced metafile */
380 hFile
= CreateFileW(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
381 OPEN_EXISTING
, 0, 0);
382 if (hFile
== INVALID_HANDLE_VALUE
) {
383 WARN("could not open %s\n", debugstr_w(lpszMetaFile
));
386 hmf
= EMF_GetEnhMetaFile( hFile
);
387 CloseHandle( hFile
);
391 /*****************************************************************************
392 * GetEnhMetaFileHeader (GDI32.@)
394 * Retrieves the record containing the header for the specified
395 * enhanced-format metafile.
398 * If buf is NULL, returns the size of buffer required.
399 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
402 UINT WINAPI
GetEnhMetaFileHeader(
403 HENHMETAFILE hmf
, /* [in] enhanced metafile */
404 UINT bufsize
, /* [in] size of buffer */
405 LPENHMETAHEADER buf
/* [out] buffer */
411 emh
= EMF_GetEnhMetaHeader(hmf
);
412 if(!emh
) return FALSE
;
414 if (!buf
) return size
;
415 size
= min(size
, bufsize
);
416 memmove(buf
, emh
, size
);
421 /*****************************************************************************
422 * GetEnhMetaFileDescriptionA (GDI32.@)
424 * See GetEnhMetaFileDescriptionW.
426 UINT WINAPI
GetEnhMetaFileDescriptionA(
427 HENHMETAFILE hmf
, /* [in] enhanced metafile */
428 UINT size
, /* [in] size of buf */
429 LPSTR buf
/* [out] buffer to receive description */
432 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
436 if(!emh
) return FALSE
;
437 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
438 descrW
= (WCHAR
*) ((char *) emh
+ emh
->offDescription
);
439 len
= WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, NULL
, 0, NULL
, NULL
);
441 if (!buf
|| !size
) return len
;
443 len
= min( size
, len
);
444 WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, buf
, len
, NULL
, NULL
);
448 /*****************************************************************************
449 * GetEnhMetaFileDescriptionW (GDI32.@)
451 * Copies the description string of an enhanced metafile into a buffer
455 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
456 * number of characters copied.
458 UINT WINAPI
GetEnhMetaFileDescriptionW(
459 HENHMETAFILE hmf
, /* [in] enhanced metafile */
460 UINT size
, /* [in] size of buf */
461 LPWSTR buf
/* [out] buffer to receive description */
464 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
466 if(!emh
) return FALSE
;
467 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
468 if (!buf
|| !size
) return emh
->nDescription
;
470 memmove(buf
, (char *) emh
+ emh
->offDescription
, min(size
,emh
->nDescription
)*sizeof(WCHAR
));
471 return min(size
, emh
->nDescription
);
474 /****************************************************************************
475 * SetEnhMetaFileBits (GDI32.@)
477 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
479 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
481 ENHMETAHEADER
*emh
= HeapAlloc( GetProcessHeap(), 0, bufsize
);
485 memcpy(emh
, buf
, bufsize
);
486 hmf
= EMF_Create_HENHMETAFILE( emh
, bufsize
, FALSE
);
488 HeapFree( GetProcessHeap(), 0, emh
);
492 /*****************************************************************************
493 * GetEnhMetaFileBits (GDI32.@)
496 UINT WINAPI
GetEnhMetaFileBits(
502 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
508 if( buf
== NULL
) return size
;
510 size
= min( size
, bufsize
);
511 memmove(buf
, emh
, size
);
515 typedef struct EMF_dc_state
518 XFORM world_transform
;
527 struct EMF_dc_state
*next
;
530 typedef struct enum_emh_data
532 XFORM init_transform
;
535 EMF_dc_state
*saved_state
;
538 #define ENUM_GET_PRIVATE_DATA(ht) \
539 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
541 #define WIDTH(rect) ( (rect).right - (rect).left )
542 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
544 #define IS_WIN9X() (GetVersion()&0x80000000)
546 static void EMF_Update_MF_Xform(HDC hdc
, const enum_emh_data
*info
)
548 XFORM mapping_mode_trans
, final_trans
;
549 double scaleX
, scaleY
;
551 scaleX
= (double)info
->state
.vportExtX
/ (double)info
->state
.wndExtX
;
552 scaleY
= (double)info
->state
.vportExtY
/ (double)info
->state
.wndExtY
;
553 mapping_mode_trans
.eM11
= scaleX
;
554 mapping_mode_trans
.eM12
= 0.0;
555 mapping_mode_trans
.eM21
= 0.0;
556 mapping_mode_trans
.eM22
= scaleY
;
557 mapping_mode_trans
.eDx
= (double)info
->state
.vportOrgX
- scaleX
* (double)info
->state
.wndOrgX
;
558 mapping_mode_trans
.eDy
= (double)info
->state
.vportOrgY
- scaleY
* (double)info
->state
.wndOrgY
;
560 CombineTransform(&final_trans
, &info
->state
.world_transform
, &mapping_mode_trans
);
561 CombineTransform(&final_trans
, &final_trans
, &info
->init_transform
);
563 if (!SetWorldTransform(hdc
, &final_trans
))
565 ERR("World transform failed!\n");
569 static void EMF_RestoreDC( enum_emh_data
*info
, INT level
)
571 if (abs(level
) > info
->save_level
|| level
== 0) return;
573 if (level
< 0) level
= info
->save_level
+ level
+ 1;
575 while (info
->save_level
>= level
)
577 EMF_dc_state
*state
= info
->saved_state
;
578 info
->saved_state
= state
->next
;
580 if (--info
->save_level
< level
)
581 info
->state
= *state
;
582 HeapFree( GetProcessHeap(), 0, state
);
586 static void EMF_SaveDC( enum_emh_data
*info
)
588 EMF_dc_state
*state
= HeapAlloc( GetProcessHeap(), 0, sizeof(*state
));
591 *state
= info
->state
;
592 state
->next
= info
->saved_state
;
593 info
->saved_state
= state
;
595 TRACE("save_level %d\n", info
->save_level
);
599 static void EMF_SetMapMode(HDC hdc
, enum_emh_data
*info
)
601 INT horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
602 INT vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
603 INT horzRes
= GetDeviceCaps( hdc
, HORZRES
);
604 INT vertRes
= GetDeviceCaps( hdc
, VERTRES
);
606 TRACE("%d\n", info
->state
.mode
);
608 switch(info
->state
.mode
)
611 info
->state
.wndExtX
= 1;
612 info
->state
.wndExtY
= 1;
613 info
->state
.vportExtX
= 1;
614 info
->state
.vportExtY
= 1;
618 info
->state
.wndExtX
= horzSize
* 10;
619 info
->state
.wndExtY
= vertSize
* 10;
620 info
->state
.vportExtX
= horzRes
;
621 info
->state
.vportExtY
= -vertRes
;
624 info
->state
.wndExtX
= horzSize
* 100;
625 info
->state
.wndExtY
= vertSize
* 100;
626 info
->state
.vportExtX
= horzRes
;
627 info
->state
.vportExtY
= -vertRes
;
630 info
->state
.wndExtX
= MulDiv(1000, horzSize
, 254);
631 info
->state
.wndExtY
= MulDiv(1000, vertSize
, 254);
632 info
->state
.vportExtX
= horzRes
;
633 info
->state
.vportExtY
= -vertRes
;
636 info
->state
.wndExtX
= MulDiv(10000, horzSize
, 254);
637 info
->state
.wndExtY
= MulDiv(10000, vertSize
, 254);
638 info
->state
.vportExtX
= horzRes
;
639 info
->state
.vportExtY
= -vertRes
;
642 info
->state
.wndExtX
= MulDiv(14400, horzSize
, 254);
643 info
->state
.wndExtY
= MulDiv(14400, vertSize
, 254);
644 info
->state
.vportExtX
= horzRes
;
645 info
->state
.vportExtY
= -vertRes
;
654 /***********************************************************************
657 * Fix viewport extensions for isotropic mode.
660 static void EMF_FixIsotropic(HDC hdc
, enum_emh_data
*info
)
662 double xdim
= fabs((double)info
->state
.vportExtX
* GetDeviceCaps( hdc
, HORZSIZE
) /
663 (GetDeviceCaps( hdc
, HORZRES
) * info
->state
.wndExtX
));
664 double ydim
= fabs((double)info
->state
.vportExtY
* GetDeviceCaps( hdc
, VERTSIZE
) /
665 (GetDeviceCaps( hdc
, VERTRES
) * info
->state
.wndExtY
));
669 INT mincx
= (info
->state
.vportExtX
>= 0) ? 1 : -1;
670 info
->state
.vportExtX
= floor(info
->state
.vportExtX
* ydim
/ xdim
+ 0.5);
671 if (!info
->state
.vportExtX
) info
->state
.vportExtX
= mincx
;
675 INT mincy
= (info
->state
.vportExtY
>= 0) ? 1 : -1;
676 info
->state
.vportExtY
= floor(info
->state
.vportExtY
* xdim
/ ydim
+ 0.5);
677 if (!info
->state
.vportExtY
) info
->state
.vportExtY
= mincy
;
681 /*****************************************************************************
682 * emr_produces_output
684 * Returns TRUE if the record type writes something to the dc. Used by
685 * PlayEnhMetaFileRecord to determine whether it needs to update the
686 * dc's xform when in win9x mode.
688 * FIXME: need to test which records should be here.
690 static BOOL
emr_produces_output(int type
)
696 case EMR_POLYBEZIERTO
:
698 case EMR_POLYPOLYLINE
:
699 case EMR_POLYPOLYGON
:
702 case EMR_EXCLUDECLIPRECT
:
703 case EMR_INTERSECTCLIPRECT
:
704 case EMR_SELECTOBJECT
:
712 case EMR_EXTFLOODFILL
:
725 case EMR_SETDIBITSTODEVICE
:
726 case EMR_STRETCHDIBITS
:
727 case EMR_EXTTEXTOUTA
:
728 case EMR_EXTTEXTOUTW
:
729 case EMR_POLYBEZIER16
:
732 case EMR_POLYBEZIERTO16
:
733 case EMR_POLYLINETO16
:
734 case EMR_POLYPOLYLINE16
:
735 case EMR_POLYPOLYGON16
:
737 case EMR_POLYTEXTOUTA
:
738 case EMR_POLYTEXTOUTW
:
739 case EMR_SMALLTEXTOUT
:
741 case EMR_TRANSPARENTBLT
:
749 /*****************************************************************************
750 * PlayEnhMetaFileRecord (GDI32.@)
752 * Render a single enhanced metafile record in the device context hdc.
755 * TRUE (non zero) on success, FALSE on error.
757 * Many unimplemented records.
758 * No error handling on record play failures (ie checking return codes)
761 * WinNT actually updates the current world transform in this function
762 * whereas Win9x does not.
764 BOOL WINAPI
PlayEnhMetaFileRecord(
765 HDC hdc
, /* [in] device context in which to render EMF record */
766 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
767 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
768 UINT handles
/* [in] size of handle array */
773 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
775 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
776 hdc
, handletable
, mr
, handles
);
777 if (!mr
) return FALSE
;
781 TRACE("record %s\n", get_emr_name(type
));
790 const EMRGDICOMMENT
*lpGdiComment
= (const EMRGDICOMMENT
*)mr
;
791 /* In an enhanced metafile, there can be both public and private GDI comments */
792 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
797 const EMRSETMAPMODE
*pSetMapMode
= (const EMRSETMAPMODE
*)mr
;
799 if (info
->state
.mode
== pSetMapMode
->iMode
&&
800 (info
->state
.mode
== MM_ISOTROPIC
|| info
->state
.mode
== MM_ANISOTROPIC
))
802 info
->state
.mode
= pSetMapMode
->iMode
;
803 EMF_SetMapMode(hdc
, info
);
806 EMF_Update_MF_Xform(hdc
, info
);
812 const EMRSETBKMODE
*pSetBkMode
= (const EMRSETBKMODE
*)mr
;
813 SetBkMode(hdc
, pSetBkMode
->iMode
);
818 const EMRSETBKCOLOR
*pSetBkColor
= (const EMRSETBKCOLOR
*)mr
;
819 SetBkColor(hdc
, pSetBkColor
->crColor
);
822 case EMR_SETPOLYFILLMODE
:
824 const EMRSETPOLYFILLMODE
*pSetPolyFillMode
= (const EMRSETPOLYFILLMODE
*)mr
;
825 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
830 const EMRSETROP2
*pSetROP2
= (const EMRSETROP2
*)mr
;
831 SetROP2(hdc
, pSetROP2
->iMode
);
834 case EMR_SETSTRETCHBLTMODE
:
836 const EMRSETSTRETCHBLTMODE
*pSetStretchBltMode
= (const EMRSETSTRETCHBLTMODE
*)mr
;
837 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
840 case EMR_SETTEXTALIGN
:
842 const EMRSETTEXTALIGN
*pSetTextAlign
= (const EMRSETTEXTALIGN
*)mr
;
843 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
846 case EMR_SETTEXTCOLOR
:
848 const EMRSETTEXTCOLOR
*pSetTextColor
= (const EMRSETTEXTCOLOR
*)mr
;
849 SetTextColor(hdc
, pSetTextColor
->crColor
);
860 const EMRRESTOREDC
*pRestoreDC
= (const EMRRESTOREDC
*)mr
;
861 TRACE("EMR_RESTORE: %d\n", pRestoreDC
->iRelative
);
862 if (RestoreDC( hdc
, pRestoreDC
->iRelative
))
863 EMF_RestoreDC( info
, pRestoreDC
->iRelative
);
866 case EMR_INTERSECTCLIPRECT
:
868 const EMRINTERSECTCLIPRECT
*pClipRect
= (const EMRINTERSECTCLIPRECT
*)mr
;
869 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
870 pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
871 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
872 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
873 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
876 case EMR_SELECTOBJECT
:
878 const EMRSELECTOBJECT
*pSelectObject
= (const EMRSELECTOBJECT
*)mr
;
879 if( pSelectObject
->ihObject
& 0x80000000 ) {
880 /* High order bit is set - it's a stock object
881 * Strip the high bit to get the index.
882 * See MSDN article Q142319
884 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
887 /* High order bit wasn't set - not a stock object
890 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
894 case EMR_DELETEOBJECT
:
896 const EMRDELETEOBJECT
*pDeleteObject
= (const EMRDELETEOBJECT
*)mr
;
897 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
898 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
901 case EMR_SETWINDOWORGEX
:
903 const EMRSETWINDOWORGEX
*pSetWindowOrgEx
= (const EMRSETWINDOWORGEX
*)mr
;
905 info
->state
.wndOrgX
= pSetWindowOrgEx
->ptlOrigin
.x
;
906 info
->state
.wndOrgY
= pSetWindowOrgEx
->ptlOrigin
.y
;
908 TRACE("SetWindowOrgEx: %d,%d\n", info
->state
.wndOrgX
, info
->state
.wndOrgY
);
911 EMF_Update_MF_Xform(hdc
, info
);
915 case EMR_SETWINDOWEXTEX
:
917 const EMRSETWINDOWEXTEX
*pSetWindowExtEx
= (const EMRSETWINDOWEXTEX
*)mr
;
919 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
921 info
->state
.wndExtX
= pSetWindowExtEx
->szlExtent
.cx
;
922 info
->state
.wndExtY
= pSetWindowExtEx
->szlExtent
.cy
;
923 if (info
->state
.mode
== MM_ISOTROPIC
)
924 EMF_FixIsotropic(hdc
, info
);
926 TRACE("SetWindowExtEx: %d,%d\n",info
->state
.wndExtX
, info
->state
.wndExtY
);
929 EMF_Update_MF_Xform(hdc
, info
);
933 case EMR_SETVIEWPORTORGEX
:
935 const EMRSETVIEWPORTORGEX
*pSetViewportOrgEx
= (const EMRSETVIEWPORTORGEX
*)mr
;
937 info
->state
.vportOrgX
= pSetViewportOrgEx
->ptlOrigin
.x
;
938 info
->state
.vportOrgY
= pSetViewportOrgEx
->ptlOrigin
.y
;
939 TRACE("SetViewportOrgEx: %d,%d\n", info
->state
.vportOrgX
, info
->state
.vportOrgY
);
942 EMF_Update_MF_Xform(hdc
, info
);
946 case EMR_SETVIEWPORTEXTEX
:
948 const EMRSETVIEWPORTEXTEX
*pSetViewportExtEx
= (const EMRSETVIEWPORTEXTEX
*)mr
;
950 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
952 info
->state
.vportExtX
= pSetViewportExtEx
->szlExtent
.cx
;
953 info
->state
.vportExtY
= pSetViewportExtEx
->szlExtent
.cy
;
954 if (info
->state
.mode
== MM_ISOTROPIC
)
955 EMF_FixIsotropic(hdc
, info
);
956 TRACE("SetViewportExtEx: %d,%d\n", info
->state
.vportExtX
, info
->state
.vportExtY
);
959 EMF_Update_MF_Xform(hdc
, info
);
965 const EMRCREATEPEN
*pCreatePen
= (const EMRCREATEPEN
*)mr
;
966 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
967 CreatePenIndirect(&pCreatePen
->lopn
);
970 case EMR_EXTCREATEPEN
:
972 const EMREXTCREATEPEN
*pPen
= (const EMREXTCREATEPEN
*)mr
;
974 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
975 lb
.lbColor
= pPen
->elp
.elpColor
;
976 lb
.lbHatch
= pPen
->elp
.elpHatch
;
978 if(pPen
->offBmi
|| pPen
->offBits
)
979 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
981 (handletable
->objectHandle
)[pPen
->ihPen
] =
982 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
983 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpNumEntries
? pPen
->elp
.elpStyleEntry
: NULL
);
986 case EMR_CREATEBRUSHINDIRECT
:
988 const EMRCREATEBRUSHINDIRECT
*pBrush
= (const EMRCREATEBRUSHINDIRECT
*)mr
;
990 brush
.lbStyle
= pBrush
->lb
.lbStyle
;
991 brush
.lbColor
= pBrush
->lb
.lbColor
;
992 brush
.lbHatch
= pBrush
->lb
.lbHatch
;
993 (handletable
->objectHandle
)[pBrush
->ihBrush
] = CreateBrushIndirect(&brush
);
996 case EMR_EXTCREATEFONTINDIRECTW
:
998 const EMREXTCREATEFONTINDIRECTW
*pFont
= (const EMREXTCREATEFONTINDIRECTW
*)mr
;
999 (handletable
->objectHandle
)[pFont
->ihFont
] =
1000 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
1005 const EMRMOVETOEX
*pMoveToEx
= (const EMRMOVETOEX
*)mr
;
1006 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
1011 const EMRLINETO
*pLineTo
= (const EMRLINETO
*)mr
;
1012 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
1017 const EMRRECTANGLE
*pRect
= (const EMRRECTANGLE
*)mr
;
1018 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
1019 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
1024 const EMRELLIPSE
*pEllipse
= (const EMRELLIPSE
*)mr
;
1025 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
1026 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
1031 const EMRPOLYGON16
*pPoly
= (const EMRPOLYGON16
*)mr
;
1032 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
1033 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1034 pPoly
->cpts
* sizeof(POINT
) );
1036 for(i
= 0; i
< pPoly
->cpts
; i
++)
1038 pts
[i
].x
= pPoly
->apts
[i
].x
;
1039 pts
[i
].y
= pPoly
->apts
[i
].y
;
1041 Polygon(hdc
, pts
, pPoly
->cpts
);
1042 HeapFree( GetProcessHeap(), 0, pts
);
1045 case EMR_POLYLINE16
:
1047 const EMRPOLYLINE16
*pPoly
= (const EMRPOLYLINE16
*)mr
;
1048 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1049 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1050 pPoly
->cpts
* sizeof(POINT
) );
1052 for(i
= 0; i
< pPoly
->cpts
; i
++)
1054 pts
[i
].x
= pPoly
->apts
[i
].x
;
1055 pts
[i
].y
= pPoly
->apts
[i
].y
;
1057 Polyline(hdc
, pts
, pPoly
->cpts
);
1058 HeapFree( GetProcessHeap(), 0, pts
);
1061 case EMR_POLYLINETO16
:
1063 const EMRPOLYLINETO16
*pPoly
= (const EMRPOLYLINETO16
*)mr
;
1064 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1065 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1066 pPoly
->cpts
* sizeof(POINT
) );
1068 for(i
= 0; i
< pPoly
->cpts
; i
++)
1070 pts
[i
].x
= pPoly
->apts
[i
].x
;
1071 pts
[i
].y
= pPoly
->apts
[i
].y
;
1073 PolylineTo(hdc
, pts
, pPoly
->cpts
);
1074 HeapFree( GetProcessHeap(), 0, pts
);
1077 case EMR_POLYBEZIER16
:
1079 const EMRPOLYBEZIER16
*pPoly
= (const EMRPOLYBEZIER16
*)mr
;
1080 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1081 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1082 pPoly
->cpts
* sizeof(POINT
) );
1084 for(i
= 0; i
< pPoly
->cpts
; i
++)
1086 pts
[i
].x
= pPoly
->apts
[i
].x
;
1087 pts
[i
].y
= pPoly
->apts
[i
].y
;
1089 PolyBezier(hdc
, pts
, pPoly
->cpts
);
1090 HeapFree( GetProcessHeap(), 0, pts
);
1093 case EMR_POLYBEZIERTO16
:
1095 const EMRPOLYBEZIERTO16
*pPoly
= (const EMRPOLYBEZIERTO16
*)mr
;
1096 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1097 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1098 pPoly
->cpts
* sizeof(POINT
) );
1100 for(i
= 0; i
< pPoly
->cpts
; i
++)
1102 pts
[i
].x
= pPoly
->apts
[i
].x
;
1103 pts
[i
].y
= pPoly
->apts
[i
].y
;
1105 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
1106 HeapFree( GetProcessHeap(), 0, pts
);
1109 case EMR_POLYPOLYGON16
:
1111 const EMRPOLYPOLYGON16
*pPolyPoly
= (const EMRPOLYPOLYGON16
*)mr
;
1112 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1113 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1115 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1116 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1118 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1123 PolyPolygon(hdc
, pt
, (const INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1124 HeapFree( GetProcessHeap(), 0, pt
);
1127 case EMR_POLYPOLYLINE16
:
1129 const EMRPOLYPOLYLINE16
*pPolyPoly
= (const EMRPOLYPOLYLINE16
*)mr
;
1130 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1131 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1133 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1134 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1136 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1141 PolyPolyline(hdc
, pt
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1142 HeapFree( GetProcessHeap(), 0, pt
);
1146 case EMR_STRETCHDIBITS
:
1148 const EMRSTRETCHDIBITS
*pStretchDIBits
= (const EMRSTRETCHDIBITS
*)mr
;
1151 pStretchDIBits
->xDest
,
1152 pStretchDIBits
->yDest
,
1153 pStretchDIBits
->cxDest
,
1154 pStretchDIBits
->cyDest
,
1155 pStretchDIBits
->xSrc
,
1156 pStretchDIBits
->ySrc
,
1157 pStretchDIBits
->cxSrc
,
1158 pStretchDIBits
->cySrc
,
1159 (const BYTE
*)mr
+ pStretchDIBits
->offBitsSrc
,
1160 (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchDIBits
->offBmiSrc
),
1161 pStretchDIBits
->iUsageSrc
,
1162 pStretchDIBits
->dwRop
);
1166 case EMR_EXTTEXTOUTA
:
1168 const EMREXTTEXTOUTA
*pExtTextOutA
= (const EMREXTTEXTOUTA
*)mr
;
1170 const INT
*dx
= NULL
;
1173 rc
.left
= pExtTextOutA
->emrtext
.rcl
.left
;
1174 rc
.top
= pExtTextOutA
->emrtext
.rcl
.top
;
1175 rc
.right
= pExtTextOutA
->emrtext
.rcl
.right
;
1176 rc
.bottom
= pExtTextOutA
->emrtext
.rcl
.bottom
;
1177 TRACE("EMR_EXTTEXTOUTA: x,y = %d, %d. rect = %s. flags %08x\n",
1178 pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1179 wine_dbgstr_rect(&rc
), pExtTextOutA
->emrtext
.fOptions
);
1181 old_mode
= SetGraphicsMode(hdc
, pExtTextOutA
->iGraphicsMode
);
1182 /* Reselect the font back into the dc so that the transformation
1184 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1186 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1187 * These files can be enumerated and played under Win98 just
1188 * fine, but at least Win2k chokes on them.
1190 if (pExtTextOutA
->emrtext
.offDx
)
1191 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offDx
);
1193 ExtTextOutA(hdc
, pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1194 pExtTextOutA
->emrtext
.fOptions
, &rc
,
1195 (LPCSTR
)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offString
), pExtTextOutA
->emrtext
.nChars
,
1198 SetGraphicsMode(hdc
, old_mode
);
1202 case EMR_EXTTEXTOUTW
:
1204 const EMREXTTEXTOUTW
*pExtTextOutW
= (const EMREXTTEXTOUTW
*)mr
;
1206 const INT
*dx
= NULL
;
1209 rc
.left
= pExtTextOutW
->emrtext
.rcl
.left
;
1210 rc
.top
= pExtTextOutW
->emrtext
.rcl
.top
;
1211 rc
.right
= pExtTextOutW
->emrtext
.rcl
.right
;
1212 rc
.bottom
= pExtTextOutW
->emrtext
.rcl
.bottom
;
1213 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %s. flags %08x\n",
1214 pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1215 wine_dbgstr_rect(&rc
), pExtTextOutW
->emrtext
.fOptions
);
1217 old_mode
= SetGraphicsMode(hdc
, pExtTextOutW
->iGraphicsMode
);
1218 /* Reselect the font back into the dc so that the transformation
1220 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1222 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1223 * These files can be enumerated and played under Win98 just
1224 * fine, but at least Win2k chokes on them.
1226 if (pExtTextOutW
->emrtext
.offDx
)
1227 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offDx
);
1229 ExtTextOutW(hdc
, pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1230 pExtTextOutW
->emrtext
.fOptions
, &rc
,
1231 (LPCWSTR
)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offString
), pExtTextOutW
->emrtext
.nChars
,
1234 SetGraphicsMode(hdc
, old_mode
);
1238 case EMR_CREATEPALETTE
:
1240 const EMRCREATEPALETTE
*lpCreatePal
= (const EMRCREATEPALETTE
*)mr
;
1242 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1243 CreatePalette( &lpCreatePal
->lgpl
);
1248 case EMR_SELECTPALETTE
:
1250 const EMRSELECTPALETTE
*lpSelectPal
= (const EMRSELECTPALETTE
*)mr
;
1252 if( lpSelectPal
->ihPal
& 0x80000000 ) {
1253 SelectPalette( hdc
, GetStockObject(lpSelectPal
->ihPal
& 0x7fffffff), TRUE
);
1255 SelectPalette( hdc
, (handletable
->objectHandle
)[lpSelectPal
->ihPal
], TRUE
);
1260 case EMR_REALIZEPALETTE
:
1262 RealizePalette( hdc
);
1266 case EMR_EXTSELECTCLIPRGN
:
1268 const EMREXTSELECTCLIPRGN
*lpRgn
= (const EMREXTSELECTCLIPRGN
*)mr
;
1271 if (mr
->nSize
>= sizeof(*lpRgn
) + sizeof(RGNDATAHEADER
))
1272 hRgn
= ExtCreateRegion( &info
->init_transform
, 0, (const RGNDATA
*)lpRgn
->RgnData
);
1274 ExtSelectClipRgn(hdc
, hRgn
, (INT
)(lpRgn
->iMode
));
1275 /* ExtSelectClipRgn created a copy of the region */
1280 case EMR_SETMETARGN
:
1286 case EMR_SETWORLDTRANSFORM
:
1288 const EMRSETWORLDTRANSFORM
*lpXfrm
= (const EMRSETWORLDTRANSFORM
*)mr
;
1289 info
->state
.world_transform
= lpXfrm
->xform
;
1292 EMF_Update_MF_Xform(hdc
, info
);
1297 case EMR_POLYBEZIER
:
1299 const EMRPOLYBEZIER
*lpPolyBez
= (const EMRPOLYBEZIER
*)mr
;
1300 PolyBezier(hdc
, (const POINT
*)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1306 const EMRPOLYGON
*lpPoly
= (const EMRPOLYGON
*)mr
;
1307 Polygon( hdc
, (const POINT
*)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1313 const EMRPOLYLINE
*lpPolyLine
= (const EMRPOLYLINE
*)mr
;
1314 Polyline(hdc
, (const POINT
*)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1318 case EMR_POLYBEZIERTO
:
1320 const EMRPOLYBEZIERTO
*lpPolyBezierTo
= (const EMRPOLYBEZIERTO
*)mr
;
1321 PolyBezierTo( hdc
, (const POINT
*)lpPolyBezierTo
->aptl
,
1322 (UINT
)lpPolyBezierTo
->cptl
);
1326 case EMR_POLYLINETO
:
1328 const EMRPOLYLINETO
*lpPolyLineTo
= (const EMRPOLYLINETO
*)mr
;
1329 PolylineTo( hdc
, (const POINT
*)lpPolyLineTo
->aptl
,
1330 (UINT
)lpPolyLineTo
->cptl
);
1334 case EMR_POLYPOLYLINE
:
1336 const EMRPOLYPOLYLINE
*pPolyPolyline
= (const EMRPOLYPOLYLINE
*)mr
;
1337 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1339 PolyPolyline(hdc
, (const POINT
*)(pPolyPolyline
->aPolyCounts
+
1340 pPolyPolyline
->nPolys
),
1341 pPolyPolyline
->aPolyCounts
,
1342 pPolyPolyline
->nPolys
);
1347 case EMR_POLYPOLYGON
:
1349 const EMRPOLYPOLYGON
*pPolyPolygon
= (const EMRPOLYPOLYGON
*)mr
;
1351 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1353 PolyPolygon(hdc
, (const POINT
*)(pPolyPolygon
->aPolyCounts
+
1354 pPolyPolygon
->nPolys
),
1355 (const INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
1359 case EMR_SETBRUSHORGEX
:
1361 const EMRSETBRUSHORGEX
*lpSetBrushOrgEx
= (const EMRSETBRUSHORGEX
*)mr
;
1364 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1365 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1373 const EMRSETPIXELV
*lpSetPixelV
= (const EMRSETPIXELV
*)mr
;
1376 (INT
)lpSetPixelV
->ptlPixel
.x
,
1377 (INT
)lpSetPixelV
->ptlPixel
.y
,
1378 lpSetPixelV
->crColor
);
1383 case EMR_SETMAPPERFLAGS
:
1385 const EMRSETMAPPERFLAGS
*lpSetMapperFlags
= (const EMRSETMAPPERFLAGS
*)mr
;
1387 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1392 case EMR_SETCOLORADJUSTMENT
:
1394 const EMRSETCOLORADJUSTMENT
*lpSetColorAdjust
= (const EMRSETCOLORADJUSTMENT
*)mr
;
1396 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1401 case EMR_OFFSETCLIPRGN
:
1403 const EMROFFSETCLIPRGN
*lpOffsetClipRgn
= (const EMROFFSETCLIPRGN
*)mr
;
1406 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1407 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1408 FIXME("OffsetClipRgn\n");
1413 case EMR_EXCLUDECLIPRECT
:
1415 const EMREXCLUDECLIPRECT
*lpExcludeClipRect
= (const EMREXCLUDECLIPRECT
*)mr
;
1417 ExcludeClipRect( hdc
,
1418 lpExcludeClipRect
->rclClip
.left
,
1419 lpExcludeClipRect
->rclClip
.top
,
1420 lpExcludeClipRect
->rclClip
.right
,
1421 lpExcludeClipRect
->rclClip
.bottom
);
1422 FIXME("ExcludeClipRect\n");
1427 case EMR_SCALEVIEWPORTEXTEX
:
1429 const EMRSCALEVIEWPORTEXTEX
*lpScaleViewportExtEx
= (const EMRSCALEVIEWPORTEXTEX
*)mr
;
1431 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1433 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1434 !lpScaleViewportExtEx
->yNum
|| !lpScaleViewportExtEx
->yDenom
)
1436 info
->state
.vportExtX
= MulDiv(info
->state
.vportExtX
, lpScaleViewportExtEx
->xNum
,
1437 lpScaleViewportExtEx
->xDenom
);
1438 info
->state
.vportExtY
= MulDiv(info
->state
.vportExtY
, lpScaleViewportExtEx
->yNum
,
1439 lpScaleViewportExtEx
->yDenom
);
1440 if (info
->state
.vportExtX
== 0) info
->state
.vportExtX
= 1;
1441 if (info
->state
.vportExtY
== 0) info
->state
.vportExtY
= 1;
1442 if (info
->state
.mode
== MM_ISOTROPIC
)
1443 EMF_FixIsotropic(hdc
, info
);
1445 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1446 lpScaleViewportExtEx
->xNum
,lpScaleViewportExtEx
->xDenom
,
1447 lpScaleViewportExtEx
->yNum
,lpScaleViewportExtEx
->yDenom
);
1450 EMF_Update_MF_Xform(hdc
, info
);
1455 case EMR_SCALEWINDOWEXTEX
:
1457 const EMRSCALEWINDOWEXTEX
*lpScaleWindowExtEx
= (const EMRSCALEWINDOWEXTEX
*)mr
;
1459 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1461 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1462 !lpScaleWindowExtEx
->yNum
|| !lpScaleWindowExtEx
->yDenom
)
1464 info
->state
.wndExtX
= MulDiv(info
->state
.wndExtX
, lpScaleWindowExtEx
->xNum
,
1465 lpScaleWindowExtEx
->xDenom
);
1466 info
->state
.wndExtY
= MulDiv(info
->state
.wndExtY
, lpScaleWindowExtEx
->yNum
,
1467 lpScaleWindowExtEx
->yDenom
);
1468 if (info
->state
.wndExtX
== 0) info
->state
.wndExtX
= 1;
1469 if (info
->state
.wndExtY
== 0) info
->state
.wndExtY
= 1;
1470 if (info
->state
.mode
== MM_ISOTROPIC
)
1471 EMF_FixIsotropic(hdc
, info
);
1473 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1474 lpScaleWindowExtEx
->xNum
,lpScaleWindowExtEx
->xDenom
,
1475 lpScaleWindowExtEx
->yNum
,lpScaleWindowExtEx
->yDenom
);
1478 EMF_Update_MF_Xform(hdc
, info
);
1483 case EMR_MODIFYWORLDTRANSFORM
:
1485 const EMRMODIFYWORLDTRANSFORM
*lpModifyWorldTrans
= (const EMRMODIFYWORLDTRANSFORM
*)mr
;
1487 switch(lpModifyWorldTrans
->iMode
) {
1489 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
1490 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
1491 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
1493 EMF_Update_MF_Xform(hdc
, info
);
1495 case MWT_LEFTMULTIPLY
:
1496 CombineTransform(&info
->state
.world_transform
, &lpModifyWorldTrans
->xform
,
1497 &info
->state
.world_transform
);
1499 ModifyWorldTransform(hdc
, &lpModifyWorldTrans
->xform
, MWT_LEFTMULTIPLY
);
1501 case MWT_RIGHTMULTIPLY
:
1502 CombineTransform(&info
->state
.world_transform
, &info
->state
.world_transform
,
1503 &lpModifyWorldTrans
->xform
);
1505 EMF_Update_MF_Xform(hdc
, info
);
1508 FIXME("Unknown imode %d\n", lpModifyWorldTrans
->iMode
);
1516 const EMRANGLEARC
*lpAngleArc
= (const EMRANGLEARC
*)mr
;
1519 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1520 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1521 lpAngleArc
->eSweepAngle
);
1528 const EMRROUNDRECT
*lpRoundRect
= (const EMRROUNDRECT
*)mr
;
1531 lpRoundRect
->rclBox
.left
,
1532 lpRoundRect
->rclBox
.top
,
1533 lpRoundRect
->rclBox
.right
,
1534 lpRoundRect
->rclBox
.bottom
,
1535 lpRoundRect
->szlCorner
.cx
,
1536 lpRoundRect
->szlCorner
.cy
);
1543 const EMRARC
*lpArc
= (const EMRARC
*)mr
;
1546 (INT
)lpArc
->rclBox
.left
,
1547 (INT
)lpArc
->rclBox
.top
,
1548 (INT
)lpArc
->rclBox
.right
,
1549 (INT
)lpArc
->rclBox
.bottom
,
1550 (INT
)lpArc
->ptlStart
.x
,
1551 (INT
)lpArc
->ptlStart
.y
,
1552 (INT
)lpArc
->ptlEnd
.x
,
1553 (INT
)lpArc
->ptlEnd
.y
);
1560 const EMRCHORD
*lpChord
= (const EMRCHORD
*)mr
;
1563 (INT
)lpChord
->rclBox
.left
,
1564 (INT
)lpChord
->rclBox
.top
,
1565 (INT
)lpChord
->rclBox
.right
,
1566 (INT
)lpChord
->rclBox
.bottom
,
1567 (INT
)lpChord
->ptlStart
.x
,
1568 (INT
)lpChord
->ptlStart
.y
,
1569 (INT
)lpChord
->ptlEnd
.x
,
1570 (INT
)lpChord
->ptlEnd
.y
);
1577 const EMRPIE
*lpPie
= (const EMRPIE
*)mr
;
1580 (INT
)lpPie
->rclBox
.left
,
1581 (INT
)lpPie
->rclBox
.top
,
1582 (INT
)lpPie
->rclBox
.right
,
1583 (INT
)lpPie
->rclBox
.bottom
,
1584 (INT
)lpPie
->ptlStart
.x
,
1585 (INT
)lpPie
->ptlStart
.y
,
1586 (INT
)lpPie
->ptlEnd
.x
,
1587 (INT
)lpPie
->ptlEnd
.y
);
1594 const EMRARC
*lpArcTo
= (const EMRARC
*)mr
;
1597 (INT
)lpArcTo
->rclBox
.left
,
1598 (INT
)lpArcTo
->rclBox
.top
,
1599 (INT
)lpArcTo
->rclBox
.right
,
1600 (INT
)lpArcTo
->rclBox
.bottom
,
1601 (INT
)lpArcTo
->ptlStart
.x
,
1602 (INT
)lpArcTo
->ptlStart
.y
,
1603 (INT
)lpArcTo
->ptlEnd
.x
,
1604 (INT
)lpArcTo
->ptlEnd
.y
);
1609 case EMR_EXTFLOODFILL
:
1611 const EMREXTFLOODFILL
*lpExtFloodFill
= (const EMREXTFLOODFILL
*)mr
;
1614 (INT
)lpExtFloodFill
->ptlStart
.x
,
1615 (INT
)lpExtFloodFill
->ptlStart
.y
,
1616 lpExtFloodFill
->crColor
,
1617 (UINT
)lpExtFloodFill
->iMode
);
1624 const EMRPOLYDRAW
*lpPolyDraw
= (const EMRPOLYDRAW
*)mr
;
1626 (const POINT
*)lpPolyDraw
->aptl
,
1627 lpPolyDraw
->abTypes
,
1628 (INT
)lpPolyDraw
->cptl
);
1633 case EMR_SETARCDIRECTION
:
1635 const EMRSETARCDIRECTION
*lpSetArcDirection
= (const EMRSETARCDIRECTION
*)mr
;
1636 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1640 case EMR_SETMITERLIMIT
:
1642 const EMRSETMITERLIMIT
*lpSetMiterLimit
= (const EMRSETMITERLIMIT
*)mr
;
1643 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1659 case EMR_CLOSEFIGURE
:
1667 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1672 case EMR_STROKEANDFILLPATH
:
1674 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1675 StrokeAndFillPath( hdc
);
1679 case EMR_STROKEPATH
:
1681 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1686 case EMR_FLATTENPATH
:
1698 case EMR_SELECTCLIPPATH
:
1700 const EMRSELECTCLIPPATH
*lpSelectClipPath
= (const EMRSELECTCLIPPATH
*)mr
;
1701 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1711 case EMR_CREATECOLORSPACE
:
1713 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1714 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1715 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1719 case EMR_SETCOLORSPACE
:
1721 const EMRSETCOLORSPACE
*lpSetColorSpace
= (const EMRSETCOLORSPACE
*)mr
;
1723 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1727 case EMR_DELETECOLORSPACE
:
1729 const EMRDELETECOLORSPACE
*lpDeleteColorSpace
= (const EMRDELETECOLORSPACE
*)mr
;
1730 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1734 case EMR_SETICMMODE
:
1736 const EMRSETICMMODE
*lpSetICMMode
= (const EMRSETICMMODE
*)mr
;
1737 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1741 case EMR_PIXELFORMAT
:
1744 const EMRPIXELFORMAT
*lpPixelFormat
= (const EMRPIXELFORMAT
*)mr
;
1746 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1747 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1752 case EMR_SETPALETTEENTRIES
:
1754 const EMRSETPALETTEENTRIES
*lpSetPaletteEntries
= (const EMRSETPALETTEENTRIES
*)mr
;
1756 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1757 (UINT
)lpSetPaletteEntries
->iStart
,
1758 (UINT
)lpSetPaletteEntries
->cEntries
,
1759 lpSetPaletteEntries
->aPalEntries
);
1764 case EMR_RESIZEPALETTE
:
1766 const EMRRESIZEPALETTE
*lpResizePalette
= (const EMRRESIZEPALETTE
*)mr
;
1768 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1769 (UINT
)lpResizePalette
->cEntries
);
1774 case EMR_CREATEDIBPATTERNBRUSHPT
:
1776 const EMRCREATEDIBPATTERNBRUSHPT
*lpCreate
= (const EMRCREATEDIBPATTERNBRUSHPT
*)mr
;
1777 LPVOID lpPackedStruct
;
1779 /* Check that offsets and data are contained within the record
1780 * (including checking for wrap-arounds).
1782 if ( lpCreate
->offBmi
+ lpCreate
->cbBmi
> mr
->nSize
1783 || lpCreate
->offBits
+ lpCreate
->cbBits
> mr
->nSize
1784 || lpCreate
->offBmi
+ lpCreate
->cbBmi
< lpCreate
->offBmi
1785 || lpCreate
->offBits
+ lpCreate
->cbBits
< lpCreate
->offBits
)
1787 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1791 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1792 lpPackedStruct
= HeapAlloc( GetProcessHeap(), 0,
1793 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1796 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1800 /* Now pack this structure */
1801 memcpy( lpPackedStruct
,
1802 ((const BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1804 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1805 ((const BYTE
*)lpCreate
) + lpCreate
->offBits
,
1808 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1809 CreateDIBPatternBrushPt( lpPackedStruct
,
1810 (UINT
)lpCreate
->iUsage
);
1812 HeapFree(GetProcessHeap(), 0, lpPackedStruct
);
1816 case EMR_CREATEMONOBRUSH
:
1818 const EMRCREATEMONOBRUSH
*pCreateMonoBrush
= (const EMRCREATEMONOBRUSH
*)mr
;
1819 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
1822 /* Need to check if the bitmap is monochrome, and if the
1823 two colors are really black and white */
1824 if (pCreateMonoBrush
->iUsage
== DIB_PAL_MONO
)
1828 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1829 * aligned to 32 rather than 16 bits.
1832 bm
.bmWidth
= pbi
->bmiHeader
.biWidth
;
1833 bm
.bmHeight
= abs(pbi
->bmiHeader
.biHeight
);
1834 bm
.bmWidthBytes
= 4 * ((pbi
->bmiHeader
.biWidth
+ 31) / 32);
1835 bm
.bmPlanes
= pbi
->bmiHeader
.biPlanes
;
1836 bm
.bmBitsPixel
= pbi
->bmiHeader
.biBitCount
;
1837 bm
.bmBits
= (BYTE
*)mr
+ pCreateMonoBrush
->offBits
;
1838 hBmp
= CreateBitmapIndirect(&bm
);
1840 else if (is_dib_monochrome(pbi
))
1842 /* Top-down DIBs have a negative height */
1843 LONG height
= pbi
->bmiHeader
.biHeight
;
1845 hBmp
= CreateBitmap(pbi
->bmiHeader
.biWidth
, abs(height
), 1, 1, NULL
);
1846 SetDIBits(hdc
, hBmp
, 0, pbi
->bmiHeader
.biHeight
,
1847 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1851 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1852 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1855 (handletable
->objectHandle
)[pCreateMonoBrush
->ihBrush
] = CreatePatternBrush(hBmp
);
1857 /* CreatePatternBrush created a copy of the bitmap */
1864 const EMRBITBLT
*pBitBlt
= (const EMRBITBLT
*)mr
;
1866 if(pBitBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1867 PatBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1869 } else { /* BitBlt */
1870 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1871 HBRUSH hBrush
, hBrushOld
;
1872 HBITMAP hBmp
= 0, hBmpOld
= 0;
1873 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pBitBlt
->offBmiSrc
);
1875 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1876 SetWorldTransform(hdcSrc
, &pBitBlt
->xformSrc
);
1878 hBrush
= CreateSolidBrush(pBitBlt
->crBkColorSrc
);
1879 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1880 PatBlt(hdcSrc
, pBitBlt
->rclBounds
.left
, pBitBlt
->rclBounds
.top
,
1881 pBitBlt
->rclBounds
.right
- pBitBlt
->rclBounds
.left
,
1882 pBitBlt
->rclBounds
.bottom
- pBitBlt
->rclBounds
.top
, PATCOPY
);
1883 SelectObject(hdcSrc
, hBrushOld
);
1884 DeleteObject(hBrush
);
1886 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1887 (const BYTE
*)mr
+ pBitBlt
->offBitsSrc
, pbi
, pBitBlt
->iUsageSrc
);
1888 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1890 BitBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1891 hdcSrc
, pBitBlt
->xSrc
, pBitBlt
->ySrc
, pBitBlt
->dwRop
);
1893 SelectObject(hdcSrc
, hBmpOld
);
1900 case EMR_STRETCHBLT
:
1902 const EMRSTRETCHBLT
*pStretchBlt
= (const EMRSTRETCHBLT
*)mr
;
1904 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1905 pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1906 pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1907 pStretchBlt
->dwRop
, pStretchBlt
->offBitsSrc
);
1909 if(pStretchBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1910 PatBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1911 pStretchBlt
->dwRop
);
1912 } else { /* StretchBlt */
1913 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1914 HBRUSH hBrush
, hBrushOld
;
1915 HBITMAP hBmp
= 0, hBmpOld
= 0;
1916 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchBlt
->offBmiSrc
);
1918 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1919 SetWorldTransform(hdcSrc
, &pStretchBlt
->xformSrc
);
1921 hBrush
= CreateSolidBrush(pStretchBlt
->crBkColorSrc
);
1922 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1923 PatBlt(hdcSrc
, pStretchBlt
->rclBounds
.left
, pStretchBlt
->rclBounds
.top
,
1924 pStretchBlt
->rclBounds
.right
- pStretchBlt
->rclBounds
.left
,
1925 pStretchBlt
->rclBounds
.bottom
- pStretchBlt
->rclBounds
.top
, PATCOPY
);
1926 SelectObject(hdcSrc
, hBrushOld
);
1927 DeleteObject(hBrush
);
1929 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1930 (const BYTE
*)mr
+ pStretchBlt
->offBitsSrc
, pbi
, pStretchBlt
->iUsageSrc
);
1931 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1933 StretchBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1934 hdcSrc
, pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1935 pStretchBlt
->dwRop
);
1937 SelectObject(hdcSrc
, hBmpOld
);
1944 case EMR_ALPHABLEND
:
1946 const EMRALPHABLEND
*pAlphaBlend
= (const EMRALPHABLEND
*)mr
;
1948 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1949 pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1950 pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1951 pAlphaBlend
->dwRop
, pAlphaBlend
->offBitsSrc
);
1953 if(pAlphaBlend
->offBmiSrc
== 0) {
1954 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1956 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1957 HBITMAP hBmp
= 0, hBmpOld
= 0;
1958 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pAlphaBlend
->offBmiSrc
);
1961 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1962 SetWorldTransform(hdcSrc
, &pAlphaBlend
->xformSrc
);
1964 hBmp
= CreateDIBSection(hdc
, pbi
, pAlphaBlend
->iUsageSrc
, &bits
, NULL
, 0);
1965 memcpy(bits
, (const BYTE
*)mr
+ pAlphaBlend
->offBitsSrc
, pAlphaBlend
->cbBitsSrc
);
1966 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1968 GdiAlphaBlend(hdc
, pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1969 hdcSrc
, pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1970 *(BLENDFUNCTION
*)&pAlphaBlend
->dwRop
);
1972 SelectObject(hdcSrc
, hBmpOld
);
1981 const EMRMASKBLT
*pMaskBlt
= (const EMRMASKBLT
*)mr
;
1982 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1983 HBRUSH hBrush
, hBrushOld
;
1984 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1985 const BITMAPINFO
*pbi
;
1987 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1988 SetWorldTransform(hdcSrc
, &pMaskBlt
->xformSrc
);
1990 hBrush
= CreateSolidBrush(pMaskBlt
->crBkColorSrc
);
1991 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1992 PatBlt(hdcSrc
, pMaskBlt
->rclBounds
.left
, pMaskBlt
->rclBounds
.top
,
1993 pMaskBlt
->rclBounds
.right
- pMaskBlt
->rclBounds
.left
,
1994 pMaskBlt
->rclBounds
.bottom
- pMaskBlt
->rclBounds
.top
, PATCOPY
);
1995 SelectObject(hdcSrc
, hBrushOld
);
1996 DeleteObject(hBrush
);
1998 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiMask
);
1999 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2001 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2002 (const BYTE
*)mr
+ pMaskBlt
->offBitsMask
, pbi
, pMaskBlt
->iUsageMask
);
2004 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiSrc
);
2005 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2006 (const BYTE
*)mr
+ pMaskBlt
->offBitsSrc
, pbi
, pMaskBlt
->iUsageSrc
);
2007 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2020 SelectObject(hdcSrc
, hBmpOld
);
2022 DeleteObject(hBmpMask
);
2029 const EMRPLGBLT
*pPlgBlt
= (const EMRPLGBLT
*)mr
;
2030 HDC hdcSrc
= CreateCompatibleDC(hdc
);
2031 HBRUSH hBrush
, hBrushOld
;
2032 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
2033 const BITMAPINFO
*pbi
;
2036 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
2037 SetWorldTransform(hdcSrc
, &pPlgBlt
->xformSrc
);
2039 pts
[0].x
= pPlgBlt
->aptlDest
[0].x
; pts
[0].y
= pPlgBlt
->aptlDest
[0].y
;
2040 pts
[1].x
= pPlgBlt
->aptlDest
[1].x
; pts
[1].y
= pPlgBlt
->aptlDest
[1].y
;
2041 pts
[2].x
= pPlgBlt
->aptlDest
[2].x
; pts
[2].y
= pPlgBlt
->aptlDest
[2].y
;
2043 hBrush
= CreateSolidBrush(pPlgBlt
->crBkColorSrc
);
2044 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
2045 PatBlt(hdcSrc
, pPlgBlt
->rclBounds
.left
, pPlgBlt
->rclBounds
.top
,
2046 pPlgBlt
->rclBounds
.right
- pPlgBlt
->rclBounds
.left
,
2047 pPlgBlt
->rclBounds
.bottom
- pPlgBlt
->rclBounds
.top
, PATCOPY
);
2048 SelectObject(hdcSrc
, hBrushOld
);
2049 DeleteObject(hBrush
);
2051 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiMask
);
2052 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2054 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2055 (const BYTE
*)mr
+ pPlgBlt
->offBitsMask
, pbi
, pPlgBlt
->iUsageMask
);
2057 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiSrc
);
2058 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2059 (const BYTE
*)mr
+ pPlgBlt
->offBitsSrc
, pbi
, pPlgBlt
->iUsageSrc
);
2060 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2071 SelectObject(hdcSrc
, hBmpOld
);
2073 DeleteObject(hBmpMask
);
2078 case EMR_SETDIBITSTODEVICE
:
2080 const EMRSETDIBITSTODEVICE
*pSetDIBitsToDevice
= (const EMRSETDIBITSTODEVICE
*)mr
;
2082 SetDIBitsToDevice(hdc
,
2083 pSetDIBitsToDevice
->xDest
,
2084 pSetDIBitsToDevice
->yDest
,
2085 pSetDIBitsToDevice
->cxSrc
,
2086 pSetDIBitsToDevice
->cySrc
,
2087 pSetDIBitsToDevice
->xSrc
,
2088 pSetDIBitsToDevice
->ySrc
,
2089 pSetDIBitsToDevice
->iStartScan
,
2090 pSetDIBitsToDevice
->cScans
,
2091 (const BYTE
*)mr
+ pSetDIBitsToDevice
->offBitsSrc
,
2092 (const BITMAPINFO
*)((const BYTE
*)mr
+ pSetDIBitsToDevice
->offBmiSrc
),
2093 pSetDIBitsToDevice
->iUsageSrc
);
2097 case EMR_POLYTEXTOUTA
:
2099 const EMRPOLYTEXTOUTA
*pPolyTextOutA
= (const EMRPOLYTEXTOUTA
*)mr
;
2100 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
2102 XFORM xform
, xformOld
;
2105 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
2106 GetWorldTransform(hdc
, &xformOld
);
2108 xform
.eM11
= pPolyTextOutA
->exScale
;
2111 xform
.eM22
= pPolyTextOutA
->eyScale
;
2114 SetWorldTransform(hdc
, &xform
);
2116 /* Set up POLYTEXTA structures */
2117 for(i
= 0; i
< pPolyTextOutA
->cStrings
; i
++)
2119 polytextA
[i
].x
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.x
;
2120 polytextA
[i
].y
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.y
;
2121 polytextA
[i
].n
= pPolyTextOutA
->aemrtext
[i
].nChars
;
2122 polytextA
[i
].lpstr
= (LPCSTR
)((const BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offString
);
2123 polytextA
[i
].uiFlags
= pPolyTextOutA
->aemrtext
[i
].fOptions
;
2124 polytextA
[i
].rcl
.left
= pPolyTextOutA
->aemrtext
[i
].rcl
.left
;
2125 polytextA
[i
].rcl
.right
= pPolyTextOutA
->aemrtext
[i
].rcl
.right
;
2126 polytextA
[i
].rcl
.top
= pPolyTextOutA
->aemrtext
[i
].rcl
.top
;
2127 polytextA
[i
].rcl
.bottom
= pPolyTextOutA
->aemrtext
[i
].rcl
.bottom
;
2128 polytextA
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offDx
);
2130 PolyTextOutA(hdc
, polytextA
, pPolyTextOutA
->cStrings
);
2131 HeapFree(GetProcessHeap(), 0, polytextA
);
2133 SetWorldTransform(hdc
, &xformOld
);
2134 SetGraphicsMode(hdc
, gModeOld
);
2138 case EMR_POLYTEXTOUTW
:
2140 const EMRPOLYTEXTOUTW
*pPolyTextOutW
= (const EMRPOLYTEXTOUTW
*)mr
;
2141 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
2143 XFORM xform
, xformOld
;
2146 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
2147 GetWorldTransform(hdc
, &xformOld
);
2149 xform
.eM11
= pPolyTextOutW
->exScale
;
2152 xform
.eM22
= pPolyTextOutW
->eyScale
;
2155 SetWorldTransform(hdc
, &xform
);
2157 /* Set up POLYTEXTW structures */
2158 for(i
= 0; i
< pPolyTextOutW
->cStrings
; i
++)
2160 polytextW
[i
].x
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.x
;
2161 polytextW
[i
].y
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.y
;
2162 polytextW
[i
].n
= pPolyTextOutW
->aemrtext
[i
].nChars
;
2163 polytextW
[i
].lpstr
= (LPCWSTR
)((const BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offString
);
2164 polytextW
[i
].uiFlags
= pPolyTextOutW
->aemrtext
[i
].fOptions
;
2165 polytextW
[i
].rcl
.left
= pPolyTextOutW
->aemrtext
[i
].rcl
.left
;
2166 polytextW
[i
].rcl
.right
= pPolyTextOutW
->aemrtext
[i
].rcl
.right
;
2167 polytextW
[i
].rcl
.top
= pPolyTextOutW
->aemrtext
[i
].rcl
.top
;
2168 polytextW
[i
].rcl
.bottom
= pPolyTextOutW
->aemrtext
[i
].rcl
.bottom
;
2169 polytextW
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offDx
);
2171 PolyTextOutW(hdc
, polytextW
, pPolyTextOutW
->cStrings
);
2172 HeapFree(GetProcessHeap(), 0, polytextW
);
2174 SetWorldTransform(hdc
, &xformOld
);
2175 SetGraphicsMode(hdc
, gModeOld
);
2181 const EMRFILLRGN
*pFillRgn
= (const EMRFILLRGN
*)mr
;
2182 HRGN hRgn
= ExtCreateRegion(NULL
, pFillRgn
->cbRgnData
, (const RGNDATA
*)pFillRgn
->RgnData
);
2185 (handletable
->objectHandle
)[pFillRgn
->ihBrush
]);
2192 const EMRFRAMERGN
*pFrameRgn
= (const EMRFRAMERGN
*)mr
;
2193 HRGN hRgn
= ExtCreateRegion(NULL
, pFrameRgn
->cbRgnData
, (const RGNDATA
*)pFrameRgn
->RgnData
);
2196 (handletable
->objectHandle
)[pFrameRgn
->ihBrush
],
2197 pFrameRgn
->szlStroke
.cx
,
2198 pFrameRgn
->szlStroke
.cy
);
2205 const EMRINVERTRGN
*pInvertRgn
= (const EMRINVERTRGN
*)mr
;
2206 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (const RGNDATA
*)pInvertRgn
->RgnData
);
2207 InvertRgn(hdc
, hRgn
);
2214 const EMRPAINTRGN
*pPaintRgn
= (const EMRPAINTRGN
*)mr
;
2215 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (const RGNDATA
*)pPaintRgn
->RgnData
);
2216 PaintRgn(hdc
, hRgn
);
2221 case EMR_SETTEXTJUSTIFICATION
:
2223 const EMRSETTEXTJUSTIFICATION
*pSetTextJust
= (const EMRSETTEXTJUSTIFICATION
*)mr
;
2224 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
2230 const EMRSETLAYOUT
*pSetLayout
= (const EMRSETLAYOUT
*)mr
;
2231 SetLayout(hdc
, pSetLayout
->iMode
);
2235 case EMR_GRADIENTFILL
:
2237 EMRGRADIENTFILL
*grad
= (EMRGRADIENTFILL
*)mr
;
2238 GdiGradientFill( hdc
, grad
->Ver
, grad
->nVer
, grad
->Ver
+ grad
->nVer
,
2239 grad
->nTri
, grad
->ulMode
);
2243 case EMR_POLYDRAW16
:
2245 case EMR_GLSBOUNDEDRECORD
:
2246 case EMR_DRAWESCAPE
:
2249 case EMR_SMALLTEXTOUT
:
2250 case EMR_FORCEUFIMAPPING
:
2251 case EMR_NAMEDESCAPE
:
2252 case EMR_COLORCORRECTPALETTE
:
2253 case EMR_SETICMPROFILEA
:
2254 case EMR_SETICMPROFILEW
:
2255 case EMR_TRANSPARENTBLT
:
2256 case EMR_SETLINKEDUFI
:
2257 case EMR_COLORMATCHTOTARGETW
:
2258 case EMR_CREATECOLORSPACEW
:
2261 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2262 record then ignore and return TRUE. */
2263 FIXME("type %d is unimplemented\n", type
);
2266 tmprc
.left
= tmprc
.top
= 0;
2267 tmprc
.right
= tmprc
.bottom
= 1000;
2268 LPtoDP(hdc
, (POINT
*)&tmprc
, 2);
2269 TRACE("L:0,0 - 1000,1000 -> D:%s\n", wine_dbgstr_rect(&tmprc
));
2275 /*****************************************************************************
2277 * EnumEnhMetaFile (GDI32.@)
2279 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2281 * record. Returns when either every record has been used or
2282 * when _EnhMetaFunc_ returns FALSE.
2286 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2293 * This function behaves differently in Win9x and WinNT.
2295 * In WinNT, the DC's world transform is updated as the EMF changes
2296 * the Window/Viewport Extent and Origin or its world transform.
2297 * The actual Window/Viewport Extent and Origin are left untouched.
2299 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2300 * updates the scaling itself but only just before a record that
2301 * writes anything to the DC.
2303 * I'm not sure where the data (enum_emh_data) is stored in either
2304 * version. For this implementation, it is stored before the handle
2305 * table, but it could be stored in the DC, in the EMF handle or in
2309 BOOL WINAPI
EnumEnhMetaFile(
2310 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
2311 HENHMETAFILE hmf
, /* [in] EMF to walk */
2312 ENHMFENUMPROC callback
, /* [in] callback function */
2313 LPVOID data
, /* [in] optional data for callback function */
2314 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
2326 HBRUSH hBrush
= NULL
;
2329 enum_emh_data
*info
;
2330 SIZE vp_size
, win_size
;
2331 POINT vp_org
, win_org
;
2332 INT mapMode
= MM_TEXT
, old_align
= 0, old_rop2
= 0, old_arcdir
= 0, old_polyfill
= 0, old_stretchblt
= 0;
2333 COLORREF old_text_color
= 0, old_bk_color
= 0;
2337 SetLastError(ERROR_INVALID_PARAMETER
);
2341 emh
= EMF_GetEnhMetaHeader(hmf
);
2343 SetLastError(ERROR_INVALID_HANDLE
);
2347 info
= HeapAlloc( GetProcessHeap(), 0,
2348 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2351 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2354 info
->state
.mode
= MM_TEXT
;
2355 info
->state
.wndOrgX
= 0;
2356 info
->state
.wndOrgY
= 0;
2357 info
->state
.wndExtX
= 1;
2358 info
->state
.wndExtY
= 1;
2359 info
->state
.vportOrgX
= 0;
2360 info
->state
.vportOrgY
= 0;
2361 info
->state
.vportExtX
= 1;
2362 info
->state
.vportExtY
= 1;
2363 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
2364 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
2365 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
2367 info
->state
.next
= NULL
;
2368 info
->save_level
= 0;
2369 info
->saved_state
= NULL
;
2371 ht
= (HANDLETABLE
*) &info
[1];
2372 ht
->objectHandle
[0] = hmf
;
2373 for(i
= 1; i
< emh
->nHandles
; i
++)
2374 ht
->objectHandle
[i
] = NULL
;
2378 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
2379 GetWorldTransform(hdc
, &savedXform
);
2380 GetViewportExtEx(hdc
, &vp_size
);
2381 GetWindowExtEx(hdc
, &win_size
);
2382 GetViewportOrgEx(hdc
, &vp_org
);
2383 GetWindowOrgEx(hdc
, &win_org
);
2384 mapMode
= GetMapMode(hdc
);
2387 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
2388 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
2389 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
2391 hRgn
= CreateRectRgn(0, 0, 0, 0);
2392 if (!GetClipRgn(hdc
, hRgn
))
2398 old_text_color
= SetTextColor(hdc
, RGB(0,0,0));
2399 old_bk_color
= SetBkColor(hdc
, RGB(0xff, 0xff, 0xff));
2400 old_align
= SetTextAlign(hdc
, 0);
2401 old_rop2
= SetROP2(hdc
, R2_COPYPEN
);
2402 old_arcdir
= SetArcDirection(hdc
, AD_COUNTERCLOCKWISE
);
2403 old_polyfill
= SetPolyFillMode(hdc
, ALTERNATE
);
2404 old_stretchblt
= SetStretchBltMode(hdc
, BLACKONWHITE
);
2408 /* Win95 leaves the vp/win ext/org info alone */
2409 info
->init_transform
.eM11
= 1.0;
2410 info
->init_transform
.eM12
= 0.0;
2411 info
->init_transform
.eM21
= 0.0;
2412 info
->init_transform
.eM22
= 1.0;
2413 info
->init_transform
.eDx
= 0.0;
2414 info
->init_transform
.eDy
= 0.0;
2418 /* WinNT combines the vp/win ext/org info into a transform */
2419 double xscale
, yscale
;
2420 xscale
= (double)vp_size
.cx
/ (double)win_size
.cx
;
2421 yscale
= (double)vp_size
.cy
/ (double)win_size
.cy
;
2422 info
->init_transform
.eM11
= xscale
;
2423 info
->init_transform
.eM12
= 0.0;
2424 info
->init_transform
.eM21
= 0.0;
2425 info
->init_transform
.eM22
= yscale
;
2426 info
->init_transform
.eDx
= (double)vp_org
.x
- xscale
* (double)win_org
.x
;
2427 info
->init_transform
.eDy
= (double)vp_org
.y
- yscale
* (double)win_org
.y
;
2429 CombineTransform(&info
->init_transform
, &savedXform
, &info
->init_transform
);
2432 if ( lpRect
&& WIDTH(emh
->rclFrame
) && HEIGHT(emh
->rclFrame
) )
2434 double xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
2437 TRACE("rect: %s. rclFrame: (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(lpRect
),
2438 emh
->rclFrame
.left
, emh
->rclFrame
.top
, emh
->rclFrame
.right
,
2439 emh
->rclFrame
.bottom
);
2441 xSrcPixSize
= (double) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
2442 ySrcPixSize
= (double) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
2443 xscale
= (double) WIDTH(*lpRect
) * 100.0 /
2444 WIDTH(emh
->rclFrame
) * xSrcPixSize
;
2445 yscale
= (double) HEIGHT(*lpRect
) * 100.0 /
2446 HEIGHT(emh
->rclFrame
) * ySrcPixSize
;
2447 TRACE("xscale = %f, yscale = %f\n", xscale
, yscale
);
2449 xform
.eM11
= xscale
;
2452 xform
.eM22
= yscale
;
2453 xform
.eDx
= (double) lpRect
->left
- (double) WIDTH(*lpRect
) / WIDTH(emh
->rclFrame
) * emh
->rclFrame
.left
;
2454 xform
.eDy
= (double) lpRect
->top
- (double) HEIGHT(*lpRect
) / HEIGHT(emh
->rclFrame
) * emh
->rclFrame
.top
;
2456 CombineTransform(&info
->init_transform
, &xform
, &info
->init_transform
);
2459 /* WinNT resets the current vp/win org/ext */
2462 SetMapMode(hdc
, MM_TEXT
);
2463 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2464 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2465 EMF_Update_MF_Xform(hdc
, info
);
2471 while(ret
&& offset
< emh
->nBytes
)
2473 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
2475 if (offset
+ 8 > emh
->nBytes
||
2476 offset
> offset
+ emr
->nSize
||
2477 offset
+ emr
->nSize
> emh
->nBytes
)
2479 WARN("record truncated\n");
2483 /* In Win9x mode we update the xform if the record will produce output */
2484 if (hdc
&& IS_WIN9X() && emr_produces_output(emr
->iType
))
2485 EMF_Update_MF_Xform(hdc
, info
);
2487 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr
->iType
), emr
->nSize
);
2488 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nHandles
, (LPARAM
)data
);
2489 offset
+= emr
->nSize
;
2494 SetStretchBltMode(hdc
, old_stretchblt
);
2495 SetPolyFillMode(hdc
, old_polyfill
);
2496 SetArcDirection(hdc
, old_arcdir
);
2497 SetROP2(hdc
, old_rop2
);
2498 SetTextAlign(hdc
, old_align
);
2499 SetBkColor(hdc
, old_bk_color
);
2500 SetTextColor(hdc
, old_text_color
);
2503 SelectObject(hdc
, hBrush
);
2504 SelectObject(hdc
, hPen
);
2505 SelectObject(hdc
, hFont
);
2506 ExtSelectClipRgn(hdc
, hRgn
, RGN_COPY
);
2509 SetWorldTransform(hdc
, &savedXform
);
2511 SetGraphicsMode(hdc
, savedMode
);
2512 SetMapMode(hdc
, mapMode
);
2513 SetWindowOrgEx(hdc
, win_org
.x
, win_org
.y
, NULL
);
2514 SetWindowExtEx(hdc
, win_size
.cx
, win_size
.cy
, NULL
);
2515 SetViewportOrgEx(hdc
, vp_org
.x
, vp_org
.y
, NULL
);
2516 SetViewportExtEx(hdc
, vp_size
.cx
, vp_size
.cy
, NULL
);
2519 for(i
= 1; i
< emh
->nHandles
; i
++) /* Don't delete element 0 (hmf) */
2520 if( (ht
->objectHandle
)[i
] )
2521 DeleteObject( (ht
->objectHandle
)[i
] );
2523 while (info
->saved_state
)
2525 EMF_dc_state
*state
= info
->saved_state
;
2526 info
->saved_state
= info
->saved_state
->next
;
2527 HeapFree( GetProcessHeap(), 0, state
);
2529 HeapFree( GetProcessHeap(), 0, info
);
2533 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
2534 const ENHMETARECORD
*emr
,
2535 INT handles
, LPARAM data
)
2537 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
2540 /**************************************************************************
2541 * PlayEnhMetaFile (GDI32.@)
2543 * Renders an enhanced metafile into a specified rectangle *lpRect
2544 * in device context hdc.
2550 BOOL WINAPI
PlayEnhMetaFile(
2551 HDC hdc
, /* [in] DC to render into */
2552 HENHMETAFILE hmf
, /* [in] metafile to render */
2553 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
2556 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
2560 /*****************************************************************************
2561 * DeleteEnhMetaFile (GDI32.@)
2563 * Deletes an enhanced metafile and frees the associated storage.
2565 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
2567 return EMF_Delete_HENHMETAFILE( hmf
);
2570 /*****************************************************************************
2571 * CopyEnhMetaFileA (GDI32.@)
2573 * Duplicate an enhanced metafile.
2577 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
2578 HENHMETAFILE hmfSrc
,
2581 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2582 HENHMETAFILE hmfDst
;
2584 if(!emrSrc
) return FALSE
;
2586 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2587 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2588 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2590 HeapFree( GetProcessHeap(), 0, emrDst
);
2594 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2595 NULL
, CREATE_ALWAYS
, 0, 0);
2596 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2597 CloseHandle( hFile
);
2598 /* Reopen file for reading only, so that apps can share
2599 read access to the file while hmf is still valid */
2600 hFile
= CreateFileA( file
, GENERIC_READ
, FILE_SHARE_READ
,
2601 NULL
, OPEN_EXISTING
, 0, 0);
2602 if(hFile
== INVALID_HANDLE_VALUE
) {
2603 ERR("Can't reopen emf for reading\n");
2606 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2607 CloseHandle( hFile
);
2612 /*****************************************************************************
2613 * CopyEnhMetaFileW (GDI32.@)
2615 * See CopyEnhMetaFileA.
2619 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2620 HENHMETAFILE hmfSrc
,
2623 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2624 HENHMETAFILE hmfDst
;
2626 if(!emrSrc
) return FALSE
;
2628 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2629 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2630 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2632 HeapFree( GetProcessHeap(), 0, emrDst
);
2636 hFile
= CreateFileW( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2637 NULL
, CREATE_ALWAYS
, 0, 0);
2638 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2639 CloseHandle( hFile
);
2640 /* Reopen file for reading only, so that apps can share
2641 read access to the file while hmf is still valid */
2642 hFile
= CreateFileW( file
, GENERIC_READ
, FILE_SHARE_READ
,
2643 NULL
, OPEN_EXISTING
, 0, 0);
2644 if(hFile
== INVALID_HANDLE_VALUE
) {
2645 ERR("Can't reopen emf for reading\n");
2648 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2649 CloseHandle( hFile
);
2655 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2656 typedef struct tagEMF_PaletteCopy
2659 LPPALETTEENTRY lpPe
;
2662 /***************************************************************
2663 * Find the EMR_EOF record and then use it to find the
2664 * palette entries for this enhanced metafile.
2665 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2666 * which contains the max number of elements to copy and where
2669 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2671 static INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2673 const ENHMETARECORD
*lpEMR
,
2678 if ( lpEMR
->iType
== EMR_EOF
)
2680 const EMREOF
*lpEof
= (const EMREOF
*)lpEMR
;
2681 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
2682 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
2684 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy
);
2686 memcpy( info
->lpPe
, (LPCSTR
)lpEof
+ lpEof
->offPalEntries
,
2687 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
2689 /* Update the passed data as a return code */
2690 info
->lpPe
= NULL
; /* Palettes were copied! */
2691 info
->cEntries
= dwNumPalToCopy
;
2693 return FALSE
; /* That's all we need */
2699 /*****************************************************************************
2700 * GetEnhMetaFilePaletteEntries (GDI32.@)
2702 * Copy the palette and report size
2704 * BUGS: Error codes (SetLastError) are not set on failures
2706 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
2708 LPPALETTEENTRY lpPe
)
2710 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
2711 EMF_PaletteCopy infoForCallBack
;
2713 TRACE( "(%p,%d,%p)\n", hEmf
, cEntries
, lpPe
);
2715 if (!enhHeader
) return 0;
2717 /* First check if there are any palettes associated with
2719 if ( enhHeader
->nPalEntries
== 0 ) return 0;
2721 /* Is the user requesting the number of palettes? */
2722 if ( lpPe
== NULL
) return enhHeader
->nPalEntries
;
2724 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2725 infoForCallBack
.cEntries
= cEntries
;
2726 infoForCallBack
.lpPe
= lpPe
;
2728 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
2729 &infoForCallBack
, 0 ) )
2732 /* Verify that the callback executed correctly */
2733 if ( infoForCallBack
.lpPe
!= NULL
)
2735 /* Callback proc had error! */
2736 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2740 return infoForCallBack
.cEntries
;
2743 /******************************************************************
2744 * extract_emf_from_comment
2746 * If the WMF was created by GetWinMetaFileBits, then extract the
2747 * original EMF that is stored in MFCOMMENT chunks.
2749 static HENHMETAFILE
extract_emf_from_comment( const BYTE
*buf
, UINT mf_size
)
2751 METAHEADER
*mh
= (METAHEADER
*)buf
;
2753 emf_in_wmf_comment
*chunk
;
2755 DWORD size
= 0, remaining
, chunks
;
2756 BYTE
*emf_bits
= NULL
, *ptr
;
2758 HENHMETAFILE emf
= NULL
;
2760 if (mf_size
< sizeof(*mh
)) return NULL
;
2762 for (offset
= mh
->mtHeaderSize
* 2; offset
< mf_size
; offset
+= (mr
->rdSize
* 2))
2764 mr
= (METARECORD
*)((char *)mh
+ offset
);
2765 chunk
= (emf_in_wmf_comment
*)(mr
->rdParm
+ 2);
2767 if (mr
->rdFunction
!= META_ESCAPE
|| mr
->rdParm
[0] != MFCOMMENT
) goto done
;
2768 if (chunk
->magic
!= WMFC_MAGIC
) goto done
;
2772 size
= remaining
= chunk
->emf_size
;
2773 chunks
= chunk
->num_chunks
;
2774 emf_bits
= ptr
= HeapAlloc( GetProcessHeap(), 0, size
);
2775 if (!emf_bits
) goto done
;
2777 if (chunk
->chunk_size
> remaining
) goto done
;
2778 remaining
-= chunk
->chunk_size
;
2779 if (chunk
->remaining_size
!= remaining
) goto done
;
2780 memcpy( ptr
, chunk
->emf_data
, chunk
->chunk_size
);
2781 ptr
+= chunk
->chunk_size
;
2782 if (--chunks
== 0) break;
2785 for (offset
= 0; offset
< mf_size
/ 2; offset
++)
2786 checksum
+= *((WORD
*)buf
+ offset
);
2787 if (checksum
) goto done
;
2789 emf
= SetEnhMetaFileBits( size
, emf_bits
);
2792 HeapFree( GetProcessHeap(), 0, emf_bits
);
2796 typedef struct wmf_in_emf_comment
2803 DWORD cbWinMetaFile
;
2804 } wmf_in_emf_comment
;
2806 /******************************************************************
2807 * SetWinMetaFileBits (GDI32.@)
2809 * Translate from old style to new style.
2812 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
, const BYTE
*lpbBuffer
, HDC hdcRef
,
2813 const METAFILEPICT
*lpmfp
)
2815 static const WCHAR szDisplayW
[] = { 'D','I','S','P','L','A','Y','\0' };
2816 HMETAFILE hmf
= NULL
;
2817 HENHMETAFILE ret
= NULL
;
2818 HDC hdc
= NULL
, hdcdisp
= NULL
;
2819 RECT rc
, *prcFrame
= NULL
;
2820 LONG mm
, xExt
, yExt
;
2821 INT horzsize
, vertsize
, horzres
, vertres
;
2823 TRACE("(%d, %p, %p, %p)\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
2825 hmf
= SetMetaFileBitsEx(cbBuffer
, lpbBuffer
);
2828 WARN("SetMetaFileBitsEx failed\n");
2832 ret
= extract_emf_from_comment( lpbBuffer
, cbBuffer
);
2833 if (ret
) return ret
;
2836 hdcRef
= hdcdisp
= CreateDCW(szDisplayW
, NULL
, NULL
, NULL
);
2840 TRACE("mm = %d %dx%d\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2848 TRACE("lpmfp == NULL\n");
2850 /* Use the whole device surface */
2851 mm
= MM_ANISOTROPIC
;
2856 if (mm
== MM_ISOTROPIC
|| mm
== MM_ANISOTROPIC
)
2858 if (xExt
< 0 || yExt
< 0)
2860 /* Use the whole device surface */
2865 /* Use the x and y extents as the frame box */
2868 rc
.left
= rc
.top
= 0;
2875 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
)))
2877 ERR("CreateEnhMetaFile failed\n");
2882 * Write the original METAFILE into the enhanced metafile.
2883 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2887 wmf_in_emf_comment
*mfcomment
;
2888 UINT mfcomment_size
;
2890 mfcomment_size
= sizeof (*mfcomment
) + cbBuffer
;
2891 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
2894 mfcomment
->ident
= GDICOMMENT_IDENTIFIER
;
2895 mfcomment
->iComment
= GDICOMMENT_WINDOWS_METAFILE
;
2896 mfcomment
->nVersion
= 0x00000300;
2897 mfcomment
->nChecksum
= 0; /* FIXME */
2898 mfcomment
->fFlags
= 0;
2899 mfcomment
->cbWinMetaFile
= cbBuffer
;
2900 memcpy(&mfcomment
[1], lpbBuffer
, cbBuffer
);
2901 GdiComment(hdc
, mfcomment_size
, (BYTE
*) mfcomment
);
2902 HeapFree(GetProcessHeap(), 0, mfcomment
);
2904 SetMapMode(hdc
, mm
);
2908 horzsize
= GetDeviceCaps(hdcRef
, HORZSIZE
);
2909 vertsize
= GetDeviceCaps(hdcRef
, VERTSIZE
);
2910 horzres
= GetDeviceCaps(hdcRef
, HORZRES
);
2911 vertres
= GetDeviceCaps(hdcRef
, VERTRES
);
2915 /* Use the whole device surface */
2921 xExt
= MulDiv(xExt
, horzres
, 100 * horzsize
);
2922 yExt
= MulDiv(yExt
, vertres
, 100 * vertsize
);
2925 /* set the initial viewport:window ratio as 1:1 */
2926 SetViewportExtEx(hdc
, xExt
, yExt
, NULL
);
2927 SetWindowExtEx(hdc
, xExt
, yExt
, NULL
);
2929 PlayMetaFile(hdc
, hmf
);
2931 ret
= CloseEnhMetaFile(hdc
);
2933 if (hdcdisp
) DeleteDC(hdcdisp
);
2934 DeleteMetaFile(hmf
);