2 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * The enhanced format consists of the following elements:
25 * A table of handles to GDI objects
26 * An array of metafile records
30 * The standard format consists of a header and an array of metafile records.
35 #include "wine/port.h"
46 #include "gdi_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile
);
54 BOOL on_disk
; /* true if metafile is on disk */
57 static const struct emr_name
{
70 X(EMR_SETWINDOWEXTEX
),
71 X(EMR_SETWINDOWORGEX
),
72 X(EMR_SETVIEWPORTEXTEX
),
73 X(EMR_SETVIEWPORTORGEX
),
77 X(EMR_SETMAPPERFLAGS
),
80 X(EMR_SETPOLYFILLMODE
),
82 X(EMR_SETSTRETCHBLTMODE
),
84 X(EMR_SETCOLORADJUSTMENT
),
90 X(EMR_EXCLUDECLIPRECT
),
91 X(EMR_INTERSECTCLIPRECT
),
92 X(EMR_SCALEVIEWPORTEXTEX
),
93 X(EMR_SCALEWINDOWEXTEX
),
96 X(EMR_SETWORLDTRANSFORM
),
97 X(EMR_MODIFYWORLDTRANSFORM
),
100 X(EMR_CREATEBRUSHINDIRECT
),
109 X(EMR_SELECTPALETTE
),
110 X(EMR_CREATEPALETTE
),
111 X(EMR_SETPALETTEENTRIES
),
112 X(EMR_RESIZEPALETTE
),
113 X(EMR_REALIZEPALETTE
),
118 X(EMR_SETARCDIRECTION
),
119 X(EMR_SETMITERLIMIT
),
124 X(EMR_STROKEANDFILLPATH
),
128 X(EMR_SELECTCLIPPATH
),
135 X(EMR_EXTSELECTCLIPRGN
),
140 X(EMR_SETDIBITSTODEVICE
),
141 X(EMR_STRETCHDIBITS
),
142 X(EMR_EXTCREATEFONTINDIRECTW
),
148 X(EMR_POLYBEZIERTO16
),
150 X(EMR_POLYPOLYLINE16
),
151 X(EMR_POLYPOLYGON16
),
153 X(EMR_CREATEMONOBRUSH
),
154 X(EMR_CREATEDIBPATTERNBRUSHPT
),
159 X(EMR_CREATECOLORSPACE
),
160 X(EMR_SETCOLORSPACE
),
161 X(EMR_DELETECOLORSPACE
),
163 X(EMR_GLSBOUNDEDRECORD
),
169 X(EMR_FORCEUFIMAPPING
),
171 X(EMR_COLORCORRECTPALETTE
),
172 X(EMR_SETICMPROFILEA
),
173 X(EMR_SETICMPROFILEW
),
176 X(EMR_TRANSPARENTBLT
),
180 X(EMR_SETTEXTJUSTIFICATION
),
181 X(EMR_COLORMATCHTOTARGETW
),
182 X(EMR_CREATECOLORSPACEW
)
186 /****************************************************************************
189 static const char *get_emr_name(DWORD type
)
192 for(i
= 0; i
< sizeof(emr_names
) / sizeof(emr_names
[0]); i
++)
193 if(type
== emr_names
[i
].type
) return emr_names
[i
].name
;
194 TRACE("Unknown record type %d\n", type
);
198 /***********************************************************************
201 * Returns whether a DIB can be converted to a monochrome DDB.
203 * A DIB can be converted if its color table contains only black and
204 * white. Black must be the first color in the color table.
206 * Note : If the first color in the color table is white followed by
207 * black, we can't convert it to a monochrome DDB with
208 * SetDIBits, because black and white would be inverted.
210 static inline BOOL
is_dib_monochrome( const BITMAPINFO
* info
)
212 if (info
->bmiHeader
.biBitCount
!= 1) return FALSE
;
214 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
216 const RGBTRIPLE
*rgb
= ((const BITMAPCOREINFO
*) info
)->bmciColors
;
218 /* Check if the first color is black */
219 if ((rgb
->rgbtRed
== 0) && (rgb
->rgbtGreen
== 0) && (rgb
->rgbtBlue
== 0))
222 /* Check if the second color is white */
223 return ((rgb
->rgbtRed
== 0xff) && (rgb
->rgbtGreen
== 0xff)
224 && (rgb
->rgbtBlue
== 0xff));
228 else /* assume BITMAPINFOHEADER */
230 const RGBQUAD
*rgb
= info
->bmiColors
;
232 /* Check if the first color is black */
233 if ((rgb
->rgbRed
== 0) && (rgb
->rgbGreen
== 0) &&
234 (rgb
->rgbBlue
== 0) && (rgb
->rgbReserved
== 0))
238 /* Check if the second color is white */
239 return ((rgb
->rgbRed
== 0xff) && (rgb
->rgbGreen
== 0xff)
240 && (rgb
->rgbBlue
== 0xff) && (rgb
->rgbReserved
== 0));
246 /****************************************************************************
247 * EMF_Create_HENHMETAFILE
249 HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, 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
);
483 memmove(emh
, buf
, bufsize
);
484 hmf
= EMF_Create_HENHMETAFILE( emh
, bufsize
, FALSE
);
486 HeapFree( GetProcessHeap(), 0, emh
);
490 /*****************************************************************************
491 * GetEnhMetaFileBits (GDI32.@)
494 UINT WINAPI
GetEnhMetaFileBits(
500 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
506 if( buf
== NULL
) return size
;
508 size
= min( size
, bufsize
);
509 memmove(buf
, emh
, size
);
513 typedef struct EMF_dc_state
516 XFORM world_transform
;
525 struct EMF_dc_state
*next
;
528 typedef struct enum_emh_data
530 XFORM init_transform
;
533 EMF_dc_state
*saved_state
;
536 #define ENUM_GET_PRIVATE_DATA(ht) \
537 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
539 #define WIDTH(rect) ( (rect).right - (rect).left )
540 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
542 #define IS_WIN9X() (GetVersion()&0x80000000)
544 static void EMF_Update_MF_Xform(HDC hdc
, const enum_emh_data
*info
)
546 XFORM mapping_mode_trans
, final_trans
;
547 double scaleX
, scaleY
;
549 scaleX
= (double)info
->state
.vportExtX
/ (double)info
->state
.wndExtX
;
550 scaleY
= (double)info
->state
.vportExtY
/ (double)info
->state
.wndExtY
;
551 mapping_mode_trans
.eM11
= scaleX
;
552 mapping_mode_trans
.eM12
= 0.0;
553 mapping_mode_trans
.eM21
= 0.0;
554 mapping_mode_trans
.eM22
= scaleY
;
555 mapping_mode_trans
.eDx
= (double)info
->state
.vportOrgX
- scaleX
* (double)info
->state
.wndOrgX
;
556 mapping_mode_trans
.eDy
= (double)info
->state
.vportOrgY
- scaleY
* (double)info
->state
.wndOrgY
;
558 CombineTransform(&final_trans
, &info
->state
.world_transform
, &mapping_mode_trans
);
559 CombineTransform(&final_trans
, &final_trans
, &info
->init_transform
);
561 if (!SetWorldTransform(hdc
, &final_trans
))
563 ERR("World transform failed!\n");
567 static void EMF_RestoreDC( enum_emh_data
*info
, INT level
)
569 if (abs(level
) > info
->save_level
|| level
== 0) return;
571 if (level
< 0) level
= info
->save_level
+ level
+ 1;
573 while (info
->save_level
>= level
)
575 EMF_dc_state
*state
= info
->saved_state
;
576 info
->saved_state
= state
->next
;
578 if (--info
->save_level
< level
)
579 info
->state
= *state
;
580 HeapFree( GetProcessHeap(), 0, state
);
584 static void EMF_SaveDC( enum_emh_data
*info
)
586 EMF_dc_state
*state
= HeapAlloc( GetProcessHeap(), 0, sizeof(*state
));
589 *state
= info
->state
;
590 state
->next
= info
->saved_state
;
591 info
->saved_state
= state
;
593 TRACE("save_level %d\n", info
->save_level
);
597 static void EMF_SetMapMode(HDC hdc
, enum_emh_data
*info
)
599 INT horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
600 INT vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
601 INT horzRes
= GetDeviceCaps( hdc
, HORZRES
);
602 INT vertRes
= GetDeviceCaps( hdc
, VERTRES
);
604 TRACE("%d\n", info
->state
.mode
);
606 switch(info
->state
.mode
)
609 info
->state
.wndExtX
= 1;
610 info
->state
.wndExtY
= 1;
611 info
->state
.vportExtX
= 1;
612 info
->state
.vportExtY
= 1;
616 info
->state
.wndExtX
= horzSize
* 10;
617 info
->state
.wndExtY
= vertSize
* 10;
618 info
->state
.vportExtX
= horzRes
;
619 info
->state
.vportExtY
= -vertRes
;
622 info
->state
.wndExtX
= horzSize
* 100;
623 info
->state
.wndExtY
= vertSize
* 100;
624 info
->state
.vportExtX
= horzRes
;
625 info
->state
.vportExtY
= -vertRes
;
628 info
->state
.wndExtX
= MulDiv(1000, horzSize
, 254);
629 info
->state
.wndExtY
= MulDiv(1000, vertSize
, 254);
630 info
->state
.vportExtX
= horzRes
;
631 info
->state
.vportExtY
= -vertRes
;
634 info
->state
.wndExtX
= MulDiv(10000, horzSize
, 254);
635 info
->state
.wndExtY
= MulDiv(10000, vertSize
, 254);
636 info
->state
.vportExtX
= horzRes
;
637 info
->state
.vportExtY
= -vertRes
;
640 info
->state
.wndExtX
= MulDiv(14400, horzSize
, 254);
641 info
->state
.wndExtY
= MulDiv(14400, vertSize
, 254);
642 info
->state
.vportExtX
= horzRes
;
643 info
->state
.vportExtY
= -vertRes
;
652 /***********************************************************************
655 * Fix viewport extensions for isotropic mode.
658 static void EMF_FixIsotropic(HDC hdc
, enum_emh_data
*info
)
660 double xdim
= fabs((double)info
->state
.vportExtX
* GetDeviceCaps( hdc
, HORZSIZE
) /
661 (GetDeviceCaps( hdc
, HORZRES
) * info
->state
.wndExtX
));
662 double ydim
= fabs((double)info
->state
.vportExtY
* GetDeviceCaps( hdc
, VERTSIZE
) /
663 (GetDeviceCaps( hdc
, VERTRES
) * info
->state
.wndExtY
));
667 INT mincx
= (info
->state
.vportExtX
>= 0) ? 1 : -1;
668 info
->state
.vportExtX
= floor(info
->state
.vportExtX
* ydim
/ xdim
+ 0.5);
669 if (!info
->state
.vportExtX
) info
->state
.vportExtX
= mincx
;
673 INT mincy
= (info
->state
.vportExtY
>= 0) ? 1 : -1;
674 info
->state
.vportExtY
= floor(info
->state
.vportExtY
* xdim
/ ydim
+ 0.5);
675 if (!info
->state
.vportExtY
) info
->state
.vportExtY
= mincy
;
679 /*****************************************************************************
680 * emr_produces_output
682 * Returns TRUE if the record type writes something to the dc. Used by
683 * PlayEnhMetaFileRecord to determine whether it needs to update the
684 * dc's xform when in win9x mode.
686 * FIXME: need to test which records should be here.
688 static BOOL
emr_produces_output(int type
)
694 case EMR_POLYBEZIERTO
:
696 case EMR_POLYPOLYLINE
:
697 case EMR_POLYPOLYGON
:
700 case EMR_EXCLUDECLIPRECT
:
701 case EMR_INTERSECTCLIPRECT
:
702 case EMR_SELECTOBJECT
:
710 case EMR_EXTFLOODFILL
:
723 case EMR_SETDIBITSTODEVICE
:
724 case EMR_STRETCHDIBITS
:
725 case EMR_EXTTEXTOUTA
:
726 case EMR_EXTTEXTOUTW
:
727 case EMR_POLYBEZIER16
:
730 case EMR_POLYBEZIERTO16
:
731 case EMR_POLYLINETO16
:
732 case EMR_POLYPOLYLINE16
:
733 case EMR_POLYPOLYGON16
:
735 case EMR_POLYTEXTOUTA
:
736 case EMR_POLYTEXTOUTW
:
737 case EMR_SMALLTEXTOUT
:
739 case EMR_TRANSPARENTBLT
:
747 /*****************************************************************************
748 * PlayEnhMetaFileRecord (GDI32.@)
750 * Render a single enhanced metafile record in the device context hdc.
753 * TRUE (non zero) on success, FALSE on error.
755 * Many unimplemented records.
756 * No error handling on record play failures (ie checking return codes)
759 * WinNT actually updates the current world transform in this function
760 * whereas Win9x does not.
762 BOOL WINAPI
PlayEnhMetaFileRecord(
763 HDC hdc
, /* [in] device context in which to render EMF record */
764 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
765 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
766 UINT handles
/* [in] size of handle array */
771 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
773 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
774 hdc
, handletable
, mr
, handles
);
775 if (!mr
) return FALSE
;
779 TRACE("record %s\n", get_emr_name(type
));
788 const EMRGDICOMMENT
*lpGdiComment
= (const EMRGDICOMMENT
*)mr
;
789 /* In an enhanced metafile, there can be both public and private GDI comments */
790 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
795 const EMRSETMAPMODE
*pSetMapMode
= (const EMRSETMAPMODE
*)mr
;
797 if (info
->state
.mode
== pSetMapMode
->iMode
&&
798 (info
->state
.mode
== MM_ISOTROPIC
|| info
->state
.mode
== MM_ANISOTROPIC
))
800 info
->state
.mode
= pSetMapMode
->iMode
;
801 EMF_SetMapMode(hdc
, info
);
804 EMF_Update_MF_Xform(hdc
, info
);
810 const EMRSETBKMODE
*pSetBkMode
= (const EMRSETBKMODE
*)mr
;
811 SetBkMode(hdc
, pSetBkMode
->iMode
);
816 const EMRSETBKCOLOR
*pSetBkColor
= (const EMRSETBKCOLOR
*)mr
;
817 SetBkColor(hdc
, pSetBkColor
->crColor
);
820 case EMR_SETPOLYFILLMODE
:
822 const EMRSETPOLYFILLMODE
*pSetPolyFillMode
= (const EMRSETPOLYFILLMODE
*)mr
;
823 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
828 const EMRSETROP2
*pSetROP2
= (const EMRSETROP2
*)mr
;
829 SetROP2(hdc
, pSetROP2
->iMode
);
832 case EMR_SETSTRETCHBLTMODE
:
834 const EMRSETSTRETCHBLTMODE
*pSetStretchBltMode
= (const EMRSETSTRETCHBLTMODE
*)mr
;
835 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
838 case EMR_SETTEXTALIGN
:
840 const EMRSETTEXTALIGN
*pSetTextAlign
= (const EMRSETTEXTALIGN
*)mr
;
841 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
844 case EMR_SETTEXTCOLOR
:
846 const EMRSETTEXTCOLOR
*pSetTextColor
= (const EMRSETTEXTCOLOR
*)mr
;
847 SetTextColor(hdc
, pSetTextColor
->crColor
);
858 const EMRRESTOREDC
*pRestoreDC
= (const EMRRESTOREDC
*)mr
;
859 TRACE("EMR_RESTORE: %d\n", pRestoreDC
->iRelative
);
860 if (RestoreDC( hdc
, pRestoreDC
->iRelative
))
861 EMF_RestoreDC( info
, pRestoreDC
->iRelative
);
864 case EMR_INTERSECTCLIPRECT
:
866 const EMRINTERSECTCLIPRECT
*pClipRect
= (const EMRINTERSECTCLIPRECT
*)mr
;
867 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
868 pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
869 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
870 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
871 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
874 case EMR_SELECTOBJECT
:
876 const EMRSELECTOBJECT
*pSelectObject
= (const EMRSELECTOBJECT
*)mr
;
877 if( pSelectObject
->ihObject
& 0x80000000 ) {
878 /* High order bit is set - it's a stock object
879 * Strip the high bit to get the index.
880 * See MSDN article Q142319
882 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
885 /* High order bit wasn't set - not a stock object
888 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
892 case EMR_DELETEOBJECT
:
894 const EMRDELETEOBJECT
*pDeleteObject
= (const EMRDELETEOBJECT
*)mr
;
895 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
896 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
899 case EMR_SETWINDOWORGEX
:
901 const EMRSETWINDOWORGEX
*pSetWindowOrgEx
= (const EMRSETWINDOWORGEX
*)mr
;
903 info
->state
.wndOrgX
= pSetWindowOrgEx
->ptlOrigin
.x
;
904 info
->state
.wndOrgY
= pSetWindowOrgEx
->ptlOrigin
.y
;
906 TRACE("SetWindowOrgEx: %d,%d\n", info
->state
.wndOrgX
, info
->state
.wndOrgY
);
909 EMF_Update_MF_Xform(hdc
, info
);
913 case EMR_SETWINDOWEXTEX
:
915 const EMRSETWINDOWEXTEX
*pSetWindowExtEx
= (const EMRSETWINDOWEXTEX
*)mr
;
917 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
919 info
->state
.wndExtX
= pSetWindowExtEx
->szlExtent
.cx
;
920 info
->state
.wndExtY
= pSetWindowExtEx
->szlExtent
.cy
;
921 if (info
->state
.mode
== MM_ISOTROPIC
)
922 EMF_FixIsotropic(hdc
, info
);
924 TRACE("SetWindowExtEx: %d,%d\n",info
->state
.wndExtX
, info
->state
.wndExtY
);
927 EMF_Update_MF_Xform(hdc
, info
);
931 case EMR_SETVIEWPORTORGEX
:
933 const EMRSETVIEWPORTORGEX
*pSetViewportOrgEx
= (const EMRSETVIEWPORTORGEX
*)mr
;
935 info
->state
.vportOrgX
= pSetViewportOrgEx
->ptlOrigin
.x
;
936 info
->state
.vportOrgY
= pSetViewportOrgEx
->ptlOrigin
.y
;
937 TRACE("SetViewportOrgEx: %d,%d\n", info
->state
.vportOrgX
, info
->state
.vportOrgY
);
940 EMF_Update_MF_Xform(hdc
, info
);
944 case EMR_SETVIEWPORTEXTEX
:
946 const EMRSETVIEWPORTEXTEX
*pSetViewportExtEx
= (const EMRSETVIEWPORTEXTEX
*)mr
;
948 if (info
->state
.mode
!= MM_ISOTROPIC
&& info
->state
.mode
!= MM_ANISOTROPIC
)
950 info
->state
.vportExtX
= pSetViewportExtEx
->szlExtent
.cx
;
951 info
->state
.vportExtY
= pSetViewportExtEx
->szlExtent
.cy
;
952 if (info
->state
.mode
== MM_ISOTROPIC
)
953 EMF_FixIsotropic(hdc
, info
);
954 TRACE("SetViewportExtEx: %d,%d\n", info
->state
.vportExtX
, info
->state
.vportExtY
);
957 EMF_Update_MF_Xform(hdc
, info
);
963 const EMRCREATEPEN
*pCreatePen
= (const EMRCREATEPEN
*)mr
;
964 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
965 CreatePenIndirect(&pCreatePen
->lopn
);
968 case EMR_EXTCREATEPEN
:
970 const EMREXTCREATEPEN
*pPen
= (const EMREXTCREATEPEN
*)mr
;
972 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
973 lb
.lbColor
= pPen
->elp
.elpColor
;
974 lb
.lbHatch
= pPen
->elp
.elpHatch
;
976 if(pPen
->offBmi
|| pPen
->offBits
)
977 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
979 (handletable
->objectHandle
)[pPen
->ihPen
] =
980 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
981 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpNumEntries
? pPen
->elp
.elpStyleEntry
: NULL
);
984 case EMR_CREATEBRUSHINDIRECT
:
986 const EMRCREATEBRUSHINDIRECT
*pBrush
= (const EMRCREATEBRUSHINDIRECT
*)mr
;
988 brush
.lbStyle
= pBrush
->lb
.lbStyle
;
989 brush
.lbColor
= pBrush
->lb
.lbColor
;
990 brush
.lbHatch
= pBrush
->lb
.lbHatch
;
991 (handletable
->objectHandle
)[pBrush
->ihBrush
] = CreateBrushIndirect(&brush
);
994 case EMR_EXTCREATEFONTINDIRECTW
:
996 const EMREXTCREATEFONTINDIRECTW
*pFont
= (const EMREXTCREATEFONTINDIRECTW
*)mr
;
997 (handletable
->objectHandle
)[pFont
->ihFont
] =
998 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
1003 const EMRMOVETOEX
*pMoveToEx
= (const EMRMOVETOEX
*)mr
;
1004 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
1009 const EMRLINETO
*pLineTo
= (const EMRLINETO
*)mr
;
1010 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
1015 const EMRRECTANGLE
*pRect
= (const EMRRECTANGLE
*)mr
;
1016 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
1017 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
1022 const EMRELLIPSE
*pEllipse
= (const EMRELLIPSE
*)mr
;
1023 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
1024 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
1029 const EMRPOLYGON16
*pPoly
= (const EMRPOLYGON16
*)mr
;
1030 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
1031 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1032 pPoly
->cpts
* sizeof(POINT
) );
1034 for(i
= 0; i
< pPoly
->cpts
; i
++)
1036 pts
[i
].x
= pPoly
->apts
[i
].x
;
1037 pts
[i
].y
= pPoly
->apts
[i
].y
;
1039 Polygon(hdc
, pts
, pPoly
->cpts
);
1040 HeapFree( GetProcessHeap(), 0, pts
);
1043 case EMR_POLYLINE16
:
1045 const EMRPOLYLINE16
*pPoly
= (const EMRPOLYLINE16
*)mr
;
1046 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1047 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1048 pPoly
->cpts
* sizeof(POINT
) );
1050 for(i
= 0; i
< pPoly
->cpts
; i
++)
1052 pts
[i
].x
= pPoly
->apts
[i
].x
;
1053 pts
[i
].y
= pPoly
->apts
[i
].y
;
1055 Polyline(hdc
, pts
, pPoly
->cpts
);
1056 HeapFree( GetProcessHeap(), 0, pts
);
1059 case EMR_POLYLINETO16
:
1061 const EMRPOLYLINETO16
*pPoly
= (const EMRPOLYLINETO16
*)mr
;
1062 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1063 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1064 pPoly
->cpts
* sizeof(POINT
) );
1066 for(i
= 0; i
< pPoly
->cpts
; i
++)
1068 pts
[i
].x
= pPoly
->apts
[i
].x
;
1069 pts
[i
].y
= pPoly
->apts
[i
].y
;
1071 PolylineTo(hdc
, pts
, pPoly
->cpts
);
1072 HeapFree( GetProcessHeap(), 0, pts
);
1075 case EMR_POLYBEZIER16
:
1077 const EMRPOLYBEZIER16
*pPoly
= (const EMRPOLYBEZIER16
*)mr
;
1078 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1079 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1080 pPoly
->cpts
* sizeof(POINT
) );
1082 for(i
= 0; i
< pPoly
->cpts
; i
++)
1084 pts
[i
].x
= pPoly
->apts
[i
].x
;
1085 pts
[i
].y
= pPoly
->apts
[i
].y
;
1087 PolyBezier(hdc
, pts
, pPoly
->cpts
);
1088 HeapFree( GetProcessHeap(), 0, pts
);
1091 case EMR_POLYBEZIERTO16
:
1093 const EMRPOLYBEZIERTO16
*pPoly
= (const EMRPOLYBEZIERTO16
*)mr
;
1094 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1095 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
1096 pPoly
->cpts
* sizeof(POINT
) );
1098 for(i
= 0; i
< pPoly
->cpts
; i
++)
1100 pts
[i
].x
= pPoly
->apts
[i
].x
;
1101 pts
[i
].y
= pPoly
->apts
[i
].y
;
1103 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
1104 HeapFree( GetProcessHeap(), 0, pts
);
1107 case EMR_POLYPOLYGON16
:
1109 const EMRPOLYPOLYGON16
*pPolyPoly
= (const EMRPOLYPOLYGON16
*)mr
;
1110 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1111 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1113 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1114 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1116 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1121 PolyPolygon(hdc
, pt
, (const INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1122 HeapFree( GetProcessHeap(), 0, pt
);
1125 case EMR_POLYPOLYLINE16
:
1127 const EMRPOLYPOLYLINE16
*pPolyPoly
= (const EMRPOLYPOLYLINE16
*)mr
;
1128 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1129 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1131 const POINTS
*pts
= (const POINTS
*)(pPolyPoly
->aPolyCounts
+ pPolyPoly
->nPolys
);
1132 POINT
*pt
= HeapAlloc( GetProcessHeap(), 0, pPolyPoly
->cpts
* sizeof(POINT
) );
1134 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
1139 PolyPolyline(hdc
, pt
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
1140 HeapFree( GetProcessHeap(), 0, pt
);
1144 case EMR_STRETCHDIBITS
:
1146 const EMRSTRETCHDIBITS
*pStretchDIBits
= (const EMRSTRETCHDIBITS
*)mr
;
1149 pStretchDIBits
->xDest
,
1150 pStretchDIBits
->yDest
,
1151 pStretchDIBits
->cxDest
,
1152 pStretchDIBits
->cyDest
,
1153 pStretchDIBits
->xSrc
,
1154 pStretchDIBits
->ySrc
,
1155 pStretchDIBits
->cxSrc
,
1156 pStretchDIBits
->cySrc
,
1157 (const BYTE
*)mr
+ pStretchDIBits
->offBitsSrc
,
1158 (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchDIBits
->offBmiSrc
),
1159 pStretchDIBits
->iUsageSrc
,
1160 pStretchDIBits
->dwRop
);
1164 case EMR_EXTTEXTOUTA
:
1166 const EMREXTTEXTOUTA
*pExtTextOutA
= (const EMREXTTEXTOUTA
*)mr
;
1168 const INT
*dx
= NULL
;
1171 rc
.left
= pExtTextOutA
->emrtext
.rcl
.left
;
1172 rc
.top
= pExtTextOutA
->emrtext
.rcl
.top
;
1173 rc
.right
= pExtTextOutA
->emrtext
.rcl
.right
;
1174 rc
.bottom
= pExtTextOutA
->emrtext
.rcl
.bottom
;
1175 TRACE("EMR_EXTTEXTOUTA: x,y = %d, %d. rect = %s. flags %08x\n",
1176 pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1177 wine_dbgstr_rect(&rc
), pExtTextOutA
->emrtext
.fOptions
);
1179 old_mode
= SetGraphicsMode(hdc
, pExtTextOutA
->iGraphicsMode
);
1180 /* Reselect the font back into the dc so that the transformation
1182 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1184 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1185 * These files can be enumerated and played under Win98 just
1186 * fine, but at least Win2k chokes on them.
1188 if (pExtTextOutA
->emrtext
.offDx
)
1189 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offDx
);
1191 ExtTextOutA(hdc
, pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
1192 pExtTextOutA
->emrtext
.fOptions
, &rc
,
1193 (LPCSTR
)((const BYTE
*)mr
+ pExtTextOutA
->emrtext
.offString
), pExtTextOutA
->emrtext
.nChars
,
1196 SetGraphicsMode(hdc
, old_mode
);
1200 case EMR_EXTTEXTOUTW
:
1202 const EMREXTTEXTOUTW
*pExtTextOutW
= (const EMREXTTEXTOUTW
*)mr
;
1204 const INT
*dx
= NULL
;
1207 rc
.left
= pExtTextOutW
->emrtext
.rcl
.left
;
1208 rc
.top
= pExtTextOutW
->emrtext
.rcl
.top
;
1209 rc
.right
= pExtTextOutW
->emrtext
.rcl
.right
;
1210 rc
.bottom
= pExtTextOutW
->emrtext
.rcl
.bottom
;
1211 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %s. flags %08x\n",
1212 pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1213 wine_dbgstr_rect(&rc
), pExtTextOutW
->emrtext
.fOptions
);
1215 old_mode
= SetGraphicsMode(hdc
, pExtTextOutW
->iGraphicsMode
);
1216 /* Reselect the font back into the dc so that the transformation
1218 SelectObject(hdc
, GetCurrentObject(hdc
, OBJ_FONT
));
1220 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1221 * These files can be enumerated and played under Win98 just
1222 * fine, but at least Win2k chokes on them.
1224 if (pExtTextOutW
->emrtext
.offDx
)
1225 dx
= (const INT
*)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offDx
);
1227 ExtTextOutW(hdc
, pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1228 pExtTextOutW
->emrtext
.fOptions
, &rc
,
1229 (LPCWSTR
)((const BYTE
*)mr
+ pExtTextOutW
->emrtext
.offString
), pExtTextOutW
->emrtext
.nChars
,
1232 SetGraphicsMode(hdc
, old_mode
);
1236 case EMR_CREATEPALETTE
:
1238 const EMRCREATEPALETTE
*lpCreatePal
= (const EMRCREATEPALETTE
*)mr
;
1240 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1241 CreatePalette( &lpCreatePal
->lgpl
);
1246 case EMR_SELECTPALETTE
:
1248 const EMRSELECTPALETTE
*lpSelectPal
= (const EMRSELECTPALETTE
*)mr
;
1250 if( lpSelectPal
->ihPal
& 0x80000000 ) {
1251 SelectPalette( hdc
, GetStockObject(lpSelectPal
->ihPal
& 0x7fffffff), TRUE
);
1253 SelectPalette( hdc
, (handletable
->objectHandle
)[lpSelectPal
->ihPal
], TRUE
);
1258 case EMR_REALIZEPALETTE
:
1260 RealizePalette( hdc
);
1264 case EMR_EXTSELECTCLIPRGN
:
1266 const EMREXTSELECTCLIPRGN
*lpRgn
= (const EMREXTSELECTCLIPRGN
*)mr
;
1269 if (mr
->nSize
>= sizeof(*lpRgn
) + sizeof(RGNDATAHEADER
))
1270 hRgn
= ExtCreateRegion( &info
->init_transform
, 0, (const RGNDATA
*)lpRgn
->RgnData
);
1272 ExtSelectClipRgn(hdc
, hRgn
, (INT
)(lpRgn
->iMode
));
1273 /* ExtSelectClipRgn created a copy of the region */
1278 case EMR_SETMETARGN
:
1284 case EMR_SETWORLDTRANSFORM
:
1286 const EMRSETWORLDTRANSFORM
*lpXfrm
= (const EMRSETWORLDTRANSFORM
*)mr
;
1287 info
->state
.world_transform
= lpXfrm
->xform
;
1290 EMF_Update_MF_Xform(hdc
, info
);
1295 case EMR_POLYBEZIER
:
1297 const EMRPOLYBEZIER
*lpPolyBez
= (const EMRPOLYBEZIER
*)mr
;
1298 PolyBezier(hdc
, (const POINT
*)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1304 const EMRPOLYGON
*lpPoly
= (const EMRPOLYGON
*)mr
;
1305 Polygon( hdc
, (const POINT
*)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1311 const EMRPOLYLINE
*lpPolyLine
= (const EMRPOLYLINE
*)mr
;
1312 Polyline(hdc
, (const POINT
*)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1316 case EMR_POLYBEZIERTO
:
1318 const EMRPOLYBEZIERTO
*lpPolyBezierTo
= (const EMRPOLYBEZIERTO
*)mr
;
1319 PolyBezierTo( hdc
, (const POINT
*)lpPolyBezierTo
->aptl
,
1320 (UINT
)lpPolyBezierTo
->cptl
);
1324 case EMR_POLYLINETO
:
1326 const EMRPOLYLINETO
*lpPolyLineTo
= (const EMRPOLYLINETO
*)mr
;
1327 PolylineTo( hdc
, (const POINT
*)lpPolyLineTo
->aptl
,
1328 (UINT
)lpPolyLineTo
->cptl
);
1332 case EMR_POLYPOLYLINE
:
1334 const EMRPOLYPOLYLINE
*pPolyPolyline
= (const EMRPOLYPOLYLINE
*)mr
;
1335 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1337 PolyPolyline(hdc
, (const POINT
*)(pPolyPolyline
->aPolyCounts
+
1338 pPolyPolyline
->nPolys
),
1339 pPolyPolyline
->aPolyCounts
,
1340 pPolyPolyline
->nPolys
);
1345 case EMR_POLYPOLYGON
:
1347 const EMRPOLYPOLYGON
*pPolyPolygon
= (const EMRPOLYPOLYGON
*)mr
;
1349 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1351 PolyPolygon(hdc
, (const POINT
*)(pPolyPolygon
->aPolyCounts
+
1352 pPolyPolygon
->nPolys
),
1353 (const INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
1357 case EMR_SETBRUSHORGEX
:
1359 const EMRSETBRUSHORGEX
*lpSetBrushOrgEx
= (const EMRSETBRUSHORGEX
*)mr
;
1362 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1363 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1371 const EMRSETPIXELV
*lpSetPixelV
= (const EMRSETPIXELV
*)mr
;
1374 (INT
)lpSetPixelV
->ptlPixel
.x
,
1375 (INT
)lpSetPixelV
->ptlPixel
.y
,
1376 lpSetPixelV
->crColor
);
1381 case EMR_SETMAPPERFLAGS
:
1383 const EMRSETMAPPERFLAGS
*lpSetMapperFlags
= (const EMRSETMAPPERFLAGS
*)mr
;
1385 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1390 case EMR_SETCOLORADJUSTMENT
:
1392 const EMRSETCOLORADJUSTMENT
*lpSetColorAdjust
= (const EMRSETCOLORADJUSTMENT
*)mr
;
1394 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1399 case EMR_OFFSETCLIPRGN
:
1401 const EMROFFSETCLIPRGN
*lpOffsetClipRgn
= (const EMROFFSETCLIPRGN
*)mr
;
1404 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1405 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1406 FIXME("OffsetClipRgn\n");
1411 case EMR_EXCLUDECLIPRECT
:
1413 const EMREXCLUDECLIPRECT
*lpExcludeClipRect
= (const EMREXCLUDECLIPRECT
*)mr
;
1415 ExcludeClipRect( hdc
,
1416 lpExcludeClipRect
->rclClip
.left
,
1417 lpExcludeClipRect
->rclClip
.top
,
1418 lpExcludeClipRect
->rclClip
.right
,
1419 lpExcludeClipRect
->rclClip
.bottom
);
1420 FIXME("ExcludeClipRect\n");
1425 case EMR_SCALEVIEWPORTEXTEX
:
1427 const EMRSCALEVIEWPORTEXTEX
*lpScaleViewportExtEx
= (const EMRSCALEVIEWPORTEXTEX
*)mr
;
1429 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1431 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1432 !lpScaleViewportExtEx
->yNum
|| !lpScaleViewportExtEx
->yDenom
)
1434 info
->state
.vportExtX
= MulDiv(info
->state
.vportExtX
, lpScaleViewportExtEx
->xNum
,
1435 lpScaleViewportExtEx
->xDenom
);
1436 info
->state
.vportExtY
= MulDiv(info
->state
.vportExtY
, lpScaleViewportExtEx
->yNum
,
1437 lpScaleViewportExtEx
->yDenom
);
1438 if (info
->state
.vportExtX
== 0) info
->state
.vportExtX
= 1;
1439 if (info
->state
.vportExtY
== 0) info
->state
.vportExtY
= 1;
1440 if (info
->state
.mode
== MM_ISOTROPIC
)
1441 EMF_FixIsotropic(hdc
, info
);
1443 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1444 lpScaleViewportExtEx
->xNum
,lpScaleViewportExtEx
->xDenom
,
1445 lpScaleViewportExtEx
->yNum
,lpScaleViewportExtEx
->yDenom
);
1448 EMF_Update_MF_Xform(hdc
, info
);
1453 case EMR_SCALEWINDOWEXTEX
:
1455 const EMRSCALEWINDOWEXTEX
*lpScaleWindowExtEx
= (const EMRSCALEWINDOWEXTEX
*)mr
;
1457 if ((info
->state
.mode
!= MM_ISOTROPIC
) && (info
->state
.mode
!= MM_ANISOTROPIC
))
1459 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1460 !lpScaleWindowExtEx
->yNum
|| !lpScaleWindowExtEx
->yDenom
)
1462 info
->state
.wndExtX
= MulDiv(info
->state
.wndExtX
, lpScaleWindowExtEx
->xNum
,
1463 lpScaleWindowExtEx
->xDenom
);
1464 info
->state
.wndExtY
= MulDiv(info
->state
.wndExtY
, lpScaleWindowExtEx
->yNum
,
1465 lpScaleWindowExtEx
->yDenom
);
1466 if (info
->state
.wndExtX
== 0) info
->state
.wndExtX
= 1;
1467 if (info
->state
.wndExtY
== 0) info
->state
.wndExtY
= 1;
1468 if (info
->state
.mode
== MM_ISOTROPIC
)
1469 EMF_FixIsotropic(hdc
, info
);
1471 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1472 lpScaleWindowExtEx
->xNum
,lpScaleWindowExtEx
->xDenom
,
1473 lpScaleWindowExtEx
->yNum
,lpScaleWindowExtEx
->yDenom
);
1476 EMF_Update_MF_Xform(hdc
, info
);
1481 case EMR_MODIFYWORLDTRANSFORM
:
1483 const EMRMODIFYWORLDTRANSFORM
*lpModifyWorldTrans
= (const EMRMODIFYWORLDTRANSFORM
*)mr
;
1485 switch(lpModifyWorldTrans
->iMode
) {
1487 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
1488 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
1489 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
1491 EMF_Update_MF_Xform(hdc
, info
);
1493 case MWT_LEFTMULTIPLY
:
1494 CombineTransform(&info
->state
.world_transform
, &lpModifyWorldTrans
->xform
,
1495 &info
->state
.world_transform
);
1497 ModifyWorldTransform(hdc
, &lpModifyWorldTrans
->xform
, MWT_LEFTMULTIPLY
);
1499 case MWT_RIGHTMULTIPLY
:
1500 CombineTransform(&info
->state
.world_transform
, &info
->state
.world_transform
,
1501 &lpModifyWorldTrans
->xform
);
1503 EMF_Update_MF_Xform(hdc
, info
);
1506 FIXME("Unknown imode %d\n", lpModifyWorldTrans
->iMode
);
1514 const EMRANGLEARC
*lpAngleArc
= (const EMRANGLEARC
*)mr
;
1517 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1518 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1519 lpAngleArc
->eSweepAngle
);
1526 const EMRROUNDRECT
*lpRoundRect
= (const EMRROUNDRECT
*)mr
;
1529 lpRoundRect
->rclBox
.left
,
1530 lpRoundRect
->rclBox
.top
,
1531 lpRoundRect
->rclBox
.right
,
1532 lpRoundRect
->rclBox
.bottom
,
1533 lpRoundRect
->szlCorner
.cx
,
1534 lpRoundRect
->szlCorner
.cy
);
1541 const EMRARC
*lpArc
= (const EMRARC
*)mr
;
1544 (INT
)lpArc
->rclBox
.left
,
1545 (INT
)lpArc
->rclBox
.top
,
1546 (INT
)lpArc
->rclBox
.right
,
1547 (INT
)lpArc
->rclBox
.bottom
,
1548 (INT
)lpArc
->ptlStart
.x
,
1549 (INT
)lpArc
->ptlStart
.y
,
1550 (INT
)lpArc
->ptlEnd
.x
,
1551 (INT
)lpArc
->ptlEnd
.y
);
1558 const EMRCHORD
*lpChord
= (const EMRCHORD
*)mr
;
1561 (INT
)lpChord
->rclBox
.left
,
1562 (INT
)lpChord
->rclBox
.top
,
1563 (INT
)lpChord
->rclBox
.right
,
1564 (INT
)lpChord
->rclBox
.bottom
,
1565 (INT
)lpChord
->ptlStart
.x
,
1566 (INT
)lpChord
->ptlStart
.y
,
1567 (INT
)lpChord
->ptlEnd
.x
,
1568 (INT
)lpChord
->ptlEnd
.y
);
1575 const EMRPIE
*lpPie
= (const EMRPIE
*)mr
;
1578 (INT
)lpPie
->rclBox
.left
,
1579 (INT
)lpPie
->rclBox
.top
,
1580 (INT
)lpPie
->rclBox
.right
,
1581 (INT
)lpPie
->rclBox
.bottom
,
1582 (INT
)lpPie
->ptlStart
.x
,
1583 (INT
)lpPie
->ptlStart
.y
,
1584 (INT
)lpPie
->ptlEnd
.x
,
1585 (INT
)lpPie
->ptlEnd
.y
);
1592 const EMRARC
*lpArcTo
= (const EMRARC
*)mr
;
1595 (INT
)lpArcTo
->rclBox
.left
,
1596 (INT
)lpArcTo
->rclBox
.top
,
1597 (INT
)lpArcTo
->rclBox
.right
,
1598 (INT
)lpArcTo
->rclBox
.bottom
,
1599 (INT
)lpArcTo
->ptlStart
.x
,
1600 (INT
)lpArcTo
->ptlStart
.y
,
1601 (INT
)lpArcTo
->ptlEnd
.x
,
1602 (INT
)lpArcTo
->ptlEnd
.y
);
1607 case EMR_EXTFLOODFILL
:
1609 const EMREXTFLOODFILL
*lpExtFloodFill
= (const EMREXTFLOODFILL
*)mr
;
1612 (INT
)lpExtFloodFill
->ptlStart
.x
,
1613 (INT
)lpExtFloodFill
->ptlStart
.y
,
1614 lpExtFloodFill
->crColor
,
1615 (UINT
)lpExtFloodFill
->iMode
);
1622 const EMRPOLYDRAW
*lpPolyDraw
= (const EMRPOLYDRAW
*)mr
;
1624 (const POINT
*)lpPolyDraw
->aptl
,
1625 lpPolyDraw
->abTypes
,
1626 (INT
)lpPolyDraw
->cptl
);
1631 case EMR_SETARCDIRECTION
:
1633 const EMRSETARCDIRECTION
*lpSetArcDirection
= (const EMRSETARCDIRECTION
*)mr
;
1634 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1638 case EMR_SETMITERLIMIT
:
1640 const EMRSETMITERLIMIT
*lpSetMiterLimit
= (const EMRSETMITERLIMIT
*)mr
;
1641 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1657 case EMR_CLOSEFIGURE
:
1665 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1670 case EMR_STROKEANDFILLPATH
:
1672 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1673 StrokeAndFillPath( hdc
);
1677 case EMR_STROKEPATH
:
1679 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1684 case EMR_FLATTENPATH
:
1696 case EMR_SELECTCLIPPATH
:
1698 const EMRSELECTCLIPPATH
*lpSelectClipPath
= (const EMRSELECTCLIPPATH
*)mr
;
1699 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1709 case EMR_CREATECOLORSPACE
:
1711 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1712 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1713 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1717 case EMR_SETCOLORSPACE
:
1719 const EMRSETCOLORSPACE
*lpSetColorSpace
= (const EMRSETCOLORSPACE
*)mr
;
1721 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1725 case EMR_DELETECOLORSPACE
:
1727 const EMRDELETECOLORSPACE
*lpDeleteColorSpace
= (const EMRDELETECOLORSPACE
*)mr
;
1728 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1732 case EMR_SETICMMODE
:
1734 const EMRSETICMMODE
*lpSetICMMode
= (const EMRSETICMMODE
*)mr
;
1735 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1739 case EMR_PIXELFORMAT
:
1742 const EMRPIXELFORMAT
*lpPixelFormat
= (const EMRPIXELFORMAT
*)mr
;
1744 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1745 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1750 case EMR_SETPALETTEENTRIES
:
1752 const EMRSETPALETTEENTRIES
*lpSetPaletteEntries
= (const EMRSETPALETTEENTRIES
*)mr
;
1754 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1755 (UINT
)lpSetPaletteEntries
->iStart
,
1756 (UINT
)lpSetPaletteEntries
->cEntries
,
1757 lpSetPaletteEntries
->aPalEntries
);
1762 case EMR_RESIZEPALETTE
:
1764 const EMRRESIZEPALETTE
*lpResizePalette
= (const EMRRESIZEPALETTE
*)mr
;
1766 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1767 (UINT
)lpResizePalette
->cEntries
);
1772 case EMR_CREATEDIBPATTERNBRUSHPT
:
1774 const EMRCREATEDIBPATTERNBRUSHPT
*lpCreate
= (const EMRCREATEDIBPATTERNBRUSHPT
*)mr
;
1775 LPVOID lpPackedStruct
;
1777 /* Check that offsets and data are contained within the record
1778 * (including checking for wrap-arounds).
1780 if ( lpCreate
->offBmi
+ lpCreate
->cbBmi
> mr
->nSize
1781 || lpCreate
->offBits
+ lpCreate
->cbBits
> mr
->nSize
1782 || lpCreate
->offBmi
+ lpCreate
->cbBmi
< lpCreate
->offBmi
1783 || lpCreate
->offBits
+ lpCreate
->cbBits
< lpCreate
->offBits
)
1785 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1789 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1790 lpPackedStruct
= HeapAlloc( GetProcessHeap(), 0,
1791 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1794 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1798 /* Now pack this structure */
1799 memcpy( lpPackedStruct
,
1800 ((const BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1802 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1803 ((const BYTE
*)lpCreate
) + lpCreate
->offBits
,
1806 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1807 CreateDIBPatternBrushPt( lpPackedStruct
,
1808 (UINT
)lpCreate
->iUsage
);
1810 HeapFree(GetProcessHeap(), 0, lpPackedStruct
);
1814 case EMR_CREATEMONOBRUSH
:
1816 const EMRCREATEMONOBRUSH
*pCreateMonoBrush
= (const EMRCREATEMONOBRUSH
*)mr
;
1817 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
1820 /* Need to check if the bitmap is monochrome, and if the
1821 two colors are really black and white */
1822 if (pCreateMonoBrush
->iUsage
== DIB_PAL_MONO
)
1826 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1827 * aligned to 32 rather than 16 bits.
1830 bm
.bmWidth
= pbi
->bmiHeader
.biWidth
;
1831 bm
.bmHeight
= abs(pbi
->bmiHeader
.biHeight
);
1832 bm
.bmWidthBytes
= 4 * ((pbi
->bmiHeader
.biWidth
+ 31) / 32);
1833 bm
.bmPlanes
= pbi
->bmiHeader
.biPlanes
;
1834 bm
.bmBitsPixel
= pbi
->bmiHeader
.biBitCount
;
1835 bm
.bmBits
= (BYTE
*)mr
+ pCreateMonoBrush
->offBits
;
1836 hBmp
= CreateBitmapIndirect(&bm
);
1838 else if (is_dib_monochrome(pbi
))
1840 /* Top-down DIBs have a negative height */
1841 LONG height
= pbi
->bmiHeader
.biHeight
;
1843 hBmp
= CreateBitmap(pbi
->bmiHeader
.biWidth
, abs(height
), 1, 1, NULL
);
1844 SetDIBits(hdc
, hBmp
, 0, pbi
->bmiHeader
.biHeight
,
1845 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1849 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1850 (const BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1853 (handletable
->objectHandle
)[pCreateMonoBrush
->ihBrush
] = CreatePatternBrush(hBmp
);
1855 /* CreatePatternBrush created a copy of the bitmap */
1862 const EMRBITBLT
*pBitBlt
= (const EMRBITBLT
*)mr
;
1864 if(pBitBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1865 PatBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1867 } else { /* BitBlt */
1868 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1869 HBRUSH hBrush
, hBrushOld
;
1870 HBITMAP hBmp
= 0, hBmpOld
= 0;
1871 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pBitBlt
->offBmiSrc
);
1873 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1874 SetWorldTransform(hdcSrc
, &pBitBlt
->xformSrc
);
1876 hBrush
= CreateSolidBrush(pBitBlt
->crBkColorSrc
);
1877 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1878 PatBlt(hdcSrc
, pBitBlt
->rclBounds
.left
, pBitBlt
->rclBounds
.top
,
1879 pBitBlt
->rclBounds
.right
- pBitBlt
->rclBounds
.left
,
1880 pBitBlt
->rclBounds
.bottom
- pBitBlt
->rclBounds
.top
, PATCOPY
);
1881 SelectObject(hdcSrc
, hBrushOld
);
1882 DeleteObject(hBrush
);
1884 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1885 (const BYTE
*)mr
+ pBitBlt
->offBitsSrc
, pbi
, pBitBlt
->iUsageSrc
);
1886 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1888 BitBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1889 hdcSrc
, pBitBlt
->xSrc
, pBitBlt
->ySrc
, pBitBlt
->dwRop
);
1891 SelectObject(hdcSrc
, hBmpOld
);
1898 case EMR_STRETCHBLT
:
1900 const EMRSTRETCHBLT
*pStretchBlt
= (const EMRSTRETCHBLT
*)mr
;
1902 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1903 pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1904 pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1905 pStretchBlt
->dwRop
, pStretchBlt
->offBitsSrc
);
1907 if(pStretchBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1908 PatBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1909 pStretchBlt
->dwRop
);
1910 } else { /* StretchBlt */
1911 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1912 HBRUSH hBrush
, hBrushOld
;
1913 HBITMAP hBmp
= 0, hBmpOld
= 0;
1914 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pStretchBlt
->offBmiSrc
);
1916 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1917 SetWorldTransform(hdcSrc
, &pStretchBlt
->xformSrc
);
1919 hBrush
= CreateSolidBrush(pStretchBlt
->crBkColorSrc
);
1920 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1921 PatBlt(hdcSrc
, pStretchBlt
->rclBounds
.left
, pStretchBlt
->rclBounds
.top
,
1922 pStretchBlt
->rclBounds
.right
- pStretchBlt
->rclBounds
.left
,
1923 pStretchBlt
->rclBounds
.bottom
- pStretchBlt
->rclBounds
.top
, PATCOPY
);
1924 SelectObject(hdcSrc
, hBrushOld
);
1925 DeleteObject(hBrush
);
1927 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1928 (const BYTE
*)mr
+ pStretchBlt
->offBitsSrc
, pbi
, pStretchBlt
->iUsageSrc
);
1929 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1931 StretchBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1932 hdcSrc
, pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1933 pStretchBlt
->dwRop
);
1935 SelectObject(hdcSrc
, hBmpOld
);
1942 case EMR_ALPHABLEND
:
1944 const EMRALPHABLEND
*pAlphaBlend
= (const EMRALPHABLEND
*)mr
;
1946 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1947 pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1948 pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1949 pAlphaBlend
->dwRop
, pAlphaBlend
->offBitsSrc
);
1951 if(pAlphaBlend
->offBmiSrc
== 0) {
1952 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1954 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1955 HBITMAP hBmp
= 0, hBmpOld
= 0;
1956 const BITMAPINFO
*pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pAlphaBlend
->offBmiSrc
);
1959 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1960 SetWorldTransform(hdcSrc
, &pAlphaBlend
->xformSrc
);
1962 hBmp
= CreateDIBSection(hdc
, pbi
, pAlphaBlend
->iUsageSrc
, &bits
, NULL
, 0);
1963 memcpy(bits
, (const BYTE
*)mr
+ pAlphaBlend
->offBitsSrc
, pAlphaBlend
->cbBitsSrc
);
1964 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1966 GdiAlphaBlend(hdc
, pAlphaBlend
->xDest
, pAlphaBlend
->yDest
, pAlphaBlend
->cxDest
, pAlphaBlend
->cyDest
,
1967 hdcSrc
, pAlphaBlend
->xSrc
, pAlphaBlend
->ySrc
, pAlphaBlend
->cxSrc
, pAlphaBlend
->cySrc
,
1968 *(BLENDFUNCTION
*)&pAlphaBlend
->dwRop
);
1970 SelectObject(hdcSrc
, hBmpOld
);
1979 const EMRMASKBLT
*pMaskBlt
= (const EMRMASKBLT
*)mr
;
1980 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1981 HBRUSH hBrush
, hBrushOld
;
1982 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1983 const BITMAPINFO
*pbi
;
1985 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
1986 SetWorldTransform(hdcSrc
, &pMaskBlt
->xformSrc
);
1988 hBrush
= CreateSolidBrush(pMaskBlt
->crBkColorSrc
);
1989 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1990 PatBlt(hdcSrc
, pMaskBlt
->rclBounds
.left
, pMaskBlt
->rclBounds
.top
,
1991 pMaskBlt
->rclBounds
.right
- pMaskBlt
->rclBounds
.left
,
1992 pMaskBlt
->rclBounds
.bottom
- pMaskBlt
->rclBounds
.top
, PATCOPY
);
1993 SelectObject(hdcSrc
, hBrushOld
);
1994 DeleteObject(hBrush
);
1996 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiMask
);
1997 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
1999 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2000 (const BYTE
*)mr
+ pMaskBlt
->offBitsMask
, pbi
, pMaskBlt
->iUsageMask
);
2002 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pMaskBlt
->offBmiSrc
);
2003 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2004 (const BYTE
*)mr
+ pMaskBlt
->offBitsSrc
, pbi
, pMaskBlt
->iUsageSrc
);
2005 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2018 SelectObject(hdcSrc
, hBmpOld
);
2020 DeleteObject(hBmpMask
);
2027 const EMRPLGBLT
*pPlgBlt
= (const EMRPLGBLT
*)mr
;
2028 HDC hdcSrc
= CreateCompatibleDC(hdc
);
2029 HBRUSH hBrush
, hBrushOld
;
2030 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
2031 const BITMAPINFO
*pbi
;
2034 SetGraphicsMode(hdcSrc
, GM_ADVANCED
);
2035 SetWorldTransform(hdcSrc
, &pPlgBlt
->xformSrc
);
2037 pts
[0].x
= pPlgBlt
->aptlDest
[0].x
; pts
[0].y
= pPlgBlt
->aptlDest
[0].y
;
2038 pts
[1].x
= pPlgBlt
->aptlDest
[1].x
; pts
[1].y
= pPlgBlt
->aptlDest
[1].y
;
2039 pts
[2].x
= pPlgBlt
->aptlDest
[2].x
; pts
[2].y
= pPlgBlt
->aptlDest
[2].y
;
2041 hBrush
= CreateSolidBrush(pPlgBlt
->crBkColorSrc
);
2042 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
2043 PatBlt(hdcSrc
, pPlgBlt
->rclBounds
.left
, pPlgBlt
->rclBounds
.top
,
2044 pPlgBlt
->rclBounds
.right
- pPlgBlt
->rclBounds
.left
,
2045 pPlgBlt
->rclBounds
.bottom
- pPlgBlt
->rclBounds
.top
, PATCOPY
);
2046 SelectObject(hdcSrc
, hBrushOld
);
2047 DeleteObject(hBrush
);
2049 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiMask
);
2050 hBmpMask
= CreateBitmap(pbi
->bmiHeader
.biWidth
, pbi
->bmiHeader
.biHeight
,
2052 SetDIBits(hdc
, hBmpMask
, 0, pbi
->bmiHeader
.biHeight
,
2053 (const BYTE
*)mr
+ pPlgBlt
->offBitsMask
, pbi
, pPlgBlt
->iUsageMask
);
2055 pbi
= (const BITMAPINFO
*)((const BYTE
*)mr
+ pPlgBlt
->offBmiSrc
);
2056 hBmp
= CreateDIBitmap(hdc
, (const BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
2057 (const BYTE
*)mr
+ pPlgBlt
->offBitsSrc
, pbi
, pPlgBlt
->iUsageSrc
);
2058 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
2069 SelectObject(hdcSrc
, hBmpOld
);
2071 DeleteObject(hBmpMask
);
2076 case EMR_SETDIBITSTODEVICE
:
2078 const EMRSETDIBITSTODEVICE
*pSetDIBitsToDevice
= (const EMRSETDIBITSTODEVICE
*)mr
;
2080 SetDIBitsToDevice(hdc
,
2081 pSetDIBitsToDevice
->xDest
,
2082 pSetDIBitsToDevice
->yDest
,
2083 pSetDIBitsToDevice
->cxSrc
,
2084 pSetDIBitsToDevice
->cySrc
,
2085 pSetDIBitsToDevice
->xSrc
,
2086 pSetDIBitsToDevice
->ySrc
,
2087 pSetDIBitsToDevice
->iStartScan
,
2088 pSetDIBitsToDevice
->cScans
,
2089 (const BYTE
*)mr
+ pSetDIBitsToDevice
->offBitsSrc
,
2090 (const BITMAPINFO
*)((const BYTE
*)mr
+ pSetDIBitsToDevice
->offBmiSrc
),
2091 pSetDIBitsToDevice
->iUsageSrc
);
2095 case EMR_POLYTEXTOUTA
:
2097 const EMRPOLYTEXTOUTA
*pPolyTextOutA
= (const EMRPOLYTEXTOUTA
*)mr
;
2098 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
2100 XFORM xform
, xformOld
;
2103 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
2104 GetWorldTransform(hdc
, &xformOld
);
2106 xform
.eM11
= pPolyTextOutA
->exScale
;
2109 xform
.eM22
= pPolyTextOutA
->eyScale
;
2112 SetWorldTransform(hdc
, &xform
);
2114 /* Set up POLYTEXTA structures */
2115 for(i
= 0; i
< pPolyTextOutA
->cStrings
; i
++)
2117 polytextA
[i
].x
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.x
;
2118 polytextA
[i
].y
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.y
;
2119 polytextA
[i
].n
= pPolyTextOutA
->aemrtext
[i
].nChars
;
2120 polytextA
[i
].lpstr
= (LPCSTR
)((const BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offString
);
2121 polytextA
[i
].uiFlags
= pPolyTextOutA
->aemrtext
[i
].fOptions
;
2122 polytextA
[i
].rcl
.left
= pPolyTextOutA
->aemrtext
[i
].rcl
.left
;
2123 polytextA
[i
].rcl
.right
= pPolyTextOutA
->aemrtext
[i
].rcl
.right
;
2124 polytextA
[i
].rcl
.top
= pPolyTextOutA
->aemrtext
[i
].rcl
.top
;
2125 polytextA
[i
].rcl
.bottom
= pPolyTextOutA
->aemrtext
[i
].rcl
.bottom
;
2126 polytextA
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offDx
);
2128 PolyTextOutA(hdc
, polytextA
, pPolyTextOutA
->cStrings
);
2129 HeapFree(GetProcessHeap(), 0, polytextA
);
2131 SetWorldTransform(hdc
, &xformOld
);
2132 SetGraphicsMode(hdc
, gModeOld
);
2136 case EMR_POLYTEXTOUTW
:
2138 const EMRPOLYTEXTOUTW
*pPolyTextOutW
= (const EMRPOLYTEXTOUTW
*)mr
;
2139 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
2141 XFORM xform
, xformOld
;
2144 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
2145 GetWorldTransform(hdc
, &xformOld
);
2147 xform
.eM11
= pPolyTextOutW
->exScale
;
2150 xform
.eM22
= pPolyTextOutW
->eyScale
;
2153 SetWorldTransform(hdc
, &xform
);
2155 /* Set up POLYTEXTW structures */
2156 for(i
= 0; i
< pPolyTextOutW
->cStrings
; i
++)
2158 polytextW
[i
].x
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.x
;
2159 polytextW
[i
].y
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.y
;
2160 polytextW
[i
].n
= pPolyTextOutW
->aemrtext
[i
].nChars
;
2161 polytextW
[i
].lpstr
= (LPCWSTR
)((const BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offString
);
2162 polytextW
[i
].uiFlags
= pPolyTextOutW
->aemrtext
[i
].fOptions
;
2163 polytextW
[i
].rcl
.left
= pPolyTextOutW
->aemrtext
[i
].rcl
.left
;
2164 polytextW
[i
].rcl
.right
= pPolyTextOutW
->aemrtext
[i
].rcl
.right
;
2165 polytextW
[i
].rcl
.top
= pPolyTextOutW
->aemrtext
[i
].rcl
.top
;
2166 polytextW
[i
].rcl
.bottom
= pPolyTextOutW
->aemrtext
[i
].rcl
.bottom
;
2167 polytextW
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offDx
);
2169 PolyTextOutW(hdc
, polytextW
, pPolyTextOutW
->cStrings
);
2170 HeapFree(GetProcessHeap(), 0, polytextW
);
2172 SetWorldTransform(hdc
, &xformOld
);
2173 SetGraphicsMode(hdc
, gModeOld
);
2179 const EMRFILLRGN
*pFillRgn
= (const EMRFILLRGN
*)mr
;
2180 HRGN hRgn
= ExtCreateRegion(NULL
, pFillRgn
->cbRgnData
, (const RGNDATA
*)pFillRgn
->RgnData
);
2183 (handletable
->objectHandle
)[pFillRgn
->ihBrush
]);
2190 const EMRFRAMERGN
*pFrameRgn
= (const EMRFRAMERGN
*)mr
;
2191 HRGN hRgn
= ExtCreateRegion(NULL
, pFrameRgn
->cbRgnData
, (const RGNDATA
*)pFrameRgn
->RgnData
);
2194 (handletable
->objectHandle
)[pFrameRgn
->ihBrush
],
2195 pFrameRgn
->szlStroke
.cx
,
2196 pFrameRgn
->szlStroke
.cy
);
2203 const EMRINVERTRGN
*pInvertRgn
= (const EMRINVERTRGN
*)mr
;
2204 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (const RGNDATA
*)pInvertRgn
->RgnData
);
2205 InvertRgn(hdc
, hRgn
);
2212 const EMRPAINTRGN
*pPaintRgn
= (const EMRPAINTRGN
*)mr
;
2213 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (const RGNDATA
*)pPaintRgn
->RgnData
);
2214 PaintRgn(hdc
, hRgn
);
2219 case EMR_SETTEXTJUSTIFICATION
:
2221 const EMRSETTEXTJUSTIFICATION
*pSetTextJust
= (const EMRSETTEXTJUSTIFICATION
*)mr
;
2222 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
2228 const EMRSETLAYOUT
*pSetLayout
= (const EMRSETLAYOUT
*)mr
;
2229 SetLayout(hdc
, pSetLayout
->iMode
);
2233 case EMR_GRADIENTFILL
:
2235 EMRGRADIENTFILL
*grad
= (EMRGRADIENTFILL
*)mr
;
2236 GdiGradientFill( hdc
, grad
->Ver
, grad
->nVer
, grad
->Ver
+ grad
->nVer
,
2237 grad
->nTri
, grad
->ulMode
);
2241 case EMR_POLYDRAW16
:
2243 case EMR_GLSBOUNDEDRECORD
:
2244 case EMR_DRAWESCAPE
:
2247 case EMR_SMALLTEXTOUT
:
2248 case EMR_FORCEUFIMAPPING
:
2249 case EMR_NAMEDESCAPE
:
2250 case EMR_COLORCORRECTPALETTE
:
2251 case EMR_SETICMPROFILEA
:
2252 case EMR_SETICMPROFILEW
:
2253 case EMR_TRANSPARENTBLT
:
2254 case EMR_SETLINKEDUFI
:
2255 case EMR_COLORMATCHTOTARGETW
:
2256 case EMR_CREATECOLORSPACEW
:
2259 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2260 record then ignore and return TRUE. */
2261 FIXME("type %d is unimplemented\n", type
);
2264 tmprc
.left
= tmprc
.top
= 0;
2265 tmprc
.right
= tmprc
.bottom
= 1000;
2266 LPtoDP(hdc
, (POINT
*)&tmprc
, 2);
2267 TRACE("L:0,0 - 1000,1000 -> D:%s\n", wine_dbgstr_rect(&tmprc
));
2273 /*****************************************************************************
2275 * EnumEnhMetaFile (GDI32.@)
2277 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2279 * record. Returns when either every record has been used or
2280 * when _EnhMetaFunc_ returns FALSE.
2284 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2291 * This function behaves differently in Win9x and WinNT.
2293 * In WinNT, the DC's world transform is updated as the EMF changes
2294 * the Window/Viewport Extent and Origin or its world transform.
2295 * The actual Window/Viewport Extent and Origin are left untouched.
2297 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2298 * updates the scaling itself but only just before a record that
2299 * writes anything to the DC.
2301 * I'm not sure where the data (enum_emh_data) is stored in either
2302 * version. For this implementation, it is stored before the handle
2303 * table, but it could be stored in the DC, in the EMF handle or in
2307 BOOL WINAPI
EnumEnhMetaFile(
2308 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
2309 HENHMETAFILE hmf
, /* [in] EMF to walk */
2310 ENHMFENUMPROC callback
, /* [in] callback function */
2311 LPVOID data
, /* [in] optional data for callback function */
2312 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
2324 HBRUSH hBrush
= NULL
;
2327 enum_emh_data
*info
;
2328 SIZE vp_size
, win_size
;
2329 POINT vp_org
, win_org
;
2330 INT mapMode
= MM_TEXT
, old_align
= 0, old_rop2
= 0, old_arcdir
= 0, old_polyfill
= 0, old_stretchblt
= 0;
2331 COLORREF old_text_color
= 0, old_bk_color
= 0;
2335 SetLastError(ERROR_INVALID_PARAMETER
);
2339 emh
= EMF_GetEnhMetaHeader(hmf
);
2341 SetLastError(ERROR_INVALID_HANDLE
);
2345 info
= HeapAlloc( GetProcessHeap(), 0,
2346 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2349 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2352 info
->state
.mode
= MM_TEXT
;
2353 info
->state
.wndOrgX
= 0;
2354 info
->state
.wndOrgY
= 0;
2355 info
->state
.wndExtX
= 1;
2356 info
->state
.wndExtY
= 1;
2357 info
->state
.vportOrgX
= 0;
2358 info
->state
.vportOrgY
= 0;
2359 info
->state
.vportExtX
= 1;
2360 info
->state
.vportExtY
= 1;
2361 info
->state
.world_transform
.eM11
= info
->state
.world_transform
.eM22
= 1;
2362 info
->state
.world_transform
.eM12
= info
->state
.world_transform
.eM21
= 0;
2363 info
->state
.world_transform
.eDx
= info
->state
.world_transform
.eDy
= 0;
2365 info
->state
.next
= NULL
;
2366 info
->save_level
= 0;
2367 info
->saved_state
= NULL
;
2369 ht
= (HANDLETABLE
*) &info
[1];
2370 ht
->objectHandle
[0] = hmf
;
2371 for(i
= 1; i
< emh
->nHandles
; i
++)
2372 ht
->objectHandle
[i
] = NULL
;
2376 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
2377 GetWorldTransform(hdc
, &savedXform
);
2378 GetViewportExtEx(hdc
, &vp_size
);
2379 GetWindowExtEx(hdc
, &win_size
);
2380 GetViewportOrgEx(hdc
, &vp_org
);
2381 GetWindowOrgEx(hdc
, &win_org
);
2382 mapMode
= GetMapMode(hdc
);
2385 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
2386 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
2387 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
2389 hRgn
= CreateRectRgn(0, 0, 0, 0);
2390 if (!GetClipRgn(hdc
, hRgn
))
2396 old_text_color
= SetTextColor(hdc
, RGB(0,0,0));
2397 old_bk_color
= SetBkColor(hdc
, RGB(0xff, 0xff, 0xff));
2398 old_align
= SetTextAlign(hdc
, 0);
2399 old_rop2
= SetROP2(hdc
, R2_COPYPEN
);
2400 old_arcdir
= SetArcDirection(hdc
, AD_COUNTERCLOCKWISE
);
2401 old_polyfill
= SetPolyFillMode(hdc
, ALTERNATE
);
2402 old_stretchblt
= SetStretchBltMode(hdc
, BLACKONWHITE
);
2406 /* Win95 leaves the vp/win ext/org info alone */
2407 info
->init_transform
.eM11
= 1.0;
2408 info
->init_transform
.eM12
= 0.0;
2409 info
->init_transform
.eM21
= 0.0;
2410 info
->init_transform
.eM22
= 1.0;
2411 info
->init_transform
.eDx
= 0.0;
2412 info
->init_transform
.eDy
= 0.0;
2416 /* WinNT combines the vp/win ext/org info into a transform */
2417 double xscale
, yscale
;
2418 xscale
= (double)vp_size
.cx
/ (double)win_size
.cx
;
2419 yscale
= (double)vp_size
.cy
/ (double)win_size
.cy
;
2420 info
->init_transform
.eM11
= xscale
;
2421 info
->init_transform
.eM12
= 0.0;
2422 info
->init_transform
.eM21
= 0.0;
2423 info
->init_transform
.eM22
= yscale
;
2424 info
->init_transform
.eDx
= (double)vp_org
.x
- xscale
* (double)win_org
.x
;
2425 info
->init_transform
.eDy
= (double)vp_org
.y
- yscale
* (double)win_org
.y
;
2427 CombineTransform(&info
->init_transform
, &savedXform
, &info
->init_transform
);
2430 if ( lpRect
&& WIDTH(emh
->rclFrame
) && HEIGHT(emh
->rclFrame
) )
2432 double xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
2435 TRACE("rect: %s. rclFrame: (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(lpRect
),
2436 emh
->rclFrame
.left
, emh
->rclFrame
.top
, emh
->rclFrame
.right
,
2437 emh
->rclFrame
.bottom
);
2439 xSrcPixSize
= (double) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
2440 ySrcPixSize
= (double) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
2441 xscale
= (double) WIDTH(*lpRect
) * 100.0 /
2442 WIDTH(emh
->rclFrame
) * xSrcPixSize
;
2443 yscale
= (double) HEIGHT(*lpRect
) * 100.0 /
2444 HEIGHT(emh
->rclFrame
) * ySrcPixSize
;
2445 TRACE("xscale = %f, yscale = %f\n", xscale
, yscale
);
2447 xform
.eM11
= xscale
;
2450 xform
.eM22
= yscale
;
2451 xform
.eDx
= (double) lpRect
->left
- (double) WIDTH(*lpRect
) / WIDTH(emh
->rclFrame
) * emh
->rclFrame
.left
;
2452 xform
.eDy
= (double) lpRect
->top
- (double) HEIGHT(*lpRect
) / HEIGHT(emh
->rclFrame
) * emh
->rclFrame
.top
;
2454 CombineTransform(&info
->init_transform
, &xform
, &info
->init_transform
);
2457 /* WinNT resets the current vp/win org/ext */
2460 SetMapMode(hdc
, MM_TEXT
);
2461 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2462 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2463 EMF_Update_MF_Xform(hdc
, info
);
2469 while(ret
&& offset
< emh
->nBytes
)
2471 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
2473 if (offset
+ 8 > emh
->nBytes
||
2474 offset
> offset
+ emr
->nSize
||
2475 offset
+ emr
->nSize
> emh
->nBytes
)
2477 WARN("record truncated\n");
2481 /* In Win9x mode we update the xform if the record will produce output */
2482 if (hdc
&& IS_WIN9X() && emr_produces_output(emr
->iType
))
2483 EMF_Update_MF_Xform(hdc
, info
);
2485 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr
->iType
), emr
->nSize
);
2486 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nHandles
, (LPARAM
)data
);
2487 offset
+= emr
->nSize
;
2492 SetStretchBltMode(hdc
, old_stretchblt
);
2493 SetPolyFillMode(hdc
, old_polyfill
);
2494 SetArcDirection(hdc
, old_arcdir
);
2495 SetROP2(hdc
, old_rop2
);
2496 SetTextAlign(hdc
, old_align
);
2497 SetBkColor(hdc
, old_bk_color
);
2498 SetTextColor(hdc
, old_text_color
);
2501 SelectObject(hdc
, hBrush
);
2502 SelectObject(hdc
, hPen
);
2503 SelectObject(hdc
, hFont
);
2504 ExtSelectClipRgn(hdc
, hRgn
, RGN_COPY
);
2507 SetWorldTransform(hdc
, &savedXform
);
2509 SetGraphicsMode(hdc
, savedMode
);
2510 SetMapMode(hdc
, mapMode
);
2511 SetWindowOrgEx(hdc
, win_org
.x
, win_org
.y
, NULL
);
2512 SetWindowExtEx(hdc
, win_size
.cx
, win_size
.cy
, NULL
);
2513 SetViewportOrgEx(hdc
, vp_org
.x
, vp_org
.y
, NULL
);
2514 SetViewportExtEx(hdc
, vp_size
.cx
, vp_size
.cy
, NULL
);
2517 for(i
= 1; i
< emh
->nHandles
; i
++) /* Don't delete element 0 (hmf) */
2518 if( (ht
->objectHandle
)[i
] )
2519 DeleteObject( (ht
->objectHandle
)[i
] );
2521 while (info
->saved_state
)
2523 EMF_dc_state
*state
= info
->saved_state
;
2524 info
->saved_state
= info
->saved_state
->next
;
2525 HeapFree( GetProcessHeap(), 0, state
);
2527 HeapFree( GetProcessHeap(), 0, info
);
2531 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
2532 const ENHMETARECORD
*emr
,
2533 INT handles
, LPARAM data
)
2535 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
2538 /**************************************************************************
2539 * PlayEnhMetaFile (GDI32.@)
2541 * Renders an enhanced metafile into a specified rectangle *lpRect
2542 * in device context hdc.
2548 BOOL WINAPI
PlayEnhMetaFile(
2549 HDC hdc
, /* [in] DC to render into */
2550 HENHMETAFILE hmf
, /* [in] metafile to render */
2551 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
2554 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
2558 /*****************************************************************************
2559 * DeleteEnhMetaFile (GDI32.@)
2561 * Deletes an enhanced metafile and frees the associated storage.
2563 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
2565 return EMF_Delete_HENHMETAFILE( hmf
);
2568 /*****************************************************************************
2569 * CopyEnhMetaFileA (GDI32.@)
2571 * Duplicate an enhanced metafile.
2575 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
2576 HENHMETAFILE hmfSrc
,
2579 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2580 HENHMETAFILE hmfDst
;
2582 if(!emrSrc
) return FALSE
;
2584 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2585 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2586 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2588 HeapFree( GetProcessHeap(), 0, emrDst
);
2592 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2593 NULL
, CREATE_ALWAYS
, 0, 0);
2594 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2595 CloseHandle( hFile
);
2596 /* Reopen file for reading only, so that apps can share
2597 read access to the file while hmf is still valid */
2598 hFile
= CreateFileA( file
, GENERIC_READ
, FILE_SHARE_READ
,
2599 NULL
, OPEN_EXISTING
, 0, 0);
2600 if(hFile
== INVALID_HANDLE_VALUE
) {
2601 ERR("Can't reopen emf for reading\n");
2604 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2605 CloseHandle( hFile
);
2610 /*****************************************************************************
2611 * CopyEnhMetaFileW (GDI32.@)
2613 * See CopyEnhMetaFileA.
2617 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2618 HENHMETAFILE hmfSrc
,
2621 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2622 HENHMETAFILE hmfDst
;
2624 if(!emrSrc
) return FALSE
;
2626 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2627 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2628 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, emrSrc
->nBytes
, FALSE
);
2630 HeapFree( GetProcessHeap(), 0, emrDst
);
2634 hFile
= CreateFileW( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2635 NULL
, CREATE_ALWAYS
, 0, 0);
2636 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, &w
, NULL
);
2637 CloseHandle( hFile
);
2638 /* Reopen file for reading only, so that apps can share
2639 read access to the file while hmf is still valid */
2640 hFile
= CreateFileW( file
, GENERIC_READ
, FILE_SHARE_READ
,
2641 NULL
, OPEN_EXISTING
, 0, 0);
2642 if(hFile
== INVALID_HANDLE_VALUE
) {
2643 ERR("Can't reopen emf for reading\n");
2646 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2647 CloseHandle( hFile
);
2653 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2654 typedef struct tagEMF_PaletteCopy
2657 LPPALETTEENTRY lpPe
;
2660 /***************************************************************
2661 * Find the EMR_EOF record and then use it to find the
2662 * palette entries for this enhanced metafile.
2663 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2664 * which contains the max number of elements to copy and where
2667 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2669 static INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2671 const ENHMETARECORD
*lpEMR
,
2676 if ( lpEMR
->iType
== EMR_EOF
)
2678 const EMREOF
*lpEof
= (const EMREOF
*)lpEMR
;
2679 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
2680 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
2682 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy
);
2684 memcpy( info
->lpPe
, (LPCSTR
)lpEof
+ lpEof
->offPalEntries
,
2685 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
2687 /* Update the passed data as a return code */
2688 info
->lpPe
= NULL
; /* Palettes were copied! */
2689 info
->cEntries
= dwNumPalToCopy
;
2691 return FALSE
; /* That's all we need */
2697 /*****************************************************************************
2698 * GetEnhMetaFilePaletteEntries (GDI32.@)
2700 * Copy the palette and report size
2702 * BUGS: Error codes (SetLastError) are not set on failures
2704 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
2706 LPPALETTEENTRY lpPe
)
2708 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
2709 EMF_PaletteCopy infoForCallBack
;
2711 TRACE( "(%p,%d,%p)\n", hEmf
, cEntries
, lpPe
);
2713 if (!enhHeader
) return 0;
2715 /* First check if there are any palettes associated with
2717 if ( enhHeader
->nPalEntries
== 0 ) return 0;
2719 /* Is the user requesting the number of palettes? */
2720 if ( lpPe
== NULL
) return enhHeader
->nPalEntries
;
2722 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2723 infoForCallBack
.cEntries
= cEntries
;
2724 infoForCallBack
.lpPe
= lpPe
;
2726 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
2727 &infoForCallBack
, 0 ) )
2730 /* Verify that the callback executed correctly */
2731 if ( infoForCallBack
.lpPe
!= NULL
)
2733 /* Callback proc had error! */
2734 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2738 return infoForCallBack
.cEntries
;
2741 /******************************************************************
2742 * extract_emf_from_comment
2744 * If the WMF was created by GetWinMetaFileBits, then extract the
2745 * original EMF that is stored in MFCOMMENT chunks.
2747 static HENHMETAFILE
extract_emf_from_comment( const BYTE
*buf
, UINT mf_size
)
2749 METAHEADER
*mh
= (METAHEADER
*)buf
;
2751 emf_in_wmf_comment
*chunk
;
2753 DWORD size
= 0, remaining
, chunks
;
2754 BYTE
*emf_bits
= NULL
, *ptr
;
2756 HENHMETAFILE emf
= NULL
;
2758 if (mf_size
< sizeof(*mh
)) return NULL
;
2760 for (offset
= mh
->mtHeaderSize
* 2; offset
< mf_size
; offset
+= (mr
->rdSize
* 2))
2762 mr
= (METARECORD
*)((char *)mh
+ offset
);
2763 chunk
= (emf_in_wmf_comment
*)(mr
->rdParm
+ 2);
2765 if (mr
->rdFunction
!= META_ESCAPE
|| mr
->rdParm
[0] != MFCOMMENT
) goto done
;
2766 if (chunk
->magic
!= WMFC_MAGIC
) goto done
;
2770 size
= remaining
= chunk
->emf_size
;
2771 chunks
= chunk
->num_chunks
;
2772 emf_bits
= ptr
= HeapAlloc( GetProcessHeap(), 0, size
);
2773 if (!emf_bits
) goto done
;
2775 if (chunk
->chunk_size
> remaining
) goto done
;
2776 remaining
-= chunk
->chunk_size
;
2777 if (chunk
->remaining_size
!= remaining
) goto done
;
2778 memcpy( ptr
, chunk
->emf_data
, chunk
->chunk_size
);
2779 ptr
+= chunk
->chunk_size
;
2780 if (--chunks
== 0) break;
2783 for (offset
= 0; offset
< mf_size
/ 2; offset
++)
2784 checksum
+= *((WORD
*)buf
+ offset
);
2785 if (checksum
) goto done
;
2787 emf
= SetEnhMetaFileBits( size
, emf_bits
);
2790 HeapFree( GetProcessHeap(), 0, emf_bits
);
2794 typedef struct wmf_in_emf_comment
2801 DWORD cbWinMetaFile
;
2802 } wmf_in_emf_comment
;
2804 /******************************************************************
2805 * SetWinMetaFileBits (GDI32.@)
2807 * Translate from old style to new style.
2810 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
, const BYTE
*lpbBuffer
, HDC hdcRef
,
2811 const METAFILEPICT
*lpmfp
)
2813 static const WCHAR szDisplayW
[] = { 'D','I','S','P','L','A','Y','\0' };
2814 HMETAFILE hmf
= NULL
;
2815 HENHMETAFILE ret
= NULL
;
2816 HDC hdc
= NULL
, hdcdisp
= NULL
;
2817 RECT rc
, *prcFrame
= NULL
;
2818 LONG mm
, xExt
, yExt
;
2819 INT horzsize
, vertsize
, horzres
, vertres
;
2821 TRACE("(%d, %p, %p, %p)\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
2823 hmf
= SetMetaFileBitsEx(cbBuffer
, lpbBuffer
);
2826 WARN("SetMetaFileBitsEx failed\n");
2830 ret
= extract_emf_from_comment( lpbBuffer
, cbBuffer
);
2831 if (ret
) return ret
;
2834 hdcRef
= hdcdisp
= CreateDCW(szDisplayW
, NULL
, NULL
, NULL
);
2838 TRACE("mm = %d %dx%d\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2846 TRACE("lpmfp == NULL\n");
2848 /* Use the whole device surface */
2849 mm
= MM_ANISOTROPIC
;
2854 if (mm
== MM_ISOTROPIC
|| mm
== MM_ANISOTROPIC
)
2856 if (xExt
< 0 || yExt
< 0)
2858 /* Use the whole device surface */
2863 /* Use the x and y extents as the frame box */
2866 rc
.left
= rc
.top
= 0;
2873 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
)))
2875 ERR("CreateEnhMetaFile failed\n");
2880 * Write the original METAFILE into the enhanced metafile.
2881 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2885 wmf_in_emf_comment
*mfcomment
;
2886 UINT mfcomment_size
;
2888 mfcomment_size
= sizeof (*mfcomment
) + cbBuffer
;
2889 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
2892 mfcomment
->ident
= GDICOMMENT_IDENTIFIER
;
2893 mfcomment
->iComment
= GDICOMMENT_WINDOWS_METAFILE
;
2894 mfcomment
->nVersion
= 0x00000300;
2895 mfcomment
->nChecksum
= 0; /* FIXME */
2896 mfcomment
->fFlags
= 0;
2897 mfcomment
->cbWinMetaFile
= cbBuffer
;
2898 memcpy(&mfcomment
[1], lpbBuffer
, cbBuffer
);
2899 GdiComment(hdc
, mfcomment_size
, (BYTE
*) mfcomment
);
2900 HeapFree(GetProcessHeap(), 0, mfcomment
);
2902 SetMapMode(hdc
, mm
);
2906 horzsize
= GetDeviceCaps(hdcRef
, HORZSIZE
);
2907 vertsize
= GetDeviceCaps(hdcRef
, VERTSIZE
);
2908 horzres
= GetDeviceCaps(hdcRef
, HORZRES
);
2909 vertres
= GetDeviceCaps(hdcRef
, VERTRES
);
2913 /* Use the whole device surface */
2919 xExt
= MulDiv(xExt
, horzres
, 100 * horzsize
);
2920 yExt
= MulDiv(yExt
, vertres
, 100 * vertsize
);
2923 /* set the initial viewport:window ratio as 1:1 */
2924 SetViewportExtEx(hdc
, xExt
, yExt
, NULL
);
2925 SetWindowExtEx(hdc
, xExt
, yExt
, NULL
);
2927 PlayMetaFile(hdc
, hmf
);
2929 ret
= CloseEnhMetaFile(hdc
);
2931 if (hdcdisp
) DeleteDC(hdcdisp
);
2932 DeleteMetaFile(hmf
);