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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "wine/debug.h"
48 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 %ld\n", type
);
198 /****************************************************************************
199 * EMF_Create_HENHMETAFILE
201 HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, BOOL on_disk
)
203 HENHMETAFILE hmf
= 0;
204 ENHMETAFILEOBJ
*metaObj
= GDI_AllocObject( sizeof(ENHMETAFILEOBJ
),
206 (HGDIOBJ
*)&hmf
, NULL
);
210 metaObj
->on_disk
= on_disk
;
211 GDI_ReleaseObj( hmf
);
216 /****************************************************************************
217 * EMF_Delete_HENHMETAFILE
219 static BOOL
EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf
)
221 ENHMETAFILEOBJ
*metaObj
= (ENHMETAFILEOBJ
*)GDI_GetObjPtr( hmf
,
223 if(!metaObj
) return FALSE
;
226 UnmapViewOfFile( metaObj
->emh
);
228 HeapFree( GetProcessHeap(), 0, metaObj
->emh
);
229 return GDI_FreeObject( hmf
, metaObj
);
232 /******************************************************************
233 * EMF_GetEnhMetaHeader
235 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
237 static ENHMETAHEADER
*EMF_GetEnhMetaHeader( HENHMETAFILE hmf
)
239 ENHMETAHEADER
*ret
= NULL
;
240 ENHMETAFILEOBJ
*metaObj
= (ENHMETAFILEOBJ
*)GDI_GetObjPtr( hmf
, ENHMETAFILE_MAGIC
);
241 TRACE("hmf %p -> enhmetaObj %p\n", hmf
, metaObj
);
245 GDI_ReleaseObj( hmf
);
250 /*****************************************************************************
254 static HENHMETAFILE
EMF_GetEnhMetaFile( HANDLE hFile
)
259 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
260 emh
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, 0 );
261 CloseHandle( hMapping
);
265 if (emh
->iType
!= EMR_HEADER
|| emh
->dSignature
!= ENHMETA_SIGNATURE
) {
266 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
267 emh
->iType
, emh
->dSignature
);
271 /* refuse to load unaligned EMF as Windows does */
274 WARN("Refusing to load unaligned EMF\n");
278 return EMF_Create_HENHMETAFILE( emh
, TRUE
);
281 UnmapViewOfFile( emh
);
286 /*****************************************************************************
287 * GetEnhMetaFileA (GDI32.@)
291 HENHMETAFILE WINAPI
GetEnhMetaFileA(
292 LPCSTR lpszMetaFile
/* [in] filename of enhanced metafile */
298 hFile
= CreateFileA(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
299 OPEN_EXISTING
, 0, 0);
300 if (hFile
== INVALID_HANDLE_VALUE
) {
301 WARN("could not open %s\n", lpszMetaFile
);
304 hmf
= EMF_GetEnhMetaFile( hFile
);
305 CloseHandle( hFile
);
309 /*****************************************************************************
310 * GetEnhMetaFileW (GDI32.@)
312 HENHMETAFILE WINAPI
GetEnhMetaFileW(
313 LPCWSTR lpszMetaFile
) /* [in] filename of enhanced metafile */
318 hFile
= CreateFileW(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
319 OPEN_EXISTING
, 0, 0);
320 if (hFile
== INVALID_HANDLE_VALUE
) {
321 WARN("could not open %s\n", debugstr_w(lpszMetaFile
));
324 hmf
= EMF_GetEnhMetaFile( hFile
);
325 CloseHandle( hFile
);
329 /*****************************************************************************
330 * GetEnhMetaFileHeader (GDI32.@)
332 * If buf is NULL, returns the size of buffer required.
333 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
336 UINT WINAPI
GetEnhMetaFileHeader(
337 HENHMETAFILE hmf
, /* [in] enhanced metafile */
338 UINT bufsize
, /* [in] size of buffer */
339 LPENHMETAHEADER buf
/* [out] buffer */
345 emh
= EMF_GetEnhMetaHeader(hmf
);
346 if(!emh
) return FALSE
;
348 if (!buf
) return size
;
349 size
= min(size
, bufsize
);
350 memmove(buf
, emh
, size
);
355 /*****************************************************************************
356 * GetEnhMetaFileDescriptionA (GDI32.@)
358 UINT WINAPI
GetEnhMetaFileDescriptionA(
359 HENHMETAFILE hmf
, /* [in] enhanced metafile */
360 UINT size
, /* [in] size of buf */
361 LPSTR buf
/* [out] buffer to receive description */
364 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
368 if(!emh
) return FALSE
;
369 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
370 descrW
= (WCHAR
*) ((char *) emh
+ emh
->offDescription
);
371 len
= WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, NULL
, 0, NULL
, NULL
);
373 if (!buf
|| !size
) return len
;
375 len
= min( size
, len
);
376 WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, buf
, len
, NULL
, NULL
);
380 /*****************************************************************************
381 * GetEnhMetaFileDescriptionW (GDI32.@)
383 * Copies the description string of an enhanced metafile into a buffer
386 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
387 * number of characters copied.
389 UINT WINAPI
GetEnhMetaFileDescriptionW(
390 HENHMETAFILE hmf
, /* [in] enhanced metafile */
391 UINT size
, /* [in] size of buf */
392 LPWSTR buf
/* [out] buffer to receive description */
395 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
397 if(!emh
) return FALSE
;
398 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) return 0;
399 if (!buf
|| !size
) return emh
->nDescription
;
401 memmove(buf
, (char *) emh
+ emh
->offDescription
, min(size
,emh
->nDescription
)*sizeof(WCHAR
));
402 return min(size
, emh
->nDescription
);
405 /****************************************************************************
406 * SetEnhMetaFileBits (GDI32.@)
408 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
410 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
412 ENHMETAHEADER
*emh
= HeapAlloc( GetProcessHeap(), 0, bufsize
);
413 memmove(emh
, buf
, bufsize
);
414 return EMF_Create_HENHMETAFILE( emh
, FALSE
);
417 /*****************************************************************************
418 * GetEnhMetaFileBits (GDI32.@)
421 UINT WINAPI
GetEnhMetaFileBits(
427 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
433 if( buf
== NULL
) return size
;
435 size
= min( size
, bufsize
);
436 memmove(buf
, emh
, size
);
440 typedef struct enum_emh_data
443 XFORM init_transform
;
444 XFORM world_transform
;
455 #define ENUM_GET_PRIVATE_DATA(ht) \
456 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
458 #define WIDTH(rect) ( (rect).right - (rect).left )
459 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
461 #define IS_WIN9X() (GetVersion()&0x80000000)
463 void EMF_Update_MF_Xform(HDC hdc
, enum_emh_data
*info
)
465 XFORM mapping_mode_trans
, final_trans
;
466 FLOAT scaleX
, scaleY
;
468 scaleX
= (FLOAT
)info
->vportExtX
/ (FLOAT
)info
->wndExtX
;
469 scaleY
= (FLOAT
)info
->vportExtY
/ (FLOAT
)info
->wndExtY
;
470 mapping_mode_trans
.eM11
= scaleX
;
471 mapping_mode_trans
.eM12
= 0.0;
472 mapping_mode_trans
.eM21
= 0.0;
473 mapping_mode_trans
.eM22
= scaleY
;
474 mapping_mode_trans
.eDx
= (FLOAT
)info
->vportOrgX
- scaleX
* (FLOAT
)info
->wndOrgX
;
475 mapping_mode_trans
.eDy
= (FLOAT
)info
->vportOrgY
- scaleY
* (FLOAT
)info
->wndOrgY
;
477 CombineTransform(&final_trans
, &info
->world_transform
, &mapping_mode_trans
);
478 CombineTransform(&final_trans
, &final_trans
, &info
->init_transform
);
480 if (!SetWorldTransform(hdc
, &final_trans
))
482 ERR("World transform failed!\n");
486 void EMF_SetMapMode(HDC hdc
, enum_emh_data
*info
)
488 INT horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
489 INT vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
490 INT horzRes
= GetDeviceCaps( hdc
, HORZRES
);
491 INT vertRes
= GetDeviceCaps( hdc
, VERTRES
);
493 TRACE("%d\n",info
->mode
);
505 info
->wndExtX
= horzSize
* 10;
506 info
->wndExtY
= vertSize
* 10;
507 info
->vportExtX
= horzRes
;
508 info
->vportExtY
= -vertRes
;
511 info
->wndExtX
= horzSize
* 100;
512 info
->wndExtY
= vertSize
* 100;
513 info
->vportExtX
= horzRes
;
514 info
->vportExtY
= -vertRes
;
517 info
->wndExtX
= MulDiv(1000, horzSize
, 254);
518 info
->wndExtY
= MulDiv(1000, vertSize
, 254);
519 info
->vportExtX
= horzRes
;
520 info
->vportExtY
= -vertRes
;
523 info
->wndExtX
= MulDiv(10000, horzSize
, 254);
524 info
->wndExtY
= MulDiv(10000, vertSize
, 254);
525 info
->vportExtX
= horzRes
;
526 info
->vportExtY
= -vertRes
;
529 info
->wndExtX
= MulDiv(14400, horzSize
, 254);
530 info
->wndExtY
= MulDiv(14400, vertSize
, 254);
531 info
->vportExtX
= horzRes
;
532 info
->vportExtY
= -vertRes
;
541 /*****************************************************************************
542 * emr_produces_output
544 * Returns TRUE if the record type writes something to the dc. Used by
545 * PlayEnhMetaFileRecord to determine whether it needs to update the
546 * dc's xform when in win9x mode.
548 * FIXME: need to test which records should be here.
550 static BOOL
emr_produces_output(int type
)
556 case EMR_POLYBEZIERTO
:
558 case EMR_POLYPOLYLINE
:
559 case EMR_POLYPOLYGON
:
562 case EMR_EXCLUDECLIPRECT
:
563 case EMR_INTERSECTCLIPRECT
:
564 case EMR_SELECTOBJECT
:
572 case EMR_EXTFLOODFILL
:
584 case EMR_SETDIBITSTODEVICE
:
585 case EMR_STRETCHDIBITS
:
586 case EMR_EXTTEXTOUTA
:
587 case EMR_EXTTEXTOUTW
:
588 case EMR_POLYBEZIER16
:
591 case EMR_POLYBEZIERTO16
:
592 case EMR_POLYLINETO16
:
593 case EMR_POLYPOLYLINE16
:
594 case EMR_POLYPOLYGON16
:
596 case EMR_POLYTEXTOUTA
:
597 case EMR_POLYTEXTOUTW
:
598 case EMR_SMALLTEXTOUT
:
599 case EMR_TRANSPARENTBLT
:
607 /*****************************************************************************
608 * PlayEnhMetaFileRecord (GDI32.@)
610 * Render a single enhanced metafile record in the device context hdc.
613 * TRUE (non zero) on success, FALSE on error.
615 * Many unimplemented records.
616 * No error handling on record play failures (ie checking return codes)
619 * WinNT actually updates the current world transform in this function
620 * whereas Win9x does not.
622 BOOL WINAPI
PlayEnhMetaFileRecord(
623 HDC hdc
, /* [in] device context in which to render EMF record */
624 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
625 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
626 UINT handles
/* [in] size of handle array */
631 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
633 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
634 hdc
, handletable
, mr
, handles
);
635 if (!mr
) return FALSE
;
639 /* In Win9x mode we update the xform if the record will produce output */
640 if ( IS_WIN9X() && emr_produces_output(type
) )
641 EMF_Update_MF_Xform(hdc
, info
);
643 TRACE("record %s\n", get_emr_name(type
));
652 PEMRGDICOMMENT lpGdiComment
= (PEMRGDICOMMENT
)mr
;
653 /* In an enhanced metafile, there can be both public and private GDI comments */
654 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
659 PEMRSETMAPMODE pSetMapMode
= (PEMRSETMAPMODE
) mr
;
661 if(info
->mode
== pSetMapMode
->iMode
&& (info
->mode
== MM_ISOTROPIC
|| info
->mode
== MM_ANISOTROPIC
))
663 info
->mode
= pSetMapMode
->iMode
;
664 EMF_SetMapMode(hdc
, info
);
669 PEMRSETBKMODE pSetBkMode
= (PEMRSETBKMODE
) mr
;
670 SetBkMode(hdc
, pSetBkMode
->iMode
);
675 PEMRSETBKCOLOR pSetBkColor
= (PEMRSETBKCOLOR
) mr
;
676 SetBkColor(hdc
, pSetBkColor
->crColor
);
679 case EMR_SETPOLYFILLMODE
:
681 PEMRSETPOLYFILLMODE pSetPolyFillMode
= (PEMRSETPOLYFILLMODE
) mr
;
682 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
687 PEMRSETROP2 pSetROP2
= (PEMRSETROP2
) mr
;
688 SetROP2(hdc
, pSetROP2
->iMode
);
691 case EMR_SETSTRETCHBLTMODE
:
693 PEMRSETSTRETCHBLTMODE pSetStretchBltMode
= (PEMRSETSTRETCHBLTMODE
) mr
;
694 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
697 case EMR_SETTEXTALIGN
:
699 PEMRSETTEXTALIGN pSetTextAlign
= (PEMRSETTEXTALIGN
) mr
;
700 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
703 case EMR_SETTEXTCOLOR
:
705 PEMRSETTEXTCOLOR pSetTextColor
= (PEMRSETTEXTCOLOR
) mr
;
706 SetTextColor(hdc
, pSetTextColor
->crColor
);
716 PEMRRESTOREDC pRestoreDC
= (PEMRRESTOREDC
) mr
;
717 TRACE("EMR_RESTORE: %ld\n", pRestoreDC
->iRelative
);
718 RestoreDC(hdc
, pRestoreDC
->iRelative
);
721 case EMR_INTERSECTCLIPRECT
:
723 PEMRINTERSECTCLIPRECT pClipRect
= (PEMRINTERSECTCLIPRECT
) mr
;
724 TRACE("EMR_INTERSECTCLIPRECT: rect %ld,%ld - %ld, %ld\n",
725 pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
726 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
727 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
728 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
731 case EMR_SELECTOBJECT
:
733 PEMRSELECTOBJECT pSelectObject
= (PEMRSELECTOBJECT
) mr
;
734 if( pSelectObject
->ihObject
& 0x80000000 ) {
735 /* High order bit is set - it's a stock object
736 * Strip the high bit to get the index.
737 * See MSDN article Q142319
739 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
742 /* High order bit wasn't set - not a stock object
745 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
749 case EMR_DELETEOBJECT
:
751 PEMRDELETEOBJECT pDeleteObject
= (PEMRDELETEOBJECT
) mr
;
752 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
753 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
756 case EMR_SETWINDOWORGEX
:
758 PEMRSETWINDOWORGEX pSetWindowOrgEx
= (PEMRSETWINDOWORGEX
) mr
;
760 info
->wndOrgX
= pSetWindowOrgEx
->ptlOrigin
.x
;
761 info
->wndOrgY
= pSetWindowOrgEx
->ptlOrigin
.y
;
763 TRACE("SetWindowOrgEx: %d,%d\n",info
->wndOrgX
,info
->wndOrgY
);
766 case EMR_SETWINDOWEXTEX
:
768 PEMRSETWINDOWEXTEX pSetWindowExtEx
= (PEMRSETWINDOWEXTEX
) mr
;
770 if(info
->mode
!= MM_ISOTROPIC
&& info
->mode
!= MM_ANISOTROPIC
)
772 info
->wndExtX
= pSetWindowExtEx
->szlExtent
.cx
;
773 info
->wndExtY
= pSetWindowExtEx
->szlExtent
.cy
;
775 TRACE("SetWindowExtEx: %d,%d\n",info
->wndExtX
,info
->wndExtY
);
778 case EMR_SETVIEWPORTORGEX
:
780 PEMRSETVIEWPORTORGEX pSetViewportOrgEx
= (PEMRSETVIEWPORTORGEX
) mr
;
781 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
783 info
->vportOrgX
= pSetViewportOrgEx
->ptlOrigin
.x
;
784 info
->vportOrgY
= pSetViewportOrgEx
->ptlOrigin
.y
;
785 TRACE("SetViewportOrgEx: %d,%d\n",info
->vportOrgX
,info
->vportOrgY
);
788 case EMR_SETVIEWPORTEXTEX
:
790 PEMRSETVIEWPORTEXTEX pSetViewportExtEx
= (PEMRSETVIEWPORTEXTEX
) mr
;
791 enum_emh_data
*info
= ENUM_GET_PRIVATE_DATA(handletable
);
793 if(info
->mode
!= MM_ISOTROPIC
&& info
->mode
!= MM_ANISOTROPIC
)
795 info
->vportExtX
= pSetViewportExtEx
->szlExtent
.cx
;
796 info
->vportExtY
= pSetViewportExtEx
->szlExtent
.cy
;
797 TRACE("SetViewportExtEx: %d,%d\n",info
->vportExtX
,info
->vportExtY
);
802 PEMRCREATEPEN pCreatePen
= (PEMRCREATEPEN
) mr
;
803 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
804 CreatePenIndirect(&pCreatePen
->lopn
);
807 case EMR_EXTCREATEPEN
:
809 PEMREXTCREATEPEN pPen
= (PEMREXTCREATEPEN
) mr
;
811 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
812 lb
.lbColor
= pPen
->elp
.elpColor
;
813 lb
.lbHatch
= pPen
->elp
.elpHatch
;
815 if(pPen
->offBmi
|| pPen
->offBits
)
816 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
818 (handletable
->objectHandle
)[pPen
->ihPen
] =
819 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
820 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpStyleEntry
);
823 case EMR_CREATEBRUSHINDIRECT
:
825 PEMRCREATEBRUSHINDIRECT pBrush
= (PEMRCREATEBRUSHINDIRECT
) mr
;
826 (handletable
->objectHandle
)[pBrush
->ihBrush
] =
827 CreateBrushIndirect(&pBrush
->lb
);
830 case EMR_EXTCREATEFONTINDIRECTW
:
832 PEMREXTCREATEFONTINDIRECTW pFont
= (PEMREXTCREATEFONTINDIRECTW
) mr
;
833 (handletable
->objectHandle
)[pFont
->ihFont
] =
834 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
839 PEMRMOVETOEX pMoveToEx
= (PEMRMOVETOEX
) mr
;
840 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
845 PEMRLINETO pLineTo
= (PEMRLINETO
) mr
;
846 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
851 PEMRRECTANGLE pRect
= (PEMRRECTANGLE
) mr
;
852 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
853 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
858 PEMRELLIPSE pEllipse
= (PEMRELLIPSE
) mr
;
859 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
860 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
865 PEMRPOLYGON16 pPoly
= (PEMRPOLYGON16
) mr
;
866 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
867 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
868 pPoly
->cpts
* sizeof(POINT
) );
870 for(i
= 0; i
< pPoly
->cpts
; i
++)
871 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
872 Polygon(hdc
, pts
, pPoly
->cpts
);
873 HeapFree( GetProcessHeap(), 0, pts
);
878 PEMRPOLYLINE16 pPoly
= (PEMRPOLYLINE16
) mr
;
879 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
880 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
881 pPoly
->cpts
* sizeof(POINT
) );
883 for(i
= 0; i
< pPoly
->cpts
; i
++)
884 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
885 Polyline(hdc
, pts
, pPoly
->cpts
);
886 HeapFree( GetProcessHeap(), 0, pts
);
889 case EMR_POLYLINETO16
:
891 PEMRPOLYLINETO16 pPoly
= (PEMRPOLYLINETO16
) mr
;
892 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
893 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
894 pPoly
->cpts
* sizeof(POINT
) );
896 for(i
= 0; i
< pPoly
->cpts
; i
++)
897 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
898 PolylineTo(hdc
, pts
, pPoly
->cpts
);
899 HeapFree( GetProcessHeap(), 0, pts
);
902 case EMR_POLYBEZIER16
:
904 PEMRPOLYBEZIER16 pPoly
= (PEMRPOLYBEZIER16
) mr
;
905 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
906 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
907 pPoly
->cpts
* sizeof(POINT
) );
909 for(i
= 0; i
< pPoly
->cpts
; i
++)
910 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
911 PolyBezier(hdc
, pts
, pPoly
->cpts
);
912 HeapFree( GetProcessHeap(), 0, pts
);
915 case EMR_POLYBEZIERTO16
:
917 PEMRPOLYBEZIERTO16 pPoly
= (PEMRPOLYBEZIERTO16
) mr
;
918 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
919 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
920 pPoly
->cpts
* sizeof(POINT
) );
922 for(i
= 0; i
< pPoly
->cpts
; i
++)
923 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
924 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
925 HeapFree( GetProcessHeap(), 0, pts
);
928 case EMR_POLYPOLYGON16
:
930 PEMRPOLYPOLYGON16 pPolyPoly
= (PEMRPOLYPOLYGON16
) mr
;
931 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
932 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
934 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
935 pPolyPoly
->cpts
* sizeof(POINT
) );
937 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
938 CONV_POINT16TO32((POINT16
*) (pPolyPoly
->aPolyCounts
+
939 pPolyPoly
->nPolys
) + i
, pts
+ i
);
941 PolyPolygon(hdc
, pts
, (INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
942 HeapFree( GetProcessHeap(), 0, pts
);
945 case EMR_POLYPOLYLINE16
:
947 PEMRPOLYPOLYLINE16 pPolyPoly
= (PEMRPOLYPOLYLINE16
) mr
;
948 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
949 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
951 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
952 pPolyPoly
->cpts
* sizeof(POINT
) );
954 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
955 CONV_POINT16TO32((POINT16
*) (pPolyPoly
->aPolyCounts
+
956 pPolyPoly
->nPolys
) + i
, pts
+ i
);
958 PolyPolyline(hdc
, pts
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
959 HeapFree( GetProcessHeap(), 0, pts
);
963 case EMR_STRETCHDIBITS
:
965 EMRSTRETCHDIBITS
*pStretchDIBits
= (EMRSTRETCHDIBITS
*)mr
;
968 pStretchDIBits
->xDest
,
969 pStretchDIBits
->yDest
,
970 pStretchDIBits
->cxDest
,
971 pStretchDIBits
->cyDest
,
972 pStretchDIBits
->xSrc
,
973 pStretchDIBits
->ySrc
,
974 pStretchDIBits
->cxSrc
,
975 pStretchDIBits
->cySrc
,
976 (BYTE
*)mr
+ pStretchDIBits
->offBitsSrc
,
977 (const BITMAPINFO
*)((BYTE
*)mr
+ pStretchDIBits
->offBmiSrc
),
978 pStretchDIBits
->iUsageSrc
,
979 pStretchDIBits
->dwRop
);
983 case EMR_EXTTEXTOUTA
:
985 PEMREXTTEXTOUTA pExtTextOutA
= (PEMREXTTEXTOUTA
)mr
;
988 rc
.left
= pExtTextOutA
->emrtext
.rcl
.left
;
989 rc
.top
= pExtTextOutA
->emrtext
.rcl
.top
;
990 rc
.right
= pExtTextOutA
->emrtext
.rcl
.right
;
991 rc
.bottom
= pExtTextOutA
->emrtext
.rcl
.bottom
;
992 ExtTextOutA(hdc
, pExtTextOutA
->emrtext
.ptlReference
.x
, pExtTextOutA
->emrtext
.ptlReference
.y
,
993 pExtTextOutA
->emrtext
.fOptions
, &rc
,
994 (LPSTR
)((BYTE
*)mr
+ pExtTextOutA
->emrtext
.offString
), pExtTextOutA
->emrtext
.nChars
,
995 (INT
*)((BYTE
*)mr
+ pExtTextOutA
->emrtext
.offDx
));
999 case EMR_EXTTEXTOUTW
:
1001 PEMREXTTEXTOUTW pExtTextOutW
= (PEMREXTTEXTOUTW
)mr
;
1004 rc
.left
= pExtTextOutW
->emrtext
.rcl
.left
;
1005 rc
.top
= pExtTextOutW
->emrtext
.rcl
.top
;
1006 rc
.right
= pExtTextOutW
->emrtext
.rcl
.right
;
1007 rc
.bottom
= pExtTextOutW
->emrtext
.rcl
.bottom
;
1008 TRACE("EMR_EXTTEXTOUTW: x,y = %ld, %ld. rect = %ld, %ld - %ld, %ld. flags %08lx\n",
1009 pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1010 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, pExtTextOutW
->emrtext
.fOptions
);
1012 ExtTextOutW(hdc
, pExtTextOutW
->emrtext
.ptlReference
.x
, pExtTextOutW
->emrtext
.ptlReference
.y
,
1013 pExtTextOutW
->emrtext
.fOptions
, &rc
,
1014 (LPWSTR
)((BYTE
*)mr
+ pExtTextOutW
->emrtext
.offString
), pExtTextOutW
->emrtext
.nChars
,
1015 (INT
*)((BYTE
*)mr
+ pExtTextOutW
->emrtext
.offDx
));
1019 case EMR_CREATEPALETTE
:
1021 PEMRCREATEPALETTE lpCreatePal
= (PEMRCREATEPALETTE
)mr
;
1023 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
1024 CreatePalette( &lpCreatePal
->lgpl
);
1029 case EMR_SELECTPALETTE
:
1031 PEMRSELECTPALETTE lpSelectPal
= (PEMRSELECTPALETTE
)mr
;
1033 if( lpSelectPal
->ihPal
& 0x80000000 ) {
1034 SelectPalette( hdc
, GetStockObject(lpSelectPal
->ihPal
& 0x7fffffff), TRUE
);
1036 (handletable
->objectHandle
)[ lpSelectPal
->ihPal
] =
1037 SelectPalette( hdc
, (handletable
->objectHandle
)[lpSelectPal
->ihPal
], TRUE
);
1042 case EMR_REALIZEPALETTE
:
1044 RealizePalette( hdc
);
1048 case EMR_EXTSELECTCLIPRGN
:
1051 PEMREXTSELECTCLIPRGN lpRgn
= (PEMREXTSELECTCLIPRGN
)mr
;
1052 HRGN hRgn
= ExtCreateRegion(NULL
, lpRgn
->cbRgnData
, (RGNDATA
*)lpRgn
->RgnData
);
1053 ExtSelectClipRgn(hdc
, hRgn
, (INT
)(lpRgn
->iMode
));
1054 /* ExtSelectClipRgn created a copy of the region */
1057 FIXME("ExtSelectClipRgn\n");
1061 case EMR_SETMETARGN
:
1067 case EMR_SETWORLDTRANSFORM
:
1069 PEMRSETWORLDTRANSFORM lpXfrm
= (PEMRSETWORLDTRANSFORM
)mr
;
1070 info
->world_transform
= lpXfrm
->xform
;
1074 case EMR_POLYBEZIER
:
1076 PEMRPOLYBEZIER lpPolyBez
= (PEMRPOLYBEZIER
)mr
;
1077 PolyBezier(hdc
, (const LPPOINT
)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
1083 PEMRPOLYGON lpPoly
= (PEMRPOLYGON
)mr
;
1084 Polygon( hdc
, (const LPPOINT
)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
1090 PEMRPOLYLINE lpPolyLine
= (PEMRPOLYLINE
)mr
;
1091 Polyline(hdc
, (const LPPOINT
)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
1095 case EMR_POLYBEZIERTO
:
1097 PEMRPOLYBEZIERTO lpPolyBezierTo
= (PEMRPOLYBEZIERTO
)mr
;
1098 PolyBezierTo( hdc
, (const LPPOINT
)lpPolyBezierTo
->aptl
,
1099 (UINT
)lpPolyBezierTo
->cptl
);
1103 case EMR_POLYLINETO
:
1105 PEMRPOLYLINETO lpPolyLineTo
= (PEMRPOLYLINETO
)mr
;
1106 PolylineTo( hdc
, (const LPPOINT
)lpPolyLineTo
->aptl
,
1107 (UINT
)lpPolyLineTo
->cptl
);
1111 case EMR_POLYPOLYLINE
:
1113 PEMRPOLYPOLYLINE pPolyPolyline
= (PEMRPOLYPOLYLINE
) mr
;
1114 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1116 PolyPolyline(hdc
, (LPPOINT
)(pPolyPolyline
->aPolyCounts
+
1117 pPolyPolyline
->nPolys
),
1118 pPolyPolyline
->aPolyCounts
,
1119 pPolyPolyline
->nPolys
);
1124 case EMR_POLYPOLYGON
:
1126 PEMRPOLYPOLYGON pPolyPolygon
= (PEMRPOLYPOLYGON
) mr
;
1128 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1130 PolyPolygon(hdc
, (LPPOINT
)(pPolyPolygon
->aPolyCounts
+
1131 pPolyPolygon
->nPolys
),
1132 (INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
1136 case EMR_SETBRUSHORGEX
:
1138 PEMRSETBRUSHORGEX lpSetBrushOrgEx
= (PEMRSETBRUSHORGEX
)mr
;
1141 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
1142 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
1150 PEMRSETPIXELV lpSetPixelV
= (PEMRSETPIXELV
)mr
;
1153 (INT
)lpSetPixelV
->ptlPixel
.x
,
1154 (INT
)lpSetPixelV
->ptlPixel
.y
,
1155 lpSetPixelV
->crColor
);
1160 case EMR_SETMAPPERFLAGS
:
1162 PEMRSETMAPPERFLAGS lpSetMapperFlags
= (PEMRSETMAPPERFLAGS
)mr
;
1164 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
1169 case EMR_SETCOLORADJUSTMENT
:
1171 PEMRSETCOLORADJUSTMENT lpSetColorAdjust
= (PEMRSETCOLORADJUSTMENT
)mr
;
1173 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
1178 case EMR_OFFSETCLIPRGN
:
1180 PEMROFFSETCLIPRGN lpOffsetClipRgn
= (PEMROFFSETCLIPRGN
)mr
;
1183 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
1184 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
1185 FIXME("OffsetClipRgn\n");
1190 case EMR_EXCLUDECLIPRECT
:
1192 PEMREXCLUDECLIPRECT lpExcludeClipRect
= (PEMREXCLUDECLIPRECT
)mr
;
1194 ExcludeClipRect( hdc
,
1195 lpExcludeClipRect
->rclClip
.left
,
1196 lpExcludeClipRect
->rclClip
.top
,
1197 lpExcludeClipRect
->rclClip
.right
,
1198 lpExcludeClipRect
->rclClip
.bottom
);
1199 FIXME("ExcludeClipRect\n");
1204 case EMR_SCALEVIEWPORTEXTEX
:
1206 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx
= (PEMRSCALEVIEWPORTEXTEX
)mr
;
1208 if ((info
->mode
!= MM_ISOTROPIC
) && (info
->mode
!= MM_ANISOTROPIC
))
1210 if (!lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->xDenom
||
1211 !lpScaleViewportExtEx
->xNum
|| !lpScaleViewportExtEx
->yDenom
)
1213 info
->vportExtX
= (info
->vportExtX
* lpScaleViewportExtEx
->xNum
) /
1214 lpScaleViewportExtEx
->xDenom
;
1215 info
->vportExtY
= (info
->vportExtY
* lpScaleViewportExtEx
->yNum
) /
1216 lpScaleViewportExtEx
->yDenom
;
1217 if (info
->vportExtX
== 0) info
->vportExtX
= 1;
1218 if (info
->vportExtY
== 0) info
->vportExtY
= 1;
1219 if (info
->mode
== MM_ISOTROPIC
)
1220 FIXME("EMRSCALEVIEWPORTEXTEX MM_ISOTROPIC mapping\n");
1221 /* MAPPING_FixIsotropic( dc ); */
1223 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1224 lpScaleViewportExtEx
->xNum
,lpScaleViewportExtEx
->xDenom
,
1225 lpScaleViewportExtEx
->yNum
,lpScaleViewportExtEx
->yDenom
);
1230 case EMR_SCALEWINDOWEXTEX
:
1232 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx
= (PEMRSCALEWINDOWEXTEX
)mr
;
1234 if ((info
->mode
!= MM_ISOTROPIC
) && (info
->mode
!= MM_ANISOTROPIC
))
1236 if (!lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->xDenom
||
1237 !lpScaleWindowExtEx
->xNum
|| !lpScaleWindowExtEx
->yDenom
)
1239 info
->wndExtX
= (info
->wndExtX
* lpScaleWindowExtEx
->xNum
) /
1240 lpScaleWindowExtEx
->xDenom
;
1241 info
->wndExtY
= (info
->wndExtY
* lpScaleWindowExtEx
->yNum
) /
1242 lpScaleWindowExtEx
->yDenom
;
1243 if (info
->wndExtX
== 0) info
->wndExtX
= 1;
1244 if (info
->wndExtY
== 0) info
->wndExtY
= 1;
1245 if (info
->mode
== MM_ISOTROPIC
)
1246 FIXME("EMRSCALEWINDOWEXTEX MM_ISOTROPIC mapping\n");
1247 /* MAPPING_FixIsotropic( dc ); */
1249 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1250 lpScaleWindowExtEx
->xNum
,lpScaleWindowExtEx
->xDenom
,
1251 lpScaleWindowExtEx
->yNum
,lpScaleWindowExtEx
->yDenom
);
1256 case EMR_MODIFYWORLDTRANSFORM
:
1258 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans
= (PEMRMODIFYWORLDTRANSFORM
)mr
;
1260 switch(lpModifyWorldTrans
->iMode
) {
1262 info
->world_transform
.eM11
= info
->world_transform
.eM22
= 1;
1263 info
->world_transform
.eM12
= info
->world_transform
.eM21
= 0;
1264 info
->world_transform
.eDx
= info
->world_transform
.eDy
= 0;
1266 case MWT_LEFTMULTIPLY
:
1267 CombineTransform(&info
->world_transform
, &lpModifyWorldTrans
->xform
,
1268 &info
->world_transform
);
1270 case MWT_RIGHTMULTIPLY
:
1271 CombineTransform(&info
->world_transform
, &info
->world_transform
,
1272 &lpModifyWorldTrans
->xform
);
1275 FIXME("Unknown imode %ld\n", lpModifyWorldTrans
->iMode
);
1283 PEMRANGLEARC lpAngleArc
= (PEMRANGLEARC
)mr
;
1286 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
1287 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
1288 lpAngleArc
->eSweepAngle
);
1295 PEMRROUNDRECT lpRoundRect
= (PEMRROUNDRECT
)mr
;
1298 lpRoundRect
->rclBox
.left
,
1299 lpRoundRect
->rclBox
.top
,
1300 lpRoundRect
->rclBox
.right
,
1301 lpRoundRect
->rclBox
.bottom
,
1302 lpRoundRect
->szlCorner
.cx
,
1303 lpRoundRect
->szlCorner
.cy
);
1310 PEMRARC lpArc
= (PEMRARC
)mr
;
1313 (INT
)lpArc
->rclBox
.left
,
1314 (INT
)lpArc
->rclBox
.top
,
1315 (INT
)lpArc
->rclBox
.right
,
1316 (INT
)lpArc
->rclBox
.bottom
,
1317 (INT
)lpArc
->ptlStart
.x
,
1318 (INT
)lpArc
->ptlStart
.y
,
1319 (INT
)lpArc
->ptlEnd
.x
,
1320 (INT
)lpArc
->ptlEnd
.y
);
1327 PEMRCHORD lpChord
= (PEMRCHORD
)mr
;
1330 (INT
)lpChord
->rclBox
.left
,
1331 (INT
)lpChord
->rclBox
.top
,
1332 (INT
)lpChord
->rclBox
.right
,
1333 (INT
)lpChord
->rclBox
.bottom
,
1334 (INT
)lpChord
->ptlStart
.x
,
1335 (INT
)lpChord
->ptlStart
.y
,
1336 (INT
)lpChord
->ptlEnd
.x
,
1337 (INT
)lpChord
->ptlEnd
.y
);
1344 PEMRPIE lpPie
= (PEMRPIE
)mr
;
1347 (INT
)lpPie
->rclBox
.left
,
1348 (INT
)lpPie
->rclBox
.top
,
1349 (INT
)lpPie
->rclBox
.right
,
1350 (INT
)lpPie
->rclBox
.bottom
,
1351 (INT
)lpPie
->ptlStart
.x
,
1352 (INT
)lpPie
->ptlStart
.y
,
1353 (INT
)lpPie
->ptlEnd
.x
,
1354 (INT
)lpPie
->ptlEnd
.y
);
1361 PEMRARC lpArcTo
= (PEMRARC
)mr
;
1364 (INT
)lpArcTo
->rclBox
.left
,
1365 (INT
)lpArcTo
->rclBox
.top
,
1366 (INT
)lpArcTo
->rclBox
.right
,
1367 (INT
)lpArcTo
->rclBox
.bottom
,
1368 (INT
)lpArcTo
->ptlStart
.x
,
1369 (INT
)lpArcTo
->ptlStart
.y
,
1370 (INT
)lpArcTo
->ptlEnd
.x
,
1371 (INT
)lpArcTo
->ptlEnd
.y
);
1376 case EMR_EXTFLOODFILL
:
1378 PEMREXTFLOODFILL lpExtFloodFill
= (PEMREXTFLOODFILL
)mr
;
1381 (INT
)lpExtFloodFill
->ptlStart
.x
,
1382 (INT
)lpExtFloodFill
->ptlStart
.y
,
1383 lpExtFloodFill
->crColor
,
1384 (UINT
)lpExtFloodFill
->iMode
);
1391 PEMRPOLYDRAW lpPolyDraw
= (PEMRPOLYDRAW
)mr
;
1393 (const LPPOINT
)lpPolyDraw
->aptl
,
1394 lpPolyDraw
->abTypes
,
1395 (INT
)lpPolyDraw
->cptl
);
1400 case EMR_SETARCDIRECTION
:
1402 PEMRSETARCDIRECTION lpSetArcDirection
= (PEMRSETARCDIRECTION
)mr
;
1403 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1407 case EMR_SETMITERLIMIT
:
1409 PEMRSETMITERLIMIT lpSetMiterLimit
= (PEMRSETMITERLIMIT
)mr
;
1410 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1426 case EMR_CLOSEFIGURE
:
1434 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1439 case EMR_STROKEANDFILLPATH
:
1441 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1442 StrokeAndFillPath( hdc
);
1446 case EMR_STROKEPATH
:
1448 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1453 case EMR_FLATTENPATH
:
1465 case EMR_SELECTCLIPPATH
:
1467 PEMRSELECTCLIPPATH lpSelectClipPath
= (PEMRSELECTCLIPPATH
)mr
;
1468 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1478 case EMR_CREATECOLORSPACE
:
1480 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1481 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1482 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1486 case EMR_SETCOLORSPACE
:
1488 PEMRSETCOLORSPACE lpSetColorSpace
= (PEMRSETCOLORSPACE
)mr
;
1490 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1494 case EMR_DELETECOLORSPACE
:
1496 PEMRDELETECOLORSPACE lpDeleteColorSpace
= (PEMRDELETECOLORSPACE
)mr
;
1497 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1501 case EMR_SETICMMODE
:
1503 PEMRSETICMMODE lpSetICMMode
= (PEMRSETICMMODE
)mr
;
1504 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1508 case EMR_PIXELFORMAT
:
1511 PEMRPIXELFORMAT lpPixelFormat
= (PEMRPIXELFORMAT
)mr
;
1513 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1514 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1519 case EMR_SETPALETTEENTRIES
:
1521 PEMRSETPALETTEENTRIES lpSetPaletteEntries
= (PEMRSETPALETTEENTRIES
)mr
;
1523 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1524 (UINT
)lpSetPaletteEntries
->iStart
,
1525 (UINT
)lpSetPaletteEntries
->cEntries
,
1526 lpSetPaletteEntries
->aPalEntries
);
1531 case EMR_RESIZEPALETTE
:
1533 PEMRRESIZEPALETTE lpResizePalette
= (PEMRRESIZEPALETTE
)mr
;
1535 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1536 (UINT
)lpResizePalette
->cEntries
);
1541 case EMR_CREATEDIBPATTERNBRUSHPT
:
1543 PEMRCREATEDIBPATTERNBRUSHPT lpCreate
= (PEMRCREATEDIBPATTERNBRUSHPT
)mr
;
1544 LPVOID lpPackedStruct
;
1546 /* check that offsets and data are contained within the record */
1547 if ( !( (lpCreate
->cbBmi
>=0) && (lpCreate
->cbBits
>=0) &&
1548 (lpCreate
->offBmi
>=0) && (lpCreate
->offBits
>=0) &&
1549 ((lpCreate
->offBmi
+lpCreate
->cbBmi
) <= mr
->nSize
) &&
1550 ((lpCreate
->offBits
+lpCreate
->cbBits
) <= mr
->nSize
) ) )
1552 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1556 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1557 lpPackedStruct
= HeapAlloc( GetProcessHeap(), 0,
1558 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1561 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1565 /* Now pack this structure */
1566 memcpy( lpPackedStruct
,
1567 ((BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1569 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1570 ((BYTE
*)lpCreate
) + lpCreate
->offBits
,
1573 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1574 CreateDIBPatternBrushPt( lpPackedStruct
,
1575 (UINT
)lpCreate
->iUsage
);
1577 HeapFree(GetProcessHeap(), 0, lpPackedStruct
);
1582 case EMR_CREATEMONOBRUSH
:
1584 PEMRCREATEMONOBRUSH pCreateMonoBrush
= (PEMRCREATEMONOBRUSH
)mr
;
1585 BITMAPINFO
*pbi
= (BITMAPINFO
*)((BYTE
*)mr
+ pCreateMonoBrush
->offBmi
);
1586 HBITMAP hBmp
= CreateDIBitmap(0, (BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1587 (BYTE
*)mr
+ pCreateMonoBrush
->offBits
, pbi
, pCreateMonoBrush
->iUsage
);
1588 (handletable
->objectHandle
)[pCreateMonoBrush
->ihBrush
] = CreatePatternBrush(hBmp
);
1589 /* CreatePatternBrush created a copy of the bitmap */
1596 PEMRBITBLT pBitBlt
= (PEMRBITBLT
)mr
;
1598 if(pBitBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1599 PatBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1601 } else { /* BitBlt */
1602 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1603 HBRUSH hBrush
, hBrushOld
;
1604 HBITMAP hBmp
= 0, hBmpOld
= 0;
1605 BITMAPINFO
*pbi
= (BITMAPINFO
*)((BYTE
*)mr
+ pBitBlt
->offBmiSrc
);
1607 SetWorldTransform(hdcSrc
, &pBitBlt
->xformSrc
);
1609 hBrush
= CreateSolidBrush(pBitBlt
->crBkColorSrc
);
1610 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1611 PatBlt(hdcSrc
, pBitBlt
->rclBounds
.left
, pBitBlt
->rclBounds
.top
,
1612 pBitBlt
->rclBounds
.right
- pBitBlt
->rclBounds
.left
,
1613 pBitBlt
->rclBounds
.bottom
- pBitBlt
->rclBounds
.top
, PATCOPY
);
1614 SelectObject(hdcSrc
, hBrushOld
);
1615 DeleteObject(hBrush
);
1617 hBmp
= CreateDIBitmap(0, (BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1618 (BYTE
*)mr
+ pBitBlt
->offBitsSrc
, pbi
, pBitBlt
->iUsageSrc
);
1619 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1621 BitBlt(hdc
, pBitBlt
->xDest
, pBitBlt
->yDest
, pBitBlt
->cxDest
, pBitBlt
->cyDest
,
1622 hdcSrc
, pBitBlt
->xSrc
, pBitBlt
->ySrc
, pBitBlt
->dwRop
);
1624 SelectObject(hdcSrc
, hBmpOld
);
1631 case EMR_STRETCHBLT
:
1633 PEMRSTRETCHBLT pStretchBlt
= (PEMRSTRETCHBLT
)mr
;
1635 TRACE("EMR_STRETCHBLT: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. rop %08lx offBitsSrc %ld\n",
1636 pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1637 pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1638 pStretchBlt
->dwRop
, pStretchBlt
->offBitsSrc
);
1640 if(pStretchBlt
->offBmiSrc
== 0) { /* Record is a PatBlt */
1641 PatBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1642 pStretchBlt
->dwRop
);
1643 } else { /* StretchBlt */
1644 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1645 HBRUSH hBrush
, hBrushOld
;
1646 HBITMAP hBmp
= 0, hBmpOld
= 0;
1647 BITMAPINFO
*pbi
= (BITMAPINFO
*)((BYTE
*)mr
+ pStretchBlt
->offBmiSrc
);
1649 SetWorldTransform(hdcSrc
, &pStretchBlt
->xformSrc
);
1651 hBrush
= CreateSolidBrush(pStretchBlt
->crBkColorSrc
);
1652 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1653 PatBlt(hdcSrc
, pStretchBlt
->rclBounds
.left
, pStretchBlt
->rclBounds
.top
,
1654 pStretchBlt
->rclBounds
.right
- pStretchBlt
->rclBounds
.left
,
1655 pStretchBlt
->rclBounds
.bottom
- pStretchBlt
->rclBounds
.top
, PATCOPY
);
1656 SelectObject(hdcSrc
, hBrushOld
);
1657 DeleteObject(hBrush
);
1659 hBmp
= CreateDIBitmap(0, (BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1660 (BYTE
*)mr
+ pStretchBlt
->offBitsSrc
, pbi
, pStretchBlt
->iUsageSrc
);
1661 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1663 StretchBlt(hdc
, pStretchBlt
->xDest
, pStretchBlt
->yDest
, pStretchBlt
->cxDest
, pStretchBlt
->cyDest
,
1664 hdcSrc
, pStretchBlt
->xSrc
, pStretchBlt
->ySrc
, pStretchBlt
->cxSrc
, pStretchBlt
->cySrc
,
1665 pStretchBlt
->dwRop
);
1667 SelectObject(hdcSrc
, hBmpOld
);
1676 PEMRMASKBLT pMaskBlt
= (PEMRMASKBLT
)mr
;
1677 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1678 HBRUSH hBrush
, hBrushOld
;
1679 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1682 SetWorldTransform(hdcSrc
, &pMaskBlt
->xformSrc
);
1684 hBrush
= CreateSolidBrush(pMaskBlt
->crBkColorSrc
);
1685 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1686 PatBlt(hdcSrc
, pMaskBlt
->rclBounds
.left
, pMaskBlt
->rclBounds
.top
,
1687 pMaskBlt
->rclBounds
.right
- pMaskBlt
->rclBounds
.left
,
1688 pMaskBlt
->rclBounds
.bottom
- pMaskBlt
->rclBounds
.top
, PATCOPY
);
1689 SelectObject(hdcSrc
, hBrushOld
);
1690 DeleteObject(hBrush
);
1692 pbi
= (BITMAPINFO
*)((BYTE
*)mr
+ pMaskBlt
->offBmiMask
);
1693 hBmpMask
= CreateDIBitmap(0, (BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1694 (BYTE
*)mr
+ pMaskBlt
->offBitsMask
, pbi
, pMaskBlt
->iUsageMask
);
1696 pbi
= (BITMAPINFO
*)((BYTE
*)mr
+ pMaskBlt
->offBmiSrc
);
1697 hBmp
= CreateDIBitmap(0, (BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1698 (BYTE
*)mr
+ pMaskBlt
->offBitsSrc
, pbi
, pMaskBlt
->iUsageSrc
);
1699 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1712 SelectObject(hdcSrc
, hBmpOld
);
1714 DeleteObject(hBmpMask
);
1721 PEMRPLGBLT pPlgBlt
= (PEMRPLGBLT
)mr
;
1722 HDC hdcSrc
= CreateCompatibleDC(hdc
);
1723 HBRUSH hBrush
, hBrushOld
;
1724 HBITMAP hBmp
, hBmpOld
, hBmpMask
;
1728 SetWorldTransform(hdcSrc
, &pPlgBlt
->xformSrc
);
1730 pts
[0].x
= pPlgBlt
->aptlDest
[0].x
; pts
[0].y
= pPlgBlt
->aptlDest
[0].y
;
1731 pts
[1].x
= pPlgBlt
->aptlDest
[1].x
; pts
[1].y
= pPlgBlt
->aptlDest
[1].y
;
1732 pts
[2].x
= pPlgBlt
->aptlDest
[2].x
; pts
[2].y
= pPlgBlt
->aptlDest
[2].y
;
1734 hBrush
= CreateSolidBrush(pPlgBlt
->crBkColorSrc
);
1735 hBrushOld
= SelectObject(hdcSrc
, hBrush
);
1736 PatBlt(hdcSrc
, pPlgBlt
->rclBounds
.left
, pPlgBlt
->rclBounds
.top
,
1737 pPlgBlt
->rclBounds
.right
- pPlgBlt
->rclBounds
.left
,
1738 pPlgBlt
->rclBounds
.bottom
- pPlgBlt
->rclBounds
.top
, PATCOPY
);
1739 SelectObject(hdcSrc
, hBrushOld
);
1740 DeleteObject(hBrush
);
1742 pbi
= (BITMAPINFO
*)((BYTE
*)mr
+ pPlgBlt
->offBmiMask
);
1743 hBmpMask
= CreateDIBitmap(0, (BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1744 (BYTE
*)mr
+ pPlgBlt
->offBitsMask
, pbi
, pPlgBlt
->iUsageMask
);
1746 pbi
= (BITMAPINFO
*)((BYTE
*)mr
+ pPlgBlt
->offBmiSrc
);
1747 hBmp
= CreateDIBitmap(0, (BITMAPINFOHEADER
*)pbi
, CBM_INIT
,
1748 (BYTE
*)mr
+ pPlgBlt
->offBitsSrc
, pbi
, pPlgBlt
->iUsageSrc
);
1749 hBmpOld
= SelectObject(hdcSrc
, hBmp
);
1760 SelectObject(hdcSrc
, hBmpOld
);
1762 DeleteObject(hBmpMask
);
1767 case EMR_SETDIBITSTODEVICE
:
1769 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice
= (PEMRSETDIBITSTODEVICE
)mr
;
1771 SetDIBitsToDevice(hdc
,
1772 pSetDIBitsToDevice
->xDest
,
1773 pSetDIBitsToDevice
->yDest
,
1774 pSetDIBitsToDevice
->cxSrc
,
1775 pSetDIBitsToDevice
->cySrc
,
1776 pSetDIBitsToDevice
->xSrc
,
1777 pSetDIBitsToDevice
->ySrc
,
1778 pSetDIBitsToDevice
->iStartScan
,
1779 pSetDIBitsToDevice
->cScans
,
1780 (BYTE
*)mr
+ pSetDIBitsToDevice
->offBitsSrc
,
1781 (BITMAPINFO
*)((BYTE
*)mr
+ pSetDIBitsToDevice
->offBmiSrc
),
1782 pSetDIBitsToDevice
->iUsageSrc
);
1786 case EMR_POLYTEXTOUTA
:
1788 PEMRPOLYTEXTOUTA pPolyTextOutA
= (PEMRPOLYTEXTOUTA
)mr
;
1789 POLYTEXTA
*polytextA
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA
->cStrings
* sizeof(POLYTEXTA
));
1791 XFORM xform
, xformOld
;
1794 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutA
->iGraphicsMode
);
1795 GetWorldTransform(hdc
, &xformOld
);
1797 xform
.eM11
= pPolyTextOutA
->exScale
;
1800 xform
.eM22
= pPolyTextOutA
->eyScale
;
1803 SetWorldTransform(hdc
, &xform
);
1805 /* Set up POLYTEXTA structures */
1806 for(i
= 0; i
< pPolyTextOutA
->cStrings
; i
++)
1808 polytextA
[i
].x
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.x
;
1809 polytextA
[i
].y
= pPolyTextOutA
->aemrtext
[i
].ptlReference
.y
;
1810 polytextA
[i
].n
= pPolyTextOutA
->aemrtext
[i
].nChars
;
1811 polytextA
[i
].lpstr
= (LPSTR
)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offString
);
1812 polytextA
[i
].uiFlags
= pPolyTextOutA
->aemrtext
[i
].fOptions
;
1813 polytextA
[i
].rcl
.left
= pPolyTextOutA
->aemrtext
[i
].rcl
.left
;
1814 polytextA
[i
].rcl
.right
= pPolyTextOutA
->aemrtext
[i
].rcl
.right
;
1815 polytextA
[i
].rcl
.top
= pPolyTextOutA
->aemrtext
[i
].rcl
.top
;
1816 polytextA
[i
].rcl
.bottom
= pPolyTextOutA
->aemrtext
[i
].rcl
.bottom
;
1817 polytextA
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutA
->aemrtext
[i
].offDx
);
1819 PolyTextOutA(hdc
, polytextA
, pPolyTextOutA
->cStrings
);
1820 HeapFree(GetProcessHeap(), 0, polytextA
);
1822 SetWorldTransform(hdc
, &xformOld
);
1823 SetGraphicsMode(hdc
, gModeOld
);
1827 case EMR_POLYTEXTOUTW
:
1829 PEMRPOLYTEXTOUTW pPolyTextOutW
= (PEMRPOLYTEXTOUTW
)mr
;
1830 POLYTEXTW
*polytextW
= HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW
->cStrings
* sizeof(POLYTEXTW
));
1832 XFORM xform
, xformOld
;
1835 gModeOld
= SetGraphicsMode(hdc
, pPolyTextOutW
->iGraphicsMode
);
1836 GetWorldTransform(hdc
, &xformOld
);
1838 xform
.eM11
= pPolyTextOutW
->exScale
;
1841 xform
.eM22
= pPolyTextOutW
->eyScale
;
1844 SetWorldTransform(hdc
, &xform
);
1846 /* Set up POLYTEXTW structures */
1847 for(i
= 0; i
< pPolyTextOutW
->cStrings
; i
++)
1849 polytextW
[i
].x
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.x
;
1850 polytextW
[i
].y
= pPolyTextOutW
->aemrtext
[i
].ptlReference
.y
;
1851 polytextW
[i
].n
= pPolyTextOutW
->aemrtext
[i
].nChars
;
1852 polytextW
[i
].lpstr
= (LPWSTR
)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offString
);
1853 polytextW
[i
].uiFlags
= pPolyTextOutW
->aemrtext
[i
].fOptions
;
1854 polytextW
[i
].rcl
.left
= pPolyTextOutW
->aemrtext
[i
].rcl
.left
;
1855 polytextW
[i
].rcl
.right
= pPolyTextOutW
->aemrtext
[i
].rcl
.right
;
1856 polytextW
[i
].rcl
.top
= pPolyTextOutW
->aemrtext
[i
].rcl
.top
;
1857 polytextW
[i
].rcl
.bottom
= pPolyTextOutW
->aemrtext
[i
].rcl
.bottom
;
1858 polytextW
[i
].pdx
= (int *)((BYTE
*)mr
+ pPolyTextOutW
->aemrtext
[i
].offDx
);
1860 PolyTextOutW(hdc
, polytextW
, pPolyTextOutW
->cStrings
);
1861 HeapFree(GetProcessHeap(), 0, polytextW
);
1863 SetWorldTransform(hdc
, &xformOld
);
1864 SetGraphicsMode(hdc
, gModeOld
);
1870 PEMRFILLRGN pFillRgn
= (PEMRFILLRGN
)mr
;
1871 HRGN hRgn
= ExtCreateRegion(NULL
, pFillRgn
->cbRgnData
, (RGNDATA
*)pFillRgn
->RgnData
);
1874 (handletable
->objectHandle
)[pFillRgn
->ihBrush
]);
1881 PEMRFRAMERGN pFrameRgn
= (PEMRFRAMERGN
)mr
;
1882 HRGN hRgn
= ExtCreateRegion(NULL
, pFrameRgn
->cbRgnData
, (RGNDATA
*)pFrameRgn
->RgnData
);
1885 (handletable
->objectHandle
)[pFrameRgn
->ihBrush
],
1886 pFrameRgn
->szlStroke
.cx
,
1887 pFrameRgn
->szlStroke
.cy
);
1894 PEMRINVERTRGN pInvertRgn
= (PEMRINVERTRGN
)mr
;
1895 HRGN hRgn
= ExtCreateRegion(NULL
, pInvertRgn
->cbRgnData
, (RGNDATA
*)pInvertRgn
->RgnData
);
1896 InvertRgn(hdc
, hRgn
);
1903 PEMRPAINTRGN pPaintRgn
= (PEMRPAINTRGN
)mr
;
1904 HRGN hRgn
= ExtCreateRegion(NULL
, pPaintRgn
->cbRgnData
, (RGNDATA
*)pPaintRgn
->RgnData
);
1905 PaintRgn(hdc
, hRgn
);
1910 case EMR_SETTEXTJUSTIFICATION
:
1912 PEMRSETTEXTJUSTIFICATION pSetTextJust
= (PEMRSETTEXTJUSTIFICATION
)mr
;
1913 SetTextJustification(hdc
, pSetTextJust
->nBreakExtra
, pSetTextJust
->nBreakCount
);
1919 PEMRSETLAYOUT pSetLayout
= (PEMRSETLAYOUT
)mr
;
1920 SetLayout(hdc
, pSetLayout
->iMode
);
1924 case EMR_POLYDRAW16
:
1926 case EMR_GLSBOUNDEDRECORD
:
1927 case EMR_DRAWESCAPE
:
1930 case EMR_SMALLTEXTOUT
:
1931 case EMR_FORCEUFIMAPPING
:
1932 case EMR_NAMEDESCAPE
:
1933 case EMR_COLORCORRECTPALETTE
:
1934 case EMR_SETICMPROFILEA
:
1935 case EMR_SETICMPROFILEW
:
1936 case EMR_ALPHABLEND
:
1937 case EMR_TRANSPARENTBLT
:
1938 case EMR_GRADIENTFILL
:
1939 case EMR_SETLINKEDUFI
:
1940 case EMR_COLORMATCHTOTARGETW
:
1941 case EMR_CREATECOLORSPACEW
:
1944 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1945 record then ignore and return TRUE. */
1946 FIXME("type %d is unimplemented\n", type
);
1949 tmprc
.left
= tmprc
.top
= 0;
1950 tmprc
.right
= tmprc
.bottom
= 1000;
1951 LPtoDP(hdc
, (POINT
*)&tmprc
, 2);
1952 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", tmprc
.left
,
1953 tmprc
.top
, tmprc
.right
, tmprc
.bottom
);
1957 /* WinNT - update the transform (win9x updates when the next graphics output
1958 record is played). */
1959 EMF_Update_MF_Xform(hdc
, info
);
1966 /*****************************************************************************
1968 * EnumEnhMetaFile (GDI32.@)
1970 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1972 * record. Returns when either every record has been used or
1973 * when _EnhMetaFunc_ returns FALSE.
1977 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1984 * This function behaves differently in Win9x and WinNT.
1986 * In WinNT, the DC's world transform is updated as the EMF changes
1987 * the Window/Viewport Extent and Origin or it's world transform.
1988 * The actual Window/Viewport Extent and Origin are left untouched.
1990 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
1991 * updates the scaling itself but only just before a record that
1992 * writes anything to the DC.
1994 * I'm not sure where the data (enum_emh_data) is stored in either
1995 * version. For this implementation, it is stored before the handle
1996 * table, but it could be stored in the DC, in the EMF handle or in
2000 BOOL WINAPI
EnumEnhMetaFile(
2001 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
2002 HENHMETAFILE hmf
, /* [in] EMF to walk */
2003 ENHMFENUMPROC callback
, /* [in] callback function */
2004 LPVOID data
, /* [in] optional data for callback function */
2005 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
2017 HBRUSH hBrush
= NULL
;
2019 enum_emh_data
*info
;
2020 SIZE vp_size
, win_size
;
2021 POINT vp_org
, win_org
;
2022 INT mapMode
= MM_TEXT
;
2023 COLORREF old_text_color
= 0, old_bk_color
= 0;
2027 SetLastError(ERROR_INVALID_PARAMETER
);
2031 emh
= EMF_GetEnhMetaHeader(hmf
);
2033 SetLastError(ERROR_INVALID_HANDLE
);
2037 info
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
2038 sizeof (enum_emh_data
) + sizeof(HANDLETABLE
) * emh
->nHandles
);
2041 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2048 info
->vportOrgX
= 0;
2049 info
->vportOrgY
= 0;
2050 info
->vportExtX
= 1;
2051 info
->vportExtY
= 1;
2052 info
->world_transform
.eM11
= info
->world_transform
.eM22
= 1;
2053 info
->world_transform
.eM12
= info
->world_transform
.eM21
= 0;
2054 info
->world_transform
.eDx
= info
->world_transform
.eDy
= 0;
2056 ht
= (HANDLETABLE
*) &info
[1];
2057 ht
->objectHandle
[0] = hmf
;
2061 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
2062 GetWorldTransform(hdc
, &savedXform
);
2063 GetViewportExtEx(hdc
, &vp_size
);
2064 GetWindowExtEx(hdc
, &win_size
);
2065 GetViewportOrgEx(hdc
, &vp_org
);
2066 GetWindowOrgEx(hdc
, &win_org
);
2067 mapMode
= GetMapMode(hdc
);
2069 /* save the current pen, brush and font */
2070 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
2071 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
2072 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
2074 old_text_color
= SetTextColor(hdc
, RGB(0,0,0));
2075 old_bk_color
= SetBkColor(hdc
, RGB(0xff, 0xff, 0xff));
2078 info
->mode
= MM_TEXT
;
2082 /* Win95 leaves the vp/win ext/org info alone */
2083 info
->init_transform
.eM11
= 1.0;
2084 info
->init_transform
.eM12
= 0.0;
2085 info
->init_transform
.eM21
= 0.0;
2086 info
->init_transform
.eM22
= 1.0;
2087 info
->init_transform
.eDx
= 0.0;
2088 info
->init_transform
.eDy
= 0.0;
2092 /* WinNT combines the vp/win ext/org info into a transform */
2093 FLOAT xscale
, yscale
;
2094 xscale
= (FLOAT
)vp_size
.cx
/ (FLOAT
)win_size
.cx
;
2095 yscale
= (FLOAT
)vp_size
.cy
/ (FLOAT
)win_size
.cy
;
2096 info
->init_transform
.eM11
= xscale
;
2097 info
->init_transform
.eM12
= 0.0;
2098 info
->init_transform
.eM21
= 0.0;
2099 info
->init_transform
.eM22
= yscale
;
2100 info
->init_transform
.eDx
= (FLOAT
)vp_org
.x
- xscale
* (FLOAT
)win_org
.x
;
2101 info
->init_transform
.eDy
= (FLOAT
)vp_org
.y
- yscale
* (FLOAT
)win_org
.y
;
2103 CombineTransform(&info
->init_transform
, &savedXform
, &info
->init_transform
);
2106 if ( WIDTH(emh
->rclFrame
) && HEIGHT(emh
->rclFrame
) )
2108 FLOAT xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
2111 TRACE("rect: %ld,%ld - %ld,%ld. rclFrame: %ld,%ld - %ld,%ld\n",
2112 lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
,
2113 emh
->rclFrame
.left
, emh
->rclFrame
.top
, emh
->rclFrame
.right
,
2114 emh
->rclFrame
.bottom
);
2116 xSrcPixSize
= (FLOAT
) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
2117 ySrcPixSize
= (FLOAT
) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
2118 xscale
= (FLOAT
) WIDTH(*lpRect
) * 100.0 /
2119 WIDTH(emh
->rclFrame
) * xSrcPixSize
;
2120 yscale
= (FLOAT
) HEIGHT(*lpRect
) * 100.0 /
2121 HEIGHT(emh
->rclFrame
) * ySrcPixSize
;
2123 xform
.eM11
= xscale
;
2126 xform
.eM22
= yscale
;
2127 xform
.eDx
= (FLOAT
) lpRect
->left
- (FLOAT
) WIDTH(*lpRect
) / WIDTH(emh
->rclFrame
) * emh
->rclFrame
.left
;
2128 xform
.eDy
= (FLOAT
) lpRect
->top
- (FLOAT
) HEIGHT(*lpRect
) / HEIGHT(emh
->rclFrame
) * emh
->rclFrame
.top
;
2130 CombineTransform(&info
->init_transform
, &xform
, &info
->init_transform
);
2133 /* WinNT resets the current vp/win org/ext */
2136 SetMapMode(hdc
, MM_TEXT
);
2137 SetWindowOrgEx(hdc
, 0, 0, NULL
);
2138 SetViewportOrgEx(hdc
, 0, 0, NULL
);
2139 EMF_Update_MF_Xform(hdc
, info
);
2144 while(ret
&& offset
< emh
->nBytes
)
2146 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
2147 TRACE("Calling EnumFunc with record %s, size %ld\n", get_emr_name(emr
->iType
), emr
->nSize
);
2148 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nHandles
, (LPARAM
)data
);
2149 offset
+= emr
->nSize
;
2154 SetBkColor(hdc
, old_bk_color
);
2155 SetTextColor(hdc
, old_text_color
);
2157 /* restore pen, brush and font */
2158 SelectObject(hdc
, hBrush
);
2159 SelectObject(hdc
, hPen
);
2160 SelectObject(hdc
, hFont
);
2162 SetWorldTransform(hdc
, &savedXform
);
2164 SetGraphicsMode(hdc
, savedMode
);
2165 SetMapMode(hdc
, mapMode
);
2166 SetWindowOrgEx(hdc
, win_org
.x
, win_org
.y
, NULL
);
2167 SetWindowExtEx(hdc
, win_size
.cx
, win_size
.cy
, NULL
);
2168 SetViewportOrgEx(hdc
, vp_org
.x
, vp_org
.y
, NULL
);
2169 SetViewportExtEx(hdc
, vp_size
.cx
, vp_size
.cy
, NULL
);
2172 for(i
= 1; i
< emh
->nHandles
; i
++) /* Don't delete element 0 (hmf) */
2173 if( (ht
->objectHandle
)[i
] )
2174 DeleteObject( (ht
->objectHandle
)[i
] );
2176 HeapFree( GetProcessHeap(), 0, info
);
2180 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
2181 const ENHMETARECORD
*emr
,
2182 INT handles
, LPARAM data
)
2184 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
2187 /**************************************************************************
2188 * PlayEnhMetaFile (GDI32.@)
2190 * Renders an enhanced metafile into a specified rectangle *lpRect
2191 * in device context hdc.
2194 BOOL WINAPI
PlayEnhMetaFile(
2195 HDC hdc
, /* [in] DC to render into */
2196 HENHMETAFILE hmf
, /* [in] metafile to render */
2197 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
2200 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
2204 /*****************************************************************************
2205 * DeleteEnhMetaFile (GDI32.@)
2207 * Deletes an enhanced metafile and frees the associated storage.
2209 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
2211 return EMF_Delete_HENHMETAFILE( hmf
);
2214 /*****************************************************************************
2215 * CopyEnhMetaFileA (GDI32.@) Duplicate an enhanced metafile
2219 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
2220 HENHMETAFILE hmfSrc
,
2223 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2224 HENHMETAFILE hmfDst
;
2226 if(!emrSrc
) return FALSE
;
2228 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2229 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2230 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, FALSE
);
2233 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2234 NULL
, CREATE_ALWAYS
, 0, 0);
2235 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, 0, 0);
2236 CloseHandle( hFile
);
2237 /* Reopen file for reading only, so that apps can share
2238 read access to the file while hmf is still valid */
2239 hFile
= CreateFileA( file
, GENERIC_READ
, FILE_SHARE_READ
,
2240 NULL
, OPEN_EXISTING
, 0, 0);
2241 if(hFile
== INVALID_HANDLE_VALUE
) {
2242 ERR("Can't reopen emf for reading\n");
2245 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2246 CloseHandle( hFile
);
2251 /*****************************************************************************
2252 * CopyEnhMetaFileW (GDI32.@) Duplicate an enhanced metafile
2256 HENHMETAFILE WINAPI
CopyEnhMetaFileW(
2257 HENHMETAFILE hmfSrc
,
2260 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
2261 HENHMETAFILE hmfDst
;
2263 if(!emrSrc
) return FALSE
;
2265 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
2266 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
2267 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, FALSE
);
2270 hFile
= CreateFileW( file
, GENERIC_WRITE
| GENERIC_READ
, 0,
2271 NULL
, CREATE_ALWAYS
, 0, 0);
2272 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, 0, 0);
2273 CloseHandle( hFile
);
2274 /* Reopen file for reading only, so that apps can share
2275 read access to the file while hmf is still valid */
2276 hFile
= CreateFileW( file
, GENERIC_READ
, FILE_SHARE_READ
,
2277 NULL
, OPEN_EXISTING
, 0, 0);
2278 if(hFile
== INVALID_HANDLE_VALUE
) {
2279 ERR("Can't reopen emf for reading\n");
2282 hmfDst
= EMF_GetEnhMetaFile( hFile
);
2283 CloseHandle( hFile
);
2289 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2290 typedef struct tagEMF_PaletteCopy
2293 LPPALETTEENTRY lpPe
;
2296 /***************************************************************
2297 * Find the EMR_EOF record and then use it to find the
2298 * palette entries for this enhanced metafile.
2299 * The lpData is actually a pointer to a EMF_PaletteCopy struct
2300 * which contains the max number of elements to copy and where
2303 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2305 INT CALLBACK
cbEnhPaletteCopy( HDC a
,
2307 const ENHMETARECORD
*lpEMR
,
2312 if ( lpEMR
->iType
== EMR_EOF
)
2314 PEMREOF lpEof
= (PEMREOF
)lpEMR
;
2315 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
2316 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
2318 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy
);
2320 memcpy( (LPVOID
)info
->lpPe
,
2321 (LPVOID
)(((LPSTR
)lpEof
) + lpEof
->offPalEntries
),
2322 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
2324 /* Update the passed data as a return code */
2325 info
->lpPe
= NULL
; /* Palettes were copied! */
2326 info
->cEntries
= (UINT
)dwNumPalToCopy
;
2328 return FALSE
; /* That's all we need */
2334 /*****************************************************************************
2335 * GetEnhMetaFilePaletteEntries (GDI32.@)
2337 * Copy the palette and report size
2339 * BUGS: Error codes (SetLastError) are not set on failures
2341 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
2343 LPPALETTEENTRY lpPe
)
2345 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
2346 EMF_PaletteCopy infoForCallBack
;
2348 TRACE( "(%p,%d,%p)\n", hEmf
, cEntries
, lpPe
);
2350 /* First check if there are any palettes associated with
2352 if ( enhHeader
->nPalEntries
== 0 ) return 0;
2354 /* Is the user requesting the number of palettes? */
2355 if ( lpPe
== NULL
) return (UINT
)enhHeader
->nPalEntries
;
2357 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2358 infoForCallBack
.cEntries
= cEntries
;
2359 infoForCallBack
.lpPe
= lpPe
;
2361 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
2362 &infoForCallBack
, 0 ) )
2365 /* Verify that the callback executed correctly */
2366 if ( infoForCallBack
.lpPe
!= NULL
)
2368 /* Callback proc had error! */
2369 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2373 return infoForCallBack
.cEntries
;
2376 typedef struct gdi_mf_comment
2383 DWORD cbWinMetaFile
;
2386 /******************************************************************
2387 * SetWinMetaFileBits (GDI32.@)
2389 * Translate from old style to new style.
2392 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
,
2393 CONST BYTE
*lpbBuffer
,
2395 CONST METAFILEPICT
*lpmfp
2399 HENHMETAFILE ret
= 0;
2400 HDC hdc
= 0, hdcdisp
= 0;
2402 RECT rc
, *prcFrame
= NULL
;
2403 gdi_mf_comment
*mfcomment
;
2404 UINT mfcomment_size
;
2405 INT horzres
, vertres
, horzsize
, vertsize
, xext
, yext
;
2407 TRACE("(%d, %p, %p, %p)\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
2409 hmf
= SetMetaFileBitsEx(cbBuffer
, lpbBuffer
);
2412 WARN("SetMetaFileBitsEx failed\n");
2417 hdcRef
= hdcdisp
= CreateDCA("DISPLAY", NULL
, NULL
, NULL
);
2421 mfp
.mm
= MM_ANISOTROPIC
;
2424 FIXME("Correct Exts from dc\n");
2428 TRACE("mm = %ld %ldx%ld\n", lpmfp
->mm
, lpmfp
->xExt
, lpmfp
->yExt
);
2429 if ( ( mfp
.xExt
< 0 ) || ( mfp
.yExt
< 0) )
2430 FIXME("Negative coordinates!\n");
2433 if(lpmfp
->mm
== MM_ISOTROPIC
|| lpmfp
->mm
== MM_ANISOTROPIC
) {
2434 rc
.left
= rc
.top
= 0;
2435 rc
.right
= lpmfp
->xExt
;
2436 rc
.bottom
= lpmfp
->yExt
;
2440 if(!(hdc
= CreateEnhMetaFileW(hdcRef
, NULL
, prcFrame
, NULL
))) {
2441 ERR("CreateEnhMetaFile fails?\n");
2445 horzres
= GetDeviceCaps(hdcRef
, HORZRES
);
2446 vertres
= GetDeviceCaps(hdcRef
, VERTRES
);
2447 horzsize
= GetDeviceCaps(hdcRef
, HORZSIZE
);
2448 vertsize
= GetDeviceCaps(hdcRef
, VERTSIZE
);
2456 * Write the original METAFILE into the enhanced metafile.
2457 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2459 mfcomment_size
= sizeof (gdi_mf_comment
) + cbBuffer
;
2460 mfcomment
= HeapAlloc(GetProcessHeap(), 0, mfcomment_size
);
2463 mfcomment
->ident
= GDICOMMENT_IDENTIFIER
;
2464 mfcomment
->iComment
= GDICOMMENT_WINDOWS_METAFILE
;
2465 mfcomment
->nVersion
= 0x00000300;
2466 mfcomment
->nChecksum
= 0; /* FIXME */
2467 mfcomment
->fFlags
= 0;
2468 mfcomment
->cbWinMetaFile
= cbBuffer
;
2469 memcpy(&mfcomment
[1], lpbBuffer
, cbBuffer
);
2470 GdiComment(hdc
, mfcomment_size
, (BYTE
*) mfcomment
);
2471 HeapFree(GetProcessHeap(), 0, mfcomment
);
2474 if(lpmfp
->mm
!= MM_TEXT
)
2475 SetMapMode(hdc
, lpmfp
->mm
);
2477 /* set the initial viewport:window ratio as 1:1 */
2478 xext
= lpmfp
->xExt
*horzres
/(100*horzsize
);
2479 yext
= lpmfp
->yExt
*vertres
/(100*vertsize
);
2480 SetViewportExtEx(hdc
, xext
, yext
, NULL
);
2481 SetWindowExtEx(hdc
, xext
, yext
, NULL
);
2483 PlayMetaFile(hdc
, hmf
);
2485 ret
= CloseEnhMetaFile(hdc
);
2487 DeleteMetaFile(hmf
);