2 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * The enhanced format consists of the following elements:
25 * A table of handles to GDI objects
26 * An array of metafile records
30 * The standard format consists of a header and an array of metafile records.
35 #include "wine/port.h"
46 #include "gdi_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
55 BOOL on_disk; /* true if metafile is on disk */
58 static const struct emr_name {
71 X(EMR_SETWINDOWEXTEX),
72 X(EMR_SETWINDOWORGEX),
73 X(EMR_SETVIEWPORTEXTEX),
74 X(EMR_SETVIEWPORTORGEX),
78 X(EMR_SETMAPPERFLAGS),
81 X(EMR_SETPOLYFILLMODE),
83 X(EMR_SETSTRETCHBLTMODE),
85 X(EMR_SETCOLORADJUSTMENT),
91 X(EMR_EXCLUDECLIPRECT),
92 X(EMR_INTERSECTCLIPRECT),
93 X(EMR_SCALEVIEWPORTEXTEX),
94 X(EMR_SCALEWINDOWEXTEX),
97 X(EMR_SETWORLDTRANSFORM),
98 X(EMR_MODIFYWORLDTRANSFORM),
101 X(EMR_CREATEBRUSHINDIRECT),
110 X(EMR_SELECTPALETTE),
111 X(EMR_CREATEPALETTE),
112 X(EMR_SETPALETTEENTRIES),
113 X(EMR_RESIZEPALETTE),
114 X(EMR_REALIZEPALETTE),
119 X(EMR_SETARCDIRECTION),
120 X(EMR_SETMITERLIMIT),
125 X(EMR_STROKEANDFILLPATH),
129 X(EMR_SELECTCLIPPATH),
136 X(EMR_EXTSELECTCLIPRGN),
141 X(EMR_SETDIBITSTODEVICE),
142 X(EMR_STRETCHDIBITS),
143 X(EMR_EXTCREATEFONTINDIRECTW),
149 X(EMR_POLYBEZIERTO16),
151 X(EMR_POLYPOLYLINE16),
152 X(EMR_POLYPOLYGON16),
154 X(EMR_CREATEMONOBRUSH),
155 X(EMR_CREATEDIBPATTERNBRUSHPT),
160 X(EMR_CREATECOLORSPACE),
161 X(EMR_SETCOLORSPACE),
162 X(EMR_DELETECOLORSPACE),
164 X(EMR_GLSBOUNDEDRECORD),
170 X(EMR_FORCEUFIMAPPING),
172 X(EMR_COLORCORRECTPALETTE),
173 X(EMR_SETICMPROFILEA),
174 X(EMR_SETICMPROFILEW),
177 X(EMR_TRANSPARENTBLT),
181 X(EMR_SETTEXTJUSTIFICATION),
182 X(EMR_COLORMATCHTOTARGETW),
183 X(EMR_CREATECOLORSPACEW)
187 /****************************************************************************
190 static const char *get_emr_name(DWORD type)
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 %d\n", type);
199 /***********************************************************************
202 * Returns whether a DIB can be converted to a monochrome DDB.
204 * A DIB can be converted if its color table contains only black and
205 * white. Black must be the first color in the color table.
207 * Note : If the first color in the color table is white followed by
208 * black, we can't convert it to a monochrome DDB with
209 * SetDIBits, because black and white would be inverted.
211 static inline BOOL is_dib_monochrome( const BITMAPINFO* info )
213 if (info->bmiHeader.biBitCount != 1) return FALSE;
215 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
217 const RGBTRIPLE *rgb = ((const BITMAPCOREINFO *) info)->bmciColors;
219 /* Check if the first color is black */
220 if ((rgb->rgbtRed == 0) && (rgb->rgbtGreen == 0) && (rgb->rgbtBlue == 0))
223 /* Check if the second color is white */
224 return ((rgb->rgbtRed == 0xff) && (rgb->rgbtGreen == 0xff)
225 && (rgb->rgbtBlue == 0xff));
229 else /* assume BITMAPINFOHEADER */
231 const RGBQUAD *rgb = info->bmiColors;
233 /* Check if the first color is black */
234 if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) &&
235 (rgb->rgbBlue == 0) && (rgb->rgbReserved == 0))
239 /* Check if the second color is white */
240 return ((rgb->rgbRed == 0xff) && (rgb->rgbGreen == 0xff)
241 && (rgb->rgbBlue == 0xff) && (rgb->rgbReserved == 0));
247 /****************************************************************************
248 * EMF_Create_HENHMETAFILE
250 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk )
253 ENHMETAFILEOBJ *metaObj;
255 if (emh->iType != EMR_HEADER)
257 SetLastError(ERROR_INVALID_DATA);
260 if (emh->dSignature != ENHMETA_SIGNATURE ||
261 (emh->nBytes & 3)) /* refuse to load unaligned EMF as Windows does */
263 WARN("Invalid emf header type 0x%08x sig 0x%08x.\n",
264 emh->iType, emh->dSignature);
268 if (!(metaObj = HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj) ))) return 0;
271 metaObj->on_disk = on_disk;
273 if (!(hmf = alloc_gdi_handle( &metaObj->header, OBJ_ENHMETAFILE, NULL )))
274 HeapFree( GetProcessHeap(), 0, metaObj );
278 /****************************************************************************
279 * EMF_Delete_HENHMETAFILE
281 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
283 ENHMETAFILEOBJ *metaObj = free_gdi_handle( hmf );
285 if(!metaObj) return FALSE;
288 UnmapViewOfFile( metaObj->emh );
290 HeapFree( GetProcessHeap(), 0, metaObj->emh );
291 return HeapFree( GetProcessHeap(), 0, metaObj );
294 /******************************************************************
295 * EMF_GetEnhMetaHeader
297 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
299 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
301 ENHMETAHEADER *ret = NULL;
302 ENHMETAFILEOBJ *metaObj = GDI_GetObjPtr( hmf, OBJ_ENHMETAFILE );
303 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
307 GDI_ReleaseObj( hmf );
312 /*****************************************************************************
316 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
322 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
323 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
324 CloseHandle( hMapping );
328 hemf = EMF_Create_HENHMETAFILE( emh, TRUE );
330 UnmapViewOfFile( emh );
335 /*****************************************************************************
336 * GetEnhMetaFileA (GDI32.@)
340 HENHMETAFILE WINAPI GetEnhMetaFileA(
341 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
347 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
348 OPEN_EXISTING, 0, 0);
349 if (hFile == INVALID_HANDLE_VALUE) {
350 WARN("could not open %s\n", lpszMetaFile);
353 hmf = EMF_GetEnhMetaFile( hFile );
354 CloseHandle( hFile );
358 /*****************************************************************************
359 * GetEnhMetaFileW (GDI32.@)
361 HENHMETAFILE WINAPI GetEnhMetaFileW(
362 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
367 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
368 OPEN_EXISTING, 0, 0);
369 if (hFile == INVALID_HANDLE_VALUE) {
370 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
373 hmf = EMF_GetEnhMetaFile( hFile );
374 CloseHandle( hFile );
378 /*****************************************************************************
379 * GetEnhMetaFileHeader (GDI32.@)
381 * Retrieves the record containing the header for the specified
382 * enhanced-format metafile.
385 * If buf is NULL, returns the size of buffer required.
386 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
389 UINT WINAPI GetEnhMetaFileHeader(
390 HENHMETAFILE hmf, /* [in] enhanced metafile */
391 UINT bufsize, /* [in] size of buffer */
392 LPENHMETAHEADER buf /* [out] buffer */
398 emh = EMF_GetEnhMetaHeader(hmf);
399 if(!emh) return FALSE;
401 if (!buf) return size;
402 size = min(size, bufsize);
403 memmove(buf, emh, size);
408 /*****************************************************************************
409 * GetEnhMetaFileDescriptionA (GDI32.@)
411 * See GetEnhMetaFileDescriptionW.
413 UINT WINAPI GetEnhMetaFileDescriptionA(
414 HENHMETAFILE hmf, /* [in] enhanced metafile */
415 UINT size, /* [in] size of buf */
416 LPSTR buf /* [out] buffer to receive description */
419 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
423 if(!emh) return FALSE;
424 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
425 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
426 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
428 if (!buf || !size ) return len;
430 len = min( size, len );
431 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
435 /*****************************************************************************
436 * GetEnhMetaFileDescriptionW (GDI32.@)
438 * Copies the description string of an enhanced metafile into a buffer
442 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
443 * number of characters copied.
445 UINT WINAPI GetEnhMetaFileDescriptionW(
446 HENHMETAFILE hmf, /* [in] enhanced metafile */
447 UINT size, /* [in] size of buf */
448 LPWSTR buf /* [out] buffer to receive description */
451 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
453 if(!emh) return FALSE;
454 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
455 if (!buf || !size ) return emh->nDescription;
457 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
458 return min(size, emh->nDescription);
461 /****************************************************************************
462 * SetEnhMetaFileBits (GDI32.@)
464 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
466 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
468 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
469 memmove(emh, buf, bufsize);
470 return EMF_Create_HENHMETAFILE( emh, FALSE );
473 /*****************************************************************************
474 * GetEnhMetaFileBits (GDI32.@)
477 UINT WINAPI GetEnhMetaFileBits(
483 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
489 if( buf == NULL ) return size;
491 size = min( size, bufsize );
492 memmove(buf, emh, size);
496 typedef struct EMF_dc_state
499 XFORM world_transform;
508 struct EMF_dc_state *next;
511 typedef struct enum_emh_data
513 XFORM init_transform;
516 EMF_dc_state *saved_state;
519 #define ENUM_GET_PRIVATE_DATA(ht) \
520 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
522 #define WIDTH(rect) ( (rect).right - (rect).left )
523 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
525 #define IS_WIN9X() (GetVersion()&0x80000000)
527 static void EMF_Update_MF_Xform(HDC hdc, const enum_emh_data *info)
529 XFORM mapping_mode_trans, final_trans;
530 double scaleX, scaleY;
532 scaleX = (double)info->state.vportExtX / (double)info->state.wndExtX;
533 scaleY = (double)info->state.vportExtY / (double)info->state.wndExtY;
534 mapping_mode_trans.eM11 = scaleX;
535 mapping_mode_trans.eM12 = 0.0;
536 mapping_mode_trans.eM21 = 0.0;
537 mapping_mode_trans.eM22 = scaleY;
538 mapping_mode_trans.eDx = (double)info->state.vportOrgX - scaleX * (double)info->state.wndOrgX;
539 mapping_mode_trans.eDy = (double)info->state.vportOrgY - scaleY * (double)info->state.wndOrgY;
541 CombineTransform(&final_trans, &info->state.world_transform, &mapping_mode_trans);
542 CombineTransform(&final_trans, &final_trans, &info->init_transform);
544 if (!SetWorldTransform(hdc, &final_trans))
546 ERR("World transform failed!\n");
550 static void EMF_RestoreDC( enum_emh_data *info, INT level )
552 if (abs(level) > info->save_level || level == 0) return;
554 if (level < 0) level = info->save_level + level + 1;
556 while (info->save_level >= level)
558 EMF_dc_state *state = info->saved_state;
559 info->saved_state = state->next;
561 if (--info->save_level < level)
562 info->state = *state;
563 HeapFree( GetProcessHeap(), 0, state );
567 static void EMF_SaveDC( enum_emh_data *info )
569 EMF_dc_state *state = HeapAlloc( GetProcessHeap(), 0, sizeof(*state));
572 *state = info->state;
573 state->next = info->saved_state;
574 info->saved_state = state;
576 TRACE("save_level %d\n", info->save_level);
580 static void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
582 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
583 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
584 INT horzRes = GetDeviceCaps( hdc, HORZRES );
585 INT vertRes = GetDeviceCaps( hdc, VERTRES );
587 TRACE("%d\n", info->state.mode);
589 switch(info->state.mode)
592 info->state.wndExtX = 1;
593 info->state.wndExtY = 1;
594 info->state.vportExtX = 1;
595 info->state.vportExtY = 1;
599 info->state.wndExtX = horzSize * 10;
600 info->state.wndExtY = vertSize * 10;
601 info->state.vportExtX = horzRes;
602 info->state.vportExtY = -vertRes;
605 info->state.wndExtX = horzSize * 100;
606 info->state.wndExtY = vertSize * 100;
607 info->state.vportExtX = horzRes;
608 info->state.vportExtY = -vertRes;
611 info->state.wndExtX = MulDiv(1000, horzSize, 254);
612 info->state.wndExtY = MulDiv(1000, vertSize, 254);
613 info->state.vportExtX = horzRes;
614 info->state.vportExtY = -vertRes;
617 info->state.wndExtX = MulDiv(10000, horzSize, 254);
618 info->state.wndExtY = MulDiv(10000, vertSize, 254);
619 info->state.vportExtX = horzRes;
620 info->state.vportExtY = -vertRes;
623 info->state.wndExtX = MulDiv(14400, horzSize, 254);
624 info->state.wndExtY = MulDiv(14400, vertSize, 254);
625 info->state.vportExtX = horzRes;
626 info->state.vportExtY = -vertRes;
635 /***********************************************************************
638 * Fix viewport extensions for isotropic mode.
641 static void EMF_FixIsotropic(HDC hdc, enum_emh_data *info)
643 double xdim = fabs((double)info->state.vportExtX * GetDeviceCaps( hdc, HORZSIZE ) /
644 (GetDeviceCaps( hdc, HORZRES ) * info->state.wndExtX));
645 double ydim = fabs((double)info->state.vportExtY * GetDeviceCaps( hdc, VERTSIZE ) /
646 (GetDeviceCaps( hdc, VERTRES ) * info->state.wndExtY));
650 INT mincx = (info->state.vportExtX >= 0) ? 1 : -1;
651 info->state.vportExtX = floor(info->state.vportExtX * ydim / xdim + 0.5);
652 if (!info->state.vportExtX) info->state.vportExtX = mincx;
656 INT mincy = (info->state.vportExtY >= 0) ? 1 : -1;
657 info->state.vportExtY = floor(info->state.vportExtY * xdim / ydim + 0.5);
658 if (!info->state.vportExtY) info->state.vportExtY = mincy;
662 /*****************************************************************************
663 * emr_produces_output
665 * Returns TRUE if the record type writes something to the dc. Used by
666 * PlayEnhMetaFileRecord to determine whether it needs to update the
667 * dc's xform when in win9x mode.
669 * FIXME: need to test which records should be here.
671 static BOOL emr_produces_output(int type)
677 case EMR_POLYBEZIERTO:
679 case EMR_POLYPOLYLINE:
680 case EMR_POLYPOLYGON:
683 case EMR_EXCLUDECLIPRECT:
684 case EMR_INTERSECTCLIPRECT:
685 case EMR_SELECTOBJECT:
693 case EMR_EXTFLOODFILL:
706 case EMR_SETDIBITSTODEVICE:
707 case EMR_STRETCHDIBITS:
708 case EMR_EXTTEXTOUTA:
709 case EMR_EXTTEXTOUTW:
710 case EMR_POLYBEZIER16:
713 case EMR_POLYBEZIERTO16:
714 case EMR_POLYLINETO16:
715 case EMR_POLYPOLYLINE16:
716 case EMR_POLYPOLYGON16:
718 case EMR_POLYTEXTOUTA:
719 case EMR_POLYTEXTOUTW:
720 case EMR_SMALLTEXTOUT:
722 case EMR_TRANSPARENTBLT:
730 /*****************************************************************************
731 * PlayEnhMetaFileRecord (GDI32.@)
733 * Render a single enhanced metafile record in the device context hdc.
736 * TRUE (non zero) on success, FALSE on error.
738 * Many unimplemented records.
739 * No error handling on record play failures (ie checking return codes)
742 * WinNT actually updates the current world transform in this function
743 * whereas Win9x does not.
745 BOOL WINAPI PlayEnhMetaFileRecord(
746 HDC hdc, /* [in] device context in which to render EMF record */
747 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
748 const ENHMETARECORD *mr, /* [in] EMF record to render */
749 UINT handles /* [in] size of handle array */
754 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
756 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
757 hdc, handletable, mr, handles);
758 if (!mr) return FALSE;
762 TRACE("record %s\n", get_emr_name(type));
771 const EMRGDICOMMENT *lpGdiComment = (const EMRGDICOMMENT *)mr;
772 /* In an enhanced metafile, there can be both public and private GDI comments */
773 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
778 const EMRSETMAPMODE *pSetMapMode = (const EMRSETMAPMODE *)mr;
780 if (info->state.mode == pSetMapMode->iMode &&
781 (info->state.mode == MM_ISOTROPIC || info->state.mode == MM_ANISOTROPIC))
783 info->state.mode = pSetMapMode->iMode;
784 EMF_SetMapMode(hdc, info);
789 const EMRSETBKMODE *pSetBkMode = (const EMRSETBKMODE *)mr;
790 SetBkMode(hdc, pSetBkMode->iMode);
795 const EMRSETBKCOLOR *pSetBkColor = (const EMRSETBKCOLOR *)mr;
796 SetBkColor(hdc, pSetBkColor->crColor);
799 case EMR_SETPOLYFILLMODE:
801 const EMRSETPOLYFILLMODE *pSetPolyFillMode = (const EMRSETPOLYFILLMODE *)mr;
802 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
807 const EMRSETROP2 *pSetROP2 = (const EMRSETROP2 *)mr;
808 SetROP2(hdc, pSetROP2->iMode);
811 case EMR_SETSTRETCHBLTMODE:
813 const EMRSETSTRETCHBLTMODE *pSetStretchBltMode = (const EMRSETSTRETCHBLTMODE *)mr;
814 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
817 case EMR_SETTEXTALIGN:
819 const EMRSETTEXTALIGN *pSetTextAlign = (const EMRSETTEXTALIGN *)mr;
820 SetTextAlign(hdc, pSetTextAlign->iMode);
823 case EMR_SETTEXTCOLOR:
825 const EMRSETTEXTCOLOR *pSetTextColor = (const EMRSETTEXTCOLOR *)mr;
826 SetTextColor(hdc, pSetTextColor->crColor);
837 const EMRRESTOREDC *pRestoreDC = (const EMRRESTOREDC *)mr;
838 TRACE("EMR_RESTORE: %d\n", pRestoreDC->iRelative);
839 if (RestoreDC( hdc, pRestoreDC->iRelative ))
840 EMF_RestoreDC( info, pRestoreDC->iRelative );
843 case EMR_INTERSECTCLIPRECT:
845 const EMRINTERSECTCLIPRECT *pClipRect = (const EMRINTERSECTCLIPRECT *)mr;
846 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
847 pClipRect->rclClip.left, pClipRect->rclClip.top,
848 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
849 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
850 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
853 case EMR_SELECTOBJECT:
855 const EMRSELECTOBJECT *pSelectObject = (const EMRSELECTOBJECT *)mr;
856 if( pSelectObject->ihObject & 0x80000000 ) {
857 /* High order bit is set - it's a stock object
858 * Strip the high bit to get the index.
859 * See MSDN article Q142319
861 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
864 /* High order bit wasn't set - not a stock object
867 (handletable->objectHandle)[pSelectObject->ihObject] );
871 case EMR_DELETEOBJECT:
873 const EMRDELETEOBJECT *pDeleteObject = (const EMRDELETEOBJECT *)mr;
874 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
875 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
878 case EMR_SETWINDOWORGEX:
880 const EMRSETWINDOWORGEX *pSetWindowOrgEx = (const EMRSETWINDOWORGEX *)mr;
882 info->state.wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
883 info->state.wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
885 TRACE("SetWindowOrgEx: %d,%d\n", info->state.wndOrgX, info->state.wndOrgY);
888 case EMR_SETWINDOWEXTEX:
890 const EMRSETWINDOWEXTEX *pSetWindowExtEx = (const EMRSETWINDOWEXTEX *)mr;
892 if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
894 info->state.wndExtX = pSetWindowExtEx->szlExtent.cx;
895 info->state.wndExtY = pSetWindowExtEx->szlExtent.cy;
896 if (info->state.mode == MM_ISOTROPIC)
897 EMF_FixIsotropic(hdc, info);
899 TRACE("SetWindowExtEx: %d,%d\n",info->state.wndExtX, info->state.wndExtY);
902 case EMR_SETVIEWPORTORGEX:
904 const EMRSETVIEWPORTORGEX *pSetViewportOrgEx = (const EMRSETVIEWPORTORGEX *)mr;
906 info->state.vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
907 info->state.vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
908 TRACE("SetViewportOrgEx: %d,%d\n", info->state.vportOrgX, info->state.vportOrgY);
911 case EMR_SETVIEWPORTEXTEX:
913 const EMRSETVIEWPORTEXTEX *pSetViewportExtEx = (const EMRSETVIEWPORTEXTEX *)mr;
915 if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
917 info->state.vportExtX = pSetViewportExtEx->szlExtent.cx;
918 info->state.vportExtY = pSetViewportExtEx->szlExtent.cy;
919 if (info->state.mode == MM_ISOTROPIC)
920 EMF_FixIsotropic(hdc, info);
921 TRACE("SetViewportExtEx: %d,%d\n", info->state.vportExtX, info->state.vportExtY);
926 const EMRCREATEPEN *pCreatePen = (const EMRCREATEPEN *)mr;
927 (handletable->objectHandle)[pCreatePen->ihPen] =
928 CreatePenIndirect(&pCreatePen->lopn);
931 case EMR_EXTCREATEPEN:
933 const EMREXTCREATEPEN *pPen = (const EMREXTCREATEPEN *)mr;
935 lb.lbStyle = pPen->elp.elpBrushStyle;
936 lb.lbColor = pPen->elp.elpColor;
937 lb.lbHatch = pPen->elp.elpHatch;
939 if(pPen->offBmi || pPen->offBits)
940 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
942 (handletable->objectHandle)[pPen->ihPen] =
943 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
944 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
947 case EMR_CREATEBRUSHINDIRECT:
949 const EMRCREATEBRUSHINDIRECT *pBrush = (const EMRCREATEBRUSHINDIRECT *)mr;
951 brush.lbStyle = pBrush->lb.lbStyle;
952 brush.lbColor = pBrush->lb.lbColor;
953 brush.lbHatch = pBrush->lb.lbHatch;
954 (handletable->objectHandle)[pBrush->ihBrush] = CreateBrushIndirect(&brush);
957 case EMR_EXTCREATEFONTINDIRECTW:
959 const EMREXTCREATEFONTINDIRECTW *pFont = (const EMREXTCREATEFONTINDIRECTW *)mr;
960 (handletable->objectHandle)[pFont->ihFont] =
961 CreateFontIndirectW(&pFont->elfw.elfLogFont);
966 const EMRMOVETOEX *pMoveToEx = (const EMRMOVETOEX *)mr;
967 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
972 const EMRLINETO *pLineTo = (const EMRLINETO *)mr;
973 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
978 const EMRRECTANGLE *pRect = (const EMRRECTANGLE *)mr;
979 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
980 pRect->rclBox.right, pRect->rclBox.bottom);
985 const EMRELLIPSE *pEllipse = (const EMRELLIPSE *)mr;
986 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
987 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
992 const EMRPOLYGON16 *pPoly = (const EMRPOLYGON16 *)mr;
993 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
994 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
995 pPoly->cpts * sizeof(POINT) );
997 for(i = 0; i < pPoly->cpts; i++)
999 pts[i].x = pPoly->apts[i].x;
1000 pts[i].y = pPoly->apts[i].y;
1002 Polygon(hdc, pts, pPoly->cpts);
1003 HeapFree( GetProcessHeap(), 0, pts );
1006 case EMR_POLYLINE16:
1008 const EMRPOLYLINE16 *pPoly = (const EMRPOLYLINE16 *)mr;
1009 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1010 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1011 pPoly->cpts * sizeof(POINT) );
1013 for(i = 0; i < pPoly->cpts; i++)
1015 pts[i].x = pPoly->apts[i].x;
1016 pts[i].y = pPoly->apts[i].y;
1018 Polyline(hdc, pts, pPoly->cpts);
1019 HeapFree( GetProcessHeap(), 0, pts );
1022 case EMR_POLYLINETO16:
1024 const EMRPOLYLINETO16 *pPoly = (const EMRPOLYLINETO16 *)mr;
1025 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1026 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1027 pPoly->cpts * sizeof(POINT) );
1029 for(i = 0; i < pPoly->cpts; i++)
1031 pts[i].x = pPoly->apts[i].x;
1032 pts[i].y = pPoly->apts[i].y;
1034 PolylineTo(hdc, pts, pPoly->cpts);
1035 HeapFree( GetProcessHeap(), 0, pts );
1038 case EMR_POLYBEZIER16:
1040 const EMRPOLYBEZIER16 *pPoly = (const EMRPOLYBEZIER16 *)mr;
1041 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1042 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1043 pPoly->cpts * sizeof(POINT) );
1045 for(i = 0; i < pPoly->cpts; i++)
1047 pts[i].x = pPoly->apts[i].x;
1048 pts[i].y = pPoly->apts[i].y;
1050 PolyBezier(hdc, pts, pPoly->cpts);
1051 HeapFree( GetProcessHeap(), 0, pts );
1054 case EMR_POLYBEZIERTO16:
1056 const EMRPOLYBEZIERTO16 *pPoly = (const EMRPOLYBEZIERTO16 *)mr;
1057 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1058 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1059 pPoly->cpts * sizeof(POINT) );
1061 for(i = 0; i < pPoly->cpts; i++)
1063 pts[i].x = pPoly->apts[i].x;
1064 pts[i].y = pPoly->apts[i].y;
1066 PolyBezierTo(hdc, pts, pPoly->cpts);
1067 HeapFree( GetProcessHeap(), 0, pts );
1070 case EMR_POLYPOLYGON16:
1072 const EMRPOLYPOLYGON16 *pPolyPoly = (const EMRPOLYPOLYGON16 *)mr;
1073 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1074 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1076 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1077 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1079 for(i = 0; i < pPolyPoly->cpts; i++)
1081 pts[i].x = pts16[i].x;
1082 pts[i].y = pts16[i].y;
1084 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1085 HeapFree( GetProcessHeap(), 0, pts );
1088 case EMR_POLYPOLYLINE16:
1090 const EMRPOLYPOLYLINE16 *pPolyPoly = (const EMRPOLYPOLYLINE16 *)mr;
1091 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1092 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1094 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1095 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1097 for(i = 0; i < pPolyPoly->cpts; i++)
1099 pts[i].x = pts16[i].x;
1100 pts[i].y = pts16[i].y;
1102 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1103 HeapFree( GetProcessHeap(), 0, pts );
1107 case EMR_STRETCHDIBITS:
1109 const EMRSTRETCHDIBITS *pStretchDIBits = (const EMRSTRETCHDIBITS *)mr;
1112 pStretchDIBits->xDest,
1113 pStretchDIBits->yDest,
1114 pStretchDIBits->cxDest,
1115 pStretchDIBits->cyDest,
1116 pStretchDIBits->xSrc,
1117 pStretchDIBits->ySrc,
1118 pStretchDIBits->cxSrc,
1119 pStretchDIBits->cySrc,
1120 (const BYTE *)mr + pStretchDIBits->offBitsSrc,
1121 (const BITMAPINFO *)((const BYTE *)mr + pStretchDIBits->offBmiSrc),
1122 pStretchDIBits->iUsageSrc,
1123 pStretchDIBits->dwRop);
1127 case EMR_EXTTEXTOUTA:
1129 const EMREXTTEXTOUTA *pExtTextOutA = (const EMREXTTEXTOUTA *)mr;
1131 const INT *dx = NULL;
1133 rc.left = pExtTextOutA->emrtext.rcl.left;
1134 rc.top = pExtTextOutA->emrtext.rcl.top;
1135 rc.right = pExtTextOutA->emrtext.rcl.right;
1136 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
1137 TRACE("EMR_EXTTEXTOUTA: x,y = %d, %d. rect = %d, %d - %d, %d. flags %08x\n",
1138 pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1139 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutA->emrtext.fOptions);
1141 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1142 * These files can be enumerated and played under Win98 just
1143 * fine, but at least Win2k chokes on them.
1145 if (pExtTextOutA->emrtext.offDx)
1146 dx = (const INT *)((const BYTE *)mr + pExtTextOutA->emrtext.offDx);
1148 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1149 pExtTextOutA->emrtext.fOptions, &rc,
1150 (LPCSTR)((const BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
1155 case EMR_EXTTEXTOUTW:
1157 const EMREXTTEXTOUTW *pExtTextOutW = (const EMREXTTEXTOUTW *)mr;
1159 const INT *dx = NULL;
1161 rc.left = pExtTextOutW->emrtext.rcl.left;
1162 rc.top = pExtTextOutW->emrtext.rcl.top;
1163 rc.right = pExtTextOutW->emrtext.rcl.right;
1164 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
1165 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %d, %d - %d, %d. flags %08x\n",
1166 pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1167 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutW->emrtext.fOptions);
1169 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1170 * These files can be enumerated and played under Win98 just
1171 * fine, but at least Win2k chokes on them.
1173 if (pExtTextOutW->emrtext.offDx)
1174 dx = (const INT *)((const BYTE *)mr + pExtTextOutW->emrtext.offDx);
1176 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1177 pExtTextOutW->emrtext.fOptions, &rc,
1178 (LPCWSTR)((const BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
1183 case EMR_CREATEPALETTE:
1185 const EMRCREATEPALETTE *lpCreatePal = (const EMRCREATEPALETTE *)mr;
1187 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
1188 CreatePalette( &lpCreatePal->lgpl );
1193 case EMR_SELECTPALETTE:
1195 const EMRSELECTPALETTE *lpSelectPal = (const EMRSELECTPALETTE *)mr;
1197 if( lpSelectPal->ihPal & 0x80000000 ) {
1198 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
1200 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
1205 case EMR_REALIZEPALETTE:
1207 RealizePalette( hdc );
1211 case EMR_EXTSELECTCLIPRGN:
1213 const EMREXTSELECTCLIPRGN *lpRgn = (const EMREXTSELECTCLIPRGN *)mr;
1216 if (mr->nSize >= sizeof(*lpRgn) + sizeof(RGNDATAHEADER))
1217 hRgn = ExtCreateRegion( &info->init_transform, 0, (RGNDATA *)lpRgn->RgnData );
1219 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
1220 /* ExtSelectClipRgn created a copy of the region */
1225 case EMR_SETMETARGN:
1231 case EMR_SETWORLDTRANSFORM:
1233 const EMRSETWORLDTRANSFORM *lpXfrm = (const EMRSETWORLDTRANSFORM *)mr;
1234 info->state.world_transform = lpXfrm->xform;
1238 case EMR_POLYBEZIER:
1240 const EMRPOLYBEZIER *lpPolyBez = (const EMRPOLYBEZIER *)mr;
1241 PolyBezier(hdc, (const POINT*)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
1247 const EMRPOLYGON *lpPoly = (const EMRPOLYGON *)mr;
1248 Polygon( hdc, (const POINT*)lpPoly->aptl, (UINT)lpPoly->cptl );
1254 const EMRPOLYLINE *lpPolyLine = (const EMRPOLYLINE *)mr;
1255 Polyline(hdc, (const POINT*)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
1259 case EMR_POLYBEZIERTO:
1261 const EMRPOLYBEZIERTO *lpPolyBezierTo = (const EMRPOLYBEZIERTO *)mr;
1262 PolyBezierTo( hdc, (const POINT*)lpPolyBezierTo->aptl,
1263 (UINT)lpPolyBezierTo->cptl );
1267 case EMR_POLYLINETO:
1269 const EMRPOLYLINETO *lpPolyLineTo = (const EMRPOLYLINETO *)mr;
1270 PolylineTo( hdc, (const POINT*)lpPolyLineTo->aptl,
1271 (UINT)lpPolyLineTo->cptl );
1275 case EMR_POLYPOLYLINE:
1277 const EMRPOLYPOLYLINE *pPolyPolyline = (const EMRPOLYPOLYLINE *)mr;
1278 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1280 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
1281 pPolyPolyline->nPolys),
1282 pPolyPolyline->aPolyCounts,
1283 pPolyPolyline->nPolys );
1288 case EMR_POLYPOLYGON:
1290 const EMRPOLYPOLYGON *pPolyPolygon = (const EMRPOLYPOLYGON *)mr;
1292 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1294 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
1295 pPolyPolygon->nPolys),
1296 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
1300 case EMR_SETBRUSHORGEX:
1302 const EMRSETBRUSHORGEX *lpSetBrushOrgEx = (const EMRSETBRUSHORGEX *)mr;
1305 (INT)lpSetBrushOrgEx->ptlOrigin.x,
1306 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1314 const EMRSETPIXELV *lpSetPixelV = (const EMRSETPIXELV *)mr;
1317 (INT)lpSetPixelV->ptlPixel.x,
1318 (INT)lpSetPixelV->ptlPixel.y,
1319 lpSetPixelV->crColor );
1324 case EMR_SETMAPPERFLAGS:
1326 const EMRSETMAPPERFLAGS *lpSetMapperFlags = (const EMRSETMAPPERFLAGS *)mr;
1328 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1333 case EMR_SETCOLORADJUSTMENT:
1335 const EMRSETCOLORADJUSTMENT *lpSetColorAdjust = (const EMRSETCOLORADJUSTMENT *)mr;
1337 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1342 case EMR_OFFSETCLIPRGN:
1344 const EMROFFSETCLIPRGN *lpOffsetClipRgn = (const EMROFFSETCLIPRGN *)mr;
1347 (INT)lpOffsetClipRgn->ptlOffset.x,
1348 (INT)lpOffsetClipRgn->ptlOffset.y );
1349 FIXME("OffsetClipRgn\n");
1354 case EMR_EXCLUDECLIPRECT:
1356 const EMREXCLUDECLIPRECT *lpExcludeClipRect = (const EMREXCLUDECLIPRECT *)mr;
1358 ExcludeClipRect( hdc,
1359 lpExcludeClipRect->rclClip.left,
1360 lpExcludeClipRect->rclClip.top,
1361 lpExcludeClipRect->rclClip.right,
1362 lpExcludeClipRect->rclClip.bottom );
1363 FIXME("ExcludeClipRect\n");
1368 case EMR_SCALEVIEWPORTEXTEX:
1370 const EMRSCALEVIEWPORTEXTEX *lpScaleViewportExtEx = (const EMRSCALEVIEWPORTEXTEX *)mr;
1372 if ((info->state.mode != MM_ISOTROPIC) && (info->state.mode != MM_ANISOTROPIC))
1374 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1375 !lpScaleViewportExtEx->yNum || !lpScaleViewportExtEx->yDenom)
1377 info->state.vportExtX = MulDiv(info->state.vportExtX, lpScaleViewportExtEx->xNum,
1378 lpScaleViewportExtEx->xDenom);
1379 info->state.vportExtY = MulDiv(info->state.vportExtY, lpScaleViewportExtEx->yNum,
1380 lpScaleViewportExtEx->yDenom);
1381 if (info->state.vportExtX == 0) info->state.vportExtX = 1;
1382 if (info->state.vportExtY == 0) info->state.vportExtY = 1;
1383 if (info->state.mode == MM_ISOTROPIC)
1384 EMF_FixIsotropic(hdc, info);
1386 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1387 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1388 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1393 case EMR_SCALEWINDOWEXTEX:
1395 const EMRSCALEWINDOWEXTEX *lpScaleWindowExtEx = (const EMRSCALEWINDOWEXTEX *)mr;
1397 if ((info->state.mode != MM_ISOTROPIC) && (info->state.mode != MM_ANISOTROPIC))
1399 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1400 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1402 info->state.wndExtX = MulDiv(info->state.wndExtX, lpScaleWindowExtEx->xNum,
1403 lpScaleWindowExtEx->xDenom);
1404 info->state.wndExtY = MulDiv(info->state.wndExtY, lpScaleWindowExtEx->yNum,
1405 lpScaleWindowExtEx->yDenom);
1406 if (info->state.wndExtX == 0) info->state.wndExtX = 1;
1407 if (info->state.wndExtY == 0) info->state.wndExtY = 1;
1408 if (info->state.mode == MM_ISOTROPIC)
1409 EMF_FixIsotropic(hdc, info);
1411 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1412 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1413 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1418 case EMR_MODIFYWORLDTRANSFORM:
1420 const EMRMODIFYWORLDTRANSFORM *lpModifyWorldTrans = (const EMRMODIFYWORLDTRANSFORM *)mr;
1422 switch(lpModifyWorldTrans->iMode) {
1424 info->state.world_transform.eM11 = info->state.world_transform.eM22 = 1;
1425 info->state.world_transform.eM12 = info->state.world_transform.eM21 = 0;
1426 info->state.world_transform.eDx = info->state.world_transform.eDy = 0;
1428 case MWT_LEFTMULTIPLY:
1429 CombineTransform(&info->state.world_transform, &lpModifyWorldTrans->xform,
1430 &info->state.world_transform);
1432 case MWT_RIGHTMULTIPLY:
1433 CombineTransform(&info->state.world_transform, &info->state.world_transform,
1434 &lpModifyWorldTrans->xform);
1437 FIXME("Unknown imode %d\n", lpModifyWorldTrans->iMode);
1445 const EMRANGLEARC *lpAngleArc = (const EMRANGLEARC *)mr;
1448 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1449 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1450 lpAngleArc->eSweepAngle );
1457 const EMRROUNDRECT *lpRoundRect = (const EMRROUNDRECT *)mr;
1460 lpRoundRect->rclBox.left,
1461 lpRoundRect->rclBox.top,
1462 lpRoundRect->rclBox.right,
1463 lpRoundRect->rclBox.bottom,
1464 lpRoundRect->szlCorner.cx,
1465 lpRoundRect->szlCorner.cy );
1472 const EMRARC *lpArc = (const EMRARC *)mr;
1475 (INT)lpArc->rclBox.left,
1476 (INT)lpArc->rclBox.top,
1477 (INT)lpArc->rclBox.right,
1478 (INT)lpArc->rclBox.bottom,
1479 (INT)lpArc->ptlStart.x,
1480 (INT)lpArc->ptlStart.y,
1481 (INT)lpArc->ptlEnd.x,
1482 (INT)lpArc->ptlEnd.y );
1489 const EMRCHORD *lpChord = (const EMRCHORD *)mr;
1492 (INT)lpChord->rclBox.left,
1493 (INT)lpChord->rclBox.top,
1494 (INT)lpChord->rclBox.right,
1495 (INT)lpChord->rclBox.bottom,
1496 (INT)lpChord->ptlStart.x,
1497 (INT)lpChord->ptlStart.y,
1498 (INT)lpChord->ptlEnd.x,
1499 (INT)lpChord->ptlEnd.y );
1506 const EMRPIE *lpPie = (const EMRPIE *)mr;
1509 (INT)lpPie->rclBox.left,
1510 (INT)lpPie->rclBox.top,
1511 (INT)lpPie->rclBox.right,
1512 (INT)lpPie->rclBox.bottom,
1513 (INT)lpPie->ptlStart.x,
1514 (INT)lpPie->ptlStart.y,
1515 (INT)lpPie->ptlEnd.x,
1516 (INT)lpPie->ptlEnd.y );
1523 const EMRARC *lpArcTo = (const EMRARC *)mr;
1526 (INT)lpArcTo->rclBox.left,
1527 (INT)lpArcTo->rclBox.top,
1528 (INT)lpArcTo->rclBox.right,
1529 (INT)lpArcTo->rclBox.bottom,
1530 (INT)lpArcTo->ptlStart.x,
1531 (INT)lpArcTo->ptlStart.y,
1532 (INT)lpArcTo->ptlEnd.x,
1533 (INT)lpArcTo->ptlEnd.y );
1538 case EMR_EXTFLOODFILL:
1540 const EMREXTFLOODFILL *lpExtFloodFill = (const EMREXTFLOODFILL *)mr;
1543 (INT)lpExtFloodFill->ptlStart.x,
1544 (INT)lpExtFloodFill->ptlStart.y,
1545 lpExtFloodFill->crColor,
1546 (UINT)lpExtFloodFill->iMode );
1553 const EMRPOLYDRAW *lpPolyDraw = (const EMRPOLYDRAW *)mr;
1555 (const POINT*)lpPolyDraw->aptl,
1556 lpPolyDraw->abTypes,
1557 (INT)lpPolyDraw->cptl );
1562 case EMR_SETARCDIRECTION:
1564 const EMRSETARCDIRECTION *lpSetArcDirection = (const EMRSETARCDIRECTION *)mr;
1565 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1569 case EMR_SETMITERLIMIT:
1571 const EMRSETMITERLIMIT *lpSetMiterLimit = (const EMRSETMITERLIMIT *)mr;
1572 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1588 case EMR_CLOSEFIGURE:
1596 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1601 case EMR_STROKEANDFILLPATH:
1603 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1604 StrokeAndFillPath( hdc );
1608 case EMR_STROKEPATH:
1610 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1615 case EMR_FLATTENPATH:
1627 case EMR_SELECTCLIPPATH:
1629 const EMRSELECTCLIPPATH *lpSelectClipPath = (const EMRSELECTCLIPPATH *)mr;
1630 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1640 case EMR_CREATECOLORSPACE:
1642 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1643 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1644 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1648 case EMR_SETCOLORSPACE:
1650 const EMRSETCOLORSPACE *lpSetColorSpace = (const EMRSETCOLORSPACE *)mr;
1652 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1656 case EMR_DELETECOLORSPACE:
1658 const EMRDELETECOLORSPACE *lpDeleteColorSpace = (const EMRDELETECOLORSPACE *)mr;
1659 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1663 case EMR_SETICMMODE:
1665 const EMRSETICMMODE *lpSetICMMode = (const EMRSETICMMODE *)mr;
1666 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1670 case EMR_PIXELFORMAT:
1673 const EMRPIXELFORMAT *lpPixelFormat = (const EMRPIXELFORMAT *)mr;
1675 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1676 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1681 case EMR_SETPALETTEENTRIES:
1683 const EMRSETPALETTEENTRIES *lpSetPaletteEntries = (const EMRSETPALETTEENTRIES *)mr;
1685 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1686 (UINT)lpSetPaletteEntries->iStart,
1687 (UINT)lpSetPaletteEntries->cEntries,
1688 lpSetPaletteEntries->aPalEntries );
1693 case EMR_RESIZEPALETTE:
1695 const EMRRESIZEPALETTE *lpResizePalette = (const EMRRESIZEPALETTE *)mr;
1697 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1698 (UINT)lpResizePalette->cEntries );
1703 case EMR_CREATEDIBPATTERNBRUSHPT:
1705 const EMRCREATEDIBPATTERNBRUSHPT *lpCreate = (const EMRCREATEDIBPATTERNBRUSHPT *)mr;
1706 LPVOID lpPackedStruct;
1708 /* Check that offsets and data are contained within the record
1709 * (including checking for wrap-arounds).
1711 if ( lpCreate->offBmi + lpCreate->cbBmi > mr->nSize
1712 || lpCreate->offBits + lpCreate->cbBits > mr->nSize
1713 || lpCreate->offBmi + lpCreate->cbBmi < lpCreate->offBmi
1714 || lpCreate->offBits + lpCreate->cbBits < lpCreate->offBits )
1716 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1720 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1721 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1722 lpCreate->cbBmi + lpCreate->cbBits );
1725 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1729 /* Now pack this structure */
1730 memcpy( lpPackedStruct,
1731 ((const BYTE *)lpCreate) + lpCreate->offBmi,
1733 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1734 ((const BYTE *)lpCreate) + lpCreate->offBits,
1737 (handletable->objectHandle)[lpCreate->ihBrush] =
1738 CreateDIBPatternBrushPt( lpPackedStruct,
1739 (UINT)lpCreate->iUsage );
1741 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1745 case EMR_CREATEMONOBRUSH:
1747 const EMRCREATEMONOBRUSH *pCreateMonoBrush = (const EMRCREATEMONOBRUSH *)mr;
1748 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pCreateMonoBrush->offBmi);
1751 /* Need to check if the bitmap is monochrome, and if the
1752 two colors are really black and white */
1753 if (pCreateMonoBrush->iUsage == DIB_PAL_MONO)
1757 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1758 * aligned to 32 rather than 16 bits.
1761 bm.bmWidth = pbi->bmiHeader.biWidth;
1762 bm.bmHeight = abs(pbi->bmiHeader.biHeight);
1763 bm.bmWidthBytes = 4 * ((pbi->bmiHeader.biWidth + 31) / 32);
1764 bm.bmPlanes = pbi->bmiHeader.biPlanes;
1765 bm.bmBitsPixel = pbi->bmiHeader.biBitCount;
1766 bm.bmBits = (BYTE *)mr + pCreateMonoBrush->offBits;
1767 hBmp = CreateBitmapIndirect(&bm);
1769 else if (is_dib_monochrome(pbi))
1771 /* Top-down DIBs have a negative height */
1772 LONG height = pbi->bmiHeader.biHeight;
1774 hBmp = CreateBitmap(pbi->bmiHeader.biWidth, abs(height), 1, 1, NULL);
1775 SetDIBits(hdc, hBmp, 0, pbi->bmiHeader.biHeight,
1776 (const BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1780 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1781 (const BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1784 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1786 /* CreatePatternBrush created a copy of the bitmap */
1793 const EMRBITBLT *pBitBlt = (const EMRBITBLT *)mr;
1795 if(pBitBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1796 PatBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1798 } else { /* BitBlt */
1799 HDC hdcSrc = CreateCompatibleDC(hdc);
1800 HBRUSH hBrush, hBrushOld;
1801 HBITMAP hBmp = 0, hBmpOld = 0;
1802 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pBitBlt->offBmiSrc);
1804 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1806 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1807 hBrushOld = SelectObject(hdcSrc, hBrush);
1808 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1809 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1810 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1811 SelectObject(hdcSrc, hBrushOld);
1812 DeleteObject(hBrush);
1814 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1815 (const BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1816 hBmpOld = SelectObject(hdcSrc, hBmp);
1818 BitBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1819 hdcSrc, pBitBlt->xSrc, pBitBlt->ySrc, pBitBlt->dwRop);
1821 SelectObject(hdcSrc, hBmpOld);
1828 case EMR_STRETCHBLT:
1830 const EMRSTRETCHBLT *pStretchBlt = (const EMRSTRETCHBLT *)mr;
1832 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1833 pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1834 pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1835 pStretchBlt->dwRop, pStretchBlt->offBitsSrc);
1837 if(pStretchBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1838 PatBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1839 pStretchBlt->dwRop);
1840 } else { /* StretchBlt */
1841 HDC hdcSrc = CreateCompatibleDC(hdc);
1842 HBRUSH hBrush, hBrushOld;
1843 HBITMAP hBmp = 0, hBmpOld = 0;
1844 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pStretchBlt->offBmiSrc);
1846 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1848 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1849 hBrushOld = SelectObject(hdcSrc, hBrush);
1850 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1851 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1852 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1853 SelectObject(hdcSrc, hBrushOld);
1854 DeleteObject(hBrush);
1856 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1857 (const BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1858 hBmpOld = SelectObject(hdcSrc, hBmp);
1860 StretchBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1861 hdcSrc, pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1862 pStretchBlt->dwRop);
1864 SelectObject(hdcSrc, hBmpOld);
1871 case EMR_ALPHABLEND:
1873 const EMRALPHABLEND *pAlphaBlend = (const EMRALPHABLEND *)mr;
1875 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1876 pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1877 pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1878 pAlphaBlend->dwRop, pAlphaBlend->offBitsSrc);
1880 if(pAlphaBlend->offBmiSrc == 0) {
1881 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1883 HDC hdcSrc = CreateCompatibleDC(hdc);
1884 HBITMAP hBmp = 0, hBmpOld = 0;
1885 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pAlphaBlend->offBmiSrc);
1886 BLENDFUNCTION blendfn;
1889 SetWorldTransform(hdcSrc, &pAlphaBlend->xformSrc);
1891 hBmp = CreateDIBSection(hdc, pbi, pAlphaBlend->iUsageSrc, &bits, NULL, 0);
1892 memcpy(bits, (const BYTE *)mr + pAlphaBlend->offBitsSrc, pAlphaBlend->cbBitsSrc);
1893 hBmpOld = SelectObject(hdcSrc, hBmp);
1895 blendfn.BlendOp = (pAlphaBlend->dwRop >> 24) & 0xff;
1896 blendfn.BlendFlags = (pAlphaBlend->dwRop >> 16) & 0xff;
1897 blendfn.SourceConstantAlpha = (pAlphaBlend->dwRop >> 8) & 0xff;
1898 blendfn.AlphaFormat = (pAlphaBlend->dwRop) & 0xff;
1900 GdiAlphaBlend(hdc, pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1901 hdcSrc, pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1904 SelectObject(hdcSrc, hBmpOld);
1913 const EMRMASKBLT *pMaskBlt = (const EMRMASKBLT *)mr;
1914 HDC hdcSrc = CreateCompatibleDC(hdc);
1915 HBRUSH hBrush, hBrushOld;
1916 HBITMAP hBmp, hBmpOld, hBmpMask;
1917 const BITMAPINFO *pbi;
1919 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1921 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1922 hBrushOld = SelectObject(hdcSrc, hBrush);
1923 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1924 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1925 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1926 SelectObject(hdcSrc, hBrushOld);
1927 DeleteObject(hBrush);
1929 pbi = (const BITMAPINFO *)((const BYTE *)mr + pMaskBlt->offBmiMask);
1930 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1932 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1933 (const BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1935 pbi = (const BITMAPINFO *)((const BYTE *)mr + pMaskBlt->offBmiSrc);
1936 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1937 (const BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1938 hBmpOld = SelectObject(hdcSrc, hBmp);
1951 SelectObject(hdcSrc, hBmpOld);
1953 DeleteObject(hBmpMask);
1960 const EMRPLGBLT *pPlgBlt = (const EMRPLGBLT *)mr;
1961 HDC hdcSrc = CreateCompatibleDC(hdc);
1962 HBRUSH hBrush, hBrushOld;
1963 HBITMAP hBmp, hBmpOld, hBmpMask;
1964 const BITMAPINFO *pbi;
1967 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1969 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1970 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1971 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1973 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1974 hBrushOld = SelectObject(hdcSrc, hBrush);
1975 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1976 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1977 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1978 SelectObject(hdcSrc, hBrushOld);
1979 DeleteObject(hBrush);
1981 pbi = (const BITMAPINFO *)((const BYTE *)mr + pPlgBlt->offBmiMask);
1982 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1984 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1985 (const BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1987 pbi = (const BITMAPINFO *)((const BYTE *)mr + pPlgBlt->offBmiSrc);
1988 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1989 (const BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1990 hBmpOld = SelectObject(hdcSrc, hBmp);
2001 SelectObject(hdcSrc, hBmpOld);
2003 DeleteObject(hBmpMask);
2008 case EMR_SETDIBITSTODEVICE:
2010 const EMRSETDIBITSTODEVICE *pSetDIBitsToDevice = (const EMRSETDIBITSTODEVICE *)mr;
2012 SetDIBitsToDevice(hdc,
2013 pSetDIBitsToDevice->xDest,
2014 pSetDIBitsToDevice->yDest,
2015 pSetDIBitsToDevice->cxSrc,
2016 pSetDIBitsToDevice->cySrc,
2017 pSetDIBitsToDevice->xSrc,
2018 pSetDIBitsToDevice->ySrc,
2019 pSetDIBitsToDevice->iStartScan,
2020 pSetDIBitsToDevice->cScans,
2021 (const BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
2022 (const BITMAPINFO *)((const BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
2023 pSetDIBitsToDevice->iUsageSrc);
2027 case EMR_POLYTEXTOUTA:
2029 const EMRPOLYTEXTOUTA *pPolyTextOutA = (const EMRPOLYTEXTOUTA *)mr;
2030 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
2032 XFORM xform, xformOld;
2035 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
2036 GetWorldTransform(hdc, &xformOld);
2038 xform.eM11 = pPolyTextOutA->exScale;
2041 xform.eM22 = pPolyTextOutA->eyScale;
2044 SetWorldTransform(hdc, &xform);
2046 /* Set up POLYTEXTA structures */
2047 for(i = 0; i < pPolyTextOutA->cStrings; i++)
2049 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
2050 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
2051 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
2052 polytextA[i].lpstr = (LPCSTR)((const BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
2053 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
2054 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
2055 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
2056 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
2057 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
2058 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
2060 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
2061 HeapFree(GetProcessHeap(), 0, polytextA);
2063 SetWorldTransform(hdc, &xformOld);
2064 SetGraphicsMode(hdc, gModeOld);
2068 case EMR_POLYTEXTOUTW:
2070 const EMRPOLYTEXTOUTW *pPolyTextOutW = (const EMRPOLYTEXTOUTW *)mr;
2071 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
2073 XFORM xform, xformOld;
2076 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
2077 GetWorldTransform(hdc, &xformOld);
2079 xform.eM11 = pPolyTextOutW->exScale;
2082 xform.eM22 = pPolyTextOutW->eyScale;
2085 SetWorldTransform(hdc, &xform);
2087 /* Set up POLYTEXTW structures */
2088 for(i = 0; i < pPolyTextOutW->cStrings; i++)
2090 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
2091 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
2092 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
2093 polytextW[i].lpstr = (LPCWSTR)((const BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
2094 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
2095 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
2096 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
2097 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
2098 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
2099 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
2101 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
2102 HeapFree(GetProcessHeap(), 0, polytextW);
2104 SetWorldTransform(hdc, &xformOld);
2105 SetGraphicsMode(hdc, gModeOld);
2111 const EMRFILLRGN *pFillRgn = (const EMRFILLRGN *)mr;
2112 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
2115 (handletable->objectHandle)[pFillRgn->ihBrush]);
2122 const EMRFRAMERGN *pFrameRgn = (const EMRFRAMERGN *)mr;
2123 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
2126 (handletable->objectHandle)[pFrameRgn->ihBrush],
2127 pFrameRgn->szlStroke.cx,
2128 pFrameRgn->szlStroke.cy);
2135 const EMRINVERTRGN *pInvertRgn = (const EMRINVERTRGN *)mr;
2136 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
2137 InvertRgn(hdc, hRgn);
2144 const EMRPAINTRGN *pPaintRgn = (const EMRPAINTRGN *)mr;
2145 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
2146 PaintRgn(hdc, hRgn);
2151 case EMR_SETTEXTJUSTIFICATION:
2153 const EMRSETTEXTJUSTIFICATION *pSetTextJust = (const EMRSETTEXTJUSTIFICATION *)mr;
2154 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
2160 const EMRSETLAYOUT *pSetLayout = (const EMRSETLAYOUT *)mr;
2161 SetLayout(hdc, pSetLayout->iMode);
2165 case EMR_POLYDRAW16:
2167 case EMR_GLSBOUNDEDRECORD:
2168 case EMR_DRAWESCAPE :
2171 case EMR_SMALLTEXTOUT:
2172 case EMR_FORCEUFIMAPPING:
2173 case EMR_NAMEDESCAPE:
2174 case EMR_COLORCORRECTPALETTE:
2175 case EMR_SETICMPROFILEA:
2176 case EMR_SETICMPROFILEW:
2177 case EMR_TRANSPARENTBLT:
2178 case EMR_GRADIENTFILL:
2179 case EMR_SETLINKEDUFI:
2180 case EMR_COLORMATCHTOTARGETW:
2181 case EMR_CREATECOLORSPACEW:
2184 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2185 record then ignore and return TRUE. */
2186 FIXME("type %d is unimplemented\n", type);
2189 tmprc.left = tmprc.top = 0;
2190 tmprc.right = tmprc.bottom = 1000;
2191 LPtoDP(hdc, (POINT*)&tmprc, 2);
2192 TRACE("L:0,0 - 1000,1000 -> D:%d,%d - %d,%d\n", tmprc.left,
2193 tmprc.top, tmprc.right, tmprc.bottom);
2199 /*****************************************************************************
2201 * EnumEnhMetaFile (GDI32.@)
2203 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2205 * record. Returns when either every record has been used or
2206 * when _EnhMetaFunc_ returns FALSE.
2210 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2217 * This function behaves differently in Win9x and WinNT.
2219 * In WinNT, the DC's world transform is updated as the EMF changes
2220 * the Window/Viewport Extent and Origin or it's world transform.
2221 * The actual Window/Viewport Extent and Origin are left untouched.
2223 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2224 * updates the scaling itself but only just before a record that
2225 * writes anything to the DC.
2227 * I'm not sure where the data (enum_emh_data) is stored in either
2228 * version. For this implementation, it is stored before the handle
2229 * table, but it could be stored in the DC, in the EMF handle or in
2233 BOOL WINAPI EnumEnhMetaFile(
2234 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
2235 HENHMETAFILE hmf, /* [in] EMF to walk */
2236 ENHMFENUMPROC callback, /* [in] callback function */
2237 LPVOID data, /* [in] optional data for callback function */
2238 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
2250 HBRUSH hBrush = NULL;
2253 enum_emh_data *info;
2254 SIZE vp_size, win_size;
2255 POINT vp_org, win_org;
2256 INT mapMode = MM_TEXT, old_align = 0, old_rop2 = 0, old_arcdir = 0, old_polyfill = 0, old_stretchblt = 0;
2257 COLORREF old_text_color = 0, old_bk_color = 0;
2261 SetLastError(ERROR_INVALID_PARAMETER);
2265 emh = EMF_GetEnhMetaHeader(hmf);
2267 SetLastError(ERROR_INVALID_HANDLE);
2271 info = HeapAlloc( GetProcessHeap(), 0,
2272 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
2275 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2278 info->state.wndOrgX = 0;
2279 info->state.wndOrgY = 0;
2280 info->state.wndExtX = 1;
2281 info->state.wndExtY = 1;
2282 info->state.vportOrgX = 0;
2283 info->state.vportOrgY = 0;
2284 info->state.vportExtX = 1;
2285 info->state.vportExtY = 1;
2286 info->state.world_transform.eM11 = info->state.world_transform.eM22 = 1;
2287 info->state.world_transform.eM12 = info->state.world_transform.eM21 = 0;
2288 info->state.world_transform.eDx = info->state.world_transform.eDy = 0;
2290 info->state.next = NULL;
2291 info->save_level = 0;
2292 info->saved_state = NULL;
2294 ht = (HANDLETABLE*) &info[1];
2295 ht->objectHandle[0] = hmf;
2296 for(i = 1; i < emh->nHandles; i++)
2297 ht->objectHandle[i] = NULL;
2301 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
2302 GetWorldTransform(hdc, &savedXform);
2303 GetViewportExtEx(hdc, &vp_size);
2304 GetWindowExtEx(hdc, &win_size);
2305 GetViewportOrgEx(hdc, &vp_org);
2306 GetWindowOrgEx(hdc, &win_org);
2307 mapMode = GetMapMode(hdc);
2310 hPen = GetCurrentObject(hdc, OBJ_PEN);
2311 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
2312 hFont = GetCurrentObject(hdc, OBJ_FONT);
2314 hRgn = CreateRectRgn(0, 0, 0, 0);
2315 if (!GetClipRgn(hdc, hRgn))
2321 old_text_color = SetTextColor(hdc, RGB(0,0,0));
2322 old_bk_color = SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
2323 old_align = SetTextAlign(hdc, 0);
2324 old_rop2 = SetROP2(hdc, R2_COPYPEN);
2325 old_arcdir = SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
2326 old_polyfill = SetPolyFillMode(hdc, ALTERNATE);
2327 old_stretchblt = SetStretchBltMode(hdc, BLACKONWHITE);
2330 info->state.mode = MM_TEXT;
2334 /* Win95 leaves the vp/win ext/org info alone */
2335 info->init_transform.eM11 = 1.0;
2336 info->init_transform.eM12 = 0.0;
2337 info->init_transform.eM21 = 0.0;
2338 info->init_transform.eM22 = 1.0;
2339 info->init_transform.eDx = 0.0;
2340 info->init_transform.eDy = 0.0;
2344 /* WinNT combines the vp/win ext/org info into a transform */
2345 double xscale, yscale;
2346 xscale = (double)vp_size.cx / (double)win_size.cx;
2347 yscale = (double)vp_size.cy / (double)win_size.cy;
2348 info->init_transform.eM11 = xscale;
2349 info->init_transform.eM12 = 0.0;
2350 info->init_transform.eM21 = 0.0;
2351 info->init_transform.eM22 = yscale;
2352 info->init_transform.eDx = (double)vp_org.x - xscale * (double)win_org.x;
2353 info->init_transform.eDy = (double)vp_org.y - yscale * (double)win_org.y;
2355 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
2358 if ( lpRect && WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
2360 double xSrcPixSize, ySrcPixSize, xscale, yscale;
2363 TRACE("rect: %d,%d - %d,%d. rclFrame: %d,%d - %d,%d\n",
2364 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
2365 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
2366 emh->rclFrame.bottom);
2368 xSrcPixSize = (double) emh->szlMillimeters.cx / emh->szlDevice.cx;
2369 ySrcPixSize = (double) emh->szlMillimeters.cy / emh->szlDevice.cy;
2370 xscale = (double) WIDTH(*lpRect) * 100.0 /
2371 WIDTH(emh->rclFrame) * xSrcPixSize;
2372 yscale = (double) HEIGHT(*lpRect) * 100.0 /
2373 HEIGHT(emh->rclFrame) * ySrcPixSize;
2374 TRACE("xscale = %f, yscale = %f\n", xscale, yscale);
2376 xform.eM11 = xscale;
2379 xform.eM22 = yscale;
2380 xform.eDx = (double) lpRect->left - (double) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
2381 xform.eDy = (double) lpRect->top - (double) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
2383 CombineTransform(&info->init_transform, &xform, &info->init_transform);
2386 /* WinNT resets the current vp/win org/ext */
2387 if ( !IS_WIN9X() && hdc )
2389 SetMapMode(hdc, MM_TEXT);
2390 SetWindowOrgEx(hdc, 0, 0, NULL);
2391 SetViewportOrgEx(hdc, 0, 0, NULL);
2392 EMF_Update_MF_Xform(hdc, info);
2397 while(ret && offset < emh->nBytes)
2399 emr = (ENHMETARECORD *)((char *)emh + offset);
2401 /* In Win9x mode we update the xform if the record will produce output */
2402 if (hdc && IS_WIN9X() && emr_produces_output(emr->iType))
2403 EMF_Update_MF_Xform(hdc, info);
2405 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr->iType), emr->nSize);
2406 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2407 offset += emr->nSize;
2409 /* WinNT - update the transform (win9x updates when the next graphics
2410 output record is played). */
2411 if (hdc && !IS_WIN9X())
2412 EMF_Update_MF_Xform(hdc, info);
2417 SetStretchBltMode(hdc, old_stretchblt);
2418 SetPolyFillMode(hdc, old_polyfill);
2419 SetArcDirection(hdc, old_arcdir);
2420 SetROP2(hdc, old_rop2);
2421 SetTextAlign(hdc, old_align);
2422 SetBkColor(hdc, old_bk_color);
2423 SetTextColor(hdc, old_text_color);
2426 SelectObject(hdc, hBrush);
2427 SelectObject(hdc, hPen);
2428 SelectObject(hdc, hFont);
2429 ExtSelectClipRgn(hdc, hRgn, RGN_COPY);
2432 SetWorldTransform(hdc, &savedXform);
2434 SetGraphicsMode(hdc, savedMode);
2435 SetMapMode(hdc, mapMode);
2436 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2437 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2438 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2439 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2442 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2443 if( (ht->objectHandle)[i] )
2444 DeleteObject( (ht->objectHandle)[i] );
2446 while (info->saved_state)
2448 EMF_dc_state *state = info->saved_state;
2449 info->saved_state = info->saved_state->next;
2450 HeapFree( GetProcessHeap(), 0, state );
2452 HeapFree( GetProcessHeap(), 0, info );
2456 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2457 const ENHMETARECORD *emr,
2458 INT handles, LPARAM data)
2460 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2463 /**************************************************************************
2464 * PlayEnhMetaFile (GDI32.@)
2466 * Renders an enhanced metafile into a specified rectangle *lpRect
2467 * in device context hdc.
2473 BOOL WINAPI PlayEnhMetaFile(
2474 HDC hdc, /* [in] DC to render into */
2475 HENHMETAFILE hmf, /* [in] metafile to render */
2476 const RECT *lpRect /* [in] rectangle to place metafile inside */
2479 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2483 /*****************************************************************************
2484 * DeleteEnhMetaFile (GDI32.@)
2486 * Deletes an enhanced metafile and frees the associated storage.
2488 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2490 return EMF_Delete_HENHMETAFILE( hmf );
2493 /*****************************************************************************
2494 * CopyEnhMetaFileA (GDI32.@)
2496 * Duplicate an enhanced metafile.
2500 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2501 HENHMETAFILE hmfSrc,
2504 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2505 HENHMETAFILE hmfDst;
2507 if(!emrSrc) return FALSE;
2509 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2510 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2511 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2515 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2516 NULL, CREATE_ALWAYS, 0, 0);
2517 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2518 CloseHandle( hFile );
2519 /* Reopen file for reading only, so that apps can share
2520 read access to the file while hmf is still valid */
2521 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2522 NULL, OPEN_EXISTING, 0, 0);
2523 if(hFile == INVALID_HANDLE_VALUE) {
2524 ERR("Can't reopen emf for reading\n");
2527 hmfDst = EMF_GetEnhMetaFile( hFile );
2528 CloseHandle( hFile );
2533 /*****************************************************************************
2534 * CopyEnhMetaFileW (GDI32.@)
2536 * See CopyEnhMetaFileA.
2540 HENHMETAFILE WINAPI CopyEnhMetaFileW(
2541 HENHMETAFILE hmfSrc,
2544 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2545 HENHMETAFILE hmfDst;
2547 if(!emrSrc) return FALSE;
2549 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2550 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2551 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2555 hFile = CreateFileW( file, GENERIC_WRITE | GENERIC_READ, 0,
2556 NULL, CREATE_ALWAYS, 0, 0);
2557 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2558 CloseHandle( hFile );
2559 /* Reopen file for reading only, so that apps can share
2560 read access to the file while hmf is still valid */
2561 hFile = CreateFileW( file, GENERIC_READ, FILE_SHARE_READ,
2562 NULL, OPEN_EXISTING, 0, 0);
2563 if(hFile == INVALID_HANDLE_VALUE) {
2564 ERR("Can't reopen emf for reading\n");
2567 hmfDst = EMF_GetEnhMetaFile( hFile );
2568 CloseHandle( hFile );
2574 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2575 typedef struct tagEMF_PaletteCopy
2578 LPPALETTEENTRY lpPe;
2581 /***************************************************************
2582 * Find the EMR_EOF record and then use it to find the
2583 * palette entries for this enhanced metafile.
2584 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2585 * which contains the max number of elements to copy and where
2588 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2590 static INT CALLBACK cbEnhPaletteCopy( HDC a,
2592 const ENHMETARECORD *lpEMR,
2597 if ( lpEMR->iType == EMR_EOF )
2599 const EMREOF *lpEof = (const EMREOF *)lpEMR;
2600 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2601 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2603 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy );
2605 memcpy( info->lpPe, (LPCSTR)lpEof + lpEof->offPalEntries,
2606 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2608 /* Update the passed data as a return code */
2609 info->lpPe = NULL; /* Palettes were copied! */
2610 info->cEntries = dwNumPalToCopy;
2612 return FALSE; /* That's all we need */
2618 /*****************************************************************************
2619 * GetEnhMetaFilePaletteEntries (GDI32.@)
2621 * Copy the palette and report size
2623 * BUGS: Error codes (SetLastError) are not set on failures
2625 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2627 LPPALETTEENTRY lpPe )
2629 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2630 EMF_PaletteCopy infoForCallBack;
2632 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2634 if (!enhHeader) return 0;
2636 /* First check if there are any palettes associated with
2638 if ( enhHeader->nPalEntries == 0 ) return 0;
2640 /* Is the user requesting the number of palettes? */
2641 if ( lpPe == NULL ) return enhHeader->nPalEntries;
2643 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2644 infoForCallBack.cEntries = cEntries;
2645 infoForCallBack.lpPe = lpPe;
2647 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2648 &infoForCallBack, 0 ) )
2651 /* Verify that the callback executed correctly */
2652 if ( infoForCallBack.lpPe != NULL )
2654 /* Callback proc had error! */
2655 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2659 return infoForCallBack.cEntries;
2662 typedef struct gdi_mf_comment
2669 DWORD cbWinMetaFile;
2672 /******************************************************************
2673 * SetWinMetaFileBits (GDI32.@)
2675 * Translate from old style to new style.
2678 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2679 CONST BYTE *lpbBuffer,
2681 CONST METAFILEPICT *lpmfp
2684 static const WCHAR szDisplayW[] = { 'D','I','S','P','L','A','Y','\0' };
2685 HMETAFILE hmf = NULL;
2686 HENHMETAFILE ret = NULL;
2687 HDC hdc = NULL, hdcdisp = NULL;
2688 RECT rc, *prcFrame = NULL;
2689 LONG mm, xExt, yExt;
2690 INT horzsize, vertsize, horzres, vertres;
2692 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2694 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2697 WARN("SetMetaFileBitsEx failed\n");
2702 hdcRef = hdcdisp = CreateDCW(szDisplayW, NULL, NULL, NULL);
2706 TRACE("mm = %d %dx%d\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2714 TRACE("lpmfp == NULL\n");
2716 /* Use the whole device surface */
2717 mm = MM_ANISOTROPIC;
2722 if (mm == MM_ISOTROPIC || mm == MM_ANISOTROPIC)
2724 if (xExt < 0 || yExt < 0)
2726 /* Use the whole device surface */
2731 /* Use the x and y extents as the frame box */
2734 rc.left = rc.top = 0;
2741 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL)))
2743 ERR("CreateEnhMetaFile failed\n");
2748 * Write the original METAFILE into the enhanced metafile.
2749 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2753 gdi_mf_comment *mfcomment;
2754 UINT mfcomment_size;
2756 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2757 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2760 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2761 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2762 mfcomment->nVersion = 0x00000300;
2763 mfcomment->nChecksum = 0; /* FIXME */
2764 mfcomment->fFlags = 0;
2765 mfcomment->cbWinMetaFile = cbBuffer;
2766 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2767 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2768 HeapFree(GetProcessHeap(), 0, mfcomment);
2770 SetMapMode(hdc, mm);
2774 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2775 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2776 horzres = GetDeviceCaps(hdcRef, HORZRES);
2777 vertres = GetDeviceCaps(hdcRef, VERTRES);
2781 /* Use the whole device surface */
2787 xExt = MulDiv(xExt, horzres, 100 * horzsize);
2788 yExt = MulDiv(yExt, vertres, 100 * vertsize);
2791 /* set the initial viewport:window ratio as 1:1 */
2792 SetViewportExtEx(hdc, xExt, yExt, NULL);
2793 SetWindowExtEx(hdc, xExt, yExt, NULL);
2795 PlayMetaFile(hdc, hmf);
2797 ret = CloseEnhMetaFile(hdc);
2799 if (hdcdisp) DeleteDC(hdcdisp);
2800 DeleteMetaFile(hmf);