StrRetToStrN returns BOOL and shouldn't crash on NULL dest.
[wine/hacks.git] / objects / enhmetafile.c
blob2605e0fb085e68222ef3f71b38a80d0c40af9ca2
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 <stdarg.h>
38 #include <string.h>
39 #include <assert.h>
40 #include "windef.h"
41 #include "winbase.h"
42 #include "wingdi.h"
43 #include "winnls.h"
44 #include "winerror.h"
45 #include "gdi.h"
46 #include "gdi_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
51 typedef struct
53 GDIOBJHDR header;
54 ENHMETAHEADER *emh;
55 BOOL on_disk; /* true if metafile is on disk */
56 } ENHMETAFILEOBJ;
58 static const struct emr_name {
59 DWORD type;
60 const char *name;
61 } emr_names[] = {
62 #define X(p) {p, #p}
63 X(EMR_HEADER),
64 X(EMR_POLYBEZIER),
65 X(EMR_POLYGON),
66 X(EMR_POLYLINE),
67 X(EMR_POLYBEZIERTO),
68 X(EMR_POLYLINETO),
69 X(EMR_POLYPOLYLINE),
70 X(EMR_POLYPOLYGON),
71 X(EMR_SETWINDOWEXTEX),
72 X(EMR_SETWINDOWORGEX),
73 X(EMR_SETVIEWPORTEXTEX),
74 X(EMR_SETVIEWPORTORGEX),
75 X(EMR_SETBRUSHORGEX),
76 X(EMR_EOF),
77 X(EMR_SETPIXELV),
78 X(EMR_SETMAPPERFLAGS),
79 X(EMR_SETMAPMODE),
80 X(EMR_SETBKMODE),
81 X(EMR_SETPOLYFILLMODE),
82 X(EMR_SETROP2),
83 X(EMR_SETSTRETCHBLTMODE),
84 X(EMR_SETTEXTALIGN),
85 X(EMR_SETCOLORADJUSTMENT),
86 X(EMR_SETTEXTCOLOR),
87 X(EMR_SETBKCOLOR),
88 X(EMR_OFFSETCLIPRGN),
89 X(EMR_MOVETOEX),
90 X(EMR_SETMETARGN),
91 X(EMR_EXCLUDECLIPRECT),
92 X(EMR_INTERSECTCLIPRECT),
93 X(EMR_SCALEVIEWPORTEXTEX),
94 X(EMR_SCALEWINDOWEXTEX),
95 X(EMR_SAVEDC),
96 X(EMR_RESTOREDC),
97 X(EMR_SETWORLDTRANSFORM),
98 X(EMR_MODIFYWORLDTRANSFORM),
99 X(EMR_SELECTOBJECT),
100 X(EMR_CREATEPEN),
101 X(EMR_CREATEBRUSHINDIRECT),
102 X(EMR_DELETEOBJECT),
103 X(EMR_ANGLEARC),
104 X(EMR_ELLIPSE),
105 X(EMR_RECTANGLE),
106 X(EMR_ROUNDRECT),
107 X(EMR_ARC),
108 X(EMR_CHORD),
109 X(EMR_PIE),
110 X(EMR_SELECTPALETTE),
111 X(EMR_CREATEPALETTE),
112 X(EMR_SETPALETTEENTRIES),
113 X(EMR_RESIZEPALETTE),
114 X(EMR_REALIZEPALETTE),
115 X(EMR_EXTFLOODFILL),
116 X(EMR_LINETO),
117 X(EMR_ARCTO),
118 X(EMR_POLYDRAW),
119 X(EMR_SETARCDIRECTION),
120 X(EMR_SETMITERLIMIT),
121 X(EMR_BEGINPATH),
122 X(EMR_ENDPATH),
123 X(EMR_CLOSEFIGURE),
124 X(EMR_FILLPATH),
125 X(EMR_STROKEANDFILLPATH),
126 X(EMR_STROKEPATH),
127 X(EMR_FLATTENPATH),
128 X(EMR_WIDENPATH),
129 X(EMR_SELECTCLIPPATH),
130 X(EMR_ABORTPATH),
131 X(EMR_GDICOMMENT),
132 X(EMR_FILLRGN),
133 X(EMR_FRAMERGN),
134 X(EMR_INVERTRGN),
135 X(EMR_PAINTRGN),
136 X(EMR_EXTSELECTCLIPRGN),
137 X(EMR_BITBLT),
138 X(EMR_STRETCHBLT),
139 X(EMR_MASKBLT),
140 X(EMR_PLGBLT),
141 X(EMR_SETDIBITSTODEVICE),
142 X(EMR_STRETCHDIBITS),
143 X(EMR_EXTCREATEFONTINDIRECTW),
144 X(EMR_EXTTEXTOUTA),
145 X(EMR_EXTTEXTOUTW),
146 X(EMR_POLYBEZIER16),
147 X(EMR_POLYGON16),
148 X(EMR_POLYLINE16),
149 X(EMR_POLYBEZIERTO16),
150 X(EMR_POLYLINETO16),
151 X(EMR_POLYPOLYLINE16),
152 X(EMR_POLYPOLYGON16),
153 X(EMR_POLYDRAW16),
154 X(EMR_CREATEMONOBRUSH),
155 X(EMR_CREATEDIBPATTERNBRUSHPT),
156 X(EMR_EXTCREATEPEN),
157 X(EMR_POLYTEXTOUTA),
158 X(EMR_POLYTEXTOUTW),
159 X(EMR_SETICMMODE),
160 X(EMR_CREATECOLORSPACE),
161 X(EMR_SETCOLORSPACE),
162 X(EMR_DELETECOLORSPACE),
163 X(EMR_GLSRECORD),
164 X(EMR_GLSBOUNDEDRECORD),
165 X(EMR_PIXELFORMAT),
166 X(EMR_DRAWESCAPE),
167 X(EMR_EXTESCAPE),
168 X(EMR_STARTDOC),
169 X(EMR_SMALLTEXTOUT),
170 X(EMR_FORCEUFIMAPPING),
171 X(EMR_NAMEDESCAPE),
172 X(EMR_COLORCORRECTPALETTE),
173 X(EMR_SETICMPROFILEA),
174 X(EMR_SETICMPROFILEW),
175 X(EMR_ALPHABLEND),
176 X(EMR_SETLAYOUT),
177 X(EMR_TRANSPARENTBLT),
178 X(EMR_RESERVED_117),
179 X(EMR_GRADIENTFILL),
180 X(EMR_SETLINKEDUFI),
181 X(EMR_SETTEXTJUSTIFICATION),
182 X(EMR_COLORMATCHTOTARGETW),
183 X(EMR_CREATECOLORSPACEW)
184 #undef X
187 /****************************************************************************
188 * get_emr_name
190 static const char *get_emr_name(DWORD type)
192 int i;
193 for(i = 0; i < sizeof(emr_names) / sizeof(emr_names[0]); i++)
194 if(type == emr_names[i].type) return emr_names[i].name;
195 TRACE("Unknown record type %ld\n", type);
196 return NULL;
199 /****************************************************************************
200 * EMF_Create_HENHMETAFILE
202 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk )
204 HENHMETAFILE hmf = 0;
205 ENHMETAFILEOBJ *metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
206 ENHMETAFILE_MAGIC,
207 (HGDIOBJ *)&hmf, NULL );
208 if (metaObj)
210 metaObj->emh = emh;
211 metaObj->on_disk = on_disk;
212 GDI_ReleaseObj( hmf );
214 return hmf;
217 /****************************************************************************
218 * EMF_Delete_HENHMETAFILE
220 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
222 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
223 ENHMETAFILE_MAGIC );
224 if(!metaObj) return FALSE;
226 if(metaObj->on_disk)
227 UnmapViewOfFile( metaObj->emh );
228 else
229 HeapFree( GetProcessHeap(), 0, metaObj->emh );
230 return GDI_FreeObject( hmf, metaObj );
233 /******************************************************************
234 * EMF_GetEnhMetaHeader
236 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
238 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
240 ENHMETAHEADER *ret = NULL;
241 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
242 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
243 if (metaObj)
245 ret = metaObj->emh;
246 GDI_ReleaseObj( hmf );
248 return ret;
251 /*****************************************************************************
252 * EMF_GetEnhMetaFile
255 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
257 ENHMETAHEADER *emh;
258 HANDLE hMapping;
260 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
261 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
262 CloseHandle( hMapping );
264 if (!emh) return 0;
266 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
267 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
268 emh->iType, emh->dSignature);
269 goto err;
272 /* refuse to load unaligned EMF as Windows does */
273 if (emh->nBytes & 3)
275 WARN("Refusing to load unaligned EMF\n");
276 goto err;
279 return EMF_Create_HENHMETAFILE( emh, TRUE );
281 err:
282 UnmapViewOfFile( emh );
283 return 0;
287 /*****************************************************************************
288 * GetEnhMetaFileA (GDI32.@)
292 HENHMETAFILE WINAPI GetEnhMetaFileA(
293 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
296 HENHMETAFILE hmf;
297 HANDLE hFile;
299 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
300 OPEN_EXISTING, 0, 0);
301 if (hFile == INVALID_HANDLE_VALUE) {
302 WARN("could not open %s\n", lpszMetaFile);
303 return 0;
305 hmf = EMF_GetEnhMetaFile( hFile );
306 CloseHandle( hFile );
307 return hmf;
310 /*****************************************************************************
311 * GetEnhMetaFileW (GDI32.@)
313 HENHMETAFILE WINAPI GetEnhMetaFileW(
314 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
316 HENHMETAFILE hmf;
317 HANDLE hFile;
319 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
320 OPEN_EXISTING, 0, 0);
321 if (hFile == INVALID_HANDLE_VALUE) {
322 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
323 return 0;
325 hmf = EMF_GetEnhMetaFile( hFile );
326 CloseHandle( hFile );
327 return hmf;
330 /*****************************************************************************
331 * GetEnhMetaFileHeader (GDI32.@)
333 * If buf is NULL, returns the size of buffer required.
334 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
335 * buf.
337 UINT WINAPI GetEnhMetaFileHeader(
338 HENHMETAFILE hmf, /* [in] enhanced metafile */
339 UINT bufsize, /* [in] size of buffer */
340 LPENHMETAHEADER buf /* [out] buffer */
343 LPENHMETAHEADER emh;
344 UINT size;
346 emh = EMF_GetEnhMetaHeader(hmf);
347 if(!emh) return FALSE;
348 size = emh->nSize;
349 if (!buf) return size;
350 size = min(size, bufsize);
351 memmove(buf, emh, size);
352 return size;
356 /*****************************************************************************
357 * GetEnhMetaFileDescriptionA (GDI32.@)
359 UINT WINAPI GetEnhMetaFileDescriptionA(
360 HENHMETAFILE hmf, /* [in] enhanced metafile */
361 UINT size, /* [in] size of buf */
362 LPSTR buf /* [out] buffer to receive description */
365 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
366 DWORD len;
367 WCHAR *descrW;
369 if(!emh) return FALSE;
370 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
371 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
372 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
374 if (!buf || !size ) return len;
376 len = min( size, len );
377 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
378 return len;
381 /*****************************************************************************
382 * GetEnhMetaFileDescriptionW (GDI32.@)
384 * Copies the description string of an enhanced metafile into a buffer
385 * _buf_.
387 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
388 * number of characters copied.
390 UINT WINAPI GetEnhMetaFileDescriptionW(
391 HENHMETAFILE hmf, /* [in] enhanced metafile */
392 UINT size, /* [in] size of buf */
393 LPWSTR buf /* [out] buffer to receive description */
396 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
398 if(!emh) return FALSE;
399 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
400 if (!buf || !size ) return emh->nDescription;
402 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
403 return min(size, emh->nDescription);
406 /****************************************************************************
407 * SetEnhMetaFileBits (GDI32.@)
409 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
411 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
413 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
414 memmove(emh, buf, bufsize);
415 return EMF_Create_HENHMETAFILE( emh, FALSE );
418 /*****************************************************************************
419 * GetEnhMetaFileBits (GDI32.@)
422 UINT WINAPI GetEnhMetaFileBits(
423 HENHMETAFILE hmf,
424 UINT bufsize,
425 LPBYTE buf
428 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
429 UINT size;
431 if(!emh) return 0;
433 size = emh->nBytes;
434 if( buf == NULL ) return size;
436 size = min( size, bufsize );
437 memmove(buf, emh, size);
438 return size;
441 typedef struct enum_emh_data
443 INT mode;
444 XFORM init_transform;
445 XFORM world_transform;
446 INT wndOrgX;
447 INT wndOrgY;
448 INT wndExtX;
449 INT wndExtY;
450 INT vportOrgX;
451 INT vportOrgY;
452 INT vportExtX;
453 INT vportExtY;
454 } enum_emh_data;
456 #define ENUM_GET_PRIVATE_DATA(ht) \
457 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
459 #define WIDTH(rect) ( (rect).right - (rect).left )
460 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
462 #define IS_WIN9X() (GetVersion()&0x80000000)
464 void EMF_Update_MF_Xform(HDC hdc, enum_emh_data *info)
466 XFORM mapping_mode_trans, final_trans;
467 FLOAT scaleX, scaleY;
469 scaleX = (FLOAT)info->vportExtX / (FLOAT)info->wndExtX;
470 scaleY = (FLOAT)info->vportExtY / (FLOAT)info->wndExtY;
471 mapping_mode_trans.eM11 = scaleX;
472 mapping_mode_trans.eM12 = 0.0;
473 mapping_mode_trans.eM21 = 0.0;
474 mapping_mode_trans.eM22 = scaleY;
475 mapping_mode_trans.eDx = (FLOAT)info->vportOrgX - scaleX * (FLOAT)info->wndOrgX;
476 mapping_mode_trans.eDy = (FLOAT)info->vportOrgY - scaleY * (FLOAT)info->wndOrgY;
478 CombineTransform(&final_trans, &info->world_transform, &mapping_mode_trans);
479 CombineTransform(&final_trans, &final_trans, &info->init_transform);
481 if (!SetWorldTransform(hdc, &final_trans))
483 ERR("World transform failed!\n");
487 void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
489 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
490 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
491 INT horzRes = GetDeviceCaps( hdc, HORZRES );
492 INT vertRes = GetDeviceCaps( hdc, VERTRES );
494 TRACE("%d\n",info->mode);
496 switch(info->mode)
498 case MM_TEXT:
499 info->wndExtX = 1;
500 info->wndExtY = 1;
501 info->vportExtX = 1;
502 info->vportExtY = 1;
503 break;
504 case MM_LOMETRIC:
505 case MM_ISOTROPIC:
506 info->wndExtX = horzSize * 10;
507 info->wndExtY = vertSize * 10;
508 info->vportExtX = horzRes;
509 info->vportExtY = -vertRes;
510 break;
511 case MM_HIMETRIC:
512 info->wndExtX = horzSize * 100;
513 info->wndExtY = vertSize * 100;
514 info->vportExtX = horzRes;
515 info->vportExtY = -vertRes;
516 break;
517 case MM_LOENGLISH:
518 info->wndExtX = MulDiv(1000, horzSize, 254);
519 info->wndExtY = MulDiv(1000, vertSize, 254);
520 info->vportExtX = horzRes;
521 info->vportExtY = -vertRes;
522 break;
523 case MM_HIENGLISH:
524 info->wndExtX = MulDiv(10000, horzSize, 254);
525 info->wndExtY = MulDiv(10000, vertSize, 254);
526 info->vportExtX = horzRes;
527 info->vportExtY = -vertRes;
528 break;
529 case MM_TWIPS:
530 info->wndExtX = MulDiv(14400, horzSize, 254);
531 info->wndExtY = MulDiv(14400, vertSize, 254);
532 info->vportExtX = horzRes;
533 info->vportExtY = -vertRes;
534 break;
535 case MM_ANISOTROPIC:
536 break;
537 default:
538 return;
542 /*****************************************************************************
543 * emr_produces_output
545 * Returns TRUE if the record type writes something to the dc. Used by
546 * PlayEnhMetaFileRecord to determine whether it needs to update the
547 * dc's xform when in win9x mode.
549 * FIXME: need to test which records should be here.
551 static BOOL emr_produces_output(int type)
553 switch(type) {
554 case EMR_POLYBEZIER:
555 case EMR_POLYGON:
556 case EMR_POLYLINE:
557 case EMR_POLYBEZIERTO:
558 case EMR_POLYLINETO:
559 case EMR_POLYPOLYLINE:
560 case EMR_POLYPOLYGON:
561 case EMR_SETPIXELV:
562 case EMR_MOVETOEX:
563 case EMR_EXCLUDECLIPRECT:
564 case EMR_INTERSECTCLIPRECT:
565 case EMR_SELECTOBJECT:
566 case EMR_ANGLEARC:
567 case EMR_ELLIPSE:
568 case EMR_RECTANGLE:
569 case EMR_ROUNDRECT:
570 case EMR_ARC:
571 case EMR_CHORD:
572 case EMR_PIE:
573 case EMR_EXTFLOODFILL:
574 case EMR_LINETO:
575 case EMR_ARCTO:
576 case EMR_POLYDRAW:
577 case EMR_FILLRGN:
578 case EMR_FRAMERGN:
579 case EMR_INVERTRGN:
580 case EMR_PAINTRGN:
581 case EMR_BITBLT:
582 case EMR_STRETCHBLT:
583 case EMR_MASKBLT:
584 case EMR_PLGBLT:
585 case EMR_SETDIBITSTODEVICE:
586 case EMR_STRETCHDIBITS:
587 case EMR_EXTTEXTOUTA:
588 case EMR_EXTTEXTOUTW:
589 case EMR_POLYBEZIER16:
590 case EMR_POLYGON16:
591 case EMR_POLYLINE16:
592 case EMR_POLYBEZIERTO16:
593 case EMR_POLYLINETO16:
594 case EMR_POLYPOLYLINE16:
595 case EMR_POLYPOLYGON16:
596 case EMR_POLYDRAW16:
597 case EMR_POLYTEXTOUTA:
598 case EMR_POLYTEXTOUTW:
599 case EMR_SMALLTEXTOUT:
600 case EMR_TRANSPARENTBLT:
601 return TRUE;
602 default:
603 return FALSE;
608 /*****************************************************************************
609 * PlayEnhMetaFileRecord (GDI32.@)
611 * Render a single enhanced metafile record in the device context hdc.
613 * RETURNS
614 * TRUE (non zero) on success, FALSE on error.
615 * BUGS
616 * Many unimplemented records.
617 * No error handling on record play failures (ie checking return codes)
619 * NOTES
620 * WinNT actually updates the current world transform in this function
621 * whereas Win9x does not.
623 BOOL WINAPI PlayEnhMetaFileRecord(
624 HDC hdc, /* [in] device context in which to render EMF record */
625 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
626 const ENHMETARECORD *mr, /* [in] EMF record to render */
627 UINT handles /* [in] size of handle array */
630 int type;
631 RECT tmprc;
632 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
634 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
635 hdc, handletable, mr, handles);
636 if (!mr) return FALSE;
638 type = mr->iType;
640 /* In Win9x mode we update the xform if the record will produce output */
641 if ( IS_WIN9X() && emr_produces_output(type) )
642 EMF_Update_MF_Xform(hdc, info);
644 TRACE("record %s\n", get_emr_name(type));
645 switch(type)
647 case EMR_HEADER:
648 break;
649 case EMR_EOF:
650 break;
651 case EMR_GDICOMMENT:
653 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
654 /* In an enhanced metafile, there can be both public and private GDI comments */
655 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
656 break;
658 case EMR_SETMAPMODE:
660 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
662 if(info->mode == pSetMapMode->iMode && (info->mode == MM_ISOTROPIC || info->mode == MM_ANISOTROPIC))
663 break;
664 info->mode = pSetMapMode->iMode;
665 EMF_SetMapMode(hdc, info);
666 break;
668 case EMR_SETBKMODE:
670 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
671 SetBkMode(hdc, pSetBkMode->iMode);
672 break;
674 case EMR_SETBKCOLOR:
676 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
677 SetBkColor(hdc, pSetBkColor->crColor);
678 break;
680 case EMR_SETPOLYFILLMODE:
682 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
683 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
684 break;
686 case EMR_SETROP2:
688 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
689 SetROP2(hdc, pSetROP2->iMode);
690 break;
692 case EMR_SETSTRETCHBLTMODE:
694 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
695 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
696 break;
698 case EMR_SETTEXTALIGN:
700 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
701 SetTextAlign(hdc, pSetTextAlign->iMode);
702 break;
704 case EMR_SETTEXTCOLOR:
706 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
707 SetTextColor(hdc, pSetTextColor->crColor);
708 break;
710 case EMR_SAVEDC:
712 SaveDC(hdc);
713 break;
715 case EMR_RESTOREDC:
717 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
718 TRACE("EMR_RESTORE: %ld\n", pRestoreDC->iRelative);
719 RestoreDC(hdc, pRestoreDC->iRelative);
720 break;
722 case EMR_INTERSECTCLIPRECT:
724 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
725 TRACE("EMR_INTERSECTCLIPRECT: rect %ld,%ld - %ld, %ld\n",
726 pClipRect->rclClip.left, pClipRect->rclClip.top,
727 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
728 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
729 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
730 break;
732 case EMR_SELECTOBJECT:
734 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
735 if( pSelectObject->ihObject & 0x80000000 ) {
736 /* High order bit is set - it's a stock object
737 * Strip the high bit to get the index.
738 * See MSDN article Q142319
740 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
741 0x7fffffff ) );
742 } else {
743 /* High order bit wasn't set - not a stock object
745 SelectObject( hdc,
746 (handletable->objectHandle)[pSelectObject->ihObject] );
748 break;
750 case EMR_DELETEOBJECT:
752 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
753 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
754 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
755 break;
757 case EMR_SETWINDOWORGEX:
759 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
761 info->wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
762 info->wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
764 TRACE("SetWindowOrgEx: %d,%d\n",info->wndOrgX,info->wndOrgY);
765 break;
767 case EMR_SETWINDOWEXTEX:
769 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
771 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
772 break;
773 info->wndExtX = pSetWindowExtEx->szlExtent.cx;
774 info->wndExtY = pSetWindowExtEx->szlExtent.cy;
776 TRACE("SetWindowExtEx: %d,%d\n",info->wndExtX,info->wndExtY);
777 break;
779 case EMR_SETVIEWPORTORGEX:
781 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
782 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
784 info->vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
785 info->vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
786 TRACE("SetViewportOrgEx: %d,%d\n",info->vportOrgX,info->vportOrgY);
787 break;
789 case EMR_SETVIEWPORTEXTEX:
791 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
792 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
794 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
795 break;
796 info->vportExtX = pSetViewportExtEx->szlExtent.cx;
797 info->vportExtY = pSetViewportExtEx->szlExtent.cy;
798 TRACE("SetViewportExtEx: %d,%d\n",info->vportExtX,info->vportExtY);
799 break;
801 case EMR_CREATEPEN:
803 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
804 (handletable->objectHandle)[pCreatePen->ihPen] =
805 CreatePenIndirect(&pCreatePen->lopn);
806 break;
808 case EMR_EXTCREATEPEN:
810 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
811 LOGBRUSH lb;
812 lb.lbStyle = pPen->elp.elpBrushStyle;
813 lb.lbColor = pPen->elp.elpColor;
814 lb.lbHatch = pPen->elp.elpHatch;
816 if(pPen->offBmi || pPen->offBits)
817 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
819 (handletable->objectHandle)[pPen->ihPen] =
820 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
821 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
822 break;
824 case EMR_CREATEBRUSHINDIRECT:
826 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
827 (handletable->objectHandle)[pBrush->ihBrush] =
828 CreateBrushIndirect(&pBrush->lb);
829 break;
831 case EMR_EXTCREATEFONTINDIRECTW:
833 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
834 (handletable->objectHandle)[pFont->ihFont] =
835 CreateFontIndirectW(&pFont->elfw.elfLogFont);
836 break;
838 case EMR_MOVETOEX:
840 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
841 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
842 break;
844 case EMR_LINETO:
846 PEMRLINETO pLineTo = (PEMRLINETO) mr;
847 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
848 break;
850 case EMR_RECTANGLE:
852 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
853 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
854 pRect->rclBox.right, pRect->rclBox.bottom);
855 break;
857 case EMR_ELLIPSE:
859 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
860 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
861 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
862 break;
864 case EMR_POLYGON16:
866 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
867 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
868 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
869 pPoly->cpts * sizeof(POINT) );
870 DWORD i;
871 for(i = 0; i < pPoly->cpts; i++)
872 CONV_POINT16TO32(pPoly->apts + i, pts + i);
873 Polygon(hdc, pts, pPoly->cpts);
874 HeapFree( GetProcessHeap(), 0, pts );
875 break;
877 case EMR_POLYLINE16:
879 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
880 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
881 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
882 pPoly->cpts * sizeof(POINT) );
883 DWORD i;
884 for(i = 0; i < pPoly->cpts; i++)
885 CONV_POINT16TO32(pPoly->apts + i, pts + i);
886 Polyline(hdc, pts, pPoly->cpts);
887 HeapFree( GetProcessHeap(), 0, pts );
888 break;
890 case EMR_POLYLINETO16:
892 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
893 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
894 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
895 pPoly->cpts * sizeof(POINT) );
896 DWORD i;
897 for(i = 0; i < pPoly->cpts; i++)
898 CONV_POINT16TO32(pPoly->apts + i, pts + i);
899 PolylineTo(hdc, pts, pPoly->cpts);
900 HeapFree( GetProcessHeap(), 0, pts );
901 break;
903 case EMR_POLYBEZIER16:
905 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
906 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
907 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
908 pPoly->cpts * sizeof(POINT) );
909 DWORD i;
910 for(i = 0; i < pPoly->cpts; i++)
911 CONV_POINT16TO32(pPoly->apts + i, pts + i);
912 PolyBezier(hdc, pts, pPoly->cpts);
913 HeapFree( GetProcessHeap(), 0, pts );
914 break;
916 case EMR_POLYBEZIERTO16:
918 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
919 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
920 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
921 pPoly->cpts * sizeof(POINT) );
922 DWORD i;
923 for(i = 0; i < pPoly->cpts; i++)
924 CONV_POINT16TO32(pPoly->apts + i, pts + i);
925 PolyBezierTo(hdc, pts, pPoly->cpts);
926 HeapFree( GetProcessHeap(), 0, pts );
927 break;
929 case EMR_POLYPOLYGON16:
931 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
932 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
933 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
935 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
936 pPolyPoly->cpts * sizeof(POINT) );
937 DWORD i;
938 for(i = 0; i < pPolyPoly->cpts; i++)
939 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
940 pPolyPoly->nPolys) + i, pts + i);
942 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
943 HeapFree( GetProcessHeap(), 0, pts );
944 break;
946 case EMR_POLYPOLYLINE16:
948 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
949 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
950 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
952 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
953 pPolyPoly->cpts * sizeof(POINT) );
954 DWORD i;
955 for(i = 0; i < pPolyPoly->cpts; i++)
956 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
957 pPolyPoly->nPolys) + i, pts + i);
959 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
960 HeapFree( GetProcessHeap(), 0, pts );
961 break;
964 case EMR_STRETCHDIBITS:
966 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
968 StretchDIBits(hdc,
969 pStretchDIBits->xDest,
970 pStretchDIBits->yDest,
971 pStretchDIBits->cxDest,
972 pStretchDIBits->cyDest,
973 pStretchDIBits->xSrc,
974 pStretchDIBits->ySrc,
975 pStretchDIBits->cxSrc,
976 pStretchDIBits->cySrc,
977 (BYTE *)mr + pStretchDIBits->offBitsSrc,
978 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
979 pStretchDIBits->iUsageSrc,
980 pStretchDIBits->dwRop);
981 break;
984 case EMR_EXTTEXTOUTA:
986 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
987 RECT rc;
989 rc.left = pExtTextOutA->emrtext.rcl.left;
990 rc.top = pExtTextOutA->emrtext.rcl.top;
991 rc.right = pExtTextOutA->emrtext.rcl.right;
992 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
993 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
994 pExtTextOutA->emrtext.fOptions, &rc,
995 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
996 (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx));
997 break;
1000 case EMR_EXTTEXTOUTW:
1002 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
1003 RECT rc;
1005 rc.left = pExtTextOutW->emrtext.rcl.left;
1006 rc.top = pExtTextOutW->emrtext.rcl.top;
1007 rc.right = pExtTextOutW->emrtext.rcl.right;
1008 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
1009 TRACE("EMR_EXTTEXTOUTW: x,y = %ld, %ld. rect = %ld, %ld - %ld, %ld. flags %08lx\n",
1010 pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1011 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutW->emrtext.fOptions);
1013 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1014 pExtTextOutW->emrtext.fOptions, &rc,
1015 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
1016 (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx));
1017 break;
1020 case EMR_CREATEPALETTE:
1022 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
1024 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
1025 CreatePalette( &lpCreatePal->lgpl );
1027 break;
1030 case EMR_SELECTPALETTE:
1032 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
1034 if( lpSelectPal->ihPal & 0x80000000 ) {
1035 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
1036 } else {
1037 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
1038 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
1040 break;
1043 case EMR_REALIZEPALETTE:
1045 RealizePalette( hdc );
1046 break;
1049 case EMR_EXTSELECTCLIPRGN:
1051 #if 0
1052 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
1053 HRGN hRgn = ExtCreateRegion(NULL, lpRgn->cbRgnData, (RGNDATA *)lpRgn->RgnData);
1054 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
1055 /* ExtSelectClipRgn created a copy of the region */
1056 DeleteObject(hRgn);
1057 #endif
1058 FIXME("ExtSelectClipRgn\n");
1059 break;
1062 case EMR_SETMETARGN:
1064 SetMetaRgn( hdc );
1065 break;
1068 case EMR_SETWORLDTRANSFORM:
1070 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
1071 info->world_transform = lpXfrm->xform;
1072 break;
1075 case EMR_POLYBEZIER:
1077 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
1078 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
1079 break;
1082 case EMR_POLYGON:
1084 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
1085 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
1086 break;
1089 case EMR_POLYLINE:
1091 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
1092 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
1093 break;
1096 case EMR_POLYBEZIERTO:
1098 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
1099 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
1100 (UINT)lpPolyBezierTo->cptl );
1101 break;
1104 case EMR_POLYLINETO:
1106 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
1107 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
1108 (UINT)lpPolyLineTo->cptl );
1109 break;
1112 case EMR_POLYPOLYLINE:
1114 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
1115 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1117 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
1118 pPolyPolyline->nPolys),
1119 pPolyPolyline->aPolyCounts,
1120 pPolyPolyline->nPolys );
1122 break;
1125 case EMR_POLYPOLYGON:
1127 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
1129 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1131 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
1132 pPolyPolygon->nPolys),
1133 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
1134 break;
1137 case EMR_SETBRUSHORGEX:
1139 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
1141 SetBrushOrgEx( hdc,
1142 (INT)lpSetBrushOrgEx->ptlOrigin.x,
1143 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1144 NULL );
1146 break;
1149 case EMR_SETPIXELV:
1151 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
1153 SetPixelV( hdc,
1154 (INT)lpSetPixelV->ptlPixel.x,
1155 (INT)lpSetPixelV->ptlPixel.y,
1156 lpSetPixelV->crColor );
1158 break;
1161 case EMR_SETMAPPERFLAGS:
1163 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
1165 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1167 break;
1170 case EMR_SETCOLORADJUSTMENT:
1172 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
1174 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1176 break;
1179 case EMR_OFFSETCLIPRGN:
1181 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
1183 OffsetClipRgn( hdc,
1184 (INT)lpOffsetClipRgn->ptlOffset.x,
1185 (INT)lpOffsetClipRgn->ptlOffset.y );
1186 FIXME("OffsetClipRgn\n");
1188 break;
1191 case EMR_EXCLUDECLIPRECT:
1193 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
1195 ExcludeClipRect( hdc,
1196 lpExcludeClipRect->rclClip.left,
1197 lpExcludeClipRect->rclClip.top,
1198 lpExcludeClipRect->rclClip.right,
1199 lpExcludeClipRect->rclClip.bottom );
1200 FIXME("ExcludeClipRect\n");
1202 break;
1205 case EMR_SCALEVIEWPORTEXTEX:
1207 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
1209 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1210 break;
1211 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1212 !lpScaleViewportExtEx->yNum || !lpScaleViewportExtEx->yDenom)
1213 break;
1214 info->vportExtX = (info->vportExtX * lpScaleViewportExtEx->xNum) /
1215 lpScaleViewportExtEx->xDenom;
1216 info->vportExtY = (info->vportExtY * lpScaleViewportExtEx->yNum) /
1217 lpScaleViewportExtEx->yDenom;
1218 if (info->vportExtX == 0) info->vportExtX = 1;
1219 if (info->vportExtY == 0) info->vportExtY = 1;
1220 if (info->mode == MM_ISOTROPIC)
1221 FIXME("EMRSCALEVIEWPORTEXTEX MM_ISOTROPIC mapping\n");
1222 /* MAPPING_FixIsotropic( dc ); */
1224 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1225 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1226 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1228 break;
1231 case EMR_SCALEWINDOWEXTEX:
1233 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
1235 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1236 break;
1237 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1238 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1239 break;
1240 info->wndExtX = (info->wndExtX * lpScaleWindowExtEx->xNum) /
1241 lpScaleWindowExtEx->xDenom;
1242 info->wndExtY = (info->wndExtY * lpScaleWindowExtEx->yNum) /
1243 lpScaleWindowExtEx->yDenom;
1244 if (info->wndExtX == 0) info->wndExtX = 1;
1245 if (info->wndExtY == 0) info->wndExtY = 1;
1246 if (info->mode == MM_ISOTROPIC)
1247 FIXME("EMRSCALEWINDOWEXTEX MM_ISOTROPIC mapping\n");
1248 /* MAPPING_FixIsotropic( dc ); */
1250 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1251 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1252 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1254 break;
1257 case EMR_MODIFYWORLDTRANSFORM:
1259 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
1261 switch(lpModifyWorldTrans->iMode) {
1262 case MWT_IDENTITY:
1263 info->world_transform.eM11 = info->world_transform.eM22 = 1;
1264 info->world_transform.eM12 = info->world_transform.eM21 = 0;
1265 info->world_transform.eDx = info->world_transform.eDy = 0;
1266 break;
1267 case MWT_LEFTMULTIPLY:
1268 CombineTransform(&info->world_transform, &lpModifyWorldTrans->xform,
1269 &info->world_transform);
1270 break;
1271 case MWT_RIGHTMULTIPLY:
1272 CombineTransform(&info->world_transform, &info->world_transform,
1273 &lpModifyWorldTrans->xform);
1274 break;
1275 default:
1276 FIXME("Unknown imode %ld\n", lpModifyWorldTrans->iMode);
1277 break;
1279 break;
1282 case EMR_ANGLEARC:
1284 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
1286 AngleArc( hdc,
1287 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1288 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1289 lpAngleArc->eSweepAngle );
1291 break;
1294 case EMR_ROUNDRECT:
1296 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
1298 RoundRect( hdc,
1299 lpRoundRect->rclBox.left,
1300 lpRoundRect->rclBox.top,
1301 lpRoundRect->rclBox.right,
1302 lpRoundRect->rclBox.bottom,
1303 lpRoundRect->szlCorner.cx,
1304 lpRoundRect->szlCorner.cy );
1306 break;
1309 case EMR_ARC:
1311 PEMRARC lpArc = (PEMRARC)mr;
1313 Arc( hdc,
1314 (INT)lpArc->rclBox.left,
1315 (INT)lpArc->rclBox.top,
1316 (INT)lpArc->rclBox.right,
1317 (INT)lpArc->rclBox.bottom,
1318 (INT)lpArc->ptlStart.x,
1319 (INT)lpArc->ptlStart.y,
1320 (INT)lpArc->ptlEnd.x,
1321 (INT)lpArc->ptlEnd.y );
1323 break;
1326 case EMR_CHORD:
1328 PEMRCHORD lpChord = (PEMRCHORD)mr;
1330 Chord( hdc,
1331 (INT)lpChord->rclBox.left,
1332 (INT)lpChord->rclBox.top,
1333 (INT)lpChord->rclBox.right,
1334 (INT)lpChord->rclBox.bottom,
1335 (INT)lpChord->ptlStart.x,
1336 (INT)lpChord->ptlStart.y,
1337 (INT)lpChord->ptlEnd.x,
1338 (INT)lpChord->ptlEnd.y );
1340 break;
1343 case EMR_PIE:
1345 PEMRPIE lpPie = (PEMRPIE)mr;
1347 Pie( hdc,
1348 (INT)lpPie->rclBox.left,
1349 (INT)lpPie->rclBox.top,
1350 (INT)lpPie->rclBox.right,
1351 (INT)lpPie->rclBox.bottom,
1352 (INT)lpPie->ptlStart.x,
1353 (INT)lpPie->ptlStart.y,
1354 (INT)lpPie->ptlEnd.x,
1355 (INT)lpPie->ptlEnd.y );
1357 break;
1360 case EMR_ARCTO:
1362 PEMRARC lpArcTo = (PEMRARC)mr;
1364 ArcTo( hdc,
1365 (INT)lpArcTo->rclBox.left,
1366 (INT)lpArcTo->rclBox.top,
1367 (INT)lpArcTo->rclBox.right,
1368 (INT)lpArcTo->rclBox.bottom,
1369 (INT)lpArcTo->ptlStart.x,
1370 (INT)lpArcTo->ptlStart.y,
1371 (INT)lpArcTo->ptlEnd.x,
1372 (INT)lpArcTo->ptlEnd.y );
1374 break;
1377 case EMR_EXTFLOODFILL:
1379 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
1381 ExtFloodFill( hdc,
1382 (INT)lpExtFloodFill->ptlStart.x,
1383 (INT)lpExtFloodFill->ptlStart.y,
1384 lpExtFloodFill->crColor,
1385 (UINT)lpExtFloodFill->iMode );
1387 break;
1390 case EMR_POLYDRAW:
1392 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
1393 PolyDraw( hdc,
1394 (const LPPOINT)lpPolyDraw->aptl,
1395 lpPolyDraw->abTypes,
1396 (INT)lpPolyDraw->cptl );
1398 break;
1401 case EMR_SETARCDIRECTION:
1403 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1404 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1405 break;
1408 case EMR_SETMITERLIMIT:
1410 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1411 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1412 break;
1415 case EMR_BEGINPATH:
1417 BeginPath( hdc );
1418 break;
1421 case EMR_ENDPATH:
1423 EndPath( hdc );
1424 break;
1427 case EMR_CLOSEFIGURE:
1429 CloseFigure( hdc );
1430 break;
1433 case EMR_FILLPATH:
1435 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1436 FillPath( hdc );
1437 break;
1440 case EMR_STROKEANDFILLPATH:
1442 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1443 StrokeAndFillPath( hdc );
1444 break;
1447 case EMR_STROKEPATH:
1449 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1450 StrokePath( hdc );
1451 break;
1454 case EMR_FLATTENPATH:
1456 FlattenPath( hdc );
1457 break;
1460 case EMR_WIDENPATH:
1462 WidenPath( hdc );
1463 break;
1466 case EMR_SELECTCLIPPATH:
1468 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1469 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1470 break;
1473 case EMR_ABORTPATH:
1475 AbortPath( hdc );
1476 break;
1479 case EMR_CREATECOLORSPACE:
1481 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1482 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1483 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1484 break;
1487 case EMR_SETCOLORSPACE:
1489 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1490 SetColorSpace( hdc,
1491 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1492 break;
1495 case EMR_DELETECOLORSPACE:
1497 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1498 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1499 break;
1502 case EMR_SETICMMODE:
1504 PEMRSETICMMODE lpSetICMMode = (PEMRSETICMMODE)mr;
1505 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1506 break;
1509 case EMR_PIXELFORMAT:
1511 INT iPixelFormat;
1512 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1514 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1515 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1517 break;
1520 case EMR_SETPALETTEENTRIES:
1522 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1524 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1525 (UINT)lpSetPaletteEntries->iStart,
1526 (UINT)lpSetPaletteEntries->cEntries,
1527 lpSetPaletteEntries->aPalEntries );
1529 break;
1532 case EMR_RESIZEPALETTE:
1534 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1536 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1537 (UINT)lpResizePalette->cEntries );
1539 break;
1542 case EMR_CREATEDIBPATTERNBRUSHPT:
1544 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1545 LPVOID lpPackedStruct;
1547 /* check that offsets and data are contained within the record */
1548 if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
1549 (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
1550 ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
1551 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
1553 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1554 break;
1557 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1558 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1559 lpCreate->cbBmi + lpCreate->cbBits );
1560 if(!lpPackedStruct)
1562 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1563 break;
1566 /* Now pack this structure */
1567 memcpy( lpPackedStruct,
1568 ((BYTE*)lpCreate) + lpCreate->offBmi,
1569 lpCreate->cbBmi );
1570 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1571 ((BYTE*)lpCreate) + lpCreate->offBits,
1572 lpCreate->cbBits );
1574 (handletable->objectHandle)[lpCreate->ihBrush] =
1575 CreateDIBPatternBrushPt( lpPackedStruct,
1576 (UINT)lpCreate->iUsage );
1578 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1580 break;
1583 case EMR_CREATEMONOBRUSH:
1585 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1586 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1587 HBITMAP hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1588 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1589 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1590 /* CreatePatternBrush created a copy of the bitmap */
1591 DeleteObject(hBmp);
1592 break;
1595 case EMR_BITBLT:
1597 PEMRBITBLT pBitBlt = (PEMRBITBLT)mr;
1599 if(pBitBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1600 PatBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1601 pBitBlt->dwRop);
1602 } else { /* BitBlt */
1603 HDC hdcSrc = CreateCompatibleDC(hdc);
1604 HBRUSH hBrush, hBrushOld;
1605 HBITMAP hBmp = 0, hBmpOld = 0;
1606 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pBitBlt->offBmiSrc);
1608 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1610 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1611 hBrushOld = SelectObject(hdcSrc, hBrush);
1612 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1613 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1614 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1615 SelectObject(hdcSrc, hBrushOld);
1616 DeleteObject(hBrush);
1618 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1619 (BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1620 hBmpOld = SelectObject(hdcSrc, hBmp);
1622 BitBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1623 hdcSrc, pBitBlt->xSrc, pBitBlt->ySrc, pBitBlt->dwRop);
1625 SelectObject(hdcSrc, hBmpOld);
1626 DeleteObject(hBmp);
1627 DeleteDC(hdcSrc);
1629 break;
1632 case EMR_STRETCHBLT:
1634 PEMRSTRETCHBLT pStretchBlt= (PEMRSTRETCHBLT)mr;
1636 TRACE("EMR_STRETCHBLT: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. rop %08lx offBitsSrc %ld\n",
1637 pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1638 pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1639 pStretchBlt->dwRop, pStretchBlt->offBitsSrc);
1641 if(pStretchBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1642 PatBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1643 pStretchBlt->dwRop);
1644 } else { /* StretchBlt */
1645 HDC hdcSrc = CreateCompatibleDC(hdc);
1646 HBRUSH hBrush, hBrushOld;
1647 HBITMAP hBmp = 0, hBmpOld = 0;
1648 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pStretchBlt->offBmiSrc);
1650 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1652 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1653 hBrushOld = SelectObject(hdcSrc, hBrush);
1654 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1655 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1656 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1657 SelectObject(hdcSrc, hBrushOld);
1658 DeleteObject(hBrush);
1660 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1661 (BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1662 hBmpOld = SelectObject(hdcSrc, hBmp);
1664 StretchBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1665 hdcSrc, pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1666 pStretchBlt->dwRop);
1668 SelectObject(hdcSrc, hBmpOld);
1669 DeleteObject(hBmp);
1670 DeleteDC(hdcSrc);
1672 break;
1675 case EMR_MASKBLT:
1677 PEMRMASKBLT pMaskBlt= (PEMRMASKBLT)mr;
1678 HDC hdcSrc = CreateCompatibleDC(hdc);
1679 HBRUSH hBrush, hBrushOld;
1680 HBITMAP hBmp, hBmpOld, hBmpMask;
1681 BITMAPINFO *pbi;
1683 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1685 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1686 hBrushOld = SelectObject(hdcSrc, hBrush);
1687 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1688 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1689 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1690 SelectObject(hdcSrc, hBrushOld);
1691 DeleteObject(hBrush);
1693 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiMask);
1694 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1695 (BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1697 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiSrc);
1698 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1699 (BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1700 hBmpOld = SelectObject(hdcSrc, hBmp);
1701 MaskBlt(hdc,
1702 pMaskBlt->xDest,
1703 pMaskBlt->yDest,
1704 pMaskBlt->cxDest,
1705 pMaskBlt->cyDest,
1706 hdcSrc,
1707 pMaskBlt->xSrc,
1708 pMaskBlt->ySrc,
1709 hBmpMask,
1710 pMaskBlt->xMask,
1711 pMaskBlt->yMask,
1712 pMaskBlt->dwRop);
1713 SelectObject(hdcSrc, hBmpOld);
1714 DeleteObject(hBmp);
1715 DeleteObject(hBmpMask);
1716 DeleteDC(hdcSrc);
1717 break;
1720 case EMR_PLGBLT:
1722 PEMRPLGBLT pPlgBlt= (PEMRPLGBLT)mr;
1723 HDC hdcSrc = CreateCompatibleDC(hdc);
1724 HBRUSH hBrush, hBrushOld;
1725 HBITMAP hBmp, hBmpOld, hBmpMask;
1726 BITMAPINFO *pbi;
1727 POINT pts[3];
1729 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1731 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1732 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1733 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1735 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1736 hBrushOld = SelectObject(hdcSrc, hBrush);
1737 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1738 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1739 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1740 SelectObject(hdcSrc, hBrushOld);
1741 DeleteObject(hBrush);
1743 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiMask);
1744 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1745 (BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1747 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiSrc);
1748 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1749 (BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1750 hBmpOld = SelectObject(hdcSrc, hBmp);
1751 PlgBlt(hdc,
1752 pts,
1753 hdcSrc,
1754 pPlgBlt->xSrc,
1755 pPlgBlt->ySrc,
1756 pPlgBlt->cxSrc,
1757 pPlgBlt->cySrc,
1758 hBmpMask,
1759 pPlgBlt->xMask,
1760 pPlgBlt->yMask);
1761 SelectObject(hdcSrc, hBmpOld);
1762 DeleteObject(hBmp);
1763 DeleteObject(hBmpMask);
1764 DeleteDC(hdcSrc);
1765 break;
1768 case EMR_SETDIBITSTODEVICE:
1770 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice = (PEMRSETDIBITSTODEVICE)mr;
1772 SetDIBitsToDevice(hdc,
1773 pSetDIBitsToDevice->xDest,
1774 pSetDIBitsToDevice->yDest,
1775 pSetDIBitsToDevice->cxSrc,
1776 pSetDIBitsToDevice->cySrc,
1777 pSetDIBitsToDevice->xSrc,
1778 pSetDIBitsToDevice->ySrc,
1779 pSetDIBitsToDevice->iStartScan,
1780 pSetDIBitsToDevice->cScans,
1781 (BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
1782 (BITMAPINFO *)((BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
1783 pSetDIBitsToDevice->iUsageSrc);
1784 break;
1787 case EMR_POLYTEXTOUTA:
1789 PEMRPOLYTEXTOUTA pPolyTextOutA = (PEMRPOLYTEXTOUTA)mr;
1790 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
1791 LONG i;
1792 XFORM xform, xformOld;
1793 int gModeOld;
1795 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
1796 GetWorldTransform(hdc, &xformOld);
1798 xform.eM11 = pPolyTextOutA->exScale;
1799 xform.eM12 = 0.0;
1800 xform.eM21 = 0.0;
1801 xform.eM22 = pPolyTextOutA->eyScale;
1802 xform.eDx = 0.0;
1803 xform.eDy = 0.0;
1804 SetWorldTransform(hdc, &xform);
1806 /* Set up POLYTEXTA structures */
1807 for(i = 0; i < pPolyTextOutA->cStrings; i++)
1809 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
1810 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
1811 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
1812 polytextA[i].lpstr = (LPSTR)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
1813 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
1814 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
1815 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
1816 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
1817 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
1818 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
1820 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
1821 HeapFree(GetProcessHeap(), 0, polytextA);
1823 SetWorldTransform(hdc, &xformOld);
1824 SetGraphicsMode(hdc, gModeOld);
1825 break;
1828 case EMR_POLYTEXTOUTW:
1830 PEMRPOLYTEXTOUTW pPolyTextOutW = (PEMRPOLYTEXTOUTW)mr;
1831 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
1832 LONG i;
1833 XFORM xform, xformOld;
1834 int gModeOld;
1836 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
1837 GetWorldTransform(hdc, &xformOld);
1839 xform.eM11 = pPolyTextOutW->exScale;
1840 xform.eM12 = 0.0;
1841 xform.eM21 = 0.0;
1842 xform.eM22 = pPolyTextOutW->eyScale;
1843 xform.eDx = 0.0;
1844 xform.eDy = 0.0;
1845 SetWorldTransform(hdc, &xform);
1847 /* Set up POLYTEXTW structures */
1848 for(i = 0; i < pPolyTextOutW->cStrings; i++)
1850 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
1851 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
1852 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
1853 polytextW[i].lpstr = (LPWSTR)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
1854 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
1855 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
1856 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
1857 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
1858 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
1859 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
1861 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
1862 HeapFree(GetProcessHeap(), 0, polytextW);
1864 SetWorldTransform(hdc, &xformOld);
1865 SetGraphicsMode(hdc, gModeOld);
1866 break;
1869 case EMR_FILLRGN:
1871 PEMRFILLRGN pFillRgn = (PEMRFILLRGN)mr;
1872 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
1873 FillRgn(hdc,
1874 hRgn,
1875 (handletable->objectHandle)[pFillRgn->ihBrush]);
1876 DeleteObject(hRgn);
1877 break;
1880 case EMR_FRAMERGN:
1882 PEMRFRAMERGN pFrameRgn = (PEMRFRAMERGN)mr;
1883 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
1884 FrameRgn(hdc,
1885 hRgn,
1886 (handletable->objectHandle)[pFrameRgn->ihBrush],
1887 pFrameRgn->szlStroke.cx,
1888 pFrameRgn->szlStroke.cy);
1889 DeleteObject(hRgn);
1890 break;
1893 case EMR_INVERTRGN:
1895 PEMRINVERTRGN pInvertRgn = (PEMRINVERTRGN)mr;
1896 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
1897 InvertRgn(hdc, hRgn);
1898 DeleteObject(hRgn);
1899 break;
1902 case EMR_PAINTRGN:
1904 PEMRPAINTRGN pPaintRgn = (PEMRPAINTRGN)mr;
1905 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
1906 PaintRgn(hdc, hRgn);
1907 DeleteObject(hRgn);
1908 break;
1911 case EMR_SETTEXTJUSTIFICATION:
1913 PEMRSETTEXTJUSTIFICATION pSetTextJust = (PEMRSETTEXTJUSTIFICATION)mr;
1914 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
1915 break;
1918 case EMR_SETLAYOUT:
1920 PEMRSETLAYOUT pSetLayout = (PEMRSETLAYOUT)mr;
1921 SetLayout(hdc, pSetLayout->iMode);
1922 break;
1925 case EMR_POLYDRAW16:
1926 case EMR_GLSRECORD:
1927 case EMR_GLSBOUNDEDRECORD:
1928 case EMR_DRAWESCAPE :
1929 case EMR_EXTESCAPE:
1930 case EMR_STARTDOC:
1931 case EMR_SMALLTEXTOUT:
1932 case EMR_FORCEUFIMAPPING:
1933 case EMR_NAMEDESCAPE:
1934 case EMR_COLORCORRECTPALETTE:
1935 case EMR_SETICMPROFILEA:
1936 case EMR_SETICMPROFILEW:
1937 case EMR_ALPHABLEND:
1938 case EMR_TRANSPARENTBLT:
1939 case EMR_GRADIENTFILL:
1940 case EMR_SETLINKEDUFI:
1941 case EMR_COLORMATCHTOTARGETW:
1942 case EMR_CREATECOLORSPACEW:
1944 default:
1945 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1946 record then ignore and return TRUE. */
1947 FIXME("type %d is unimplemented\n", type);
1948 break;
1950 tmprc.left = tmprc.top = 0;
1951 tmprc.right = tmprc.bottom = 1000;
1952 LPtoDP(hdc, (POINT*)&tmprc, 2);
1953 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", tmprc.left,
1954 tmprc.top, tmprc.right, tmprc.bottom);
1956 if ( !IS_WIN9X() )
1958 /* WinNT - update the transform (win9x updates when the next graphics output
1959 record is played). */
1960 EMF_Update_MF_Xform(hdc, info);
1963 return TRUE;
1967 /*****************************************************************************
1969 * EnumEnhMetaFile (GDI32.@)
1971 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1972 * for each
1973 * record. Returns when either every record has been used or
1974 * when _EnhMetaFunc_ returns FALSE.
1977 * RETURNS
1978 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1979 * returns FALSE.
1981 * BUGS
1982 * Ignores rect.
1984 * NOTES
1985 * This function behaves differently in Win9x and WinNT.
1987 * In WinNT, the DC's world transform is updated as the EMF changes
1988 * the Window/Viewport Extent and Origin or it's world transform.
1989 * The actual Window/Viewport Extent and Origin are left untouched.
1991 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
1992 * updates the scaling itself but only just before a record that
1993 * writes anything to the DC.
1995 * I'm not sure where the data (enum_emh_data) is stored in either
1996 * version. For this implementation, it is stored before the handle
1997 * table, but it could be stored in the DC, in the EMF handle or in
1998 * TLS.
1999 * MJM 5 Oct 2002
2001 BOOL WINAPI EnumEnhMetaFile(
2002 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
2003 HENHMETAFILE hmf, /* [in] EMF to walk */
2004 ENHMFENUMPROC callback, /* [in] callback function */
2005 LPVOID data, /* [in] optional data for callback function */
2006 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
2009 BOOL ret;
2010 ENHMETAHEADER *emh;
2011 ENHMETARECORD *emr;
2012 DWORD offset;
2013 UINT i;
2014 HANDLETABLE *ht;
2015 INT savedMode = 0;
2016 XFORM savedXform;
2017 HPEN hPen = NULL;
2018 HBRUSH hBrush = NULL;
2019 HFONT hFont = NULL;
2020 enum_emh_data *info;
2021 SIZE vp_size, win_size;
2022 POINT vp_org, win_org;
2023 INT mapMode = MM_TEXT;
2024 COLORREF old_text_color = 0, old_bk_color = 0;
2026 if(!lpRect)
2028 SetLastError(ERROR_INVALID_PARAMETER);
2029 return FALSE;
2032 emh = EMF_GetEnhMetaHeader(hmf);
2033 if(!emh) {
2034 SetLastError(ERROR_INVALID_HANDLE);
2035 return FALSE;
2038 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2039 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
2040 if(!info)
2042 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2043 return FALSE;
2045 info->wndOrgX = 0;
2046 info->wndOrgY = 0;
2047 info->wndExtX = 1;
2048 info->wndExtY = 1;
2049 info->vportOrgX = 0;
2050 info->vportOrgY = 0;
2051 info->vportExtX = 1;
2052 info->vportExtY = 1;
2053 info->world_transform.eM11 = info->world_transform.eM22 = 1;
2054 info->world_transform.eM12 = info->world_transform.eM21 = 0;
2055 info->world_transform.eDx = info->world_transform.eDy = 0;
2057 ht = (HANDLETABLE*) &info[1];
2058 ht->objectHandle[0] = hmf;
2060 if(hdc)
2062 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
2063 GetWorldTransform(hdc, &savedXform);
2064 GetViewportExtEx(hdc, &vp_size);
2065 GetWindowExtEx(hdc, &win_size);
2066 GetViewportOrgEx(hdc, &vp_org);
2067 GetWindowOrgEx(hdc, &win_org);
2068 mapMode = GetMapMode(hdc);
2070 /* save the current pen, brush and font */
2071 hPen = GetCurrentObject(hdc, OBJ_PEN);
2072 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
2073 hFont = GetCurrentObject(hdc, OBJ_FONT);
2075 old_text_color = SetTextColor(hdc, RGB(0,0,0));
2076 old_bk_color = SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
2079 info->mode = MM_TEXT;
2081 if ( IS_WIN9X() )
2083 /* Win95 leaves the vp/win ext/org info alone */
2084 info->init_transform.eM11 = 1.0;
2085 info->init_transform.eM12 = 0.0;
2086 info->init_transform.eM21 = 0.0;
2087 info->init_transform.eM22 = 1.0;
2088 info->init_transform.eDx = 0.0;
2089 info->init_transform.eDy = 0.0;
2091 else
2093 /* WinNT combines the vp/win ext/org info into a transform */
2094 FLOAT xscale, yscale;
2095 xscale = (FLOAT)vp_size.cx / (FLOAT)win_size.cx;
2096 yscale = (FLOAT)vp_size.cy / (FLOAT)win_size.cy;
2097 info->init_transform.eM11 = xscale;
2098 info->init_transform.eM12 = 0.0;
2099 info->init_transform.eM21 = 0.0;
2100 info->init_transform.eM22 = yscale;
2101 info->init_transform.eDx = (FLOAT)vp_org.x - xscale * (FLOAT)win_org.x;
2102 info->init_transform.eDy = (FLOAT)vp_org.y - yscale * (FLOAT)win_org.y;
2104 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
2107 if ( WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
2109 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
2110 XFORM xform;
2112 TRACE("rect: %ld,%ld - %ld,%ld. rclFrame: %ld,%ld - %ld,%ld\n",
2113 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
2114 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
2115 emh->rclFrame.bottom);
2117 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
2118 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
2119 xscale = (FLOAT) WIDTH(*lpRect) * 100.0 /
2120 WIDTH(emh->rclFrame) * xSrcPixSize;
2121 yscale = (FLOAT) HEIGHT(*lpRect) * 100.0 /
2122 HEIGHT(emh->rclFrame) * ySrcPixSize;
2124 xform.eM11 = xscale;
2125 xform.eM12 = 0;
2126 xform.eM21 = 0;
2127 xform.eM22 = yscale;
2128 xform.eDx = (FLOAT) lpRect->left - (FLOAT) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
2129 xform.eDy = (FLOAT) lpRect->top - (FLOAT) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
2131 CombineTransform(&info->init_transform, &xform, &info->init_transform);
2134 /* WinNT resets the current vp/win org/ext */
2135 if ( !IS_WIN9X() )
2137 SetMapMode(hdc, MM_TEXT);
2138 SetWindowOrgEx(hdc, 0, 0, NULL);
2139 SetViewportOrgEx(hdc, 0, 0, NULL);
2140 EMF_Update_MF_Xform(hdc, info);
2143 ret = TRUE;
2144 offset = 0;
2145 while(ret && offset < emh->nBytes)
2147 emr = (ENHMETARECORD *)((char *)emh + offset);
2148 TRACE("Calling EnumFunc with record %s, size %ld\n", get_emr_name(emr->iType), emr->nSize);
2149 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2150 offset += emr->nSize;
2153 if (hdc)
2155 SetBkColor(hdc, old_bk_color);
2156 SetTextColor(hdc, old_text_color);
2158 /* restore pen, brush and font */
2159 SelectObject(hdc, hBrush);
2160 SelectObject(hdc, hPen);
2161 SelectObject(hdc, hFont);
2163 SetWorldTransform(hdc, &savedXform);
2164 if (savedMode)
2165 SetGraphicsMode(hdc, savedMode);
2166 SetMapMode(hdc, mapMode);
2167 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2168 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2169 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2170 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2173 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2174 if( (ht->objectHandle)[i] )
2175 DeleteObject( (ht->objectHandle)[i] );
2177 HeapFree( GetProcessHeap(), 0, info );
2178 return ret;
2181 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2182 const ENHMETARECORD *emr,
2183 INT handles, LPARAM data)
2185 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2188 /**************************************************************************
2189 * PlayEnhMetaFile (GDI32.@)
2191 * Renders an enhanced metafile into a specified rectangle *lpRect
2192 * in device context hdc.
2195 BOOL WINAPI PlayEnhMetaFile(
2196 HDC hdc, /* [in] DC to render into */
2197 HENHMETAFILE hmf, /* [in] metafile to render */
2198 const RECT *lpRect /* [in] rectangle to place metafile inside */
2201 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2202 lpRect);
2205 /*****************************************************************************
2206 * DeleteEnhMetaFile (GDI32.@)
2208 * Deletes an enhanced metafile and frees the associated storage.
2210 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2212 return EMF_Delete_HENHMETAFILE( hmf );
2215 /*****************************************************************************
2216 * CopyEnhMetaFileA (GDI32.@)
2218 * Duplicate an enhanced metafile.
2222 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2223 HENHMETAFILE hmfSrc,
2224 LPCSTR file)
2226 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2227 HENHMETAFILE hmfDst;
2229 if(!emrSrc) return FALSE;
2230 if (!file) {
2231 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2232 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2233 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2234 } else {
2235 HANDLE hFile;
2236 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2237 NULL, CREATE_ALWAYS, 0, 0);
2238 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
2239 CloseHandle( hFile );
2240 /* Reopen file for reading only, so that apps can share
2241 read access to the file while hmf is still valid */
2242 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2243 NULL, OPEN_EXISTING, 0, 0);
2244 if(hFile == INVALID_HANDLE_VALUE) {
2245 ERR("Can't reopen emf for reading\n");
2246 return 0;
2248 hmfDst = EMF_GetEnhMetaFile( hFile );
2249 CloseHandle( hFile );
2251 return hmfDst;
2254 /*****************************************************************************
2255 * CopyEnhMetaFileW (GDI32.@)
2257 * See CopyEnhMetaFileA.
2261 HENHMETAFILE WINAPI CopyEnhMetaFileW(
2262 HENHMETAFILE hmfSrc,
2263 LPCWSTR file)
2265 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2266 HENHMETAFILE hmfDst;
2268 if(!emrSrc) return FALSE;
2269 if (!file) {
2270 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2271 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2272 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2273 } else {
2274 HANDLE hFile;
2275 hFile = CreateFileW( file, GENERIC_WRITE | GENERIC_READ, 0,
2276 NULL, CREATE_ALWAYS, 0, 0);
2277 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
2278 CloseHandle( hFile );
2279 /* Reopen file for reading only, so that apps can share
2280 read access to the file while hmf is still valid */
2281 hFile = CreateFileW( file, GENERIC_READ, FILE_SHARE_READ,
2282 NULL, OPEN_EXISTING, 0, 0);
2283 if(hFile == INVALID_HANDLE_VALUE) {
2284 ERR("Can't reopen emf for reading\n");
2285 return 0;
2287 hmfDst = EMF_GetEnhMetaFile( hFile );
2288 CloseHandle( hFile );
2290 return hmfDst;
2294 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2295 typedef struct tagEMF_PaletteCopy
2297 UINT cEntries;
2298 LPPALETTEENTRY lpPe;
2299 } EMF_PaletteCopy;
2301 /***************************************************************
2302 * Find the EMR_EOF record and then use it to find the
2303 * palette entries for this enhanced metafile.
2304 * The lpData is actually a pointer to a EMF_PaletteCopy struct
2305 * which contains the max number of elements to copy and where
2306 * to copy them to.
2308 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2310 INT CALLBACK cbEnhPaletteCopy( HDC a,
2311 HANDLETABLE *b,
2312 const ENHMETARECORD *lpEMR,
2313 INT c,
2314 LPARAM lpData )
2317 if ( lpEMR->iType == EMR_EOF )
2319 PEMREOF lpEof = (PEMREOF)lpEMR;
2320 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2321 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2323 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
2325 memcpy( (LPVOID)info->lpPe,
2326 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
2327 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2329 /* Update the passed data as a return code */
2330 info->lpPe = NULL; /* Palettes were copied! */
2331 info->cEntries = (UINT)dwNumPalToCopy;
2333 return FALSE; /* That's all we need */
2336 return TRUE;
2339 /*****************************************************************************
2340 * GetEnhMetaFilePaletteEntries (GDI32.@)
2342 * Copy the palette and report size
2344 * BUGS: Error codes (SetLastError) are not set on failures
2346 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2347 UINT cEntries,
2348 LPPALETTEENTRY lpPe )
2350 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2351 EMF_PaletteCopy infoForCallBack;
2353 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2355 /* First check if there are any palettes associated with
2356 this metafile. */
2357 if ( enhHeader->nPalEntries == 0 ) return 0;
2359 /* Is the user requesting the number of palettes? */
2360 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
2362 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2363 infoForCallBack.cEntries = cEntries;
2364 infoForCallBack.lpPe = lpPe;
2366 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2367 &infoForCallBack, 0 ) )
2368 return GDI_ERROR;
2370 /* Verify that the callback executed correctly */
2371 if ( infoForCallBack.lpPe != NULL )
2373 /* Callback proc had error! */
2374 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2375 return GDI_ERROR;
2378 return infoForCallBack.cEntries;
2381 typedef struct gdi_mf_comment
2383 DWORD ident;
2384 DWORD iComment;
2385 DWORD nVersion;
2386 DWORD nChecksum;
2387 DWORD fFlags;
2388 DWORD cbWinMetaFile;
2389 } gdi_mf_comment;
2391 /******************************************************************
2392 * SetWinMetaFileBits (GDI32.@)
2394 * Translate from old style to new style.
2397 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2398 CONST BYTE *lpbBuffer,
2399 HDC hdcRef,
2400 CONST METAFILEPICT *lpmfp
2403 HMETAFILE hmf = 0;
2404 HENHMETAFILE ret = 0;
2405 HDC hdc = 0, hdcdisp = 0;
2406 METAFILEPICT mfp;
2407 RECT rc, *prcFrame = NULL;
2408 gdi_mf_comment *mfcomment;
2409 UINT mfcomment_size;
2410 INT horzres, vertres, horzsize, vertsize, xext, yext;
2412 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2414 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2415 if(!hmf)
2417 WARN("SetMetaFileBitsEx failed\n");
2418 return 0;
2421 if(!hdcRef)
2422 hdcRef = hdcdisp = CreateDCA("DISPLAY", NULL, NULL, NULL);
2424 if(!lpmfp) {
2425 lpmfp = &mfp;
2426 mfp.mm = MM_ANISOTROPIC;
2427 mfp.xExt = 100;
2428 mfp.yExt = 100;
2429 FIXME("Correct Exts from dc\n");
2431 else
2433 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2434 if ( ( mfp.xExt < 0 ) || ( mfp.yExt < 0) )
2435 FIXME("Negative coordinates!\n");
2438 if(lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC) {
2439 rc.left = rc.top = 0;
2440 rc.right = lpmfp->xExt;
2441 rc.bottom = lpmfp->yExt;
2442 prcFrame = &rc;
2445 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL))) {
2446 ERR("CreateEnhMetaFile fails?\n");
2447 goto end;
2450 horzres = GetDeviceCaps(hdcRef, HORZRES);
2451 vertres = GetDeviceCaps(hdcRef, VERTRES);
2452 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2453 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2455 if(hdcdisp) {
2456 DeleteDC(hdcdisp);
2457 hdcRef = 0;
2461 * Write the original METAFILE into the enhanced metafile.
2462 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2464 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2465 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2466 if(mfcomment)
2468 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2469 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2470 mfcomment->nVersion = 0x00000300;
2471 mfcomment->nChecksum = 0; /* FIXME */
2472 mfcomment->fFlags = 0;
2473 mfcomment->cbWinMetaFile = cbBuffer;
2474 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2475 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2476 HeapFree(GetProcessHeap(), 0, mfcomment);
2479 if(lpmfp->mm != MM_TEXT)
2480 SetMapMode(hdc, lpmfp->mm);
2482 /* set the initial viewport:window ratio as 1:1 */
2483 xext = lpmfp->xExt*horzres/(100*horzsize);
2484 yext = lpmfp->yExt*vertres/(100*vertsize);
2485 SetViewportExtEx(hdc, xext, yext, NULL);
2486 SetWindowExtEx(hdc, xext, yext, NULL);
2488 PlayMetaFile(hdc, hmf);
2490 ret = CloseEnhMetaFile(hdc);
2491 end:
2492 DeleteMetaFile(hmf);
2493 return ret;