Release 20020904.
[wine/gsoc-2012-control.git] / objects / enhmetafile.c
blob9a99c9d1679efa7490046089c0b00a48fe292c18
1 /*
2 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
4 * 1999 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * NOTES:
22 * The enhanced format consists of the following elements:
24 * A header
25 * A table of handles to GDI objects
26 * An array of metafile records
27 * A private palette
30 * The standard format consists of a header and an array of metafile records.
34 #include "config.h"
35 #include "wine/port.h"
37 #include <string.h>
38 #include <assert.h>
39 #include "winnls.h"
40 #include "winbase.h"
41 #include "wingdi.h"
42 #include "winerror.h"
43 #include "gdi.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
48 typedef struct
50 GDIOBJHDR header;
51 ENHMETAHEADER *emh;
52 BOOL on_disk; /* true if metafile is on disk */
53 } ENHMETAFILEOBJ;
56 /****************************************************************************
57 * EMF_Create_HENHMETAFILE
59 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk )
61 HENHMETAFILE hmf = 0;
62 ENHMETAFILEOBJ *metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
63 ENHMETAFILE_MAGIC, &hmf, NULL );
64 if (metaObj)
66 metaObj->emh = emh;
67 metaObj->on_disk = on_disk;
68 GDI_ReleaseObj( hmf );
70 return hmf;
73 /****************************************************************************
74 * EMF_Delete_HENHMETAFILE
76 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
78 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
79 ENHMETAFILE_MAGIC );
80 if(!metaObj) return FALSE;
82 if(metaObj->on_disk)
83 UnmapViewOfFile( metaObj->emh );
84 else
85 HeapFree( GetProcessHeap(), 0, metaObj->emh );
86 return GDI_FreeObject( hmf, metaObj );
89 /******************************************************************
90 * EMF_GetEnhMetaHeader
92 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
94 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
96 ENHMETAHEADER *ret = NULL;
97 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
98 TRACE("hmf %04x -> enhmetaObj %p\n", hmf, metaObj);
99 if (metaObj)
101 ret = metaObj->emh;
102 GDI_ReleaseObj( hmf );
104 return ret;
107 /*****************************************************************************
108 * EMF_GetEnhMetaFile
111 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
113 ENHMETAHEADER *emh;
114 HANDLE hMapping;
116 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
117 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
118 CloseHandle( hMapping );
120 if (!emh) return 0;
122 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
123 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
124 emh->iType, emh->dSignature);
125 UnmapViewOfFile( emh );
126 return 0;
128 return EMF_Create_HENHMETAFILE( emh, TRUE );
132 /*****************************************************************************
133 * GetEnhMetaFileA (GDI32.@)
137 HENHMETAFILE WINAPI GetEnhMetaFileA(
138 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
141 HENHMETAFILE hmf;
142 HANDLE hFile;
144 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
145 OPEN_EXISTING, 0, 0);
146 if (hFile == INVALID_HANDLE_VALUE) {
147 WARN("could not open %s\n", lpszMetaFile);
148 return 0;
150 hmf = EMF_GetEnhMetaFile( hFile );
151 CloseHandle( hFile );
152 return hmf;
155 /*****************************************************************************
156 * GetEnhMetaFileW (GDI32.@)
158 HENHMETAFILE WINAPI GetEnhMetaFileW(
159 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
161 HENHMETAFILE hmf;
162 HANDLE hFile;
164 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
165 OPEN_EXISTING, 0, 0);
166 if (hFile == INVALID_HANDLE_VALUE) {
167 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
168 return 0;
170 hmf = EMF_GetEnhMetaFile( hFile );
171 CloseHandle( hFile );
172 return hmf;
175 /*****************************************************************************
176 * GetEnhMetaFileHeader (GDI32.@)
178 * If buf is NULL, returns the size of buffer required.
179 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
180 * buf.
182 UINT WINAPI GetEnhMetaFileHeader(
183 HENHMETAFILE hmf, /* [in] enhanced metafile */
184 UINT bufsize, /* [in] size of buffer */
185 LPENHMETAHEADER buf /* [out] buffer */
188 LPENHMETAHEADER emh;
189 UINT size;
191 emh = EMF_GetEnhMetaHeader(hmf);
192 if(!emh) return FALSE;
193 size = emh->nSize;
194 if (!buf) return size;
195 size = min(size, bufsize);
196 memmove(buf, emh, size);
197 return size;
201 /*****************************************************************************
202 * GetEnhMetaFileDescriptionA (GDI32.@)
204 UINT WINAPI GetEnhMetaFileDescriptionA(
205 HENHMETAFILE hmf, /* [in] enhanced metafile */
206 UINT size, /* [in] size of buf */
207 LPSTR buf /* [out] buffer to receive description */
210 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
211 DWORD len;
212 WCHAR *descrW;
214 if(!emh) return FALSE;
215 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
216 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
217 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
219 if (!buf || !size ) return len;
221 len = min( size, len );
222 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
223 return len;
226 /*****************************************************************************
227 * GetEnhMetaFileDescriptionW (GDI32.@)
229 * Copies the description string of an enhanced metafile into a buffer
230 * _buf_.
232 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
233 * number of characters copied.
235 UINT WINAPI GetEnhMetaFileDescriptionW(
236 HENHMETAFILE hmf, /* [in] enhanced metafile */
237 UINT size, /* [in] size of buf */
238 LPWSTR buf /* [out] buffer to receive description */
241 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
243 if(!emh) return FALSE;
244 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
245 if (!buf || !size ) return emh->nDescription;
247 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
248 return min(size, emh->nDescription);
251 /****************************************************************************
252 * SetEnhMetaFileBits (GDI32.@)
254 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
256 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
258 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
259 memmove(emh, buf, bufsize);
260 return EMF_Create_HENHMETAFILE( emh, FALSE );
263 /*****************************************************************************
264 * GetEnhMetaFileBits (GDI32.@)
267 UINT WINAPI GetEnhMetaFileBits(
268 HENHMETAFILE hmf,
269 UINT bufsize,
270 LPBYTE buf
273 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
274 UINT size;
276 if(!emh) return 0;
278 size = emh->nBytes;
279 if( buf == NULL ) return size;
281 size = min( size, bufsize );
282 memmove(buf, emh, size);
283 return size;
286 /*****************************************************************************
287 * PlayEnhMetaFileRecord (GDI32.@)
289 * Render a single enhanced metafile record in the device context hdc.
291 * RETURNS
292 * TRUE (non zero) on success, FALSE on error.
293 * BUGS
294 * Many unimplemented records.
295 * No error handling on record play failures (ie checking return codes)
297 BOOL WINAPI PlayEnhMetaFileRecord(
298 HDC hdc, /* [in] device context in which to render EMF record */
299 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
300 const ENHMETARECORD *mr, /* [in] EMF record to render */
301 UINT handles /* [in] size of handle array */
304 int type;
305 RECT tmprc;
307 TRACE(
308 "hdc = %08x, handletable = %p, record = %p, numHandles = %d\n",
309 hdc, handletable, mr, handles);
310 if (!mr) return FALSE;
312 type = mr->iType;
314 TRACE(" type=%d\n", type);
315 switch(type)
317 case EMR_HEADER:
318 break;
319 case EMR_EOF:
320 break;
321 case EMR_GDICOMMENT:
323 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
324 /* In an enhanced metafile, there can be both public and private GDI comments */
325 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
326 break;
328 case EMR_SETMAPMODE:
330 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
331 SetMapMode(hdc, pSetMapMode->iMode);
332 break;
334 case EMR_SETBKMODE:
336 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
337 SetBkMode(hdc, pSetBkMode->iMode);
338 break;
340 case EMR_SETBKCOLOR:
342 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
343 SetBkColor(hdc, pSetBkColor->crColor);
344 break;
346 case EMR_SETPOLYFILLMODE:
348 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
349 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
350 break;
352 case EMR_SETROP2:
354 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
355 SetROP2(hdc, pSetROP2->iMode);
356 break;
358 case EMR_SETSTRETCHBLTMODE:
360 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
361 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
362 break;
364 case EMR_SETTEXTALIGN:
366 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
367 SetTextAlign(hdc, pSetTextAlign->iMode);
368 break;
370 case EMR_SETTEXTCOLOR:
372 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
373 SetTextColor(hdc, pSetTextColor->crColor);
374 break;
376 case EMR_SAVEDC:
378 SaveDC(hdc);
379 break;
381 case EMR_RESTOREDC:
383 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
384 RestoreDC(hdc, pRestoreDC->iRelative);
385 break;
387 case EMR_INTERSECTCLIPRECT:
389 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
390 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
391 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
392 break;
394 case EMR_SELECTOBJECT:
396 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
397 if( pSelectObject->ihObject & 0x80000000 ) {
398 /* High order bit is set - it's a stock object
399 * Strip the high bit to get the index.
400 * See MSDN article Q142319
402 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
403 0x7fffffff ) );
404 } else {
405 /* High order bit wasn't set - not a stock object
407 SelectObject( hdc,
408 (handletable->objectHandle)[pSelectObject->ihObject] );
410 break;
412 case EMR_DELETEOBJECT:
414 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
415 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
416 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
417 break;
419 case EMR_SETWINDOWORGEX:
421 XFORM xform;
422 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
424 xform.eM11 = 1;
425 xform.eM12 = 0;
426 xform.eM21 = 0;
427 xform.eM22 = 1;
428 xform.eDx = -pSetWindowOrgEx->ptlOrigin.x;
429 xform.eDy = -pSetWindowOrgEx->ptlOrigin.y;
431 ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
432 break;
434 case EMR_SETWINDOWEXTEX:
436 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
437 SetWindowExtEx(hdc, pSetWindowExtEx->szlExtent.cx,
438 pSetWindowExtEx->szlExtent.cy, NULL);
439 break;
441 case EMR_SETVIEWPORTORGEX:
443 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
444 SetViewportOrgEx(hdc, pSetViewportOrgEx->ptlOrigin.x,
445 pSetViewportOrgEx->ptlOrigin.y, NULL);
446 break;
448 case EMR_SETVIEWPORTEXTEX:
450 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
451 SetViewportExtEx(hdc, pSetViewportExtEx->szlExtent.cx,
452 pSetViewportExtEx->szlExtent.cy, NULL);
453 break;
455 case EMR_CREATEPEN:
457 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
458 (handletable->objectHandle)[pCreatePen->ihPen] =
459 CreatePenIndirect(&pCreatePen->lopn);
460 break;
462 case EMR_EXTCREATEPEN:
464 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
465 LOGBRUSH lb;
466 lb.lbStyle = pPen->elp.elpBrushStyle;
467 lb.lbColor = pPen->elp.elpColor;
468 lb.lbHatch = pPen->elp.elpHatch;
470 if(pPen->offBmi || pPen->offBits)
471 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
473 (handletable->objectHandle)[pPen->ihPen] =
474 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
475 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
476 break;
478 case EMR_CREATEBRUSHINDIRECT:
480 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
481 (handletable->objectHandle)[pBrush->ihBrush] =
482 CreateBrushIndirect(&pBrush->lb);
483 break;
485 case EMR_EXTCREATEFONTINDIRECTW:
487 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
488 (handletable->objectHandle)[pFont->ihFont] =
489 CreateFontIndirectW(&pFont->elfw.elfLogFont);
490 break;
492 case EMR_MOVETOEX:
494 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
495 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
496 break;
498 case EMR_LINETO:
500 PEMRLINETO pLineTo = (PEMRLINETO) mr;
501 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
502 break;
504 case EMR_RECTANGLE:
506 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
507 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
508 pRect->rclBox.right, pRect->rclBox.bottom);
509 break;
511 case EMR_ELLIPSE:
513 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
514 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
515 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
516 break;
518 case EMR_POLYGON16:
520 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
521 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
522 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
523 pPoly->cpts * sizeof(POINT) );
524 DWORD i;
525 for(i = 0; i < pPoly->cpts; i++)
526 CONV_POINT16TO32(pPoly->apts + i, pts + i);
527 Polygon(hdc, pts, pPoly->cpts);
528 HeapFree( GetProcessHeap(), 0, pts );
529 break;
531 case EMR_POLYLINE16:
533 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
534 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
535 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
536 pPoly->cpts * sizeof(POINT) );
537 DWORD i;
538 for(i = 0; i < pPoly->cpts; i++)
539 CONV_POINT16TO32(pPoly->apts + i, pts + i);
540 Polyline(hdc, pts, pPoly->cpts);
541 HeapFree( GetProcessHeap(), 0, pts );
542 break;
544 case EMR_POLYLINETO16:
546 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
547 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
548 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
549 pPoly->cpts * sizeof(POINT) );
550 DWORD i;
551 for(i = 0; i < pPoly->cpts; i++)
552 CONV_POINT16TO32(pPoly->apts + i, pts + i);
553 PolylineTo(hdc, pts, pPoly->cpts);
554 HeapFree( GetProcessHeap(), 0, pts );
555 break;
557 case EMR_POLYBEZIER16:
559 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
560 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
561 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
562 pPoly->cpts * sizeof(POINT) );
563 DWORD i;
564 for(i = 0; i < pPoly->cpts; i++)
565 CONV_POINT16TO32(pPoly->apts + i, pts + i);
566 PolyBezier(hdc, pts, pPoly->cpts);
567 HeapFree( GetProcessHeap(), 0, pts );
568 break;
570 case EMR_POLYBEZIERTO16:
572 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
573 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
574 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
575 pPoly->cpts * sizeof(POINT) );
576 DWORD i;
577 for(i = 0; i < pPoly->cpts; i++)
578 CONV_POINT16TO32(pPoly->apts + i, pts + i);
579 PolyBezierTo(hdc, pts, pPoly->cpts);
580 HeapFree( GetProcessHeap(), 0, pts );
581 break;
583 case EMR_POLYPOLYGON16:
585 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
586 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
587 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
589 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
590 pPolyPoly->cpts * sizeof(POINT) );
591 DWORD i;
592 for(i = 0; i < pPolyPoly->cpts; i++)
593 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
594 pPolyPoly->nPolys) + i, pts + i);
596 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
597 HeapFree( GetProcessHeap(), 0, pts );
598 break;
600 case EMR_POLYPOLYLINE16:
602 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
603 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
604 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
606 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
607 pPolyPoly->cpts * sizeof(POINT) );
608 DWORD i;
609 for(i = 0; i < pPolyPoly->cpts; i++)
610 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
611 pPolyPoly->nPolys) + i, pts + i);
613 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
614 HeapFree( GetProcessHeap(), 0, pts );
615 break;
618 case EMR_STRETCHDIBITS:
620 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
622 StretchDIBits(hdc,
623 pStretchDIBits->xDest,
624 pStretchDIBits->yDest,
625 pStretchDIBits->cxDest,
626 pStretchDIBits->cyDest,
627 pStretchDIBits->xSrc,
628 pStretchDIBits->ySrc,
629 pStretchDIBits->cxSrc,
630 pStretchDIBits->cySrc,
631 (BYTE *)mr + pStretchDIBits->offBitsSrc,
632 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
633 pStretchDIBits->iUsageSrc,
634 pStretchDIBits->dwRop);
635 break;
638 case EMR_EXTTEXTOUTA:
640 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
641 RECT rc;
643 rc.left = pExtTextOutA->emrtext.rcl.left;
644 rc.top = pExtTextOutA->emrtext.rcl.top;
645 rc.right = pExtTextOutA->emrtext.rcl.right;
646 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
647 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
648 pExtTextOutA->emrtext.fOptions, &rc,
649 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
650 (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx));
651 break;
654 case EMR_EXTTEXTOUTW:
656 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
657 RECT rc;
659 rc.left = pExtTextOutW->emrtext.rcl.left;
660 rc.top = pExtTextOutW->emrtext.rcl.top;
661 rc.right = pExtTextOutW->emrtext.rcl.right;
662 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
663 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
664 pExtTextOutW->emrtext.fOptions, &rc,
665 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
666 (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx));
667 break;
670 case EMR_CREATEPALETTE:
672 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
674 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
675 CreatePalette( &lpCreatePal->lgpl );
677 break;
680 case EMR_SELECTPALETTE:
682 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
684 if( lpSelectPal->ihPal & 0x80000000 ) {
685 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
686 } else {
687 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
688 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
690 break;
693 case EMR_REALIZEPALETTE:
695 RealizePalette( hdc );
696 break;
699 case EMR_EXTSELECTCLIPRGN:
701 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
702 HRGN hRgn = ExtCreateRegion(NULL, lpRgn->cbRgnData, (RGNDATA *)lpRgn->RgnData);
703 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
704 /* ExtSelectClipRgn created a copy of the region */
705 DeleteObject(hRgn);
706 break;
709 case EMR_SETMETARGN:
711 SetMetaRgn( hdc );
712 break;
715 case EMR_SETWORLDTRANSFORM:
717 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
718 SetWorldTransform( hdc, &lpXfrm->xform );
719 break;
722 case EMR_POLYBEZIER:
724 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
725 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
726 break;
729 case EMR_POLYGON:
731 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
732 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
733 break;
736 case EMR_POLYLINE:
738 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
739 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
740 break;
743 case EMR_POLYBEZIERTO:
745 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
746 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
747 (UINT)lpPolyBezierTo->cptl );
748 break;
751 case EMR_POLYLINETO:
753 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
754 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
755 (UINT)lpPolyLineTo->cptl );
756 break;
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 );
769 break;
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 );
781 break;
784 case EMR_SETBRUSHORGEX:
786 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
788 SetBrushOrgEx( hdc,
789 (INT)lpSetBrushOrgEx->ptlOrigin.x,
790 (INT)lpSetBrushOrgEx->ptlOrigin.y,
791 NULL );
793 break;
796 case EMR_SETPIXELV:
798 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
800 SetPixelV( hdc,
801 (INT)lpSetPixelV->ptlPixel.x,
802 (INT)lpSetPixelV->ptlPixel.y,
803 lpSetPixelV->crColor );
805 break;
808 case EMR_SETMAPPERFLAGS:
810 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
812 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
814 break;
817 case EMR_SETCOLORADJUSTMENT:
819 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
821 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
823 break;
826 case EMR_OFFSETCLIPRGN:
828 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
830 OffsetClipRgn( hdc,
831 (INT)lpOffsetClipRgn->ptlOffset.x,
832 (INT)lpOffsetClipRgn->ptlOffset.y );
834 break;
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 );
847 break;
850 case EMR_SCALEVIEWPORTEXTEX:
852 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
854 ScaleViewportExtEx( hdc,
855 lpScaleViewportExtEx->xNum,
856 lpScaleViewportExtEx->xDenom,
857 lpScaleViewportExtEx->yNum,
858 lpScaleViewportExtEx->yDenom,
859 NULL );
861 break;
864 case EMR_SCALEWINDOWEXTEX:
866 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
868 ScaleWindowExtEx( hdc,
869 lpScaleWindowExtEx->xNum,
870 lpScaleWindowExtEx->xDenom,
871 lpScaleWindowExtEx->yNum,
872 lpScaleWindowExtEx->yDenom,
873 NULL );
875 break;
878 case EMR_MODIFYWORLDTRANSFORM:
880 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
882 ModifyWorldTransform( hdc, &lpModifyWorldTrans->xform,
883 lpModifyWorldTrans->iMode );
885 break;
888 case EMR_ANGLEARC:
890 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
892 AngleArc( hdc,
893 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
894 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
895 lpAngleArc->eSweepAngle );
897 break;
900 case EMR_ROUNDRECT:
902 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
904 RoundRect( hdc,
905 lpRoundRect->rclBox.left,
906 lpRoundRect->rclBox.top,
907 lpRoundRect->rclBox.right,
908 lpRoundRect->rclBox.bottom,
909 lpRoundRect->szlCorner.cx,
910 lpRoundRect->szlCorner.cy );
912 break;
915 case EMR_ARC:
917 PEMRARC lpArc = (PEMRARC)mr;
919 Arc( hdc,
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 );
929 break;
932 case EMR_CHORD:
934 PEMRCHORD lpChord = (PEMRCHORD)mr;
936 Chord( hdc,
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 );
946 break;
949 case EMR_PIE:
951 PEMRPIE lpPie = (PEMRPIE)mr;
953 Pie( hdc,
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 );
963 break;
966 case EMR_ARCTO:
968 PEMRARC lpArcTo = (PEMRARC)mr;
970 ArcTo( hdc,
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 );
980 break;
983 case EMR_EXTFLOODFILL:
985 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
987 ExtFloodFill( hdc,
988 (INT)lpExtFloodFill->ptlStart.x,
989 (INT)lpExtFloodFill->ptlStart.y,
990 lpExtFloodFill->crColor,
991 (UINT)lpExtFloodFill->iMode );
993 break;
996 case EMR_POLYDRAW:
998 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
999 PolyDraw( hdc,
1000 (const LPPOINT)lpPolyDraw->aptl,
1001 lpPolyDraw->abTypes,
1002 (INT)lpPolyDraw->cptl );
1004 break;
1007 case EMR_SETARCDIRECTION:
1009 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1010 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1011 break;
1014 case EMR_SETMITERLIMIT:
1016 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1017 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1018 break;
1021 case EMR_BEGINPATH:
1023 BeginPath( hdc );
1024 break;
1027 case EMR_ENDPATH:
1029 EndPath( hdc );
1030 break;
1033 case EMR_CLOSEFIGURE:
1035 CloseFigure( hdc );
1036 break;
1039 case EMR_FILLPATH:
1041 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1042 FillPath( hdc );
1043 break;
1046 case EMR_STROKEANDFILLPATH:
1048 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1049 StrokeAndFillPath( hdc );
1050 break;
1053 case EMR_STROKEPATH:
1055 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1056 StrokePath( hdc );
1057 break;
1060 case EMR_FLATTENPATH:
1062 FlattenPath( hdc );
1063 break;
1066 case EMR_WIDENPATH:
1068 WidenPath( hdc );
1069 break;
1072 case EMR_SELECTCLIPPATH:
1074 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1075 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1076 break;
1079 case EMR_ABORTPATH:
1081 AbortPath( hdc );
1082 break;
1085 case EMR_CREATECOLORSPACE:
1087 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1088 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1089 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1090 break;
1093 case EMR_SETCOLORSPACE:
1095 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1096 SetColorSpace( hdc,
1097 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1098 break;
1101 case EMR_DELETECOLORSPACE:
1103 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1104 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1105 break;
1108 case EMR_SETICMMODE:
1110 PERMSETICMMODE lpSetICMMode = (PERMSETICMMODE)mr;
1111 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1112 break;
1115 case EMR_PIXELFORMAT:
1117 INT iPixelFormat;
1118 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1120 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1121 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1123 break;
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 );
1135 break;
1138 case EMR_RESIZEPALETTE:
1140 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1142 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1143 (UINT)lpResizePalette->cEntries );
1145 break;
1148 case EMR_CREATEDIBPATTERNBRUSHPT:
1150 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1151 LPVOID lpPackedStruct;
1153 /* check that offsets and data are contained within the record */
1154 if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
1155 (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
1156 ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
1157 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
1159 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1160 break;
1163 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1164 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1165 lpCreate->cbBmi + lpCreate->cbBits );
1166 if(!lpPackedStruct)
1168 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1169 break;
1172 /* Now pack this structure */
1173 memcpy( lpPackedStruct,
1174 ((BYTE*)lpCreate) + lpCreate->offBmi,
1175 lpCreate->cbBmi );
1176 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1177 ((BYTE*)lpCreate) + lpCreate->offBits,
1178 lpCreate->cbBits );
1180 (handletable->objectHandle)[lpCreate->ihBrush] =
1181 CreateDIBPatternBrushPt( lpPackedStruct,
1182 (UINT)lpCreate->iUsage );
1184 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1186 break;
1189 case EMR_CREATEMONOBRUSH:
1191 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1192 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1193 HBITMAP hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1194 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1195 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1196 /* CreatePatternBrush created a copy of the bitmap */
1197 DeleteObject(hBmp);
1198 break;
1201 case EMR_BITBLT:
1203 PEMRBITBLT pBitBlt = (PEMRBITBLT)mr;
1204 HDC hdcSrc = CreateCompatibleDC(hdc);
1205 HBRUSH hBrush, hBrushOld;
1206 HBITMAP hBmp = 0, hBmpOld = 0;
1207 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pBitBlt->offBmiSrc);
1209 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1211 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1212 hBrushOld = SelectObject(hdcSrc, hBrush);
1213 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1214 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1215 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1216 SelectObject(hdcSrc, hBrushOld);
1217 DeleteObject(hBrush);
1219 if (pBitBlt->offBmiSrc > 0)
1221 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1222 (BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1223 hBmpOld = SelectObject(hdcSrc, hBmp);
1226 BitBlt(hdc,
1227 pBitBlt->xDest,
1228 pBitBlt->yDest,
1229 pBitBlt->cxDest,
1230 pBitBlt->cyDest,
1231 hdcSrc,
1232 pBitBlt->xSrc,
1233 pBitBlt->ySrc,
1234 pBitBlt->dwRop);
1236 if (pBitBlt->offBmiSrc > 0)
1238 SelectObject(hdcSrc, hBmpOld);
1239 DeleteObject(hBmp);
1241 DeleteDC(hdcSrc);
1242 break;
1245 case EMR_STRETCHBLT:
1247 PEMRSTRETCHBLT pStretchBlt= (PEMRSTRETCHBLT)mr;
1248 HDC hdcSrc = CreateCompatibleDC(hdc);
1249 HBRUSH hBrush, hBrushOld;
1250 HBITMAP hBmp = 0, hBmpOld = 0;
1251 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pStretchBlt->offBmiSrc);
1253 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1255 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1256 hBrushOld = SelectObject(hdcSrc, hBrush);
1257 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1258 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1259 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1260 SelectObject(hdcSrc, hBrushOld);
1261 DeleteObject(hBrush);
1263 if (pStretchBlt->offBmiSrc)
1265 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1266 (BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1267 hBmpOld = SelectObject(hdcSrc, hBmp);
1270 StretchBlt(hdc,
1271 pStretchBlt->xDest,
1272 pStretchBlt->yDest,
1273 pStretchBlt->cxDest,
1274 pStretchBlt->cyDest,
1275 hdcSrc,
1276 pStretchBlt->xSrc,
1277 pStretchBlt->ySrc,
1278 pStretchBlt->cxSrc,
1279 pStretchBlt->cySrc,
1280 pStretchBlt->dwRop);
1283 if (pStretchBlt->offBmiSrc)
1285 SelectObject(hdcSrc, hBmpOld);
1286 DeleteObject(hBmp);
1289 DeleteDC(hdcSrc);
1290 break;
1293 case EMR_MASKBLT:
1295 PEMRMASKBLT pMaskBlt= (PEMRMASKBLT)mr;
1296 HDC hdcSrc = CreateCompatibleDC(hdc);
1297 HBRUSH hBrush, hBrushOld;
1298 HBITMAP hBmp, hBmpOld, hBmpMask;
1299 BITMAPINFO *pbi;
1301 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1303 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1304 hBrushOld = SelectObject(hdcSrc, hBrush);
1305 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1306 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1307 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1308 SelectObject(hdcSrc, hBrushOld);
1309 DeleteObject(hBrush);
1311 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiMask);
1312 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1313 (BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1315 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiSrc);
1316 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1317 (BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1318 hBmpOld = SelectObject(hdcSrc, hBmp);
1319 MaskBlt(hdc,
1320 pMaskBlt->xDest,
1321 pMaskBlt->yDest,
1322 pMaskBlt->cxDest,
1323 pMaskBlt->cyDest,
1324 hdcSrc,
1325 pMaskBlt->xSrc,
1326 pMaskBlt->ySrc,
1327 hBmpMask,
1328 pMaskBlt->xMask,
1329 pMaskBlt->yMask,
1330 pMaskBlt->dwRop);
1331 SelectObject(hdcSrc, hBmpOld);
1332 DeleteObject(hBmp);
1333 DeleteObject(hBmpMask);
1334 DeleteDC(hdcSrc);
1335 break;
1338 case EMR_PLGBLT:
1340 PEMRPLGBLT pPlgBlt= (PEMRPLGBLT)mr;
1341 HDC hdcSrc = CreateCompatibleDC(hdc);
1342 HBRUSH hBrush, hBrushOld;
1343 HBITMAP hBmp, hBmpOld, hBmpMask;
1344 BITMAPINFO *pbi;
1345 POINT pts[3];
1347 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1349 pts[0].x = pPlgBlt->aptlDst[0].x; pts[0].y = pPlgBlt->aptlDst[0].y;
1350 pts[1].x = pPlgBlt->aptlDst[1].x; pts[1].y = pPlgBlt->aptlDst[1].y;
1351 pts[2].x = pPlgBlt->aptlDst[2].x; pts[2].y = pPlgBlt->aptlDst[2].y;
1353 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1354 hBrushOld = SelectObject(hdcSrc, hBrush);
1355 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1356 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1357 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1358 SelectObject(hdcSrc, hBrushOld);
1359 DeleteObject(hBrush);
1361 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiMask);
1362 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1363 (BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1365 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiSrc);
1366 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1367 (BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1368 hBmpOld = SelectObject(hdcSrc, hBmp);
1369 PlgBlt(hdc,
1370 pts,
1371 hdcSrc,
1372 pPlgBlt->xSrc,
1373 pPlgBlt->ySrc,
1374 pPlgBlt->cxSrc,
1375 pPlgBlt->cySrc,
1376 hBmpMask,
1377 pPlgBlt->xMask,
1378 pPlgBlt->yMask);
1379 SelectObject(hdcSrc, hBmpOld);
1380 DeleteObject(hBmp);
1381 DeleteObject(hBmpMask);
1382 DeleteDC(hdcSrc);
1383 break;
1386 case EMR_SETDIBITSTODEVICE:
1388 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice = (PEMRSETDIBITSTODEVICE)mr;
1390 SetDIBitsToDevice(hdc,
1391 pSetDIBitsToDevice->xDest,
1392 pSetDIBitsToDevice->yDest,
1393 pSetDIBitsToDevice->cxSrc,
1394 pSetDIBitsToDevice->cySrc,
1395 pSetDIBitsToDevice->xSrc,
1396 pSetDIBitsToDevice->ySrc,
1397 pSetDIBitsToDevice->iStartScan,
1398 pSetDIBitsToDevice->cScans,
1399 (BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
1400 (BITMAPINFO *)((BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
1401 pSetDIBitsToDevice->iUsageSrc);
1402 break;
1405 case EMR_POLYTEXTOUTA:
1407 PEMRPOLYTEXTOUTA pPolyTextOutA = (PEMRPOLYTEXTOUTA)mr;
1408 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
1409 LONG i;
1410 XFORM xform, xformOld;
1411 int gModeOld;
1413 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
1414 GetWorldTransform(hdc, &xformOld);
1416 xform.eM11 = pPolyTextOutA->exScale;
1417 xform.eM12 = 0.0;
1418 xform.eM21 = 0.0;
1419 xform.eM22 = pPolyTextOutA->eyScale;
1420 xform.eDx = 0.0;
1421 xform.eDy = 0.0;
1422 SetWorldTransform(hdc, &xform);
1424 /* Set up POLYTEXTA structures */
1425 for(i = 0; i < pPolyTextOutA->cStrings; i++)
1427 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
1428 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
1429 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
1430 polytextA[i].lpstr = (LPSTR)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
1431 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
1432 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
1433 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
1434 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
1435 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
1436 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
1438 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
1439 HeapFree(GetProcessHeap(), 0, polytextA);
1441 SetWorldTransform(hdc, &xformOld);
1442 SetGraphicsMode(hdc, gModeOld);
1443 break;
1446 case EMR_POLYTEXTOUTW:
1448 PEMRPOLYTEXTOUTW pPolyTextOutW = (PEMRPOLYTEXTOUTW)mr;
1449 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
1450 LONG i;
1451 XFORM xform, xformOld;
1452 int gModeOld;
1454 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
1455 GetWorldTransform(hdc, &xformOld);
1457 xform.eM11 = pPolyTextOutW->exScale;
1458 xform.eM12 = 0.0;
1459 xform.eM21 = 0.0;
1460 xform.eM22 = pPolyTextOutW->eyScale;
1461 xform.eDx = 0.0;
1462 xform.eDy = 0.0;
1463 SetWorldTransform(hdc, &xform);
1465 /* Set up POLYTEXTW structures */
1466 for(i = 0; i < pPolyTextOutW->cStrings; i++)
1468 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
1469 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
1470 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
1471 polytextW[i].lpstr = (LPWSTR)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
1472 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
1473 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
1474 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
1475 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
1476 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
1477 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
1479 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
1480 HeapFree(GetProcessHeap(), 0, polytextW);
1482 SetWorldTransform(hdc, &xformOld);
1483 SetGraphicsMode(hdc, gModeOld);
1484 break;
1487 case EMR_FILLRGN:
1489 PEMRFILLRGN pFillRgn = (PEMRFILLRGN)mr;
1490 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
1491 FillRgn(hdc,
1492 hRgn,
1493 (handletable->objectHandle)[pFillRgn->ihBrush]);
1494 DeleteObject(hRgn);
1495 break;
1498 case EMR_FRAMERGN:
1500 PEMRFRAMERGN pFrameRgn = (PEMRFRAMERGN)mr;
1501 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
1502 FrameRgn(hdc,
1503 hRgn,
1504 (handletable->objectHandle)[pFrameRgn->ihBrush],
1505 pFrameRgn->szlStroke.cx,
1506 pFrameRgn->szlStroke.cy);
1507 DeleteObject(hRgn);
1508 break;
1511 case EMR_INVERTRGN:
1513 PEMRINVERTRGN pInvertRgn = (PEMRINVERTRGN)mr;
1514 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
1515 InvertRgn(hdc, hRgn);
1516 DeleteObject(hRgn);
1517 break;
1520 case EMR_PAINTRGN:
1522 PEMRPAINTRGN pPaintRgn = (PEMRPAINTRGN)mr;
1523 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
1524 PaintRgn(hdc, hRgn);
1525 DeleteObject(hRgn);
1526 break;
1529 case EMR_SETTEXTJUSTIFICATION:
1531 PEMRSETTEXTJUSTIFICATION pSetTextJust = (PEMRSETTEXTJUSTIFICATION)mr;
1532 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
1533 break;
1536 case EMR_SETLAYOUT:
1538 PEMRSETLAYOUT pSetLayout = (PEMRSETLAYOUT)mr;
1539 SetLayout(hdc, pSetLayout->iMode);
1540 break;
1543 case EMR_POLYDRAW16:
1544 case EMR_GLSRECORD:
1545 case EMR_GLSBOUNDEDRECORD:
1546 case EMR_DRAWESCAPE :
1547 case EMR_EXTESCAPE:
1548 case EMR_STARTDOC:
1549 case EMR_SMALLTEXTOUT:
1550 case EMR_FORCEUFIMAPPING:
1551 case EMR_NAMEDESCAPE:
1552 case EMR_COLORCORRECTPALETTE:
1553 case EMR_SETICMPROFILEA:
1554 case EMR_SETICMPROFILEW:
1555 case EMR_ALPHABLEND:
1556 case EMR_TRANSPARENTBLT:
1557 case EMR_GRADIENTFILL:
1558 case EMR_SETLINKEDUFI:
1559 case EMR_COLORMATCHTOTARGETW:
1560 case EMR_CREATECOLORSPACEW:
1562 default:
1563 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1564 record then ignore and return TRUE. */
1565 FIXME("type %d is unimplemented\n", type);
1566 break;
1568 tmprc.left = tmprc.top = 0;
1569 tmprc.right = tmprc.bottom = 1000;
1570 LPtoDP(hdc, (POINT*)&tmprc, 2);
1571 TRACE("L:0,0 - 1000,1000 -> D:%d,%d - %d,%d\n", tmprc.left,
1572 tmprc.top, tmprc.right, tmprc.bottom);
1573 return TRUE;
1577 /*****************************************************************************
1579 * EnumEnhMetaFile (GDI32.@)
1581 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1582 * for each
1583 * record. Returns when either every record has been used or
1584 * when _EnhMetaFunc_ returns FALSE.
1587 * RETURNS
1588 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1589 * returns FALSE.
1591 * BUGS
1592 * Ignores rect.
1594 BOOL WINAPI EnumEnhMetaFile(
1595 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
1596 HENHMETAFILE hmf, /* [in] EMF to walk */
1597 ENHMFENUMPROC callback, /* [in] callback function */
1598 LPVOID data, /* [in] optional data for callback function */
1599 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
1602 BOOL ret;
1603 ENHMETAHEADER *emh;
1604 ENHMETARECORD *emr;
1605 DWORD offset;
1606 UINT i;
1607 HANDLETABLE *ht;
1608 INT savedMode = 0;
1609 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1610 XFORM savedXform, xform;
1611 HPEN hPen = (HPEN)NULL;
1612 HBRUSH hBrush = (HBRUSH)NULL;
1613 HFONT hFont = (HFONT)NULL;
1614 RECT tmprc;
1616 if(!lpRect)
1618 SetLastError(ERROR_INVALID_PARAMETER);
1619 return FALSE;
1622 emh = EMF_GetEnhMetaHeader(hmf);
1623 if(!emh) {
1624 SetLastError(ERROR_INVALID_HANDLE);
1625 return FALSE;
1628 ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1629 sizeof(HANDLETABLE) * emh->nHandles );
1630 if(!ht)
1632 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1633 return FALSE;
1635 ht->objectHandle[0] = hmf;
1637 if (hdc && (emh->rclFrame.right - emh->rclFrame.left) && (emh->rclFrame.bottom - emh->rclFrame.top))
1639 TRACE("rect: %d,%d - %d,%d. rclFrame: %ld,%ld - %ld,%ld\n",
1640 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
1641 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
1642 emh->rclFrame.bottom);
1644 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
1645 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
1646 xscale = (FLOAT)(lpRect->right - lpRect->left) * 100.0 /
1647 (emh->rclFrame.right - emh->rclFrame.left) * xSrcPixSize;
1648 yscale = (FLOAT)(lpRect->bottom - lpRect->top) * 100.0 /
1649 (emh->rclFrame.bottom - emh->rclFrame.top) * ySrcPixSize;
1651 xform.eM11 = xscale;
1652 xform.eM12 = 0;
1653 xform.eM21 = 0;
1654 xform.eM22 = yscale;
1655 xform.eDx = (FLOAT) lpRect->left - (lpRect->right - lpRect->left) *
1656 emh->rclFrame.left / (emh->rclFrame.right - emh->rclFrame.left);
1657 xform.eDy = (FLOAT) lpRect->top - (lpRect->bottom - lpRect->top) *
1658 emh->rclFrame.top / (emh->rclFrame.bottom - emh->rclFrame.top);
1660 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1661 GetWorldTransform(hdc, &savedXform);
1663 if (!ModifyWorldTransform(hdc, &xform, MWT_RIGHTMULTIPLY)) {
1664 ERR("World transform failed!\n");
1667 /* save the current pen, brush and font */
1668 hPen = GetCurrentObject(hdc, OBJ_PEN);
1669 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
1670 hFont = GetCurrentObject(hdc, OBJ_FONT);
1673 tmprc.left = tmprc.top = 0;
1674 tmprc.right = tmprc.bottom = 1000;
1675 LPtoDP(hdc, (POINT*)&tmprc, 2);
1676 TRACE("L:0,0-1000,1000 maps to D:%d,%d - %d,%d\n", tmprc.left, tmprc.top,
1677 tmprc.right, tmprc.bottom);
1678 TRACE("nSize = %ld, nBytes = %ld, nHandles = %d, nRecords = %ld, nPalEntries = %ld\n",
1679 emh->nSize, emh->nBytes, emh->nHandles, emh->nRecords, emh->nPalEntries);
1681 ret = TRUE;
1682 offset = 0;
1683 while(ret && offset < emh->nBytes)
1685 emr = (ENHMETARECORD *)((char *)emh + offset);
1686 TRACE("Calling EnumFunc with record type %ld, size %ld\n", emr->iType, emr->nSize);
1687 ret = (*callback)(hdc, ht, emr, emh->nHandles, data);
1688 offset += emr->nSize;
1691 if (hdc)
1693 /* restore pen, brush and font */
1694 SelectObject(hdc, hBrush);
1695 SelectObject(hdc, hPen);
1696 SelectObject(hdc, hFont);
1698 SetWorldTransform(hdc, &savedXform);
1699 if (savedMode)
1700 SetGraphicsMode(hdc, savedMode);
1703 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
1704 if( (ht->objectHandle)[i] )
1705 DeleteObject( (ht->objectHandle)[i] );
1707 HeapFree( GetProcessHeap(), 0, ht );
1708 return ret;
1711 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
1712 ENHMETARECORD *emr,
1713 INT handles, LPVOID data)
1715 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
1718 /**************************************************************************
1719 * PlayEnhMetaFile (GDI32.@)
1721 * Renders an enhanced metafile into a specified rectangle *lpRect
1722 * in device context hdc.
1725 BOOL WINAPI PlayEnhMetaFile(
1726 HDC hdc, /* [in] DC to render into */
1727 HENHMETAFILE hmf, /* [in] metafile to render */
1728 const RECT *lpRect /* [in] rectangle to place metafile inside */
1731 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
1732 lpRect);
1735 /*****************************************************************************
1736 * DeleteEnhMetaFile (GDI32.@)
1738 * Deletes an enhanced metafile and frees the associated storage.
1740 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
1742 return EMF_Delete_HENHMETAFILE( hmf );
1745 /*****************************************************************************
1746 * CopyEnhMetaFileA (GDI32.@) Duplicate an enhanced metafile
1750 HENHMETAFILE WINAPI CopyEnhMetaFileA(
1751 HENHMETAFILE hmfSrc,
1752 LPCSTR file)
1754 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
1755 HENHMETAFILE hmfDst;
1757 if(!emrSrc) return FALSE;
1758 if (!file) {
1759 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
1760 memcpy( emrDst, emrSrc, emrSrc->nBytes );
1761 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
1762 } else {
1763 HANDLE hFile;
1764 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
1765 NULL, CREATE_ALWAYS, 0, 0);
1766 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
1767 CloseHandle( hFile );
1768 /* Reopen file for reading only, so that apps can share
1769 read access to the file while hmf is still valid */
1770 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
1771 NULL, OPEN_EXISTING, 0, 0);
1772 if(hFile == INVALID_HANDLE_VALUE) {
1773 ERR("Can't reopen emf for reading\n");
1774 return 0;
1776 hmfDst = EMF_GetEnhMetaFile( hFile );
1777 CloseHandle( hFile );
1779 return hmfDst;
1783 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1784 typedef struct tagEMF_PaletteCopy
1786 UINT cEntries;
1787 LPPALETTEENTRY lpPe;
1788 } EMF_PaletteCopy;
1790 /***************************************************************
1791 * Find the EMR_EOF record and then use it to find the
1792 * palette entries for this enhanced metafile.
1793 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1794 * which contains the max number of elements to copy and where
1795 * to copy them to.
1797 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1799 INT CALLBACK cbEnhPaletteCopy( HDC a,
1800 LPHANDLETABLE b,
1801 LPENHMETARECORD lpEMR,
1802 INT c,
1803 LPVOID lpData )
1806 if ( lpEMR->iType == EMR_EOF )
1808 PEMREOF lpEof = (PEMREOF)lpEMR;
1809 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
1810 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
1812 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
1814 memcpy( (LPVOID)info->lpPe,
1815 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
1816 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
1818 /* Update the passed data as a return code */
1819 info->lpPe = NULL; /* Palettes were copied! */
1820 info->cEntries = (UINT)dwNumPalToCopy;
1822 return FALSE; /* That's all we need */
1825 return TRUE;
1828 /*****************************************************************************
1829 * GetEnhMetaFilePaletteEntries (GDI32.@)
1831 * Copy the palette and report size
1833 * BUGS: Error codes (SetLastError) are not set on failures
1835 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
1836 UINT cEntries,
1837 LPPALETTEENTRY lpPe )
1839 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
1840 EMF_PaletteCopy infoForCallBack;
1842 TRACE( "(%04x,%d,%p)\n", hEmf, cEntries, lpPe );
1844 /* First check if there are any palettes associated with
1845 this metafile. */
1846 if ( enhHeader->nPalEntries == 0 ) return 0;
1848 /* Is the user requesting the number of palettes? */
1849 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
1851 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1852 infoForCallBack.cEntries = cEntries;
1853 infoForCallBack.lpPe = lpPe;
1855 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
1856 &infoForCallBack, NULL ) )
1857 return GDI_ERROR;
1859 /* Verify that the callback executed correctly */
1860 if ( infoForCallBack.lpPe != NULL )
1862 /* Callback proc had error! */
1863 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1864 return GDI_ERROR;
1867 return infoForCallBack.cEntries;
1870 /******************************************************************
1871 * SetWinMetaFileBits (GDI32.@)
1873 * Translate from old style to new style.
1876 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
1877 CONST BYTE *lpbBuffer,
1878 HDC hdcRef,
1879 CONST METAFILEPICT *lpmfp
1882 HMETAFILE hmf = 0;
1883 HENHMETAFILE ret = 0;
1884 HDC hdc = 0, hdcdisp = 0;
1885 INT horzres, vertres;
1886 METAFILEPICT mfp;
1887 RECT rc, *prcFrame = NULL;
1889 TRACE("(%d, %p, %08x, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
1891 if(!(hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer))) {
1892 WARN("SetMetaFileBitsEx fails\n");
1893 return 0;
1896 if(!hdcRef)
1897 hdcRef = hdcdisp = CreateDCA("DISPLAY", NULL, NULL, NULL);
1899 if(!lpmfp) {
1900 lpmfp = &mfp;
1901 mfp.mm = MM_ANISOTROPIC;
1902 mfp.xExt = 100;
1903 mfp.yExt = 100;
1904 FIXME("Correct Exts from dc\n");
1905 } else
1906 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
1908 horzres = GetDeviceCaps(hdcRef, HORZRES);
1909 vertres = GetDeviceCaps(hdcRef, VERTRES);
1911 if(lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC) {
1912 rc.left = rc.top = 0;
1913 rc.right = lpmfp->xExt;
1914 rc.bottom = lpmfp->yExt;
1915 prcFrame = &rc;
1918 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL))) {
1919 ERR("CreateEnhMetaFile fails?\n");
1920 goto end;
1923 if(hdcdisp) {
1924 DeleteDC(hdcdisp);
1925 hdcRef = 0;
1928 if(lpmfp->mm != MM_TEXT)
1929 SetMapMode(hdc, lpmfp->mm);
1931 SetViewportExtEx(hdc, horzres, vertres, NULL);
1932 SetWindowExtEx(hdc, horzres, vertres, NULL);
1934 PlayMetaFile(hdc, hmf); /* It's got to be harder than this... */
1936 ret = CloseEnhMetaFile(hdc);
1937 end:
1938 DeleteMetaFile(hmf);
1939 return ret;