Added support for inter-process GetWindowWord.
[wine.git] / objects / enhmetafile.c
blob324672fccf879ce28a3316c70865d89e28dd1ce3
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 "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
50 typedef struct
52 GDIOBJHDR header;
53 ENHMETAHEADER *emh;
54 BOOL on_disk; /* true if metafile is on disk */
55 } ENHMETAFILEOBJ;
57 static const struct emr_name {
58 DWORD type;
59 const char *name;
60 } emr_names[] = {
61 #define X(p) {p, #p}
62 X(EMR_HEADER),
63 X(EMR_POLYBEZIER),
64 X(EMR_POLYGON),
65 X(EMR_POLYLINE),
66 X(EMR_POLYBEZIERTO),
67 X(EMR_POLYLINETO),
68 X(EMR_POLYPOLYLINE),
69 X(EMR_POLYPOLYGON),
70 X(EMR_SETWINDOWEXTEX),
71 X(EMR_SETWINDOWORGEX),
72 X(EMR_SETVIEWPORTEXTEX),
73 X(EMR_SETVIEWPORTORGEX),
74 X(EMR_SETBRUSHORGEX),
75 X(EMR_EOF),
76 X(EMR_SETPIXELV),
77 X(EMR_SETMAPPERFLAGS),
78 X(EMR_SETMAPMODE),
79 X(EMR_SETBKMODE),
80 X(EMR_SETPOLYFILLMODE),
81 X(EMR_SETROP2),
82 X(EMR_SETSTRETCHBLTMODE),
83 X(EMR_SETTEXTALIGN),
84 X(EMR_SETCOLORADJUSTMENT),
85 X(EMR_SETTEXTCOLOR),
86 X(EMR_SETBKCOLOR),
87 X(EMR_OFFSETCLIPRGN),
88 X(EMR_MOVETOEX),
89 X(EMR_SETMETARGN),
90 X(EMR_EXCLUDECLIPRECT),
91 X(EMR_INTERSECTCLIPRECT),
92 X(EMR_SCALEVIEWPORTEXTEX),
93 X(EMR_SCALEWINDOWEXTEX),
94 X(EMR_SAVEDC),
95 X(EMR_RESTOREDC),
96 X(EMR_SETWORLDTRANSFORM),
97 X(EMR_MODIFYWORLDTRANSFORM),
98 X(EMR_SELECTOBJECT),
99 X(EMR_CREATEPEN),
100 X(EMR_CREATEBRUSHINDIRECT),
101 X(EMR_DELETEOBJECT),
102 X(EMR_ANGLEARC),
103 X(EMR_ELLIPSE),
104 X(EMR_RECTANGLE),
105 X(EMR_ROUNDRECT),
106 X(EMR_ARC),
107 X(EMR_CHORD),
108 X(EMR_PIE),
109 X(EMR_SELECTPALETTE),
110 X(EMR_CREATEPALETTE),
111 X(EMR_SETPALETTEENTRIES),
112 X(EMR_RESIZEPALETTE),
113 X(EMR_REALIZEPALETTE),
114 X(EMR_EXTFLOODFILL),
115 X(EMR_LINETO),
116 X(EMR_ARCTO),
117 X(EMR_POLYDRAW),
118 X(EMR_SETARCDIRECTION),
119 X(EMR_SETMITERLIMIT),
120 X(EMR_BEGINPATH),
121 X(EMR_ENDPATH),
122 X(EMR_CLOSEFIGURE),
123 X(EMR_FILLPATH),
124 X(EMR_STROKEANDFILLPATH),
125 X(EMR_STROKEPATH),
126 X(EMR_FLATTENPATH),
127 X(EMR_WIDENPATH),
128 X(EMR_SELECTCLIPPATH),
129 X(EMR_ABORTPATH),
130 X(EMR_GDICOMMENT),
131 X(EMR_FILLRGN),
132 X(EMR_FRAMERGN),
133 X(EMR_INVERTRGN),
134 X(EMR_PAINTRGN),
135 X(EMR_EXTSELECTCLIPRGN),
136 X(EMR_BITBLT),
137 X(EMR_STRETCHBLT),
138 X(EMR_MASKBLT),
139 X(EMR_PLGBLT),
140 X(EMR_SETDIBITSTODEVICE),
141 X(EMR_STRETCHDIBITS),
142 X(EMR_EXTCREATEFONTINDIRECTW),
143 X(EMR_EXTTEXTOUTA),
144 X(EMR_EXTTEXTOUTW),
145 X(EMR_POLYBEZIER16),
146 X(EMR_POLYGON16),
147 X(EMR_POLYLINE16),
148 X(EMR_POLYBEZIERTO16),
149 X(EMR_POLYLINETO16),
150 X(EMR_POLYPOLYLINE16),
151 X(EMR_POLYPOLYGON16),
152 X(EMR_POLYDRAW16),
153 X(EMR_CREATEMONOBRUSH),
154 X(EMR_CREATEDIBPATTERNBRUSHPT),
155 X(EMR_EXTCREATEPEN),
156 X(EMR_POLYTEXTOUTA),
157 X(EMR_POLYTEXTOUTW),
158 X(EMR_SETICMMODE),
159 X(EMR_CREATECOLORSPACE),
160 X(EMR_SETCOLORSPACE),
161 X(EMR_DELETECOLORSPACE),
162 X(EMR_GLSRECORD),
163 X(EMR_GLSBOUNDEDRECORD),
164 X(EMR_PIXELFORMAT),
165 X(EMR_DRAWESCAPE),
166 X(EMR_EXTESCAPE),
167 X(EMR_STARTDOC),
168 X(EMR_SMALLTEXTOUT),
169 X(EMR_FORCEUFIMAPPING),
170 X(EMR_NAMEDESCAPE),
171 X(EMR_COLORCORRECTPALETTE),
172 X(EMR_SETICMPROFILEA),
173 X(EMR_SETICMPROFILEW),
174 X(EMR_ALPHABLEND),
175 X(EMR_SETLAYOUT),
176 X(EMR_TRANSPARENTBLT),
177 X(EMR_RESERVED_117),
178 X(EMR_GRADIENTFILL),
179 X(EMR_SETLINKEDUFI),
180 X(EMR_SETTEXTJUSTIFICATION),
181 X(EMR_COLORMATCHTOTARGETW),
182 X(EMR_CREATECOLORSPACEW)
183 #undef X
186 /****************************************************************************
187 * get_emr_name
189 static const char *get_emr_name(DWORD type)
191 int i;
192 for(i = 0; i < sizeof(emr_names) / sizeof(emr_names[0]); i++)
193 if(type == emr_names[i].type) return emr_names[i].name;
194 TRACE("Unknown record type %ld\n", type);
195 return NULL;
198 /****************************************************************************
199 * EMF_Create_HENHMETAFILE
201 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk )
203 HENHMETAFILE hmf = 0;
204 ENHMETAFILEOBJ *metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
205 ENHMETAFILE_MAGIC,
206 (HGDIOBJ *)&hmf, NULL );
207 if (metaObj)
209 metaObj->emh = emh;
210 metaObj->on_disk = on_disk;
211 GDI_ReleaseObj( hmf );
213 return hmf;
216 /****************************************************************************
217 * EMF_Delete_HENHMETAFILE
219 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
221 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
222 ENHMETAFILE_MAGIC );
223 if(!metaObj) return FALSE;
225 if(metaObj->on_disk)
226 UnmapViewOfFile( metaObj->emh );
227 else
228 HeapFree( GetProcessHeap(), 0, metaObj->emh );
229 return GDI_FreeObject( hmf, metaObj );
232 /******************************************************************
233 * EMF_GetEnhMetaHeader
235 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
237 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
239 ENHMETAHEADER *ret = NULL;
240 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
241 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
242 if (metaObj)
244 ret = metaObj->emh;
245 GDI_ReleaseObj( hmf );
247 return ret;
250 /*****************************************************************************
251 * EMF_GetEnhMetaFile
254 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
256 ENHMETAHEADER *emh;
257 HANDLE hMapping;
259 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
260 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
261 CloseHandle( hMapping );
263 if (!emh) return 0;
265 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
266 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
267 emh->iType, emh->dSignature);
268 goto err;
271 /* refuse to load unaligned EMF as Windows does */
272 if (emh->nBytes & 3)
274 WARN("Refusing to load unaligned EMF\n");
275 goto err;
278 return EMF_Create_HENHMETAFILE( emh, TRUE );
280 err:
281 UnmapViewOfFile( emh );
282 return 0;
286 /*****************************************************************************
287 * GetEnhMetaFileA (GDI32.@)
291 HENHMETAFILE WINAPI GetEnhMetaFileA(
292 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
295 HENHMETAFILE hmf;
296 HANDLE hFile;
298 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
299 OPEN_EXISTING, 0, 0);
300 if (hFile == INVALID_HANDLE_VALUE) {
301 WARN("could not open %s\n", lpszMetaFile);
302 return 0;
304 hmf = EMF_GetEnhMetaFile( hFile );
305 CloseHandle( hFile );
306 return hmf;
309 /*****************************************************************************
310 * GetEnhMetaFileW (GDI32.@)
312 HENHMETAFILE WINAPI GetEnhMetaFileW(
313 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
315 HENHMETAFILE hmf;
316 HANDLE hFile;
318 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
319 OPEN_EXISTING, 0, 0);
320 if (hFile == INVALID_HANDLE_VALUE) {
321 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
322 return 0;
324 hmf = EMF_GetEnhMetaFile( hFile );
325 CloseHandle( hFile );
326 return hmf;
329 /*****************************************************************************
330 * GetEnhMetaFileHeader (GDI32.@)
332 * If buf is NULL, returns the size of buffer required.
333 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
334 * buf.
336 UINT WINAPI GetEnhMetaFileHeader(
337 HENHMETAFILE hmf, /* [in] enhanced metafile */
338 UINT bufsize, /* [in] size of buffer */
339 LPENHMETAHEADER buf /* [out] buffer */
342 LPENHMETAHEADER emh;
343 UINT size;
345 emh = EMF_GetEnhMetaHeader(hmf);
346 if(!emh) return FALSE;
347 size = emh->nSize;
348 if (!buf) return size;
349 size = min(size, bufsize);
350 memmove(buf, emh, size);
351 return size;
355 /*****************************************************************************
356 * GetEnhMetaFileDescriptionA (GDI32.@)
358 UINT WINAPI GetEnhMetaFileDescriptionA(
359 HENHMETAFILE hmf, /* [in] enhanced metafile */
360 UINT size, /* [in] size of buf */
361 LPSTR buf /* [out] buffer to receive description */
364 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
365 DWORD len;
366 WCHAR *descrW;
368 if(!emh) return FALSE;
369 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
370 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
371 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
373 if (!buf || !size ) return len;
375 len = min( size, len );
376 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
377 return len;
380 /*****************************************************************************
381 * GetEnhMetaFileDescriptionW (GDI32.@)
383 * Copies the description string of an enhanced metafile into a buffer
384 * _buf_.
386 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
387 * number of characters copied.
389 UINT WINAPI GetEnhMetaFileDescriptionW(
390 HENHMETAFILE hmf, /* [in] enhanced metafile */
391 UINT size, /* [in] size of buf */
392 LPWSTR buf /* [out] buffer to receive description */
395 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
397 if(!emh) return FALSE;
398 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
399 if (!buf || !size ) return emh->nDescription;
401 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
402 return min(size, emh->nDescription);
405 /****************************************************************************
406 * SetEnhMetaFileBits (GDI32.@)
408 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
410 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
412 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
413 memmove(emh, buf, bufsize);
414 return EMF_Create_HENHMETAFILE( emh, FALSE );
417 /*****************************************************************************
418 * GetEnhMetaFileBits (GDI32.@)
421 UINT WINAPI GetEnhMetaFileBits(
422 HENHMETAFILE hmf,
423 UINT bufsize,
424 LPBYTE buf
427 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
428 UINT size;
430 if(!emh) return 0;
432 size = emh->nBytes;
433 if( buf == NULL ) return size;
435 size = min( size, bufsize );
436 memmove(buf, emh, size);
437 return size;
440 typedef struct enum_emh_data
442 INT mode;
443 XFORM init_transform;
444 XFORM world_transform;
445 INT wndOrgX;
446 INT wndOrgY;
447 INT wndExtX;
448 INT wndExtY;
449 INT vportOrgX;
450 INT vportOrgY;
451 INT vportExtX;
452 INT vportExtY;
453 } enum_emh_data;
455 #define ENUM_GET_PRIVATE_DATA(ht) \
456 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
458 #define WIDTH(rect) ( (rect).right - (rect).left )
459 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
461 #define IS_WIN9X() (GetVersion()&0x80000000)
463 void EMF_Update_MF_Xform(HDC hdc, enum_emh_data *info)
465 XFORM mapping_mode_trans, final_trans;
466 FLOAT scaleX, scaleY;
468 scaleX = (FLOAT)info->vportExtX / (FLOAT)info->wndExtX;
469 scaleY = (FLOAT)info->vportExtY / (FLOAT)info->wndExtY;
470 mapping_mode_trans.eM11 = scaleX;
471 mapping_mode_trans.eM12 = 0.0;
472 mapping_mode_trans.eM21 = 0.0;
473 mapping_mode_trans.eM22 = scaleY;
474 mapping_mode_trans.eDx = (FLOAT)info->vportOrgX - scaleX * (FLOAT)info->wndOrgX;
475 mapping_mode_trans.eDy = (FLOAT)info->vportOrgY - scaleY * (FLOAT)info->wndOrgY;
477 CombineTransform(&final_trans, &info->world_transform, &mapping_mode_trans);
478 CombineTransform(&final_trans, &final_trans, &info->init_transform);
480 if (!SetWorldTransform(hdc, &final_trans))
482 ERR("World transform failed!\n");
486 void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
488 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
489 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
490 INT horzRes = GetDeviceCaps( hdc, HORZRES );
491 INT vertRes = GetDeviceCaps( hdc, VERTRES );
493 TRACE("%d\n",info->mode);
495 switch(info->mode)
497 case MM_TEXT:
498 info->wndExtX = 1;
499 info->wndExtY = 1;
500 info->vportExtX = 1;
501 info->vportExtY = 1;
502 break;
503 case MM_LOMETRIC:
504 case MM_ISOTROPIC:
505 info->wndExtX = horzSize * 10;
506 info->wndExtY = vertSize * 10;
507 info->vportExtX = horzRes;
508 info->vportExtY = -vertRes;
509 break;
510 case MM_HIMETRIC:
511 info->wndExtX = horzSize * 100;
512 info->wndExtY = vertSize * 100;
513 info->vportExtX = horzRes;
514 info->vportExtY = -vertRes;
515 break;
516 case MM_LOENGLISH:
517 info->wndExtX = MulDiv(1000, horzSize, 254);
518 info->wndExtY = MulDiv(1000, vertSize, 254);
519 info->vportExtX = horzRes;
520 info->vportExtY = -vertRes;
521 break;
522 case MM_HIENGLISH:
523 info->wndExtX = MulDiv(10000, horzSize, 254);
524 info->wndExtY = MulDiv(10000, vertSize, 254);
525 info->vportExtX = horzRes;
526 info->vportExtY = -vertRes;
527 break;
528 case MM_TWIPS:
529 info->wndExtX = MulDiv(14400, horzSize, 254);
530 info->wndExtY = MulDiv(14400, vertSize, 254);
531 info->vportExtX = horzRes;
532 info->vportExtY = -vertRes;
533 break;
534 case MM_ANISOTROPIC:
535 break;
536 default:
537 return;
541 /*****************************************************************************
542 * emr_produces_output
544 * Returns TRUE if the record type writes something to the dc. Used by
545 * PlayEnhMetaFileRecord to determine whether it needs to update the
546 * dc's xform when in win9x mode.
548 * FIXME: need to test which records should be here.
550 static BOOL emr_produces_output(int type)
552 switch(type) {
553 case EMR_POLYBEZIER:
554 case EMR_POLYGON:
555 case EMR_POLYLINE:
556 case EMR_POLYBEZIERTO:
557 case EMR_POLYLINETO:
558 case EMR_POLYPOLYLINE:
559 case EMR_POLYPOLYGON:
560 case EMR_SETPIXELV:
561 case EMR_MOVETOEX:
562 case EMR_EXCLUDECLIPRECT:
563 case EMR_INTERSECTCLIPRECT:
564 case EMR_SELECTOBJECT:
565 case EMR_ANGLEARC:
566 case EMR_ELLIPSE:
567 case EMR_RECTANGLE:
568 case EMR_ROUNDRECT:
569 case EMR_ARC:
570 case EMR_CHORD:
571 case EMR_PIE:
572 case EMR_EXTFLOODFILL:
573 case EMR_LINETO:
574 case EMR_ARCTO:
575 case EMR_POLYDRAW:
576 case EMR_FILLRGN:
577 case EMR_FRAMERGN:
578 case EMR_INVERTRGN:
579 case EMR_PAINTRGN:
580 case EMR_BITBLT:
581 case EMR_STRETCHBLT:
582 case EMR_MASKBLT:
583 case EMR_PLGBLT:
584 case EMR_SETDIBITSTODEVICE:
585 case EMR_STRETCHDIBITS:
586 case EMR_EXTTEXTOUTA:
587 case EMR_EXTTEXTOUTW:
588 case EMR_POLYBEZIER16:
589 case EMR_POLYGON16:
590 case EMR_POLYLINE16:
591 case EMR_POLYBEZIERTO16:
592 case EMR_POLYLINETO16:
593 case EMR_POLYPOLYLINE16:
594 case EMR_POLYPOLYGON16:
595 case EMR_POLYDRAW16:
596 case EMR_POLYTEXTOUTA:
597 case EMR_POLYTEXTOUTW:
598 case EMR_SMALLTEXTOUT:
599 case EMR_TRANSPARENTBLT:
600 return TRUE;
601 default:
602 return FALSE;
607 /*****************************************************************************
608 * PlayEnhMetaFileRecord (GDI32.@)
610 * Render a single enhanced metafile record in the device context hdc.
612 * RETURNS
613 * TRUE (non zero) on success, FALSE on error.
614 * BUGS
615 * Many unimplemented records.
616 * No error handling on record play failures (ie checking return codes)
618 * NOTES
619 * WinNT actually updates the current world transform in this function
620 * whereas Win9x does not.
622 BOOL WINAPI PlayEnhMetaFileRecord(
623 HDC hdc, /* [in] device context in which to render EMF record */
624 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
625 const ENHMETARECORD *mr, /* [in] EMF record to render */
626 UINT handles /* [in] size of handle array */
629 int type;
630 RECT tmprc;
631 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
633 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
634 hdc, handletable, mr, handles);
635 if (!mr) return FALSE;
637 type = mr->iType;
639 /* In Win9x mode we update the xform if the record will produce output */
640 if ( IS_WIN9X() && emr_produces_output(type) )
641 EMF_Update_MF_Xform(hdc, info);
643 TRACE("record %s\n", get_emr_name(type));
644 switch(type)
646 case EMR_HEADER:
647 break;
648 case EMR_EOF:
649 break;
650 case EMR_GDICOMMENT:
652 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
653 /* In an enhanced metafile, there can be both public and private GDI comments */
654 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
655 break;
657 case EMR_SETMAPMODE:
659 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
661 if(info->mode == pSetMapMode->iMode && (info->mode == MM_ISOTROPIC || info->mode == MM_ANISOTROPIC))
662 break;
663 info->mode = pSetMapMode->iMode;
664 EMF_SetMapMode(hdc, info);
665 break;
667 case EMR_SETBKMODE:
669 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
670 SetBkMode(hdc, pSetBkMode->iMode);
671 break;
673 case EMR_SETBKCOLOR:
675 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
676 SetBkColor(hdc, pSetBkColor->crColor);
677 break;
679 case EMR_SETPOLYFILLMODE:
681 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
682 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
683 break;
685 case EMR_SETROP2:
687 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
688 SetROP2(hdc, pSetROP2->iMode);
689 break;
691 case EMR_SETSTRETCHBLTMODE:
693 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
694 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
695 break;
697 case EMR_SETTEXTALIGN:
699 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
700 SetTextAlign(hdc, pSetTextAlign->iMode);
701 break;
703 case EMR_SETTEXTCOLOR:
705 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
706 SetTextColor(hdc, pSetTextColor->crColor);
707 break;
709 case EMR_SAVEDC:
711 SaveDC(hdc);
712 break;
714 case EMR_RESTOREDC:
716 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
717 TRACE("EMR_RESTORE: %ld\n", pRestoreDC->iRelative);
718 RestoreDC(hdc, pRestoreDC->iRelative);
719 break;
721 case EMR_INTERSECTCLIPRECT:
723 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
724 TRACE("EMR_INTERSECTCLIPRECT: rect %ld,%ld - %ld, %ld\n",
725 pClipRect->rclClip.left, pClipRect->rclClip.top,
726 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
727 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
728 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
729 break;
731 case EMR_SELECTOBJECT:
733 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
734 if( pSelectObject->ihObject & 0x80000000 ) {
735 /* High order bit is set - it's a stock object
736 * Strip the high bit to get the index.
737 * See MSDN article Q142319
739 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
740 0x7fffffff ) );
741 } else {
742 /* High order bit wasn't set - not a stock object
744 SelectObject( hdc,
745 (handletable->objectHandle)[pSelectObject->ihObject] );
747 break;
749 case EMR_DELETEOBJECT:
751 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
752 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
753 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
754 break;
756 case EMR_SETWINDOWORGEX:
758 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
760 info->wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
761 info->wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
763 TRACE("SetWindowOrgEx: %d,%d\n",info->wndOrgX,info->wndOrgY);
764 break;
766 case EMR_SETWINDOWEXTEX:
768 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
770 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
771 break;
772 info->wndExtX = pSetWindowExtEx->szlExtent.cx;
773 info->wndExtY = pSetWindowExtEx->szlExtent.cy;
775 TRACE("SetWindowExtEx: %d,%d\n",info->wndExtX,info->wndExtY);
776 break;
778 case EMR_SETVIEWPORTORGEX:
780 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
781 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
783 info->vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
784 info->vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
785 TRACE("SetViewportOrgEx: %d,%d\n",info->vportOrgX,info->vportOrgY);
786 break;
788 case EMR_SETVIEWPORTEXTEX:
790 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
791 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
793 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
794 break;
795 info->vportExtX = pSetViewportExtEx->szlExtent.cx;
796 info->vportExtY = pSetViewportExtEx->szlExtent.cy;
797 TRACE("SetViewportExtEx: %d,%d\n",info->vportExtX,info->vportExtY);
798 break;
800 case EMR_CREATEPEN:
802 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
803 (handletable->objectHandle)[pCreatePen->ihPen] =
804 CreatePenIndirect(&pCreatePen->lopn);
805 break;
807 case EMR_EXTCREATEPEN:
809 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
810 LOGBRUSH lb;
811 lb.lbStyle = pPen->elp.elpBrushStyle;
812 lb.lbColor = pPen->elp.elpColor;
813 lb.lbHatch = pPen->elp.elpHatch;
815 if(pPen->offBmi || pPen->offBits)
816 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
818 (handletable->objectHandle)[pPen->ihPen] =
819 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
820 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
821 break;
823 case EMR_CREATEBRUSHINDIRECT:
825 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
826 (handletable->objectHandle)[pBrush->ihBrush] =
827 CreateBrushIndirect(&pBrush->lb);
828 break;
830 case EMR_EXTCREATEFONTINDIRECTW:
832 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
833 (handletable->objectHandle)[pFont->ihFont] =
834 CreateFontIndirectW(&pFont->elfw.elfLogFont);
835 break;
837 case EMR_MOVETOEX:
839 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
840 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
841 break;
843 case EMR_LINETO:
845 PEMRLINETO pLineTo = (PEMRLINETO) mr;
846 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
847 break;
849 case EMR_RECTANGLE:
851 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
852 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
853 pRect->rclBox.right, pRect->rclBox.bottom);
854 break;
856 case EMR_ELLIPSE:
858 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
859 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
860 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
861 break;
863 case EMR_POLYGON16:
865 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
866 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
867 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
868 pPoly->cpts * sizeof(POINT) );
869 DWORD i;
870 for(i = 0; i < pPoly->cpts; i++)
871 CONV_POINT16TO32(pPoly->apts + i, pts + i);
872 Polygon(hdc, pts, pPoly->cpts);
873 HeapFree( GetProcessHeap(), 0, pts );
874 break;
876 case EMR_POLYLINE16:
878 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
879 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
880 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
881 pPoly->cpts * sizeof(POINT) );
882 DWORD i;
883 for(i = 0; i < pPoly->cpts; i++)
884 CONV_POINT16TO32(pPoly->apts + i, pts + i);
885 Polyline(hdc, pts, pPoly->cpts);
886 HeapFree( GetProcessHeap(), 0, pts );
887 break;
889 case EMR_POLYLINETO16:
891 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
892 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
893 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
894 pPoly->cpts * sizeof(POINT) );
895 DWORD i;
896 for(i = 0; i < pPoly->cpts; i++)
897 CONV_POINT16TO32(pPoly->apts + i, pts + i);
898 PolylineTo(hdc, pts, pPoly->cpts);
899 HeapFree( GetProcessHeap(), 0, pts );
900 break;
902 case EMR_POLYBEZIER16:
904 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
905 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
906 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
907 pPoly->cpts * sizeof(POINT) );
908 DWORD i;
909 for(i = 0; i < pPoly->cpts; i++)
910 CONV_POINT16TO32(pPoly->apts + i, pts + i);
911 PolyBezier(hdc, pts, pPoly->cpts);
912 HeapFree( GetProcessHeap(), 0, pts );
913 break;
915 case EMR_POLYBEZIERTO16:
917 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
918 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
919 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
920 pPoly->cpts * sizeof(POINT) );
921 DWORD i;
922 for(i = 0; i < pPoly->cpts; i++)
923 CONV_POINT16TO32(pPoly->apts + i, pts + i);
924 PolyBezierTo(hdc, pts, pPoly->cpts);
925 HeapFree( GetProcessHeap(), 0, pts );
926 break;
928 case EMR_POLYPOLYGON16:
930 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
931 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
932 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
934 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
935 pPolyPoly->cpts * sizeof(POINT) );
936 DWORD i;
937 for(i = 0; i < pPolyPoly->cpts; i++)
938 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
939 pPolyPoly->nPolys) + i, pts + i);
941 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
942 HeapFree( GetProcessHeap(), 0, pts );
943 break;
945 case EMR_POLYPOLYLINE16:
947 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
948 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
949 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
951 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
952 pPolyPoly->cpts * sizeof(POINT) );
953 DWORD i;
954 for(i = 0; i < pPolyPoly->cpts; i++)
955 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
956 pPolyPoly->nPolys) + i, pts + i);
958 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
959 HeapFree( GetProcessHeap(), 0, pts );
960 break;
963 case EMR_STRETCHDIBITS:
965 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
967 StretchDIBits(hdc,
968 pStretchDIBits->xDest,
969 pStretchDIBits->yDest,
970 pStretchDIBits->cxDest,
971 pStretchDIBits->cyDest,
972 pStretchDIBits->xSrc,
973 pStretchDIBits->ySrc,
974 pStretchDIBits->cxSrc,
975 pStretchDIBits->cySrc,
976 (BYTE *)mr + pStretchDIBits->offBitsSrc,
977 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
978 pStretchDIBits->iUsageSrc,
979 pStretchDIBits->dwRop);
980 break;
983 case EMR_EXTTEXTOUTA:
985 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
986 RECT rc;
988 rc.left = pExtTextOutA->emrtext.rcl.left;
989 rc.top = pExtTextOutA->emrtext.rcl.top;
990 rc.right = pExtTextOutA->emrtext.rcl.right;
991 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
992 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
993 pExtTextOutA->emrtext.fOptions, &rc,
994 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
995 (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx));
996 break;
999 case EMR_EXTTEXTOUTW:
1001 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
1002 RECT rc;
1004 rc.left = pExtTextOutW->emrtext.rcl.left;
1005 rc.top = pExtTextOutW->emrtext.rcl.top;
1006 rc.right = pExtTextOutW->emrtext.rcl.right;
1007 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
1008 TRACE("EMR_EXTTEXTOUTW: x,y = %ld, %ld. rect = %ld, %ld - %ld, %ld. flags %08lx\n",
1009 pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1010 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutW->emrtext.fOptions);
1012 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1013 pExtTextOutW->emrtext.fOptions, &rc,
1014 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
1015 (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx));
1016 break;
1019 case EMR_CREATEPALETTE:
1021 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
1023 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
1024 CreatePalette( &lpCreatePal->lgpl );
1026 break;
1029 case EMR_SELECTPALETTE:
1031 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
1033 if( lpSelectPal->ihPal & 0x80000000 ) {
1034 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
1035 } else {
1036 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
1037 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
1039 break;
1042 case EMR_REALIZEPALETTE:
1044 RealizePalette( hdc );
1045 break;
1048 case EMR_EXTSELECTCLIPRGN:
1050 #if 0
1051 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
1052 HRGN hRgn = ExtCreateRegion(NULL, lpRgn->cbRgnData, (RGNDATA *)lpRgn->RgnData);
1053 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
1054 /* ExtSelectClipRgn created a copy of the region */
1055 DeleteObject(hRgn);
1056 #endif
1057 FIXME("ExtSelectClipRgn\n");
1058 break;
1061 case EMR_SETMETARGN:
1063 SetMetaRgn( hdc );
1064 break;
1067 case EMR_SETWORLDTRANSFORM:
1069 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
1070 info->world_transform = lpXfrm->xform;
1071 break;
1074 case EMR_POLYBEZIER:
1076 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
1077 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
1078 break;
1081 case EMR_POLYGON:
1083 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
1084 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
1085 break;
1088 case EMR_POLYLINE:
1090 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
1091 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
1092 break;
1095 case EMR_POLYBEZIERTO:
1097 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
1098 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
1099 (UINT)lpPolyBezierTo->cptl );
1100 break;
1103 case EMR_POLYLINETO:
1105 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
1106 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
1107 (UINT)lpPolyLineTo->cptl );
1108 break;
1111 case EMR_POLYPOLYLINE:
1113 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
1114 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1116 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
1117 pPolyPolyline->nPolys),
1118 pPolyPolyline->aPolyCounts,
1119 pPolyPolyline->nPolys );
1121 break;
1124 case EMR_POLYPOLYGON:
1126 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
1128 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1130 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
1131 pPolyPolygon->nPolys),
1132 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
1133 break;
1136 case EMR_SETBRUSHORGEX:
1138 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
1140 SetBrushOrgEx( hdc,
1141 (INT)lpSetBrushOrgEx->ptlOrigin.x,
1142 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1143 NULL );
1145 break;
1148 case EMR_SETPIXELV:
1150 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
1152 SetPixelV( hdc,
1153 (INT)lpSetPixelV->ptlPixel.x,
1154 (INT)lpSetPixelV->ptlPixel.y,
1155 lpSetPixelV->crColor );
1157 break;
1160 case EMR_SETMAPPERFLAGS:
1162 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
1164 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1166 break;
1169 case EMR_SETCOLORADJUSTMENT:
1171 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
1173 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1175 break;
1178 case EMR_OFFSETCLIPRGN:
1180 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
1182 OffsetClipRgn( hdc,
1183 (INT)lpOffsetClipRgn->ptlOffset.x,
1184 (INT)lpOffsetClipRgn->ptlOffset.y );
1185 FIXME("OffsetClipRgn\n");
1187 break;
1190 case EMR_EXCLUDECLIPRECT:
1192 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
1194 ExcludeClipRect( hdc,
1195 lpExcludeClipRect->rclClip.left,
1196 lpExcludeClipRect->rclClip.top,
1197 lpExcludeClipRect->rclClip.right,
1198 lpExcludeClipRect->rclClip.bottom );
1199 FIXME("ExcludeClipRect\n");
1201 break;
1204 case EMR_SCALEVIEWPORTEXTEX:
1206 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
1208 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1209 break;
1210 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1211 !lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->yDenom)
1212 break;
1213 info->vportExtX = (info->vportExtX * lpScaleViewportExtEx->xNum) /
1214 lpScaleViewportExtEx->xDenom;
1215 info->vportExtY = (info->vportExtY * lpScaleViewportExtEx->yNum) /
1216 lpScaleViewportExtEx->yDenom;
1217 if (info->vportExtX == 0) info->vportExtX = 1;
1218 if (info->vportExtY == 0) info->vportExtY = 1;
1219 if (info->mode == MM_ISOTROPIC)
1220 FIXME("EMRSCALEVIEWPORTEXTEX MM_ISOTROPIC mapping\n");
1221 /* MAPPING_FixIsotropic( dc ); */
1223 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1224 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1225 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1227 break;
1230 case EMR_SCALEWINDOWEXTEX:
1232 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
1234 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1235 break;
1236 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1237 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1238 break;
1239 info->wndExtX = (info->wndExtX * lpScaleWindowExtEx->xNum) /
1240 lpScaleWindowExtEx->xDenom;
1241 info->wndExtY = (info->wndExtY * lpScaleWindowExtEx->yNum) /
1242 lpScaleWindowExtEx->yDenom;
1243 if (info->wndExtX == 0) info->wndExtX = 1;
1244 if (info->wndExtY == 0) info->wndExtY = 1;
1245 if (info->mode == MM_ISOTROPIC)
1246 FIXME("EMRSCALEWINDOWEXTEX MM_ISOTROPIC mapping\n");
1247 /* MAPPING_FixIsotropic( dc ); */
1249 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1250 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1251 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1253 break;
1256 case EMR_MODIFYWORLDTRANSFORM:
1258 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
1260 switch(lpModifyWorldTrans->iMode) {
1261 case MWT_IDENTITY:
1262 info->world_transform.eM11 = info->world_transform.eM22 = 1;
1263 info->world_transform.eM12 = info->world_transform.eM21 = 0;
1264 info->world_transform.eDx = info->world_transform.eDy = 0;
1265 break;
1266 case MWT_LEFTMULTIPLY:
1267 CombineTransform(&info->world_transform, &lpModifyWorldTrans->xform,
1268 &info->world_transform);
1269 break;
1270 case MWT_RIGHTMULTIPLY:
1271 CombineTransform(&info->world_transform, &info->world_transform,
1272 &lpModifyWorldTrans->xform);
1273 break;
1274 default:
1275 FIXME("Unknown imode %ld\n", lpModifyWorldTrans->iMode);
1276 break;
1278 break;
1281 case EMR_ANGLEARC:
1283 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
1285 AngleArc( hdc,
1286 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1287 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1288 lpAngleArc->eSweepAngle );
1290 break;
1293 case EMR_ROUNDRECT:
1295 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
1297 RoundRect( hdc,
1298 lpRoundRect->rclBox.left,
1299 lpRoundRect->rclBox.top,
1300 lpRoundRect->rclBox.right,
1301 lpRoundRect->rclBox.bottom,
1302 lpRoundRect->szlCorner.cx,
1303 lpRoundRect->szlCorner.cy );
1305 break;
1308 case EMR_ARC:
1310 PEMRARC lpArc = (PEMRARC)mr;
1312 Arc( hdc,
1313 (INT)lpArc->rclBox.left,
1314 (INT)lpArc->rclBox.top,
1315 (INT)lpArc->rclBox.right,
1316 (INT)lpArc->rclBox.bottom,
1317 (INT)lpArc->ptlStart.x,
1318 (INT)lpArc->ptlStart.y,
1319 (INT)lpArc->ptlEnd.x,
1320 (INT)lpArc->ptlEnd.y );
1322 break;
1325 case EMR_CHORD:
1327 PEMRCHORD lpChord = (PEMRCHORD)mr;
1329 Chord( hdc,
1330 (INT)lpChord->rclBox.left,
1331 (INT)lpChord->rclBox.top,
1332 (INT)lpChord->rclBox.right,
1333 (INT)lpChord->rclBox.bottom,
1334 (INT)lpChord->ptlStart.x,
1335 (INT)lpChord->ptlStart.y,
1336 (INT)lpChord->ptlEnd.x,
1337 (INT)lpChord->ptlEnd.y );
1339 break;
1342 case EMR_PIE:
1344 PEMRPIE lpPie = (PEMRPIE)mr;
1346 Pie( hdc,
1347 (INT)lpPie->rclBox.left,
1348 (INT)lpPie->rclBox.top,
1349 (INT)lpPie->rclBox.right,
1350 (INT)lpPie->rclBox.bottom,
1351 (INT)lpPie->ptlStart.x,
1352 (INT)lpPie->ptlStart.y,
1353 (INT)lpPie->ptlEnd.x,
1354 (INT)lpPie->ptlEnd.y );
1356 break;
1359 case EMR_ARCTO:
1361 PEMRARC lpArcTo = (PEMRARC)mr;
1363 ArcTo( hdc,
1364 (INT)lpArcTo->rclBox.left,
1365 (INT)lpArcTo->rclBox.top,
1366 (INT)lpArcTo->rclBox.right,
1367 (INT)lpArcTo->rclBox.bottom,
1368 (INT)lpArcTo->ptlStart.x,
1369 (INT)lpArcTo->ptlStart.y,
1370 (INT)lpArcTo->ptlEnd.x,
1371 (INT)lpArcTo->ptlEnd.y );
1373 break;
1376 case EMR_EXTFLOODFILL:
1378 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
1380 ExtFloodFill( hdc,
1381 (INT)lpExtFloodFill->ptlStart.x,
1382 (INT)lpExtFloodFill->ptlStart.y,
1383 lpExtFloodFill->crColor,
1384 (UINT)lpExtFloodFill->iMode );
1386 break;
1389 case EMR_POLYDRAW:
1391 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
1392 PolyDraw( hdc,
1393 (const LPPOINT)lpPolyDraw->aptl,
1394 lpPolyDraw->abTypes,
1395 (INT)lpPolyDraw->cptl );
1397 break;
1400 case EMR_SETARCDIRECTION:
1402 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1403 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1404 break;
1407 case EMR_SETMITERLIMIT:
1409 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1410 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1411 break;
1414 case EMR_BEGINPATH:
1416 BeginPath( hdc );
1417 break;
1420 case EMR_ENDPATH:
1422 EndPath( hdc );
1423 break;
1426 case EMR_CLOSEFIGURE:
1428 CloseFigure( hdc );
1429 break;
1432 case EMR_FILLPATH:
1434 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1435 FillPath( hdc );
1436 break;
1439 case EMR_STROKEANDFILLPATH:
1441 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1442 StrokeAndFillPath( hdc );
1443 break;
1446 case EMR_STROKEPATH:
1448 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1449 StrokePath( hdc );
1450 break;
1453 case EMR_FLATTENPATH:
1455 FlattenPath( hdc );
1456 break;
1459 case EMR_WIDENPATH:
1461 WidenPath( hdc );
1462 break;
1465 case EMR_SELECTCLIPPATH:
1467 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1468 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1469 break;
1472 case EMR_ABORTPATH:
1474 AbortPath( hdc );
1475 break;
1478 case EMR_CREATECOLORSPACE:
1480 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1481 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1482 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1483 break;
1486 case EMR_SETCOLORSPACE:
1488 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1489 SetColorSpace( hdc,
1490 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1491 break;
1494 case EMR_DELETECOLORSPACE:
1496 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1497 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1498 break;
1501 case EMR_SETICMMODE:
1503 PEMRSETICMMODE lpSetICMMode = (PEMRSETICMMODE)mr;
1504 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1505 break;
1508 case EMR_PIXELFORMAT:
1510 INT iPixelFormat;
1511 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1513 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1514 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1516 break;
1519 case EMR_SETPALETTEENTRIES:
1521 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1523 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1524 (UINT)lpSetPaletteEntries->iStart,
1525 (UINT)lpSetPaletteEntries->cEntries,
1526 lpSetPaletteEntries->aPalEntries );
1528 break;
1531 case EMR_RESIZEPALETTE:
1533 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1535 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1536 (UINT)lpResizePalette->cEntries );
1538 break;
1541 case EMR_CREATEDIBPATTERNBRUSHPT:
1543 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1544 LPVOID lpPackedStruct;
1546 /* check that offsets and data are contained within the record */
1547 if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
1548 (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
1549 ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
1550 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
1552 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1553 break;
1556 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1557 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1558 lpCreate->cbBmi + lpCreate->cbBits );
1559 if(!lpPackedStruct)
1561 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1562 break;
1565 /* Now pack this structure */
1566 memcpy( lpPackedStruct,
1567 ((BYTE*)lpCreate) + lpCreate->offBmi,
1568 lpCreate->cbBmi );
1569 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1570 ((BYTE*)lpCreate) + lpCreate->offBits,
1571 lpCreate->cbBits );
1573 (handletable->objectHandle)[lpCreate->ihBrush] =
1574 CreateDIBPatternBrushPt( lpPackedStruct,
1575 (UINT)lpCreate->iUsage );
1577 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1579 break;
1582 case EMR_CREATEMONOBRUSH:
1584 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1585 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1586 HBITMAP hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1587 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1588 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1589 /* CreatePatternBrush created a copy of the bitmap */
1590 DeleteObject(hBmp);
1591 break;
1594 case EMR_BITBLT:
1596 PEMRBITBLT pBitBlt = (PEMRBITBLT)mr;
1598 if(pBitBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1599 PatBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1600 pBitBlt->dwRop);
1601 } else { /* BitBlt */
1602 HDC hdcSrc = CreateCompatibleDC(hdc);
1603 HBRUSH hBrush, hBrushOld;
1604 HBITMAP hBmp = 0, hBmpOld = 0;
1605 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pBitBlt->offBmiSrc);
1607 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1609 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1610 hBrushOld = SelectObject(hdcSrc, hBrush);
1611 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1612 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1613 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1614 SelectObject(hdcSrc, hBrushOld);
1615 DeleteObject(hBrush);
1617 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1618 (BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1619 hBmpOld = SelectObject(hdcSrc, hBmp);
1621 BitBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1622 hdcSrc, pBitBlt->xSrc, pBitBlt->ySrc, pBitBlt->dwRop);
1624 SelectObject(hdcSrc, hBmpOld);
1625 DeleteObject(hBmp);
1626 DeleteDC(hdcSrc);
1628 break;
1631 case EMR_STRETCHBLT:
1633 PEMRSTRETCHBLT pStretchBlt= (PEMRSTRETCHBLT)mr;
1635 TRACE("EMR_STRETCHBLT: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. rop %08lx offBitsSrc %ld\n",
1636 pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1637 pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1638 pStretchBlt->dwRop, pStretchBlt->offBitsSrc);
1640 if(pStretchBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1641 PatBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1642 pStretchBlt->dwRop);
1643 } else { /* StretchBlt */
1644 HDC hdcSrc = CreateCompatibleDC(hdc);
1645 HBRUSH hBrush, hBrushOld;
1646 HBITMAP hBmp = 0, hBmpOld = 0;
1647 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pStretchBlt->offBmiSrc);
1649 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1651 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1652 hBrushOld = SelectObject(hdcSrc, hBrush);
1653 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1654 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1655 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1656 SelectObject(hdcSrc, hBrushOld);
1657 DeleteObject(hBrush);
1659 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1660 (BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1661 hBmpOld = SelectObject(hdcSrc, hBmp);
1663 StretchBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1664 hdcSrc, pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1665 pStretchBlt->dwRop);
1667 SelectObject(hdcSrc, hBmpOld);
1668 DeleteObject(hBmp);
1669 DeleteDC(hdcSrc);
1671 break;
1674 case EMR_MASKBLT:
1676 PEMRMASKBLT pMaskBlt= (PEMRMASKBLT)mr;
1677 HDC hdcSrc = CreateCompatibleDC(hdc);
1678 HBRUSH hBrush, hBrushOld;
1679 HBITMAP hBmp, hBmpOld, hBmpMask;
1680 BITMAPINFO *pbi;
1682 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1684 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1685 hBrushOld = SelectObject(hdcSrc, hBrush);
1686 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1687 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1688 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1689 SelectObject(hdcSrc, hBrushOld);
1690 DeleteObject(hBrush);
1692 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiMask);
1693 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1694 (BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1696 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiSrc);
1697 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1698 (BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1699 hBmpOld = SelectObject(hdcSrc, hBmp);
1700 MaskBlt(hdc,
1701 pMaskBlt->xDest,
1702 pMaskBlt->yDest,
1703 pMaskBlt->cxDest,
1704 pMaskBlt->cyDest,
1705 hdcSrc,
1706 pMaskBlt->xSrc,
1707 pMaskBlt->ySrc,
1708 hBmpMask,
1709 pMaskBlt->xMask,
1710 pMaskBlt->yMask,
1711 pMaskBlt->dwRop);
1712 SelectObject(hdcSrc, hBmpOld);
1713 DeleteObject(hBmp);
1714 DeleteObject(hBmpMask);
1715 DeleteDC(hdcSrc);
1716 break;
1719 case EMR_PLGBLT:
1721 PEMRPLGBLT pPlgBlt= (PEMRPLGBLT)mr;
1722 HDC hdcSrc = CreateCompatibleDC(hdc);
1723 HBRUSH hBrush, hBrushOld;
1724 HBITMAP hBmp, hBmpOld, hBmpMask;
1725 BITMAPINFO *pbi;
1726 POINT pts[3];
1728 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1730 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1731 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1732 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1734 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1735 hBrushOld = SelectObject(hdcSrc, hBrush);
1736 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1737 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1738 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1739 SelectObject(hdcSrc, hBrushOld);
1740 DeleteObject(hBrush);
1742 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiMask);
1743 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1744 (BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1746 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiSrc);
1747 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1748 (BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1749 hBmpOld = SelectObject(hdcSrc, hBmp);
1750 PlgBlt(hdc,
1751 pts,
1752 hdcSrc,
1753 pPlgBlt->xSrc,
1754 pPlgBlt->ySrc,
1755 pPlgBlt->cxSrc,
1756 pPlgBlt->cySrc,
1757 hBmpMask,
1758 pPlgBlt->xMask,
1759 pPlgBlt->yMask);
1760 SelectObject(hdcSrc, hBmpOld);
1761 DeleteObject(hBmp);
1762 DeleteObject(hBmpMask);
1763 DeleteDC(hdcSrc);
1764 break;
1767 case EMR_SETDIBITSTODEVICE:
1769 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice = (PEMRSETDIBITSTODEVICE)mr;
1771 SetDIBitsToDevice(hdc,
1772 pSetDIBitsToDevice->xDest,
1773 pSetDIBitsToDevice->yDest,
1774 pSetDIBitsToDevice->cxSrc,
1775 pSetDIBitsToDevice->cySrc,
1776 pSetDIBitsToDevice->xSrc,
1777 pSetDIBitsToDevice->ySrc,
1778 pSetDIBitsToDevice->iStartScan,
1779 pSetDIBitsToDevice->cScans,
1780 (BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
1781 (BITMAPINFO *)((BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
1782 pSetDIBitsToDevice->iUsageSrc);
1783 break;
1786 case EMR_POLYTEXTOUTA:
1788 PEMRPOLYTEXTOUTA pPolyTextOutA = (PEMRPOLYTEXTOUTA)mr;
1789 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
1790 LONG i;
1791 XFORM xform, xformOld;
1792 int gModeOld;
1794 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
1795 GetWorldTransform(hdc, &xformOld);
1797 xform.eM11 = pPolyTextOutA->exScale;
1798 xform.eM12 = 0.0;
1799 xform.eM21 = 0.0;
1800 xform.eM22 = pPolyTextOutA->eyScale;
1801 xform.eDx = 0.0;
1802 xform.eDy = 0.0;
1803 SetWorldTransform(hdc, &xform);
1805 /* Set up POLYTEXTA structures */
1806 for(i = 0; i < pPolyTextOutA->cStrings; i++)
1808 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
1809 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
1810 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
1811 polytextA[i].lpstr = (LPSTR)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
1812 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
1813 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
1814 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
1815 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
1816 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
1817 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
1819 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
1820 HeapFree(GetProcessHeap(), 0, polytextA);
1822 SetWorldTransform(hdc, &xformOld);
1823 SetGraphicsMode(hdc, gModeOld);
1824 break;
1827 case EMR_POLYTEXTOUTW:
1829 PEMRPOLYTEXTOUTW pPolyTextOutW = (PEMRPOLYTEXTOUTW)mr;
1830 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
1831 LONG i;
1832 XFORM xform, xformOld;
1833 int gModeOld;
1835 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
1836 GetWorldTransform(hdc, &xformOld);
1838 xform.eM11 = pPolyTextOutW->exScale;
1839 xform.eM12 = 0.0;
1840 xform.eM21 = 0.0;
1841 xform.eM22 = pPolyTextOutW->eyScale;
1842 xform.eDx = 0.0;
1843 xform.eDy = 0.0;
1844 SetWorldTransform(hdc, &xform);
1846 /* Set up POLYTEXTW structures */
1847 for(i = 0; i < pPolyTextOutW->cStrings; i++)
1849 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
1850 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
1851 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
1852 polytextW[i].lpstr = (LPWSTR)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
1853 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
1854 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
1855 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
1856 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
1857 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
1858 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
1860 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
1861 HeapFree(GetProcessHeap(), 0, polytextW);
1863 SetWorldTransform(hdc, &xformOld);
1864 SetGraphicsMode(hdc, gModeOld);
1865 break;
1868 case EMR_FILLRGN:
1870 PEMRFILLRGN pFillRgn = (PEMRFILLRGN)mr;
1871 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
1872 FillRgn(hdc,
1873 hRgn,
1874 (handletable->objectHandle)[pFillRgn->ihBrush]);
1875 DeleteObject(hRgn);
1876 break;
1879 case EMR_FRAMERGN:
1881 PEMRFRAMERGN pFrameRgn = (PEMRFRAMERGN)mr;
1882 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
1883 FrameRgn(hdc,
1884 hRgn,
1885 (handletable->objectHandle)[pFrameRgn->ihBrush],
1886 pFrameRgn->szlStroke.cx,
1887 pFrameRgn->szlStroke.cy);
1888 DeleteObject(hRgn);
1889 break;
1892 case EMR_INVERTRGN:
1894 PEMRINVERTRGN pInvertRgn = (PEMRINVERTRGN)mr;
1895 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
1896 InvertRgn(hdc, hRgn);
1897 DeleteObject(hRgn);
1898 break;
1901 case EMR_PAINTRGN:
1903 PEMRPAINTRGN pPaintRgn = (PEMRPAINTRGN)mr;
1904 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
1905 PaintRgn(hdc, hRgn);
1906 DeleteObject(hRgn);
1907 break;
1910 case EMR_SETTEXTJUSTIFICATION:
1912 PEMRSETTEXTJUSTIFICATION pSetTextJust = (PEMRSETTEXTJUSTIFICATION)mr;
1913 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
1914 break;
1917 case EMR_SETLAYOUT:
1919 PEMRSETLAYOUT pSetLayout = (PEMRSETLAYOUT)mr;
1920 SetLayout(hdc, pSetLayout->iMode);
1921 break;
1924 case EMR_POLYDRAW16:
1925 case EMR_GLSRECORD:
1926 case EMR_GLSBOUNDEDRECORD:
1927 case EMR_DRAWESCAPE :
1928 case EMR_EXTESCAPE:
1929 case EMR_STARTDOC:
1930 case EMR_SMALLTEXTOUT:
1931 case EMR_FORCEUFIMAPPING:
1932 case EMR_NAMEDESCAPE:
1933 case EMR_COLORCORRECTPALETTE:
1934 case EMR_SETICMPROFILEA:
1935 case EMR_SETICMPROFILEW:
1936 case EMR_ALPHABLEND:
1937 case EMR_TRANSPARENTBLT:
1938 case EMR_GRADIENTFILL:
1939 case EMR_SETLINKEDUFI:
1940 case EMR_COLORMATCHTOTARGETW:
1941 case EMR_CREATECOLORSPACEW:
1943 default:
1944 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1945 record then ignore and return TRUE. */
1946 FIXME("type %d is unimplemented\n", type);
1947 break;
1949 tmprc.left = tmprc.top = 0;
1950 tmprc.right = tmprc.bottom = 1000;
1951 LPtoDP(hdc, (POINT*)&tmprc, 2);
1952 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", tmprc.left,
1953 tmprc.top, tmprc.right, tmprc.bottom);
1955 if ( !IS_WIN9X() )
1957 /* WinNT - update the transform (win9x updates when the next graphics output
1958 record is played). */
1959 EMF_Update_MF_Xform(hdc, info);
1962 return TRUE;
1966 /*****************************************************************************
1968 * EnumEnhMetaFile (GDI32.@)
1970 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1971 * for each
1972 * record. Returns when either every record has been used or
1973 * when _EnhMetaFunc_ returns FALSE.
1976 * RETURNS
1977 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1978 * returns FALSE.
1980 * BUGS
1981 * Ignores rect.
1983 * NOTES
1984 * This function behaves differently in Win9x and WinNT.
1986 * In WinNT, the DC's world transform is updated as the EMF changes
1987 * the Window/Viewport Extent and Origin or it's world transform.
1988 * The actual Window/Viewport Extent and Origin are left untouched.
1990 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
1991 * updates the scaling itself but only just before a record that
1992 * writes anything to the DC.
1994 * I'm not sure where the data (enum_emh_data) is stored in either
1995 * version. For this implementation, it is stored before the handle
1996 * table, but it could be stored in the DC, in the EMF handle or in
1997 * TLS.
1998 * MJM 5 Oct 2002
2000 BOOL WINAPI EnumEnhMetaFile(
2001 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
2002 HENHMETAFILE hmf, /* [in] EMF to walk */
2003 ENHMFENUMPROC callback, /* [in] callback function */
2004 LPVOID data, /* [in] optional data for callback function */
2005 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
2008 BOOL ret;
2009 ENHMETAHEADER *emh;
2010 ENHMETARECORD *emr;
2011 DWORD offset;
2012 UINT i;
2013 HANDLETABLE *ht;
2014 INT savedMode = 0;
2015 XFORM savedXform;
2016 HPEN hPen = NULL;
2017 HBRUSH hBrush = NULL;
2018 HFONT hFont = NULL;
2019 enum_emh_data *info;
2020 SIZE vp_size, win_size;
2021 POINT vp_org, win_org;
2022 INT mapMode = MM_TEXT;
2023 COLORREF old_text_color = 0, old_bk_color = 0;
2025 if(!lpRect)
2027 SetLastError(ERROR_INVALID_PARAMETER);
2028 return FALSE;
2031 emh = EMF_GetEnhMetaHeader(hmf);
2032 if(!emh) {
2033 SetLastError(ERROR_INVALID_HANDLE);
2034 return FALSE;
2037 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2038 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
2039 if(!info)
2041 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2042 return FALSE;
2044 info->wndOrgX = 0;
2045 info->wndOrgY = 0;
2046 info->wndExtX = 1;
2047 info->wndExtY = 1;
2048 info->vportOrgX = 0;
2049 info->vportOrgY = 0;
2050 info->vportExtX = 1;
2051 info->vportExtY = 1;
2052 info->world_transform.eM11 = info->world_transform.eM22 = 1;
2053 info->world_transform.eM12 = info->world_transform.eM21 = 0;
2054 info->world_transform.eDx = info->world_transform.eDy = 0;
2056 ht = (HANDLETABLE*) &info[1];
2057 ht->objectHandle[0] = hmf;
2059 if(hdc)
2061 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
2062 GetWorldTransform(hdc, &savedXform);
2063 GetViewportExtEx(hdc, &vp_size);
2064 GetWindowExtEx(hdc, &win_size);
2065 GetViewportOrgEx(hdc, &vp_org);
2066 GetWindowOrgEx(hdc, &win_org);
2067 mapMode = GetMapMode(hdc);
2069 /* save the current pen, brush and font */
2070 hPen = GetCurrentObject(hdc, OBJ_PEN);
2071 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
2072 hFont = GetCurrentObject(hdc, OBJ_FONT);
2074 old_text_color = SetTextColor(hdc, RGB(0,0,0));
2075 old_bk_color = SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
2078 info->mode = MM_TEXT;
2080 if ( IS_WIN9X() )
2082 /* Win95 leaves the vp/win ext/org info alone */
2083 info->init_transform.eM11 = 1.0;
2084 info->init_transform.eM12 = 0.0;
2085 info->init_transform.eM21 = 0.0;
2086 info->init_transform.eM22 = 1.0;
2087 info->init_transform.eDx = 0.0;
2088 info->init_transform.eDy = 0.0;
2090 else
2092 /* WinNT combines the vp/win ext/org info into a transform */
2093 FLOAT xscale, yscale;
2094 xscale = (FLOAT)vp_size.cx / (FLOAT)win_size.cx;
2095 yscale = (FLOAT)vp_size.cy / (FLOAT)win_size.cy;
2096 info->init_transform.eM11 = xscale;
2097 info->init_transform.eM12 = 0.0;
2098 info->init_transform.eM21 = 0.0;
2099 info->init_transform.eM22 = yscale;
2100 info->init_transform.eDx = (FLOAT)vp_org.x - xscale * (FLOAT)win_org.x;
2101 info->init_transform.eDy = (FLOAT)vp_org.y - yscale * (FLOAT)win_org.y;
2103 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
2106 if ( WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
2108 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
2109 XFORM xform;
2111 TRACE("rect: %ld,%ld - %ld,%ld. rclFrame: %ld,%ld - %ld,%ld\n",
2112 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
2113 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
2114 emh->rclFrame.bottom);
2116 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
2117 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
2118 xscale = (FLOAT) WIDTH(*lpRect) * 100.0 /
2119 WIDTH(emh->rclFrame) * xSrcPixSize;
2120 yscale = (FLOAT) HEIGHT(*lpRect) * 100.0 /
2121 HEIGHT(emh->rclFrame) * ySrcPixSize;
2123 xform.eM11 = xscale;
2124 xform.eM12 = 0;
2125 xform.eM21 = 0;
2126 xform.eM22 = yscale;
2127 xform.eDx = (FLOAT) lpRect->left - (FLOAT) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
2128 xform.eDy = (FLOAT) lpRect->top - (FLOAT) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
2130 CombineTransform(&info->init_transform, &xform, &info->init_transform);
2133 /* WinNT resets the current vp/win org/ext */
2134 if ( !IS_WIN9X() )
2136 SetMapMode(hdc, MM_TEXT);
2137 SetWindowOrgEx(hdc, 0, 0, NULL);
2138 SetViewportOrgEx(hdc, 0, 0, NULL);
2139 EMF_Update_MF_Xform(hdc, info);
2142 ret = TRUE;
2143 offset = 0;
2144 while(ret && offset < emh->nBytes)
2146 emr = (ENHMETARECORD *)((char *)emh + offset);
2147 TRACE("Calling EnumFunc with record %s, size %ld\n", get_emr_name(emr->iType), emr->nSize);
2148 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2149 offset += emr->nSize;
2152 if (hdc)
2154 SetBkColor(hdc, old_bk_color);
2155 SetTextColor(hdc, old_text_color);
2157 /* restore pen, brush and font */
2158 SelectObject(hdc, hBrush);
2159 SelectObject(hdc, hPen);
2160 SelectObject(hdc, hFont);
2162 SetWorldTransform(hdc, &savedXform);
2163 if (savedMode)
2164 SetGraphicsMode(hdc, savedMode);
2165 SetMapMode(hdc, mapMode);
2166 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2167 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2168 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2169 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2172 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2173 if( (ht->objectHandle)[i] )
2174 DeleteObject( (ht->objectHandle)[i] );
2176 HeapFree( GetProcessHeap(), 0, info );
2177 return ret;
2180 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2181 const ENHMETARECORD *emr,
2182 INT handles, LPARAM data)
2184 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2187 /**************************************************************************
2188 * PlayEnhMetaFile (GDI32.@)
2190 * Renders an enhanced metafile into a specified rectangle *lpRect
2191 * in device context hdc.
2194 BOOL WINAPI PlayEnhMetaFile(
2195 HDC hdc, /* [in] DC to render into */
2196 HENHMETAFILE hmf, /* [in] metafile to render */
2197 const RECT *lpRect /* [in] rectangle to place metafile inside */
2200 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2201 lpRect);
2204 /*****************************************************************************
2205 * DeleteEnhMetaFile (GDI32.@)
2207 * Deletes an enhanced metafile and frees the associated storage.
2209 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2211 return EMF_Delete_HENHMETAFILE( hmf );
2214 /*****************************************************************************
2215 * CopyEnhMetaFileA (GDI32.@) Duplicate an enhanced metafile
2219 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2220 HENHMETAFILE hmfSrc,
2221 LPCSTR file)
2223 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2224 HENHMETAFILE hmfDst;
2226 if(!emrSrc) return FALSE;
2227 if (!file) {
2228 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2229 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2230 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2231 } else {
2232 HANDLE hFile;
2233 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2234 NULL, CREATE_ALWAYS, 0, 0);
2235 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
2236 CloseHandle( hFile );
2237 /* Reopen file for reading only, so that apps can share
2238 read access to the file while hmf is still valid */
2239 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2240 NULL, OPEN_EXISTING, 0, 0);
2241 if(hFile == INVALID_HANDLE_VALUE) {
2242 ERR("Can't reopen emf for reading\n");
2243 return 0;
2245 hmfDst = EMF_GetEnhMetaFile( hFile );
2246 CloseHandle( hFile );
2248 return hmfDst;
2251 /*****************************************************************************
2252 * CopyEnhMetaFileW (GDI32.@) Duplicate an enhanced metafile
2256 HENHMETAFILE WINAPI CopyEnhMetaFileW(
2257 HENHMETAFILE hmfSrc,
2258 LPCWSTR file)
2260 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2261 HENHMETAFILE hmfDst;
2263 if(!emrSrc) return FALSE;
2264 if (!file) {
2265 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2266 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2267 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2268 } else {
2269 HANDLE hFile;
2270 hFile = CreateFileW( file, GENERIC_WRITE | GENERIC_READ, 0,
2271 NULL, CREATE_ALWAYS, 0, 0);
2272 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
2273 CloseHandle( hFile );
2274 /* Reopen file for reading only, so that apps can share
2275 read access to the file while hmf is still valid */
2276 hFile = CreateFileW( file, GENERIC_READ, FILE_SHARE_READ,
2277 NULL, OPEN_EXISTING, 0, 0);
2278 if(hFile == INVALID_HANDLE_VALUE) {
2279 ERR("Can't reopen emf for reading\n");
2280 return 0;
2282 hmfDst = EMF_GetEnhMetaFile( hFile );
2283 CloseHandle( hFile );
2285 return hmfDst;
2289 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2290 typedef struct tagEMF_PaletteCopy
2292 UINT cEntries;
2293 LPPALETTEENTRY lpPe;
2294 } EMF_PaletteCopy;
2296 /***************************************************************
2297 * Find the EMR_EOF record and then use it to find the
2298 * palette entries for this enhanced metafile.
2299 * The lpData is actually a pointer to a EMF_PaletteCopy struct
2300 * which contains the max number of elements to copy and where
2301 * to copy them to.
2303 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2305 INT CALLBACK cbEnhPaletteCopy( HDC a,
2306 HANDLETABLE *b,
2307 const ENHMETARECORD *lpEMR,
2308 INT c,
2309 LPARAM lpData )
2312 if ( lpEMR->iType == EMR_EOF )
2314 PEMREOF lpEof = (PEMREOF)lpEMR;
2315 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2316 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2318 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
2320 memcpy( (LPVOID)info->lpPe,
2321 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
2322 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2324 /* Update the passed data as a return code */
2325 info->lpPe = NULL; /* Palettes were copied! */
2326 info->cEntries = (UINT)dwNumPalToCopy;
2328 return FALSE; /* That's all we need */
2331 return TRUE;
2334 /*****************************************************************************
2335 * GetEnhMetaFilePaletteEntries (GDI32.@)
2337 * Copy the palette and report size
2339 * BUGS: Error codes (SetLastError) are not set on failures
2341 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2342 UINT cEntries,
2343 LPPALETTEENTRY lpPe )
2345 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2346 EMF_PaletteCopy infoForCallBack;
2348 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2350 /* First check if there are any palettes associated with
2351 this metafile. */
2352 if ( enhHeader->nPalEntries == 0 ) return 0;
2354 /* Is the user requesting the number of palettes? */
2355 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
2357 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2358 infoForCallBack.cEntries = cEntries;
2359 infoForCallBack.lpPe = lpPe;
2361 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2362 &infoForCallBack, 0 ) )
2363 return GDI_ERROR;
2365 /* Verify that the callback executed correctly */
2366 if ( infoForCallBack.lpPe != NULL )
2368 /* Callback proc had error! */
2369 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2370 return GDI_ERROR;
2373 return infoForCallBack.cEntries;
2376 typedef struct gdi_mf_comment
2378 DWORD ident;
2379 DWORD iComment;
2380 DWORD nVersion;
2381 DWORD nChecksum;
2382 DWORD fFlags;
2383 DWORD cbWinMetaFile;
2384 } gdi_mf_comment;
2386 /******************************************************************
2387 * SetWinMetaFileBits (GDI32.@)
2389 * Translate from old style to new style.
2392 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2393 CONST BYTE *lpbBuffer,
2394 HDC hdcRef,
2395 CONST METAFILEPICT *lpmfp
2398 HMETAFILE hmf = 0;
2399 HENHMETAFILE ret = 0;
2400 HDC hdc = 0, hdcdisp = 0;
2401 METAFILEPICT mfp;
2402 RECT rc, *prcFrame = NULL;
2403 gdi_mf_comment *mfcomment;
2404 UINT mfcomment_size;
2405 INT horzres, vertres, horzsize, vertsize, xext, yext;
2407 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2409 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2410 if(!hmf)
2412 WARN("SetMetaFileBitsEx failed\n");
2413 return 0;
2416 if(!hdcRef)
2417 hdcRef = hdcdisp = CreateDCA("DISPLAY", NULL, NULL, NULL);
2419 if(!lpmfp) {
2420 lpmfp = &mfp;
2421 mfp.mm = MM_ANISOTROPIC;
2422 mfp.xExt = 100;
2423 mfp.yExt = 100;
2424 FIXME("Correct Exts from dc\n");
2426 else
2428 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2429 if ( ( mfp.xExt < 0 ) || ( mfp.yExt < 0) )
2430 FIXME("Negative coordinates!\n");
2433 if(lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC) {
2434 rc.left = rc.top = 0;
2435 rc.right = lpmfp->xExt;
2436 rc.bottom = lpmfp->yExt;
2437 prcFrame = &rc;
2440 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL))) {
2441 ERR("CreateEnhMetaFile fails?\n");
2442 goto end;
2445 horzres = GetDeviceCaps(hdcRef, HORZRES);
2446 vertres = GetDeviceCaps(hdcRef, VERTRES);
2447 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2448 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2450 if(hdcdisp) {
2451 DeleteDC(hdcdisp);
2452 hdcRef = 0;
2456 * Write the original METAFILE into the enhanced metafile.
2457 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2459 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2460 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2461 if(mfcomment)
2463 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2464 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2465 mfcomment->nVersion = 0x00000300;
2466 mfcomment->nChecksum = 0; /* FIXME */
2467 mfcomment->fFlags = 0;
2468 mfcomment->cbWinMetaFile = cbBuffer;
2469 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2470 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2471 HeapFree(GetProcessHeap(), 0, mfcomment);
2474 if(lpmfp->mm != MM_TEXT)
2475 SetMapMode(hdc, lpmfp->mm);
2477 /* set the initial viewport:window ratio as 1:1 */
2478 xext = lpmfp->xExt*horzres/(100*horzsize);
2479 yext = lpmfp->yExt*vertres/(100*vertsize);
2480 SetViewportExtEx(hdc, xext, yext, NULL);
2481 SetWindowExtEx(hdc, xext, yext, NULL);
2483 PlayMetaFile(hdc, hmf);
2485 ret = CloseEnhMetaFile(hdc);
2486 end:
2487 DeleteMetaFile(hmf);
2488 return ret;