Add support for VarAnd between integers.
[wine/multimedia.git] / objects / enhmetafile.c
blob73c2bdfcc67bb2da62a62d7f57f5a3570cdbd67b
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,
64 (HGDIOBJ *)&hmf, NULL );
65 if (metaObj)
67 metaObj->emh = emh;
68 metaObj->on_disk = on_disk;
69 GDI_ReleaseObj( hmf );
71 return hmf;
74 /****************************************************************************
75 * EMF_Delete_HENHMETAFILE
77 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
79 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
80 ENHMETAFILE_MAGIC );
81 if(!metaObj) return FALSE;
83 if(metaObj->on_disk)
84 UnmapViewOfFile( metaObj->emh );
85 else
86 HeapFree( GetProcessHeap(), 0, metaObj->emh );
87 return GDI_FreeObject( hmf, metaObj );
90 /******************************************************************
91 * EMF_GetEnhMetaHeader
93 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
95 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
97 ENHMETAHEADER *ret = NULL;
98 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
99 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
100 if (metaObj)
102 ret = metaObj->emh;
103 GDI_ReleaseObj( hmf );
105 return ret;
108 /*****************************************************************************
109 * EMF_GetEnhMetaFile
112 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
114 ENHMETAHEADER *emh;
115 HANDLE hMapping;
117 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
118 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
119 CloseHandle( hMapping );
121 if (!emh) return 0;
123 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
124 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
125 emh->iType, emh->dSignature);
126 UnmapViewOfFile( emh );
127 return 0;
129 return EMF_Create_HENHMETAFILE( emh, TRUE );
133 /*****************************************************************************
134 * GetEnhMetaFileA (GDI32.@)
138 HENHMETAFILE WINAPI GetEnhMetaFileA(
139 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
142 HENHMETAFILE hmf;
143 HANDLE hFile;
145 hFile = CreateFileA(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", lpszMetaFile);
149 return 0;
151 hmf = EMF_GetEnhMetaFile( hFile );
152 CloseHandle( hFile );
153 return hmf;
156 /*****************************************************************************
157 * GetEnhMetaFileW (GDI32.@)
159 HENHMETAFILE WINAPI GetEnhMetaFileW(
160 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
162 HENHMETAFILE hmf;
163 HANDLE hFile;
165 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
166 OPEN_EXISTING, 0, 0);
167 if (hFile == INVALID_HANDLE_VALUE) {
168 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
169 return 0;
171 hmf = EMF_GetEnhMetaFile( hFile );
172 CloseHandle( hFile );
173 return hmf;
176 /*****************************************************************************
177 * GetEnhMetaFileHeader (GDI32.@)
179 * If buf is NULL, returns the size of buffer required.
180 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
181 * buf.
183 UINT WINAPI GetEnhMetaFileHeader(
184 HENHMETAFILE hmf, /* [in] enhanced metafile */
185 UINT bufsize, /* [in] size of buffer */
186 LPENHMETAHEADER buf /* [out] buffer */
189 LPENHMETAHEADER emh;
190 UINT size;
192 emh = EMF_GetEnhMetaHeader(hmf);
193 if(!emh) return FALSE;
194 size = emh->nSize;
195 if (!buf) return size;
196 size = min(size, bufsize);
197 memmove(buf, emh, size);
198 return size;
202 /*****************************************************************************
203 * GetEnhMetaFileDescriptionA (GDI32.@)
205 UINT WINAPI GetEnhMetaFileDescriptionA(
206 HENHMETAFILE hmf, /* [in] enhanced metafile */
207 UINT size, /* [in] size of buf */
208 LPSTR buf /* [out] buffer to receive description */
211 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
212 DWORD len;
213 WCHAR *descrW;
215 if(!emh) return FALSE;
216 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
217 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
218 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
220 if (!buf || !size ) return len;
222 len = min( size, len );
223 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
224 return len;
227 /*****************************************************************************
228 * GetEnhMetaFileDescriptionW (GDI32.@)
230 * Copies the description string of an enhanced metafile into a buffer
231 * _buf_.
233 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
234 * number of characters copied.
236 UINT WINAPI GetEnhMetaFileDescriptionW(
237 HENHMETAFILE hmf, /* [in] enhanced metafile */
238 UINT size, /* [in] size of buf */
239 LPWSTR buf /* [out] buffer to receive description */
242 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
244 if(!emh) return FALSE;
245 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
246 if (!buf || !size ) return emh->nDescription;
248 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
249 return min(size, emh->nDescription);
252 /****************************************************************************
253 * SetEnhMetaFileBits (GDI32.@)
255 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
257 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
259 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
260 memmove(emh, buf, bufsize);
261 return EMF_Create_HENHMETAFILE( emh, FALSE );
264 /*****************************************************************************
265 * GetEnhMetaFileBits (GDI32.@)
268 UINT WINAPI GetEnhMetaFileBits(
269 HENHMETAFILE hmf,
270 UINT bufsize,
271 LPBYTE buf
274 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
275 UINT size;
277 if(!emh) return 0;
279 size = emh->nBytes;
280 if( buf == NULL ) return size;
282 size = min( size, bufsize );
283 memmove(buf, emh, size);
284 return size;
287 /*****************************************************************************
288 * PlayEnhMetaFileRecord (GDI32.@)
290 * Render a single enhanced metafile record in the device context hdc.
292 * RETURNS
293 * TRUE (non zero) on success, FALSE on error.
294 * BUGS
295 * Many unimplemented records.
296 * No error handling on record play failures (ie checking return codes)
298 BOOL WINAPI PlayEnhMetaFileRecord(
299 HDC hdc, /* [in] device context in which to render EMF record */
300 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
301 const ENHMETARECORD *mr, /* [in] EMF record to render */
302 UINT handles /* [in] size of handle array */
305 int type;
306 POINT pt[2];
308 TRACE("hdc = %p, 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 PEMRSETICMMODE lpSetICMMode = (PEMRSETICMMODE)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->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1350 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1351 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[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;
1569 pt[0].x = pt[0].y = 0;
1570 pt[1].x = pt[1].y = 1000;
1571 LPtoDP(hdc, pt, 2);
1572 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", pt[0].x, pt[0].y,
1573 pt[1].x, pt[1].y);
1574 return TRUE;
1578 /*****************************************************************************
1580 * EnumEnhMetaFile (GDI32.@)
1582 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1583 * for each
1584 * record. Returns when either every record has been used or
1585 * when _EnhMetaFunc_ returns FALSE.
1588 * RETURNS
1589 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1590 * returns FALSE.
1592 * BUGS
1593 * Ignores rect.
1595 BOOL WINAPI EnumEnhMetaFile(
1596 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
1597 HENHMETAFILE hmf, /* [in] EMF to walk */
1598 ENHMFENUMPROC callback, /* [in] callback function */
1599 LPVOID data, /* [in] optional data for callback function */
1600 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
1603 BOOL ret;
1604 ENHMETAHEADER *emh;
1605 ENHMETARECORD *emr;
1606 DWORD offset;
1607 UINT i;
1608 HANDLETABLE *ht;
1609 INT savedMode = 0;
1610 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1611 XFORM savedXform, xform;
1612 HPEN hPen = (HPEN)NULL;
1613 HBRUSH hBrush = (HBRUSH)NULL;
1614 HFONT hFont = (HFONT)NULL;
1615 POINT pt[2];
1617 if(!lpRect)
1619 SetLastError(ERROR_INVALID_PARAMETER);
1620 return FALSE;
1623 emh = EMF_GetEnhMetaHeader(hmf);
1624 if(!emh) {
1625 SetLastError(ERROR_INVALID_HANDLE);
1626 return FALSE;
1629 ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1630 sizeof(HANDLETABLE) * emh->nHandles );
1631 if(!ht)
1633 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1634 return FALSE;
1636 ht->objectHandle[0] = hmf;
1638 if (hdc && (emh->rclFrame.right - emh->rclFrame.left) && (emh->rclFrame.bottom - emh->rclFrame.top))
1640 TRACE("rect: %d,%d - %d,%d. rclFrame: %ld,%ld - %ld,%ld\n",
1641 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
1642 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
1643 emh->rclFrame.bottom);
1645 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
1646 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
1647 xscale = (FLOAT)(lpRect->right - lpRect->left) * 100.0 /
1648 (emh->rclFrame.right - emh->rclFrame.left) * xSrcPixSize;
1649 yscale = (FLOAT)(lpRect->bottom - lpRect->top) * 100.0 /
1650 (emh->rclFrame.bottom - emh->rclFrame.top) * ySrcPixSize;
1652 xform.eM11 = xscale;
1653 xform.eM12 = 0;
1654 xform.eM21 = 0;
1655 xform.eM22 = yscale;
1656 xform.eDx = (FLOAT) lpRect->left - (lpRect->right - lpRect->left) *
1657 emh->rclFrame.left / (emh->rclFrame.right - emh->rclFrame.left);
1658 xform.eDy = (FLOAT) lpRect->top - (lpRect->bottom - lpRect->top) *
1659 emh->rclFrame.top / (emh->rclFrame.bottom - emh->rclFrame.top);
1661 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1662 GetWorldTransform(hdc, &savedXform);
1664 if (!ModifyWorldTransform(hdc, &xform, MWT_RIGHTMULTIPLY)) {
1665 ERR("World transform failed!\n");
1668 /* save the current pen, brush and font */
1669 hPen = GetCurrentObject(hdc, OBJ_PEN);
1670 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
1671 hFont = GetCurrentObject(hdc, OBJ_FONT);
1674 pt[0].x = pt[0].y = 0;
1675 pt[1].x = pt[1].y = 1000;
1676 LPtoDP(hdc, pt, 2);
1677 TRACE("L:0,0-1000,1000 maps to D:%ld,%ld - %ld,%ld\n", pt[0].x, pt[0].y,
1678 pt[1].x, pt[1].y);
1679 TRACE("nSize = %ld, nBytes = %ld, nHandles = %d, nRecords = %ld, nPalEntries = %ld\n",
1680 emh->nSize, emh->nBytes, emh->nHandles, emh->nRecords, emh->nPalEntries);
1682 ret = TRUE;
1683 offset = 0;
1684 while(ret && offset < emh->nBytes)
1686 emr = (ENHMETARECORD *)((char *)emh + offset);
1687 TRACE("Calling EnumFunc with record type %ld, size %ld\n", emr->iType, emr->nSize);
1688 ret = (*callback)(hdc, ht, emr, emh->nHandles, data);
1689 offset += emr->nSize;
1692 if (hdc)
1694 /* restore pen, brush and font */
1695 SelectObject(hdc, hBrush);
1696 SelectObject(hdc, hPen);
1697 SelectObject(hdc, hFont);
1699 SetWorldTransform(hdc, &savedXform);
1700 if (savedMode)
1701 SetGraphicsMode(hdc, savedMode);
1704 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
1705 if( (ht->objectHandle)[i] )
1706 DeleteObject( (ht->objectHandle)[i] );
1708 HeapFree( GetProcessHeap(), 0, ht );
1709 return ret;
1712 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
1713 ENHMETARECORD *emr,
1714 INT handles, LPVOID data)
1716 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
1719 /**************************************************************************
1720 * PlayEnhMetaFile (GDI32.@)
1722 * Renders an enhanced metafile into a specified rectangle *lpRect
1723 * in device context hdc.
1726 BOOL WINAPI PlayEnhMetaFile(
1727 HDC hdc, /* [in] DC to render into */
1728 HENHMETAFILE hmf, /* [in] metafile to render */
1729 const RECT *lpRect /* [in] rectangle to place metafile inside */
1732 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
1733 lpRect);
1736 /*****************************************************************************
1737 * DeleteEnhMetaFile (GDI32.@)
1739 * Deletes an enhanced metafile and frees the associated storage.
1741 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
1743 return EMF_Delete_HENHMETAFILE( hmf );
1746 /*****************************************************************************
1747 * CopyEnhMetaFileA (GDI32.@) Duplicate an enhanced metafile
1751 HENHMETAFILE WINAPI CopyEnhMetaFileA(
1752 HENHMETAFILE hmfSrc,
1753 LPCSTR file)
1755 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
1756 HENHMETAFILE hmfDst;
1758 if(!emrSrc) return FALSE;
1759 if (!file) {
1760 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
1761 memcpy( emrDst, emrSrc, emrSrc->nBytes );
1762 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
1763 } else {
1764 HANDLE hFile;
1765 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
1766 NULL, CREATE_ALWAYS, 0, 0);
1767 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
1768 CloseHandle( hFile );
1769 /* Reopen file for reading only, so that apps can share
1770 read access to the file while hmf is still valid */
1771 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
1772 NULL, OPEN_EXISTING, 0, 0);
1773 if(hFile == INVALID_HANDLE_VALUE) {
1774 ERR("Can't reopen emf for reading\n");
1775 return 0;
1777 hmfDst = EMF_GetEnhMetaFile( hFile );
1778 CloseHandle( hFile );
1780 return hmfDst;
1784 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1785 typedef struct tagEMF_PaletteCopy
1787 UINT cEntries;
1788 LPPALETTEENTRY lpPe;
1789 } EMF_PaletteCopy;
1791 /***************************************************************
1792 * Find the EMR_EOF record and then use it to find the
1793 * palette entries for this enhanced metafile.
1794 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1795 * which contains the max number of elements to copy and where
1796 * to copy them to.
1798 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1800 INT CALLBACK cbEnhPaletteCopy( HDC a,
1801 LPHANDLETABLE b,
1802 LPENHMETARECORD lpEMR,
1803 INT c,
1804 LPVOID lpData )
1807 if ( lpEMR->iType == EMR_EOF )
1809 PEMREOF lpEof = (PEMREOF)lpEMR;
1810 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
1811 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
1813 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
1815 memcpy( (LPVOID)info->lpPe,
1816 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
1817 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
1819 /* Update the passed data as a return code */
1820 info->lpPe = NULL; /* Palettes were copied! */
1821 info->cEntries = (UINT)dwNumPalToCopy;
1823 return FALSE; /* That's all we need */
1826 return TRUE;
1829 /*****************************************************************************
1830 * GetEnhMetaFilePaletteEntries (GDI32.@)
1832 * Copy the palette and report size
1834 * BUGS: Error codes (SetLastError) are not set on failures
1836 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
1837 UINT cEntries,
1838 LPPALETTEENTRY lpPe )
1840 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
1841 EMF_PaletteCopy infoForCallBack;
1843 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
1845 /* First check if there are any palettes associated with
1846 this metafile. */
1847 if ( enhHeader->nPalEntries == 0 ) return 0;
1849 /* Is the user requesting the number of palettes? */
1850 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
1852 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1853 infoForCallBack.cEntries = cEntries;
1854 infoForCallBack.lpPe = lpPe;
1856 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
1857 &infoForCallBack, NULL ) )
1858 return GDI_ERROR;
1860 /* Verify that the callback executed correctly */
1861 if ( infoForCallBack.lpPe != NULL )
1863 /* Callback proc had error! */
1864 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1865 return GDI_ERROR;
1868 return infoForCallBack.cEntries;
1871 /******************************************************************
1872 * SetWinMetaFileBits (GDI32.@)
1874 * Translate from old style to new style.
1877 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
1878 CONST BYTE *lpbBuffer,
1879 HDC hdcRef,
1880 CONST METAFILEPICT *lpmfp
1883 HMETAFILE hmf = 0;
1884 HENHMETAFILE ret = 0;
1885 HDC hdc = 0, hdcdisp = 0;
1886 INT horzres, vertres;
1887 METAFILEPICT mfp;
1888 RECT rc, *prcFrame = NULL;
1890 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
1892 if(!(hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer))) {
1893 WARN("SetMetaFileBitsEx fails\n");
1894 return 0;
1897 if(!hdcRef)
1898 hdcRef = hdcdisp = CreateDCA("DISPLAY", NULL, NULL, NULL);
1900 if(!lpmfp) {
1901 lpmfp = &mfp;
1902 mfp.mm = MM_ANISOTROPIC;
1903 mfp.xExt = 100;
1904 mfp.yExt = 100;
1905 FIXME("Correct Exts from dc\n");
1906 } else
1907 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
1909 horzres = GetDeviceCaps(hdcRef, HORZRES);
1910 vertres = GetDeviceCaps(hdcRef, VERTRES);
1912 if(lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC) {
1913 rc.left = rc.top = 0;
1914 rc.right = lpmfp->xExt;
1915 rc.bottom = lpmfp->yExt;
1916 prcFrame = &rc;
1919 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL))) {
1920 ERR("CreateEnhMetaFile fails?\n");
1921 goto end;
1924 if(hdcdisp) {
1925 DeleteDC(hdcdisp);
1926 hdcRef = 0;
1929 if(lpmfp->mm != MM_TEXT)
1930 SetMapMode(hdc, lpmfp->mm);
1932 SetViewportExtEx(hdc, horzres, vertres, NULL);
1933 SetWindowExtEx(hdc, horzres, vertres, NULL);
1935 PlayMetaFile(hdc, hmf); /* It's got to be harder than this... */
1937 ret = CloseEnhMetaFile(hdc);
1938 end:
1939 DeleteMetaFile(hmf);
1940 return ret;