2 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
7 * The enhanced format consists of the following elements:
10 * A table of handles to GDI objects
11 * An array of metafile records
15 * The standard format consists of a header and an array of metafile records.
25 #include "enhmetafile.h"
26 #include "debugtools.h"
30 DEFAULT_DEBUG_CHANNEL(enhmetafile
);
32 /****************************************************************************
33 * EMF_Create_HENHMETAFILE
35 HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, HFILE hFile
, HANDLE
39 ENHMETAFILEOBJ
*metaObj
= GDI_AllocObject( sizeof(ENHMETAFILEOBJ
),
40 ENHMETAFILE_MAGIC
, &hmf
);
44 metaObj
->hFile
= hFile
;
45 metaObj
->hMapping
= hMapping
;
46 GDI_ReleaseObj( hmf
);
51 /****************************************************************************
52 * EMF_Delete_HENHMETAFILE
54 static BOOL
EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf
)
56 ENHMETAFILEOBJ
*metaObj
= (ENHMETAFILEOBJ
*)GDI_GetObjPtr( hmf
,
58 if(!metaObj
) return FALSE
;
59 if(metaObj
->hMapping
) {
60 UnmapViewOfFile( metaObj
->emh
);
61 CloseHandle( metaObj
->hMapping
);
62 CloseHandle( metaObj
->hFile
);
64 HeapFree( GetProcessHeap(), 0, metaObj
->emh
);
65 return GDI_FreeObject( hmf
, metaObj
);
68 /******************************************************************
69 * EMF_GetEnhMetaHeader
71 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
72 * Should be followed by call to EMF_ReleaseEnhMetaHeader
74 static ENHMETAHEADER
*EMF_GetEnhMetaHeader( HENHMETAFILE hmf
)
76 ENHMETAFILEOBJ
*metaObj
= (ENHMETAFILEOBJ
*)GDI_GetObjPtr( hmf
,
78 TRACE("hmf %04x -> enhmetaObj %p\n", hmf
, metaObj
);
79 return metaObj
? metaObj
->emh
: NULL
;
82 /******************************************************************
83 * EMF_ReleaseEnhMetaHeader
85 * Releases ENHMETAHEADER associated with HENHMETAFILE
87 static void EMF_ReleaseEnhMetaHeader( HENHMETAFILE hmf
)
89 GDI_ReleaseObj( hmf
);
92 /*****************************************************************************
96 static HENHMETAFILE
EMF_GetEnhMetaFile( HFILE hFile
)
101 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
102 emh
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, 0 );
104 if (emh
->iType
!= EMR_HEADER
|| emh
->dSignature
!= ENHMETA_SIGNATURE
) {
105 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
106 emh
->iType
, emh
->dSignature
);
107 UnmapViewOfFile( emh
);
108 CloseHandle( hMapping
);
111 return EMF_Create_HENHMETAFILE( emh
, hFile
, hMapping
);
115 /*****************************************************************************
116 * GetEnhMetaFileA (GDI32.174)
120 HENHMETAFILE WINAPI
GetEnhMetaFileA(
121 LPCSTR lpszMetaFile
/* [in] filename of enhanced metafile */
127 hFile
= CreateFileA(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
128 OPEN_EXISTING
, 0, 0);
129 if (hFile
== INVALID_HANDLE_VALUE
) {
130 WARN("could not open %s\n", lpszMetaFile
);
133 hmf
= EMF_GetEnhMetaFile( hFile
);
135 CloseHandle( hFile
);
139 /*****************************************************************************
140 * GetEnhMetaFileW (GDI32.180)
142 HENHMETAFILE WINAPI
GetEnhMetaFileW(
143 LPCWSTR lpszMetaFile
) /* [in] filename of enhanced metafile */
148 hFile
= CreateFileW(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
149 OPEN_EXISTING
, 0, 0);
150 if (hFile
== INVALID_HANDLE_VALUE
) {
151 WARN("could not open %s\n", debugstr_w(lpszMetaFile
));
154 hmf
= EMF_GetEnhMetaFile( hFile
);
156 CloseHandle( hFile
);
160 /*****************************************************************************
161 * GetEnhMetaFileHeader (GDI32.178)
163 * If buf is NULL, returns the size of buffer required.
164 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
167 UINT WINAPI
GetEnhMetaFileHeader(
168 HENHMETAFILE hmf
, /* [in] enhanced metafile */
169 UINT bufsize
, /* [in] size of buffer */
170 LPENHMETAHEADER buf
/* [out] buffer */
176 emh
= EMF_GetEnhMetaHeader(hmf
);
177 if(!emh
) return FALSE
;
180 EMF_ReleaseEnhMetaHeader(hmf
);
183 size
= min(size
, bufsize
);
184 memmove(buf
, emh
, size
);
185 EMF_ReleaseEnhMetaHeader(hmf
);
190 /*****************************************************************************
191 * GetEnhMetaFileDescriptionA (GDI32.176)
193 UINT WINAPI
GetEnhMetaFileDescriptionA(
194 HENHMETAFILE hmf
, /* [in] enhanced metafile */
195 UINT size
, /* [in] size of buf */
196 LPSTR buf
/* [out] buffer to receive description */
199 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
203 if(!emh
) return FALSE
;
204 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) {
205 EMF_ReleaseEnhMetaHeader(hmf
);
208 descrW
= (WCHAR
*) ((char *) emh
+ emh
->offDescription
);
209 len
= WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, NULL
, 0, NULL
, NULL
);
211 if (!buf
|| !size
) {
212 EMF_ReleaseEnhMetaHeader(hmf
);
216 len
= min( size
, len
);
217 WideCharToMultiByte( CP_ACP
, 0, descrW
, emh
->nDescription
, buf
, len
, NULL
, NULL
);
218 EMF_ReleaseEnhMetaHeader(hmf
);
222 /*****************************************************************************
223 * GetEnhMetaFileDescriptionW (GDI32.177)
225 * Copies the description string of an enhanced metafile into a buffer
228 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
229 * number of characters copied.
231 UINT WINAPI
GetEnhMetaFileDescriptionW(
232 HENHMETAFILE hmf
, /* [in] enhanced metafile */
233 UINT size
, /* [in] size of buf */
234 LPWSTR buf
/* [out] buffer to receive description */
237 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
239 if(!emh
) return FALSE
;
240 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) {
241 EMF_ReleaseEnhMetaHeader(hmf
);
244 if (!buf
|| !size
) {
245 EMF_ReleaseEnhMetaHeader(hmf
);
246 return emh
->nDescription
;
249 memmove(buf
, (char *) emh
+ emh
->offDescription
,
250 min(size
,emh
->nDescription
)*sizeof(WCHAR
));
251 EMF_ReleaseEnhMetaHeader(hmf
);
252 return min(size
, emh
->nDescription
);
255 /****************************************************************************
256 * SetEnhMetaFileBits (GDI32.315)
258 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
260 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
262 ENHMETAHEADER
*emh
= HeapAlloc( GetProcessHeap(), 0, bufsize
);
263 memmove(emh
, buf
, bufsize
);
264 return EMF_Create_HENHMETAFILE( emh
, 0, 0 );
267 /*****************************************************************************
268 * GetEnhMetaFileBits (GDI32.175)
271 UINT WINAPI
GetEnhMetaFileBits(
277 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
284 EMF_ReleaseEnhMetaHeader( hmf
);
288 size
= min( size
, bufsize
);
289 memmove(buf
, emh
, size
);
291 EMF_ReleaseEnhMetaHeader( hmf
);
295 /*****************************************************************************
296 * PlayEnhMetaFileRecord (GDI32.264)
298 * Render a single enhanced metafile record in the device context hdc.
301 * TRUE (non zero) on success, FALSE on error.
303 * Many unimplemented records.
304 * No error handling on record play failures (ie checking return codes)
306 BOOL WINAPI
PlayEnhMetaFileRecord(
307 HDC hdc
, /* [in] device context in which to render EMF record */
308 LPHANDLETABLE handletable
, /* [in] array of handles to be used in rendering record */
309 const ENHMETARECORD
*mr
, /* [in] EMF record to render */
310 UINT handles
/* [in] size of handle array */
315 "hdc = %08x, handletable = %p, record = %p, numHandles = %d\n",
316 hdc
, handletable
, mr
, handles
);
317 if (!mr
) return FALSE
;
321 TRACE(" type=%d\n", type
);
330 PEMRGDICOMMENT lpGdiComment
= (PEMRGDICOMMENT
)mr
;
331 /* In an enhanced metafile, there can be both public and private GDI comments */
332 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
337 PEMRSETMAPMODE pSetMapMode
= (PEMRSETMAPMODE
) mr
;
338 SetMapMode(hdc
, pSetMapMode
->iMode
);
343 PEMRSETBKMODE pSetBkMode
= (PEMRSETBKMODE
) mr
;
344 SetBkMode(hdc
, pSetBkMode
->iMode
);
349 PEMRSETBKCOLOR pSetBkColor
= (PEMRSETBKCOLOR
) mr
;
350 SetBkColor(hdc
, pSetBkColor
->crColor
);
353 case EMR_SETPOLYFILLMODE
:
355 PEMRSETPOLYFILLMODE pSetPolyFillMode
= (PEMRSETPOLYFILLMODE
) mr
;
356 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
361 PEMRSETROP2 pSetROP2
= (PEMRSETROP2
) mr
;
362 SetROP2(hdc
, pSetROP2
->iMode
);
365 case EMR_SETSTRETCHBLTMODE
:
367 PEMRSETSTRETCHBLTMODE pSetStretchBltMode
= (PEMRSETSTRETCHBLTMODE
) mr
;
368 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
371 case EMR_SETTEXTALIGN
:
373 PEMRSETTEXTALIGN pSetTextAlign
= (PEMRSETTEXTALIGN
) mr
;
374 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
377 case EMR_SETTEXTCOLOR
:
379 PEMRSETTEXTCOLOR pSetTextColor
= (PEMRSETTEXTCOLOR
) mr
;
380 SetTextColor(hdc
, pSetTextColor
->crColor
);
390 PEMRRESTOREDC pRestoreDC
= (PEMRRESTOREDC
) mr
;
391 RestoreDC(hdc
, pRestoreDC
->iRelative
);
394 case EMR_INTERSECTCLIPRECT
:
396 PEMRINTERSECTCLIPRECT pClipRect
= (PEMRINTERSECTCLIPRECT
) mr
;
397 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
398 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
401 case EMR_SELECTOBJECT
:
403 PEMRSELECTOBJECT pSelectObject
= (PEMRSELECTOBJECT
) mr
;
404 if( pSelectObject
->ihObject
& 0x80000000 ) {
405 /* High order bit is set - it's a stock object
406 * Strip the high bit to get the index.
407 * See MSDN article Q142319
409 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
412 /* High order bit wasn't set - not a stock object
415 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
419 case EMR_DELETEOBJECT
:
421 PEMRDELETEOBJECT pDeleteObject
= (PEMRDELETEOBJECT
) mr
;
422 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
423 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
426 case EMR_SETWINDOWORGEX
:
428 PEMRSETWINDOWORGEX pSetWindowOrgEx
= (PEMRSETWINDOWORGEX
) mr
;
429 SetWindowOrgEx(hdc
, pSetWindowOrgEx
->ptlOrigin
.x
,
430 pSetWindowOrgEx
->ptlOrigin
.y
, NULL
);
433 case EMR_SETWINDOWEXTEX
:
435 PEMRSETWINDOWEXTEX pSetWindowExtEx
= (PEMRSETWINDOWEXTEX
) mr
;
436 SetWindowExtEx(hdc
, pSetWindowExtEx
->szlExtent
.cx
,
437 pSetWindowExtEx
->szlExtent
.cy
, NULL
);
440 case EMR_SETVIEWPORTORGEX
:
442 PEMRSETVIEWPORTORGEX pSetViewportOrgEx
= (PEMRSETVIEWPORTORGEX
) mr
;
443 SetViewportOrgEx(hdc
, pSetViewportOrgEx
->ptlOrigin
.x
,
444 pSetViewportOrgEx
->ptlOrigin
.y
, NULL
);
447 case EMR_SETVIEWPORTEXTEX
:
449 PEMRSETVIEWPORTEXTEX pSetViewportExtEx
= (PEMRSETVIEWPORTEXTEX
) mr
;
450 SetViewportExtEx(hdc
, pSetViewportExtEx
->szlExtent
.cx
,
451 pSetViewportExtEx
->szlExtent
.cy
, NULL
);
456 PEMRCREATEPEN pCreatePen
= (PEMRCREATEPEN
) mr
;
457 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
458 CreatePenIndirect(&pCreatePen
->lopn
);
461 case EMR_EXTCREATEPEN
:
463 PEMREXTCREATEPEN pPen
= (PEMREXTCREATEPEN
) mr
;
465 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
466 lb
.lbColor
= pPen
->elp
.elpColor
;
467 lb
.lbHatch
= pPen
->elp
.elpHatch
;
469 if(pPen
->offBmi
|| pPen
->offBits
)
470 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
472 (handletable
->objectHandle
)[pPen
->ihPen
] =
473 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
474 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpStyleEntry
);
477 case EMR_CREATEBRUSHINDIRECT
:
479 PEMRCREATEBRUSHINDIRECT pBrush
= (PEMRCREATEBRUSHINDIRECT
) mr
;
480 (handletable
->objectHandle
)[pBrush
->ihBrush
] =
481 CreateBrushIndirect(&pBrush
->lb
);
484 case EMR_EXTCREATEFONTINDIRECTW
:
486 PEMREXTCREATEFONTINDIRECTW pFont
= (PEMREXTCREATEFONTINDIRECTW
) mr
;
487 (handletable
->objectHandle
)[pFont
->ihFont
] =
488 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
493 PEMRMOVETOEX pMoveToEx
= (PEMRMOVETOEX
) mr
;
494 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
499 PEMRLINETO pLineTo
= (PEMRLINETO
) mr
;
500 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
505 PEMRRECTANGLE pRect
= (PEMRRECTANGLE
) mr
;
506 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
507 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
512 PEMRELLIPSE pEllipse
= (PEMRELLIPSE
) mr
;
513 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
514 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
519 PEMRPOLYGON16 pPoly
= (PEMRPOLYGON16
) mr
;
520 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
521 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
522 pPoly
->cpts
* sizeof(POINT
) );
524 for(i
= 0; i
< pPoly
->cpts
; i
++)
525 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
526 Polygon(hdc
, pts
, pPoly
->cpts
);
527 HeapFree( GetProcessHeap(), 0, pts
);
532 PEMRPOLYLINE16 pPoly
= (PEMRPOLYLINE16
) mr
;
533 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
534 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
535 pPoly
->cpts
* sizeof(POINT
) );
537 for(i
= 0; i
< pPoly
->cpts
; i
++)
538 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
539 Polyline(hdc
, pts
, pPoly
->cpts
);
540 HeapFree( GetProcessHeap(), 0, pts
);
543 case EMR_POLYLINETO16
:
545 PEMRPOLYLINETO16 pPoly
= (PEMRPOLYLINETO16
) mr
;
546 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
547 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
548 pPoly
->cpts
* sizeof(POINT
) );
550 for(i
= 0; i
< pPoly
->cpts
; i
++)
551 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
552 PolylineTo(hdc
, pts
, pPoly
->cpts
);
553 HeapFree( GetProcessHeap(), 0, pts
);
556 case EMR_POLYBEZIER16
:
558 PEMRPOLYBEZIER16 pPoly
= (PEMRPOLYBEZIER16
) mr
;
559 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
560 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
561 pPoly
->cpts
* sizeof(POINT
) );
563 for(i
= 0; i
< pPoly
->cpts
; i
++)
564 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
565 PolyBezier(hdc
, pts
, pPoly
->cpts
);
566 HeapFree( GetProcessHeap(), 0, pts
);
569 case EMR_POLYBEZIERTO16
:
571 PEMRPOLYBEZIERTO16 pPoly
= (PEMRPOLYBEZIERTO16
) mr
;
572 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
573 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
574 pPoly
->cpts
* sizeof(POINT
) );
576 for(i
= 0; i
< pPoly
->cpts
; i
++)
577 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
578 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
579 HeapFree( GetProcessHeap(), 0, pts
);
582 case EMR_POLYPOLYGON16
:
584 PEMRPOLYPOLYGON16 pPolyPoly
= (PEMRPOLYPOLYGON16
) mr
;
585 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
586 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
588 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
589 pPolyPoly
->cpts
* sizeof(POINT
) );
591 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
592 CONV_POINT16TO32((POINTS
*) (pPolyPoly
->aPolyCounts
+
593 pPolyPoly
->nPolys
) + i
, pts
+ i
);
595 PolyPolygon(hdc
, pts
, (INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
596 HeapFree( GetProcessHeap(), 0, pts
);
599 case EMR_POLYPOLYLINE16
:
601 PEMRPOLYPOLYLINE16 pPolyPoly
= (PEMRPOLYPOLYLINE16
) mr
;
602 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
603 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
605 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
606 pPolyPoly
->cpts
* sizeof(POINT
) );
608 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
609 CONV_POINT16TO32((POINTS
*) (pPolyPoly
->aPolyCounts
+
610 pPolyPoly
->nPolys
) + i
, pts
+ i
);
612 PolyPolyline(hdc
, pts
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
613 HeapFree( GetProcessHeap(), 0, pts
);
617 case EMR_STRETCHDIBITS
:
619 LONG xDest
= mr
->dParm
[4];
620 LONG yDest
= mr
->dParm
[5];
621 LONG xSrc
= mr
->dParm
[6];
622 LONG ySrc
= mr
->dParm
[7];
623 LONG cxSrc
= mr
->dParm
[8];
624 LONG cySrc
= mr
->dParm
[9];
625 DWORD offBmiSrc
= mr
->dParm
[10];
626 DWORD offBitsSrc
= mr
->dParm
[12];
627 DWORD iUsageSrc
= mr
->dParm
[14];
628 DWORD dwRop
= mr
->dParm
[15];
629 LONG cxDest
= mr
->dParm
[16];
630 LONG cyDest
= mr
->dParm
[17];
632 StretchDIBits(hdc
,xDest
,yDest
,cxDest
,cyDest
,
633 xSrc
,ySrc
,cxSrc
,cySrc
,
634 ((char *)mr
)+offBitsSrc
,
635 (const BITMAPINFO
*)(((char *)mr
)+offBmiSrc
),
639 case EMR_EXTTEXTOUTW
:
642 DWORD flags
= mr
->dParm
[4];
644 DWORD x
= mr
->dParm
[7], y
= mr
->dParm
[8];
645 DWORD count
= mr
->dParm
[9];
647 LPWSTR str
= (LPWSTR
)& mr
->dParm
[17];
648 /* trailing info: dx array? */
649 FIXME("Many ExtTextOut args not handled\n");
650 ExtTextOutW(hdc
, x
, y
, flags
, /* lpRect */ NULL
,
651 str
, count
, /* lpDx */ NULL
);
655 case EMR_CREATEPALETTE
:
657 PEMRCREATEPALETTE lpCreatePal
= (PEMRCREATEPALETTE
)mr
;
659 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
660 CreatePalette( &lpCreatePal
->lgpl
);
665 case EMR_SELECTPALETTE
:
667 PEMRSELECTPALETTE lpSelectPal
= (PEMRSELECTPALETTE
)mr
;
669 /* FIXME: Should this be forcing background mode? */
670 (handletable
->objectHandle
)[ lpSelectPal
->ihPal
] =
671 SelectPalette( hdc
, lpSelectPal
->ihPal
, FALSE
);
675 case EMR_REALIZEPALETTE
:
677 RealizePalette( hdc
);
682 case EMR_EXTSELECTCLIPRGN
:
684 PEMREXTSELECTCLIPRGN lpRgn
= (PEMREXTSELECTCLIPRGN
)mr
;
686 /* Need to make a region out of the RGNDATA we have */
687 ExtSelectClipRgn( hdc
, ..., (INT
)(lpRgn
->iMode
) );
698 case EMR_SETWORLDTRANSFORM
:
700 PEMRSETWORLDTRANSFORM lpXfrm
= (PEMRSETWORLDTRANSFORM
)mr
;
702 SetWorldTransform( hdc
, &lpXfrm
->xform
);
709 PEMRPOLYBEZIER lpPolyBez
= (PEMRPOLYBEZIER
)mr
;
710 PolyBezier(hdc
, (const LPPOINT
)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
716 PEMRPOLYGON lpPoly
= (PEMRPOLYGON
)mr
;
717 Polygon( hdc
, (const LPPOINT
)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
723 PEMRPOLYLINE lpPolyLine
= (PEMRPOLYLINE
)mr
;
724 Polyline(hdc
, (const LPPOINT
)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
728 case EMR_POLYBEZIERTO
:
730 PEMRPOLYBEZIERTO lpPolyBezierTo
= (PEMRPOLYBEZIERTO
)mr
;
731 PolyBezierTo( hdc
, (const LPPOINT
)lpPolyBezierTo
->aptl
,
732 (UINT
)lpPolyBezierTo
->cptl
);
738 PEMRPOLYLINETO lpPolyLineTo
= (PEMRPOLYLINETO
)mr
;
739 PolylineTo( hdc
, (const LPPOINT
)lpPolyLineTo
->aptl
,
740 (UINT
)lpPolyLineTo
->cptl
);
744 case EMR_POLYPOLYLINE
:
746 PEMRPOLYPOLYLINE pPolyPolyline
= (PEMRPOLYPOLYLINE
) mr
;
747 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
749 PolyPolyline(hdc
, (LPPOINT
)(pPolyPolyline
->aPolyCounts
+
750 pPolyPolyline
->nPolys
),
751 pPolyPolyline
->aPolyCounts
,
752 pPolyPolyline
->nPolys
);
757 case EMR_POLYPOLYGON
:
759 PEMRPOLYPOLYGON pPolyPolygon
= (PEMRPOLYPOLYGON
) mr
;
761 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
763 PolyPolygon(hdc
, (LPPOINT
)(pPolyPolygon
->aPolyCounts
+
764 pPolyPolygon
->nPolys
),
765 (INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
769 case EMR_SETBRUSHORGEX
:
771 PEMRSETBRUSHORGEX lpSetBrushOrgEx
= (PEMRSETBRUSHORGEX
)mr
;
774 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
775 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
783 PEMRSETPIXELV lpSetPixelV
= (PEMRSETPIXELV
)mr
;
786 (INT
)lpSetPixelV
->ptlPixel
.x
,
787 (INT
)lpSetPixelV
->ptlPixel
.y
,
788 lpSetPixelV
->crColor
);
793 case EMR_SETMAPPERFLAGS
:
795 PEMRSETMAPPERFLAGS lpSetMapperFlags
= (PEMRSETMAPPERFLAGS
)mr
;
797 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
802 case EMR_SETCOLORADJUSTMENT
:
804 PEMRSETCOLORADJUSTMENT lpSetColorAdjust
= (PEMRSETCOLORADJUSTMENT
)mr
;
806 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
811 case EMR_OFFSETCLIPRGN
:
813 PEMROFFSETCLIPRGN lpOffsetClipRgn
= (PEMROFFSETCLIPRGN
)mr
;
816 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
817 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
822 case EMR_EXCLUDECLIPRECT
:
824 PEMREXCLUDECLIPRECT lpExcludeClipRect
= (PEMREXCLUDECLIPRECT
)mr
;
826 ExcludeClipRect( hdc
,
827 lpExcludeClipRect
->rclClip
.left
,
828 lpExcludeClipRect
->rclClip
.top
,
829 lpExcludeClipRect
->rclClip
.right
,
830 lpExcludeClipRect
->rclClip
.bottom
);
835 case EMR_SCALEVIEWPORTEXTEX
:
837 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx
= (PEMRSCALEVIEWPORTEXTEX
)mr
;
839 ScaleViewportExtEx( hdc
,
840 lpScaleViewportExtEx
->xNum
,
841 lpScaleViewportExtEx
->xDenom
,
842 lpScaleViewportExtEx
->yNum
,
843 lpScaleViewportExtEx
->yDenom
,
849 case EMR_SCALEWINDOWEXTEX
:
851 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx
= (PEMRSCALEWINDOWEXTEX
)mr
;
853 ScaleWindowExtEx( hdc
,
854 lpScaleWindowExtEx
->xNum
,
855 lpScaleWindowExtEx
->xDenom
,
856 lpScaleWindowExtEx
->yNum
,
857 lpScaleWindowExtEx
->yDenom
,
863 case EMR_MODIFYWORLDTRANSFORM
:
865 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans
= (PEMRMODIFYWORLDTRANSFORM
)mr
;
867 ModifyWorldTransform( hdc
, &lpModifyWorldTrans
->xform
,
868 lpModifyWorldTrans
->iMode
);
875 PEMRANGLEARC lpAngleArc
= (PEMRANGLEARC
)mr
;
878 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
879 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
880 lpAngleArc
->eSweepAngle
);
887 PEMRROUNDRECT lpRoundRect
= (PEMRROUNDRECT
)mr
;
890 lpRoundRect
->rclBox
.left
,
891 lpRoundRect
->rclBox
.top
,
892 lpRoundRect
->rclBox
.right
,
893 lpRoundRect
->rclBox
.bottom
,
894 lpRoundRect
->szlCorner
.cx
,
895 lpRoundRect
->szlCorner
.cy
);
902 PEMRARC lpArc
= (PEMRARC
)mr
;
905 (INT
)lpArc
->rclBox
.left
,
906 (INT
)lpArc
->rclBox
.top
,
907 (INT
)lpArc
->rclBox
.right
,
908 (INT
)lpArc
->rclBox
.bottom
,
909 (INT
)lpArc
->ptlStart
.x
,
910 (INT
)lpArc
->ptlStart
.y
,
911 (INT
)lpArc
->ptlEnd
.x
,
912 (INT
)lpArc
->ptlEnd
.y
);
919 PEMRCHORD lpChord
= (PEMRCHORD
)mr
;
922 (INT
)lpChord
->rclBox
.left
,
923 (INT
)lpChord
->rclBox
.top
,
924 (INT
)lpChord
->rclBox
.right
,
925 (INT
)lpChord
->rclBox
.bottom
,
926 (INT
)lpChord
->ptlStart
.x
,
927 (INT
)lpChord
->ptlStart
.y
,
928 (INT
)lpChord
->ptlEnd
.x
,
929 (INT
)lpChord
->ptlEnd
.y
);
936 PEMRPIE lpPie
= (PEMRPIE
)mr
;
939 (INT
)lpPie
->rclBox
.left
,
940 (INT
)lpPie
->rclBox
.top
,
941 (INT
)lpPie
->rclBox
.right
,
942 (INT
)lpPie
->rclBox
.bottom
,
943 (INT
)lpPie
->ptlStart
.x
,
944 (INT
)lpPie
->ptlStart
.y
,
945 (INT
)lpPie
->ptlEnd
.x
,
946 (INT
)lpPie
->ptlEnd
.y
);
953 PEMRARC lpArcTo
= (PEMRARC
)mr
;
956 (INT
)lpArcTo
->rclBox
.left
,
957 (INT
)lpArcTo
->rclBox
.top
,
958 (INT
)lpArcTo
->rclBox
.right
,
959 (INT
)lpArcTo
->rclBox
.bottom
,
960 (INT
)lpArcTo
->ptlStart
.x
,
961 (INT
)lpArcTo
->ptlStart
.y
,
962 (INT
)lpArcTo
->ptlEnd
.x
,
963 (INT
)lpArcTo
->ptlEnd
.y
);
968 case EMR_EXTFLOODFILL
:
970 PEMREXTFLOODFILL lpExtFloodFill
= (PEMREXTFLOODFILL
)mr
;
973 (INT
)lpExtFloodFill
->ptlStart
.x
,
974 (INT
)lpExtFloodFill
->ptlStart
.y
,
975 lpExtFloodFill
->crColor
,
976 (UINT
)lpExtFloodFill
->iMode
);
983 PEMRPOLYDRAW lpPolyDraw
= (PEMRPOLYDRAW
)mr
;
985 (const LPPOINT
)lpPolyDraw
->aptl
,
987 (INT
)lpPolyDraw
->cptl
);
992 case EMR_SETARCDIRECTION
:
994 PEMRSETARCDIRECTION lpSetArcDirection
= (PEMRSETARCDIRECTION
)mr
;
995 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
999 case EMR_SETMITERLIMIT
:
1001 PEMRSETMITERLIMIT lpSetMiterLimit
= (PEMRSETMITERLIMIT
)mr
;
1002 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1018 case EMR_CLOSEFIGURE
:
1026 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1031 case EMR_STROKEANDFILLPATH
:
1033 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1034 StrokeAndFillPath( hdc
);
1038 case EMR_STROKEPATH
:
1040 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1045 case EMR_FLATTENPATH
:
1057 case EMR_SELECTCLIPPATH
:
1059 PEMRSELECTCLIPPATH lpSelectClipPath
= (PEMRSELECTCLIPPATH
)mr
;
1060 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1070 case EMR_CREATECOLORSPACE
:
1072 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1073 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1074 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1078 case EMR_SETCOLORSPACE
:
1080 PEMRSETCOLORSPACE lpSetColorSpace
= (PEMRSETCOLORSPACE
)mr
;
1082 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1086 case EMR_DELETECOLORSPACE
:
1088 PEMRDELETECOLORSPACE lpDeleteColorSpace
= (PEMRDELETECOLORSPACE
)mr
;
1089 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1093 case EMR_SETICMMODE
:
1095 PERMSETICMMODE lpSetICMMode
= (PERMSETICMMODE
)mr
;
1096 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1100 case EMR_PIXELFORMAT
:
1103 PEMRPIXELFORMAT lpPixelFormat
= (PEMRPIXELFORMAT
)mr
;
1105 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1106 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1111 case EMR_SETPALETTEENTRIES
:
1113 PEMRSETPALETTEENTRIES lpSetPaletteEntries
= (PEMRSETPALETTEENTRIES
)mr
;
1115 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1116 (UINT
)lpSetPaletteEntries
->iStart
,
1117 (UINT
)lpSetPaletteEntries
->cEntries
,
1118 lpSetPaletteEntries
->aPalEntries
);
1123 case EMR_RESIZEPALETTE
:
1125 PEMRRESIZEPALETTE lpResizePalette
= (PEMRRESIZEPALETTE
)mr
;
1127 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1128 (UINT
)lpResizePalette
->cEntries
);
1133 case EMR_CREATEDIBPATTERNBRUSHPT
:
1135 PEMRCREATEDIBPATTERNBRUSHPT lpCreate
= (PEMRCREATEDIBPATTERNBRUSHPT
)mr
;
1137 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1138 LPVOID lpPackedStruct
= HeapAlloc( GetProcessHeap(),
1140 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1141 /* Now pack this structure */
1142 memcpy( lpPackedStruct
,
1143 ((BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1145 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1146 ((BYTE
*)lpCreate
) + lpCreate
->offBits
,
1149 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1150 CreateDIBPatternBrushPt( lpPackedStruct
,
1151 (UINT
)lpCreate
->iUsage
);
1157 case EMR_STRETCHBLT
:
1160 case EMR_SETDIBITSTODEVICE
:
1161 case EMR_EXTTEXTOUTA
:
1162 case EMR_POLYDRAW16
:
1163 case EMR_CREATEMONOBRUSH
:
1164 case EMR_POLYTEXTOUTA
:
1165 case EMR_POLYTEXTOUTW
:
1171 case EMR_GLSBOUNDEDRECORD
:
1173 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1174 record then ignore and return TRUE. */
1175 FIXME("type %d is unimplemented\n", type
);
1182 /*****************************************************************************
1184 * EnumEnhMetaFile (GDI32.79)
1186 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1188 * record. Returns when either every record has been used or
1189 * when _EnhMetaFunc_ returns FALSE.
1193 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1199 BOOL WINAPI
EnumEnhMetaFile(
1200 HDC hdc
, /* [in] device context to pass to _EnhMetaFunc_ */
1201 HENHMETAFILE hmf
, /* [in] EMF to walk */
1202 ENHMFENUMPROC callback
, /* [in] callback function */
1203 LPVOID data
, /* [in] optional data for callback function */
1204 const RECT
*lpRect
/* [in] bounding rectangle for rendered metafile */
1208 ENHMETAHEADER
*emh
, *emhTemp
;
1214 FLOAT xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
1215 XFORM savedXform
, xform
;
1222 SetLastError(ERROR_INVALID_PARAMETER
);
1226 emh
= EMF_GetEnhMetaHeader(hmf
);
1228 SetLastError(ERROR_INVALID_HANDLE
);
1232 /* Copy the metafile into memory, because we need to avoid deadlock. */
1233 emhTemp
= HeapAlloc(GetProcessHeap(), 0, emh
->nSize
+ emh
->nBytes
);
1236 EMF_ReleaseEnhMetaHeader(hmf
);
1237 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1240 memcpy(emhTemp
, emh
, emh
->nSize
+ emh
->nBytes
);
1242 EMF_ReleaseEnhMetaHeader(hmf
);
1244 ht
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1245 sizeof(HANDLETABLE
) * emh
->nHandles
);
1248 HeapFree(GetProcessHeap(), 0, emhTemp
);
1249 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1252 ht
->objectHandle
[0] = hmf
;
1254 xSrcPixSize
= (FLOAT
) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
1255 ySrcPixSize
= (FLOAT
) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
1256 xscale
= (FLOAT
)(lpRect
->right
- lpRect
->left
) * 100.0 /
1257 (emh
->rclFrame
.right
- emh
->rclFrame
.left
) * xSrcPixSize
;
1258 yscale
= (FLOAT
)(lpRect
->bottom
- lpRect
->top
) * 100.0 /
1259 (emh
->rclFrame
.bottom
- emh
->rclFrame
.top
) * ySrcPixSize
;
1261 xform
.eM11
= xscale
;
1264 xform
.eM22
= yscale
;
1265 if(emh
->rclFrame
.left
|| emh
->rclFrame
.top
)
1266 FIXME("Can't cope with nonzero rclFrame origin yet\n");
1267 /* eDx = lpRect->left - (lpRect width) / (rclFrame width) * rclFrame.left ? */
1268 xform
.eDx
= lpRect
->left
;
1269 xform
.eDy
= lpRect
->top
;
1270 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
1271 GetWorldTransform(hdc
, &savedXform
);
1272 if (!ModifyWorldTransform(hdc
, &xform
, MWT_LEFTMULTIPLY
)) {
1273 ERR("World transform failed!\n");
1276 /* save the current pen, brush and font */
1277 hPen
= GetCurrentObject(hdc
, OBJ_PEN
);
1278 hBrush
= GetCurrentObject(hdc
, OBJ_BRUSH
);
1279 hFont
= GetCurrentObject(hdc
, OBJ_FONT
);
1281 TRACE("nSize = %ld, nBytes = %ld, nHandles = %d, nRecords = %ld, nPalEntries = %ld\n",
1282 emh
->nSize
, emh
->nBytes
, emh
->nHandles
, emh
->nRecords
, emh
->nPalEntries
);
1286 while(ret
&& offset
< emh
->nBytes
)
1288 emr
= (ENHMETARECORD
*)((char *)emh
+ offset
);
1289 TRACE("Calling EnumFunc with record type %ld, size %ld\n", emr
->iType
, emr
->nSize
);
1290 ret
= (*callback
)(hdc
, ht
, emr
, emh
->nRecords
, data
);
1291 offset
+= emr
->nSize
;
1294 /* restore pen, brush and font */
1295 SelectObject(hdc
, hBrush
);
1296 SelectObject(hdc
, hPen
);
1297 SelectObject(hdc
, hFont
);
1299 for(i
= 1; i
< emh
->nRecords
; i
++) /* Don't delete element 0 (hmf) */
1300 if( (ht
->objectHandle
)[i
] )
1301 DeleteObject( (ht
->objectHandle
)[i
] );
1303 HeapFree( GetProcessHeap(), 0, ht
);
1304 HeapFree(GetProcessHeap(), 0, emhTemp
);
1306 SetWorldTransform(hdc
, &savedXform
);
1307 if (savedMode
) SetGraphicsMode(hdc
, savedMode
);
1312 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
1314 INT handles
, LPVOID data
)
1316 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
1319 /**************************************************************************
1320 * PlayEnhMetaFile (GDI32.263)
1322 * Renders an enhanced metafile into a specified rectangle *lpRect
1323 * in device context hdc.
1326 BOOL WINAPI
PlayEnhMetaFile(
1327 HDC hdc
, /* [in] DC to render into */
1328 HENHMETAFILE hmf
, /* [in] metafile to render */
1329 const RECT
*lpRect
/* [in] rectangle to place metafile inside */
1332 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
1336 /*****************************************************************************
1337 * DeleteEnhMetaFile (GDI32.68)
1339 * Deletes an enhanced metafile and frees the associated storage.
1341 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
1343 return EMF_Delete_HENHMETAFILE( hmf
);
1346 /*****************************************************************************
1347 * CopyEnhMetaFileA (GDI32.21) Duplicate an enhanced metafile
1351 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
1352 HENHMETAFILE hmfSrc
,
1355 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
1356 HENHMETAFILE hmfDst
;
1358 if(!emrSrc
) return FALSE
;
1360 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
1361 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
1362 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, 0, 0 );
1365 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0, NULL
,
1366 CREATE_ALWAYS
, 0, -1);
1367 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, 0, 0);
1368 hmfDst
= EMF_GetEnhMetaFile( hFile
);
1370 EMF_ReleaseEnhMetaHeader( hmfSrc
);
1375 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1376 typedef struct tagEMF_PaletteCopy
1379 LPPALETTEENTRY lpPe
;
1382 /***************************************************************
1383 * Find the EMR_EOF record and then use it to find the
1384 * palette entries for this enhanced metafile.
1385 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1386 * which contains the max number of elements to copy and where
1389 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1391 INT CALLBACK
cbEnhPaletteCopy( HDC a
,
1393 LPENHMETARECORD lpEMR
,
1398 if ( lpEMR
->iType
== EMR_EOF
)
1400 PEMREOF lpEof
= (PEMREOF
)lpEMR
;
1401 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
1402 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
1404 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy
);
1406 memcpy( (LPVOID
)info
->lpPe
,
1407 (LPVOID
)(((LPSTR
)lpEof
) + lpEof
->offPalEntries
),
1408 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
1410 /* Update the passed data as a return code */
1411 info
->lpPe
= NULL
; /* Palettes were copied! */
1412 info
->cEntries
= (UINT
)dwNumPalToCopy
;
1414 return FALSE
; /* That's all we need */
1420 /*****************************************************************************
1421 * GetEnhMetaFilePaletteEntries (GDI32.179)
1423 * Copy the palette and report size
1425 * BUGS: Error codes (SetLastError) are not set on failures
1427 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
1429 LPPALETTEENTRY lpPe
)
1431 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
1432 UINT uReturnValue
= GDI_ERROR
;
1433 EMF_PaletteCopy infoForCallBack
;
1435 TRACE( "(%04x,%d,%p)\n", hEmf
, cEntries
, lpPe
);
1437 /* First check if there are any palettes associated with
1439 if ( enhHeader
->nPalEntries
== 0 )
1441 /* No palette associated with this enhanced metafile */
1446 /* Is the user requesting the number of palettes? */
1449 uReturnValue
= (UINT
)enhHeader
->nPalEntries
;
1453 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1454 infoForCallBack
.cEntries
= cEntries
;
1455 infoForCallBack
.lpPe
= lpPe
;
1457 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
1458 &infoForCallBack
, NULL
) )
1463 /* Verify that the callback executed correctly */
1464 if ( infoForCallBack
.lpPe
!= NULL
)
1466 /* Callback proc had error! */
1467 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1471 uReturnValue
= infoForCallBack
.cEntries
;
1475 EMF_ReleaseEnhMetaHeader( hEmf
);
1477 return uReturnValue
;
1480 /******************************************************************
1481 * SetWinMetaFileBits (GDI32.343)
1483 * Translate from old style to new style.
1485 * BUGS: - This doesn't take the DC and scaling into account
1486 * - Most record conversions aren't implemented
1487 * - Handle slot assignement is primative and most likely doesn't work
1489 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
,
1490 CONST BYTE
*lpbBuffer
,
1492 CONST METAFILEPICT
*lpmfp
1496 LPVOID lpNewEnhMetaFileBuffer
= NULL
;
1497 UINT uNewEnhMetaFileBufferSize
= 0;
1498 BOOL bFoundEOF
= FALSE
;
1500 FIXME( "(%d,%p,%04x,%p):stub\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
1502 /* 1. Get the header - skip over this and get straight to the records */
1504 uNewEnhMetaFileBufferSize
= sizeof( ENHMETAHEADER
);
1505 lpNewEnhMetaFileBuffer
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1506 uNewEnhMetaFileBufferSize
);
1508 if( lpNewEnhMetaFileBuffer
== NULL
)
1513 /* Fill in the header record */
1515 LPENHMETAHEADER lpNewEnhMetaFileHeader
= (LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
;
1517 lpNewEnhMetaFileHeader
->iType
= EMR_HEADER
;
1518 lpNewEnhMetaFileHeader
->nSize
= sizeof( ENHMETAHEADER
);
1520 /* FIXME: Not right. Must be able to get this from the DC */
1521 lpNewEnhMetaFileHeader
->rclBounds
.left
= 0;
1522 lpNewEnhMetaFileHeader
->rclBounds
.right
= 0;
1523 lpNewEnhMetaFileHeader
->rclBounds
.top
= 0;
1524 lpNewEnhMetaFileHeader
->rclBounds
.bottom
= 0;
1526 /* FIXME: Not right. Must be able to get this from the DC */
1527 lpNewEnhMetaFileHeader
->rclFrame
.left
= 0;
1528 lpNewEnhMetaFileHeader
->rclFrame
.right
= 0;
1529 lpNewEnhMetaFileHeader
->rclFrame
.top
= 0;
1530 lpNewEnhMetaFileHeader
->rclFrame
.bottom
= 0;
1532 lpNewEnhMetaFileHeader
->nHandles
= 0; /* No handles yet */
1534 /* FIXME: Add in the rest of the fields to the header */
1549 (char*)lpbBuffer
+= ((METAHEADER
*)lpbBuffer
)->mtHeaderSize
* 2; /* Point past the header - FIXME: metafile quirk? */
1551 /* 2. Enum over individual records and convert them to the new type of records */
1555 LPMETARECORD lpMetaRecord
= (LPMETARECORD
)lpbBuffer
;
1557 #define EMF_ReAllocAndAdjustPointers( a , b ) \
1560 lpTmp = HeapReAlloc( GetProcessHeap(), 0, \
1561 lpNewEnhMetaFileBuffer, \
1562 uNewEnhMetaFileBufferSize + (b) ); \
1563 if( lpTmp == NULL ) { ERR( "No memory!\n" ); goto error; } \
1564 lpNewEnhMetaFileBuffer = lpTmp; \
1565 lpRecord = (a)( (char*)lpNewEnhMetaFileBuffer + uNewEnhMetaFileBufferSize ); \
1566 uNewEnhMetaFileBufferSize += (b); \
1569 switch( lpMetaRecord
->rdFunction
)
1574 size_t uRecord
= sizeof(*lpRecord
);
1576 EMF_ReAllocAndAdjustPointers(PEMREOF
,uRecord
);
1578 /* Fill the new record - FIXME: This is not right */
1579 lpRecord
->emr
.iType
= EMR_EOF
;
1580 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1581 lpRecord
->nPalEntries
= 0; /* FIXME */
1582 lpRecord
->offPalEntries
= 0; /* FIXME */
1583 lpRecord
->nSizeLast
= 0; /* FIXME */
1585 /* No more records after this one */
1588 FIXME( "META_EOF conversion not correct\n" );
1592 case META_SETMAPMODE
:
1594 PEMRSETMAPMODE lpRecord
;
1595 size_t uRecord
= sizeof(*lpRecord
);
1597 EMF_ReAllocAndAdjustPointers(PEMRSETMAPMODE
,uRecord
);
1599 lpRecord
->emr
.iType
= EMR_SETMAPMODE
;
1600 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1602 lpRecord
->iMode
= lpMetaRecord
->rdParm
[0];
1607 case META_DELETEOBJECT
: /* Select and Delete structures are the same */
1608 case META_SELECTOBJECT
:
1610 PEMRDELETEOBJECT lpRecord
;
1611 size_t uRecord
= sizeof(*lpRecord
);
1613 EMF_ReAllocAndAdjustPointers(PEMRDELETEOBJECT
,uRecord
);
1615 if( lpMetaRecord
->rdFunction
== META_DELETEOBJECT
)
1617 lpRecord
->emr
.iType
= EMR_DELETEOBJECT
;
1621 lpRecord
->emr
.iType
= EMR_SELECTOBJECT
;
1623 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1625 lpRecord
->ihObject
= lpMetaRecord
->rdParm
[0]; /* FIXME: Handle */
1630 case META_POLYGON
: /* This is just plain busted. I don't know what I'm doing */
1632 PEMRPOLYGON16 lpRecord
; /* FIXME: Should it be a poly or poly16? */
1633 size_t uRecord
= sizeof(*lpRecord
);
1635 EMF_ReAllocAndAdjustPointers(PEMRPOLYGON16
,uRecord
);
1637 /* FIXME: This is mostly all wrong */
1638 lpRecord
->emr
.iType
= EMR_POLYGON16
;
1639 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1641 lpRecord
->rclBounds
.left
= 0;
1642 lpRecord
->rclBounds
.right
= 0;
1643 lpRecord
->rclBounds
.top
= 0;
1644 lpRecord
->rclBounds
.bottom
= 0;
1647 lpRecord
->apts
[0].x
= 0;
1648 lpRecord
->apts
[0].y
= 0;
1650 FIXME( "META_POLYGON conversion not correct\n" );
1655 case META_SETPOLYFILLMODE
:
1657 PEMRSETPOLYFILLMODE lpRecord
;
1658 size_t uRecord
= sizeof(*lpRecord
);
1660 EMF_ReAllocAndAdjustPointers(PEMRSETPOLYFILLMODE
,uRecord
);
1662 lpRecord
->emr
.iType
= EMR_SETPOLYFILLMODE
;
1663 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1665 lpRecord
->iMode
= lpMetaRecord
->rdParm
[0];
1670 case META_SETWINDOWORG
:
1672 PEMRSETWINDOWORGEX lpRecord
; /* Seems to be the closest thing */
1673 size_t uRecord
= sizeof(*lpRecord
);
1675 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWORGEX
,uRecord
);
1677 lpRecord
->emr
.iType
= EMR_SETWINDOWORGEX
;
1678 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1680 lpRecord
->ptlOrigin
.x
= lpMetaRecord
->rdParm
[1];
1681 lpRecord
->ptlOrigin
.y
= lpMetaRecord
->rdParm
[0];
1686 case META_SETWINDOWEXT
: /* Structure is the same for SETWINDOWEXT & SETVIEWPORTEXT */
1687 case META_SETVIEWPORTEXT
:
1689 PEMRSETWINDOWEXTEX lpRecord
;
1690 size_t uRecord
= sizeof(*lpRecord
);
1692 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWEXTEX
,uRecord
);
1694 if ( lpMetaRecord
->rdFunction
== META_SETWINDOWEXT
)
1696 lpRecord
->emr
.iType
= EMR_SETWINDOWORGEX
;
1700 lpRecord
->emr
.iType
= EMR_SETVIEWPORTEXTEX
;
1702 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1704 lpRecord
->szlExtent
.cx
= lpMetaRecord
->rdParm
[1];
1705 lpRecord
->szlExtent
.cy
= lpMetaRecord
->rdParm
[0];
1710 case META_CREATEBRUSHINDIRECT
:
1712 PEMRCREATEBRUSHINDIRECT lpRecord
;
1713 size_t uRecord
= sizeof(*lpRecord
);
1715 EMF_ReAllocAndAdjustPointers(PEMRCREATEBRUSHINDIRECT
,uRecord
);
1717 lpRecord
->emr
.iType
= EMR_CREATEBRUSHINDIRECT
;
1718 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1720 lpRecord
->ihBrush
= ((LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
)->nHandles
;
1721 lpRecord
->lb
.lbStyle
= ((LPLOGBRUSH16
)lpMetaRecord
->rdParm
)->lbStyle
;
1722 lpRecord
->lb
.lbColor
= ((LPLOGBRUSH16
)lpMetaRecord
->rdParm
)->lbColor
;
1723 lpRecord
->lb
.lbHatch
= ((LPLOGBRUSH16
)lpMetaRecord
->rdParm
)->lbHatch
;
1725 ((LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
)->nHandles
+= 1; /* New handle */
1731 /* These are all unimplemented and as such are intended to fall through to the default case */
1732 case META_SETBKCOLOR
:
1733 case META_SETBKMODE
:
1735 case META_SETRELABS
:
1736 case META_SETSTRETCHBLTMODE
:
1737 case META_SETTEXTCOLOR
:
1738 case META_SETVIEWPORTORG
:
1739 case META_OFFSETWINDOWORG
:
1740 case META_SCALEWINDOWEXT
:
1741 case META_OFFSETVIEWPORTORG
:
1742 case META_SCALEVIEWPORTEXT
:
1745 case META_EXCLUDECLIPRECT
:
1746 case META_INTERSECTCLIPRECT
:
1749 case META_FLOODFILL
:
1751 case META_RECTANGLE
:
1752 case META_ROUNDRECT
:
1756 case META_OFFSETCLIPRGN
:
1758 case META_POLYPOLYGON
:
1760 case META_RESTOREDC
:
1762 case META_CREATEPATTERNBRUSH
:
1763 case META_CREATEPENINDIRECT
:
1764 case META_CREATEFONTINDIRECT
:
1765 case META_CREATEPALETTE
:
1766 case META_SETTEXTALIGN
:
1767 case META_SELECTPALETTE
:
1768 case META_SETMAPPERFLAGS
:
1769 case META_REALIZEPALETTE
:
1771 case META_EXTTEXTOUT
:
1772 case META_STRETCHDIB
:
1773 case META_DIBSTRETCHBLT
:
1774 case META_STRETCHBLT
:
1776 case META_CREATEREGION
:
1777 case META_FILLREGION
:
1778 case META_FRAMEREGION
:
1779 case META_INVERTREGION
:
1780 case META_PAINTREGION
:
1781 case META_SELECTCLIPREGION
:
1782 case META_DIBCREATEPATTERNBRUSH
:
1783 case META_DIBBITBLT
:
1784 case META_SETTEXTCHAREXTRA
:
1785 case META_SETTEXTJUSTIFICATION
:
1786 case META_EXTFLOODFILL
:
1787 case META_SETDIBTODEV
:
1789 case META_ANIMATEPALETTE
:
1790 case META_SETPALENTRIES
:
1791 case META_RESIZEPALETTE
:
1794 case META_STARTPAGE
:
1798 case META_CREATEBRUSH
:
1799 case META_CREATEBITMAPINDIRECT
:
1800 case META_CREATEBITMAP
:
1801 /* Fall through to unimplemented */
1804 /* Not implemented yet */
1805 FIXME( "Conversion of record type 0x%x not implemented.\n", lpMetaRecord
->rdFunction
);
1810 /* Move to the next record */
1811 (char*)lpbBuffer
+= ((LPMETARECORD
)lpbBuffer
)->rdSize
* 2; /* FIXME: Seem to be doing this in metafile.c */
1813 #undef ReAllocAndAdjustPointers
1816 /* We know the last of the header information now */
1817 ((LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
)->nBytes
= uNewEnhMetaFileBufferSize
;
1819 /* Create the enhanced metafile */
1820 hMf
= SetEnhMetaFileBits( uNewEnhMetaFileBufferSize
, (const BYTE
*)lpNewEnhMetaFileBuffer
);
1823 ERR( "Problem creating metafile. Did the conversion fail somewhere?\n" );
1828 /* Free the data associated with our copy since it's been copied */
1829 HeapFree( GetProcessHeap(), 0, lpNewEnhMetaFileBuffer
);