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.
23 #include "wine/winestring.h"
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
38 HENHMETAFILE hmf
= GDI_AllocObject( sizeof(ENHMETAFILEOBJ
),
40 ENHMETAFILEOBJ
*metaObj
= (ENHMETAFILEOBJ
*)GDI_HEAP_LOCK( hmf
);
42 metaObj
->hFile
= hFile
;
43 metaObj
->hMapping
= hMapping
;
44 GDI_HEAP_UNLOCK( hmf
);
48 /****************************************************************************
49 * EMF_Delete_HENHMETAFILE
51 static BOOL
EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf
)
53 ENHMETAFILEOBJ
*metaObj
= (ENHMETAFILEOBJ
*)GDI_GetObjPtr( hmf
,
55 if(!metaObj
) return FALSE
;
56 if(metaObj
->hMapping
) {
57 UnmapViewOfFile( metaObj
->emh
);
58 CloseHandle( metaObj
->hMapping
);
59 CloseHandle( metaObj
->hFile
);
61 HeapFree( GetProcessHeap(), 0, metaObj
->emh
);
62 return GDI_FreeObject( hmf
);
65 /******************************************************************
66 * EMF_GetEnhMetaHeader
68 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
69 * Should be followed by call to EMF_ReleaseEnhMetaHeader
71 static ENHMETAHEADER
*EMF_GetEnhMetaHeader( HENHMETAFILE hmf
)
73 ENHMETAFILEOBJ
*metaObj
= (ENHMETAFILEOBJ
*)GDI_GetObjPtr( hmf
,
75 TRACE("hmf %04x -> enhmetaObj %p\n", hmf
, metaObj
);
76 return metaObj
? metaObj
->emh
: NULL
;
79 /******************************************************************
80 * EMF_ReleaseEnhMetaHeader
82 * Releases ENHMETAHEADER associated with HENHMETAFILE
84 static BOOL
EMF_ReleaseEnhMetaHeader( HENHMETAFILE hmf
)
86 return GDI_HEAP_UNLOCK( hmf
);
89 /*****************************************************************************
93 static HENHMETAFILE
EMF_GetEnhMetaFile( HFILE hFile
)
98 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
99 emh
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, 0 );
101 if (emh
->iType
!= EMR_HEADER
|| emh
->dSignature
!= ENHMETA_SIGNATURE
) {
102 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
103 emh
->iType
, emh
->dSignature
);
104 UnmapViewOfFile( emh
);
105 CloseHandle( hMapping
);
108 return EMF_Create_HENHMETAFILE( emh
, hFile
, hMapping
);
112 /*****************************************************************************
113 * GetEnhMetaFileA (GDI32.174)
117 HENHMETAFILE WINAPI
GetEnhMetaFileA(
118 LPCSTR lpszMetaFile
/* filename of enhanced metafile */
124 hFile
= CreateFileA(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
125 OPEN_EXISTING
, 0, 0);
126 if (hFile
== INVALID_HANDLE_VALUE
) {
127 WARN("could not open %s\n", lpszMetaFile
);
130 hmf
= EMF_GetEnhMetaFile( hFile
);
132 CloseHandle( hFile
);
136 /*****************************************************************************
137 * GetEnhMetaFileW (GDI32.180)
139 HENHMETAFILE WINAPI
GetEnhMetaFileW(
140 LPCWSTR lpszMetaFile
) /* filename of enhanced metafile */
145 hFile
= CreateFileW(lpszMetaFile
, GENERIC_READ
, FILE_SHARE_READ
, 0,
146 OPEN_EXISTING
, 0, 0);
147 if (hFile
== INVALID_HANDLE_VALUE
) {
148 WARN("could not open %s\n", debugstr_w(lpszMetaFile
));
151 hmf
= EMF_GetEnhMetaFile( hFile
);
153 CloseHandle( hFile
);
157 /*****************************************************************************
158 * GetEnhMetaFileHeader (GDI32.178)
160 * If buf is NULL, returns the size of buffer required.
161 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
164 UINT WINAPI
GetEnhMetaFileHeader(
165 HENHMETAFILE hmf
, /* enhanced metafile */
166 UINT bufsize
, /* size of buffer */
167 LPENHMETAHEADER buf
/* buffer */
173 emh
= EMF_GetEnhMetaHeader(hmf
);
174 if(!emh
) return FALSE
;
177 EMF_ReleaseEnhMetaHeader(hmf
);
180 size
= min(size
, bufsize
);
181 memmove(buf
, emh
, size
);
182 EMF_ReleaseEnhMetaHeader(hmf
);
187 /*****************************************************************************
188 * GetEnhMetaFileDescriptionA (GDI32.176)
190 UINT WINAPI
GetEnhMetaFileDescriptionA(
191 HENHMETAFILE hmf
, /* enhanced metafile */
192 UINT size
, /* size of buf */
193 LPSTR buf
/* buffer to receive description */
196 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
199 if(!emh
) return FALSE
;
200 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) {
201 EMF_ReleaseEnhMetaHeader(hmf
);
204 if (!buf
|| !size
) {
205 EMF_ReleaseEnhMetaHeader(hmf
);
206 return emh
->nDescription
;
209 first
= lstrlenW( (WCHAR
*) ((char *) emh
+ emh
->offDescription
));
211 lstrcpynWtoA(buf
, (WCHAR
*) ((char *) emh
+ emh
->offDescription
), size
);
212 first_A
= lstrlenA( buf
);
214 lstrcpynWtoA(buf
, (WCHAR
*) ((char *) emh
+ emh
->offDescription
+2*(first
+1)),
215 size
- first_A
- 1); /* i18n ready */
216 first_A
+= lstrlenA(buf
) + 1;
218 EMF_ReleaseEnhMetaHeader(hmf
);
219 return min(size
, first_A
);
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
, /* enhanced metafile */
233 UINT size
, /* size of buf */
234 LPWSTR buf
/* 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
));
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
, /* device context in which to render EMF record */
308 LPHANDLETABLE handletable
, /* array of handles to be used in rendering record */
309 const ENHMETARECORD
*mr
, /* EMF record to render */
310 UINT handles
/* 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
);
544 case EMR_POLYPOLYGON16
:
546 PEMRPOLYPOLYGON16 pPolyPoly
= (PEMRPOLYPOLYGON16
) mr
;
547 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
548 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
550 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
551 pPolyPoly
->cpts
* sizeof(POINT
) );
553 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
554 CONV_POINT16TO32((POINTS
*) (pPolyPoly
->aPolyCounts
+
555 pPolyPoly
->nPolys
) + i
, pts
+ i
);
557 PolyPolygon(hdc
, pts
, (INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
558 HeapFree( GetProcessHeap(), 0, pts
);
562 case EMR_STRETCHDIBITS
:
564 LONG xDest
= mr
->dParm
[4];
565 LONG yDest
= mr
->dParm
[5];
566 LONG xSrc
= mr
->dParm
[6];
567 LONG ySrc
= mr
->dParm
[7];
568 LONG cxSrc
= mr
->dParm
[8];
569 LONG cySrc
= mr
->dParm
[9];
570 DWORD offBmiSrc
= mr
->dParm
[10];
571 DWORD offBitsSrc
= mr
->dParm
[12];
572 DWORD iUsageSrc
= mr
->dParm
[14];
573 DWORD dwRop
= mr
->dParm
[15];
574 LONG cxDest
= mr
->dParm
[16];
575 LONG cyDest
= mr
->dParm
[17];
577 StretchDIBits(hdc
,xDest
,yDest
,cxDest
,cyDest
,
578 xSrc
,ySrc
,cxSrc
,cySrc
,
579 ((char *)mr
)+offBitsSrc
,
580 (const BITMAPINFO
*)(((char *)mr
)+offBmiSrc
),
584 case EMR_EXTTEXTOUTW
:
587 DWORD flags
= mr
->dParm
[4];
589 DWORD x
= mr
->dParm
[7], y
= mr
->dParm
[8];
590 DWORD count
= mr
->dParm
[9];
592 LPWSTR str
= (LPWSTR
)& mr
->dParm
[17];
593 /* trailing info: dx array? */
594 FIXME("Many ExtTextOut args not handled\n");
595 ExtTextOutW(hdc
, x
, y
, flags
, /* lpRect */ NULL
,
596 str
, count
, /* lpDx */ NULL
);
600 case EMR_CREATEPALETTE
:
602 PEMRCREATEPALETTE lpCreatePal
= (PEMRCREATEPALETTE
)mr
;
604 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
605 CreatePalette( &lpCreatePal
->lgpl
);
610 case EMR_SELECTPALETTE
:
612 PEMRSELECTPALETTE lpSelectPal
= (PEMRSELECTPALETTE
)mr
;
614 /* FIXME: Should this be forcing background mode? */
615 (handletable
->objectHandle
)[ lpSelectPal
->ihPal
] =
616 SelectPalette( hdc
, lpSelectPal
->ihPal
, FALSE
);
620 case EMR_REALIZEPALETTE
:
622 RealizePalette( hdc
);
627 case EMR_EXTSELECTCLIPRGN
:
629 PEMREXTSELECTCLIPRGN lpRgn
= (PEMREXTSELECTCLIPRGN
)mr
;
631 /* Need to make a region out of the RGNDATA we have */
632 ExtSelectClipRgn( hdc
, ..., (INT
)(lpRgn
->iMode
) );
643 case EMR_SETWORLDTRANSFORM
:
645 PEMRSETWORLDTRANSFORM lpXfrm
= (PEMRSETWORLDTRANSFORM
)mr
;
647 SetWorldTransform( hdc
, &lpXfrm
->xform
);
654 PEMRPOLYBEZIER lpPolyBez
= (PEMRPOLYBEZIER
)mr
;
655 PolyBezier(hdc
, (const LPPOINT
)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
661 PEMRPOLYGON lpPoly
= (PEMRPOLYGON
)mr
;
662 Polygon( hdc
, (const LPPOINT
)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
668 PEMRPOLYLINE lpPolyLine
= (PEMRPOLYLINE
)mr
;
669 Polyline(hdc
, (const LPPOINT
)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
673 case EMR_POLYBEZIERTO
:
675 PEMRPOLYBEZIERTO lpPolyBezierTo
= (PEMRPOLYBEZIERTO
)mr
;
676 PolyBezierTo( hdc
, (const LPPOINT
)lpPolyBezierTo
->aptl
,
677 (UINT
)lpPolyBezierTo
->cptl
);
683 PEMRPOLYLINETO lpPolyLineTo
= (PEMRPOLYLINETO
)mr
;
684 PolylineTo( hdc
, (const LPPOINT
)lpPolyLineTo
->aptl
,
685 (UINT
)lpPolyLineTo
->cptl
);
689 case EMR_POLYPOLYLINE
:
691 PEMRPOLYPOLYLINE pPolyPolyline
= (PEMRPOLYPOLYLINE
) mr
;
692 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
694 PolyPolyline(hdc
, (LPPOINT
)(pPolyPolyline
->aPolyCounts
+
695 pPolyPolyline
->nPolys
),
696 pPolyPolyline
->aPolyCounts
,
697 pPolyPolyline
->nPolys
);
702 case EMR_POLYPOLYGON
:
704 PEMRPOLYPOLYGON pPolyPolygon
= (PEMRPOLYPOLYGON
) mr
;
706 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
708 PolyPolygon(hdc
, (LPPOINT
)(pPolyPolygon
->aPolyCounts
+
709 pPolyPolygon
->nPolys
),
710 (INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
714 case EMR_SETBRUSHORGEX
:
716 PEMRSETBRUSHORGEX lpSetBrushOrgEx
= (PEMRSETBRUSHORGEX
)mr
;
719 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
720 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
728 PEMRSETPIXELV lpSetPixelV
= (PEMRSETPIXELV
)mr
;
731 (INT
)lpSetPixelV
->ptlPixel
.x
,
732 (INT
)lpSetPixelV
->ptlPixel
.y
,
733 lpSetPixelV
->crColor
);
738 case EMR_SETMAPPERFLAGS
:
740 PEMRSETMAPPERFLAGS lpSetMapperFlags
= (PEMRSETMAPPERFLAGS
)mr
;
742 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
747 case EMR_SETCOLORADJUSTMENT
:
749 PEMRSETCOLORADJUSTMENT lpSetColorAdjust
= (PEMRSETCOLORADJUSTMENT
)mr
;
751 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
756 case EMR_OFFSETCLIPRGN
:
758 PEMROFFSETCLIPRGN lpOffsetClipRgn
= (PEMROFFSETCLIPRGN
)mr
;
761 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
762 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
767 case EMR_EXCLUDECLIPRECT
:
769 PEMREXCLUDECLIPRECT lpExcludeClipRect
= (PEMREXCLUDECLIPRECT
)mr
;
771 ExcludeClipRect( hdc
,
772 lpExcludeClipRect
->rclClip
.left
,
773 lpExcludeClipRect
->rclClip
.top
,
774 lpExcludeClipRect
->rclClip
.right
,
775 lpExcludeClipRect
->rclClip
.bottom
);
780 case EMR_SCALEVIEWPORTEXTEX
:
782 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx
= (PEMRSCALEVIEWPORTEXTEX
)mr
;
784 ScaleViewportExtEx( hdc
,
785 lpScaleViewportExtEx
->xNum
,
786 lpScaleViewportExtEx
->xDenom
,
787 lpScaleViewportExtEx
->yNum
,
788 lpScaleViewportExtEx
->yDenom
,
794 case EMR_SCALEWINDOWEXTEX
:
796 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx
= (PEMRSCALEWINDOWEXTEX
)mr
;
798 ScaleWindowExtEx( hdc
,
799 lpScaleWindowExtEx
->xNum
,
800 lpScaleWindowExtEx
->xDenom
,
801 lpScaleWindowExtEx
->yNum
,
802 lpScaleWindowExtEx
->yDenom
,
808 case EMR_MODIFYWORLDTRANSFORM
:
810 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans
= (PEMRMODIFYWORLDTRANSFORM
)mr
;
812 ModifyWorldTransform( hdc
, &lpModifyWorldTrans
->xform
,
813 lpModifyWorldTrans
->iMode
);
820 PEMRANGLEARC lpAngleArc
= (PEMRANGLEARC
)mr
;
823 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
824 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
825 lpAngleArc
->eSweepAngle
);
832 PEMRROUNDRECT lpRoundRect
= (PEMRROUNDRECT
)mr
;
835 lpRoundRect
->rclBox
.left
,
836 lpRoundRect
->rclBox
.top
,
837 lpRoundRect
->rclBox
.right
,
838 lpRoundRect
->rclBox
.bottom
,
839 lpRoundRect
->szlCorner
.cx
,
840 lpRoundRect
->szlCorner
.cy
);
847 PEMRARC lpArc
= (PEMRARC
)mr
;
850 (INT
)lpArc
->rclBox
.left
,
851 (INT
)lpArc
->rclBox
.top
,
852 (INT
)lpArc
->rclBox
.right
,
853 (INT
)lpArc
->rclBox
.bottom
,
854 (INT
)lpArc
->ptlStart
.x
,
855 (INT
)lpArc
->ptlStart
.y
,
856 (INT
)lpArc
->ptlEnd
.x
,
857 (INT
)lpArc
->ptlEnd
.y
);
864 PEMRCHORD lpChord
= (PEMRCHORD
)mr
;
867 (INT
)lpChord
->rclBox
.left
,
868 (INT
)lpChord
->rclBox
.top
,
869 (INT
)lpChord
->rclBox
.right
,
870 (INT
)lpChord
->rclBox
.bottom
,
871 (INT
)lpChord
->ptlStart
.x
,
872 (INT
)lpChord
->ptlStart
.y
,
873 (INT
)lpChord
->ptlEnd
.x
,
874 (INT
)lpChord
->ptlEnd
.y
);
881 PEMRPIE lpPie
= (PEMRPIE
)mr
;
884 (INT
)lpPie
->rclBox
.left
,
885 (INT
)lpPie
->rclBox
.top
,
886 (INT
)lpPie
->rclBox
.right
,
887 (INT
)lpPie
->rclBox
.bottom
,
888 (INT
)lpPie
->ptlStart
.x
,
889 (INT
)lpPie
->ptlStart
.y
,
890 (INT
)lpPie
->ptlEnd
.x
,
891 (INT
)lpPie
->ptlEnd
.y
);
898 PEMRARC lpArcTo
= (PEMRARC
)mr
;
901 (INT
)lpArcTo
->rclBox
.left
,
902 (INT
)lpArcTo
->rclBox
.top
,
903 (INT
)lpArcTo
->rclBox
.right
,
904 (INT
)lpArcTo
->rclBox
.bottom
,
905 (INT
)lpArcTo
->ptlStart
.x
,
906 (INT
)lpArcTo
->ptlStart
.y
,
907 (INT
)lpArcTo
->ptlEnd
.x
,
908 (INT
)lpArcTo
->ptlEnd
.y
);
913 case EMR_EXTFLOODFILL
:
915 PEMREXTFLOODFILL lpExtFloodFill
= (PEMREXTFLOODFILL
)mr
;
918 (INT
)lpExtFloodFill
->ptlStart
.x
,
919 (INT
)lpExtFloodFill
->ptlStart
.y
,
920 lpExtFloodFill
->crColor
,
921 (UINT
)lpExtFloodFill
->iMode
);
928 PEMRPOLYDRAW lpPolyDraw
= (PEMRPOLYDRAW
)mr
;
930 (const LPPOINT
)lpPolyDraw
->aptl
,
932 (INT
)lpPolyDraw
->cptl
);
937 case EMR_SETARCDIRECTION
:
939 PEMRSETARCDIRECTION lpSetArcDirection
= (PEMRSETARCDIRECTION
)mr
;
940 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
944 case EMR_SETMITERLIMIT
:
946 PEMRSETMITERLIMIT lpSetMiterLimit
= (PEMRSETMITERLIMIT
)mr
;
947 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
963 case EMR_CLOSEFIGURE
:
971 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
976 case EMR_STROKEANDFILLPATH
:
978 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
979 StrokeAndFillPath( hdc
);
985 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
990 case EMR_FLATTENPATH
:
1002 case EMR_SELECTCLIPPATH
:
1004 PEMRSELECTCLIPPATH lpSelectClipPath
= (PEMRSELECTCLIPPATH
)mr
;
1005 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1015 case EMR_CREATECOLORSPACE
:
1017 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1018 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1019 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1023 case EMR_SETCOLORSPACE
:
1025 PEMRSETCOLORSPACE lpSetColorSpace
= (PEMRSETCOLORSPACE
)mr
;
1027 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1031 case EMR_DELETECOLORSPACE
:
1033 PEMRDELETECOLORSPACE lpDeleteColorSpace
= (PEMRDELETECOLORSPACE
)mr
;
1034 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1038 case EMR_SETICMMODE
:
1040 PERMSETICMMODE lpSetICMMode
= (PERMSETICMMODE
)mr
;
1041 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1045 case EMR_PIXELFORMAT
:
1048 PEMRPIXELFORMAT lpPixelFormat
= (PEMRPIXELFORMAT
)mr
;
1050 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1051 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1056 case EMR_SETPALETTEENTRIES
:
1058 PEMRSETPALETTEENTRIES lpSetPaletteEntries
= (PEMRSETPALETTEENTRIES
)mr
;
1060 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1061 (UINT
)lpSetPaletteEntries
->iStart
,
1062 (UINT
)lpSetPaletteEntries
->cEntries
,
1063 lpSetPaletteEntries
->aPalEntries
);
1068 case EMR_RESIZEPALETTE
:
1070 PEMRRESIZEPALETTE lpResizePalette
= (PEMRRESIZEPALETTE
)mr
;
1072 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1073 (UINT
)lpResizePalette
->cEntries
);
1078 case EMR_CREATEDIBPATTERNBRUSHPT
:
1080 PEMRCREATEDIBPATTERNBRUSHPT lpCreate
= (PEMRCREATEDIBPATTERNBRUSHPT
)mr
;
1082 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1083 LPVOID lpPackedStruct
= HeapAlloc( GetProcessHeap(),
1085 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1086 /* Now pack this structure */
1087 memcpy( lpPackedStruct
,
1088 ((BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1090 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1091 ((BYTE
*)lpCreate
) + lpCreate
->offBits
,
1094 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1095 CreateDIBPatternBrushPt( lpPackedStruct
,
1096 (UINT
)lpCreate
->iUsage
);
1102 case EMR_STRETCHBLT
:
1105 case EMR_SETDIBITSTODEVICE
:
1106 case EMR_EXTTEXTOUTA
:
1107 case EMR_POLYBEZIER16
:
1108 case EMR_POLYBEZIERTO16
:
1109 case EMR_POLYLINETO16
:
1110 case EMR_POLYPOLYLINE16
:
1111 case EMR_POLYDRAW16
:
1112 case EMR_CREATEMONOBRUSH
:
1113 case EMR_POLYTEXTOUTA
:
1114 case EMR_POLYTEXTOUTW
:
1120 case EMR_GLSBOUNDEDRECORD
:
1122 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1123 record then ignore and return TRUE. */
1124 FIXME("type %d is unimplemented\n", type
);
1131 /*****************************************************************************
1133 * EnumEnhMetaFile (GDI32.79)
1135 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1137 * record. Returns when either every record has been used or
1138 * when _EnhMetaFunc_ returns FALSE.
1142 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1148 BOOL WINAPI
EnumEnhMetaFile(
1149 HDC hdc
, /* device context to pass to _EnhMetaFunc_ */
1150 HENHMETAFILE hmf
, /* EMF to walk */
1151 ENHMFENUMPROC callback
, /* callback function */
1152 LPVOID data
, /* optional data for callback function */
1153 const RECT
*lpRect
/* bounding rectangle for rendered metafile */
1157 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
1161 FLOAT xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
1162 XFORM savedXform
, xform
;
1165 SetLastError(ERROR_INVALID_HANDLE
);
1169 SetLastError(ERROR_INVALID_PARAMETER
);
1172 count
= emh
->nHandles
;
1173 ht
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1174 sizeof(HANDLETABLE
) * count
);
1175 ht
->objectHandle
[0] = hmf
;
1177 xSrcPixSize
= (FLOAT
) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
1178 ySrcPixSize
= (FLOAT
) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
1179 xscale
= (FLOAT
)(lpRect
->right
- lpRect
->left
) * 100.0 /
1180 (emh
->rclFrame
.right
- emh
->rclFrame
.left
) * xSrcPixSize
;
1181 yscale
= (FLOAT
)(lpRect
->bottom
- lpRect
->top
) * 100.0 /
1182 (emh
->rclFrame
.bottom
- emh
->rclFrame
.top
) * ySrcPixSize
;
1184 xform
.eM11
= xscale
;
1187 xform
.eM22
= yscale
;
1188 if(emh
->rclFrame
.left
|| emh
->rclFrame
.top
)
1189 FIXME("Can't cope with nonzero rclFrame origin yet\n");
1190 /* eDx = lpRect->left - (lpRect width) / (rclFrame width) * rclFrame.left ? */
1191 xform
.eDx
= lpRect
->left
;
1192 xform
.eDy
= lpRect
->top
;
1193 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
1194 GetWorldTransform(hdc
, &savedXform
);
1195 if (!ModifyWorldTransform(hdc
, &xform
, MWT_LEFTMULTIPLY
)) {
1196 ERR("World transform failed!\n");
1200 ret
= (*callback
)(hdc
, ht
, (LPENHMETARECORD
) emh
, count
, data
);
1201 if (emh
->iType
== EMR_EOF
) break;
1202 emh
= (LPENHMETAHEADER
) ((char *) emh
+ emh
->nSize
);
1204 for(i
= 1; i
< count
; i
++) /* Don't delete element 0 (hmf) */
1205 if( (ht
->objectHandle
)[i
] )
1206 DeleteObject( (ht
->objectHandle
)[i
] );
1207 HeapFree( GetProcessHeap(), 0, ht
);
1208 EMF_ReleaseEnhMetaHeader(hmf
);
1209 SetWorldTransform(hdc
, &savedXform
);
1210 if (savedMode
) SetGraphicsMode(hdc
, savedMode
);
1214 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
1216 INT handles
, LPVOID data
)
1218 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
1221 /**************************************************************************
1222 * PlayEnhMetaFile (GDI32.263)
1224 * Renders an enhanced metafile into a specified rectangle *lpRect
1225 * in device context hdc.
1228 BOOL WINAPI
PlayEnhMetaFile(
1229 HDC hdc
, /* DC to render into */
1230 HENHMETAFILE hmf
, /* metafile to render */
1231 const RECT
*lpRect
/* rectangle to place metafile inside */
1234 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
1238 /*****************************************************************************
1239 * DeleteEnhMetaFile (GDI32.68)
1241 * Deletes an enhanced metafile and frees the associated storage.
1243 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
1245 return EMF_Delete_HENHMETAFILE( hmf
);
1248 /*****************************************************************************
1249 * CopyEnhMetaFileA (GDI32.21) Duplicate an enhanced metafile
1253 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
1254 HENHMETAFILE hmfSrc
,
1257 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
1258 HENHMETAFILE hmfDst
;
1260 if(!emrSrc
) return FALSE
;
1262 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
1263 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
1264 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, 0, 0 );
1267 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0, NULL
,
1268 CREATE_ALWAYS
, 0, -1);
1269 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, 0, 0);
1270 hmfDst
= EMF_GetEnhMetaFile( hFile
);
1272 EMF_ReleaseEnhMetaHeader( hmfSrc
);
1277 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1278 typedef struct tagEMF_PaletteCopy
1281 LPPALETTEENTRY lpPe
;
1284 /***************************************************************
1285 * Find the EMR_EOF record and then use it to find the
1286 * palette entries for this enhanced metafile.
1287 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1288 * which contains the max number of elements to copy and where
1291 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1293 INT CALLBACK
cbEnhPaletteCopy( HDC a
,
1295 LPENHMETARECORD lpEMR
,
1300 if ( lpEMR
->iType
== EMR_EOF
)
1302 PEMREOF lpEof
= (PEMREOF
)lpEMR
;
1303 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
1304 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
1306 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy
);
1308 memcpy( (LPVOID
)info
->lpPe
,
1309 (LPVOID
)(((LPSTR
)lpEof
) + lpEof
->offPalEntries
),
1310 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
1312 /* Update the passed data as a return code */
1313 info
->lpPe
= NULL
; /* Palettes were copied! */
1314 info
->cEntries
= (UINT
)dwNumPalToCopy
;
1316 return FALSE
; /* That's all we need */
1322 /*****************************************************************************
1323 * GetEnhMetaFilePaletteEntries (GDI32.179)
1325 * Copy the palette and report size
1327 * BUGS: Error codes (SetLastError) are not set on failures
1329 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
1331 LPPALETTEENTRY lpPe
)
1333 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
1334 UINT uReturnValue
= GDI_ERROR
;
1335 EMF_PaletteCopy infoForCallBack
;
1337 TRACE( "(%04x,%d,%p)\n", hEmf
, cEntries
, lpPe
);
1339 /* First check if there are any palettes associated with
1341 if ( enhHeader
->nPalEntries
== 0 )
1343 /* No palette associated with this enhanced metafile */
1348 /* Is the user requesting the number of palettes? */
1351 uReturnValue
= (UINT
)enhHeader
->nPalEntries
;
1355 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1356 infoForCallBack
.cEntries
= cEntries
;
1357 infoForCallBack
.lpPe
= lpPe
;
1359 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
1360 &infoForCallBack
, NULL
) )
1365 /* Verify that the callback executed correctly */
1366 if ( infoForCallBack
.lpPe
!= NULL
)
1368 /* Callback proc had error! */
1369 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1373 uReturnValue
= infoForCallBack
.cEntries
;
1377 EMF_ReleaseEnhMetaHeader( hEmf
);
1379 return uReturnValue
;
1382 /******************************************************************
1383 * SetWinMetaFileBits (GDI32.343)
1385 * Translate from old style to new style.
1387 * BUGS: - This doesn't take the DC and scaling into account
1388 * - Most record conversions aren't implemented
1389 * - Handle slot assignement is primative and most likely doesn't work
1391 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
,
1392 CONST BYTE
*lpbBuffer
,
1394 CONST METAFILEPICT
*lpmfp
1398 LPVOID lpNewEnhMetaFileBuffer
= NULL
;
1399 UINT uNewEnhMetaFileBufferSize
= 0;
1400 BOOL bFoundEOF
= FALSE
;
1402 FIXME( "(%d,%p,%04x,%p):stub\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
1404 /* 1. Get the header - skip over this and get straight to the records */
1406 uNewEnhMetaFileBufferSize
= sizeof( ENHMETAHEADER
);
1407 lpNewEnhMetaFileBuffer
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1408 uNewEnhMetaFileBufferSize
);
1410 if( lpNewEnhMetaFileBuffer
== NULL
)
1415 /* Fill in the header record */
1417 LPENHMETAHEADER lpNewEnhMetaFileHeader
= (LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
;
1419 lpNewEnhMetaFileHeader
->iType
= EMR_HEADER
;
1420 lpNewEnhMetaFileHeader
->nSize
= sizeof( ENHMETAHEADER
);
1422 /* FIXME: Not right. Must be able to get this from the DC */
1423 lpNewEnhMetaFileHeader
->rclBounds
.left
= 0;
1424 lpNewEnhMetaFileHeader
->rclBounds
.right
= 0;
1425 lpNewEnhMetaFileHeader
->rclBounds
.top
= 0;
1426 lpNewEnhMetaFileHeader
->rclBounds
.bottom
= 0;
1428 /* FIXME: Not right. Must be able to get this from the DC */
1429 lpNewEnhMetaFileHeader
->rclFrame
.left
= 0;
1430 lpNewEnhMetaFileHeader
->rclFrame
.right
= 0;
1431 lpNewEnhMetaFileHeader
->rclFrame
.top
= 0;
1432 lpNewEnhMetaFileHeader
->rclFrame
.bottom
= 0;
1434 lpNewEnhMetaFileHeader
->nHandles
= 0; /* No handles yet */
1436 /* FIXME: Add in the rest of the fields to the header */
1451 (char*)lpbBuffer
+= ((METAHEADER
*)lpbBuffer
)->mtHeaderSize
* 2; /* Point past the header - FIXME: metafile quirk? */
1453 /* 2. Enum over individual records and convert them to the new type of records */
1457 LPMETARECORD lpMetaRecord
= (LPMETARECORD
)lpbBuffer
;
1459 #define EMF_ReAllocAndAdjustPointers( a , b ) \
1462 lpTmp = HeapReAlloc( GetProcessHeap(), 0, \
1463 lpNewEnhMetaFileBuffer, \
1464 uNewEnhMetaFileBufferSize + (b) ); \
1465 if( lpTmp == NULL ) { ERR( "No memory!\n" ); goto error; } \
1466 lpNewEnhMetaFileBuffer = lpTmp; \
1467 lpRecord = (a)( (char*)lpNewEnhMetaFileBuffer + uNewEnhMetaFileBufferSize ); \
1468 uNewEnhMetaFileBufferSize += (b); \
1471 switch( lpMetaRecord
->rdFunction
)
1476 size_t uRecord
= sizeof(*lpRecord
);
1478 EMF_ReAllocAndAdjustPointers(PEMREOF
,uRecord
);
1480 /* Fill the new record - FIXME: This is not right */
1481 lpRecord
->emr
.iType
= EMR_EOF
;
1482 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1483 lpRecord
->nPalEntries
= 0; /* FIXME */
1484 lpRecord
->offPalEntries
= 0; /* FIXME */
1485 lpRecord
->nSizeLast
= 0; /* FIXME */
1487 /* No more records after this one */
1490 FIXME( "META_EOF conversion not correct\n" );
1494 case META_SETMAPMODE
:
1496 PEMRSETMAPMODE lpRecord
;
1497 size_t uRecord
= sizeof(*lpRecord
);
1499 EMF_ReAllocAndAdjustPointers(PEMRSETMAPMODE
,uRecord
);
1501 lpRecord
->emr
.iType
= EMR_SETMAPMODE
;
1502 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1504 lpRecord
->iMode
= lpMetaRecord
->rdParm
[0];
1509 case META_DELETEOBJECT
: /* Select and Delete structures are the same */
1510 case META_SELECTOBJECT
:
1512 PEMRDELETEOBJECT lpRecord
;
1513 size_t uRecord
= sizeof(*lpRecord
);
1515 EMF_ReAllocAndAdjustPointers(PEMRDELETEOBJECT
,uRecord
);
1517 if( lpMetaRecord
->rdFunction
== META_DELETEOBJECT
)
1519 lpRecord
->emr
.iType
= EMR_DELETEOBJECT
;
1523 lpRecord
->emr
.iType
= EMR_SELECTOBJECT
;
1525 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1527 lpRecord
->ihObject
= lpMetaRecord
->rdParm
[0]; /* FIXME: Handle */
1532 case META_POLYGON
: /* This is just plain busted. I don't know what I'm doing */
1534 PEMRPOLYGON16 lpRecord
; /* FIXME: Should it be a poly or poly16? */
1535 size_t uRecord
= sizeof(*lpRecord
);
1537 EMF_ReAllocAndAdjustPointers(PEMRPOLYGON16
,uRecord
);
1539 /* FIXME: This is mostly all wrong */
1540 lpRecord
->emr
.iType
= EMR_POLYGON16
;
1541 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1543 lpRecord
->rclBounds
.left
= 0;
1544 lpRecord
->rclBounds
.right
= 0;
1545 lpRecord
->rclBounds
.top
= 0;
1546 lpRecord
->rclBounds
.bottom
= 0;
1549 lpRecord
->apts
[0].x
= 0;
1550 lpRecord
->apts
[0].y
= 0;
1552 FIXME( "META_POLYGON conversion not correct\n" );
1557 case META_SETPOLYFILLMODE
:
1559 PEMRSETPOLYFILLMODE lpRecord
;
1560 size_t uRecord
= sizeof(*lpRecord
);
1562 EMF_ReAllocAndAdjustPointers(PEMRSETPOLYFILLMODE
,uRecord
);
1564 lpRecord
->emr
.iType
= EMR_SETPOLYFILLMODE
;
1565 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1567 lpRecord
->iMode
= lpMetaRecord
->rdParm
[0];
1572 case META_SETWINDOWORG
:
1574 PEMRSETWINDOWORGEX lpRecord
; /* Seems to be the closest thing */
1575 size_t uRecord
= sizeof(*lpRecord
);
1577 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWORGEX
,uRecord
);
1579 lpRecord
->emr
.iType
= EMR_SETWINDOWORGEX
;
1580 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1582 lpRecord
->ptlOrigin
.x
= lpMetaRecord
->rdParm
[1];
1583 lpRecord
->ptlOrigin
.y
= lpMetaRecord
->rdParm
[0];
1588 case META_SETWINDOWEXT
: /* Structure is the same for SETWINDOWEXT & SETVIEWPORTEXT */
1589 case META_SETVIEWPORTEXT
:
1591 PEMRSETWINDOWEXTEX lpRecord
;
1592 size_t uRecord
= sizeof(*lpRecord
);
1594 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWEXTEX
,uRecord
);
1596 if ( lpMetaRecord
->rdFunction
== META_SETWINDOWEXT
)
1598 lpRecord
->emr
.iType
= EMR_SETWINDOWORGEX
;
1602 lpRecord
->emr
.iType
= EMR_SETVIEWPORTEXTEX
;
1604 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1606 lpRecord
->szlExtent
.cx
= lpMetaRecord
->rdParm
[1];
1607 lpRecord
->szlExtent
.cy
= lpMetaRecord
->rdParm
[0];
1612 case META_CREATEBRUSHINDIRECT
:
1614 PEMRCREATEBRUSHINDIRECT lpRecord
;
1615 size_t uRecord
= sizeof(*lpRecord
);
1617 EMF_ReAllocAndAdjustPointers(PEMRCREATEBRUSHINDIRECT
,uRecord
);
1619 lpRecord
->emr
.iType
= EMR_CREATEBRUSHINDIRECT
;
1620 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1622 lpRecord
->ihBrush
= ((LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
)->nHandles
;
1623 lpRecord
->lb
.lbStyle
= ((LPLOGBRUSH16
)lpMetaRecord
->rdParm
)->lbStyle
;
1624 lpRecord
->lb
.lbColor
= ((LPLOGBRUSH16
)lpMetaRecord
->rdParm
)->lbColor
;
1625 lpRecord
->lb
.lbHatch
= ((LPLOGBRUSH16
)lpMetaRecord
->rdParm
)->lbHatch
;
1627 ((LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
)->nHandles
+= 1; /* New handle */
1633 /* These are all unimplemented and as such are intended to fall through to the default case */
1634 case META_SETBKCOLOR
:
1635 case META_SETBKMODE
:
1637 case META_SETRELABS
:
1638 case META_SETSTRETCHBLTMODE
:
1639 case META_SETTEXTCOLOR
:
1640 case META_SETVIEWPORTORG
:
1641 case META_OFFSETWINDOWORG
:
1642 case META_SCALEWINDOWEXT
:
1643 case META_OFFSETVIEWPORTORG
:
1644 case META_SCALEVIEWPORTEXT
:
1647 case META_EXCLUDECLIPRECT
:
1648 case META_INTERSECTCLIPRECT
:
1651 case META_FLOODFILL
:
1653 case META_RECTANGLE
:
1654 case META_ROUNDRECT
:
1658 case META_OFFSETCLIPRGN
:
1660 case META_POLYPOLYGON
:
1662 case META_RESTOREDC
:
1664 case META_CREATEPATTERNBRUSH
:
1665 case META_CREATEPENINDIRECT
:
1666 case META_CREATEFONTINDIRECT
:
1667 case META_CREATEPALETTE
:
1668 case META_SETTEXTALIGN
:
1669 case META_SELECTPALETTE
:
1670 case META_SETMAPPERFLAGS
:
1671 case META_REALIZEPALETTE
:
1673 case META_EXTTEXTOUT
:
1674 case META_STRETCHDIB
:
1675 case META_DIBSTRETCHBLT
:
1676 case META_STRETCHBLT
:
1678 case META_CREATEREGION
:
1679 case META_FILLREGION
:
1680 case META_FRAMEREGION
:
1681 case META_INVERTREGION
:
1682 case META_PAINTREGION
:
1683 case META_SELECTCLIPREGION
:
1684 case META_DIBCREATEPATTERNBRUSH
:
1685 case META_DIBBITBLT
:
1686 case META_SETTEXTCHAREXTRA
:
1687 case META_SETTEXTJUSTIFICATION
:
1688 case META_EXTFLOODFILL
:
1689 case META_SETDIBTODEV
:
1691 case META_ANIMATEPALETTE
:
1692 case META_SETPALENTRIES
:
1693 case META_RESIZEPALETTE
:
1696 case META_STARTPAGE
:
1700 case META_CREATEBRUSH
:
1701 case META_CREATEBITMAPINDIRECT
:
1702 case META_CREATEBITMAP
:
1703 /* Fall through to unimplemented */
1706 /* Not implemented yet */
1707 FIXME( "Conversion of record type 0x%x not implemented.\n", lpMetaRecord
->rdFunction
);
1712 /* Move to the next record */
1713 (char*)lpbBuffer
+= ((LPMETARECORD
)lpbBuffer
)->rdSize
* 2; /* FIXME: Seem to be doing this in metafile.c */
1715 #undef ReAllocAndAdjustPointers
1718 /* We know the last of the header information now */
1719 ((LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
)->nBytes
= uNewEnhMetaFileBufferSize
;
1721 /* Create the enhanced metafile */
1722 hMf
= SetEnhMetaFileBits( uNewEnhMetaFileBufferSize
, (const BYTE
*)lpNewEnhMetaFileBuffer
);
1725 ERR( "Problem creating metafile. Did the conversion fail somewhere?\n" );
1730 /* Free the data associated with our copy since it's been copied */
1731 HeapFree( GetProcessHeap(), 0, lpNewEnhMetaFileBuffer
);