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 )
252 HENHMETAFILE hmf = 0;
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 metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
266 (HGDIOBJ *)&hmf, NULL );
270 metaObj->on_disk = on_disk;
271 GDI_ReleaseObj( hmf );
276 /****************************************************************************
277 * EMF_Delete_HENHMETAFILE
279 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
281 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
283 if(!metaObj) return FALSE;
286 UnmapViewOfFile( metaObj->emh );
288 HeapFree( GetProcessHeap(), 0, metaObj->emh );
289 return GDI_FreeObject( hmf, metaObj );
292 /******************************************************************
293 * EMF_GetEnhMetaHeader
295 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
297 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
299 ENHMETAHEADER *ret = NULL;
300 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
301 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
305 GDI_ReleaseObj( hmf );
310 /*****************************************************************************
314 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
320 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
321 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
322 CloseHandle( hMapping );
326 hemf = EMF_Create_HENHMETAFILE( emh, TRUE );
328 UnmapViewOfFile( emh );
333 /*****************************************************************************
334 * GetEnhMetaFileA (GDI32.@)
338 HENHMETAFILE WINAPI GetEnhMetaFileA(
339 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
345 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
346 OPEN_EXISTING, 0, 0);
347 if (hFile == INVALID_HANDLE_VALUE) {
348 WARN("could not open %s\n", lpszMetaFile);
351 hmf = EMF_GetEnhMetaFile( hFile );
352 CloseHandle( hFile );
356 /*****************************************************************************
357 * GetEnhMetaFileW (GDI32.@)
359 HENHMETAFILE WINAPI GetEnhMetaFileW(
360 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
365 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
366 OPEN_EXISTING, 0, 0);
367 if (hFile == INVALID_HANDLE_VALUE) {
368 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
371 hmf = EMF_GetEnhMetaFile( hFile );
372 CloseHandle( hFile );
376 /*****************************************************************************
377 * GetEnhMetaFileHeader (GDI32.@)
379 * Retrieves the record containing the header for the specified
380 * enhanced-format metafile.
383 * If buf is NULL, returns the size of buffer required.
384 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
387 UINT WINAPI GetEnhMetaFileHeader(
388 HENHMETAFILE hmf, /* [in] enhanced metafile */
389 UINT bufsize, /* [in] size of buffer */
390 LPENHMETAHEADER buf /* [out] buffer */
396 emh = EMF_GetEnhMetaHeader(hmf);
397 if(!emh) return FALSE;
399 if (!buf) return size;
400 size = min(size, bufsize);
401 memmove(buf, emh, size);
406 /*****************************************************************************
407 * GetEnhMetaFileDescriptionA (GDI32.@)
409 * See GetEnhMetaFileDescriptionW.
411 UINT WINAPI GetEnhMetaFileDescriptionA(
412 HENHMETAFILE hmf, /* [in] enhanced metafile */
413 UINT size, /* [in] size of buf */
414 LPSTR buf /* [out] buffer to receive description */
417 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
421 if(!emh) return FALSE;
422 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
423 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
424 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
426 if (!buf || !size ) return len;
428 len = min( size, len );
429 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
433 /*****************************************************************************
434 * GetEnhMetaFileDescriptionW (GDI32.@)
436 * Copies the description string of an enhanced metafile into a buffer
440 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
441 * number of characters copied.
443 UINT WINAPI GetEnhMetaFileDescriptionW(
444 HENHMETAFILE hmf, /* [in] enhanced metafile */
445 UINT size, /* [in] size of buf */
446 LPWSTR buf /* [out] buffer to receive description */
449 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
451 if(!emh) return FALSE;
452 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
453 if (!buf || !size ) return emh->nDescription;
455 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
456 return min(size, emh->nDescription);
459 /****************************************************************************
460 * SetEnhMetaFileBits (GDI32.@)
462 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
464 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
466 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
467 memmove(emh, buf, bufsize);
468 return EMF_Create_HENHMETAFILE( emh, FALSE );
471 /*****************************************************************************
472 * GetEnhMetaFileBits (GDI32.@)
475 UINT WINAPI GetEnhMetaFileBits(
481 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
487 if( buf == NULL ) return size;
489 size = min( size, bufsize );
490 memmove(buf, emh, size);
494 typedef struct EMF_dc_state
497 XFORM world_transform;
506 struct EMF_dc_state *next;
509 typedef struct enum_emh_data
511 XFORM init_transform;
514 EMF_dc_state *saved_state;
517 #define ENUM_GET_PRIVATE_DATA(ht) \
518 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
520 #define WIDTH(rect) ( (rect).right - (rect).left )
521 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
523 #define IS_WIN9X() (GetVersion()&0x80000000)
525 static void EMF_Update_MF_Xform(HDC hdc, const enum_emh_data *info)
527 XFORM mapping_mode_trans, final_trans;
528 double scaleX, scaleY;
530 scaleX = (double)info->state.vportExtX / (double)info->state.wndExtX;
531 scaleY = (double)info->state.vportExtY / (double)info->state.wndExtY;
532 mapping_mode_trans.eM11 = scaleX;
533 mapping_mode_trans.eM12 = 0.0;
534 mapping_mode_trans.eM21 = 0.0;
535 mapping_mode_trans.eM22 = scaleY;
536 mapping_mode_trans.eDx = (double)info->state.vportOrgX - scaleX * (double)info->state.wndOrgX;
537 mapping_mode_trans.eDy = (double)info->state.vportOrgY - scaleY * (double)info->state.wndOrgY;
539 CombineTransform(&final_trans, &info->state.world_transform, &mapping_mode_trans);
540 CombineTransform(&final_trans, &final_trans, &info->init_transform);
542 if (!SetWorldTransform(hdc, &final_trans))
544 ERR("World transform failed!\n");
548 static void EMF_RestoreDC( enum_emh_data *info, INT level )
550 if (abs(level) > info->save_level || level == 0) return;
552 if (level < 0) level = info->save_level + level + 1;
554 while (info->save_level >= level)
556 EMF_dc_state *state = info->saved_state;
557 info->saved_state = state->next;
559 if (--info->save_level < level)
560 info->state = *state;
561 HeapFree( GetProcessHeap(), 0, state );
565 static void EMF_SaveDC( enum_emh_data *info )
567 EMF_dc_state *state = HeapAlloc( GetProcessHeap(), 0, sizeof(*state));
570 *state = info->state;
571 state->next = info->saved_state;
572 info->saved_state = state;
574 TRACE("save_level %d\n", info->save_level);
578 static void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
580 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
581 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
582 INT horzRes = GetDeviceCaps( hdc, HORZRES );
583 INT vertRes = GetDeviceCaps( hdc, VERTRES );
585 TRACE("%d\n", info->state.mode);
587 switch(info->state.mode)
590 info->state.wndExtX = 1;
591 info->state.wndExtY = 1;
592 info->state.vportExtX = 1;
593 info->state.vportExtY = 1;
597 info->state.wndExtX = horzSize * 10;
598 info->state.wndExtY = vertSize * 10;
599 info->state.vportExtX = horzRes;
600 info->state.vportExtY = -vertRes;
603 info->state.wndExtX = horzSize * 100;
604 info->state.wndExtY = vertSize * 100;
605 info->state.vportExtX = horzRes;
606 info->state.vportExtY = -vertRes;
609 info->state.wndExtX = MulDiv(1000, horzSize, 254);
610 info->state.wndExtY = MulDiv(1000, vertSize, 254);
611 info->state.vportExtX = horzRes;
612 info->state.vportExtY = -vertRes;
615 info->state.wndExtX = MulDiv(10000, horzSize, 254);
616 info->state.wndExtY = MulDiv(10000, vertSize, 254);
617 info->state.vportExtX = horzRes;
618 info->state.vportExtY = -vertRes;
621 info->state.wndExtX = MulDiv(14400, horzSize, 254);
622 info->state.wndExtY = MulDiv(14400, vertSize, 254);
623 info->state.vportExtX = horzRes;
624 info->state.vportExtY = -vertRes;
633 /***********************************************************************
636 * Fix viewport extensions for isotropic mode.
639 static void EMF_FixIsotropic(HDC hdc, enum_emh_data *info)
641 double xdim = fabs((double)info->state.vportExtX * GetDeviceCaps( hdc, HORZSIZE ) /
642 (GetDeviceCaps( hdc, HORZRES ) * info->state.wndExtX));
643 double ydim = fabs((double)info->state.vportExtY * GetDeviceCaps( hdc, VERTSIZE ) /
644 (GetDeviceCaps( hdc, VERTRES ) * info->state.wndExtY));
648 INT mincx = (info->state.vportExtX >= 0) ? 1 : -1;
649 info->state.vportExtX = floor(info->state.vportExtX * ydim / xdim + 0.5);
650 if (!info->state.vportExtX) info->state.vportExtX = mincx;
654 INT mincy = (info->state.vportExtY >= 0) ? 1 : -1;
655 info->state.vportExtY = floor(info->state.vportExtY * xdim / ydim + 0.5);
656 if (!info->state.vportExtY) info->state.vportExtY = mincy;
660 /*****************************************************************************
661 * emr_produces_output
663 * Returns TRUE if the record type writes something to the dc. Used by
664 * PlayEnhMetaFileRecord to determine whether it needs to update the
665 * dc's xform when in win9x mode.
667 * FIXME: need to test which records should be here.
669 static BOOL emr_produces_output(int type)
675 case EMR_POLYBEZIERTO:
677 case EMR_POLYPOLYLINE:
678 case EMR_POLYPOLYGON:
681 case EMR_EXCLUDECLIPRECT:
682 case EMR_INTERSECTCLIPRECT:
683 case EMR_SELECTOBJECT:
691 case EMR_EXTFLOODFILL:
703 case EMR_SETDIBITSTODEVICE:
704 case EMR_STRETCHDIBITS:
705 case EMR_EXTTEXTOUTA:
706 case EMR_EXTTEXTOUTW:
707 case EMR_POLYBEZIER16:
710 case EMR_POLYBEZIERTO16:
711 case EMR_POLYLINETO16:
712 case EMR_POLYPOLYLINE16:
713 case EMR_POLYPOLYGON16:
715 case EMR_POLYTEXTOUTA:
716 case EMR_POLYTEXTOUTW:
717 case EMR_SMALLTEXTOUT:
719 case EMR_TRANSPARENTBLT:
727 /*****************************************************************************
728 * PlayEnhMetaFileRecord (GDI32.@)
730 * Render a single enhanced metafile record in the device context hdc.
733 * TRUE (non zero) on success, FALSE on error.
735 * Many unimplemented records.
736 * No error handling on record play failures (ie checking return codes)
739 * WinNT actually updates the current world transform in this function
740 * whereas Win9x does not.
742 BOOL WINAPI PlayEnhMetaFileRecord(
743 HDC hdc, /* [in] device context in which to render EMF record */
744 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
745 const ENHMETARECORD *mr, /* [in] EMF record to render */
746 UINT handles /* [in] size of handle array */
751 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
753 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
754 hdc, handletable, mr, handles);
755 if (!mr) return FALSE;
759 /* In Win9x mode we update the xform if the record will produce output */
760 if ( IS_WIN9X() && emr_produces_output(type) )
761 EMF_Update_MF_Xform(hdc, info);
763 TRACE("record %s\n", get_emr_name(type));
772 const EMRGDICOMMENT *lpGdiComment = (const EMRGDICOMMENT *)mr;
773 /* In an enhanced metafile, there can be both public and private GDI comments */
774 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
779 const EMRSETMAPMODE *pSetMapMode = (const EMRSETMAPMODE *)mr;
781 if (info->state.mode == pSetMapMode->iMode &&
782 (info->state.mode == MM_ISOTROPIC || info->state.mode == MM_ANISOTROPIC))
784 info->state.mode = pSetMapMode->iMode;
785 EMF_SetMapMode(hdc, info);
790 const EMRSETBKMODE *pSetBkMode = (const EMRSETBKMODE *)mr;
791 SetBkMode(hdc, pSetBkMode->iMode);
796 const EMRSETBKCOLOR *pSetBkColor = (const EMRSETBKCOLOR *)mr;
797 SetBkColor(hdc, pSetBkColor->crColor);
800 case EMR_SETPOLYFILLMODE:
802 const EMRSETPOLYFILLMODE *pSetPolyFillMode = (const EMRSETPOLYFILLMODE *)mr;
803 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
808 const EMRSETROP2 *pSetROP2 = (const EMRSETROP2 *)mr;
809 SetROP2(hdc, pSetROP2->iMode);
812 case EMR_SETSTRETCHBLTMODE:
814 const EMRSETSTRETCHBLTMODE *pSetStretchBltMode = (const EMRSETSTRETCHBLTMODE *)mr;
815 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
818 case EMR_SETTEXTALIGN:
820 const EMRSETTEXTALIGN *pSetTextAlign = (const EMRSETTEXTALIGN *)mr;
821 SetTextAlign(hdc, pSetTextAlign->iMode);
824 case EMR_SETTEXTCOLOR:
826 const EMRSETTEXTCOLOR *pSetTextColor = (const EMRSETTEXTCOLOR *)mr;
827 SetTextColor(hdc, pSetTextColor->crColor);
838 const EMRRESTOREDC *pRestoreDC = (const EMRRESTOREDC *)mr;
839 TRACE("EMR_RESTORE: %d\n", pRestoreDC->iRelative);
840 if (RestoreDC( hdc, pRestoreDC->iRelative ))
841 EMF_RestoreDC( info, pRestoreDC->iRelative );
844 case EMR_INTERSECTCLIPRECT:
846 const EMRINTERSECTCLIPRECT *pClipRect = (const EMRINTERSECTCLIPRECT *)mr;
847 TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
848 pClipRect->rclClip.left, pClipRect->rclClip.top,
849 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
850 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
851 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
854 case EMR_SELECTOBJECT:
856 const EMRSELECTOBJECT *pSelectObject = (const EMRSELECTOBJECT *)mr;
857 if( pSelectObject->ihObject & 0x80000000 ) {
858 /* High order bit is set - it's a stock object
859 * Strip the high bit to get the index.
860 * See MSDN article Q142319
862 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
865 /* High order bit wasn't set - not a stock object
868 (handletable->objectHandle)[pSelectObject->ihObject] );
872 case EMR_DELETEOBJECT:
874 const EMRDELETEOBJECT *pDeleteObject = (const EMRDELETEOBJECT *)mr;
875 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
876 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
879 case EMR_SETWINDOWORGEX:
881 const EMRSETWINDOWORGEX *pSetWindowOrgEx = (const EMRSETWINDOWORGEX *)mr;
883 info->state.wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
884 info->state.wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
886 TRACE("SetWindowOrgEx: %d,%d\n", info->state.wndOrgX, info->state.wndOrgY);
889 case EMR_SETWINDOWEXTEX:
891 const EMRSETWINDOWEXTEX *pSetWindowExtEx = (const EMRSETWINDOWEXTEX *)mr;
893 if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
895 info->state.wndExtX = pSetWindowExtEx->szlExtent.cx;
896 info->state.wndExtY = pSetWindowExtEx->szlExtent.cy;
897 if (info->state.mode == MM_ISOTROPIC)
898 EMF_FixIsotropic(hdc, info);
900 TRACE("SetWindowExtEx: %d,%d\n",info->state.wndExtX, info->state.wndExtY);
903 case EMR_SETVIEWPORTORGEX:
905 const EMRSETVIEWPORTORGEX *pSetViewportOrgEx = (const EMRSETVIEWPORTORGEX *)mr;
907 info->state.vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
908 info->state.vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
909 TRACE("SetViewportOrgEx: %d,%d\n", info->state.vportOrgX, info->state.vportOrgY);
912 case EMR_SETVIEWPORTEXTEX:
914 const EMRSETVIEWPORTEXTEX *pSetViewportExtEx = (const EMRSETVIEWPORTEXTEX *)mr;
916 if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
918 info->state.vportExtX = pSetViewportExtEx->szlExtent.cx;
919 info->state.vportExtY = pSetViewportExtEx->szlExtent.cy;
920 if (info->state.mode == MM_ISOTROPIC)
921 EMF_FixIsotropic(hdc, info);
922 TRACE("SetViewportExtEx: %d,%d\n", info->state.vportExtX, info->state.vportExtY);
927 const EMRCREATEPEN *pCreatePen = (const EMRCREATEPEN *)mr;
928 (handletable->objectHandle)[pCreatePen->ihPen] =
929 CreatePenIndirect(&pCreatePen->lopn);
932 case EMR_EXTCREATEPEN:
934 const EMREXTCREATEPEN *pPen = (const EMREXTCREATEPEN *)mr;
936 lb.lbStyle = pPen->elp.elpBrushStyle;
937 lb.lbColor = pPen->elp.elpColor;
938 lb.lbHatch = pPen->elp.elpHatch;
940 if(pPen->offBmi || pPen->offBits)
941 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
943 (handletable->objectHandle)[pPen->ihPen] =
944 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
945 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
948 case EMR_CREATEBRUSHINDIRECT:
950 const EMRCREATEBRUSHINDIRECT *pBrush = (const EMRCREATEBRUSHINDIRECT *)mr;
952 brush.lbStyle = pBrush->lb.lbStyle;
953 brush.lbColor = pBrush->lb.lbColor;
954 brush.lbHatch = pBrush->lb.lbHatch;
955 (handletable->objectHandle)[pBrush->ihBrush] = CreateBrushIndirect(&brush);
958 case EMR_EXTCREATEFONTINDIRECTW:
960 const EMREXTCREATEFONTINDIRECTW *pFont = (const EMREXTCREATEFONTINDIRECTW *)mr;
961 (handletable->objectHandle)[pFont->ihFont] =
962 CreateFontIndirectW(&pFont->elfw.elfLogFont);
967 const EMRMOVETOEX *pMoveToEx = (const EMRMOVETOEX *)mr;
968 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
973 const EMRLINETO *pLineTo = (const EMRLINETO *)mr;
974 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
979 const EMRRECTANGLE *pRect = (const EMRRECTANGLE *)mr;
980 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
981 pRect->rclBox.right, pRect->rclBox.bottom);
986 const EMRELLIPSE *pEllipse = (const EMRELLIPSE *)mr;
987 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
988 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
993 const EMRPOLYGON16 *pPoly = (const EMRPOLYGON16 *)mr;
994 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
995 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
996 pPoly->cpts * sizeof(POINT) );
998 for(i = 0; i < pPoly->cpts; i++)
1000 pts[i].x = pPoly->apts[i].x;
1001 pts[i].y = pPoly->apts[i].y;
1003 Polygon(hdc, pts, pPoly->cpts);
1004 HeapFree( GetProcessHeap(), 0, pts );
1007 case EMR_POLYLINE16:
1009 const EMRPOLYLINE16 *pPoly = (const EMRPOLYLINE16 *)mr;
1010 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
1011 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1012 pPoly->cpts * sizeof(POINT) );
1014 for(i = 0; i < pPoly->cpts; i++)
1016 pts[i].x = pPoly->apts[i].x;
1017 pts[i].y = pPoly->apts[i].y;
1019 Polyline(hdc, pts, pPoly->cpts);
1020 HeapFree( GetProcessHeap(), 0, pts );
1023 case EMR_POLYLINETO16:
1025 const EMRPOLYLINETO16 *pPoly = (const EMRPOLYLINETO16 *)mr;
1026 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
1027 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1028 pPoly->cpts * sizeof(POINT) );
1030 for(i = 0; i < pPoly->cpts; i++)
1032 pts[i].x = pPoly->apts[i].x;
1033 pts[i].y = pPoly->apts[i].y;
1035 PolylineTo(hdc, pts, pPoly->cpts);
1036 HeapFree( GetProcessHeap(), 0, pts );
1039 case EMR_POLYBEZIER16:
1041 const EMRPOLYBEZIER16 *pPoly = (const EMRPOLYBEZIER16 *)mr;
1042 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1043 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1044 pPoly->cpts * sizeof(POINT) );
1046 for(i = 0; i < pPoly->cpts; i++)
1048 pts[i].x = pPoly->apts[i].x;
1049 pts[i].y = pPoly->apts[i].y;
1051 PolyBezier(hdc, pts, pPoly->cpts);
1052 HeapFree( GetProcessHeap(), 0, pts );
1055 case EMR_POLYBEZIERTO16:
1057 const EMRPOLYBEZIERTO16 *pPoly = (const EMRPOLYBEZIERTO16 *)mr;
1058 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1059 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1060 pPoly->cpts * sizeof(POINT) );
1062 for(i = 0; i < pPoly->cpts; i++)
1064 pts[i].x = pPoly->apts[i].x;
1065 pts[i].y = pPoly->apts[i].y;
1067 PolyBezierTo(hdc, pts, pPoly->cpts);
1068 HeapFree( GetProcessHeap(), 0, pts );
1071 case EMR_POLYPOLYGON16:
1073 const EMRPOLYPOLYGON16 *pPolyPoly = (const EMRPOLYPOLYGON16 *)mr;
1074 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1075 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1077 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1078 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1080 for(i = 0; i < pPolyPoly->cpts; i++)
1082 pts[i].x = pts16[i].x;
1083 pts[i].y = pts16[i].y;
1085 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1086 HeapFree( GetProcessHeap(), 0, pts );
1089 case EMR_POLYPOLYLINE16:
1091 const EMRPOLYPOLYLINE16 *pPolyPoly = (const EMRPOLYPOLYLINE16 *)mr;
1092 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1093 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1095 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1096 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1098 for(i = 0; i < pPolyPoly->cpts; i++)
1100 pts[i].x = pts16[i].x;
1101 pts[i].y = pts16[i].y;
1103 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1104 HeapFree( GetProcessHeap(), 0, pts );
1108 case EMR_STRETCHDIBITS:
1110 const EMRSTRETCHDIBITS *pStretchDIBits = (const EMRSTRETCHDIBITS *)mr;
1113 pStretchDIBits->xDest,
1114 pStretchDIBits->yDest,
1115 pStretchDIBits->cxDest,
1116 pStretchDIBits->cyDest,
1117 pStretchDIBits->xSrc,
1118 pStretchDIBits->ySrc,
1119 pStretchDIBits->cxSrc,
1120 pStretchDIBits->cySrc,
1121 (const BYTE *)mr + pStretchDIBits->offBitsSrc,
1122 (const BITMAPINFO *)((const BYTE *)mr + pStretchDIBits->offBmiSrc),
1123 pStretchDIBits->iUsageSrc,
1124 pStretchDIBits->dwRop);
1128 case EMR_EXTTEXTOUTA:
1130 const EMREXTTEXTOUTA *pExtTextOutA = (const EMREXTTEXTOUTA *)mr;
1132 const INT *dx = NULL;
1134 rc.left = pExtTextOutA->emrtext.rcl.left;
1135 rc.top = pExtTextOutA->emrtext.rcl.top;
1136 rc.right = pExtTextOutA->emrtext.rcl.right;
1137 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
1138 TRACE("EMR_EXTTEXTOUTA: x,y = %d, %d. rect = %d, %d - %d, %d. flags %08x\n",
1139 pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1140 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutA->emrtext.fOptions);
1142 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1143 * These files can be enumerated and played under Win98 just
1144 * fine, but at least Win2k chokes on them.
1146 if (pExtTextOutA->emrtext.offDx)
1147 dx = (const INT *)((const BYTE *)mr + pExtTextOutA->emrtext.offDx);
1149 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1150 pExtTextOutA->emrtext.fOptions, &rc,
1151 (LPCSTR)((const BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
1156 case EMR_EXTTEXTOUTW:
1158 const EMREXTTEXTOUTW *pExtTextOutW = (const EMREXTTEXTOUTW *)mr;
1160 const INT *dx = NULL;
1162 rc.left = pExtTextOutW->emrtext.rcl.left;
1163 rc.top = pExtTextOutW->emrtext.rcl.top;
1164 rc.right = pExtTextOutW->emrtext.rcl.right;
1165 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
1166 TRACE("EMR_EXTTEXTOUTW: x,y = %d, %d. rect = %d, %d - %d, %d. flags %08x\n",
1167 pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1168 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutW->emrtext.fOptions);
1170 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1171 * These files can be enumerated and played under Win98 just
1172 * fine, but at least Win2k chokes on them.
1174 if (pExtTextOutW->emrtext.offDx)
1175 dx = (const INT *)((const BYTE *)mr + pExtTextOutW->emrtext.offDx);
1177 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1178 pExtTextOutW->emrtext.fOptions, &rc,
1179 (LPCWSTR)((const BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
1184 case EMR_CREATEPALETTE:
1186 const EMRCREATEPALETTE *lpCreatePal = (const EMRCREATEPALETTE *)mr;
1188 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
1189 CreatePalette( &lpCreatePal->lgpl );
1194 case EMR_SELECTPALETTE:
1196 const EMRSELECTPALETTE *lpSelectPal = (const EMRSELECTPALETTE *)mr;
1198 if( lpSelectPal->ihPal & 0x80000000 ) {
1199 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
1201 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
1206 case EMR_REALIZEPALETTE:
1208 RealizePalette( hdc );
1212 case EMR_EXTSELECTCLIPRGN:
1214 const EMREXTSELECTCLIPRGN *lpRgn = (const EMREXTSELECTCLIPRGN *)mr;
1217 if (mr->nSize >= sizeof(*lpRgn) + sizeof(RGNDATAHEADER))
1218 hRgn = ExtCreateRegion( &info->init_transform, 0, (RGNDATA *)lpRgn->RgnData );
1220 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
1221 /* ExtSelectClipRgn created a copy of the region */
1226 case EMR_SETMETARGN:
1232 case EMR_SETWORLDTRANSFORM:
1234 const EMRSETWORLDTRANSFORM *lpXfrm = (const EMRSETWORLDTRANSFORM *)mr;
1235 info->state.world_transform = lpXfrm->xform;
1239 case EMR_POLYBEZIER:
1241 const EMRPOLYBEZIER *lpPolyBez = (const EMRPOLYBEZIER *)mr;
1242 PolyBezier(hdc, (const POINT*)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
1248 const EMRPOLYGON *lpPoly = (const EMRPOLYGON *)mr;
1249 Polygon( hdc, (const POINT*)lpPoly->aptl, (UINT)lpPoly->cptl );
1255 const EMRPOLYLINE *lpPolyLine = (const EMRPOLYLINE *)mr;
1256 Polyline(hdc, (const POINT*)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
1260 case EMR_POLYBEZIERTO:
1262 const EMRPOLYBEZIERTO *lpPolyBezierTo = (const EMRPOLYBEZIERTO *)mr;
1263 PolyBezierTo( hdc, (const POINT*)lpPolyBezierTo->aptl,
1264 (UINT)lpPolyBezierTo->cptl );
1268 case EMR_POLYLINETO:
1270 const EMRPOLYLINETO *lpPolyLineTo = (const EMRPOLYLINETO *)mr;
1271 PolylineTo( hdc, (const POINT*)lpPolyLineTo->aptl,
1272 (UINT)lpPolyLineTo->cptl );
1276 case EMR_POLYPOLYLINE:
1278 const EMRPOLYPOLYLINE *pPolyPolyline = (const EMRPOLYPOLYLINE *)mr;
1279 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1281 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
1282 pPolyPolyline->nPolys),
1283 pPolyPolyline->aPolyCounts,
1284 pPolyPolyline->nPolys );
1289 case EMR_POLYPOLYGON:
1291 const EMRPOLYPOLYGON *pPolyPolygon = (const EMRPOLYPOLYGON *)mr;
1293 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1295 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
1296 pPolyPolygon->nPolys),
1297 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
1301 case EMR_SETBRUSHORGEX:
1303 const EMRSETBRUSHORGEX *lpSetBrushOrgEx = (const EMRSETBRUSHORGEX *)mr;
1306 (INT)lpSetBrushOrgEx->ptlOrigin.x,
1307 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1315 const EMRSETPIXELV *lpSetPixelV = (const EMRSETPIXELV *)mr;
1318 (INT)lpSetPixelV->ptlPixel.x,
1319 (INT)lpSetPixelV->ptlPixel.y,
1320 lpSetPixelV->crColor );
1325 case EMR_SETMAPPERFLAGS:
1327 const EMRSETMAPPERFLAGS *lpSetMapperFlags = (const EMRSETMAPPERFLAGS *)mr;
1329 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1334 case EMR_SETCOLORADJUSTMENT:
1336 const EMRSETCOLORADJUSTMENT *lpSetColorAdjust = (const EMRSETCOLORADJUSTMENT *)mr;
1338 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1343 case EMR_OFFSETCLIPRGN:
1345 const EMROFFSETCLIPRGN *lpOffsetClipRgn = (const EMROFFSETCLIPRGN *)mr;
1348 (INT)lpOffsetClipRgn->ptlOffset.x,
1349 (INT)lpOffsetClipRgn->ptlOffset.y );
1350 FIXME("OffsetClipRgn\n");
1355 case EMR_EXCLUDECLIPRECT:
1357 const EMREXCLUDECLIPRECT *lpExcludeClipRect = (const EMREXCLUDECLIPRECT *)mr;
1359 ExcludeClipRect( hdc,
1360 lpExcludeClipRect->rclClip.left,
1361 lpExcludeClipRect->rclClip.top,
1362 lpExcludeClipRect->rclClip.right,
1363 lpExcludeClipRect->rclClip.bottom );
1364 FIXME("ExcludeClipRect\n");
1369 case EMR_SCALEVIEWPORTEXTEX:
1371 const EMRSCALEVIEWPORTEXTEX *lpScaleViewportExtEx = (const EMRSCALEVIEWPORTEXTEX *)mr;
1373 if ((info->state.mode != MM_ISOTROPIC) && (info->state.mode != MM_ANISOTROPIC))
1375 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1376 !lpScaleViewportExtEx->yNum || !lpScaleViewportExtEx->yDenom)
1378 info->state.vportExtX = MulDiv(info->state.vportExtX, lpScaleViewportExtEx->xNum,
1379 lpScaleViewportExtEx->xDenom);
1380 info->state.vportExtY = MulDiv(info->state.vportExtY, lpScaleViewportExtEx->yNum,
1381 lpScaleViewportExtEx->yDenom);
1382 if (info->state.vportExtX == 0) info->state.vportExtX = 1;
1383 if (info->state.vportExtY == 0) info->state.vportExtY = 1;
1384 if (info->state.mode == MM_ISOTROPIC)
1385 EMF_FixIsotropic(hdc, info);
1387 TRACE("EMRSCALEVIEWPORTEXTEX %d/%d %d/%d\n",
1388 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1389 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1394 case EMR_SCALEWINDOWEXTEX:
1396 const EMRSCALEWINDOWEXTEX *lpScaleWindowExtEx = (const EMRSCALEWINDOWEXTEX *)mr;
1398 if ((info->state.mode != MM_ISOTROPIC) && (info->state.mode != MM_ANISOTROPIC))
1400 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1401 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1403 info->state.wndExtX = MulDiv(info->state.wndExtX, lpScaleWindowExtEx->xNum,
1404 lpScaleWindowExtEx->xDenom);
1405 info->state.wndExtY = MulDiv(info->state.wndExtY, lpScaleWindowExtEx->yNum,
1406 lpScaleWindowExtEx->yDenom);
1407 if (info->state.wndExtX == 0) info->state.wndExtX = 1;
1408 if (info->state.wndExtY == 0) info->state.wndExtY = 1;
1409 if (info->state.mode == MM_ISOTROPIC)
1410 EMF_FixIsotropic(hdc, info);
1412 TRACE("EMRSCALEWINDOWEXTEX %d/%d %d/%d\n",
1413 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1414 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1419 case EMR_MODIFYWORLDTRANSFORM:
1421 const EMRMODIFYWORLDTRANSFORM *lpModifyWorldTrans = (const EMRMODIFYWORLDTRANSFORM *)mr;
1423 switch(lpModifyWorldTrans->iMode) {
1425 info->state.world_transform.eM11 = info->state.world_transform.eM22 = 1;
1426 info->state.world_transform.eM12 = info->state.world_transform.eM21 = 0;
1427 info->state.world_transform.eDx = info->state.world_transform.eDy = 0;
1429 case MWT_LEFTMULTIPLY:
1430 CombineTransform(&info->state.world_transform, &lpModifyWorldTrans->xform,
1431 &info->state.world_transform);
1433 case MWT_RIGHTMULTIPLY:
1434 CombineTransform(&info->state.world_transform, &info->state.world_transform,
1435 &lpModifyWorldTrans->xform);
1438 FIXME("Unknown imode %d\n", lpModifyWorldTrans->iMode);
1446 const EMRANGLEARC *lpAngleArc = (const EMRANGLEARC *)mr;
1449 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1450 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1451 lpAngleArc->eSweepAngle );
1458 const EMRROUNDRECT *lpRoundRect = (const EMRROUNDRECT *)mr;
1461 lpRoundRect->rclBox.left,
1462 lpRoundRect->rclBox.top,
1463 lpRoundRect->rclBox.right,
1464 lpRoundRect->rclBox.bottom,
1465 lpRoundRect->szlCorner.cx,
1466 lpRoundRect->szlCorner.cy );
1473 const EMRARC *lpArc = (const EMRARC *)mr;
1476 (INT)lpArc->rclBox.left,
1477 (INT)lpArc->rclBox.top,
1478 (INT)lpArc->rclBox.right,
1479 (INT)lpArc->rclBox.bottom,
1480 (INT)lpArc->ptlStart.x,
1481 (INT)lpArc->ptlStart.y,
1482 (INT)lpArc->ptlEnd.x,
1483 (INT)lpArc->ptlEnd.y );
1490 const EMRCHORD *lpChord = (const EMRCHORD *)mr;
1493 (INT)lpChord->rclBox.left,
1494 (INT)lpChord->rclBox.top,
1495 (INT)lpChord->rclBox.right,
1496 (INT)lpChord->rclBox.bottom,
1497 (INT)lpChord->ptlStart.x,
1498 (INT)lpChord->ptlStart.y,
1499 (INT)lpChord->ptlEnd.x,
1500 (INT)lpChord->ptlEnd.y );
1507 const EMRPIE *lpPie = (const EMRPIE *)mr;
1510 (INT)lpPie->rclBox.left,
1511 (INT)lpPie->rclBox.top,
1512 (INT)lpPie->rclBox.right,
1513 (INT)lpPie->rclBox.bottom,
1514 (INT)lpPie->ptlStart.x,
1515 (INT)lpPie->ptlStart.y,
1516 (INT)lpPie->ptlEnd.x,
1517 (INT)lpPie->ptlEnd.y );
1524 const EMRARC *lpArcTo = (const EMRARC *)mr;
1527 (INT)lpArcTo->rclBox.left,
1528 (INT)lpArcTo->rclBox.top,
1529 (INT)lpArcTo->rclBox.right,
1530 (INT)lpArcTo->rclBox.bottom,
1531 (INT)lpArcTo->ptlStart.x,
1532 (INT)lpArcTo->ptlStart.y,
1533 (INT)lpArcTo->ptlEnd.x,
1534 (INT)lpArcTo->ptlEnd.y );
1539 case EMR_EXTFLOODFILL:
1541 const EMREXTFLOODFILL *lpExtFloodFill = (const EMREXTFLOODFILL *)mr;
1544 (INT)lpExtFloodFill->ptlStart.x,
1545 (INT)lpExtFloodFill->ptlStart.y,
1546 lpExtFloodFill->crColor,
1547 (UINT)lpExtFloodFill->iMode );
1554 const EMRPOLYDRAW *lpPolyDraw = (const EMRPOLYDRAW *)mr;
1556 (const POINT*)lpPolyDraw->aptl,
1557 lpPolyDraw->abTypes,
1558 (INT)lpPolyDraw->cptl );
1563 case EMR_SETARCDIRECTION:
1565 const EMRSETARCDIRECTION *lpSetArcDirection = (const EMRSETARCDIRECTION *)mr;
1566 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1570 case EMR_SETMITERLIMIT:
1572 const EMRSETMITERLIMIT *lpSetMiterLimit = (const EMRSETMITERLIMIT *)mr;
1573 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1589 case EMR_CLOSEFIGURE:
1597 /*const EMRFILLPATH lpFillPath = (const EMRFILLPATH *)mr;*/
1602 case EMR_STROKEANDFILLPATH:
1604 /*const EMRSTROKEANDFILLPATH lpStrokeAndFillPath = (const EMRSTROKEANDFILLPATH *)mr;*/
1605 StrokeAndFillPath( hdc );
1609 case EMR_STROKEPATH:
1611 /*const EMRSTROKEPATH lpStrokePath = (const EMRSTROKEPATH *)mr;*/
1616 case EMR_FLATTENPATH:
1628 case EMR_SELECTCLIPPATH:
1630 const EMRSELECTCLIPPATH *lpSelectClipPath = (const EMRSELECTCLIPPATH *)mr;
1631 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1641 case EMR_CREATECOLORSPACE:
1643 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1644 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1645 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1649 case EMR_SETCOLORSPACE:
1651 const EMRSETCOLORSPACE *lpSetColorSpace = (const EMRSETCOLORSPACE *)mr;
1653 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1657 case EMR_DELETECOLORSPACE:
1659 const EMRDELETECOLORSPACE *lpDeleteColorSpace = (const EMRDELETECOLORSPACE *)mr;
1660 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1664 case EMR_SETICMMODE:
1666 const EMRSETICMMODE *lpSetICMMode = (const EMRSETICMMODE *)mr;
1667 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1671 case EMR_PIXELFORMAT:
1674 const EMRPIXELFORMAT *lpPixelFormat = (const EMRPIXELFORMAT *)mr;
1676 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1677 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1682 case EMR_SETPALETTEENTRIES:
1684 const EMRSETPALETTEENTRIES *lpSetPaletteEntries = (const EMRSETPALETTEENTRIES *)mr;
1686 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1687 (UINT)lpSetPaletteEntries->iStart,
1688 (UINT)lpSetPaletteEntries->cEntries,
1689 lpSetPaletteEntries->aPalEntries );
1694 case EMR_RESIZEPALETTE:
1696 const EMRRESIZEPALETTE *lpResizePalette = (const EMRRESIZEPALETTE *)mr;
1698 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1699 (UINT)lpResizePalette->cEntries );
1704 case EMR_CREATEDIBPATTERNBRUSHPT:
1706 const EMRCREATEDIBPATTERNBRUSHPT *lpCreate = (const EMRCREATEDIBPATTERNBRUSHPT *)mr;
1707 LPVOID lpPackedStruct;
1709 /* Check that offsets and data are contained within the record
1710 * (including checking for wrap-arounds).
1712 if ( lpCreate->offBmi + lpCreate->cbBmi > mr->nSize
1713 || lpCreate->offBits + lpCreate->cbBits > mr->nSize
1714 || lpCreate->offBmi + lpCreate->cbBmi < lpCreate->offBmi
1715 || lpCreate->offBits + lpCreate->cbBits < lpCreate->offBits )
1717 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1721 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1722 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1723 lpCreate->cbBmi + lpCreate->cbBits );
1726 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1730 /* Now pack this structure */
1731 memcpy( lpPackedStruct,
1732 ((const BYTE *)lpCreate) + lpCreate->offBmi,
1734 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1735 ((const BYTE *)lpCreate) + lpCreate->offBits,
1738 (handletable->objectHandle)[lpCreate->ihBrush] =
1739 CreateDIBPatternBrushPt( lpPackedStruct,
1740 (UINT)lpCreate->iUsage );
1742 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1746 case EMR_CREATEMONOBRUSH:
1748 const EMRCREATEMONOBRUSH *pCreateMonoBrush = (const EMRCREATEMONOBRUSH *)mr;
1749 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pCreateMonoBrush->offBmi);
1752 /* Need to check if the bitmap is monochrome, and if the
1753 two colors are really black and white */
1754 if (pCreateMonoBrush->iUsage == DIB_PAL_MONO)
1758 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1759 * aligned to 32 rather than 16 bits.
1762 bm.bmWidth = pbi->bmiHeader.biWidth;
1763 bm.bmHeight = abs(pbi->bmiHeader.biHeight);
1764 bm.bmWidthBytes = 4 * ((pbi->bmiHeader.biWidth + 31) / 32);
1765 bm.bmPlanes = pbi->bmiHeader.biPlanes;
1766 bm.bmBitsPixel = pbi->bmiHeader.biBitCount;
1767 bm.bmBits = (BYTE *)mr + pCreateMonoBrush->offBits;
1768 hBmp = CreateBitmapIndirect(&bm);
1770 else if (is_dib_monochrome(pbi))
1772 /* Top-down DIBs have a negative height */
1773 LONG height = pbi->bmiHeader.biHeight;
1775 hBmp = CreateBitmap(pbi->bmiHeader.biWidth, abs(height), 1, 1, NULL);
1776 SetDIBits(hdc, hBmp, 0, pbi->bmiHeader.biHeight,
1777 (const BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1781 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1782 (const BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1785 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1787 /* CreatePatternBrush created a copy of the bitmap */
1794 const EMRBITBLT *pBitBlt = (const EMRBITBLT *)mr;
1796 if(pBitBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1797 PatBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1799 } else { /* BitBlt */
1800 HDC hdcSrc = CreateCompatibleDC(hdc);
1801 HBRUSH hBrush, hBrushOld;
1802 HBITMAP hBmp = 0, hBmpOld = 0;
1803 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pBitBlt->offBmiSrc);
1805 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1807 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1808 hBrushOld = SelectObject(hdcSrc, hBrush);
1809 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1810 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1811 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1812 SelectObject(hdcSrc, hBrushOld);
1813 DeleteObject(hBrush);
1815 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1816 (const BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1817 hBmpOld = SelectObject(hdcSrc, hBmp);
1819 BitBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1820 hdcSrc, pBitBlt->xSrc, pBitBlt->ySrc, pBitBlt->dwRop);
1822 SelectObject(hdcSrc, hBmpOld);
1829 case EMR_STRETCHBLT:
1831 const EMRSTRETCHBLT *pStretchBlt = (const EMRSTRETCHBLT *)mr;
1833 TRACE("EMR_STRETCHBLT: %d, %d %dx%d -> %d, %d %dx%d. rop %08x offBitsSrc %d\n",
1834 pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1835 pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1836 pStretchBlt->dwRop, pStretchBlt->offBitsSrc);
1838 if(pStretchBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1839 PatBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1840 pStretchBlt->dwRop);
1841 } else { /* StretchBlt */
1842 HDC hdcSrc = CreateCompatibleDC(hdc);
1843 HBRUSH hBrush, hBrushOld;
1844 HBITMAP hBmp = 0, hBmpOld = 0;
1845 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pStretchBlt->offBmiSrc);
1847 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1849 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1850 hBrushOld = SelectObject(hdcSrc, hBrush);
1851 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1852 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1853 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1854 SelectObject(hdcSrc, hBrushOld);
1855 DeleteObject(hBrush);
1857 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1858 (const BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1859 hBmpOld = SelectObject(hdcSrc, hBmp);
1861 StretchBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1862 hdcSrc, pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1863 pStretchBlt->dwRop);
1865 SelectObject(hdcSrc, hBmpOld);
1872 case EMR_ALPHABLEND:
1874 const EMRALPHABLEND *pAlphaBlend = (const EMRALPHABLEND *)mr;
1876 TRACE("EMR_ALPHABLEND: %d, %d %dx%d -> %d, %d %dx%d. blendfn %08x offBitsSrc %d\n",
1877 pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1878 pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1879 pAlphaBlend->dwRop, pAlphaBlend->offBitsSrc);
1881 if(pAlphaBlend->offBmiSrc == 0) {
1882 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1884 HDC hdcSrc = CreateCompatibleDC(hdc);
1885 HBITMAP hBmp = 0, hBmpOld = 0;
1886 const BITMAPINFO *pbi = (const BITMAPINFO *)((const BYTE *)mr + pAlphaBlend->offBmiSrc);
1887 BLENDFUNCTION blendfn;
1890 SetWorldTransform(hdcSrc, &pAlphaBlend->xformSrc);
1892 hBmp = CreateDIBSection(hdc, pbi, pAlphaBlend->iUsageSrc, &bits, NULL, 0);
1893 memcpy(bits, (const BYTE *)mr + pAlphaBlend->offBitsSrc, pAlphaBlend->cbBitsSrc);
1894 hBmpOld = SelectObject(hdcSrc, hBmp);
1896 blendfn.BlendOp = (pAlphaBlend->dwRop >> 24) & 0xff;
1897 blendfn.BlendFlags = (pAlphaBlend->dwRop >> 16) & 0xff;
1898 blendfn.SourceConstantAlpha = (pAlphaBlend->dwRop >> 8) & 0xff;
1899 blendfn.AlphaFormat = (pAlphaBlend->dwRop) & 0xff;
1901 GdiAlphaBlend(hdc, pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1902 hdcSrc, pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1905 SelectObject(hdcSrc, hBmpOld);
1914 const EMRMASKBLT *pMaskBlt = (const EMRMASKBLT *)mr;
1915 HDC hdcSrc = CreateCompatibleDC(hdc);
1916 HBRUSH hBrush, hBrushOld;
1917 HBITMAP hBmp, hBmpOld, hBmpMask;
1918 const BITMAPINFO *pbi;
1920 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1922 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1923 hBrushOld = SelectObject(hdcSrc, hBrush);
1924 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1925 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1926 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1927 SelectObject(hdcSrc, hBrushOld);
1928 DeleteObject(hBrush);
1930 pbi = (const BITMAPINFO *)((const BYTE *)mr + pMaskBlt->offBmiMask);
1931 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1933 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1934 (const BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1936 pbi = (const BITMAPINFO *)((const BYTE *)mr + pMaskBlt->offBmiSrc);
1937 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1938 (const BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1939 hBmpOld = SelectObject(hdcSrc, hBmp);
1952 SelectObject(hdcSrc, hBmpOld);
1954 DeleteObject(hBmpMask);
1961 const EMRPLGBLT *pPlgBlt = (const EMRPLGBLT *)mr;
1962 HDC hdcSrc = CreateCompatibleDC(hdc);
1963 HBRUSH hBrush, hBrushOld;
1964 HBITMAP hBmp, hBmpOld, hBmpMask;
1965 const BITMAPINFO *pbi;
1968 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1970 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1971 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1972 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1974 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1975 hBrushOld = SelectObject(hdcSrc, hBrush);
1976 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1977 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1978 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1979 SelectObject(hdcSrc, hBrushOld);
1980 DeleteObject(hBrush);
1982 pbi = (const BITMAPINFO *)((const BYTE *)mr + pPlgBlt->offBmiMask);
1983 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1985 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1986 (const BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1988 pbi = (const BITMAPINFO *)((const BYTE *)mr + pPlgBlt->offBmiSrc);
1989 hBmp = CreateDIBitmap(hdc, (const BITMAPINFOHEADER *)pbi, CBM_INIT,
1990 (const BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1991 hBmpOld = SelectObject(hdcSrc, hBmp);
2002 SelectObject(hdcSrc, hBmpOld);
2004 DeleteObject(hBmpMask);
2009 case EMR_SETDIBITSTODEVICE:
2011 const EMRSETDIBITSTODEVICE *pSetDIBitsToDevice = (const EMRSETDIBITSTODEVICE *)mr;
2013 SetDIBitsToDevice(hdc,
2014 pSetDIBitsToDevice->xDest,
2015 pSetDIBitsToDevice->yDest,
2016 pSetDIBitsToDevice->cxSrc,
2017 pSetDIBitsToDevice->cySrc,
2018 pSetDIBitsToDevice->xSrc,
2019 pSetDIBitsToDevice->ySrc,
2020 pSetDIBitsToDevice->iStartScan,
2021 pSetDIBitsToDevice->cScans,
2022 (const BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
2023 (const BITMAPINFO *)((const BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
2024 pSetDIBitsToDevice->iUsageSrc);
2028 case EMR_POLYTEXTOUTA:
2030 const EMRPOLYTEXTOUTA *pPolyTextOutA = (const EMRPOLYTEXTOUTA *)mr;
2031 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
2033 XFORM xform, xformOld;
2036 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
2037 GetWorldTransform(hdc, &xformOld);
2039 xform.eM11 = pPolyTextOutA->exScale;
2042 xform.eM22 = pPolyTextOutA->eyScale;
2045 SetWorldTransform(hdc, &xform);
2047 /* Set up POLYTEXTA structures */
2048 for(i = 0; i < pPolyTextOutA->cStrings; i++)
2050 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
2051 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
2052 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
2053 polytextA[i].lpstr = (LPCSTR)((const BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
2054 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
2055 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
2056 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
2057 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
2058 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
2059 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
2061 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
2062 HeapFree(GetProcessHeap(), 0, polytextA);
2064 SetWorldTransform(hdc, &xformOld);
2065 SetGraphicsMode(hdc, gModeOld);
2069 case EMR_POLYTEXTOUTW:
2071 const EMRPOLYTEXTOUTW *pPolyTextOutW = (const EMRPOLYTEXTOUTW *)mr;
2072 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
2074 XFORM xform, xformOld;
2077 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
2078 GetWorldTransform(hdc, &xformOld);
2080 xform.eM11 = pPolyTextOutW->exScale;
2083 xform.eM22 = pPolyTextOutW->eyScale;
2086 SetWorldTransform(hdc, &xform);
2088 /* Set up POLYTEXTW structures */
2089 for(i = 0; i < pPolyTextOutW->cStrings; i++)
2091 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
2092 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
2093 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
2094 polytextW[i].lpstr = (LPCWSTR)((const BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
2095 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
2096 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
2097 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
2098 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
2099 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
2100 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
2102 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
2103 HeapFree(GetProcessHeap(), 0, polytextW);
2105 SetWorldTransform(hdc, &xformOld);
2106 SetGraphicsMode(hdc, gModeOld);
2112 const EMRFILLRGN *pFillRgn = (const EMRFILLRGN *)mr;
2113 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
2116 (handletable->objectHandle)[pFillRgn->ihBrush]);
2123 const EMRFRAMERGN *pFrameRgn = (const EMRFRAMERGN *)mr;
2124 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
2127 (handletable->objectHandle)[pFrameRgn->ihBrush],
2128 pFrameRgn->szlStroke.cx,
2129 pFrameRgn->szlStroke.cy);
2136 const EMRINVERTRGN *pInvertRgn = (const EMRINVERTRGN *)mr;
2137 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
2138 InvertRgn(hdc, hRgn);
2145 const EMRPAINTRGN *pPaintRgn = (const EMRPAINTRGN *)mr;
2146 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
2147 PaintRgn(hdc, hRgn);
2152 case EMR_SETTEXTJUSTIFICATION:
2154 const EMRSETTEXTJUSTIFICATION *pSetTextJust = (const EMRSETTEXTJUSTIFICATION *)mr;
2155 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
2161 const EMRSETLAYOUT *pSetLayout = (const EMRSETLAYOUT *)mr;
2162 SetLayout(hdc, pSetLayout->iMode);
2166 case EMR_POLYDRAW16:
2168 case EMR_GLSBOUNDEDRECORD:
2169 case EMR_DRAWESCAPE :
2172 case EMR_SMALLTEXTOUT:
2173 case EMR_FORCEUFIMAPPING:
2174 case EMR_NAMEDESCAPE:
2175 case EMR_COLORCORRECTPALETTE:
2176 case EMR_SETICMPROFILEA:
2177 case EMR_SETICMPROFILEW:
2178 case EMR_TRANSPARENTBLT:
2179 case EMR_GRADIENTFILL:
2180 case EMR_SETLINKEDUFI:
2181 case EMR_COLORMATCHTOTARGETW:
2182 case EMR_CREATECOLORSPACEW:
2185 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2186 record then ignore and return TRUE. */
2187 FIXME("type %d is unimplemented\n", type);
2190 tmprc.left = tmprc.top = 0;
2191 tmprc.right = tmprc.bottom = 1000;
2192 LPtoDP(hdc, (POINT*)&tmprc, 2);
2193 TRACE("L:0,0 - 1000,1000 -> D:%d,%d - %d,%d\n", tmprc.left,
2194 tmprc.top, tmprc.right, tmprc.bottom);
2198 /* WinNT - update the transform (win9x updates when the next graphics output
2199 record is played). */
2200 EMF_Update_MF_Xform(hdc, info);
2207 /*****************************************************************************
2209 * EnumEnhMetaFile (GDI32.@)
2211 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2213 * record. Returns when either every record has been used or
2214 * when _EnhMetaFunc_ returns FALSE.
2218 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2225 * This function behaves differently in Win9x and WinNT.
2227 * In WinNT, the DC's world transform is updated as the EMF changes
2228 * the Window/Viewport Extent and Origin or it's world transform.
2229 * The actual Window/Viewport Extent and Origin are left untouched.
2231 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2232 * updates the scaling itself but only just before a record that
2233 * writes anything to the DC.
2235 * I'm not sure where the data (enum_emh_data) is stored in either
2236 * version. For this implementation, it is stored before the handle
2237 * table, but it could be stored in the DC, in the EMF handle or in
2241 BOOL WINAPI EnumEnhMetaFile(
2242 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
2243 HENHMETAFILE hmf, /* [in] EMF to walk */
2244 ENHMFENUMPROC callback, /* [in] callback function */
2245 LPVOID data, /* [in] optional data for callback function */
2246 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
2258 HBRUSH hBrush = NULL;
2261 enum_emh_data *info;
2262 SIZE vp_size, win_size;
2263 POINT vp_org, win_org;
2264 INT mapMode = MM_TEXT, old_align = 0, old_rop2 = 0, old_arcdir = 0, old_polyfill = 0, old_stretchblt = 0;
2265 COLORREF old_text_color = 0, old_bk_color = 0;
2269 SetLastError(ERROR_INVALID_PARAMETER);
2273 emh = EMF_GetEnhMetaHeader(hmf);
2275 SetLastError(ERROR_INVALID_HANDLE);
2279 info = HeapAlloc( GetProcessHeap(), 0,
2280 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
2283 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2286 info->state.wndOrgX = 0;
2287 info->state.wndOrgY = 0;
2288 info->state.wndExtX = 1;
2289 info->state.wndExtY = 1;
2290 info->state.vportOrgX = 0;
2291 info->state.vportOrgY = 0;
2292 info->state.vportExtX = 1;
2293 info->state.vportExtY = 1;
2294 info->state.world_transform.eM11 = info->state.world_transform.eM22 = 1;
2295 info->state.world_transform.eM12 = info->state.world_transform.eM21 = 0;
2296 info->state.world_transform.eDx = info->state.world_transform.eDy = 0;
2298 info->state.next = NULL;
2299 info->save_level = 0;
2300 info->saved_state = NULL;
2302 ht = (HANDLETABLE*) &info[1];
2303 ht->objectHandle[0] = hmf;
2304 for(i = 1; i < emh->nHandles; i++)
2305 ht->objectHandle[i] = NULL;
2309 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
2310 GetWorldTransform(hdc, &savedXform);
2311 GetViewportExtEx(hdc, &vp_size);
2312 GetWindowExtEx(hdc, &win_size);
2313 GetViewportOrgEx(hdc, &vp_org);
2314 GetWindowOrgEx(hdc, &win_org);
2315 mapMode = GetMapMode(hdc);
2318 hPen = GetCurrentObject(hdc, OBJ_PEN);
2319 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
2320 hFont = GetCurrentObject(hdc, OBJ_FONT);
2322 hRgn = CreateRectRgn(0, 0, 0, 0);
2323 if (!GetClipRgn(hdc, hRgn))
2329 old_text_color = SetTextColor(hdc, RGB(0,0,0));
2330 old_bk_color = SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
2331 old_align = SetTextAlign(hdc, 0);
2332 old_rop2 = SetROP2(hdc, R2_COPYPEN);
2333 old_arcdir = SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
2334 old_polyfill = SetPolyFillMode(hdc, ALTERNATE);
2335 old_stretchblt = SetStretchBltMode(hdc, BLACKONWHITE);
2338 info->state.mode = MM_TEXT;
2342 /* Win95 leaves the vp/win ext/org info alone */
2343 info->init_transform.eM11 = 1.0;
2344 info->init_transform.eM12 = 0.0;
2345 info->init_transform.eM21 = 0.0;
2346 info->init_transform.eM22 = 1.0;
2347 info->init_transform.eDx = 0.0;
2348 info->init_transform.eDy = 0.0;
2352 /* WinNT combines the vp/win ext/org info into a transform */
2353 double xscale, yscale;
2354 xscale = (double)vp_size.cx / (double)win_size.cx;
2355 yscale = (double)vp_size.cy / (double)win_size.cy;
2356 info->init_transform.eM11 = xscale;
2357 info->init_transform.eM12 = 0.0;
2358 info->init_transform.eM21 = 0.0;
2359 info->init_transform.eM22 = yscale;
2360 info->init_transform.eDx = (double)vp_org.x - xscale * (double)win_org.x;
2361 info->init_transform.eDy = (double)vp_org.y - yscale * (double)win_org.y;
2363 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
2366 if ( lpRect && WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
2368 double xSrcPixSize, ySrcPixSize, xscale, yscale;
2371 TRACE("rect: %d,%d - %d,%d. rclFrame: %d,%d - %d,%d\n",
2372 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
2373 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
2374 emh->rclFrame.bottom);
2376 xSrcPixSize = (double) emh->szlMillimeters.cx / emh->szlDevice.cx;
2377 ySrcPixSize = (double) emh->szlMillimeters.cy / emh->szlDevice.cy;
2378 xscale = (double) WIDTH(*lpRect) * 100.0 /
2379 WIDTH(emh->rclFrame) * xSrcPixSize;
2380 yscale = (double) HEIGHT(*lpRect) * 100.0 /
2381 HEIGHT(emh->rclFrame) * ySrcPixSize;
2382 TRACE("xscale = %f, yscale = %f\n", xscale, yscale);
2384 xform.eM11 = xscale;
2387 xform.eM22 = yscale;
2388 xform.eDx = (double) lpRect->left - (double) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
2389 xform.eDy = (double) lpRect->top - (double) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
2391 CombineTransform(&info->init_transform, &xform, &info->init_transform);
2394 /* WinNT resets the current vp/win org/ext */
2395 if ( !IS_WIN9X() && hdc )
2397 SetMapMode(hdc, MM_TEXT);
2398 SetWindowOrgEx(hdc, 0, 0, NULL);
2399 SetViewportOrgEx(hdc, 0, 0, NULL);
2400 EMF_Update_MF_Xform(hdc, info);
2405 while(ret && offset < emh->nBytes)
2407 emr = (ENHMETARECORD *)((char *)emh + offset);
2408 TRACE("Calling EnumFunc with record %s, size %d\n", get_emr_name(emr->iType), emr->nSize);
2409 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2410 offset += emr->nSize;
2415 SetStretchBltMode(hdc, old_stretchblt);
2416 SetPolyFillMode(hdc, old_polyfill);
2417 SetArcDirection(hdc, old_arcdir);
2418 SetROP2(hdc, old_rop2);
2419 SetTextAlign(hdc, old_align);
2420 SetBkColor(hdc, old_bk_color);
2421 SetTextColor(hdc, old_text_color);
2424 SelectObject(hdc, hBrush);
2425 SelectObject(hdc, hPen);
2426 SelectObject(hdc, hFont);
2427 ExtSelectClipRgn(hdc, hRgn, RGN_COPY);
2430 SetWorldTransform(hdc, &savedXform);
2432 SetGraphicsMode(hdc, savedMode);
2433 SetMapMode(hdc, mapMode);
2434 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2435 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2436 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2437 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2440 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2441 if( (ht->objectHandle)[i] )
2442 DeleteObject( (ht->objectHandle)[i] );
2444 while (info->saved_state)
2446 EMF_dc_state *state = info->saved_state;
2447 info->saved_state = info->saved_state->next;
2448 HeapFree( GetProcessHeap(), 0, state );
2450 HeapFree( GetProcessHeap(), 0, info );
2454 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2455 const ENHMETARECORD *emr,
2456 INT handles, LPARAM data)
2458 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2461 /**************************************************************************
2462 * PlayEnhMetaFile (GDI32.@)
2464 * Renders an enhanced metafile into a specified rectangle *lpRect
2465 * in device context hdc.
2471 BOOL WINAPI PlayEnhMetaFile(
2472 HDC hdc, /* [in] DC to render into */
2473 HENHMETAFILE hmf, /* [in] metafile to render */
2474 const RECT *lpRect /* [in] rectangle to place metafile inside */
2477 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2481 /*****************************************************************************
2482 * DeleteEnhMetaFile (GDI32.@)
2484 * Deletes an enhanced metafile and frees the associated storage.
2486 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2488 return EMF_Delete_HENHMETAFILE( hmf );
2491 /*****************************************************************************
2492 * CopyEnhMetaFileA (GDI32.@)
2494 * Duplicate an enhanced metafile.
2498 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2499 HENHMETAFILE hmfSrc,
2502 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2503 HENHMETAFILE hmfDst;
2505 if(!emrSrc) return FALSE;
2507 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2508 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2509 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2513 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2514 NULL, CREATE_ALWAYS, 0, 0);
2515 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2516 CloseHandle( hFile );
2517 /* Reopen file for reading only, so that apps can share
2518 read access to the file while hmf is still valid */
2519 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2520 NULL, OPEN_EXISTING, 0, 0);
2521 if(hFile == INVALID_HANDLE_VALUE) {
2522 ERR("Can't reopen emf for reading\n");
2525 hmfDst = EMF_GetEnhMetaFile( hFile );
2526 CloseHandle( hFile );
2531 /*****************************************************************************
2532 * CopyEnhMetaFileW (GDI32.@)
2534 * See CopyEnhMetaFileA.
2538 HENHMETAFILE WINAPI CopyEnhMetaFileW(
2539 HENHMETAFILE hmfSrc,
2542 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2543 HENHMETAFILE hmfDst;
2545 if(!emrSrc) return FALSE;
2547 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2548 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2549 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2553 hFile = CreateFileW( file, GENERIC_WRITE | GENERIC_READ, 0,
2554 NULL, CREATE_ALWAYS, 0, 0);
2555 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2556 CloseHandle( hFile );
2557 /* Reopen file for reading only, so that apps can share
2558 read access to the file while hmf is still valid */
2559 hFile = CreateFileW( file, GENERIC_READ, FILE_SHARE_READ,
2560 NULL, OPEN_EXISTING, 0, 0);
2561 if(hFile == INVALID_HANDLE_VALUE) {
2562 ERR("Can't reopen emf for reading\n");
2565 hmfDst = EMF_GetEnhMetaFile( hFile );
2566 CloseHandle( hFile );
2572 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2573 typedef struct tagEMF_PaletteCopy
2576 LPPALETTEENTRY lpPe;
2579 /***************************************************************
2580 * Find the EMR_EOF record and then use it to find the
2581 * palette entries for this enhanced metafile.
2582 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2583 * which contains the max number of elements to copy and where
2586 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2588 static INT CALLBACK cbEnhPaletteCopy( HDC a,
2590 const ENHMETARECORD *lpEMR,
2595 if ( lpEMR->iType == EMR_EOF )
2597 const EMREOF *lpEof = (const EMREOF *)lpEMR;
2598 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2599 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2601 TRACE( "copying 0x%08x palettes\n", dwNumPalToCopy );
2603 memcpy( (LPVOID)info->lpPe,
2604 (LPCVOID)(((LPCSTR)lpEof) + lpEof->offPalEntries),
2605 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2607 /* Update the passed data as a return code */
2608 info->lpPe = NULL; /* Palettes were copied! */
2609 info->cEntries = dwNumPalToCopy;
2611 return FALSE; /* That's all we need */
2617 /*****************************************************************************
2618 * GetEnhMetaFilePaletteEntries (GDI32.@)
2620 * Copy the palette and report size
2622 * BUGS: Error codes (SetLastError) are not set on failures
2624 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2626 LPPALETTEENTRY lpPe )
2628 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2629 EMF_PaletteCopy infoForCallBack;
2631 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2633 if (!enhHeader) return 0;
2635 /* First check if there are any palettes associated with
2637 if ( enhHeader->nPalEntries == 0 ) return 0;
2639 /* Is the user requesting the number of palettes? */
2640 if ( lpPe == NULL ) return enhHeader->nPalEntries;
2642 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2643 infoForCallBack.cEntries = cEntries;
2644 infoForCallBack.lpPe = lpPe;
2646 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2647 &infoForCallBack, 0 ) )
2650 /* Verify that the callback executed correctly */
2651 if ( infoForCallBack.lpPe != NULL )
2653 /* Callback proc had error! */
2654 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2658 return infoForCallBack.cEntries;
2661 typedef struct gdi_mf_comment
2668 DWORD cbWinMetaFile;
2671 /******************************************************************
2672 * SetWinMetaFileBits (GDI32.@)
2674 * Translate from old style to new style.
2677 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2678 CONST BYTE *lpbBuffer,
2680 CONST METAFILEPICT *lpmfp
2683 static const WCHAR szDisplayW[] = { 'D','I','S','P','L','A','Y','\0' };
2684 HMETAFILE hmf = NULL;
2685 HENHMETAFILE ret = NULL;
2686 HDC hdc = NULL, hdcdisp = NULL;
2687 RECT rc, *prcFrame = NULL;
2688 LONG mm, xExt, yExt;
2689 INT horzsize, vertsize, horzres, vertres;
2691 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2693 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2696 WARN("SetMetaFileBitsEx failed\n");
2701 hdcRef = hdcdisp = CreateDCW(szDisplayW, NULL, NULL, NULL);
2705 TRACE("mm = %d %dx%d\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2713 TRACE("lpmfp == NULL\n");
2715 /* Use the whole device surface */
2716 mm = MM_ANISOTROPIC;
2721 if (mm == MM_ISOTROPIC || mm == MM_ANISOTROPIC)
2723 if (xExt < 0 || yExt < 0)
2725 /* Use the whole device surface */
2730 /* Use the x and y extents as the frame box */
2733 rc.left = rc.top = 0;
2740 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL)))
2742 ERR("CreateEnhMetaFile failed\n");
2747 * Write the original METAFILE into the enhanced metafile.
2748 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2752 gdi_mf_comment *mfcomment;
2753 UINT mfcomment_size;
2755 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2756 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2759 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2760 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2761 mfcomment->nVersion = 0x00000300;
2762 mfcomment->nChecksum = 0; /* FIXME */
2763 mfcomment->fFlags = 0;
2764 mfcomment->cbWinMetaFile = cbBuffer;
2765 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2766 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2767 HeapFree(GetProcessHeap(), 0, mfcomment);
2769 SetMapMode(hdc, mm);
2773 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2774 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2775 horzres = GetDeviceCaps(hdcRef, HORZRES);
2776 vertres = GetDeviceCaps(hdcRef, VERTRES);
2780 /* Use the whole device surface */
2786 xExt = MulDiv(xExt, horzres, 100 * horzsize);
2787 yExt = MulDiv(yExt, vertres, 100 * vertsize);
2790 /* set the initial viewport:window ratio as 1:1 */
2791 SetViewportExtEx(hdc, xExt, yExt, NULL);
2792 SetWindowExtEx(hdc, xExt, yExt, NULL);
2794 PlayMetaFile(hdc, hmf);
2796 ret = CloseEnhMetaFile(hdc);
2798 if (hdcdisp) DeleteDC(hdcdisp);
2799 DeleteMetaFile(hmf);