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 || emh->dSignature != ENHMETA_SIGNATURE ||
256 (emh->nBytes & 3)) /* refuse to load unaligned EMF as Windows does */
258 WARN("Invalid emf header type 0x%08x sig 0x%08x.\n",
259 emh->iType, emh->dSignature);
260 SetLastError(ERROR_INVALID_DATA);
264 if (!(metaObj = HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj) ))) return 0;
267 metaObj->on_disk = on_disk;
269 if (!(hmf = alloc_gdi_handle( &metaObj->header, OBJ_ENHMETAFILE, NULL )))
270 HeapFree( GetProcessHeap(), 0, metaObj );
274 /****************************************************************************
275 * EMF_Delete_HENHMETAFILE
277 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
279 ENHMETAFILEOBJ *metaObj = free_gdi_handle( hmf );
281 if(!metaObj) return FALSE;
284 UnmapViewOfFile( metaObj->emh );
286 HeapFree( GetProcessHeap(), 0, metaObj->emh );
287 return HeapFree( GetProcessHeap(), 0, metaObj );
290 /******************************************************************
291 * EMF_GetEnhMetaHeader
293 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
295 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
297 ENHMETAHEADER *ret = NULL;
298 ENHMETAFILEOBJ *metaObj = GDI_GetObjPtr( hmf, OBJ_ENHMETAFILE );
299 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
303 GDI_ReleaseObj( hmf );
308 /*****************************************************************************
312 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
318 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
319 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
320 CloseHandle( hMapping );
324 hemf = EMF_Create_HENHMETAFILE( emh, TRUE );
326 UnmapViewOfFile( emh );
331 /*****************************************************************************
332 * GetEnhMetaFileA (GDI32.@)
336 HENHMETAFILE WINAPI GetEnhMetaFileA(
337 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
343 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
344 OPEN_EXISTING, 0, 0);
345 if (hFile == INVALID_HANDLE_VALUE) {
346 WARN("could not open %s\n", lpszMetaFile);
349 hmf = EMF_GetEnhMetaFile( hFile );
350 CloseHandle( hFile );
354 /*****************************************************************************
355 * GetEnhMetaFileW (GDI32.@)
357 HENHMETAFILE WINAPI GetEnhMetaFileW(
358 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
363 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
364 OPEN_EXISTING, 0, 0);
365 if (hFile == INVALID_HANDLE_VALUE) {
366 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
369 hmf = EMF_GetEnhMetaFile( hFile );
370 CloseHandle( hFile );
374 /*****************************************************************************
375 * GetEnhMetaFileHeader (GDI32.@)
377 * Retrieves the record containing the header for the specified
378 * enhanced-format metafile.
381 * If buf is NULL, returns the size of buffer required.
382 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
385 UINT WINAPI GetEnhMetaFileHeader(
386 HENHMETAFILE hmf, /* [in] enhanced metafile */
387 UINT bufsize, /* [in] size of buffer */
388 LPENHMETAHEADER buf /* [out] buffer */
394 emh = EMF_GetEnhMetaHeader(hmf);
395 if(!emh) return FALSE;
397 if (!buf) return size;
398 size = min(size, bufsize);
399 memmove(buf, emh, size);
404 /*****************************************************************************
405 * GetEnhMetaFileDescriptionA (GDI32.@)
407 * See GetEnhMetaFileDescriptionW.
409 UINT WINAPI GetEnhMetaFileDescriptionA(
410 HENHMETAFILE hmf, /* [in] enhanced metafile */
411 UINT size, /* [in] size of buf */
412 LPSTR buf /* [out] buffer to receive description */
415 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
419 if(!emh) return FALSE;
420 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
421 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
422 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
424 if (!buf || !size ) return len;
426 len = min( size, len );
427 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
431 /*****************************************************************************
432 * GetEnhMetaFileDescriptionW (GDI32.@)
434 * Copies the description string of an enhanced metafile into a buffer
438 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
439 * number of characters copied.
441 UINT WINAPI GetEnhMetaFileDescriptionW(
442 HENHMETAFILE hmf, /* [in] enhanced metafile */
443 UINT size, /* [in] size of buf */
444 LPWSTR buf /* [out] buffer to receive description */
447 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
449 if(!emh) return FALSE;
450 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
451 if (!buf || !size ) return emh->nDescription;
453 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
454 return min(size, emh->nDescription);
457 /****************************************************************************
458 * SetEnhMetaFileBits (GDI32.@)
460 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
462 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
464 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
465 memmove(emh, buf, bufsize);
466 return EMF_Create_HENHMETAFILE( emh, FALSE );
469 /*****************************************************************************
470 * GetEnhMetaFileBits (GDI32.@)
473 UINT WINAPI GetEnhMetaFileBits(
479 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
485 if( buf == NULL ) return size;
487 size = min( size, bufsize );
488 memmove(buf, emh, size);
492 typedef struct EMF_dc_state
495 XFORM world_transform;
504 struct EMF_dc_state *next;
507 typedef struct enum_emh_data
509 XFORM init_transform;
512 EMF_dc_state *saved_state;
515 #define ENUM_GET_PRIVATE_DATA(ht) \
516 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
518 #define WIDTH(rect) ( (rect).right - (rect).left )
519 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
521 #define IS_WIN9X() (GetVersion()&0x80000000)
523 static void EMF_Update_MF_Xform(HDC hdc, const enum_emh_data *info)
525 XFORM mapping_mode_trans, final_trans;
526 double scaleX, scaleY;
528 scaleX = (double)info->state.vportExtX / (double)info->state.wndExtX;
529 scaleY = (double)info->state.vportExtY / (double)info->state.wndExtY;
530 mapping_mode_trans.eM11 = scaleX;
531 mapping_mode_trans.eM12 = 0.0;
532 mapping_mode_trans.eM21 = 0.0;
533 mapping_mode_trans.eM22 = scaleY;
534 mapping_mode_trans.eDx = (double)info->state.vportOrgX - scaleX * (double)info->state.wndOrgX;
535 mapping_mode_trans.eDy = (double)info->state.vportOrgY - scaleY * (double)info->state.wndOrgY;
537 CombineTransform(&final_trans, &info->state.world_transform, &mapping_mode_trans);
538 CombineTransform(&final_trans, &final_trans, &info->init_transform);
540 if (!SetWorldTransform(hdc, &final_trans))
542 ERR("World transform failed!\n");
546 static void EMF_RestoreDC( enum_emh_data *info, INT level )
548 if (abs(level) > info->save_level || level == 0) return;
550 if (level < 0) level = info->save_level + level + 1;
552 while (info->save_level >= level)
554 EMF_dc_state *state = info->saved_state;
555 info->saved_state = state->next;
557 if (--info->save_level < level)
558 info->state = *state;
559 HeapFree( GetProcessHeap(), 0, state );
563 static void EMF_SaveDC( enum_emh_data *info )
565 EMF_dc_state *state = HeapAlloc( GetProcessHeap(), 0, sizeof(*state));
568 *state = info->state;
569 state->next = info->saved_state;
570 info->saved_state = state;
572 TRACE("save_level %d\n", info->save_level);
576 static void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
578 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
579 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
580 INT horzRes = GetDeviceCaps( hdc, HORZRES );
581 INT vertRes = GetDeviceCaps( hdc, VERTRES );
583 TRACE("%d\n", info->state.mode);
585 switch(info->state.mode)
588 info->state.wndExtX = 1;
589 info->state.wndExtY = 1;
590 info->state.vportExtX = 1;
591 info->state.vportExtY = 1;
595 info->state.wndExtX = horzSize * 10;
596 info->state.wndExtY = vertSize * 10;
597 info->state.vportExtX = horzRes;
598 info->state.vportExtY = -vertRes;
601 info->state.wndExtX = horzSize * 100;
602 info->state.wndExtY = vertSize * 100;
603 info->state.vportExtX = horzRes;
604 info->state.vportExtY = -vertRes;
607 info->state.wndExtX = MulDiv(1000, horzSize, 254);
608 info->state.wndExtY = MulDiv(1000, vertSize, 254);
609 info->state.vportExtX = horzRes;
610 info->state.vportExtY = -vertRes;
613 info->state.wndExtX = MulDiv(10000, horzSize, 254);
614 info->state.wndExtY = MulDiv(10000, vertSize, 254);
615 info->state.vportExtX = horzRes;
616 info->state.vportExtY = -vertRes;
619 info->state.wndExtX = MulDiv(14400, horzSize, 254);
620 info->state.wndExtY = MulDiv(14400, vertSize, 254);
621 info->state.vportExtX = horzRes;
622 info->state.vportExtY = -vertRes;
631 /***********************************************************************
634 * Fix viewport extensions for isotropic mode.
637 static void EMF_FixIsotropic(HDC hdc, enum_emh_data *info)
639 double xdim = fabs((double)info->state.vportExtX * GetDeviceCaps( hdc, HORZSIZE ) /
640 (GetDeviceCaps( hdc, HORZRES ) * info->state.wndExtX));
641 double ydim = fabs((double)info->state.vportExtY * GetDeviceCaps( hdc, VERTSIZE ) /
642 (GetDeviceCaps( hdc, VERTRES ) * info->state.wndExtY));
646 INT mincx = (info->state.vportExtX >= 0) ? 1 : -1;
647 info->state.vportExtX = floor(info->state.vportExtX * ydim / xdim + 0.5);
648 if (!info->state.vportExtX) info->state.vportExtX = mincx;
652 INT mincy = (info->state.vportExtY >= 0) ? 1 : -1;
653 info->state.vportExtY = floor(info->state.vportExtY * xdim / ydim + 0.5);
654 if (!info->state.vportExtY) info->state.vportExtY = mincy;
658 /*****************************************************************************
659 * emr_produces_output
661 * Returns TRUE if the record type writes something to the dc. Used by
662 * PlayEnhMetaFileRecord to determine whether it needs to update the
663 * dc's xform when in win9x mode.
665 * FIXME: need to test which records should be here.
667 static BOOL emr_produces_output(int type)
673 case EMR_POLYBEZIERTO:
675 case EMR_POLYPOLYLINE:
676 case EMR_POLYPOLYGON:
679 case EMR_EXCLUDECLIPRECT:
680 case EMR_INTERSECTCLIPRECT:
681 case EMR_SELECTOBJECT:
689 case EMR_EXTFLOODFILL:
702 case EMR_SETDIBITSTODEVICE:
703 case EMR_STRETCHDIBITS:
704 case EMR_EXTTEXTOUTA:
705 case EMR_EXTTEXTOUTW:
706 case EMR_POLYBEZIER16:
709 case EMR_POLYBEZIERTO16:
710 case EMR_POLYLINETO16:
711 case EMR_POLYPOLYLINE16:
712 case EMR_POLYPOLYGON16:
714 case EMR_POLYTEXTOUTA:
715 case EMR_POLYTEXTOUTW:
716 case EMR_SMALLTEXTOUT:
718 case EMR_TRANSPARENTBLT:
726 /*****************************************************************************
727 * PlayEnhMetaFileRecord (GDI32.@)
729 * Render a single enhanced metafile record in the device context hdc.
732 * TRUE (non zero) on success, FALSE on error.
734 * Many unimplemented records.
735 * No error handling on record play failures (ie checking return codes)
738 * WinNT actually updates the current world transform in this function
739 * whereas Win9x does not.
741 BOOL WINAPI PlayEnhMetaFileRecord(
742 HDC hdc, /* [in] device context in which to render EMF record */
743 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
744 const ENHMETARECORD *mr, /* [in] EMF record to render */
745 UINT handles /* [in] size of handle array */
750 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
752 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
753 hdc, handletable, mr, handles);
754 if (!mr) return FALSE;
758 TRACE("record %s\n", get_emr_name(type));
767 const EMRGDICOMMENT *lpGdiComment = (const EMRGDICOMMENT *)mr;
768 /* In an enhanced metafile, there can be both public and private GDI comments */
769 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
774 const EMRSETMAPMODE *pSetMapMode = (const EMRSETMAPMODE *)mr;
776 if (info->state.mode == pSetMapMode->iMode &&
777 (info->state.mode == MM_ISOTROPIC || info->state.mode == MM_ANISOTROPIC))
779 info->state.mode = pSetMapMode->iMode;
780 EMF_SetMapMode(hdc, info);
785 const EMRSETBKMODE *pSetBkMode = (const EMRSETBKMODE *)mr;
786 SetBkMode(hdc, pSetBkMode->iMode);
791 const EMRSETBKCOLOR *pSetBkColor = (const EMRSETBKCOLOR *)mr;
792 SetBkColor(hdc, pSetBkColor->crColor);
795 case EMR_SETPOLYFILLMODE:
797 const EMRSETPOLYFILLMODE *pSetPolyFillMode = (const EMRSETPOLYFILLMODE *)mr;
798 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
803 const EMRSETROP2 *pSetROP2 = (const EMRSETROP2 *)mr;
804 SetROP2(hdc, pSetROP2->iMode);
807 case EMR_SETSTRETCHBLTMODE:
809 const EMRSETSTRETCHBLTMODE *pSetStretchBltMode = (const EMRSETSTRETCHBLTMODE *)mr;
810 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
813 case EMR_SETTEXTALIGN:
815 const EMRSETTEXTALIGN *pSetTextAlign = (const EMRSETTEXTALIGN *)mr;
816 SetTextAlign(hdc, pSetTextAlign->iMode);
819 case EMR_SETTEXTCOLOR:
821 const EMRSETTEXTCOLOR *pSetTextColor = (const EMRSETTEXTCOLOR *)mr;
822 SetTextColor(hdc, pSetTextColor->crColor);
833 const EMRRESTOREDC *pRestoreDC = (const EMRRESTOREDC *)mr;
834 TRACE("EMR_RESTORE: %d\n", pRestoreDC->iRelative);
835 if (RestoreDC( hdc, pRestoreDC->iRelative ))
836 EMF_RestoreDC( info, pRestoreDC->iRelative );
839 case EMR_INTERSECTCLIPRECT:
841 const EMRINTERSECTCLIPRECT *pClipRect = (const EMRINTERSECTCLIPRECT *)mr;
842 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
843 pClipRect->rclClip.left, pClipRect->rclClip.top,
844 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
845 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
846 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
849 case EMR_SELECTOBJECT:
851 const EMRSELECTOBJECT *pSelectObject = (const EMRSELECTOBJECT *)mr;
852 if( pSelectObject->ihObject & 0x80000000 ) {
853 /* High order bit is set - it's a stock object
854 * Strip the high bit to get the index.
855 * See MSDN article Q142319
857 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
860 /* High order bit wasn't set - not a stock object
863 (handletable->objectHandle)[pSelectObject->ihObject] );
867 case EMR_DELETEOBJECT:
869 const EMRDELETEOBJECT *pDeleteObject = (const EMRDELETEOBJECT *)mr;
870 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
871 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
874 case EMR_SETWINDOWORGEX:
876 const EMRSETWINDOWORGEX *pSetWindowOrgEx = (const EMRSETWINDOWORGEX *)mr;
878 info->state.wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
879 info->state.wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
881 TRACE("SetWindowOrgEx: %d,%d\n", info->state.wndOrgX, info->state.wndOrgY);
884 case EMR_SETWINDOWEXTEX:
886 const EMRSETWINDOWEXTEX *pSetWindowExtEx = (const EMRSETWINDOWEXTEX *)mr;
888 if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
890 info->state.wndExtX = pSetWindowExtEx->szlExtent.cx;
891 info->state.wndExtY = pSetWindowExtEx->szlExtent.cy;
892 if (info->state.mode == MM_ISOTROPIC)
893 EMF_FixIsotropic(hdc, info);
895 TRACE("SetWindowExtEx: %d,%d\n",info->state.wndExtX, info->state.wndExtY);
898 case EMR_SETVIEWPORTORGEX:
900 const EMRSETVIEWPORTORGEX *pSetViewportOrgEx = (const EMRSETVIEWPORTORGEX *)mr;
902 info->state.vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
903 info->state.vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
904 TRACE("SetViewportOrgEx: %d,%d\n", info->state.vportOrgX, info->state.vportOrgY);
907 case EMR_SETVIEWPORTEXTEX:
909 const EMRSETVIEWPORTEXTEX *pSetViewportExtEx = (const EMRSETVIEWPORTEXTEX *)mr;
911 if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
913 info->state.vportExtX = pSetViewportExtEx->szlExtent.cx;
914 info->state.vportExtY = pSetViewportExtEx->szlExtent.cy;
915 if (info->state.mode == MM_ISOTROPIC)
916 EMF_FixIsotropic(hdc, info);
917 TRACE("SetViewportExtEx: %d,%d\n", info->state.vportExtX, info->state.vportExtY);
922 const EMRCREATEPEN *pCreatePen = (const EMRCREATEPEN *)mr;
923 (handletable->objectHandle)[pCreatePen->ihPen] =
924 CreatePenIndirect(&pCreatePen->lopn);
927 case EMR_EXTCREATEPEN:
929 const EMREXTCREATEPEN *pPen = (const EMREXTCREATEPEN *)mr;
931 lb.lbStyle = pPen->elp.elpBrushStyle;
932 lb.lbColor = pPen->elp.elpColor;
933 lb.lbHatch = pPen->elp.elpHatch;
935 if(pPen->offBmi || pPen->offBits)
936 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
938 (handletable->objectHandle)[pPen->ihPen] =
939 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
940 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
943 case EMR_CREATEBRUSHINDIRECT:
945 const EMRCREATEBRUSHINDIRECT *pBrush = (const EMRCREATEBRUSHINDIRECT *)mr;
947 brush.lbStyle = pBrush->lb.lbStyle;
948 brush.lbColor = pBrush->lb.lbColor;
949 brush.lbHatch = pBrush->lb.lbHatch;
950 (handletable->objectHandle)[pBrush->ihBrush] = CreateBrushIndirect(&brush);
953 case EMR_EXTCREATEFONTINDIRECTW:
955 const EMREXTCREATEFONTINDIRECTW *pFont = (const EMREXTCREATEFONTINDIRECTW *)mr;
956 (handletable->objectHandle)[pFont->ihFont] =
957 CreateFontIndirectW(&pFont->elfw.elfLogFont);
962 const EMRMOVETOEX *pMoveToEx = (const EMRMOVETOEX *)mr;
963 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
968 const EMRLINETO *pLineTo = (const EMRLINETO *)mr;
969 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
974 const EMRRECTANGLE *pRect = (const EMRRECTANGLE *)mr;
975 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
976 pRect->rclBox.right, pRect->rclBox.bottom);
981 const EMRELLIPSE *pEllipse = (const EMRELLIPSE *)mr;
982 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
983 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
988 const EMRPOLYGON16 *pPoly = (const EMRPOLYGON16 *)mr;
989 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
990 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
991 pPoly->cpts * sizeof(POINT) );
993 for(i = 0; i < pPoly->cpts; i++)
995 pts[i].x = pPoly->apts[i].x;
996 pts[i].y = pPoly->apts[i].y;
998 Polygon(hdc, pts, pPoly->cpts);
999 HeapFree( GetProcessHeap(), 0, pts );
1002 case EMR_POLYLINE16:
1004 const EMRPOLYLINE16 *pPoly = (const EMRPOLYLINE16 *)mr;
1005 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1006 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1007 pPoly->cpts * sizeof(POINT) );
1009 for(i = 0; i < pPoly->cpts; i++)
1011 pts[i].x = pPoly->apts[i].x;
1012 pts[i].y = pPoly->apts[i].y;
1014 Polyline(hdc, pts, pPoly->cpts);
1015 HeapFree( GetProcessHeap(), 0, pts );
1018 case EMR_POLYLINETO16:
1020 const EMRPOLYLINETO16 *pPoly = (const EMRPOLYLINETO16 *)mr;
1021 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1022 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1023 pPoly->cpts * sizeof(POINT) );
1025 for(i = 0; i < pPoly->cpts; i++)
1027 pts[i].x = pPoly->apts[i].x;
1028 pts[i].y = pPoly->apts[i].y;
1030 PolylineTo(hdc, pts, pPoly->cpts);
1031 HeapFree( GetProcessHeap(), 0, pts );
1034 case EMR_POLYBEZIER16:
1036 const EMRPOLYBEZIER16 *pPoly = (const EMRPOLYBEZIER16 *)mr;
1037 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1038 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1039 pPoly->cpts * sizeof(POINT) );
1041 for(i = 0; i < pPoly->cpts; i++)
1043 pts[i].x = pPoly->apts[i].x;
1044 pts[i].y = pPoly->apts[i].y;
1046 PolyBezier(hdc, pts, pPoly->cpts);
1047 HeapFree( GetProcessHeap(), 0, pts );
1050 case EMR_POLYBEZIERTO16:
1052 const EMRPOLYBEZIERTO16 *pPoly = (const EMRPOLYBEZIERTO16 *)mr;
1053 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1054 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1055 pPoly->cpts * sizeof(POINT) );
1057 for(i = 0; i < pPoly->cpts; i++)
1059 pts[i].x = pPoly->apts[i].x;
1060 pts[i].y = pPoly->apts[i].y;
1062 PolyBezierTo(hdc, pts, pPoly->cpts);
1063 HeapFree( GetProcessHeap(), 0, pts );
1066 case EMR_POLYPOLYGON16:
1068 const EMRPOLYPOLYGON16 *pPolyPoly = (const EMRPOLYPOLYGON16 *)mr;
1069 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1070 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1072 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1073 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1075 for(i = 0; i < pPolyPoly->cpts; i++)
1077 pts[i].x = pts16[i].x;
1078 pts[i].y = pts16[i].y;
1080 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1081 HeapFree( GetProcessHeap(), 0, pts );
1084 case EMR_POLYPOLYLINE16:
1086 const EMRPOLYPOLYLINE16 *pPolyPoly = (const EMRPOLYPOLYLINE16 *)mr;
1087 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1088 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1090 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1091 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1093 for(i = 0; i < pPolyPoly->cpts; i++)
1095 pts[i].x = pts16[i].x;
1096 pts[i].y = pts16[i].y;
1098 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1099 HeapFree( GetProcessHeap(), 0, pts );
1103 case EMR_STRETCHDIBITS:
1105 const EMRSTRETCHDIBITS *pStretchDIBits = (const EMRSTRETCHDIBITS *)mr;
1108 pStretchDIBits->xDest,
1109 pStretchDIBits->yDest,
1110 pStretchDIBits->cxDest,
1111 pStretchDIBits->cyDest,
1112 pStretchDIBits->xSrc,
1113 pStretchDIBits->ySrc,
1114 pStretchDIBits->cxSrc,
1115 pStretchDIBits->cySrc,
1116 (const BYTE *)mr + pStretchDIBits->offBitsSrc,
1117 (const BITMAPINFO *)((const BYTE *)mr + pStretchDIBits->offBmiSrc),
1118 pStretchDIBits->iUsageSrc,
1119 pStretchDIBits->dwRop);
1123 case EMR_EXTTEXTOUTA:
1125 const EMREXTTEXTOUTA *pExtTextOutA = (const EMREXTTEXTOUTA *)mr;
1127 const INT *dx = NULL;
1129 rc.left = pExtTextOutA->emrtext.rcl.left;
1130 rc.top = pExtTextOutA->emrtext.rcl.top;
1131 rc.right = pExtTextOutA->emrtext.rcl.right;
1132 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
1133 TRACE("EMR_EXTTEXTOUTA: x,y = %d, %d. rect = %d, %d - %d, %d. flags %08x\n",
1134 pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1135 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutA->emrtext.fOptions);
1137 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1138 * These files can be enumerated and played under Win98 just
1139 * fine, but at least Win2k chokes on them.
1141 if (pExtTextOutA->emrtext.offDx)
1142 dx = (const INT *)((const BYTE *)mr + pExtTextOutA->emrtext.offDx);
1144 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1145 pExtTextOutA->emrtext.fOptions, &rc,
1146 (LPCSTR)((const BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
1151 case EMR_EXTTEXTOUTW:
1153 const EMREXTTEXTOUTW *pExtTextOutW = (const EMREXTTEXTOUTW *)mr;
1155 const INT *dx = NULL;
1157 rc.left = pExtTextOutW->emrtext.rcl.left;
1158 rc.top = pExtTextOutW->emrtext.rcl.top;
1159 rc.right = pExtTextOutW->emrtext.rcl.right;
1160 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
1161 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %d, %d - %d, %d. flags %08x\n",
1162 pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1163 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutW->emrtext.fOptions);
1165 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1166 * These files can be enumerated and played under Win98 just
1167 * fine, but at least Win2k chokes on them.
1169 if (pExtTextOutW->emrtext.offDx)
1170 dx = (const INT *)((const BYTE *)mr + pExtTextOutW->emrtext.offDx);
1172 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1173 pExtTextOutW->emrtext.fOptions, &rc,
1174 (LPCWSTR)((const BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
1179 case EMR_CREATEPALETTE:
1181 const EMRCREATEPALETTE *lpCreatePal = (const EMRCREATEPALETTE *)mr;
1183 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
1184 CreatePalette( &lpCreatePal->lgpl );
1189 case EMR_SELECTPALETTE:
1191 const EMRSELECTPALETTE *lpSelectPal = (const EMRSELECTPALETTE *)mr;
1193 if( lpSelectPal->ihPal & 0x80000000 ) {
1194 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
1196 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
1201 case EMR_REALIZEPALETTE:
1203 RealizePalette( hdc );
1207 case EMR_EXTSELECTCLIPRGN:
1209 const EMREXTSELECTCLIPRGN *lpRgn = (const EMREXTSELECTCLIPRGN *)mr;
1212 if (mr->nSize >= sizeof(*lpRgn) + sizeof(RGNDATAHEADER))
1213 hRgn = ExtCreateRegion( &info->init_transform, 0, (RGNDATA *)lpRgn->RgnData );
1215 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
1216 /* ExtSelectClipRgn created a copy of the region */
1221 case EMR_SETMETARGN:
1227 case EMR_SETWORLDTRANSFORM:
1229 const EMRSETWORLDTRANSFORM *lpXfrm = (const EMRSETWORLDTRANSFORM *)mr;
1230 info->state.world_transform = lpXfrm->xform;
1234 case EMR_POLYBEZIER:
1236 const EMRPOLYBEZIER *lpPolyBez = (const EMRPOLYBEZIER *)mr;
1237 PolyBezier(hdc, (const POINT*)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
1243 const EMRPOLYGON *lpPoly = (const EMRPOLYGON *)mr;
1244 Polygon( hdc, (const POINT*)lpPoly->aptl, (UINT)lpPoly->cptl );
1250 const EMRPOLYLINE *lpPolyLine = (const EMRPOLYLINE *)mr;
1251 Polyline(hdc, (const POINT*)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
1255 case EMR_POLYBEZIERTO:
1257 const EMRPOLYBEZIERTO *lpPolyBezierTo = (const EMRPOLYBEZIERTO *)mr;
1258 PolyBezierTo( hdc, (const POINT*)lpPolyBezierTo->aptl,
1259 (UINT)lpPolyBezierTo->cptl );
1263 case EMR_POLYLINETO:
1265 const EMRPOLYLINETO *lpPolyLineTo = (const EMRPOLYLINETO *)mr;
1266 PolylineTo( hdc, (const POINT*)lpPolyLineTo->aptl,
1267 (UINT)lpPolyLineTo->cptl );
1271 case EMR_POLYPOLYLINE:
1273 const EMRPOLYPOLYLINE *pPolyPolyline = (const EMRPOLYPOLYLINE *)mr;
1274 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1276 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
1277 pPolyPolyline->nPolys),
1278 pPolyPolyline->aPolyCounts,
1279 pPolyPolyline->nPolys );
1284 case EMR_POLYPOLYGON:
1286 const EMRPOLYPOLYGON *pPolyPolygon = (const EMRPOLYPOLYGON *)mr;
1288 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1290 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
1291 pPolyPolygon->nPolys),
1292 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
1296 case EMR_SETBRUSHORGEX:
1298 const EMRSETBRUSHORGEX *lpSetBrushOrgEx = (const EMRSETBRUSHORGEX *)mr;
1301 (INT)lpSetBrushOrgEx->ptlOrigin.x,
1302 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1310 const EMRSETPIXELV *lpSetPixelV = (const EMRSETPIXELV *)mr;
1313 (INT)lpSetPixelV->ptlPixel.x,
1314 (INT)lpSetPixelV->ptlPixel.y,
1315 lpSetPixelV->crColor );
1320 case EMR_SETMAPPERFLAGS:
1322 const EMRSETMAPPERFLAGS *lpSetMapperFlags = (const EMRSETMAPPERFLAGS *)mr;
1324 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1329 case EMR_SETCOLORADJUSTMENT:
1331 const EMRSETCOLORADJUSTMENT *lpSetColorAdjust = (const EMRSETCOLORADJUSTMENT *)mr;
1333 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1338 case EMR_OFFSETCLIPRGN:
1340 const EMROFFSETCLIPRGN *lpOffsetClipRgn = (const EMROFFSETCLIPRGN *)mr;
1343 (INT)lpOffsetClipRgn->ptlOffset.x,
1344 (INT)lpOffsetClipRgn->ptlOffset.y );
1345 FIXME("OffsetClipRgn\n");
1350 case EMR_EXCLUDECLIPRECT:
1352 const EMREXCLUDECLIPRECT *lpExcludeClipRect = (const EMREXCLUDECLIPRECT *)mr;
1354 ExcludeClipRect( hdc,
1355 lpExcludeClipRect->rclClip.left,
1356 lpExcludeClipRect->rclClip.top,
1357 lpExcludeClipRect->rclClip.right,
1358 lpExcludeClipRect->rclClip.bottom );
1359 FIXME("ExcludeClipRect\n");
1364 case EMR_SCALEVIEWPORTEXTEX:
1366 const EMRSCALEVIEWPORTEXTEX *lpScaleViewportExtEx = (const EMRSCALEVIEWPORTEXTEX *)mr;
1368 if ((info->state.mode != MM_ISOTROPIC) && (info->state.mode != MM_ANISOTROPIC))
1370 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1371 !lpScaleViewportExtEx->yNum || !lpScaleViewportExtEx->yDenom)
1373 info->state.vportExtX = MulDiv(info->state.vportExtX, lpScaleViewportExtEx->xNum,
1374 lpScaleViewportExtEx->xDenom);
1375 info->state.vportExtY = MulDiv(info->state.vportExtY, lpScaleViewportExtEx->yNum,
1376 lpScaleViewportExtEx->yDenom);
1377 if (info->state.vportExtX == 0) info->state.vportExtX = 1;
1378 if (info->state.vportExtY == 0) info->state.vportExtY = 1;
1379 if (info->state.mode == MM_ISOTROPIC)
1380 EMF_FixIsotropic(hdc, info);
1382 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1383 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1384 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1389 case EMR_SCALEWINDOWEXTEX:
1391 const EMRSCALEWINDOWEXTEX *lpScaleWindowExtEx = (const EMRSCALEWINDOWEXTEX *)mr;
1393 if ((info->state.mode != MM_ISOTROPIC) && (info->state.mode != MM_ANISOTROPIC))
1395 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1396 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1398 info->state.wndExtX = MulDiv(info->state.wndExtX, lpScaleWindowExtEx->xNum,
1399 lpScaleWindowExtEx->xDenom);
1400 info->state.wndExtY = MulDiv(info->state.wndExtY, lpScaleWindowExtEx->yNum,
1401 lpScaleWindowExtEx->yDenom);
1402 if (info->state.wndExtX == 0) info->state.wndExtX = 1;
1403 if (info->state.wndExtY == 0) info->state.wndExtY = 1;
1404 if (info->state.mode == MM_ISOTROPIC)
1405 EMF_FixIsotropic(hdc, info);
1407 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1408 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1409 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1414 case EMR_MODIFYWORLDTRANSFORM:
1416 const EMRMODIFYWORLDTRANSFORM *lpModifyWorldTrans = (const EMRMODIFYWORLDTRANSFORM *)mr;
1418 switch(lpModifyWorldTrans->iMode) {
1420 info->state.world_transform.eM11 = info->state.world_transform.eM22 = 1;
1421 info->state.world_transform.eM12 = info->state.world_transform.eM21 = 0;
1422 info->state.world_transform.eDx = info->state.world_transform.eDy = 0;
1424 case MWT_LEFTMULTIPLY:
1425 CombineTransform(&info->state.world_transform, &lpModifyWorldTrans->xform,
1426 &info->state.world_transform);
1428 case MWT_RIGHTMULTIPLY:
1429 CombineTransform(&info->state.world_transform, &info->state.world_transform,
1430 &lpModifyWorldTrans->xform);
1433 FIXME("Unknown imode %d\n", lpModifyWorldTrans->iMode);
1441 const EMRANGLEARC *lpAngleArc = (const EMRANGLEARC *)mr;
1444 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1445 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1446 lpAngleArc->eSweepAngle );
1453 const EMRROUNDRECT *lpRoundRect = (const EMRROUNDRECT *)mr;
1456 lpRoundRect->rclBox.left,
1457 lpRoundRect->rclBox.top,
1458 lpRoundRect->rclBox.right,
1459 lpRoundRect->rclBox.bottom,
1460 lpRoundRect->szlCorner.cx,
1461 lpRoundRect->szlCorner.cy );
1468 const EMRARC *lpArc = (const EMRARC *)mr;
1471 (INT)lpArc->rclBox.left,
1472 (INT)lpArc->rclBox.top,
1473 (INT)lpArc->rclBox.right,
1474 (INT)lpArc->rclBox.bottom,
1475 (INT)lpArc->ptlStart.x,
1476 (INT)lpArc->ptlStart.y,
1477 (INT)lpArc->ptlEnd.x,
1478 (INT)lpArc->ptlEnd.y );
1485 const EMRCHORD *lpChord = (const EMRCHORD *)mr;
1488 (INT)lpChord->rclBox.left,
1489 (INT)lpChord->rclBox.top,
1490 (INT)lpChord->rclBox.right,
1491 (INT)lpChord->rclBox.bottom,
1492 (INT)lpChord->ptlStart.x,
1493 (INT)lpChord->ptlStart.y,
1494 (INT)lpChord->ptlEnd.x,
1495 (INT)lpChord->ptlEnd.y );
1502 const EMRPIE *lpPie = (const EMRPIE *)mr;
1505 (INT)lpPie->rclBox.left,
1506 (INT)lpPie->rclBox.top,
1507 (INT)lpPie->rclBox.right,
1508 (INT)lpPie->rclBox.bottom,
1509 (INT)lpPie->ptlStart.x,
1510 (INT)lpPie->ptlStart.y,
1511 (INT)lpPie->ptlEnd.x,
1512 (INT)lpPie->ptlEnd.y );
1519 const EMRARC *lpArcTo = (const EMRARC *)mr;
1522 (INT)lpArcTo->rclBox.left,
1523 (INT)lpArcTo->rclBox.top,
1524 (INT)lpArcTo->rclBox.right,
1525 (INT)lpArcTo->rclBox.bottom,
1526 (INT)lpArcTo->ptlStart.x,
1527 (INT)lpArcTo->ptlStart.y,
1528 (INT)lpArcTo->ptlEnd.x,
1529 (INT)lpArcTo->ptlEnd.y );
1534 case EMR_EXTFLOODFILL:
1536 const EMREXTFLOODFILL *lpExtFloodFill = (const EMREXTFLOODFILL *)mr;
1539 (INT)lpExtFloodFill->ptlStart.x,
1540 (INT)lpExtFloodFill->ptlStart.y,
1541 lpExtFloodFill->crColor,
1542 (UINT)lpExtFloodFill->iMode );
1549 const EMRPOLYDRAW *lpPolyDraw = (const EMRPOLYDRAW *)mr;
1551 (const POINT*)lpPolyDraw->aptl,
1552 lpPolyDraw->abTypes,
1553 (INT)lpPolyDraw->cptl );
1558 case EMR_SETARCDIRECTION:
1560 const EMRSETARCDIRECTION *lpSetArcDirection = (const EMRSETARCDIRECTION *)mr;
1561 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1565 case EMR_SETMITERLIMIT:
1567 const EMRSETMITERLIMIT *lpSetMiterLimit = (const EMRSETMITERLIMIT *)mr;
1568 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1584 case EMR_CLOSEFIGURE:
1592 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1597 case EMR_STROKEANDFILLPATH:
1599 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1600 StrokeAndFillPath( hdc );
1604 case EMR_STROKEPATH:
1606 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1611 case EMR_FLATTENPATH:
1623 case EMR_SELECTCLIPPATH:
1625 const EMRSELECTCLIPPATH *lpSelectClipPath = (const EMRSELECTCLIPPATH *)mr;
1626 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1636 case EMR_CREATECOLORSPACE:
1638 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1639 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1640 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1644 case EMR_SETCOLORSPACE:
1646 const EMRSETCOLORSPACE *lpSetColorSpace = (const EMRSETCOLORSPACE *)mr;
1648 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1652 case EMR_DELETECOLORSPACE:
1654 const EMRDELETECOLORSPACE *lpDeleteColorSpace = (const EMRDELETECOLORSPACE *)mr;
1655 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1659 case EMR_SETICMMODE:
1661 const EMRSETICMMODE *lpSetICMMode = (const EMRSETICMMODE *)mr;
1662 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1666 case EMR_PIXELFORMAT:
1669 const EMRPIXELFORMAT *lpPixelFormat = (const EMRPIXELFORMAT *)mr;
1671 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1672 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1677 case EMR_SETPALETTEENTRIES:
1679 const EMRSETPALETTEENTRIES *lpSetPaletteEntries = (const EMRSETPALETTEENTRIES *)mr;
1681 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1682 (UINT)lpSetPaletteEntries->iStart,
1683 (UINT)lpSetPaletteEntries->cEntries,
1684 lpSetPaletteEntries->aPalEntries );
1689 case EMR_RESIZEPALETTE:
1691 const EMRRESIZEPALETTE *lpResizePalette = (const EMRRESIZEPALETTE *)mr;
1693 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1694 (UINT)lpResizePalette->cEntries );
1699 case EMR_CREATEDIBPATTERNBRUSHPT:
1701 const EMRCREATEDIBPATTERNBRUSHPT *lpCreate = (const EMRCREATEDIBPATTERNBRUSHPT *)mr;
1702 LPVOID lpPackedStruct;
1704 /* Check that offsets and data are contained within the record
1705 * (including checking for wrap-arounds).
1707 if ( lpCreate->offBmi + lpCreate->cbBmi > mr->nSize
1708 || lpCreate->offBits + lpCreate->cbBits > mr->nSize
1709 || lpCreate->offBmi + lpCreate->cbBmi < lpCreate->offBmi
1710 || lpCreate->offBits + lpCreate->cbBits < lpCreate->offBits )
1712 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1716 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1717 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1718 lpCreate->cbBmi + lpCreate->cbBits );
1721 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1725 /* Now pack this structure */
1726 memcpy( lpPackedStruct,
1727 ((const BYTE *)lpCreate) + lpCreate->offBmi,
1729 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1730 ((const BYTE *)lpCreate) + lpCreate->offBits,
1733 (handletable->objectHandle)[lpCreate->ihBrush] =
1734 CreateDIBPatternBrushPt( lpPackedStruct,
1735 (UINT)lpCreate->iUsage );
1737 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1741 case EMR_CREATEMONOBRUSH:
1743 const EMRCREATEMONOBRUSH *pCreateMonoBrush = (const EMRCREATEMONOBRUSH *)mr;
1744 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pCreateMonoBrush->offBmi);
1747 /* Need to check if the bitmap is monochrome, and if the
1748 two colors are really black and white */
1749 if (pCreateMonoBrush->iUsage == DIB_PAL_MONO)
1753 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1754 * aligned to 32 rather than 16 bits.
1757 bm.bmWidth = pbi->bmiHeader.biWidth;
1758 bm.bmHeight = abs(pbi->bmiHeader.biHeight);
1759 bm.bmWidthBytes = 4 * ((pbi->bmiHeader.biWidth + 31) / 32);
1760 bm.bmPlanes = pbi->bmiHeader.biPlanes;
1761 bm.bmBitsPixel = pbi->bmiHeader.biBitCount;
1762 bm.bmBits = (BYTE *)mr + pCreateMonoBrush->offBits;
1763 hBmp = CreateBitmapIndirect(&bm);
1765 else if (is_dib_monochrome(pbi))
1767 /* Top-down DIBs have a negative height */
1768 LONG height = pbi->bmiHeader.biHeight;
1770 hBmp = CreateBitmap(pbi->bmiHeader.biWidth, abs(height), 1, 1, NULL);
1771 SetDIBits(hdc, hBmp, 0, pbi->bmiHeader.biHeight,
1772 (const BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1776 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1777 (const BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1780 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1782 /* CreatePatternBrush created a copy of the bitmap */
1789 const EMRBITBLT *pBitBlt = (const EMRBITBLT *)mr;
1791 if(pBitBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1792 PatBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1794 } else { /* BitBlt */
1795 HDC hdcSrc = CreateCompatibleDC(hdc);
1796 HBRUSH hBrush, hBrushOld;
1797 HBITMAP hBmp = 0, hBmpOld = 0;
1798 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pBitBlt->offBmiSrc);
1800 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1802 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1803 hBrushOld = SelectObject(hdcSrc, hBrush);
1804 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1805 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1806 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1807 SelectObject(hdcSrc, hBrushOld);
1808 DeleteObject(hBrush);
1810 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1811 (const BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1812 hBmpOld = SelectObject(hdcSrc, hBmp);
1814 BitBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1815 hdcSrc, pBitBlt->xSrc, pBitBlt->ySrc, pBitBlt->dwRop);
1817 SelectObject(hdcSrc, hBmpOld);
1824 case EMR_STRETCHBLT:
1826 const EMRSTRETCHBLT *pStretchBlt = (const EMRSTRETCHBLT *)mr;
1828 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1829 pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1830 pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1831 pStretchBlt->dwRop, pStretchBlt->offBitsSrc);
1833 if(pStretchBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1834 PatBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1835 pStretchBlt->dwRop);
1836 } else { /* StretchBlt */
1837 HDC hdcSrc = CreateCompatibleDC(hdc);
1838 HBRUSH hBrush, hBrushOld;
1839 HBITMAP hBmp = 0, hBmpOld = 0;
1840 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pStretchBlt->offBmiSrc);
1842 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1844 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1845 hBrushOld = SelectObject(hdcSrc, hBrush);
1846 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1847 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1848 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1849 SelectObject(hdcSrc, hBrushOld);
1850 DeleteObject(hBrush);
1852 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1853 (const BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1854 hBmpOld = SelectObject(hdcSrc, hBmp);
1856 StretchBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1857 hdcSrc, pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1858 pStretchBlt->dwRop);
1860 SelectObject(hdcSrc, hBmpOld);
1867 case EMR_ALPHABLEND:
1869 const EMRALPHABLEND *pAlphaBlend = (const EMRALPHABLEND *)mr;
1871 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1872 pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1873 pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1874 pAlphaBlend->dwRop, pAlphaBlend->offBitsSrc);
1876 if(pAlphaBlend->offBmiSrc == 0) {
1877 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1879 HDC hdcSrc = CreateCompatibleDC(hdc);
1880 HBITMAP hBmp = 0, hBmpOld = 0;
1881 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pAlphaBlend->offBmiSrc);
1882 BLENDFUNCTION blendfn;
1885 SetWorldTransform(hdcSrc, &pAlphaBlend->xformSrc);
1887 hBmp = CreateDIBSection(hdc, pbi, pAlphaBlend->iUsageSrc, &bits, NULL, 0);
1888 memcpy(bits, (const BYTE *)mr + pAlphaBlend->offBitsSrc, pAlphaBlend->cbBitsSrc);
1889 hBmpOld = SelectObject(hdcSrc, hBmp);
1891 blendfn.BlendOp = (pAlphaBlend->dwRop >> 24) & 0xff;
1892 blendfn.BlendFlags = (pAlphaBlend->dwRop >> 16) & 0xff;
1893 blendfn.SourceConstantAlpha = (pAlphaBlend->dwRop >> 8) & 0xff;
1894 blendfn.AlphaFormat = (pAlphaBlend->dwRop) & 0xff;
1896 GdiAlphaBlend(hdc, pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1897 hdcSrc, pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1900 SelectObject(hdcSrc, hBmpOld);
1909 const EMRMASKBLT *pMaskBlt = (const EMRMASKBLT *)mr;
1910 HDC hdcSrc = CreateCompatibleDC(hdc);
1911 HBRUSH hBrush, hBrushOld;
1912 HBITMAP hBmp, hBmpOld, hBmpMask;
1913 const BITMAPINFO *pbi;
1915 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1917 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1918 hBrushOld = SelectObject(hdcSrc, hBrush);
1919 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1920 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1921 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1922 SelectObject(hdcSrc, hBrushOld);
1923 DeleteObject(hBrush);
1925 pbi = (const BITMAPINFO *)((const BYTE *)mr + pMaskBlt->offBmiMask);
1926 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1928 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1929 (const BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1931 pbi = (const BITMAPINFO *)((const BYTE *)mr + pMaskBlt->offBmiSrc);
1932 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1933 (const BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1934 hBmpOld = SelectObject(hdcSrc, hBmp);
1947 SelectObject(hdcSrc, hBmpOld);
1949 DeleteObject(hBmpMask);
1956 const EMRPLGBLT *pPlgBlt = (const EMRPLGBLT *)mr;
1957 HDC hdcSrc = CreateCompatibleDC(hdc);
1958 HBRUSH hBrush, hBrushOld;
1959 HBITMAP hBmp, hBmpOld, hBmpMask;
1960 const BITMAPINFO *pbi;
1963 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1965 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1966 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1967 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1969 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1970 hBrushOld = SelectObject(hdcSrc, hBrush);
1971 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1972 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1973 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1974 SelectObject(hdcSrc, hBrushOld);
1975 DeleteObject(hBrush);
1977 pbi = (const BITMAPINFO *)((const BYTE *)mr + pPlgBlt->offBmiMask);
1978 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1980 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1981 (const BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1983 pbi = (const BITMAPINFO *)((const BYTE *)mr + pPlgBlt->offBmiSrc);
1984 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1985 (const BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1986 hBmpOld = SelectObject(hdcSrc, hBmp);
1997 SelectObject(hdcSrc, hBmpOld);
1999 DeleteObject(hBmpMask);
2004 case EMR_SETDIBITSTODEVICE:
2006 const EMRSETDIBITSTODEVICE *pSetDIBitsToDevice = (const EMRSETDIBITSTODEVICE *)mr;
2008 SetDIBitsToDevice(hdc,
2009 pSetDIBitsToDevice->xDest,
2010 pSetDIBitsToDevice->yDest,
2011 pSetDIBitsToDevice->cxSrc,
2012 pSetDIBitsToDevice->cySrc,
2013 pSetDIBitsToDevice->xSrc,
2014 pSetDIBitsToDevice->ySrc,
2015 pSetDIBitsToDevice->iStartScan,
2016 pSetDIBitsToDevice->cScans,
2017 (const BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
2018 (const BITMAPINFO *)((const BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
2019 pSetDIBitsToDevice->iUsageSrc);
2023 case EMR_POLYTEXTOUTA:
2025 const EMRPOLYTEXTOUTA *pPolyTextOutA = (const EMRPOLYTEXTOUTA *)mr;
2026 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
2028 XFORM xform, xformOld;
2031 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
2032 GetWorldTransform(hdc, &xformOld);
2034 xform.eM11 = pPolyTextOutA->exScale;
2037 xform.eM22 = pPolyTextOutA->eyScale;
2040 SetWorldTransform(hdc, &xform);
2042 /* Set up POLYTEXTA structures */
2043 for(i = 0; i < pPolyTextOutA->cStrings; i++)
2045 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
2046 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
2047 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
2048 polytextA[i].lpstr = (LPCSTR)((const BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
2049 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
2050 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
2051 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
2052 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
2053 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
2054 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
2056 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
2057 HeapFree(GetProcessHeap(), 0, polytextA);
2059 SetWorldTransform(hdc, &xformOld);
2060 SetGraphicsMode(hdc, gModeOld);
2064 case EMR_POLYTEXTOUTW:
2066 const EMRPOLYTEXTOUTW *pPolyTextOutW = (const EMRPOLYTEXTOUTW *)mr;
2067 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
2069 XFORM xform, xformOld;
2072 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
2073 GetWorldTransform(hdc, &xformOld);
2075 xform.eM11 = pPolyTextOutW->exScale;
2078 xform.eM22 = pPolyTextOutW->eyScale;
2081 SetWorldTransform(hdc, &xform);
2083 /* Set up POLYTEXTW structures */
2084 for(i = 0; i < pPolyTextOutW->cStrings; i++)
2086 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
2087 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
2088 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
2089 polytextW[i].lpstr = (LPCWSTR)((const BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
2090 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
2091 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
2092 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
2093 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
2094 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
2095 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
2097 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
2098 HeapFree(GetProcessHeap(), 0, polytextW);
2100 SetWorldTransform(hdc, &xformOld);
2101 SetGraphicsMode(hdc, gModeOld);
2107 const EMRFILLRGN *pFillRgn = (const EMRFILLRGN *)mr;
2108 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
2111 (handletable->objectHandle)[pFillRgn->ihBrush]);
2118 const EMRFRAMERGN *pFrameRgn = (const EMRFRAMERGN *)mr;
2119 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
2122 (handletable->objectHandle)[pFrameRgn->ihBrush],
2123 pFrameRgn->szlStroke.cx,
2124 pFrameRgn->szlStroke.cy);
2131 const EMRINVERTRGN *pInvertRgn = (const EMRINVERTRGN *)mr;
2132 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
2133 InvertRgn(hdc, hRgn);
2140 const EMRPAINTRGN *pPaintRgn = (const EMRPAINTRGN *)mr;
2141 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
2142 PaintRgn(hdc, hRgn);
2147 case EMR_SETTEXTJUSTIFICATION:
2149 const EMRSETTEXTJUSTIFICATION *pSetTextJust = (const EMRSETTEXTJUSTIFICATION *)mr;
2150 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
2156 const EMRSETLAYOUT *pSetLayout = (const EMRSETLAYOUT *)mr;
2157 SetLayout(hdc, pSetLayout->iMode);
2161 case EMR_POLYDRAW16:
2163 case EMR_GLSBOUNDEDRECORD:
2164 case EMR_DRAWESCAPE :
2167 case EMR_SMALLTEXTOUT:
2168 case EMR_FORCEUFIMAPPING:
2169 case EMR_NAMEDESCAPE:
2170 case EMR_COLORCORRECTPALETTE:
2171 case EMR_SETICMPROFILEA:
2172 case EMR_SETICMPROFILEW:
2173 case EMR_TRANSPARENTBLT:
2174 case EMR_GRADIENTFILL:
2175 case EMR_SETLINKEDUFI:
2176 case EMR_COLORMATCHTOTARGETW:
2177 case EMR_CREATECOLORSPACEW:
2180 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2181 record then ignore and return TRUE. */
2182 FIXME("type %d is unimplemented\n", type);
2185 tmprc.left = tmprc.top = 0;
2186 tmprc.right = tmprc.bottom = 1000;
2187 LPtoDP(hdc, (POINT*)&tmprc, 2);
2188 TRACE("L:0,0 - 1000,1000 -> D:%d,%d - %d,%d\n", tmprc.left,
2189 tmprc.top, tmprc.right, tmprc.bottom);
2195 /*****************************************************************************
2197 * EnumEnhMetaFile (GDI32.@)
2199 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2201 * record. Returns when either every record has been used or
2202 * when _EnhMetaFunc_ returns FALSE.
2206 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2213 * This function behaves differently in Win9x and WinNT.
2215 * In WinNT, the DC's world transform is updated as the EMF changes
2216 * the Window/Viewport Extent and Origin or it's world transform.
2217 * The actual Window/Viewport Extent and Origin are left untouched.
2219 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2220 * updates the scaling itself but only just before a record that
2221 * writes anything to the DC.
2223 * I'm not sure where the data (enum_emh_data) is stored in either
2224 * version. For this implementation, it is stored before the handle
2225 * table, but it could be stored in the DC, in the EMF handle or in
2229 BOOL WINAPI EnumEnhMetaFile(
2230 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
2231 HENHMETAFILE hmf, /* [in] EMF to walk */
2232 ENHMFENUMPROC callback, /* [in] callback function */
2233 LPVOID data, /* [in] optional data for callback function */
2234 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
2246 HBRUSH hBrush = NULL;
2249 enum_emh_data *info;
2250 SIZE vp_size, win_size;
2251 POINT vp_org, win_org;
2252 INT mapMode = MM_TEXT, old_align = 0, old_rop2 = 0, old_arcdir = 0, old_polyfill = 0, old_stretchblt = 0;
2253 COLORREF old_text_color = 0, old_bk_color = 0;
2257 SetLastError(ERROR_INVALID_PARAMETER);
2261 emh = EMF_GetEnhMetaHeader(hmf);
2263 SetLastError(ERROR_INVALID_HANDLE);
2267 info = HeapAlloc( GetProcessHeap(), 0,
2268 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
2271 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2274 info->state.wndOrgX = 0;
2275 info->state.wndOrgY = 0;
2276 info->state.wndExtX = 1;
2277 info->state.wndExtY = 1;
2278 info->state.vportOrgX = 0;
2279 info->state.vportOrgY = 0;
2280 info->state.vportExtX = 1;
2281 info->state.vportExtY = 1;
2282 info->state.world_transform.eM11 = info->state.world_transform.eM22 = 1;
2283 info->state.world_transform.eM12 = info->state.world_transform.eM21 = 0;
2284 info->state.world_transform.eDx = info->state.world_transform.eDy = 0;
2286 info->state.next = NULL;
2287 info->save_level = 0;
2288 info->saved_state = NULL;
2290 ht = (HANDLETABLE*) &info[1];
2291 ht->objectHandle[0] = hmf;
2292 for(i = 1; i < emh->nHandles; i++)
2293 ht->objectHandle[i] = NULL;
2297 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
2298 GetWorldTransform(hdc, &savedXform);
2299 GetViewportExtEx(hdc, &vp_size);
2300 GetWindowExtEx(hdc, &win_size);
2301 GetViewportOrgEx(hdc, &vp_org);
2302 GetWindowOrgEx(hdc, &win_org);
2303 mapMode = GetMapMode(hdc);
2306 hPen = GetCurrentObject(hdc, OBJ_PEN);
2307 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
2308 hFont = GetCurrentObject(hdc, OBJ_FONT);
2310 hRgn = CreateRectRgn(0, 0, 0, 0);
2311 if (!GetClipRgn(hdc, hRgn))
2317 old_text_color = SetTextColor(hdc, RGB(0,0,0));
2318 old_bk_color = SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
2319 old_align = SetTextAlign(hdc, 0);
2320 old_rop2 = SetROP2(hdc, R2_COPYPEN);
2321 old_arcdir = SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
2322 old_polyfill = SetPolyFillMode(hdc, ALTERNATE);
2323 old_stretchblt = SetStretchBltMode(hdc, BLACKONWHITE);
2326 info->state.mode = MM_TEXT;
2330 /* Win95 leaves the vp/win ext/org info alone */
2331 info->init_transform.eM11 = 1.0;
2332 info->init_transform.eM12 = 0.0;
2333 info->init_transform.eM21 = 0.0;
2334 info->init_transform.eM22 = 1.0;
2335 info->init_transform.eDx = 0.0;
2336 info->init_transform.eDy = 0.0;
2340 /* WinNT combines the vp/win ext/org info into a transform */
2341 double xscale, yscale;
2342 xscale = (double)vp_size.cx / (double)win_size.cx;
2343 yscale = (double)vp_size.cy / (double)win_size.cy;
2344 info->init_transform.eM11 = xscale;
2345 info->init_transform.eM12 = 0.0;
2346 info->init_transform.eM21 = 0.0;
2347 info->init_transform.eM22 = yscale;
2348 info->init_transform.eDx = (double)vp_org.x - xscale * (double)win_org.x;
2349 info->init_transform.eDy = (double)vp_org.y - yscale * (double)win_org.y;
2351 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
2354 if ( lpRect && WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
2356 double xSrcPixSize, ySrcPixSize, xscale, yscale;
2359 TRACE("rect: %d,%d - %d,%d. rclFrame: %d,%d - %d,%d\n",
2360 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
2361 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
2362 emh->rclFrame.bottom);
2364 xSrcPixSize = (double) emh->szlMillimeters.cx / emh->szlDevice.cx;
2365 ySrcPixSize = (double) emh->szlMillimeters.cy / emh->szlDevice.cy;
2366 xscale = (double) WIDTH(*lpRect) * 100.0 /
2367 WIDTH(emh->rclFrame) * xSrcPixSize;
2368 yscale = (double) HEIGHT(*lpRect) * 100.0 /
2369 HEIGHT(emh->rclFrame) * ySrcPixSize;
2370 TRACE("xscale = %f, yscale = %f\n", xscale, yscale);
2372 xform.eM11 = xscale;
2375 xform.eM22 = yscale;
2376 xform.eDx = (double) lpRect->left - (double) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
2377 xform.eDy = (double) lpRect->top - (double) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
2379 CombineTransform(&info->init_transform, &xform, &info->init_transform);
2382 /* WinNT resets the current vp/win org/ext */
2383 if ( !IS_WIN9X() && hdc )
2385 SetMapMode(hdc, MM_TEXT);
2386 SetWindowOrgEx(hdc, 0, 0, NULL);
2387 SetViewportOrgEx(hdc, 0, 0, NULL);
2388 EMF_Update_MF_Xform(hdc, info);
2393 while(ret && offset < emh->nBytes)
2395 emr = (ENHMETARECORD *)((char *)emh + offset);
2397 /* In Win9x mode we update the xform if the record will produce output */
2398 if (hdc && IS_WIN9X() && emr_produces_output(emr->iType))
2399 EMF_Update_MF_Xform(hdc, info);
2401 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr->iType), emr->nSize);
2402 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2403 offset += emr->nSize;
2405 /* WinNT - update the transform (win9x updates when the next graphics
2406 output record is played). */
2407 if (hdc && !IS_WIN9X())
2408 EMF_Update_MF_Xform(hdc, info);
2413 SetStretchBltMode(hdc, old_stretchblt);
2414 SetPolyFillMode(hdc, old_polyfill);
2415 SetArcDirection(hdc, old_arcdir);
2416 SetROP2(hdc, old_rop2);
2417 SetTextAlign(hdc, old_align);
2418 SetBkColor(hdc, old_bk_color);
2419 SetTextColor(hdc, old_text_color);
2422 SelectObject(hdc, hBrush);
2423 SelectObject(hdc, hPen);
2424 SelectObject(hdc, hFont);
2425 ExtSelectClipRgn(hdc, hRgn, RGN_COPY);
2428 SetWorldTransform(hdc, &savedXform);
2430 SetGraphicsMode(hdc, savedMode);
2431 SetMapMode(hdc, mapMode);
2432 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2433 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2434 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2435 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2438 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2439 if( (ht->objectHandle)[i] )
2440 DeleteObject( (ht->objectHandle)[i] );
2442 while (info->saved_state)
2444 EMF_dc_state *state = info->saved_state;
2445 info->saved_state = info->saved_state->next;
2446 HeapFree( GetProcessHeap(), 0, state );
2448 HeapFree( GetProcessHeap(), 0, info );
2452 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2453 const ENHMETARECORD *emr,
2454 INT handles, LPARAM data)
2456 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2459 /**************************************************************************
2460 * PlayEnhMetaFile (GDI32.@)
2462 * Renders an enhanced metafile into a specified rectangle *lpRect
2463 * in device context hdc.
2469 BOOL WINAPI PlayEnhMetaFile(
2470 HDC hdc, /* [in] DC to render into */
2471 HENHMETAFILE hmf, /* [in] metafile to render */
2472 const RECT *lpRect /* [in] rectangle to place metafile inside */
2475 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2479 /*****************************************************************************
2480 * DeleteEnhMetaFile (GDI32.@)
2482 * Deletes an enhanced metafile and frees the associated storage.
2484 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2486 return EMF_Delete_HENHMETAFILE( hmf );
2489 /*****************************************************************************
2490 * CopyEnhMetaFileA (GDI32.@)
2492 * Duplicate an enhanced metafile.
2496 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2497 HENHMETAFILE hmfSrc,
2500 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2501 HENHMETAFILE hmfDst;
2503 if(!emrSrc) return FALSE;
2505 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2506 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2507 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2511 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2512 NULL, CREATE_ALWAYS, 0, 0);
2513 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2514 CloseHandle( hFile );
2515 /* Reopen file for reading only, so that apps can share
2516 read access to the file while hmf is still valid */
2517 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2518 NULL, OPEN_EXISTING, 0, 0);
2519 if(hFile == INVALID_HANDLE_VALUE) {
2520 ERR("Can't reopen emf for reading\n");
2523 hmfDst = EMF_GetEnhMetaFile( hFile );
2524 CloseHandle( hFile );
2529 /*****************************************************************************
2530 * CopyEnhMetaFileW (GDI32.@)
2532 * See CopyEnhMetaFileA.
2536 HENHMETAFILE WINAPI CopyEnhMetaFileW(
2537 HENHMETAFILE hmfSrc,
2540 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2541 HENHMETAFILE hmfDst;
2543 if(!emrSrc) return FALSE;
2545 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2546 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2547 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2551 hFile = CreateFileW( file, GENERIC_WRITE | GENERIC_READ, 0,
2552 NULL, CREATE_ALWAYS, 0, 0);
2553 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2554 CloseHandle( hFile );
2555 /* Reopen file for reading only, so that apps can share
2556 read access to the file while hmf is still valid */
2557 hFile = CreateFileW( file, GENERIC_READ, FILE_SHARE_READ,
2558 NULL, OPEN_EXISTING, 0, 0);
2559 if(hFile == INVALID_HANDLE_VALUE) {
2560 ERR("Can't reopen emf for reading\n");
2563 hmfDst = EMF_GetEnhMetaFile( hFile );
2564 CloseHandle( hFile );
2570 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2571 typedef struct tagEMF_PaletteCopy
2574 LPPALETTEENTRY lpPe;
2577 /***************************************************************
2578 * Find the EMR_EOF record and then use it to find the
2579 * palette entries for this enhanced metafile.
2580 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2581 * which contains the max number of elements to copy and where
2584 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2586 static INT CALLBACK cbEnhPaletteCopy( HDC a,
2588 const ENHMETARECORD *lpEMR,
2593 if ( lpEMR->iType == EMR_EOF )
2595 const EMREOF *lpEof = (const EMREOF *)lpEMR;
2596 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2597 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2599 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy );
2601 memcpy( info->lpPe, (LPCSTR)lpEof + lpEof->offPalEntries,
2602 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2604 /* Update the passed data as a return code */
2605 info->lpPe = NULL; /* Palettes were copied! */
2606 info->cEntries = dwNumPalToCopy;
2608 return FALSE; /* That's all we need */
2614 /*****************************************************************************
2615 * GetEnhMetaFilePaletteEntries (GDI32.@)
2617 * Copy the palette and report size
2619 * BUGS: Error codes (SetLastError) are not set on failures
2621 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2623 LPPALETTEENTRY lpPe )
2625 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2626 EMF_PaletteCopy infoForCallBack;
2628 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2630 if (!enhHeader) return 0;
2632 /* First check if there are any palettes associated with
2634 if ( enhHeader->nPalEntries == 0 ) return 0;
2636 /* Is the user requesting the number of palettes? */
2637 if ( lpPe == NULL ) return enhHeader->nPalEntries;
2639 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2640 infoForCallBack.cEntries = cEntries;
2641 infoForCallBack.lpPe = lpPe;
2643 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2644 &infoForCallBack, 0 ) )
2647 /* Verify that the callback executed correctly */
2648 if ( infoForCallBack.lpPe != NULL )
2650 /* Callback proc had error! */
2651 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2655 return infoForCallBack.cEntries;
2658 typedef struct gdi_mf_comment
2665 DWORD cbWinMetaFile;
2668 /******************************************************************
2669 * SetWinMetaFileBits (GDI32.@)
2671 * Translate from old style to new style.
2674 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2675 CONST BYTE *lpbBuffer,
2677 CONST METAFILEPICT *lpmfp
2680 static const WCHAR szDisplayW[] = { 'D','I','S','P','L','A','Y','\0' };
2681 HMETAFILE hmf = NULL;
2682 HENHMETAFILE ret = NULL;
2683 HDC hdc = NULL, hdcdisp = NULL;
2684 RECT rc, *prcFrame = NULL;
2685 LONG mm, xExt, yExt;
2686 INT horzsize, vertsize, horzres, vertres;
2688 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2690 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2693 WARN("SetMetaFileBitsEx failed\n");
2698 hdcRef = hdcdisp = CreateDCW(szDisplayW, NULL, NULL, NULL);
2702 TRACE("mm = %d %dx%d\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2710 TRACE("lpmfp == NULL\n");
2712 /* Use the whole device surface */
2713 mm = MM_ANISOTROPIC;
2718 if (mm == MM_ISOTROPIC || mm == MM_ANISOTROPIC)
2720 if (xExt < 0 || yExt < 0)
2722 /* Use the whole device surface */
2727 /* Use the x and y extents as the frame box */
2730 rc.left = rc.top = 0;
2737 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL)))
2739 ERR("CreateEnhMetaFile failed\n");
2744 * Write the original METAFILE into the enhanced metafile.
2745 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2749 gdi_mf_comment *mfcomment;
2750 UINT mfcomment_size;
2752 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2753 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2756 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2757 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2758 mfcomment->nVersion = 0x00000300;
2759 mfcomment->nChecksum = 0; /* FIXME */
2760 mfcomment->fFlags = 0;
2761 mfcomment->cbWinMetaFile = cbBuffer;
2762 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2763 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2764 HeapFree(GetProcessHeap(), 0, mfcomment);
2766 SetMapMode(hdc, mm);
2770 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2771 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2772 horzres = GetDeviceCaps(hdcRef, HORZRES);
2773 vertres = GetDeviceCaps(hdcRef, VERTRES);
2777 /* Use the whole device surface */
2783 xExt = MulDiv(xExt, horzres, 100 * horzsize);
2784 yExt = MulDiv(yExt, vertres, 100 * vertsize);
2787 /* set the initial viewport:window ratio as 1:1 */
2788 SetViewportExtEx(hdc, xExt, yExt, NULL);
2789 SetWindowExtEx(hdc, xExt, yExt, NULL);
2791 PlayMetaFile(hdc, hmf);
2793 ret = CloseEnhMetaFile(hdc);
2795 if (hdcdisp) DeleteDC(hdcdisp);
2796 DeleteMetaFile(hmf);