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( HANDLE 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:
429 * FIXME: The call to SetWindowOrgEx prevents EMFs from being scrolled
430 * by an application. This is very BAD!!!
433 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
434 SetWindowOrgEx(hdc, pSetWindowOrgEx->ptlOrigin.x,
435 pSetWindowOrgEx->ptlOrigin.y, NULL);
439 case EMR_SETWINDOWEXTEX:
441 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
442 SetWindowExtEx(hdc, pSetWindowExtEx->szlExtent.cx,
443 pSetWindowExtEx->szlExtent.cy, NULL);
446 case EMR_SETVIEWPORTORGEX:
448 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
449 SetViewportOrgEx(hdc, pSetViewportOrgEx->ptlOrigin.x,
450 pSetViewportOrgEx->ptlOrigin.y, NULL);
453 case EMR_SETVIEWPORTEXTEX:
455 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
456 SetViewportExtEx(hdc, pSetViewportExtEx->szlExtent.cx,
457 pSetViewportExtEx->szlExtent.cy, NULL);
462 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
463 (handletable->objectHandle)[pCreatePen->ihPen] =
464 CreatePenIndirect(&pCreatePen->lopn);
467 case EMR_EXTCREATEPEN:
469 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
471 lb.lbStyle = pPen->elp.elpBrushStyle;
472 lb.lbColor = pPen->elp.elpColor;
473 lb.lbHatch = pPen->elp.elpHatch;
475 if(pPen->offBmi || pPen->offBits)
476 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
478 (handletable->objectHandle)[pPen->ihPen] =
479 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
480 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
483 case EMR_CREATEBRUSHINDIRECT:
485 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
486 (handletable->objectHandle)[pBrush->ihBrush] =
487 CreateBrushIndirect(&pBrush->lb);
490 case EMR_EXTCREATEFONTINDIRECTW:
492 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
493 (handletable->objectHandle)[pFont->ihFont] =
494 CreateFontIndirectW(&pFont->elfw.elfLogFont);
499 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
500 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
505 PEMRLINETO pLineTo = (PEMRLINETO) mr;
506 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
511 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
512 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
513 pRect->rclBox.right, pRect->rclBox.bottom);
518 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
519 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
520 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
525 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
526 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
527 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
528 pPoly->cpts * sizeof(POINT) );
530 for(i = 0; i < pPoly->cpts; i++)
531 CONV_POINT16TO32(pPoly->apts + i, pts + i);
532 Polygon(hdc, pts, pPoly->cpts);
533 HeapFree( GetProcessHeap(), 0, pts );
538 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
539 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
540 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
541 pPoly->cpts * sizeof(POINT) );
543 for(i = 0; i < pPoly->cpts; i++)
544 CONV_POINT16TO32(pPoly->apts + i, pts + i);
545 Polyline(hdc, pts, pPoly->cpts);
546 HeapFree( GetProcessHeap(), 0, pts );
549 case EMR_POLYLINETO16:
551 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
552 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
553 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
554 pPoly->cpts * sizeof(POINT) );
556 for(i = 0; i < pPoly->cpts; i++)
557 CONV_POINT16TO32(pPoly->apts + i, pts + i);
558 PolylineTo(hdc, pts, pPoly->cpts);
559 HeapFree( GetProcessHeap(), 0, pts );
562 case EMR_POLYBEZIER16:
564 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
565 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
566 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
567 pPoly->cpts * sizeof(POINT) );
569 for(i = 0; i < pPoly->cpts; i++)
570 CONV_POINT16TO32(pPoly->apts + i, pts + i);
571 PolyBezier(hdc, pts, pPoly->cpts);
572 HeapFree( GetProcessHeap(), 0, pts );
575 case EMR_POLYBEZIERTO16:
577 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
578 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
579 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
580 pPoly->cpts * sizeof(POINT) );
582 for(i = 0; i < pPoly->cpts; i++)
583 CONV_POINT16TO32(pPoly->apts + i, pts + i);
584 PolyBezierTo(hdc, pts, pPoly->cpts);
585 HeapFree( GetProcessHeap(), 0, pts );
588 case EMR_POLYPOLYGON16:
590 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
591 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
592 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
594 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
595 pPolyPoly->cpts * sizeof(POINT) );
597 for(i = 0; i < pPolyPoly->cpts; i++)
598 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
599 pPolyPoly->nPolys) + i, pts + i);
601 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
602 HeapFree( GetProcessHeap(), 0, pts );
605 case EMR_POLYPOLYLINE16:
607 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
608 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
609 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
611 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
612 pPolyPoly->cpts * sizeof(POINT) );
614 for(i = 0; i < pPolyPoly->cpts; i++)
615 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
616 pPolyPoly->nPolys) + i, pts + i);
618 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
619 HeapFree( GetProcessHeap(), 0, pts );
623 case EMR_STRETCHDIBITS:
625 LONG xDest = mr->dParm[4];
626 LONG yDest = mr->dParm[5];
627 LONG xSrc = mr->dParm[6];
628 LONG ySrc = mr->dParm[7];
629 LONG cxSrc = mr->dParm[8];
630 LONG cySrc = mr->dParm[9];
631 DWORD offBmiSrc = mr->dParm[10];
632 DWORD offBitsSrc = mr->dParm[12];
633 DWORD iUsageSrc = mr->dParm[14];
634 DWORD dwRop = mr->dParm[15];
635 LONG cxDest = mr->dParm[16];
636 LONG cyDest = mr->dParm[17];
638 StretchDIBits(hdc,xDest,yDest,cxDest,cyDest,
639 xSrc,ySrc,cxSrc,cySrc,
640 ((char *)mr)+offBitsSrc,
641 (const BITMAPINFO *)(((char *)mr)+offBmiSrc),
645 case EMR_EXTTEXTOUTW:
648 DWORD flags = mr->dParm[4];
650 DWORD x = mr->dParm[7], y = mr->dParm[8];
651 DWORD count = mr->dParm[9];
652 LPWSTR str = (LPWSTR)((char *)mr + mr->dParm[10]);
655 LPINT lpDx = (LPINT)((char *)mr + mr->dParm[16]);
657 FIXME("Some ExtTextOut args not handled\n");
658 ExtTextOutW(hdc, x, y, flags, NULL,
663 case EMR_CREATEPALETTE:
665 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
667 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
668 CreatePalette( &lpCreatePal->lgpl );
673 case EMR_SELECTPALETTE:
675 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
677 if( lpSelectPal->ihPal & 0x80000000 ) {
678 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
680 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
681 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
686 case EMR_REALIZEPALETTE:
688 RealizePalette( hdc );
692 case EMR_EXTSELECTCLIPRGN:
694 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
696 if ((lpRgn->cbRgnData == 0) && (lpRgn->iMode == RGN_COPY)) {
697 ExtSelectClipRgn( hdc, 0, RGN_COPY );
699 FIXME("EMR_EXTSELECTCLIPRGN cbRgnData %lu\n", lpRgn->cbRgnData);
701 /* Need to make a region out of the RGNDATA we have */
702 /* ExtCreateRegion(....); */
703 /* ExtSelectClipRgn( hdc, ..., (INT)(lpRgn->iMode) ); */
715 case EMR_SETWORLDTRANSFORM:
717 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
718 SetWorldTransform( hdc, &lpXfrm->xform );
724 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
725 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
731 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
732 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
738 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
739 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
743 case EMR_POLYBEZIERTO:
745 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
746 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
747 (UINT)lpPolyBezierTo->cptl );
753 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
754 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
755 (UINT)lpPolyLineTo->cptl );
759 case EMR_POLYPOLYLINE:
761 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
762 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
764 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
765 pPolyPolyline->nPolys),
766 pPolyPolyline->aPolyCounts,
767 pPolyPolyline->nPolys );
772 case EMR_POLYPOLYGON:
774 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
776 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
778 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
779 pPolyPolygon->nPolys),
780 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
784 case EMR_SETBRUSHORGEX:
786 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
789 (INT)lpSetBrushOrgEx->ptlOrigin.x,
790 (INT)lpSetBrushOrgEx->ptlOrigin.y,
798 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
801 (INT)lpSetPixelV->ptlPixel.x,
802 (INT)lpSetPixelV->ptlPixel.y,
803 lpSetPixelV->crColor );
808 case EMR_SETMAPPERFLAGS:
810 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
812 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
817 case EMR_SETCOLORADJUSTMENT:
819 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
821 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
826 case EMR_OFFSETCLIPRGN:
828 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
831 (INT)lpOffsetClipRgn->ptlOffset.x,
832 (INT)lpOffsetClipRgn->ptlOffset.y );
837 case EMR_EXCLUDECLIPRECT:
839 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
841 ExcludeClipRect( hdc,
842 lpExcludeClipRect->rclClip.left,
843 lpExcludeClipRect->rclClip.top,
844 lpExcludeClipRect->rclClip.right,
845 lpExcludeClipRect->rclClip.bottom );
850 case EMR_SCALEVIEWPORTEXTEX:
852 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
854 ScaleViewportExtEx( hdc,
855 lpScaleViewportExtEx->xNum,
856 lpScaleViewportExtEx->xDenom,
857 lpScaleViewportExtEx->yNum,
858 lpScaleViewportExtEx->yDenom,
864 case EMR_SCALEWINDOWEXTEX:
866 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
868 ScaleWindowExtEx( hdc,
869 lpScaleWindowExtEx->xNum,
870 lpScaleWindowExtEx->xDenom,
871 lpScaleWindowExtEx->yNum,
872 lpScaleWindowExtEx->yDenom,
878 case EMR_MODIFYWORLDTRANSFORM:
880 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
882 ModifyWorldTransform( hdc, &lpModifyWorldTrans->xform,
883 lpModifyWorldTrans->iMode );
890 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
893 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
894 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
895 lpAngleArc->eSweepAngle );
902 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
905 lpRoundRect->rclBox.left,
906 lpRoundRect->rclBox.top,
907 lpRoundRect->rclBox.right,
908 lpRoundRect->rclBox.bottom,
909 lpRoundRect->szlCorner.cx,
910 lpRoundRect->szlCorner.cy );
917 PEMRARC lpArc = (PEMRARC)mr;
920 (INT)lpArc->rclBox.left,
921 (INT)lpArc->rclBox.top,
922 (INT)lpArc->rclBox.right,
923 (INT)lpArc->rclBox.bottom,
924 (INT)lpArc->ptlStart.x,
925 (INT)lpArc->ptlStart.y,
926 (INT)lpArc->ptlEnd.x,
927 (INT)lpArc->ptlEnd.y );
934 PEMRCHORD lpChord = (PEMRCHORD)mr;
937 (INT)lpChord->rclBox.left,
938 (INT)lpChord->rclBox.top,
939 (INT)lpChord->rclBox.right,
940 (INT)lpChord->rclBox.bottom,
941 (INT)lpChord->ptlStart.x,
942 (INT)lpChord->ptlStart.y,
943 (INT)lpChord->ptlEnd.x,
944 (INT)lpChord->ptlEnd.y );
951 PEMRPIE lpPie = (PEMRPIE)mr;
954 (INT)lpPie->rclBox.left,
955 (INT)lpPie->rclBox.top,
956 (INT)lpPie->rclBox.right,
957 (INT)lpPie->rclBox.bottom,
958 (INT)lpPie->ptlStart.x,
959 (INT)lpPie->ptlStart.y,
960 (INT)lpPie->ptlEnd.x,
961 (INT)lpPie->ptlEnd.y );
968 PEMRARC lpArcTo = (PEMRARC)mr;
971 (INT)lpArcTo->rclBox.left,
972 (INT)lpArcTo->rclBox.top,
973 (INT)lpArcTo->rclBox.right,
974 (INT)lpArcTo->rclBox.bottom,
975 (INT)lpArcTo->ptlStart.x,
976 (INT)lpArcTo->ptlStart.y,
977 (INT)lpArcTo->ptlEnd.x,
978 (INT)lpArcTo->ptlEnd.y );
983 case EMR_EXTFLOODFILL:
985 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
988 (INT)lpExtFloodFill->ptlStart.x,
989 (INT)lpExtFloodFill->ptlStart.y,
990 lpExtFloodFill->crColor,
991 (UINT)lpExtFloodFill->iMode );
998 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
1000 (const LPPOINT)lpPolyDraw->aptl,
1001 lpPolyDraw->abTypes,
1002 (INT)lpPolyDraw->cptl );
1007 case EMR_SETARCDIRECTION:
1009 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1010 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1014 case EMR_SETMITERLIMIT:
1016 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1017 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1033 case EMR_CLOSEFIGURE:
1041 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1046 case EMR_STROKEANDFILLPATH:
1048 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1049 StrokeAndFillPath( hdc );
1053 case EMR_STROKEPATH:
1055 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1060 case EMR_FLATTENPATH:
1072 case EMR_SELECTCLIPPATH:
1074 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1075 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1085 case EMR_CREATECOLORSPACE:
1087 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1088 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1089 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1093 case EMR_SETCOLORSPACE:
1095 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1097 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1101 case EMR_DELETECOLORSPACE:
1103 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1104 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1108 case EMR_SETICMMODE:
1110 PERMSETICMMODE lpSetICMMode = (PERMSETICMMODE)mr;
1111 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1115 case EMR_PIXELFORMAT:
1118 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1120 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1121 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1126 case EMR_SETPALETTEENTRIES:
1128 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1130 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1131 (UINT)lpSetPaletteEntries->iStart,
1132 (UINT)lpSetPaletteEntries->cEntries,
1133 lpSetPaletteEntries->aPalEntries );
1138 case EMR_RESIZEPALETTE:
1140 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1142 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1143 (UINT)lpResizePalette->cEntries );
1148 case EMR_CREATEDIBPATTERNBRUSHPT:
1150 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1152 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1153 LPVOID lpPackedStruct = HeapAlloc( GetProcessHeap(),
1155 lpCreate->cbBmi + lpCreate->cbBits );
1156 /* Now pack this structure */
1157 memcpy( lpPackedStruct,
1158 ((BYTE*)lpCreate) + lpCreate->offBmi,
1160 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1161 ((BYTE*)lpCreate) + lpCreate->offBits,
1164 (handletable->objectHandle)[lpCreate->ihBrush] =
1165 CreateDIBPatternBrushPt( lpPackedStruct,
1166 (UINT)lpCreate->iUsage );
1172 case EMR_STRETCHBLT:
1175 case EMR_SETDIBITSTODEVICE:
1176 case EMR_EXTTEXTOUTA:
1177 case EMR_POLYDRAW16:
1178 case EMR_CREATEMONOBRUSH:
1179 case EMR_POLYTEXTOUTA:
1180 case EMR_POLYTEXTOUTW:
1186 case EMR_GLSBOUNDEDRECORD:
1188 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1189 record then ignore and return TRUE. */
1190 FIXME("type %d is unimplemented\n", type);
1197 /*****************************************************************************
1199 * EnumEnhMetaFile (GDI32.79)
1201 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1203 * record. Returns when either every record has been used or
1204 * when _EnhMetaFunc_ returns FALSE.
1208 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1214 BOOL WINAPI EnumEnhMetaFile(
1215 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
1216 HENHMETAFILE hmf, /* [in] EMF to walk */
1217 ENHMFENUMPROC callback, /* [in] callback function */
1218 LPVOID data, /* [in] optional data for callback function */
1219 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
1223 ENHMETAHEADER *emh, *emhTemp;
1229 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1230 XFORM savedXform, xform;
1231 HPEN hPen = (HPEN)NULL;
1232 HBRUSH hBrush = (HBRUSH)NULL;
1233 HFONT hFont = (HFONT)NULL;
1239 SetLastError(ERROR_INVALID_PARAMETER);
1243 emh = EMF_GetEnhMetaHeader(hmf);
1245 SetLastError(ERROR_INVALID_HANDLE);
1249 /* Copy the metafile into memory, because we need to avoid deadlock. */
1250 emhTemp = HeapAlloc(GetProcessHeap(), 0, emh->nSize + emh->nBytes);
1253 EMF_ReleaseEnhMetaHeader(hmf);
1254 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1257 memcpy(emhTemp, emh, emh->nSize + emh->nBytes);
1259 EMF_ReleaseEnhMetaHeader(hmf);
1261 ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1262 sizeof(HANDLETABLE) * emh->nHandles );
1265 HeapFree(GetProcessHeap(), 0, emhTemp);
1266 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1269 ht->objectHandle[0] = hmf;
1273 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
1274 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
1275 xscale = (FLOAT)(lpRect->right - lpRect->left) * 100.0 /
1276 (emh->rclFrame.right - emh->rclFrame.left) * xSrcPixSize;
1277 yscale = (FLOAT)(lpRect->bottom - lpRect->top) * 100.0 /
1278 (emh->rclFrame.bottom - emh->rclFrame.top) * ySrcPixSize;
1280 xform.eM11 = xscale;
1283 xform.eM22 = yscale;
1284 xform.eDx = (FLOAT)lpRect->left - (xscale * emh->rclFrame.left * 0.5);
1285 xform.eDy = (FLOAT)lpRect->top - (yscale * (FLOAT)emh->rclFrame.top * 0.5);
1287 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1288 GetWorldTransform(hdc, &savedXform);
1290 if (!ModifyWorldTransform(hdc, &xform, MWT_RIGHTMULTIPLY)) {
1291 ERR("World transform failed!\n");
1294 GetWorldTransform(hdc, &outXform);
1296 /* save the current pen, brush and font */
1297 hPen = GetCurrentObject(hdc, OBJ_PEN);
1298 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
1299 hFont = GetCurrentObject(hdc, OBJ_FONT);
1302 TRACE("nSize = %ld, nBytes = %ld, nHandles = %d, nRecords = %ld, nPalEntries = %ld\n",
1303 emh->nSize, emh->nBytes, emh->nHandles, emh->nRecords, emh->nPalEntries);
1307 while(ret && offset < emh->nBytes)
1309 emr = (ENHMETARECORD *)((char *)emh + offset);
1310 TRACE("Calling EnumFunc with record type %ld, size %ld\n", emr->iType, emr->nSize);
1311 ret = (*callback)(hdc, ht, emr, emh->nHandles, data);
1312 offset += emr->nSize;
1317 /* restore pen, brush and font */
1318 SelectObject(hdc, hBrush);
1319 SelectObject(hdc, hPen);
1320 SelectObject(hdc, hFont);
1322 SetWorldTransform(hdc, &savedXform);
1324 SetGraphicsMode(hdc, savedMode);
1327 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
1328 if( (ht->objectHandle)[i] )
1329 DeleteObject( (ht->objectHandle)[i] );
1331 HeapFree( GetProcessHeap(), 0, ht );
1332 HeapFree(GetProcessHeap(), 0, emhTemp);
1337 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
1339 INT handles, LPVOID data)
1341 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
1344 /**************************************************************************
1345 * PlayEnhMetaFile (GDI32.263)
1347 * Renders an enhanced metafile into a specified rectangle *lpRect
1348 * in device context hdc.
1351 BOOL WINAPI PlayEnhMetaFile(
1352 HDC hdc, /* [in] DC to render into */
1353 HENHMETAFILE hmf, /* [in] metafile to render */
1354 const RECT *lpRect /* [in] rectangle to place metafile inside */
1357 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
1361 /*****************************************************************************
1362 * DeleteEnhMetaFile (GDI32.68)
1364 * Deletes an enhanced metafile and frees the associated storage.
1366 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
1368 return EMF_Delete_HENHMETAFILE( hmf );
1371 /*****************************************************************************
1372 * CopyEnhMetaFileA (GDI32.21) Duplicate an enhanced metafile
1376 HENHMETAFILE WINAPI CopyEnhMetaFileA(
1377 HENHMETAFILE hmfSrc,
1380 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
1381 HENHMETAFILE hmfDst;
1383 if(!emrSrc) return FALSE;
1385 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
1386 memcpy( emrDst, emrSrc, emrSrc->nBytes );
1387 hmfDst = EMF_Create_HENHMETAFILE( emrDst, 0, 0 );
1390 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0, NULL,
1391 CREATE_ALWAYS, 0, 0);
1392 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
1393 hmfDst = EMF_GetEnhMetaFile( hFile );
1395 EMF_ReleaseEnhMetaHeader( hmfSrc );
1400 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1401 typedef struct tagEMF_PaletteCopy
1404 LPPALETTEENTRY lpPe;
1407 /***************************************************************
1408 * Find the EMR_EOF record and then use it to find the
1409 * palette entries for this enhanced metafile.
1410 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1411 * which contains the max number of elements to copy and where
1414 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1416 INT CALLBACK cbEnhPaletteCopy( HDC a,
1418 LPENHMETARECORD lpEMR,
1423 if ( lpEMR->iType == EMR_EOF )
1425 PEMREOF lpEof = (PEMREOF)lpEMR;
1426 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
1427 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
1429 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
1431 memcpy( (LPVOID)info->lpPe,
1432 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
1433 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
1435 /* Update the passed data as a return code */
1436 info->lpPe = NULL; /* Palettes were copied! */
1437 info->cEntries = (UINT)dwNumPalToCopy;
1439 return FALSE; /* That's all we need */
1445 /*****************************************************************************
1446 * GetEnhMetaFilePaletteEntries (GDI32.179)
1448 * Copy the palette and report size
1450 * BUGS: Error codes (SetLastError) are not set on failures
1452 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
1454 LPPALETTEENTRY lpPe )
1456 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
1457 UINT uReturnValue = GDI_ERROR;
1458 EMF_PaletteCopy infoForCallBack;
1460 TRACE( "(%04x,%d,%p)\n", hEmf, cEntries, lpPe );
1462 /* First check if there are any palettes associated with
1464 if ( enhHeader->nPalEntries == 0 )
1466 /* No palette associated with this enhanced metafile */
1471 /* Is the user requesting the number of palettes? */
1474 uReturnValue = (UINT)enhHeader->nPalEntries;
1478 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1479 infoForCallBack.cEntries = cEntries;
1480 infoForCallBack.lpPe = lpPe;
1482 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
1483 &infoForCallBack, NULL ) )
1488 /* Verify that the callback executed correctly */
1489 if ( infoForCallBack.lpPe != NULL )
1491 /* Callback proc had error! */
1492 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1496 uReturnValue = infoForCallBack.cEntries;
1500 EMF_ReleaseEnhMetaHeader( hEmf );
1502 return uReturnValue;
1505 /******************************************************************
1506 * SetWinMetaFileBits (GDI32.343)
1508 * Translate from old style to new style.
1510 * BUGS: - This doesn't take the DC and scaling into account
1511 * - Most record conversions aren't implemented
1512 * - Handle slot assignement is primative and most likely doesn't work
1514 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
1515 CONST BYTE *lpbBuffer,
1517 CONST METAFILEPICT *lpmfp
1521 LPVOID lpNewEnhMetaFileBuffer = NULL;
1522 UINT uNewEnhMetaFileBufferSize = 0;
1523 BOOL bFoundEOF = FALSE;
1525 FIXME( "(%d,%p,%04x,%p):stub\n", cbBuffer, lpbBuffer, hdcRef, lpmfp );
1527 /* 1. Get the header - skip over this and get straight to the records */
1529 uNewEnhMetaFileBufferSize = sizeof( ENHMETAHEADER );
1530 lpNewEnhMetaFileBuffer = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1531 uNewEnhMetaFileBufferSize );
1533 if( lpNewEnhMetaFileBuffer == NULL )
1538 /* Fill in the header record */
1540 LPENHMETAHEADER lpNewEnhMetaFileHeader = (LPENHMETAHEADER)lpNewEnhMetaFileBuffer;
1542 lpNewEnhMetaFileHeader->iType = EMR_HEADER;
1543 lpNewEnhMetaFileHeader->nSize = sizeof( ENHMETAHEADER );
1545 /* FIXME: Not right. Must be able to get this from the DC */
1546 lpNewEnhMetaFileHeader->rclBounds.left = 0;
1547 lpNewEnhMetaFileHeader->rclBounds.right = 0;
1548 lpNewEnhMetaFileHeader->rclBounds.top = 0;
1549 lpNewEnhMetaFileHeader->rclBounds.bottom = 0;
1551 /* FIXME: Not right. Must be able to get this from the DC */
1552 lpNewEnhMetaFileHeader->rclFrame.left = 0;
1553 lpNewEnhMetaFileHeader->rclFrame.right = 0;
1554 lpNewEnhMetaFileHeader->rclFrame.top = 0;
1555 lpNewEnhMetaFileHeader->rclFrame.bottom = 0;
1557 lpNewEnhMetaFileHeader->nHandles = 0; /* No handles yet */
1559 /* FIXME: Add in the rest of the fields to the header */
1574 (char*)lpbBuffer += ((METAHEADER*)lpbBuffer)->mtHeaderSize * 2; /* Point past the header - FIXME: metafile quirk? */
1576 /* 2. Enum over individual records and convert them to the new type of records */
1580 LPMETARECORD lpMetaRecord = (LPMETARECORD)lpbBuffer;
1582 #define EMF_ReAllocAndAdjustPointers( a , b ) \
1585 lpTmp = HeapReAlloc( GetProcessHeap(), 0, \
1586 lpNewEnhMetaFileBuffer, \
1587 uNewEnhMetaFileBufferSize + (b) ); \
1588 if( lpTmp == NULL ) { ERR( "No memory!\n" ); goto error; } \
1589 lpNewEnhMetaFileBuffer = lpTmp; \
1590 lpRecord = (a)( (char*)lpNewEnhMetaFileBuffer + uNewEnhMetaFileBufferSize ); \
1591 uNewEnhMetaFileBufferSize += (b); \
1594 switch( lpMetaRecord->rdFunction )
1599 size_t uRecord = sizeof(*lpRecord);
1601 EMF_ReAllocAndAdjustPointers(PEMREOF,uRecord);
1603 /* Fill the new record - FIXME: This is not right */
1604 lpRecord->emr.iType = EMR_EOF;
1605 lpRecord->emr.nSize = sizeof( *lpRecord );
1606 lpRecord->nPalEntries = 0; /* FIXME */
1607 lpRecord->offPalEntries = 0; /* FIXME */
1608 lpRecord->nSizeLast = 0; /* FIXME */
1610 /* No more records after this one */
1613 FIXME( "META_EOF conversion not correct\n" );
1617 case META_SETMAPMODE:
1619 PEMRSETMAPMODE lpRecord;
1620 size_t uRecord = sizeof(*lpRecord);
1622 EMF_ReAllocAndAdjustPointers(PEMRSETMAPMODE,uRecord);
1624 lpRecord->emr.iType = EMR_SETMAPMODE;
1625 lpRecord->emr.nSize = sizeof( *lpRecord );
1627 lpRecord->iMode = lpMetaRecord->rdParm[0];
1632 case META_DELETEOBJECT: /* Select and Delete structures are the same */
1633 case META_SELECTOBJECT:
1635 PEMRDELETEOBJECT lpRecord;
1636 size_t uRecord = sizeof(*lpRecord);
1638 EMF_ReAllocAndAdjustPointers(PEMRDELETEOBJECT,uRecord);
1640 if( lpMetaRecord->rdFunction == META_DELETEOBJECT )
1642 lpRecord->emr.iType = EMR_DELETEOBJECT;
1646 lpRecord->emr.iType = EMR_SELECTOBJECT;
1648 lpRecord->emr.nSize = sizeof( *lpRecord );
1650 lpRecord->ihObject = lpMetaRecord->rdParm[0]; /* FIXME: Handle */
1655 case META_POLYGON: /* This is just plain busted. I don't know what I'm doing */
1657 PEMRPOLYGON16 lpRecord; /* FIXME: Should it be a poly or poly16? */
1658 size_t uRecord = sizeof(*lpRecord);
1660 EMF_ReAllocAndAdjustPointers(PEMRPOLYGON16,uRecord);
1662 /* FIXME: This is mostly all wrong */
1663 lpRecord->emr.iType = EMR_POLYGON16;
1664 lpRecord->emr.nSize = sizeof( *lpRecord );
1666 lpRecord->rclBounds.left = 0;
1667 lpRecord->rclBounds.right = 0;
1668 lpRecord->rclBounds.top = 0;
1669 lpRecord->rclBounds.bottom = 0;
1672 lpRecord->apts[0].x = 0;
1673 lpRecord->apts[0].y = 0;
1675 FIXME( "META_POLYGON conversion not correct\n" );
1680 case META_SETPOLYFILLMODE:
1682 PEMRSETPOLYFILLMODE lpRecord;
1683 size_t uRecord = sizeof(*lpRecord);
1685 EMF_ReAllocAndAdjustPointers(PEMRSETPOLYFILLMODE,uRecord);
1687 lpRecord->emr.iType = EMR_SETPOLYFILLMODE;
1688 lpRecord->emr.nSize = sizeof( *lpRecord );
1690 lpRecord->iMode = lpMetaRecord->rdParm[0];
1695 case META_SETWINDOWORG:
1697 PEMRSETWINDOWORGEX lpRecord; /* Seems to be the closest thing */
1698 size_t uRecord = sizeof(*lpRecord);
1700 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWORGEX,uRecord);
1702 lpRecord->emr.iType = EMR_SETWINDOWORGEX;
1703 lpRecord->emr.nSize = sizeof( *lpRecord );
1705 lpRecord->ptlOrigin.x = lpMetaRecord->rdParm[1];
1706 lpRecord->ptlOrigin.y = lpMetaRecord->rdParm[0];
1711 case META_SETWINDOWEXT: /* Structure is the same for SETWINDOWEXT & SETVIEWPORTEXT */
1712 case META_SETVIEWPORTEXT:
1714 PEMRSETWINDOWEXTEX lpRecord;
1715 size_t uRecord = sizeof(*lpRecord);
1717 EMF_ReAllocAndAdjustPointers(PEMRSETWINDOWEXTEX,uRecord);
1719 if ( lpMetaRecord->rdFunction == META_SETWINDOWEXT )
1721 lpRecord->emr.iType = EMR_SETWINDOWORGEX;
1725 lpRecord->emr.iType = EMR_SETVIEWPORTEXTEX;
1727 lpRecord->emr.nSize = sizeof( *lpRecord );
1729 lpRecord->szlExtent.cx = lpMetaRecord->rdParm[1];
1730 lpRecord->szlExtent.cy = lpMetaRecord->rdParm[0];
1735 case META_CREATEBRUSHINDIRECT:
1737 PEMRCREATEBRUSHINDIRECT lpRecord;
1738 size_t uRecord = sizeof(*lpRecord);
1740 EMF_ReAllocAndAdjustPointers(PEMRCREATEBRUSHINDIRECT,uRecord);
1742 lpRecord->emr.iType = EMR_CREATEBRUSHINDIRECT;
1743 lpRecord->emr.nSize = sizeof( *lpRecord );
1745 lpRecord->ihBrush = ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nHandles;
1746 lpRecord->lb.lbStyle = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbStyle;
1747 lpRecord->lb.lbColor = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbColor;
1748 lpRecord->lb.lbHatch = ((LPLOGBRUSH16)lpMetaRecord->rdParm)->lbHatch;
1750 ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nHandles += 1; /* New handle */
1756 /* These are all unimplemented and as such are intended to fall through to the default case */
1757 case META_SETBKCOLOR:
1758 case META_SETBKMODE:
1760 case META_SETRELABS:
1761 case META_SETSTRETCHBLTMODE:
1762 case META_SETTEXTCOLOR:
1763 case META_SETVIEWPORTORG:
1764 case META_OFFSETWINDOWORG:
1765 case META_SCALEWINDOWEXT:
1766 case META_OFFSETVIEWPORTORG:
1767 case META_SCALEVIEWPORTEXT:
1770 case META_EXCLUDECLIPRECT:
1771 case META_INTERSECTCLIPRECT:
1774 case META_FLOODFILL:
1776 case META_RECTANGLE:
1777 case META_ROUNDRECT:
1781 case META_OFFSETCLIPRGN:
1783 case META_POLYPOLYGON:
1785 case META_RESTOREDC:
1787 case META_CREATEPATTERNBRUSH:
1788 case META_CREATEPENINDIRECT:
1789 case META_CREATEFONTINDIRECT:
1790 case META_CREATEPALETTE:
1791 case META_SETTEXTALIGN:
1792 case META_SELECTPALETTE:
1793 case META_SETMAPPERFLAGS:
1794 case META_REALIZEPALETTE:
1796 case META_EXTTEXTOUT:
1797 case META_STRETCHDIB:
1798 case META_DIBSTRETCHBLT:
1799 case META_STRETCHBLT:
1801 case META_CREATEREGION:
1802 case META_FILLREGION:
1803 case META_FRAMEREGION:
1804 case META_INVERTREGION:
1805 case META_PAINTREGION:
1806 case META_SELECTCLIPREGION:
1807 case META_DIBCREATEPATTERNBRUSH:
1808 case META_DIBBITBLT:
1809 case META_SETTEXTCHAREXTRA:
1810 case META_SETTEXTJUSTIFICATION:
1811 case META_EXTFLOODFILL:
1812 case META_SETDIBTODEV:
1814 case META_ANIMATEPALETTE:
1815 case META_SETPALENTRIES:
1816 case META_RESIZEPALETTE:
1819 case META_STARTPAGE:
1823 case META_CREATEBRUSH:
1824 case META_CREATEBITMAPINDIRECT:
1825 case META_CREATEBITMAP:
1826 /* Fall through to unimplemented */
1829 /* Not implemented yet */
1830 FIXME( "Conversion of record type 0x%x not implemented.\n", lpMetaRecord->rdFunction );
1835 /* Move to the next record */
1836 (char*)lpbBuffer += ((LPMETARECORD)lpbBuffer)->rdSize * 2; /* FIXME: Seem to be doing this in metafile.c */
1838 #undef ReAllocAndAdjustPointers
1841 /* We know the last of the header information now */
1842 ((LPENHMETAHEADER)lpNewEnhMetaFileBuffer)->nBytes = uNewEnhMetaFileBufferSize;
1844 /* Create the enhanced metafile */
1845 hMf = SetEnhMetaFileBits( uNewEnhMetaFileBufferSize, (const BYTE*)lpNewEnhMetaFileBuffer );
1848 ERR( "Problem creating metafile. Did the conversion fail somewhere?\n" );
1853 /* Free the data associated with our copy since it's been copied */
1854 HeapFree( GetProcessHeap(), 0, lpNewEnhMetaFileBuffer );