Pass the main exe name in the CREATE_PROCESS debug event.
[wine.git] / objects / enhmetafile.c
blobe8dbaf8ad0c18849622c51361f79526d6518a0c3
1 /*
2 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
4 * 1999 Huw D M Davies
6 *
7 * The enhanced format consists of the following elements:
9 * A header
10 * A table of handles to GDI objects
11 * An array of metafile records
12 * A private palette
15 * The standard format consists of a header and an array of metafile records.
17 */
19 #include <string.h>
20 #include <assert.h>
21 #include "winbase.h"
22 #include "wingdi.h"
23 #include "wine/winestring.h"
24 #include "winerror.h"
25 #include "enhmetafile.h"
26 #include "debugtools.h"
27 #include "heap.h"
28 #include "metafile.h"
30 DEFAULT_DEBUG_CHANNEL(enhmetafile)
32 /****************************************************************************
33 * EMF_Create_HENHMETAFILE
35 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, HFILE hFile, HANDLE
36 hMapping )
38 HENHMETAFILE hmf = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
39 ENHMETAFILE_MAGIC );
40 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_HEAP_LOCK( hmf );
41 metaObj->emh = emh;
42 metaObj->hFile = hFile;
43 metaObj->hMapping = hMapping;
44 GDI_HEAP_UNLOCK( hmf );
45 return hmf;
48 /****************************************************************************
49 * EMF_Delete_HENHMETAFILE
51 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
53 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
54 ENHMETAFILE_MAGIC );
55 if(!metaObj) return FALSE;
56 if(metaObj->hMapping) {
57 UnmapViewOfFile( metaObj->emh );
58 CloseHandle( metaObj->hMapping );
59 CloseHandle( metaObj->hFile );
60 } else
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,
74 ENHMETAFILE_MAGIC );
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 /*****************************************************************************
90 * EMF_GetEnhMetaFile
93 static HENHMETAFILE EMF_GetEnhMetaFile( HFILE hFile )
95 ENHMETAHEADER *emh;
96 HANDLE hMapping;
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 );
106 return 0;
108 return EMF_Create_HENHMETAFILE( emh, hFile, hMapping );
112 /*****************************************************************************
113 * GetEnhMetaFileA (GDI32.174)
117 HENHMETAFILE WINAPI GetEnhMetaFileA(
118 LPCSTR lpszMetaFile /* filename of enhanced metafile */
121 HENHMETAFILE hmf;
122 HFILE hFile;
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);
128 return 0;
130 hmf = EMF_GetEnhMetaFile( hFile );
131 if(!hmf)
132 CloseHandle( hFile );
133 return hmf;
136 /*****************************************************************************
137 * GetEnhMetaFileW (GDI32.180)
139 HENHMETAFILE WINAPI GetEnhMetaFileW(
140 LPCWSTR lpszMetaFile) /* filename of enhanced metafile */
142 HENHMETAFILE hmf;
143 HFILE hFile;
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));
149 return 0;
151 hmf = EMF_GetEnhMetaFile( hFile );
152 if(!hmf)
153 CloseHandle( hFile );
154 return hmf;
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
162 * buf.
164 UINT WINAPI GetEnhMetaFileHeader(
165 HENHMETAFILE hmf, /* enhanced metafile */
166 UINT bufsize, /* size of buffer */
167 LPENHMETAHEADER buf /* buffer */
170 LPENHMETAHEADER emh;
171 UINT size;
173 emh = EMF_GetEnhMetaHeader(hmf);
174 if(!emh) return FALSE;
175 size = emh->nSize;
176 if (!buf) {
177 EMF_ReleaseEnhMetaHeader(hmf);
178 return size;
180 size = min(size, bufsize);
181 memmove(buf, emh, size);
182 EMF_ReleaseEnhMetaHeader(hmf);
183 return size;
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);
197 INT first, first_A;
199 if(!emh) return FALSE;
200 if(emh->nDescription == 0 || emh->offDescription == 0) {
201 EMF_ReleaseEnhMetaHeader(hmf);
202 return 0;
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 );
213 buf += first_A + 1;
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
226 * _buf_.
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);
242 return 0;
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(
272 HENHMETAFILE hmf,
273 UINT bufsize,
274 LPBYTE buf
277 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
278 UINT size;
280 if(!emh) return 0;
282 size = emh->nBytes;
283 if( buf == NULL ) {
284 EMF_ReleaseEnhMetaHeader( hmf );
285 return size;
288 size = min( size, bufsize );
289 memmove(buf, emh, size);
291 EMF_ReleaseEnhMetaHeader( hmf );
292 return size;
295 /*****************************************************************************
296 * PlayEnhMetaFileRecord (GDI32.264)
298 * Render a single enhanced metafile record in the device context hdc.
300 * RETURNS
301 * TRUE (non zero) on success, FALSE on error.
302 * BUGS
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 */
313 int type;
314 TRACE(
315 "hdc = %08x, handletable = %p, record = %p, numHandles = %d\n",
316 hdc, handletable, mr, handles);
317 if (!mr) return FALSE;
319 type = mr->iType;
321 TRACE(" type=%d\n", type);
322 switch(type)
324 case EMR_HEADER:
325 break;
326 case EMR_EOF:
327 break;
328 case EMR_GDICOMMENT:
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 );
333 break;
335 case EMR_SETMAPMODE:
337 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
338 SetMapMode(hdc, pSetMapMode->iMode);
339 break;
341 case EMR_SETBKMODE:
343 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
344 SetBkMode(hdc, pSetBkMode->iMode);
345 break;
347 case EMR_SETBKCOLOR:
349 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
350 SetBkColor(hdc, pSetBkColor->crColor);
351 break;
353 case EMR_SETPOLYFILLMODE:
355 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
356 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
357 break;
359 case EMR_SETROP2:
361 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
362 SetROP2(hdc, pSetROP2->iMode);
363 break;
365 case EMR_SETSTRETCHBLTMODE:
367 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
368 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
369 break;
371 case EMR_SETTEXTALIGN:
373 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
374 SetTextAlign(hdc, pSetTextAlign->iMode);
375 break;
377 case EMR_SETTEXTCOLOR:
379 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
380 SetTextColor(hdc, pSetTextColor->crColor);
381 break;
383 case EMR_SAVEDC:
385 SaveDC(hdc);
386 break;
388 case EMR_RESTOREDC:
390 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
391 RestoreDC(hdc, pRestoreDC->iRelative);
392 break;
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);
399 break;
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 &
410 0x7fffffff ) );
411 } else {
412 /* High order bit wasn't set - not a stock object
414 SelectObject( hdc,
415 (handletable->objectHandle)[pSelectObject->ihObject] );
417 break;
419 case EMR_DELETEOBJECT:
421 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
422 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
423 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
424 break;
426 case EMR_SETWINDOWORGEX:
428 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
429 SetWindowOrgEx(hdc, pSetWindowOrgEx->ptlOrigin.x,
430 pSetWindowOrgEx->ptlOrigin.y, NULL);
431 break;
433 case EMR_SETWINDOWEXTEX:
435 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
436 SetWindowExtEx(hdc, pSetWindowExtEx->szlExtent.cx,
437 pSetWindowExtEx->szlExtent.cy, NULL);
438 break;
440 case EMR_SETVIEWPORTORGEX:
442 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
443 SetViewportOrgEx(hdc, pSetViewportOrgEx->ptlOrigin.x,
444 pSetViewportOrgEx->ptlOrigin.y, NULL);
445 break;
447 case EMR_SETVIEWPORTEXTEX:
449 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
450 SetViewportExtEx(hdc, pSetViewportExtEx->szlExtent.cx,
451 pSetViewportExtEx->szlExtent.cy, NULL);
452 break;
454 case EMR_CREATEPEN:
456 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
457 (handletable->objectHandle)[pCreatePen->ihPen] =
458 CreatePenIndirect(&pCreatePen->lopn);
459 break;
461 case EMR_EXTCREATEPEN:
463 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
464 LOGBRUSH lb;
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);
475 break;
477 case EMR_CREATEBRUSHINDIRECT:
479 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
480 (handletable->objectHandle)[pBrush->ihBrush] =
481 CreateBrushIndirect(&pBrush->lb);
482 break;
484 case EMR_EXTCREATEFONTINDIRECTW:
486 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
487 (handletable->objectHandle)[pFont->ihFont] =
488 CreateFontIndirectW(&pFont->elfw.elfLogFont);
489 break;
491 case EMR_MOVETOEX:
493 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
494 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
495 break;
497 case EMR_LINETO:
499 PEMRLINETO pLineTo = (PEMRLINETO) mr;
500 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
501 break;
503 case EMR_RECTANGLE:
505 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
506 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
507 pRect->rclBox.right, pRect->rclBox.bottom);
508 break;
510 case EMR_ELLIPSE:
512 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
513 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
514 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
515 break;
517 case EMR_POLYGON16:
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) );
523 DWORD i;
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 );
528 break;
530 case EMR_POLYLINE16:
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) );
536 DWORD i;
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 );
541 break;
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) );
552 DWORD i;
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 );
559 break;
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),
581 iUsageSrc,dwRop);
582 break;
584 case EMR_EXTTEXTOUTW:
586 /* 0-3: ??? */
587 DWORD flags = mr->dParm[4];
588 /* 5, 6: ??? */
589 DWORD x = mr->dParm[7], y = mr->dParm[8];
590 DWORD count = mr->dParm[9];
591 /* 10-16: ??? */
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);
597 break;
600 case EMR_CREATEPALETTE:
602 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
604 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
605 CreatePalette( &lpCreatePal->lgpl );
607 break;
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 );
617 break;
620 case EMR_REALIZEPALETTE:
622 RealizePalette( hdc );
623 break;
626 #if 0
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) );
635 #endif
637 case EMR_SETMETARGN:
639 SetMetaRgn( hdc );
640 break;
643 case EMR_SETWORLDTRANSFORM:
645 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
647 SetWorldTransform( hdc, &lpXfrm->xform );
649 break;
652 case EMR_POLYBEZIER:
654 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
655 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
656 break;
659 case EMR_POLYGON:
661 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
662 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
663 break;
666 case EMR_POLYLINE:
668 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
669 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
670 break;
673 case EMR_POLYBEZIERTO:
675 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
676 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
677 (UINT)lpPolyBezierTo->cptl );
678 break;
681 case EMR_POLYLINETO:
683 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
684 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
685 (UINT)lpPolyLineTo->cptl );
686 break;
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 );
699 break;
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 );
711 break;
714 case EMR_SETBRUSHORGEX:
716 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
718 SetBrushOrgEx( hdc,
719 (INT)lpSetBrushOrgEx->ptlOrigin.x,
720 (INT)lpSetBrushOrgEx->ptlOrigin.y,
721 NULL );
723 break;
726 case EMR_SETPIXELV:
728 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
730 SetPixelV( hdc,
731 (INT)lpSetPixelV->ptlPixel.x,
732 (INT)lpSetPixelV->ptlPixel.y,
733 lpSetPixelV->crColor );
735 break;
738 case EMR_SETMAPPERFLAGS:
740 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
742 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
744 break;
747 case EMR_SETCOLORADJUSTMENT:
749 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
751 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
753 break;
756 case EMR_OFFSETCLIPRGN:
758 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
760 OffsetClipRgn( hdc,
761 (INT)lpOffsetClipRgn->ptlOffset.x,
762 (INT)lpOffsetClipRgn->ptlOffset.y );
764 break;
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 );
777 break;
780 case EMR_SCALEVIEWPORTEXTEX:
782 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
784 ScaleViewportExtEx( hdc,
785 lpScaleViewportExtEx->xNum,
786 lpScaleViewportExtEx->xDenom,
787 lpScaleViewportExtEx->yNum,
788 lpScaleViewportExtEx->yDenom,
789 NULL );
791 break;
794 case EMR_SCALEWINDOWEXTEX:
796 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
798 ScaleWindowExtEx( hdc,
799 lpScaleWindowExtEx->xNum,
800 lpScaleWindowExtEx->xDenom,
801 lpScaleWindowExtEx->yNum,
802 lpScaleWindowExtEx->yDenom,
803 NULL );
805 break;
808 case EMR_MODIFYWORLDTRANSFORM:
810 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
812 ModifyWorldTransform( hdc, &lpModifyWorldTrans->xform,
813 lpModifyWorldTrans->iMode );
815 break;
818 case EMR_ANGLEARC:
820 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
822 AngleArc( hdc,
823 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
824 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
825 lpAngleArc->eSweepAngle );
827 break;
830 case EMR_ROUNDRECT:
832 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
834 RoundRect( hdc,
835 lpRoundRect->rclBox.left,
836 lpRoundRect->rclBox.top,
837 lpRoundRect->rclBox.right,
838 lpRoundRect->rclBox.bottom,
839 lpRoundRect->szlCorner.cx,
840 lpRoundRect->szlCorner.cy );
842 break;
845 case EMR_ARC:
847 PEMRARC lpArc = (PEMRARC)mr;
849 Arc( hdc,
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 );
859 break;
862 case EMR_CHORD:
864 PEMRCHORD lpChord = (PEMRCHORD)mr;
866 Chord( hdc,
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 );
876 break;
879 case EMR_PIE:
881 PEMRPIE lpPie = (PEMRPIE)mr;
883 Pie( hdc,
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 );
893 break;
896 case EMR_ARCTO:
898 PEMRARC lpArcTo = (PEMRARC)mr;
900 ArcTo( hdc,
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 );
910 break;
913 case EMR_EXTFLOODFILL:
915 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
917 ExtFloodFill( hdc,
918 (INT)lpExtFloodFill->ptlStart.x,
919 (INT)lpExtFloodFill->ptlStart.y,
920 lpExtFloodFill->crColor,
921 (UINT)lpExtFloodFill->iMode );
923 break;
926 case EMR_POLYDRAW:
928 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
929 PolyDraw( hdc,
930 (const LPPOINT)lpPolyDraw->aptl,
931 lpPolyDraw->abTypes,
932 (INT)lpPolyDraw->cptl );
934 break;
937 case EMR_SETARCDIRECTION:
939 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
940 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
941 break;
944 case EMR_SETMITERLIMIT:
946 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
947 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
948 break;
951 case EMR_BEGINPATH:
953 BeginPath( hdc );
954 break;
957 case EMR_ENDPATH:
959 EndPath( hdc );
960 break;
963 case EMR_CLOSEFIGURE:
965 CloseFigure( hdc );
966 break;
969 case EMR_FILLPATH:
971 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
972 FillPath( hdc );
973 break;
976 case EMR_STROKEANDFILLPATH:
978 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
979 StrokeAndFillPath( hdc );
980 break;
983 case EMR_STROKEPATH:
985 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
986 StrokePath( hdc );
987 break;
990 case EMR_FLATTENPATH:
992 FlattenPath( hdc );
993 break;
996 case EMR_WIDENPATH:
998 WidenPath( hdc );
999 break;
1002 case EMR_SELECTCLIPPATH:
1004 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1005 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1006 break;
1009 case EMR_ABORTPATH:
1011 AbortPath( hdc );
1012 break;
1015 case EMR_CREATECOLORSPACE:
1017 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1018 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1019 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1020 break;
1023 case EMR_SETCOLORSPACE:
1025 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1026 SetColorSpace( hdc,
1027 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1028 break;
1031 case EMR_DELETECOLORSPACE:
1033 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1034 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1035 break;
1038 case EMR_SETICMMODE:
1040 PERMSETICMMODE lpSetICMMode = (PERMSETICMMODE)mr;
1041 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1042 break;
1045 case EMR_PIXELFORMAT:
1047 INT iPixelFormat;
1048 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1050 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1051 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1053 break;
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 );
1065 break;
1068 case EMR_RESIZEPALETTE:
1070 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1072 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1073 (UINT)lpResizePalette->cEntries );
1075 break;
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,
1089 lpCreate->cbBmi );
1090 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1091 ((BYTE*)lpCreate) + lpCreate->offBits,
1092 lpCreate->cbBits );
1094 (handletable->objectHandle)[lpCreate->ihBrush] =
1095 CreateDIBPatternBrushPt( lpPackedStruct,
1096 (UINT)lpCreate->iUsage );
1098 break;
1101 case EMR_BITBLT:
1102 case EMR_STRETCHBLT:
1103 case EMR_MASKBLT:
1104 case EMR_PLGBLT:
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:
1115 case EMR_FILLRGN:
1116 case EMR_FRAMERGN:
1117 case EMR_INVERTRGN:
1118 case EMR_PAINTRGN:
1119 case EMR_GLSRECORD:
1120 case EMR_GLSBOUNDEDRECORD:
1121 default:
1122 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1123 record then ignore and return TRUE. */
1124 FIXME("type %d is unimplemented\n", type);
1125 break;
1127 return TRUE;
1131 /*****************************************************************************
1133 * EnumEnhMetaFile (GDI32.79)
1135 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1136 * for each
1137 * record. Returns when either every record has been used or
1138 * when _EnhMetaFunc_ returns FALSE.
1141 * RETURNS
1142 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1143 * returns FALSE.
1145 * BUGS
1146 * Ignores rect.
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 */
1156 BOOL ret = TRUE;
1157 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
1158 INT count, i;
1159 HANDLETABLE *ht;
1160 INT savedMode = 0;
1161 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1162 XFORM savedXform, xform;
1164 if(!emh) {
1165 SetLastError(ERROR_INVALID_HANDLE);
1166 return FALSE;
1168 if(!lpRect) {
1169 SetLastError(ERROR_INVALID_PARAMETER);
1170 return FALSE;
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;
1185 xform.eM12 = 0;
1186 xform.eM21 = 0;
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");
1199 while (ret) {
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);
1211 return ret;
1214 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
1215 ENHMETARECORD *emr,
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,
1235 lpRect);
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,
1255 LPCSTR file)
1257 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
1258 HENHMETAFILE hmfDst;
1260 if(!emrSrc) return FALSE;
1261 if (!file) {
1262 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
1263 memcpy( emrDst, emrSrc, emrSrc->nBytes );
1264 hmfDst = EMF_Create_HENHMETAFILE( emrDst, 0, 0 );
1265 } else {
1266 HFILE hFile;
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 );
1273 return hmfDst;
1277 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1278 typedef struct tagEMF_PaletteCopy
1280 UINT cEntries;
1281 LPPALETTEENTRY lpPe;
1282 } EMF_PaletteCopy;
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
1289 * to copy them to.
1291 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1293 INT CALLBACK cbEnhPaletteCopy( HDC a,
1294 LPHANDLETABLE b,
1295 LPENHMETARECORD lpEMR,
1296 INT c,
1297 LPVOID lpData )
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 */
1319 return TRUE;
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,
1330 UINT cEntries,
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
1340 this metafile. */
1341 if ( enhHeader->nPalEntries == 0 )
1343 /* No palette associated with this enhanced metafile */
1344 uReturnValue = 0;
1345 goto done;
1348 /* Is the user requesting the number of palettes? */
1349 if ( lpPe == NULL )
1351 uReturnValue = (UINT)enhHeader->nPalEntries;
1352 goto done;
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 ) )
1362 goto done;
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" );
1370 goto done;
1373 uReturnValue = infoForCallBack.cEntries;
1375 done:
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,
1393 HDC hdcRef,
1394 CONST METAFILEPICT *lpmfp
1397 HENHMETAFILE hMf;
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 )
1412 goto error;
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 */
1437 /* dSignature
1438 nVersion
1439 nRecords
1440 sReserved
1441 nDescription
1442 offDescription
1443 nPalEntries
1444 szlDevice
1445 szlMillimeters
1446 cbPixelFormat
1447 offPixelFormat,
1448 bOpenGL */
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 */
1454 while( !bFoundEOF )
1457 LPMETARECORD lpMetaRecord = (LPMETARECORD)lpbBuffer;
1459 #define EMF_ReAllocAndAdjustPointers( a , b ) \
1461 LPVOID lpTmp; \
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 )
1473 case META_EOF:
1475 PEMREOF lpRecord;
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 */
1488 bFoundEOF = TRUE;
1490 FIXME( "META_EOF conversion not correct\n" );
1491 break;
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];
1506 break;
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;
1521 else
1523 lpRecord->emr.iType = EMR_SELECTOBJECT;
1525 lpRecord->emr.nSize = sizeof( *lpRecord );
1527 lpRecord->ihObject = lpMetaRecord->rdParm[0]; /* FIXME: Handle */
1529 break;
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;
1548 lpRecord->cpts = 0;
1549 lpRecord->apts[0].x = 0;
1550 lpRecord->apts[0].y = 0;
1552 FIXME( "META_POLYGON conversion not correct\n" );
1554 break;
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];
1569 break;
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];
1585 break;
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;
1600 else
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];
1609 break;
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 */
1629 break;
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:
1636 case META_SETROP2:
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:
1645 case META_LINETO:
1646 case META_MOVETO:
1647 case META_EXCLUDECLIPRECT:
1648 case META_INTERSECTCLIPRECT:
1649 case META_ARC:
1650 case META_ELLIPSE:
1651 case META_FLOODFILL:
1652 case META_PIE:
1653 case META_RECTANGLE:
1654 case META_ROUNDRECT:
1655 case META_PATBLT:
1656 case META_SAVEDC:
1657 case META_SETPIXEL:
1658 case META_OFFSETCLIPRGN:
1659 case META_TEXTOUT:
1660 case META_POLYPOLYGON:
1661 case META_POLYLINE:
1662 case META_RESTOREDC:
1663 case META_CHORD:
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:
1672 case META_ESCAPE:
1673 case META_EXTTEXTOUT:
1674 case META_STRETCHDIB:
1675 case META_DIBSTRETCHBLT:
1676 case META_STRETCHBLT:
1677 case META_BITBLT:
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:
1690 case META_DRAWTEXT:
1691 case META_ANIMATEPALETTE:
1692 case META_SETPALENTRIES:
1693 case META_RESIZEPALETTE:
1694 case META_RESETDC:
1695 case META_STARTDOC:
1696 case META_STARTPAGE:
1697 case META_ENDPAGE:
1698 case META_ABORTDOC:
1699 case META_ENDDOC:
1700 case META_CREATEBRUSH:
1701 case META_CREATEBITMAPINDIRECT:
1702 case META_CREATEBITMAP:
1703 /* Fall through to unimplemented */
1704 default:
1706 /* Not implemented yet */
1707 FIXME( "Conversion of record type 0x%x not implemented.\n", lpMetaRecord->rdFunction );
1708 break;
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 );
1724 if( !hMf )
1725 ERR( "Problem creating metafile. Did the conversion fail somewhere?\n" );
1727 return hMf;
1729 error:
1730 /* Free the data associated with our copy since it's been copied */
1731 HeapFree( GetProcessHeap(), 0, lpNewEnhMetaFileBuffer );
1733 return 0;