- s/cvs -PAd update/cvs update -PAd/.
[wine.git] / objects / enhmetafile.c
blobc897008798052a4897d3f28535ec70ddce3ff7d9
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 goto err;
129 /* refuse to load unaligned EMF as Windows does */
130 if (emh->nBytes & 3)
132 WARN("Refusing to load unaligned EMF\n");
133 goto err;
136 return EMF_Create_HENHMETAFILE( emh, TRUE );
138 err:
139 UnmapViewOfFile( emh );
140 return 0;
144 /*****************************************************************************
145 * GetEnhMetaFileA (GDI32.@)
149 HENHMETAFILE WINAPI GetEnhMetaFileA(
150 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
153 HENHMETAFILE hmf;
154 HANDLE hFile;
156 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
157 OPEN_EXISTING, 0, 0);
158 if (hFile == INVALID_HANDLE_VALUE) {
159 WARN("could not open %s\n", lpszMetaFile);
160 return 0;
162 hmf = EMF_GetEnhMetaFile( hFile );
163 CloseHandle( hFile );
164 return hmf;
167 /*****************************************************************************
168 * GetEnhMetaFileW (GDI32.@)
170 HENHMETAFILE WINAPI GetEnhMetaFileW(
171 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
173 HENHMETAFILE hmf;
174 HANDLE hFile;
176 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
177 OPEN_EXISTING, 0, 0);
178 if (hFile == INVALID_HANDLE_VALUE) {
179 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
180 return 0;
182 hmf = EMF_GetEnhMetaFile( hFile );
183 CloseHandle( hFile );
184 return hmf;
187 /*****************************************************************************
188 * GetEnhMetaFileHeader (GDI32.@)
190 * If buf is NULL, returns the size of buffer required.
191 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
192 * buf.
194 UINT WINAPI GetEnhMetaFileHeader(
195 HENHMETAFILE hmf, /* [in] enhanced metafile */
196 UINT bufsize, /* [in] size of buffer */
197 LPENHMETAHEADER buf /* [out] buffer */
200 LPENHMETAHEADER emh;
201 UINT size;
203 emh = EMF_GetEnhMetaHeader(hmf);
204 if(!emh) return FALSE;
205 size = emh->nSize;
206 if (!buf) return size;
207 size = min(size, bufsize);
208 memmove(buf, emh, size);
209 return size;
213 /*****************************************************************************
214 * GetEnhMetaFileDescriptionA (GDI32.@)
216 UINT WINAPI GetEnhMetaFileDescriptionA(
217 HENHMETAFILE hmf, /* [in] enhanced metafile */
218 UINT size, /* [in] size of buf */
219 LPSTR buf /* [out] buffer to receive description */
222 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
223 DWORD len;
224 WCHAR *descrW;
226 if(!emh) return FALSE;
227 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
228 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
229 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
231 if (!buf || !size ) return len;
233 len = min( size, len );
234 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
235 return len;
238 /*****************************************************************************
239 * GetEnhMetaFileDescriptionW (GDI32.@)
241 * Copies the description string of an enhanced metafile into a buffer
242 * _buf_.
244 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
245 * number of characters copied.
247 UINT WINAPI GetEnhMetaFileDescriptionW(
248 HENHMETAFILE hmf, /* [in] enhanced metafile */
249 UINT size, /* [in] size of buf */
250 LPWSTR buf /* [out] buffer to receive description */
253 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
255 if(!emh) return FALSE;
256 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
257 if (!buf || !size ) return emh->nDescription;
259 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
260 return min(size, emh->nDescription);
263 /****************************************************************************
264 * SetEnhMetaFileBits (GDI32.@)
266 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
268 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
270 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
271 memmove(emh, buf, bufsize);
272 return EMF_Create_HENHMETAFILE( emh, FALSE );
275 /*****************************************************************************
276 * GetEnhMetaFileBits (GDI32.@)
279 UINT WINAPI GetEnhMetaFileBits(
280 HENHMETAFILE hmf,
281 UINT bufsize,
282 LPBYTE buf
285 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
286 UINT size;
288 if(!emh) return 0;
290 size = emh->nBytes;
291 if( buf == NULL ) return size;
293 size = min( size, bufsize );
294 memmove(buf, emh, size);
295 return size;
298 typedef struct enum_emh_data
300 INT mode;
301 XFORM init_transform;
302 XFORM world_transform;
303 INT wndOrgX;
304 INT wndOrgY;
305 INT wndExtX;
306 INT wndExtY;
307 INT vportOrgX;
308 INT vportOrgY;
309 INT vportExtX;
310 INT vportExtY;
311 } enum_emh_data;
313 #define ENUM_GET_PRIVATE_DATA(ht) \
314 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
316 #define WIDTH(rect) ( (rect).right - (rect).left )
317 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
319 #define IS_WIN9X() (GetVersion()&0x80000000)
321 void EMF_Update_MF_Xform(HDC hdc, enum_emh_data *info)
323 XFORM mapping_mode_trans, final_trans;
324 FLOAT scaleX, scaleY;
326 scaleX = (FLOAT)info->vportExtX / (FLOAT)info->wndExtX;
327 scaleY = (FLOAT)info->vportExtY / (FLOAT)info->wndExtY;
328 mapping_mode_trans.eM11 = scaleX;
329 mapping_mode_trans.eM12 = 0.0;
330 mapping_mode_trans.eM21 = 0.0;
331 mapping_mode_trans.eM22 = scaleY;
332 mapping_mode_trans.eDx = (FLOAT)info->vportOrgX - scaleX * (FLOAT)info->wndOrgX;
333 mapping_mode_trans.eDy = (FLOAT)info->vportOrgY - scaleY * (FLOAT)info->wndOrgY;
335 CombineTransform(&final_trans, &info->world_transform, &mapping_mode_trans);
336 CombineTransform(&final_trans, &final_trans, &info->init_transform);
338 if (!SetWorldTransform(hdc, &final_trans))
340 ERR("World transform failed!\n");
344 void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
346 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
347 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
348 INT horzRes = GetDeviceCaps( hdc, HORZRES );
349 INT vertRes = GetDeviceCaps( hdc, VERTRES );
351 TRACE("%d\n",info->mode);
353 switch(info->mode)
355 case MM_TEXT:
356 info->wndExtX = 1;
357 info->wndExtY = 1;
358 info->vportExtX = 1;
359 info->vportExtY = 1;
360 break;
361 case MM_LOMETRIC:
362 case MM_ISOTROPIC:
363 info->wndExtX = horzSize;
364 info->wndExtY = vertSize;
365 info->vportExtX = horzRes / 10;
366 info->vportExtY = vertRes / -10;
367 break;
368 case MM_HIMETRIC:
369 info->wndExtX = horzSize * 10;
370 info->wndExtY = vertSize * 10;
371 info->vportExtX = horzRes / 10;
372 info->vportExtY = vertRes / -10;
373 break;
374 case MM_LOENGLISH:
375 info->wndExtX = horzSize;
376 info->wndExtY = vertSize;
377 info->vportExtX = 254L * horzRes / 1000;
378 info->vportExtY = -254L * vertRes / 1000;
379 break;
380 case MM_HIENGLISH:
381 info->wndExtX = horzSize * 10;
382 info->wndExtY = vertSize * 10;
383 info->vportExtX = 254L * horzRes / 1000;
384 info->vportExtY = -254L * vertRes / 1000;
385 break;
386 case MM_TWIPS:
387 info->wndExtX = 144L * horzSize / 10;
388 info->wndExtY = 144L * vertSize / 10;
389 info->vportExtX = 254L * horzRes / 1000;
390 info->vportExtY = -254L * vertRes / 1000;
391 break;
392 case MM_ANISOTROPIC:
393 break;
394 default:
395 return;
399 /*****************************************************************************
400 * emr_produces_output
402 * Returns TRUE if the record type writes something to the dc. Used by
403 * PlayEnhMetaFileRecord to determine whether it needs to update the
404 * dc's xform when in win9x mode.
406 * FIXME: need to test which records should be here.
408 static BOOL emr_produces_output(int type)
410 switch(type) {
411 case EMR_POLYBEZIER:
412 case EMR_POLYGON:
413 case EMR_POLYLINE:
414 case EMR_POLYBEZIERTO:
415 case EMR_POLYLINETO:
416 case EMR_POLYPOLYLINE:
417 case EMR_POLYPOLYGON:
418 case EMR_SETPIXELV:
419 case EMR_MOVETOEX:
420 case EMR_EXCLUDECLIPRECT:
421 case EMR_INTERSECTCLIPRECT:
422 case EMR_SELECTOBJECT:
423 case EMR_ANGLEARC:
424 case EMR_ELLIPSE:
425 case EMR_RECTANGLE:
426 case EMR_ROUNDRECT:
427 case EMR_ARC:
428 case EMR_CHORD:
429 case EMR_PIE:
430 case EMR_EXTFLOODFILL:
431 case EMR_LINETO:
432 case EMR_ARCTO:
433 case EMR_POLYDRAW:
434 case EMR_FILLRGN:
435 case EMR_FRAMERGN:
436 case EMR_INVERTRGN:
437 case EMR_PAINTRGN:
438 case EMR_BITBLT:
439 case EMR_STRETCHBLT:
440 case EMR_MASKBLT:
441 case EMR_PLGBLT:
442 case EMR_SETDIBITSTODEVICE:
443 case EMR_STRETCHDIBITS:
444 case EMR_EXTTEXTOUTA:
445 case EMR_EXTTEXTOUTW:
446 case EMR_POLYBEZIER16:
447 case EMR_POLYGON16:
448 case EMR_POLYLINE16:
449 case EMR_POLYBEZIERTO16:
450 case EMR_POLYLINETO16:
451 case EMR_POLYPOLYLINE16:
452 case EMR_POLYPOLYGON16:
453 case EMR_POLYDRAW16:
454 case EMR_POLYTEXTOUTA:
455 case EMR_POLYTEXTOUTW:
456 case EMR_SMALLTEXTOUT:
457 case EMR_TRANSPARENTBLT:
458 return TRUE;
459 default:
460 return FALSE;
465 /*****************************************************************************
466 * PlayEnhMetaFileRecord (GDI32.@)
468 * Render a single enhanced metafile record in the device context hdc.
470 * RETURNS
471 * TRUE (non zero) on success, FALSE on error.
472 * BUGS
473 * Many unimplemented records.
474 * No error handling on record play failures (ie checking return codes)
476 * NOTES
477 * WinNT actually updates the current world transform in this function
478 * whereas Win9x does not.
480 BOOL WINAPI PlayEnhMetaFileRecord(
481 HDC hdc, /* [in] device context in which to render EMF record */
482 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
483 const ENHMETARECORD *mr, /* [in] EMF record to render */
484 UINT handles /* [in] size of handle array */
487 int type;
488 RECT tmprc;
489 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
491 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
492 hdc, handletable, mr, handles);
493 if (!mr) return FALSE;
495 type = mr->iType;
497 /* In Win9x mode we update the xform if the record will produce output */
498 if ( IS_WIN9X() && emr_produces_output(type) )
499 EMF_Update_MF_Xform(hdc, info);
501 TRACE(" type=%d\n", type);
502 switch(type)
504 case EMR_HEADER:
505 break;
506 case EMR_EOF:
507 break;
508 case EMR_GDICOMMENT:
510 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
511 /* In an enhanced metafile, there can be both public and private GDI comments */
512 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
513 break;
515 case EMR_SETMAPMODE:
517 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
519 if(info->mode == pSetMapMode->iMode)
520 break;
521 info->mode = pSetMapMode->iMode;
522 EMF_SetMapMode(hdc, info);
523 break;
525 case EMR_SETBKMODE:
527 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
528 SetBkMode(hdc, pSetBkMode->iMode);
529 break;
531 case EMR_SETBKCOLOR:
533 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
534 SetBkColor(hdc, pSetBkColor->crColor);
535 break;
537 case EMR_SETPOLYFILLMODE:
539 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
540 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
541 break;
543 case EMR_SETROP2:
545 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
546 SetROP2(hdc, pSetROP2->iMode);
547 break;
549 case EMR_SETSTRETCHBLTMODE:
551 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
552 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
553 break;
555 case EMR_SETTEXTALIGN:
557 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
558 SetTextAlign(hdc, pSetTextAlign->iMode);
559 break;
561 case EMR_SETTEXTCOLOR:
563 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
564 SetTextColor(hdc, pSetTextColor->crColor);
565 break;
567 case EMR_SAVEDC:
569 SaveDC(hdc);
570 break;
572 case EMR_RESTOREDC:
574 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
575 RestoreDC(hdc, pRestoreDC->iRelative);
576 break;
578 case EMR_INTERSECTCLIPRECT:
580 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
581 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
582 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
583 break;
585 case EMR_SELECTOBJECT:
587 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
588 if( pSelectObject->ihObject & 0x80000000 ) {
589 /* High order bit is set - it's a stock object
590 * Strip the high bit to get the index.
591 * See MSDN article Q142319
593 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
594 0x7fffffff ) );
595 } else {
596 /* High order bit wasn't set - not a stock object
598 SelectObject( hdc,
599 (handletable->objectHandle)[pSelectObject->ihObject] );
601 break;
603 case EMR_DELETEOBJECT:
605 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
606 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
607 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
608 break;
610 case EMR_SETWINDOWORGEX:
612 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
614 info->wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
615 info->wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
617 TRACE("SetWindowOrgEx: %d,%d\n",info->wndOrgX,info->wndOrgY);
618 break;
620 case EMR_SETWINDOWEXTEX:
622 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
624 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
625 break;
626 info->wndExtX = pSetWindowExtEx->szlExtent.cx;
627 info->wndExtY = pSetWindowExtEx->szlExtent.cy;
629 TRACE("SetWindowExtEx: %d,%d\n",info->wndExtX,info->wndExtY);
630 break;
632 case EMR_SETVIEWPORTORGEX:
634 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
635 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
637 info->vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
638 info->vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
639 TRACE("SetViewportOrgEx: %d,%d\n",info->vportOrgX,info->vportOrgY);
640 break;
642 case EMR_SETVIEWPORTEXTEX:
644 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
645 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
647 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
648 break;
649 info->vportExtX = pSetViewportExtEx->szlExtent.cx;
650 info->vportExtY = pSetViewportExtEx->szlExtent.cy;
651 TRACE("SetViewportExtEx: %d,%d\n",info->vportExtX,info->vportExtY);
652 break;
654 case EMR_CREATEPEN:
656 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
657 (handletable->objectHandle)[pCreatePen->ihPen] =
658 CreatePenIndirect(&pCreatePen->lopn);
659 break;
661 case EMR_EXTCREATEPEN:
663 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
664 LOGBRUSH lb;
665 lb.lbStyle = pPen->elp.elpBrushStyle;
666 lb.lbColor = pPen->elp.elpColor;
667 lb.lbHatch = pPen->elp.elpHatch;
669 if(pPen->offBmi || pPen->offBits)
670 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
672 (handletable->objectHandle)[pPen->ihPen] =
673 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
674 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
675 break;
677 case EMR_CREATEBRUSHINDIRECT:
679 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
680 (handletable->objectHandle)[pBrush->ihBrush] =
681 CreateBrushIndirect(&pBrush->lb);
682 break;
684 case EMR_EXTCREATEFONTINDIRECTW:
686 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
687 (handletable->objectHandle)[pFont->ihFont] =
688 CreateFontIndirectW(&pFont->elfw.elfLogFont);
689 break;
691 case EMR_MOVETOEX:
693 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
694 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
695 break;
697 case EMR_LINETO:
699 PEMRLINETO pLineTo = (PEMRLINETO) mr;
700 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
701 break;
703 case EMR_RECTANGLE:
705 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
706 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
707 pRect->rclBox.right, pRect->rclBox.bottom);
708 break;
710 case EMR_ELLIPSE:
712 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
713 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
714 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
715 break;
717 case EMR_POLYGON16:
719 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
720 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
721 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
722 pPoly->cpts * sizeof(POINT) );
723 DWORD i;
724 for(i = 0; i < pPoly->cpts; i++)
725 CONV_POINT16TO32(pPoly->apts + i, pts + i);
726 Polygon(hdc, pts, pPoly->cpts);
727 HeapFree( GetProcessHeap(), 0, pts );
728 break;
730 case EMR_POLYLINE16:
732 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
733 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
734 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
735 pPoly->cpts * sizeof(POINT) );
736 DWORD i;
737 for(i = 0; i < pPoly->cpts; i++)
738 CONV_POINT16TO32(pPoly->apts + i, pts + i);
739 Polyline(hdc, pts, pPoly->cpts);
740 HeapFree( GetProcessHeap(), 0, pts );
741 break;
743 case EMR_POLYLINETO16:
745 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
746 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
747 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
748 pPoly->cpts * sizeof(POINT) );
749 DWORD i;
750 for(i = 0; i < pPoly->cpts; i++)
751 CONV_POINT16TO32(pPoly->apts + i, pts + i);
752 PolylineTo(hdc, pts, pPoly->cpts);
753 HeapFree( GetProcessHeap(), 0, pts );
754 break;
756 case EMR_POLYBEZIER16:
758 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
759 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
760 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
761 pPoly->cpts * sizeof(POINT) );
762 DWORD i;
763 for(i = 0; i < pPoly->cpts; i++)
764 CONV_POINT16TO32(pPoly->apts + i, pts + i);
765 PolyBezier(hdc, pts, pPoly->cpts);
766 HeapFree( GetProcessHeap(), 0, pts );
767 break;
769 case EMR_POLYBEZIERTO16:
771 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
772 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
773 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
774 pPoly->cpts * sizeof(POINT) );
775 DWORD i;
776 for(i = 0; i < pPoly->cpts; i++)
777 CONV_POINT16TO32(pPoly->apts + i, pts + i);
778 PolyBezierTo(hdc, pts, pPoly->cpts);
779 HeapFree( GetProcessHeap(), 0, pts );
780 break;
782 case EMR_POLYPOLYGON16:
784 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
785 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
786 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
788 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
789 pPolyPoly->cpts * sizeof(POINT) );
790 DWORD i;
791 for(i = 0; i < pPolyPoly->cpts; i++)
792 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
793 pPolyPoly->nPolys) + i, pts + i);
795 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
796 HeapFree( GetProcessHeap(), 0, pts );
797 break;
799 case EMR_POLYPOLYLINE16:
801 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
802 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
803 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
805 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
806 pPolyPoly->cpts * sizeof(POINT) );
807 DWORD i;
808 for(i = 0; i < pPolyPoly->cpts; i++)
809 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
810 pPolyPoly->nPolys) + i, pts + i);
812 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
813 HeapFree( GetProcessHeap(), 0, pts );
814 break;
817 case EMR_STRETCHDIBITS:
819 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
821 StretchDIBits(hdc,
822 pStretchDIBits->xDest,
823 pStretchDIBits->yDest,
824 pStretchDIBits->cxDest,
825 pStretchDIBits->cyDest,
826 pStretchDIBits->xSrc,
827 pStretchDIBits->ySrc,
828 pStretchDIBits->cxSrc,
829 pStretchDIBits->cySrc,
830 (BYTE *)mr + pStretchDIBits->offBitsSrc,
831 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
832 pStretchDIBits->iUsageSrc,
833 pStretchDIBits->dwRop);
834 break;
837 case EMR_EXTTEXTOUTA:
839 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
840 RECT rc;
842 rc.left = pExtTextOutA->emrtext.rcl.left;
843 rc.top = pExtTextOutA->emrtext.rcl.top;
844 rc.right = pExtTextOutA->emrtext.rcl.right;
845 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
846 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
847 pExtTextOutA->emrtext.fOptions, &rc,
848 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
849 (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx));
850 break;
853 case EMR_EXTTEXTOUTW:
855 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
856 RECT rc;
858 rc.left = pExtTextOutW->emrtext.rcl.left;
859 rc.top = pExtTextOutW->emrtext.rcl.top;
860 rc.right = pExtTextOutW->emrtext.rcl.right;
861 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
862 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
863 pExtTextOutW->emrtext.fOptions, &rc,
864 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
865 (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx));
866 break;
869 case EMR_CREATEPALETTE:
871 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
873 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
874 CreatePalette( &lpCreatePal->lgpl );
876 break;
879 case EMR_SELECTPALETTE:
881 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
883 if( lpSelectPal->ihPal & 0x80000000 ) {
884 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
885 } else {
886 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
887 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
889 break;
892 case EMR_REALIZEPALETTE:
894 RealizePalette( hdc );
895 break;
898 case EMR_EXTSELECTCLIPRGN:
900 #if 0
901 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
902 HRGN hRgn = ExtCreateRegion(NULL, lpRgn->cbRgnData, (RGNDATA *)lpRgn->RgnData);
903 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
904 /* ExtSelectClipRgn created a copy of the region */
905 DeleteObject(hRgn);
906 #endif
907 FIXME("ExtSelectClipRgn\n");
908 break;
911 case EMR_SETMETARGN:
913 SetMetaRgn( hdc );
914 break;
917 case EMR_SETWORLDTRANSFORM:
919 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
920 info->world_transform = lpXfrm->xform;
921 break;
924 case EMR_POLYBEZIER:
926 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
927 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
928 break;
931 case EMR_POLYGON:
933 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
934 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
935 break;
938 case EMR_POLYLINE:
940 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
941 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
942 break;
945 case EMR_POLYBEZIERTO:
947 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
948 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
949 (UINT)lpPolyBezierTo->cptl );
950 break;
953 case EMR_POLYLINETO:
955 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
956 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
957 (UINT)lpPolyLineTo->cptl );
958 break;
961 case EMR_POLYPOLYLINE:
963 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
964 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
966 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
967 pPolyPolyline->nPolys),
968 pPolyPolyline->aPolyCounts,
969 pPolyPolyline->nPolys );
971 break;
974 case EMR_POLYPOLYGON:
976 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
978 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
980 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
981 pPolyPolygon->nPolys),
982 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
983 break;
986 case EMR_SETBRUSHORGEX:
988 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
990 SetBrushOrgEx( hdc,
991 (INT)lpSetBrushOrgEx->ptlOrigin.x,
992 (INT)lpSetBrushOrgEx->ptlOrigin.y,
993 NULL );
995 break;
998 case EMR_SETPIXELV:
1000 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
1002 SetPixelV( hdc,
1003 (INT)lpSetPixelV->ptlPixel.x,
1004 (INT)lpSetPixelV->ptlPixel.y,
1005 lpSetPixelV->crColor );
1007 break;
1010 case EMR_SETMAPPERFLAGS:
1012 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
1014 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1016 break;
1019 case EMR_SETCOLORADJUSTMENT:
1021 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
1023 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1025 break;
1028 case EMR_OFFSETCLIPRGN:
1030 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
1032 OffsetClipRgn( hdc,
1033 (INT)lpOffsetClipRgn->ptlOffset.x,
1034 (INT)lpOffsetClipRgn->ptlOffset.y );
1035 FIXME("OffsetClipRgn\n");
1037 break;
1040 case EMR_EXCLUDECLIPRECT:
1042 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
1044 ExcludeClipRect( hdc,
1045 lpExcludeClipRect->rclClip.left,
1046 lpExcludeClipRect->rclClip.top,
1047 lpExcludeClipRect->rclClip.right,
1048 lpExcludeClipRect->rclClip.bottom );
1049 FIXME("ExcludeClipRect\n");
1051 break;
1054 case EMR_SCALEVIEWPORTEXTEX:
1056 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
1058 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1059 break;
1060 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1061 !lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->yDenom)
1062 break;
1063 info->vportExtX = (info->vportExtX * lpScaleViewportExtEx->xNum) /
1064 lpScaleViewportExtEx->xDenom;
1065 info->vportExtY = (info->vportExtY * lpScaleViewportExtEx->yNum) /
1066 lpScaleViewportExtEx->yDenom;
1067 if (info->vportExtX == 0) info->vportExtX = 1;
1068 if (info->vportExtY == 0) info->vportExtY = 1;
1069 if (info->mode == MM_ISOTROPIC)
1070 FIXME("EMRSCALEVIEWPORTEXTEX MM_ISOTROPIC mapping\n");
1071 /* MAPPING_FixIsotropic( dc ); */
1073 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1074 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1075 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1077 break;
1080 case EMR_SCALEWINDOWEXTEX:
1082 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
1084 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1085 break;
1086 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1087 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1088 break;
1089 info->wndExtX = (info->wndExtX * lpScaleWindowExtEx->xNum) /
1090 lpScaleWindowExtEx->xDenom;
1091 info->wndExtY = (info->wndExtY * lpScaleWindowExtEx->yNum) /
1092 lpScaleWindowExtEx->yDenom;
1093 if (info->wndExtX == 0) info->wndExtX = 1;
1094 if (info->wndExtY == 0) info->wndExtY = 1;
1095 if (info->mode == MM_ISOTROPIC)
1096 FIXME("EMRSCALEWINDOWEXTEX MM_ISOTROPIC mapping\n");
1097 /* MAPPING_FixIsotropic( dc ); */
1099 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1100 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1101 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1103 break;
1106 case EMR_MODIFYWORLDTRANSFORM:
1108 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
1110 switch(lpModifyWorldTrans->iMode) {
1111 case MWT_IDENTITY:
1112 info->world_transform.eM11 = info->world_transform.eM22 = 1;
1113 info->world_transform.eM12 = info->world_transform.eM21 = 0;
1114 info->world_transform.eDx = info->world_transform.eDy = 0;
1115 break;
1116 case MWT_LEFTMULTIPLY:
1117 CombineTransform(&info->world_transform, &lpModifyWorldTrans->xform,
1118 &info->world_transform);
1119 break;
1120 case MWT_RIGHTMULTIPLY:
1121 CombineTransform(&info->world_transform, &info->world_transform,
1122 &lpModifyWorldTrans->xform);
1123 break;
1124 default:
1125 FIXME("Unknown imode %ld\n", lpModifyWorldTrans->iMode);
1126 break;
1128 break;
1131 case EMR_ANGLEARC:
1133 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
1135 AngleArc( hdc,
1136 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1137 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1138 lpAngleArc->eSweepAngle );
1140 break;
1143 case EMR_ROUNDRECT:
1145 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
1147 RoundRect( hdc,
1148 lpRoundRect->rclBox.left,
1149 lpRoundRect->rclBox.top,
1150 lpRoundRect->rclBox.right,
1151 lpRoundRect->rclBox.bottom,
1152 lpRoundRect->szlCorner.cx,
1153 lpRoundRect->szlCorner.cy );
1155 break;
1158 case EMR_ARC:
1160 PEMRARC lpArc = (PEMRARC)mr;
1162 Arc( hdc,
1163 (INT)lpArc->rclBox.left,
1164 (INT)lpArc->rclBox.top,
1165 (INT)lpArc->rclBox.right,
1166 (INT)lpArc->rclBox.bottom,
1167 (INT)lpArc->ptlStart.x,
1168 (INT)lpArc->ptlStart.y,
1169 (INT)lpArc->ptlEnd.x,
1170 (INT)lpArc->ptlEnd.y );
1172 break;
1175 case EMR_CHORD:
1177 PEMRCHORD lpChord = (PEMRCHORD)mr;
1179 Chord( hdc,
1180 (INT)lpChord->rclBox.left,
1181 (INT)lpChord->rclBox.top,
1182 (INT)lpChord->rclBox.right,
1183 (INT)lpChord->rclBox.bottom,
1184 (INT)lpChord->ptlStart.x,
1185 (INT)lpChord->ptlStart.y,
1186 (INT)lpChord->ptlEnd.x,
1187 (INT)lpChord->ptlEnd.y );
1189 break;
1192 case EMR_PIE:
1194 PEMRPIE lpPie = (PEMRPIE)mr;
1196 Pie( hdc,
1197 (INT)lpPie->rclBox.left,
1198 (INT)lpPie->rclBox.top,
1199 (INT)lpPie->rclBox.right,
1200 (INT)lpPie->rclBox.bottom,
1201 (INT)lpPie->ptlStart.x,
1202 (INT)lpPie->ptlStart.y,
1203 (INT)lpPie->ptlEnd.x,
1204 (INT)lpPie->ptlEnd.y );
1206 break;
1209 case EMR_ARCTO:
1211 PEMRARC lpArcTo = (PEMRARC)mr;
1213 ArcTo( hdc,
1214 (INT)lpArcTo->rclBox.left,
1215 (INT)lpArcTo->rclBox.top,
1216 (INT)lpArcTo->rclBox.right,
1217 (INT)lpArcTo->rclBox.bottom,
1218 (INT)lpArcTo->ptlStart.x,
1219 (INT)lpArcTo->ptlStart.y,
1220 (INT)lpArcTo->ptlEnd.x,
1221 (INT)lpArcTo->ptlEnd.y );
1223 break;
1226 case EMR_EXTFLOODFILL:
1228 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
1230 ExtFloodFill( hdc,
1231 (INT)lpExtFloodFill->ptlStart.x,
1232 (INT)lpExtFloodFill->ptlStart.y,
1233 lpExtFloodFill->crColor,
1234 (UINT)lpExtFloodFill->iMode );
1236 break;
1239 case EMR_POLYDRAW:
1241 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
1242 PolyDraw( hdc,
1243 (const LPPOINT)lpPolyDraw->aptl,
1244 lpPolyDraw->abTypes,
1245 (INT)lpPolyDraw->cptl );
1247 break;
1250 case EMR_SETARCDIRECTION:
1252 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1253 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1254 break;
1257 case EMR_SETMITERLIMIT:
1259 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1260 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1261 break;
1264 case EMR_BEGINPATH:
1266 BeginPath( hdc );
1267 break;
1270 case EMR_ENDPATH:
1272 EndPath( hdc );
1273 break;
1276 case EMR_CLOSEFIGURE:
1278 CloseFigure( hdc );
1279 break;
1282 case EMR_FILLPATH:
1284 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1285 FillPath( hdc );
1286 break;
1289 case EMR_STROKEANDFILLPATH:
1291 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1292 StrokeAndFillPath( hdc );
1293 break;
1296 case EMR_STROKEPATH:
1298 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1299 StrokePath( hdc );
1300 break;
1303 case EMR_FLATTENPATH:
1305 FlattenPath( hdc );
1306 break;
1309 case EMR_WIDENPATH:
1311 WidenPath( hdc );
1312 break;
1315 case EMR_SELECTCLIPPATH:
1317 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1318 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1319 break;
1322 case EMR_ABORTPATH:
1324 AbortPath( hdc );
1325 break;
1328 case EMR_CREATECOLORSPACE:
1330 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1331 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1332 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1333 break;
1336 case EMR_SETCOLORSPACE:
1338 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1339 SetColorSpace( hdc,
1340 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1341 break;
1344 case EMR_DELETECOLORSPACE:
1346 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1347 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1348 break;
1351 case EMR_SETICMMODE:
1353 PEMRSETICMMODE lpSetICMMode = (PEMRSETICMMODE)mr;
1354 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1355 break;
1358 case EMR_PIXELFORMAT:
1360 INT iPixelFormat;
1361 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1363 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1364 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1366 break;
1369 case EMR_SETPALETTEENTRIES:
1371 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1373 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1374 (UINT)lpSetPaletteEntries->iStart,
1375 (UINT)lpSetPaletteEntries->cEntries,
1376 lpSetPaletteEntries->aPalEntries );
1378 break;
1381 case EMR_RESIZEPALETTE:
1383 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1385 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1386 (UINT)lpResizePalette->cEntries );
1388 break;
1391 case EMR_CREATEDIBPATTERNBRUSHPT:
1393 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1394 LPVOID lpPackedStruct;
1396 /* check that offsets and data are contained within the record */
1397 if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
1398 (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
1399 ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
1400 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
1402 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1403 break;
1406 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1407 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1408 lpCreate->cbBmi + lpCreate->cbBits );
1409 if(!lpPackedStruct)
1411 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1412 break;
1415 /* Now pack this structure */
1416 memcpy( lpPackedStruct,
1417 ((BYTE*)lpCreate) + lpCreate->offBmi,
1418 lpCreate->cbBmi );
1419 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1420 ((BYTE*)lpCreate) + lpCreate->offBits,
1421 lpCreate->cbBits );
1423 (handletable->objectHandle)[lpCreate->ihBrush] =
1424 CreateDIBPatternBrushPt( lpPackedStruct,
1425 (UINT)lpCreate->iUsage );
1427 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1429 break;
1432 case EMR_CREATEMONOBRUSH:
1434 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1435 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1436 HBITMAP hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1437 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1438 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1439 /* CreatePatternBrush created a copy of the bitmap */
1440 DeleteObject(hBmp);
1441 break;
1444 case EMR_BITBLT:
1446 PEMRBITBLT pBitBlt = (PEMRBITBLT)mr;
1447 HDC hdcSrc = CreateCompatibleDC(hdc);
1448 HBRUSH hBrush, hBrushOld;
1449 HBITMAP hBmp = 0, hBmpOld = 0;
1450 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pBitBlt->offBmiSrc);
1452 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1454 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1455 hBrushOld = SelectObject(hdcSrc, hBrush);
1456 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1457 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1458 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1459 SelectObject(hdcSrc, hBrushOld);
1460 DeleteObject(hBrush);
1462 if (pBitBlt->offBmiSrc > 0)
1464 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1465 (BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1466 hBmpOld = SelectObject(hdcSrc, hBmp);
1469 BitBlt(hdc,
1470 pBitBlt->xDest,
1471 pBitBlt->yDest,
1472 pBitBlt->cxDest,
1473 pBitBlt->cyDest,
1474 hdcSrc,
1475 pBitBlt->xSrc,
1476 pBitBlt->ySrc,
1477 pBitBlt->dwRop);
1479 if (pBitBlt->offBmiSrc > 0)
1481 SelectObject(hdcSrc, hBmpOld);
1482 DeleteObject(hBmp);
1484 DeleteDC(hdcSrc);
1485 break;
1488 case EMR_STRETCHBLT:
1490 PEMRSTRETCHBLT pStretchBlt= (PEMRSTRETCHBLT)mr;
1491 HDC hdcSrc = CreateCompatibleDC(hdc);
1492 HBRUSH hBrush, hBrushOld;
1493 HBITMAP hBmp = 0, hBmpOld = 0;
1494 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pStretchBlt->offBmiSrc);
1496 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1498 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1499 hBrushOld = SelectObject(hdcSrc, hBrush);
1500 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1501 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1502 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1503 SelectObject(hdcSrc, hBrushOld);
1504 DeleteObject(hBrush);
1506 if (pStretchBlt->offBmiSrc)
1508 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1509 (BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1510 hBmpOld = SelectObject(hdcSrc, hBmp);
1513 StretchBlt(hdc,
1514 pStretchBlt->xDest,
1515 pStretchBlt->yDest,
1516 pStretchBlt->cxDest,
1517 pStretchBlt->cyDest,
1518 hdcSrc,
1519 pStretchBlt->xSrc,
1520 pStretchBlt->ySrc,
1521 pStretchBlt->cxSrc,
1522 pStretchBlt->cySrc,
1523 pStretchBlt->dwRop);
1526 if (pStretchBlt->offBmiSrc)
1528 SelectObject(hdcSrc, hBmpOld);
1529 DeleteObject(hBmp);
1532 DeleteDC(hdcSrc);
1533 break;
1536 case EMR_MASKBLT:
1538 PEMRMASKBLT pMaskBlt= (PEMRMASKBLT)mr;
1539 HDC hdcSrc = CreateCompatibleDC(hdc);
1540 HBRUSH hBrush, hBrushOld;
1541 HBITMAP hBmp, hBmpOld, hBmpMask;
1542 BITMAPINFO *pbi;
1544 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1546 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1547 hBrushOld = SelectObject(hdcSrc, hBrush);
1548 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1549 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1550 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1551 SelectObject(hdcSrc, hBrushOld);
1552 DeleteObject(hBrush);
1554 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiMask);
1555 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1556 (BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1558 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiSrc);
1559 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1560 (BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1561 hBmpOld = SelectObject(hdcSrc, hBmp);
1562 MaskBlt(hdc,
1563 pMaskBlt->xDest,
1564 pMaskBlt->yDest,
1565 pMaskBlt->cxDest,
1566 pMaskBlt->cyDest,
1567 hdcSrc,
1568 pMaskBlt->xSrc,
1569 pMaskBlt->ySrc,
1570 hBmpMask,
1571 pMaskBlt->xMask,
1572 pMaskBlt->yMask,
1573 pMaskBlt->dwRop);
1574 SelectObject(hdcSrc, hBmpOld);
1575 DeleteObject(hBmp);
1576 DeleteObject(hBmpMask);
1577 DeleteDC(hdcSrc);
1578 break;
1581 case EMR_PLGBLT:
1583 PEMRPLGBLT pPlgBlt= (PEMRPLGBLT)mr;
1584 HDC hdcSrc = CreateCompatibleDC(hdc);
1585 HBRUSH hBrush, hBrushOld;
1586 HBITMAP hBmp, hBmpOld, hBmpMask;
1587 BITMAPINFO *pbi;
1588 POINT pts[3];
1590 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1592 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1593 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1594 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1596 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1597 hBrushOld = SelectObject(hdcSrc, hBrush);
1598 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1599 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1600 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1601 SelectObject(hdcSrc, hBrushOld);
1602 DeleteObject(hBrush);
1604 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiMask);
1605 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1606 (BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1608 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiSrc);
1609 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1610 (BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1611 hBmpOld = SelectObject(hdcSrc, hBmp);
1612 PlgBlt(hdc,
1613 pts,
1614 hdcSrc,
1615 pPlgBlt->xSrc,
1616 pPlgBlt->ySrc,
1617 pPlgBlt->cxSrc,
1618 pPlgBlt->cySrc,
1619 hBmpMask,
1620 pPlgBlt->xMask,
1621 pPlgBlt->yMask);
1622 SelectObject(hdcSrc, hBmpOld);
1623 DeleteObject(hBmp);
1624 DeleteObject(hBmpMask);
1625 DeleteDC(hdcSrc);
1626 break;
1629 case EMR_SETDIBITSTODEVICE:
1631 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice = (PEMRSETDIBITSTODEVICE)mr;
1633 SetDIBitsToDevice(hdc,
1634 pSetDIBitsToDevice->xDest,
1635 pSetDIBitsToDevice->yDest,
1636 pSetDIBitsToDevice->cxSrc,
1637 pSetDIBitsToDevice->cySrc,
1638 pSetDIBitsToDevice->xSrc,
1639 pSetDIBitsToDevice->ySrc,
1640 pSetDIBitsToDevice->iStartScan,
1641 pSetDIBitsToDevice->cScans,
1642 (BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
1643 (BITMAPINFO *)((BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
1644 pSetDIBitsToDevice->iUsageSrc);
1645 break;
1648 case EMR_POLYTEXTOUTA:
1650 PEMRPOLYTEXTOUTA pPolyTextOutA = (PEMRPOLYTEXTOUTA)mr;
1651 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
1652 LONG i;
1653 XFORM xform, xformOld;
1654 int gModeOld;
1656 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
1657 GetWorldTransform(hdc, &xformOld);
1659 xform.eM11 = pPolyTextOutA->exScale;
1660 xform.eM12 = 0.0;
1661 xform.eM21 = 0.0;
1662 xform.eM22 = pPolyTextOutA->eyScale;
1663 xform.eDx = 0.0;
1664 xform.eDy = 0.0;
1665 SetWorldTransform(hdc, &xform);
1667 /* Set up POLYTEXTA structures */
1668 for(i = 0; i < pPolyTextOutA->cStrings; i++)
1670 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
1671 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
1672 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
1673 polytextA[i].lpstr = (LPSTR)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
1674 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
1675 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
1676 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
1677 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
1678 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
1679 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
1681 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
1682 HeapFree(GetProcessHeap(), 0, polytextA);
1684 SetWorldTransform(hdc, &xformOld);
1685 SetGraphicsMode(hdc, gModeOld);
1686 break;
1689 case EMR_POLYTEXTOUTW:
1691 PEMRPOLYTEXTOUTW pPolyTextOutW = (PEMRPOLYTEXTOUTW)mr;
1692 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
1693 LONG i;
1694 XFORM xform, xformOld;
1695 int gModeOld;
1697 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
1698 GetWorldTransform(hdc, &xformOld);
1700 xform.eM11 = pPolyTextOutW->exScale;
1701 xform.eM12 = 0.0;
1702 xform.eM21 = 0.0;
1703 xform.eM22 = pPolyTextOutW->eyScale;
1704 xform.eDx = 0.0;
1705 xform.eDy = 0.0;
1706 SetWorldTransform(hdc, &xform);
1708 /* Set up POLYTEXTW structures */
1709 for(i = 0; i < pPolyTextOutW->cStrings; i++)
1711 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
1712 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
1713 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
1714 polytextW[i].lpstr = (LPWSTR)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
1715 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
1716 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
1717 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
1718 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
1719 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
1720 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
1722 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
1723 HeapFree(GetProcessHeap(), 0, polytextW);
1725 SetWorldTransform(hdc, &xformOld);
1726 SetGraphicsMode(hdc, gModeOld);
1727 break;
1730 case EMR_FILLRGN:
1732 PEMRFILLRGN pFillRgn = (PEMRFILLRGN)mr;
1733 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
1734 FillRgn(hdc,
1735 hRgn,
1736 (handletable->objectHandle)[pFillRgn->ihBrush]);
1737 DeleteObject(hRgn);
1738 break;
1741 case EMR_FRAMERGN:
1743 PEMRFRAMERGN pFrameRgn = (PEMRFRAMERGN)mr;
1744 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
1745 FrameRgn(hdc,
1746 hRgn,
1747 (handletable->objectHandle)[pFrameRgn->ihBrush],
1748 pFrameRgn->szlStroke.cx,
1749 pFrameRgn->szlStroke.cy);
1750 DeleteObject(hRgn);
1751 break;
1754 case EMR_INVERTRGN:
1756 PEMRINVERTRGN pInvertRgn = (PEMRINVERTRGN)mr;
1757 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
1758 InvertRgn(hdc, hRgn);
1759 DeleteObject(hRgn);
1760 break;
1763 case EMR_PAINTRGN:
1765 PEMRPAINTRGN pPaintRgn = (PEMRPAINTRGN)mr;
1766 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
1767 PaintRgn(hdc, hRgn);
1768 DeleteObject(hRgn);
1769 break;
1772 case EMR_SETTEXTJUSTIFICATION:
1774 PEMRSETTEXTJUSTIFICATION pSetTextJust = (PEMRSETTEXTJUSTIFICATION)mr;
1775 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
1776 break;
1779 case EMR_SETLAYOUT:
1781 PEMRSETLAYOUT pSetLayout = (PEMRSETLAYOUT)mr;
1782 SetLayout(hdc, pSetLayout->iMode);
1783 break;
1786 case EMR_POLYDRAW16:
1787 case EMR_GLSRECORD:
1788 case EMR_GLSBOUNDEDRECORD:
1789 case EMR_DRAWESCAPE :
1790 case EMR_EXTESCAPE:
1791 case EMR_STARTDOC:
1792 case EMR_SMALLTEXTOUT:
1793 case EMR_FORCEUFIMAPPING:
1794 case EMR_NAMEDESCAPE:
1795 case EMR_COLORCORRECTPALETTE:
1796 case EMR_SETICMPROFILEA:
1797 case EMR_SETICMPROFILEW:
1798 case EMR_ALPHABLEND:
1799 case EMR_TRANSPARENTBLT:
1800 case EMR_GRADIENTFILL:
1801 case EMR_SETLINKEDUFI:
1802 case EMR_COLORMATCHTOTARGETW:
1803 case EMR_CREATECOLORSPACEW:
1805 default:
1806 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1807 record then ignore and return TRUE. */
1808 FIXME("type %d is unimplemented\n", type);
1809 break;
1811 tmprc.left = tmprc.top = 0;
1812 tmprc.right = tmprc.bottom = 1000;
1813 LPtoDP(hdc, (POINT*)&tmprc, 2);
1814 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", tmprc.left,
1815 tmprc.top, tmprc.right, tmprc.bottom);
1817 if ( !IS_WIN9X() )
1819 /* WinNT - update the transform (win9x updates when the next graphics output
1820 record is played). */
1821 EMF_Update_MF_Xform(hdc, info);
1824 return TRUE;
1828 /*****************************************************************************
1830 * EnumEnhMetaFile (GDI32.@)
1832 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1833 * for each
1834 * record. Returns when either every record has been used or
1835 * when _EnhMetaFunc_ returns FALSE.
1838 * RETURNS
1839 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1840 * returns FALSE.
1842 * BUGS
1843 * Ignores rect.
1845 * NOTES
1846 * This function behaves differently in Win9x and WinNT.
1848 * In WinNT, the DC's world transform is updated as the EMF changes
1849 * the Window/Viewport Extent and Origin or it's world transform.
1850 * The actual Window/Viewport Extent and Origin are left untouched.
1852 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
1853 * updates the scaling itself but only just before a record that
1854 * writes anything to the DC.
1856 * I'm not sure where the data (enum_emh_data) is stored in either
1857 * version. For this implementation, it is stored before the handle
1858 * table, but it could be stored in the DC, in the EMF handle or in
1859 * TLS.
1860 * MJM 5 Oct 2002
1862 BOOL WINAPI EnumEnhMetaFile(
1863 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
1864 HENHMETAFILE hmf, /* [in] EMF to walk */
1865 ENHMFENUMPROC callback, /* [in] callback function */
1866 LPVOID data, /* [in] optional data for callback function */
1867 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
1870 BOOL ret;
1871 ENHMETAHEADER *emh;
1872 ENHMETARECORD *emr;
1873 DWORD offset;
1874 UINT i;
1875 HANDLETABLE *ht;
1876 INT savedMode = 0;
1877 XFORM savedXform;
1878 HPEN hPen = NULL;
1879 HBRUSH hBrush = NULL;
1880 HFONT hFont = NULL;
1881 enum_emh_data *info;
1882 SIZE vp_size, win_size;
1883 POINT vp_org, win_org;
1884 INT mapMode = MM_TEXT;
1886 if(!lpRect)
1888 SetLastError(ERROR_INVALID_PARAMETER);
1889 return FALSE;
1892 emh = EMF_GetEnhMetaHeader(hmf);
1893 if(!emh) {
1894 SetLastError(ERROR_INVALID_HANDLE);
1895 return FALSE;
1898 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1899 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
1900 if(!info)
1902 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1903 return FALSE;
1905 info->wndOrgX = 0;
1906 info->wndOrgY = 0;
1907 info->wndExtX = 1;
1908 info->wndExtY = 1;
1909 info->vportOrgX = 0;
1910 info->vportOrgY = 0;
1911 info->vportExtX = 1;
1912 info->vportExtY = 1;
1913 info->world_transform.eM11 = info->world_transform.eM22 = 1;
1914 info->world_transform.eM12 = info->world_transform.eM21 = 0;
1915 info->world_transform.eDx = info->world_transform.eDy = 0;
1917 ht = (HANDLETABLE*) &info[1];
1918 ht->objectHandle[0] = hmf;
1920 if(hdc)
1922 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1923 GetWorldTransform(hdc, &savedXform);
1924 GetViewportExtEx(hdc, &vp_size);
1925 GetWindowExtEx(hdc, &win_size);
1926 GetViewportOrgEx(hdc, &vp_org);
1927 GetWindowOrgEx(hdc, &win_org);
1928 mapMode = GetMapMode(hdc);
1930 /* save the current pen, brush and font */
1931 hPen = GetCurrentObject(hdc, OBJ_PEN);
1932 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
1933 hFont = GetCurrentObject(hdc, OBJ_FONT);
1936 info->mode = MM_TEXT;
1938 if ( IS_WIN9X() )
1940 /* Win95 leaves the vp/win ext/org info alone */
1941 info->init_transform.eM11 = 1.0;
1942 info->init_transform.eM12 = 0.0;
1943 info->init_transform.eM21 = 0.0;
1944 info->init_transform.eM22 = 1.0;
1945 info->init_transform.eDx = 0.0;
1946 info->init_transform.eDy = 0.0;
1948 else
1950 /* WinNT combines the vp/win ext/org info into a transform */
1951 FLOAT xscale, yscale;
1952 xscale = (FLOAT)vp_size.cx / (FLOAT)win_size.cx;
1953 yscale = (FLOAT)vp_size.cy / (FLOAT)win_size.cy;
1954 info->init_transform.eM11 = xscale;
1955 info->init_transform.eM12 = 0.0;
1956 info->init_transform.eM21 = 0.0;
1957 info->init_transform.eM22 = yscale;
1958 info->init_transform.eDx = (FLOAT)vp_org.x - xscale * (FLOAT)win_org.x;
1959 info->init_transform.eDy = (FLOAT)vp_org.y - yscale * (FLOAT)win_org.y;
1961 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
1964 if ( WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
1966 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1967 XFORM xform;
1969 TRACE("rect: %ld,%ld - %ld,%ld. rclFrame: %ld,%ld - %ld,%ld\n",
1970 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
1971 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
1972 emh->rclFrame.bottom);
1974 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
1975 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
1976 xscale = (FLOAT) WIDTH(*lpRect) * 100.0 /
1977 WIDTH(emh->rclFrame) * xSrcPixSize;
1978 yscale = (FLOAT) HEIGHT(*lpRect) * 100.0 /
1979 HEIGHT(emh->rclFrame) * ySrcPixSize;
1981 xform.eM11 = xscale;
1982 xform.eM12 = 0;
1983 xform.eM21 = 0;
1984 xform.eM22 = yscale;
1985 xform.eDx = (FLOAT) lpRect->left - (FLOAT) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
1986 xform.eDy = (FLOAT) lpRect->top - (FLOAT) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
1988 CombineTransform(&info->init_transform, &xform, &info->init_transform);
1991 /* WinNT resets the current vp/win org/ext */
1992 if ( !IS_WIN9X() )
1994 SetMapMode(hdc, MM_TEXT);
1995 SetWindowOrgEx(hdc, 0, 0, NULL);
1996 SetViewportOrgEx(hdc, 0, 0, NULL);
1997 EMF_Update_MF_Xform(hdc, info);
2000 ret = TRUE;
2001 offset = 0;
2002 while(ret && offset < emh->nBytes)
2004 emr = (ENHMETARECORD *)((char *)emh + offset);
2005 TRACE("Calling EnumFunc with record type %ld, size %ld\n", emr->iType, emr->nSize);
2006 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2007 offset += emr->nSize;
2010 if (hdc)
2012 /* restore pen, brush and font */
2013 SelectObject(hdc, hBrush);
2014 SelectObject(hdc, hPen);
2015 SelectObject(hdc, hFont);
2017 SetWorldTransform(hdc, &savedXform);
2018 if (savedMode)
2019 SetGraphicsMode(hdc, savedMode);
2020 SetMapMode(hdc, mapMode);
2021 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2022 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2023 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2024 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2027 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2028 if( (ht->objectHandle)[i] )
2029 DeleteObject( (ht->objectHandle)[i] );
2031 HeapFree( GetProcessHeap(), 0, info );
2032 return ret;
2035 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2036 const ENHMETARECORD *emr,
2037 INT handles, LPARAM data)
2039 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2042 /**************************************************************************
2043 * PlayEnhMetaFile (GDI32.@)
2045 * Renders an enhanced metafile into a specified rectangle *lpRect
2046 * in device context hdc.
2049 BOOL WINAPI PlayEnhMetaFile(
2050 HDC hdc, /* [in] DC to render into */
2051 HENHMETAFILE hmf, /* [in] metafile to render */
2052 const RECT *lpRect /* [in] rectangle to place metafile inside */
2055 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2056 lpRect);
2059 /*****************************************************************************
2060 * DeleteEnhMetaFile (GDI32.@)
2062 * Deletes an enhanced metafile and frees the associated storage.
2064 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2066 return EMF_Delete_HENHMETAFILE( hmf );
2069 /*****************************************************************************
2070 * CopyEnhMetaFileA (GDI32.@) Duplicate an enhanced metafile
2074 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2075 HENHMETAFILE hmfSrc,
2076 LPCSTR file)
2078 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2079 HENHMETAFILE hmfDst;
2081 if(!emrSrc) return FALSE;
2082 if (!file) {
2083 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2084 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2085 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2086 } else {
2087 HANDLE hFile;
2088 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2089 NULL, CREATE_ALWAYS, 0, 0);
2090 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
2091 CloseHandle( hFile );
2092 /* Reopen file for reading only, so that apps can share
2093 read access to the file while hmf is still valid */
2094 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2095 NULL, OPEN_EXISTING, 0, 0);
2096 if(hFile == INVALID_HANDLE_VALUE) {
2097 ERR("Can't reopen emf for reading\n");
2098 return 0;
2100 hmfDst = EMF_GetEnhMetaFile( hFile );
2101 CloseHandle( hFile );
2103 return hmfDst;
2107 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2108 typedef struct tagEMF_PaletteCopy
2110 UINT cEntries;
2111 LPPALETTEENTRY lpPe;
2112 } EMF_PaletteCopy;
2114 /***************************************************************
2115 * Find the EMR_EOF record and then use it to find the
2116 * palette entries for this enhanced metafile.
2117 * The lpData is actually a pointer to a EMF_PaletteCopy struct
2118 * which contains the max number of elements to copy and where
2119 * to copy them to.
2121 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2123 INT CALLBACK cbEnhPaletteCopy( HDC a,
2124 HANDLETABLE *b,
2125 const ENHMETARECORD *lpEMR,
2126 INT c,
2127 LPARAM lpData )
2130 if ( lpEMR->iType == EMR_EOF )
2132 PEMREOF lpEof = (PEMREOF)lpEMR;
2133 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2134 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2136 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
2138 memcpy( (LPVOID)info->lpPe,
2139 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
2140 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2142 /* Update the passed data as a return code */
2143 info->lpPe = NULL; /* Palettes were copied! */
2144 info->cEntries = (UINT)dwNumPalToCopy;
2146 return FALSE; /* That's all we need */
2149 return TRUE;
2152 /*****************************************************************************
2153 * GetEnhMetaFilePaletteEntries (GDI32.@)
2155 * Copy the palette and report size
2157 * BUGS: Error codes (SetLastError) are not set on failures
2159 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2160 UINT cEntries,
2161 LPPALETTEENTRY lpPe )
2163 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2164 EMF_PaletteCopy infoForCallBack;
2166 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2168 /* First check if there are any palettes associated with
2169 this metafile. */
2170 if ( enhHeader->nPalEntries == 0 ) return 0;
2172 /* Is the user requesting the number of palettes? */
2173 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
2175 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2176 infoForCallBack.cEntries = cEntries;
2177 infoForCallBack.lpPe = lpPe;
2179 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2180 &infoForCallBack, 0 ) )
2181 return GDI_ERROR;
2183 /* Verify that the callback executed correctly */
2184 if ( infoForCallBack.lpPe != NULL )
2186 /* Callback proc had error! */
2187 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2188 return GDI_ERROR;
2191 return infoForCallBack.cEntries;
2194 typedef struct gdi_mf_comment
2196 DWORD ident;
2197 DWORD iComment;
2198 DWORD nVersion;
2199 DWORD nChecksum;
2200 DWORD fFlags;
2201 DWORD cbWinMetaFile;
2202 } gdi_mf_comment;
2204 /******************************************************************
2205 * SetWinMetaFileBits (GDI32.@)
2207 * Translate from old style to new style.
2210 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2211 CONST BYTE *lpbBuffer,
2212 HDC hdcRef,
2213 CONST METAFILEPICT *lpmfp
2216 HMETAFILE hmf = 0;
2217 HENHMETAFILE ret = 0;
2218 HDC hdc = 0, hdcdisp = 0;
2219 METAFILEPICT mfp;
2220 RECT rc, *prcFrame = NULL;
2221 gdi_mf_comment *mfcomment;
2222 UINT mfcomment_size;
2223 INT horzres, vertres, horzsize, vertsize, xext, yext;
2225 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2227 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2228 if(!hmf)
2230 WARN("SetMetaFileBitsEx failed\n");
2231 return 0;
2234 if(!hdcRef)
2235 hdcRef = hdcdisp = CreateDCA("DISPLAY", NULL, NULL, NULL);
2237 if(!lpmfp) {
2238 lpmfp = &mfp;
2239 mfp.mm = MM_ANISOTROPIC;
2240 mfp.xExt = 100;
2241 mfp.yExt = 100;
2242 FIXME("Correct Exts from dc\n");
2244 else
2246 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2247 if ( ( mfp.xExt < 0 ) || ( mfp.yExt < 0) )
2248 FIXME("Negative coordinates!\n");
2251 if(lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC) {
2252 rc.left = rc.top = 0;
2253 rc.right = lpmfp->xExt;
2254 rc.bottom = lpmfp->yExt;
2255 prcFrame = &rc;
2258 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL))) {
2259 ERR("CreateEnhMetaFile fails?\n");
2260 goto end;
2263 horzres = GetDeviceCaps(hdcRef, HORZRES);
2264 vertres = GetDeviceCaps(hdcRef, VERTRES);
2265 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2266 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2268 if(hdcdisp) {
2269 DeleteDC(hdcdisp);
2270 hdcRef = 0;
2274 * Write the original METAFILE into the enhanced metafile.
2275 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2277 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2278 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2279 if(mfcomment)
2281 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2282 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2283 mfcomment->nVersion = 0x00000300;
2284 mfcomment->nChecksum = 0; /* FIXME */
2285 mfcomment->fFlags = 0;
2286 mfcomment->cbWinMetaFile = cbBuffer;
2287 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2288 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2289 HeapFree(GetProcessHeap(), 0, mfcomment);
2292 if(lpmfp->mm != MM_TEXT)
2293 SetMapMode(hdc, lpmfp->mm);
2295 /* set the initial viewport:window ratio as 1:1 */
2296 xext = lpmfp->xExt*horzres/(100*horzsize);
2297 yext = lpmfp->yExt*vertres/(100*vertsize);
2298 SetViewportExtEx(hdc, xext, yext, NULL);
2299 SetWindowExtEx(hdc, xext, yext, NULL);
2301 PlayMetaFile(hdc, hmf);
2303 ret = CloseEnhMetaFile(hdc);
2304 end:
2305 DeleteMetaFile(hmf);
2306 return ret;