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
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
/* 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
) /* 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
, /* enhanced metafile */
169 UINT bufsize
, /* size of buffer */
170 LPENHMETAHEADER buf
/* 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
, /* enhanced metafile */
195 UINT size
, /* size of buf */
196 LPSTR buf
/* buffer to receive description */
199 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
202 if(!emh
) return FALSE
;
203 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) {
204 EMF_ReleaseEnhMetaHeader(hmf
);
207 if (!buf
|| !size
) {
208 EMF_ReleaseEnhMetaHeader(hmf
);
209 return emh
->nDescription
;
212 first
= lstrlenW( (WCHAR
*) ((char *) emh
+ emh
->offDescription
));
214 lstrcpynWtoA(buf
, (WCHAR
*) ((char *) emh
+ emh
->offDescription
), size
);
215 first_A
= strlen( buf
);
217 lstrcpynWtoA(buf
, (WCHAR
*) ((char *) emh
+ emh
->offDescription
+2*(first
+1)),
218 size
- first_A
- 1); /* i18n ready */
219 first_A
+= strlen(buf
) + 1;
221 EMF_ReleaseEnhMetaHeader(hmf
);
222 return min(size
, first_A
);
225 /*****************************************************************************
226 * GetEnhMetaFileDescriptionW (GDI32.177)
228 * Copies the description string of an enhanced metafile into a buffer
231 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
232 * number of characters copied.
234 UINT WINAPI
GetEnhMetaFileDescriptionW(
235 HENHMETAFILE hmf
, /* enhanced metafile */
236 UINT size
, /* size of buf */
237 LPWSTR buf
/* buffer to receive description */
240 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
242 if(!emh
) return FALSE
;
243 if(emh
->nDescription
== 0 || emh
->offDescription
== 0) {
244 EMF_ReleaseEnhMetaHeader(hmf
);
247 if (!buf
|| !size
) {
248 EMF_ReleaseEnhMetaHeader(hmf
);
249 return emh
->nDescription
;
252 memmove(buf
, (char *) emh
+ emh
->offDescription
,
253 min(size
,emh
->nDescription
));
254 EMF_ReleaseEnhMetaHeader(hmf
);
255 return min(size
, emh
->nDescription
);
258 /****************************************************************************
259 * SetEnhMetaFileBits (GDI32.315)
261 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
263 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
265 ENHMETAHEADER
*emh
= HeapAlloc( GetProcessHeap(), 0, bufsize
);
266 memmove(emh
, buf
, bufsize
);
267 return EMF_Create_HENHMETAFILE( emh
, 0, 0 );
270 /*****************************************************************************
271 * GetEnhMetaFileBits (GDI32.175)
274 UINT WINAPI
GetEnhMetaFileBits(
280 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader( hmf
);
287 EMF_ReleaseEnhMetaHeader( hmf
);
291 size
= min( size
, bufsize
);
292 memmove(buf
, emh
, size
);
294 EMF_ReleaseEnhMetaHeader( hmf
);
298 /*****************************************************************************
299 * PlayEnhMetaFileRecord (GDI32.264)
301 * Render a single enhanced metafile record in the device context hdc.
304 * TRUE (non zero) on success, FALSE on error.
306 * Many unimplemented records.
307 * No error handling on record play failures (ie checking return codes)
309 BOOL WINAPI
PlayEnhMetaFileRecord(
310 HDC hdc
, /* device context in which to render EMF record */
311 LPHANDLETABLE handletable
, /* array of handles to be used in rendering record */
312 const ENHMETARECORD
*mr
, /* EMF record to render */
313 UINT handles
/* size of handle array */
318 "hdc = %08x, handletable = %p, record = %p, numHandles = %d\n",
319 hdc
, handletable
, mr
, handles
);
320 if (!mr
) return FALSE
;
324 TRACE(" type=%d\n", type
);
333 PEMRGDICOMMENT lpGdiComment
= (PEMRGDICOMMENT
)mr
;
334 /* In an enhanced metafile, there can be both public and private GDI comments */
335 GdiComment( hdc
, lpGdiComment
->cbData
, lpGdiComment
->Data
);
340 PEMRSETMAPMODE pSetMapMode
= (PEMRSETMAPMODE
) mr
;
341 SetMapMode(hdc
, pSetMapMode
->iMode
);
346 PEMRSETBKMODE pSetBkMode
= (PEMRSETBKMODE
) mr
;
347 SetBkMode(hdc
, pSetBkMode
->iMode
);
352 PEMRSETBKCOLOR pSetBkColor
= (PEMRSETBKCOLOR
) mr
;
353 SetBkColor(hdc
, pSetBkColor
->crColor
);
356 case EMR_SETPOLYFILLMODE
:
358 PEMRSETPOLYFILLMODE pSetPolyFillMode
= (PEMRSETPOLYFILLMODE
) mr
;
359 SetPolyFillMode(hdc
, pSetPolyFillMode
->iMode
);
364 PEMRSETROP2 pSetROP2
= (PEMRSETROP2
) mr
;
365 SetROP2(hdc
, pSetROP2
->iMode
);
368 case EMR_SETSTRETCHBLTMODE
:
370 PEMRSETSTRETCHBLTMODE pSetStretchBltMode
= (PEMRSETSTRETCHBLTMODE
) mr
;
371 SetStretchBltMode(hdc
, pSetStretchBltMode
->iMode
);
374 case EMR_SETTEXTALIGN
:
376 PEMRSETTEXTALIGN pSetTextAlign
= (PEMRSETTEXTALIGN
) mr
;
377 SetTextAlign(hdc
, pSetTextAlign
->iMode
);
380 case EMR_SETTEXTCOLOR
:
382 PEMRSETTEXTCOLOR pSetTextColor
= (PEMRSETTEXTCOLOR
) mr
;
383 SetTextColor(hdc
, pSetTextColor
->crColor
);
393 PEMRRESTOREDC pRestoreDC
= (PEMRRESTOREDC
) mr
;
394 RestoreDC(hdc
, pRestoreDC
->iRelative
);
397 case EMR_INTERSECTCLIPRECT
:
399 PEMRINTERSECTCLIPRECT pClipRect
= (PEMRINTERSECTCLIPRECT
) mr
;
400 IntersectClipRect(hdc
, pClipRect
->rclClip
.left
, pClipRect
->rclClip
.top
,
401 pClipRect
->rclClip
.right
, pClipRect
->rclClip
.bottom
);
404 case EMR_SELECTOBJECT
:
406 PEMRSELECTOBJECT pSelectObject
= (PEMRSELECTOBJECT
) mr
;
407 if( pSelectObject
->ihObject
& 0x80000000 ) {
408 /* High order bit is set - it's a stock object
409 * Strip the high bit to get the index.
410 * See MSDN article Q142319
412 SelectObject( hdc
, GetStockObject( pSelectObject
->ihObject
&
415 /* High order bit wasn't set - not a stock object
418 (handletable
->objectHandle
)[pSelectObject
->ihObject
] );
422 case EMR_DELETEOBJECT
:
424 PEMRDELETEOBJECT pDeleteObject
= (PEMRDELETEOBJECT
) mr
;
425 DeleteObject( (handletable
->objectHandle
)[pDeleteObject
->ihObject
]);
426 (handletable
->objectHandle
)[pDeleteObject
->ihObject
] = 0;
429 case EMR_SETWINDOWORGEX
:
431 PEMRSETWINDOWORGEX pSetWindowOrgEx
= (PEMRSETWINDOWORGEX
) mr
;
432 SetWindowOrgEx(hdc
, pSetWindowOrgEx
->ptlOrigin
.x
,
433 pSetWindowOrgEx
->ptlOrigin
.y
, NULL
);
436 case EMR_SETWINDOWEXTEX
:
438 PEMRSETWINDOWEXTEX pSetWindowExtEx
= (PEMRSETWINDOWEXTEX
) mr
;
439 SetWindowExtEx(hdc
, pSetWindowExtEx
->szlExtent
.cx
,
440 pSetWindowExtEx
->szlExtent
.cy
, NULL
);
443 case EMR_SETVIEWPORTORGEX
:
445 PEMRSETVIEWPORTORGEX pSetViewportOrgEx
= (PEMRSETVIEWPORTORGEX
) mr
;
446 SetViewportOrgEx(hdc
, pSetViewportOrgEx
->ptlOrigin
.x
,
447 pSetViewportOrgEx
->ptlOrigin
.y
, NULL
);
450 case EMR_SETVIEWPORTEXTEX
:
452 PEMRSETVIEWPORTEXTEX pSetViewportExtEx
= (PEMRSETVIEWPORTEXTEX
) mr
;
453 SetViewportExtEx(hdc
, pSetViewportExtEx
->szlExtent
.cx
,
454 pSetViewportExtEx
->szlExtent
.cy
, NULL
);
459 PEMRCREATEPEN pCreatePen
= (PEMRCREATEPEN
) mr
;
460 (handletable
->objectHandle
)[pCreatePen
->ihPen
] =
461 CreatePenIndirect(&pCreatePen
->lopn
);
464 case EMR_EXTCREATEPEN
:
466 PEMREXTCREATEPEN pPen
= (PEMREXTCREATEPEN
) mr
;
468 lb
.lbStyle
= pPen
->elp
.elpBrushStyle
;
469 lb
.lbColor
= pPen
->elp
.elpColor
;
470 lb
.lbHatch
= pPen
->elp
.elpHatch
;
472 if(pPen
->offBmi
|| pPen
->offBits
)
473 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
475 (handletable
->objectHandle
)[pPen
->ihPen
] =
476 ExtCreatePen(pPen
->elp
.elpPenStyle
, pPen
->elp
.elpWidth
, &lb
,
477 pPen
->elp
.elpNumEntries
, pPen
->elp
.elpStyleEntry
);
480 case EMR_CREATEBRUSHINDIRECT
:
482 PEMRCREATEBRUSHINDIRECT pBrush
= (PEMRCREATEBRUSHINDIRECT
) mr
;
483 (handletable
->objectHandle
)[pBrush
->ihBrush
] =
484 CreateBrushIndirect(&pBrush
->lb
);
487 case EMR_EXTCREATEFONTINDIRECTW
:
489 PEMREXTCREATEFONTINDIRECTW pFont
= (PEMREXTCREATEFONTINDIRECTW
) mr
;
490 (handletable
->objectHandle
)[pFont
->ihFont
] =
491 CreateFontIndirectW(&pFont
->elfw
.elfLogFont
);
496 PEMRMOVETOEX pMoveToEx
= (PEMRMOVETOEX
) mr
;
497 MoveToEx(hdc
, pMoveToEx
->ptl
.x
, pMoveToEx
->ptl
.y
, NULL
);
502 PEMRLINETO pLineTo
= (PEMRLINETO
) mr
;
503 LineTo(hdc
, pLineTo
->ptl
.x
, pLineTo
->ptl
.y
);
508 PEMRRECTANGLE pRect
= (PEMRRECTANGLE
) mr
;
509 Rectangle(hdc
, pRect
->rclBox
.left
, pRect
->rclBox
.top
,
510 pRect
->rclBox
.right
, pRect
->rclBox
.bottom
);
515 PEMRELLIPSE pEllipse
= (PEMRELLIPSE
) mr
;
516 Ellipse(hdc
, pEllipse
->rclBox
.left
, pEllipse
->rclBox
.top
,
517 pEllipse
->rclBox
.right
, pEllipse
->rclBox
.bottom
);
522 PEMRPOLYGON16 pPoly
= (PEMRPOLYGON16
) mr
;
523 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
524 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
525 pPoly
->cpts
* sizeof(POINT
) );
527 for(i
= 0; i
< pPoly
->cpts
; i
++)
528 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
529 Polygon(hdc
, pts
, pPoly
->cpts
);
530 HeapFree( GetProcessHeap(), 0, pts
);
535 PEMRPOLYLINE16 pPoly
= (PEMRPOLYLINE16
) mr
;
536 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
537 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
538 pPoly
->cpts
* sizeof(POINT
) );
540 for(i
= 0; i
< pPoly
->cpts
; i
++)
541 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
542 Polyline(hdc
, pts
, pPoly
->cpts
);
543 HeapFree( GetProcessHeap(), 0, pts
);
546 case EMR_POLYLINETO16
:
548 PEMRPOLYLINETO16 pPoly
= (PEMRPOLYLINETO16
) mr
;
549 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
550 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
551 pPoly
->cpts
* sizeof(POINT
) );
553 for(i
= 0; i
< pPoly
->cpts
; i
++)
554 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
555 PolylineTo(hdc
, pts
, pPoly
->cpts
);
556 HeapFree( GetProcessHeap(), 0, pts
);
559 case EMR_POLYBEZIER16
:
561 PEMRPOLYBEZIER16 pPoly
= (PEMRPOLYBEZIER16
) mr
;
562 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
563 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
564 pPoly
->cpts
* sizeof(POINT
) );
566 for(i
= 0; i
< pPoly
->cpts
; i
++)
567 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
568 PolyBezier(hdc
, pts
, pPoly
->cpts
);
569 HeapFree( GetProcessHeap(), 0, pts
);
572 case EMR_POLYBEZIERTO16
:
574 PEMRPOLYBEZIERTO16 pPoly
= (PEMRPOLYBEZIERTO16
) mr
;
575 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
576 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
577 pPoly
->cpts
* sizeof(POINT
) );
579 for(i
= 0; i
< pPoly
->cpts
; i
++)
580 CONV_POINT16TO32(pPoly
->apts
+ i
, pts
+ i
);
581 PolyBezierTo(hdc
, pts
, pPoly
->cpts
);
582 HeapFree( GetProcessHeap(), 0, pts
);
585 case EMR_POLYPOLYGON16
:
587 PEMRPOLYPOLYGON16 pPolyPoly
= (PEMRPOLYPOLYGON16
) mr
;
588 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
589 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
591 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
592 pPolyPoly
->cpts
* sizeof(POINT
) );
594 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
595 CONV_POINT16TO32((POINTS
*) (pPolyPoly
->aPolyCounts
+
596 pPolyPoly
->nPolys
) + i
, pts
+ i
);
598 PolyPolygon(hdc
, pts
, (INT
*)pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
599 HeapFree( GetProcessHeap(), 0, pts
);
602 case EMR_POLYPOLYLINE16
:
604 PEMRPOLYPOLYLINE16 pPolyPoly
= (PEMRPOLYPOLYLINE16
) mr
;
605 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
606 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
608 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
609 pPolyPoly
->cpts
* sizeof(POINT
) );
611 for(i
= 0; i
< pPolyPoly
->cpts
; i
++)
612 CONV_POINT16TO32((POINTS
*) (pPolyPoly
->aPolyCounts
+
613 pPolyPoly
->nPolys
) + i
, pts
+ i
);
615 PolyPolyline(hdc
, pts
, pPolyPoly
->aPolyCounts
, pPolyPoly
->nPolys
);
616 HeapFree( GetProcessHeap(), 0, pts
);
620 case EMR_STRETCHDIBITS
:
622 LONG xDest
= mr
->dParm
[4];
623 LONG yDest
= mr
->dParm
[5];
624 LONG xSrc
= mr
->dParm
[6];
625 LONG ySrc
= mr
->dParm
[7];
626 LONG cxSrc
= mr
->dParm
[8];
627 LONG cySrc
= mr
->dParm
[9];
628 DWORD offBmiSrc
= mr
->dParm
[10];
629 DWORD offBitsSrc
= mr
->dParm
[12];
630 DWORD iUsageSrc
= mr
->dParm
[14];
631 DWORD dwRop
= mr
->dParm
[15];
632 LONG cxDest
= mr
->dParm
[16];
633 LONG cyDest
= mr
->dParm
[17];
635 StretchDIBits(hdc
,xDest
,yDest
,cxDest
,cyDest
,
636 xSrc
,ySrc
,cxSrc
,cySrc
,
637 ((char *)mr
)+offBitsSrc
,
638 (const BITMAPINFO
*)(((char *)mr
)+offBmiSrc
),
642 case EMR_EXTTEXTOUTW
:
645 DWORD flags
= mr
->dParm
[4];
647 DWORD x
= mr
->dParm
[7], y
= mr
->dParm
[8];
648 DWORD count
= mr
->dParm
[9];
650 LPWSTR str
= (LPWSTR
)& mr
->dParm
[17];
651 /* trailing info: dx array? */
652 FIXME("Many ExtTextOut args not handled\n");
653 ExtTextOutW(hdc
, x
, y
, flags
, /* lpRect */ NULL
,
654 str
, count
, /* lpDx */ NULL
);
658 case EMR_CREATEPALETTE
:
660 PEMRCREATEPALETTE lpCreatePal
= (PEMRCREATEPALETTE
)mr
;
662 (handletable
->objectHandle
)[ lpCreatePal
->ihPal
] =
663 CreatePalette( &lpCreatePal
->lgpl
);
668 case EMR_SELECTPALETTE
:
670 PEMRSELECTPALETTE lpSelectPal
= (PEMRSELECTPALETTE
)mr
;
672 /* FIXME: Should this be forcing background mode? */
673 (handletable
->objectHandle
)[ lpSelectPal
->ihPal
] =
674 SelectPalette( hdc
, lpSelectPal
->ihPal
, FALSE
);
678 case EMR_REALIZEPALETTE
:
680 RealizePalette( hdc
);
685 case EMR_EXTSELECTCLIPRGN
:
687 PEMREXTSELECTCLIPRGN lpRgn
= (PEMREXTSELECTCLIPRGN
)mr
;
689 /* Need to make a region out of the RGNDATA we have */
690 ExtSelectClipRgn( hdc
, ..., (INT
)(lpRgn
->iMode
) );
701 case EMR_SETWORLDTRANSFORM
:
703 PEMRSETWORLDTRANSFORM lpXfrm
= (PEMRSETWORLDTRANSFORM
)mr
;
705 SetWorldTransform( hdc
, &lpXfrm
->xform
);
712 PEMRPOLYBEZIER lpPolyBez
= (PEMRPOLYBEZIER
)mr
;
713 PolyBezier(hdc
, (const LPPOINT
)lpPolyBez
->aptl
, (UINT
)lpPolyBez
->cptl
);
719 PEMRPOLYGON lpPoly
= (PEMRPOLYGON
)mr
;
720 Polygon( hdc
, (const LPPOINT
)lpPoly
->aptl
, (UINT
)lpPoly
->cptl
);
726 PEMRPOLYLINE lpPolyLine
= (PEMRPOLYLINE
)mr
;
727 Polyline(hdc
, (const LPPOINT
)lpPolyLine
->aptl
, (UINT
)lpPolyLine
->cptl
);
731 case EMR_POLYBEZIERTO
:
733 PEMRPOLYBEZIERTO lpPolyBezierTo
= (PEMRPOLYBEZIERTO
)mr
;
734 PolyBezierTo( hdc
, (const LPPOINT
)lpPolyBezierTo
->aptl
,
735 (UINT
)lpPolyBezierTo
->cptl
);
741 PEMRPOLYLINETO lpPolyLineTo
= (PEMRPOLYLINETO
)mr
;
742 PolylineTo( hdc
, (const LPPOINT
)lpPolyLineTo
->aptl
,
743 (UINT
)lpPolyLineTo
->cptl
);
747 case EMR_POLYPOLYLINE
:
749 PEMRPOLYPOLYLINE pPolyPolyline
= (PEMRPOLYPOLYLINE
) mr
;
750 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
752 PolyPolyline(hdc
, (LPPOINT
)(pPolyPolyline
->aPolyCounts
+
753 pPolyPolyline
->nPolys
),
754 pPolyPolyline
->aPolyCounts
,
755 pPolyPolyline
->nPolys
);
760 case EMR_POLYPOLYGON
:
762 PEMRPOLYPOLYGON pPolyPolygon
= (PEMRPOLYPOLYGON
) mr
;
764 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
766 PolyPolygon(hdc
, (LPPOINT
)(pPolyPolygon
->aPolyCounts
+
767 pPolyPolygon
->nPolys
),
768 (INT
*)pPolyPolygon
->aPolyCounts
, pPolyPolygon
->nPolys
);
772 case EMR_SETBRUSHORGEX
:
774 PEMRSETBRUSHORGEX lpSetBrushOrgEx
= (PEMRSETBRUSHORGEX
)mr
;
777 (INT
)lpSetBrushOrgEx
->ptlOrigin
.x
,
778 (INT
)lpSetBrushOrgEx
->ptlOrigin
.y
,
786 PEMRSETPIXELV lpSetPixelV
= (PEMRSETPIXELV
)mr
;
789 (INT
)lpSetPixelV
->ptlPixel
.x
,
790 (INT
)lpSetPixelV
->ptlPixel
.y
,
791 lpSetPixelV
->crColor
);
796 case EMR_SETMAPPERFLAGS
:
798 PEMRSETMAPPERFLAGS lpSetMapperFlags
= (PEMRSETMAPPERFLAGS
)mr
;
800 SetMapperFlags( hdc
, lpSetMapperFlags
->dwFlags
);
805 case EMR_SETCOLORADJUSTMENT
:
807 PEMRSETCOLORADJUSTMENT lpSetColorAdjust
= (PEMRSETCOLORADJUSTMENT
)mr
;
809 SetColorAdjustment( hdc
, &lpSetColorAdjust
->ColorAdjustment
);
814 case EMR_OFFSETCLIPRGN
:
816 PEMROFFSETCLIPRGN lpOffsetClipRgn
= (PEMROFFSETCLIPRGN
)mr
;
819 (INT
)lpOffsetClipRgn
->ptlOffset
.x
,
820 (INT
)lpOffsetClipRgn
->ptlOffset
.y
);
825 case EMR_EXCLUDECLIPRECT
:
827 PEMREXCLUDECLIPRECT lpExcludeClipRect
= (PEMREXCLUDECLIPRECT
)mr
;
829 ExcludeClipRect( hdc
,
830 lpExcludeClipRect
->rclClip
.left
,
831 lpExcludeClipRect
->rclClip
.top
,
832 lpExcludeClipRect
->rclClip
.right
,
833 lpExcludeClipRect
->rclClip
.bottom
);
838 case EMR_SCALEVIEWPORTEXTEX
:
840 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx
= (PEMRSCALEVIEWPORTEXTEX
)mr
;
842 ScaleViewportExtEx( hdc
,
843 lpScaleViewportExtEx
->xNum
,
844 lpScaleViewportExtEx
->xDenom
,
845 lpScaleViewportExtEx
->yNum
,
846 lpScaleViewportExtEx
->yDenom
,
852 case EMR_SCALEWINDOWEXTEX
:
854 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx
= (PEMRSCALEWINDOWEXTEX
)mr
;
856 ScaleWindowExtEx( hdc
,
857 lpScaleWindowExtEx
->xNum
,
858 lpScaleWindowExtEx
->xDenom
,
859 lpScaleWindowExtEx
->yNum
,
860 lpScaleWindowExtEx
->yDenom
,
866 case EMR_MODIFYWORLDTRANSFORM
:
868 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans
= (PEMRMODIFYWORLDTRANSFORM
)mr
;
870 ModifyWorldTransform( hdc
, &lpModifyWorldTrans
->xform
,
871 lpModifyWorldTrans
->iMode
);
878 PEMRANGLEARC lpAngleArc
= (PEMRANGLEARC
)mr
;
881 (INT
)lpAngleArc
->ptlCenter
.x
, (INT
)lpAngleArc
->ptlCenter
.y
,
882 lpAngleArc
->nRadius
, lpAngleArc
->eStartAngle
,
883 lpAngleArc
->eSweepAngle
);
890 PEMRROUNDRECT lpRoundRect
= (PEMRROUNDRECT
)mr
;
893 lpRoundRect
->rclBox
.left
,
894 lpRoundRect
->rclBox
.top
,
895 lpRoundRect
->rclBox
.right
,
896 lpRoundRect
->rclBox
.bottom
,
897 lpRoundRect
->szlCorner
.cx
,
898 lpRoundRect
->szlCorner
.cy
);
905 PEMRARC lpArc
= (PEMRARC
)mr
;
908 (INT
)lpArc
->rclBox
.left
,
909 (INT
)lpArc
->rclBox
.top
,
910 (INT
)lpArc
->rclBox
.right
,
911 (INT
)lpArc
->rclBox
.bottom
,
912 (INT
)lpArc
->ptlStart
.x
,
913 (INT
)lpArc
->ptlStart
.y
,
914 (INT
)lpArc
->ptlEnd
.x
,
915 (INT
)lpArc
->ptlEnd
.y
);
922 PEMRCHORD lpChord
= (PEMRCHORD
)mr
;
925 (INT
)lpChord
->rclBox
.left
,
926 (INT
)lpChord
->rclBox
.top
,
927 (INT
)lpChord
->rclBox
.right
,
928 (INT
)lpChord
->rclBox
.bottom
,
929 (INT
)lpChord
->ptlStart
.x
,
930 (INT
)lpChord
->ptlStart
.y
,
931 (INT
)lpChord
->ptlEnd
.x
,
932 (INT
)lpChord
->ptlEnd
.y
);
939 PEMRPIE lpPie
= (PEMRPIE
)mr
;
942 (INT
)lpPie
->rclBox
.left
,
943 (INT
)lpPie
->rclBox
.top
,
944 (INT
)lpPie
->rclBox
.right
,
945 (INT
)lpPie
->rclBox
.bottom
,
946 (INT
)lpPie
->ptlStart
.x
,
947 (INT
)lpPie
->ptlStart
.y
,
948 (INT
)lpPie
->ptlEnd
.x
,
949 (INT
)lpPie
->ptlEnd
.y
);
956 PEMRARC lpArcTo
= (PEMRARC
)mr
;
959 (INT
)lpArcTo
->rclBox
.left
,
960 (INT
)lpArcTo
->rclBox
.top
,
961 (INT
)lpArcTo
->rclBox
.right
,
962 (INT
)lpArcTo
->rclBox
.bottom
,
963 (INT
)lpArcTo
->ptlStart
.x
,
964 (INT
)lpArcTo
->ptlStart
.y
,
965 (INT
)lpArcTo
->ptlEnd
.x
,
966 (INT
)lpArcTo
->ptlEnd
.y
);
971 case EMR_EXTFLOODFILL
:
973 PEMREXTFLOODFILL lpExtFloodFill
= (PEMREXTFLOODFILL
)mr
;
976 (INT
)lpExtFloodFill
->ptlStart
.x
,
977 (INT
)lpExtFloodFill
->ptlStart
.y
,
978 lpExtFloodFill
->crColor
,
979 (UINT
)lpExtFloodFill
->iMode
);
986 PEMRPOLYDRAW lpPolyDraw
= (PEMRPOLYDRAW
)mr
;
988 (const LPPOINT
)lpPolyDraw
->aptl
,
990 (INT
)lpPolyDraw
->cptl
);
995 case EMR_SETARCDIRECTION
:
997 PEMRSETARCDIRECTION lpSetArcDirection
= (PEMRSETARCDIRECTION
)mr
;
998 SetArcDirection( hdc
, (INT
)lpSetArcDirection
->iArcDirection
);
1002 case EMR_SETMITERLIMIT
:
1004 PEMRSETMITERLIMIT lpSetMiterLimit
= (PEMRSETMITERLIMIT
)mr
;
1005 SetMiterLimit( hdc
, lpSetMiterLimit
->eMiterLimit
, NULL
);
1021 case EMR_CLOSEFIGURE
:
1029 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1034 case EMR_STROKEANDFILLPATH
:
1036 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1037 StrokeAndFillPath( hdc
);
1041 case EMR_STROKEPATH
:
1043 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1048 case EMR_FLATTENPATH
:
1060 case EMR_SELECTCLIPPATH
:
1062 PEMRSELECTCLIPPATH lpSelectClipPath
= (PEMRSELECTCLIPPATH
)mr
;
1063 SelectClipPath( hdc
, (INT
)lpSelectClipPath
->iMode
);
1073 case EMR_CREATECOLORSPACE
:
1075 PEMRCREATECOLORSPACE lpCreateColorSpace
= (PEMRCREATECOLORSPACE
)mr
;
1076 (handletable
->objectHandle
)[lpCreateColorSpace
->ihCS
] =
1077 CreateColorSpaceA( &lpCreateColorSpace
->lcs
);
1081 case EMR_SETCOLORSPACE
:
1083 PEMRSETCOLORSPACE lpSetColorSpace
= (PEMRSETCOLORSPACE
)mr
;
1085 (handletable
->objectHandle
)[lpSetColorSpace
->ihCS
] );
1089 case EMR_DELETECOLORSPACE
:
1091 PEMRDELETECOLORSPACE lpDeleteColorSpace
= (PEMRDELETECOLORSPACE
)mr
;
1092 DeleteColorSpace( (handletable
->objectHandle
)[lpDeleteColorSpace
->ihCS
] );
1096 case EMR_SETICMMODE
:
1098 PERMSETICMMODE lpSetICMMode
= (PERMSETICMMODE
)mr
;
1099 SetICMMode( hdc
, (INT
)lpSetICMMode
->iMode
);
1103 case EMR_PIXELFORMAT
:
1106 PEMRPIXELFORMAT lpPixelFormat
= (PEMRPIXELFORMAT
)mr
;
1108 iPixelFormat
= ChoosePixelFormat( hdc
, &lpPixelFormat
->pfd
);
1109 SetPixelFormat( hdc
, iPixelFormat
, &lpPixelFormat
->pfd
);
1114 case EMR_SETPALETTEENTRIES
:
1116 PEMRSETPALETTEENTRIES lpSetPaletteEntries
= (PEMRSETPALETTEENTRIES
)mr
;
1118 SetPaletteEntries( (handletable
->objectHandle
)[lpSetPaletteEntries
->ihPal
],
1119 (UINT
)lpSetPaletteEntries
->iStart
,
1120 (UINT
)lpSetPaletteEntries
->cEntries
,
1121 lpSetPaletteEntries
->aPalEntries
);
1126 case EMR_RESIZEPALETTE
:
1128 PEMRRESIZEPALETTE lpResizePalette
= (PEMRRESIZEPALETTE
)mr
;
1130 ResizePalette( (handletable
->objectHandle
)[lpResizePalette
->ihPal
],
1131 (UINT
)lpResizePalette
->cEntries
);
1136 case EMR_CREATEDIBPATTERNBRUSHPT
:
1138 PEMRCREATEDIBPATTERNBRUSHPT lpCreate
= (PEMRCREATEDIBPATTERNBRUSHPT
)mr
;
1140 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1141 LPVOID lpPackedStruct
= HeapAlloc( GetProcessHeap(),
1143 lpCreate
->cbBmi
+ lpCreate
->cbBits
);
1144 /* Now pack this structure */
1145 memcpy( lpPackedStruct
,
1146 ((BYTE
*)lpCreate
) + lpCreate
->offBmi
,
1148 memcpy( ((BYTE
*)lpPackedStruct
) + lpCreate
->cbBmi
,
1149 ((BYTE
*)lpCreate
) + lpCreate
->offBits
,
1152 (handletable
->objectHandle
)[lpCreate
->ihBrush
] =
1153 CreateDIBPatternBrushPt( lpPackedStruct
,
1154 (UINT
)lpCreate
->iUsage
);
1160 case EMR_STRETCHBLT
:
1163 case EMR_SETDIBITSTODEVICE
:
1164 case EMR_EXTTEXTOUTA
:
1165 case EMR_POLYDRAW16
:
1166 case EMR_CREATEMONOBRUSH
:
1167 case EMR_POLYTEXTOUTA
:
1168 case EMR_POLYTEXTOUTW
:
1174 case EMR_GLSBOUNDEDRECORD
:
1176 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1177 record then ignore and return TRUE. */
1178 FIXME("type %d is unimplemented\n", type
);
1185 /*****************************************************************************
1187 * EnumEnhMetaFile (GDI32.79)
1189 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1191 * record. Returns when either every record has been used or
1192 * when _EnhMetaFunc_ returns FALSE.
1196 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1202 BOOL WINAPI
EnumEnhMetaFile(
1203 HDC hdc
, /* device context to pass to _EnhMetaFunc_ */
1204 HENHMETAFILE hmf
, /* EMF to walk */
1205 ENHMFENUMPROC callback
, /* callback function */
1206 LPVOID data
, /* optional data for callback function */
1207 const RECT
*lpRect
/* bounding rectangle for rendered metafile */
1211 LPENHMETAHEADER emh
= EMF_GetEnhMetaHeader(hmf
);
1215 FLOAT xSrcPixSize
, ySrcPixSize
, xscale
, yscale
;
1216 XFORM savedXform
, xform
;
1219 SetLastError(ERROR_INVALID_HANDLE
);
1223 SetLastError(ERROR_INVALID_PARAMETER
);
1226 count
= emh
->nHandles
;
1227 ht
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1228 sizeof(HANDLETABLE
) * count
);
1229 ht
->objectHandle
[0] = hmf
;
1231 xSrcPixSize
= (FLOAT
) emh
->szlMillimeters
.cx
/ emh
->szlDevice
.cx
;
1232 ySrcPixSize
= (FLOAT
) emh
->szlMillimeters
.cy
/ emh
->szlDevice
.cy
;
1233 xscale
= (FLOAT
)(lpRect
->right
- lpRect
->left
) * 100.0 /
1234 (emh
->rclFrame
.right
- emh
->rclFrame
.left
) * xSrcPixSize
;
1235 yscale
= (FLOAT
)(lpRect
->bottom
- lpRect
->top
) * 100.0 /
1236 (emh
->rclFrame
.bottom
- emh
->rclFrame
.top
) * ySrcPixSize
;
1238 xform
.eM11
= xscale
;
1241 xform
.eM22
= yscale
;
1242 if(emh
->rclFrame
.left
|| emh
->rclFrame
.top
)
1243 FIXME("Can't cope with nonzero rclFrame origin yet\n");
1244 /* eDx = lpRect->left - (lpRect width) / (rclFrame width) * rclFrame.left ? */
1245 xform
.eDx
= lpRect
->left
;
1246 xform
.eDy
= lpRect
->top
;
1247 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
1248 GetWorldTransform(hdc
, &savedXform
);
1249 if (!ModifyWorldTransform(hdc
, &xform
, MWT_LEFTMULTIPLY
)) {
1250 ERR("World transform failed!\n");
1254 ret
= (*callback
)(hdc
, ht
, (LPENHMETARECORD
) emh
, count
, data
);
1255 if (emh
->iType
== EMR_EOF
) break;
1256 emh
= (LPENHMETAHEADER
) ((char *) emh
+ emh
->nSize
);
1258 for(i
= 1; i
< count
; i
++) /* Don't delete element 0 (hmf) */
1259 if( (ht
->objectHandle
)[i
] )
1260 DeleteObject( (ht
->objectHandle
)[i
] );
1261 HeapFree( GetProcessHeap(), 0, ht
);
1262 EMF_ReleaseEnhMetaHeader(hmf
);
1263 SetWorldTransform(hdc
, &savedXform
);
1264 if (savedMode
) SetGraphicsMode(hdc
, savedMode
);
1268 static INT CALLBACK
EMF_PlayEnhMetaFileCallback(HDC hdc
, HANDLETABLE
*ht
,
1270 INT handles
, LPVOID data
)
1272 return PlayEnhMetaFileRecord(hdc
, ht
, emr
, handles
);
1275 /**************************************************************************
1276 * PlayEnhMetaFile (GDI32.263)
1278 * Renders an enhanced metafile into a specified rectangle *lpRect
1279 * in device context hdc.
1282 BOOL WINAPI
PlayEnhMetaFile(
1283 HDC hdc
, /* DC to render into */
1284 HENHMETAFILE hmf
, /* metafile to render */
1285 const RECT
*lpRect
/* rectangle to place metafile inside */
1288 return EnumEnhMetaFile(hdc
, hmf
, EMF_PlayEnhMetaFileCallback
, NULL
,
1292 /*****************************************************************************
1293 * DeleteEnhMetaFile (GDI32.68)
1295 * Deletes an enhanced metafile and frees the associated storage.
1297 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
)
1299 return EMF_Delete_HENHMETAFILE( hmf
);
1302 /*****************************************************************************
1303 * CopyEnhMetaFileA (GDI32.21) Duplicate an enhanced metafile
1307 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
1308 HENHMETAFILE hmfSrc
,
1311 ENHMETAHEADER
*emrSrc
= EMF_GetEnhMetaHeader( hmfSrc
), *emrDst
;
1312 HENHMETAFILE hmfDst
;
1314 if(!emrSrc
) return FALSE
;
1316 emrDst
= HeapAlloc( GetProcessHeap(), 0, emrSrc
->nBytes
);
1317 memcpy( emrDst
, emrSrc
, emrSrc
->nBytes
);
1318 hmfDst
= EMF_Create_HENHMETAFILE( emrDst
, 0, 0 );
1321 hFile
= CreateFileA( file
, GENERIC_WRITE
| GENERIC_READ
, 0, NULL
,
1322 CREATE_ALWAYS
, 0, -1);
1323 WriteFile( hFile
, emrSrc
, emrSrc
->nBytes
, 0, 0);
1324 hmfDst
= EMF_GetEnhMetaFile( hFile
);
1326 EMF_ReleaseEnhMetaHeader( hmfSrc
);
1331 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1332 typedef struct tagEMF_PaletteCopy
1335 LPPALETTEENTRY lpPe
;
1338 /***************************************************************
1339 * Find the EMR_EOF record and then use it to find the
1340 * palette entries for this enhanced metafile.
1341 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1342 * which contains the max number of elements to copy and where
1345 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1347 INT CALLBACK
cbEnhPaletteCopy( HDC a
,
1349 LPENHMETARECORD lpEMR
,
1354 if ( lpEMR
->iType
== EMR_EOF
)
1356 PEMREOF lpEof
= (PEMREOF
)lpEMR
;
1357 EMF_PaletteCopy
* info
= (EMF_PaletteCopy
*)lpData
;
1358 DWORD dwNumPalToCopy
= min( lpEof
->nPalEntries
, info
->cEntries
);
1360 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy
);
1362 memcpy( (LPVOID
)info
->lpPe
,
1363 (LPVOID
)(((LPSTR
)lpEof
) + lpEof
->offPalEntries
),
1364 sizeof( *(info
->lpPe
) ) * dwNumPalToCopy
);
1366 /* Update the passed data as a return code */
1367 info
->lpPe
= NULL
; /* Palettes were copied! */
1368 info
->cEntries
= (UINT
)dwNumPalToCopy
;
1370 return FALSE
; /* That's all we need */
1376 /*****************************************************************************
1377 * GetEnhMetaFilePaletteEntries (GDI32.179)
1379 * Copy the palette and report size
1381 * BUGS: Error codes (SetLastError) are not set on failures
1383 UINT WINAPI
GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf
,
1385 LPPALETTEENTRY lpPe
)
1387 ENHMETAHEADER
* enhHeader
= EMF_GetEnhMetaHeader( hEmf
);
1388 UINT uReturnValue
= GDI_ERROR
;
1389 EMF_PaletteCopy infoForCallBack
;
1391 TRACE( "(%04x,%d,%p)\n", hEmf
, cEntries
, lpPe
);
1393 /* First check if there are any palettes associated with
1395 if ( enhHeader
->nPalEntries
== 0 )
1397 /* No palette associated with this enhanced metafile */
1402 /* Is the user requesting the number of palettes? */
1405 uReturnValue
= (UINT
)enhHeader
->nPalEntries
;
1409 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1410 infoForCallBack
.cEntries
= cEntries
;
1411 infoForCallBack
.lpPe
= lpPe
;
1413 if ( !EnumEnhMetaFile( 0, hEmf
, cbEnhPaletteCopy
,
1414 &infoForCallBack
, NULL
) )
1419 /* Verify that the callback executed correctly */
1420 if ( infoForCallBack
.lpPe
!= NULL
)
1422 /* Callback proc had error! */
1423 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1427 uReturnValue
= infoForCallBack
.cEntries
;
1431 EMF_ReleaseEnhMetaHeader( hEmf
);
1433 return uReturnValue
;
1436 /******************************************************************
1437 * SetWinMetaFileBits (GDI32.343)
1439 * Translate from old style to new style.
1441 * BUGS: - This doesn't take the DC and scaling into account
1442 * - Most record conversions aren't implemented
1443 * - Handle slot assignement is primative and most likely doesn't work
1445 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
,
1446 CONST BYTE
*lpbBuffer
,
1448 CONST METAFILEPICT
*lpmfp
1452 LPVOID lpNewEnhMetaFileBuffer
= NULL
;
1453 UINT uNewEnhMetaFileBufferSize
= 0;
1454 BOOL bFoundEOF
= FALSE
;
1456 FIXME( "(%d,%p,%04x,%p):stub\n", cbBuffer
, lpbBuffer
, hdcRef
, lpmfp
);
1458 /* 1. Get the header - skip over this and get straight to the records */
1460 uNewEnhMetaFileBufferSize
= sizeof( ENHMETAHEADER
);
1461 lpNewEnhMetaFileBuffer
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1462 uNewEnhMetaFileBufferSize
);
1464 if( lpNewEnhMetaFileBuffer
== NULL
)
1469 /* Fill in the header record */
1471 LPENHMETAHEADER lpNewEnhMetaFileHeader
= (LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
;
1473 lpNewEnhMetaFileHeader
->iType
= EMR_HEADER
;
1474 lpNewEnhMetaFileHeader
->nSize
= sizeof( ENHMETAHEADER
);
1476 /* FIXME: Not right. Must be able to get this from the DC */
1477 lpNewEnhMetaFileHeader
->rclBounds
.left
= 0;
1478 lpNewEnhMetaFileHeader
->rclBounds
.right
= 0;
1479 lpNewEnhMetaFileHeader
->rclBounds
.top
= 0;
1480 lpNewEnhMetaFileHeader
->rclBounds
.bottom
= 0;
1482 /* FIXME: Not right. Must be able to get this from the DC */
1483 lpNewEnhMetaFileHeader
->rclFrame
.left
= 0;
1484 lpNewEnhMetaFileHeader
->rclFrame
.right
= 0;
1485 lpNewEnhMetaFileHeader
->rclFrame
.top
= 0;
1486 lpNewEnhMetaFileHeader
->rclFrame
.bottom
= 0;
1488 lpNewEnhMetaFileHeader
->nHandles
= 0; /* No handles yet */
1490 /* FIXME: Add in the rest of the fields to the header */
1505 (char*)lpbBuffer
+= ((METAHEADER
*)lpbBuffer
)->mtHeaderSize
* 2; /* Point past the header - FIXME: metafile quirk? */
1507 /* 2. Enum over individual records and convert them to the new type of records */
1511 LPMETARECORD lpMetaRecord
= (LPMETARECORD
)lpbBuffer
;
1513 #define EMF_ReAllocAndAdjustPointers( a , b ) \
1516 lpTmp = HeapReAlloc( GetProcessHeap(), 0, \
1517 lpNewEnhMetaFileBuffer, \
1518 uNewEnhMetaFileBufferSize + (b) ); \
1519 if( lpTmp == NULL ) { ERR( "No memory!\n" ); goto error; } \
1520 lpNewEnhMetaFileBuffer = lpTmp; \
1521 lpRecord = (a)( (char*)lpNewEnhMetaFileBuffer + uNewEnhMetaFileBufferSize ); \
1522 uNewEnhMetaFileBufferSize += (b); \
1525 switch( lpMetaRecord
->rdFunction
)
1530 size_t uRecord
= sizeof(*lpRecord
);
1532 EMF_ReAllocAndAdjustPointers(PEMREOF
,uRecord
);
1534 /* Fill the new record - FIXME: This is not right */
1535 lpRecord
->emr
.iType
= EMR_EOF
;
1536 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1537 lpRecord
->nPalEntries
= 0; /* FIXME */
1538 lpRecord
->offPalEntries
= 0; /* FIXME */
1539 lpRecord
->nSizeLast
= 0; /* FIXME */
1541 /* No more records after this one */
1544 FIXME( "META_EOF conversion not correct\n" );
1548 case META_SETMAPMODE
:
1550 PEMRSETMAPMODE lpRecord
;
1551 size_t uRecord
= sizeof(*lpRecord
);
1553 EMF_ReAllocAndAdjustPointers(PEMRSETMAPMODE
,uRecord
);
1555 lpRecord
->emr
.iType
= EMR_SETMAPMODE
;
1556 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1558 lpRecord
->iMode
= lpMetaRecord
->rdParm
[0];
1563 case META_DELETEOBJECT
: /* Select and Delete structures are the same */
1564 case META_SELECTOBJECT
:
1566 PEMRDELETEOBJECT lpRecord
;
1567 size_t uRecord
= sizeof(*lpRecord
);
1569 EMF_ReAllocAndAdjustPointers(PEMRDELETEOBJECT
,uRecord
);
1571 if( lpMetaRecord
->rdFunction
== META_DELETEOBJECT
)
1573 lpRecord
->emr
.iType
= EMR_DELETEOBJECT
;
1577 lpRecord
->emr
.iType
= EMR_SELECTOBJECT
;
1579 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1581 lpRecord
->ihObject
= lpMetaRecord
->rdParm
[0]; /* FIXME: Handle */
1586 case META_POLYGON
: /* This is just plain busted. I don't know what I'm doing */
1588 PEMRPOLYGON16 lpRecord
; /* FIXME: Should it be a poly or poly16? */
1589 size_t uRecord
= sizeof(*lpRecord
);
1591 EMF_ReAllocAndAdjustPointers(PEMRPOLYGON16
,uRecord
);
1593 /* FIXME: This is mostly all wrong */
1594 lpRecord
->emr
.iType
= EMR_POLYGON16
;
1595 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1597 lpRecord
->rclBounds
.left
= 0;
1598 lpRecord
->rclBounds
.right
= 0;
1599 lpRecord
->rclBounds
.top
= 0;
1600 lpRecord
->rclBounds
.bottom
= 0;
1603 lpRecord
->apts
[0].x
= 0;
1604 lpRecord
->apts
[0].y
= 0;
1606 FIXME( "META_POLYGON conversion not correct\n" );
1611 case META_SETPOLYFILLMODE
:
1613 PEMRSETPOLYFILLMODE lpRecord
;
1614 size_t uRecord
= sizeof(*lpRecord
);
1616 EMF_ReAllocAndAdjustPointers(PEMRSETPOLYFILLMODE
,uRecord
);
1618 lpRecord
->emr
.iType
= EMR_SETPOLYFILLMODE
;
1619 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1621 lpRecord
->iMode
= lpMetaRecord
->rdParm
[0];
1626 case META_SETWINDOWORG
:
1628 PEMRSETWINDOWORGEX lpRecord
; /* Seems to be the closest thing */
1629 size_t uRecord
= sizeof(*lpRecord
);
1631 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWORGEX
,uRecord
);
1633 lpRecord
->emr
.iType
= EMR_SETWINDOWORGEX
;
1634 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1636 lpRecord
->ptlOrigin
.x
= lpMetaRecord
->rdParm
[1];
1637 lpRecord
->ptlOrigin
.y
= lpMetaRecord
->rdParm
[0];
1642 case META_SETWINDOWEXT
: /* Structure is the same for SETWINDOWEXT & SETVIEWPORTEXT */
1643 case META_SETVIEWPORTEXT
:
1645 PEMRSETWINDOWEXTEX lpRecord
;
1646 size_t uRecord
= sizeof(*lpRecord
);
1648 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWEXTEX
,uRecord
);
1650 if ( lpMetaRecord
->rdFunction
== META_SETWINDOWEXT
)
1652 lpRecord
->emr
.iType
= EMR_SETWINDOWORGEX
;
1656 lpRecord
->emr
.iType
= EMR_SETVIEWPORTEXTEX
;
1658 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1660 lpRecord
->szlExtent
.cx
= lpMetaRecord
->rdParm
[1];
1661 lpRecord
->szlExtent
.cy
= lpMetaRecord
->rdParm
[0];
1666 case META_CREATEBRUSHINDIRECT
:
1668 PEMRCREATEBRUSHINDIRECT lpRecord
;
1669 size_t uRecord
= sizeof(*lpRecord
);
1671 EMF_ReAllocAndAdjustPointers(PEMRCREATEBRUSHINDIRECT
,uRecord
);
1673 lpRecord
->emr
.iType
= EMR_CREATEBRUSHINDIRECT
;
1674 lpRecord
->emr
.nSize
= sizeof( *lpRecord
);
1676 lpRecord
->ihBrush
= ((LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
)->nHandles
;
1677 lpRecord
->lb
.lbStyle
= ((LPLOGBRUSH16
)lpMetaRecord
->rdParm
)->lbStyle
;
1678 lpRecord
->lb
.lbColor
= ((LPLOGBRUSH16
)lpMetaRecord
->rdParm
)->lbColor
;
1679 lpRecord
->lb
.lbHatch
= ((LPLOGBRUSH16
)lpMetaRecord
->rdParm
)->lbHatch
;
1681 ((LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
)->nHandles
+= 1; /* New handle */
1687 /* These are all unimplemented and as such are intended to fall through to the default case */
1688 case META_SETBKCOLOR
:
1689 case META_SETBKMODE
:
1691 case META_SETRELABS
:
1692 case META_SETSTRETCHBLTMODE
:
1693 case META_SETTEXTCOLOR
:
1694 case META_SETVIEWPORTORG
:
1695 case META_OFFSETWINDOWORG
:
1696 case META_SCALEWINDOWEXT
:
1697 case META_OFFSETVIEWPORTORG
:
1698 case META_SCALEVIEWPORTEXT
:
1701 case META_EXCLUDECLIPRECT
:
1702 case META_INTERSECTCLIPRECT
:
1705 case META_FLOODFILL
:
1707 case META_RECTANGLE
:
1708 case META_ROUNDRECT
:
1712 case META_OFFSETCLIPRGN
:
1714 case META_POLYPOLYGON
:
1716 case META_RESTOREDC
:
1718 case META_CREATEPATTERNBRUSH
:
1719 case META_CREATEPENINDIRECT
:
1720 case META_CREATEFONTINDIRECT
:
1721 case META_CREATEPALETTE
:
1722 case META_SETTEXTALIGN
:
1723 case META_SELECTPALETTE
:
1724 case META_SETMAPPERFLAGS
:
1725 case META_REALIZEPALETTE
:
1727 case META_EXTTEXTOUT
:
1728 case META_STRETCHDIB
:
1729 case META_DIBSTRETCHBLT
:
1730 case META_STRETCHBLT
:
1732 case META_CREATEREGION
:
1733 case META_FILLREGION
:
1734 case META_FRAMEREGION
:
1735 case META_INVERTREGION
:
1736 case META_PAINTREGION
:
1737 case META_SELECTCLIPREGION
:
1738 case META_DIBCREATEPATTERNBRUSH
:
1739 case META_DIBBITBLT
:
1740 case META_SETTEXTCHAREXTRA
:
1741 case META_SETTEXTJUSTIFICATION
:
1742 case META_EXTFLOODFILL
:
1743 case META_SETDIBTODEV
:
1745 case META_ANIMATEPALETTE
:
1746 case META_SETPALENTRIES
:
1747 case META_RESIZEPALETTE
:
1750 case META_STARTPAGE
:
1754 case META_CREATEBRUSH
:
1755 case META_CREATEBITMAPINDIRECT
:
1756 case META_CREATEBITMAP
:
1757 /* Fall through to unimplemented */
1760 /* Not implemented yet */
1761 FIXME( "Conversion of record type 0x%x not implemented.\n", lpMetaRecord
->rdFunction
);
1766 /* Move to the next record */
1767 (char*)lpbBuffer
+= ((LPMETARECORD
)lpbBuffer
)->rdSize
* 2; /* FIXME: Seem to be doing this in metafile.c */
1769 #undef ReAllocAndAdjustPointers
1772 /* We know the last of the header information now */
1773 ((LPENHMETAHEADER
)lpNewEnhMetaFileBuffer
)->nBytes
= uNewEnhMetaFileBufferSize
;
1775 /* Create the enhanced metafile */
1776 hMf
= SetEnhMetaFileBits( uNewEnhMetaFileBufferSize
, (const BYTE
*)lpNewEnhMetaFileBuffer
);
1779 ERR( "Problem creating metafile. Did the conversion fail somewhere?\n" );
1784 /* Free the data associated with our copy since it's been copied */
1785 HeapFree( GetProcessHeap(), 0, lpNewEnhMetaFileBuffer
);