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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
47 #include "gdi_private.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
56 BOOL on_disk; /* true if metafile is on disk */
59 static const struct emr_name {
72 X(EMR_SETWINDOWEXTEX),
73 X(EMR_SETWINDOWORGEX),
74 X(EMR_SETVIEWPORTEXTEX),
75 X(EMR_SETVIEWPORTORGEX),
79 X(EMR_SETMAPPERFLAGS),
82 X(EMR_SETPOLYFILLMODE),
84 X(EMR_SETSTRETCHBLTMODE),
86 X(EMR_SETCOLORADJUSTMENT),
92 X(EMR_EXCLUDECLIPRECT),
93 X(EMR_INTERSECTCLIPRECT),
94 X(EMR_SCALEVIEWPORTEXTEX),
95 X(EMR_SCALEWINDOWEXTEX),
98 X(EMR_SETWORLDTRANSFORM),
99 X(EMR_MODIFYWORLDTRANSFORM),
102 X(EMR_CREATEBRUSHINDIRECT),
111 X(EMR_SELECTPALETTE),
112 X(EMR_CREATEPALETTE),
113 X(EMR_SETPALETTEENTRIES),
114 X(EMR_RESIZEPALETTE),
115 X(EMR_REALIZEPALETTE),
120 X(EMR_SETARCDIRECTION),
121 X(EMR_SETMITERLIMIT),
126 X(EMR_STROKEANDFILLPATH),
130 X(EMR_SELECTCLIPPATH),
137 X(EMR_EXTSELECTCLIPRGN),
142 X(EMR_SETDIBITSTODEVICE),
143 X(EMR_STRETCHDIBITS),
144 X(EMR_EXTCREATEFONTINDIRECTW),
150 X(EMR_POLYBEZIERTO16),
152 X(EMR_POLYPOLYLINE16),
153 X(EMR_POLYPOLYGON16),
155 X(EMR_CREATEMONOBRUSH),
156 X(EMR_CREATEDIBPATTERNBRUSHPT),
161 X(EMR_CREATECOLORSPACE),
162 X(EMR_SETCOLORSPACE),
163 X(EMR_DELETECOLORSPACE),
165 X(EMR_GLSBOUNDEDRECORD),
171 X(EMR_FORCEUFIMAPPING),
173 X(EMR_COLORCORRECTPALETTE),
174 X(EMR_SETICMPROFILEA),
175 X(EMR_SETICMPROFILEW),
178 X(EMR_TRANSPARENTBLT),
182 X(EMR_SETTEXTJUSTIFICATION),
183 X(EMR_COLORMATCHTOTARGETW),
184 X(EMR_CREATECOLORSPACEW)
188 /****************************************************************************
191 static const char *get_emr_name(DWORD type)
194 for(i = 0; i < sizeof(emr_names) / sizeof(emr_names[0]); i++)
195 if(type == emr_names[i].type) return emr_names[i].name;
196 TRACE("Unknown record type %ld\n", type);
200 /***********************************************************************
203 * Returns whether a DIB can be converted to a monochrome DDB.
205 * A DIB can be converted if its color table contains only black and
206 * white. Black must be the first color in the color table.
208 * Note : If the first color in the color table is white followed by
209 * black, we can't convert it to a monochrome DDB with
210 * SetDIBits, because black and white would be inverted.
212 static inline BOOL is_dib_monochrome( const BITMAPINFO* info )
214 if (info->bmiHeader.biBitCount != 1) return FALSE;
216 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
218 RGBTRIPLE *rgb = ((BITMAPCOREINFO *) info)->bmciColors;
220 /* Check if the first color is black */
221 if ((rgb->rgbtRed == 0) && (rgb->rgbtGreen == 0) && (rgb->rgbtBlue == 0))
224 /* Check if the second color is white */
225 return ((rgb->rgbtRed == 0xff) && (rgb->rgbtGreen == 0xff)
226 && (rgb->rgbtBlue == 0xff));
230 else /* assume BITMAPINFOHEADER */
232 const RGBQUAD *rgb = info->bmiColors;
234 /* Check if the first color is black */
235 if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) &&
236 (rgb->rgbBlue == 0) && (rgb->rgbReserved == 0))
240 /* Check if the second color is white */
241 return ((rgb->rgbRed == 0xff) && (rgb->rgbGreen == 0xff)
242 && (rgb->rgbBlue == 0xff) && (rgb->rgbReserved == 0));
248 /****************************************************************************
249 * EMF_Create_HENHMETAFILE
251 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk )
253 HENHMETAFILE hmf = 0;
254 ENHMETAFILEOBJ *metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
256 (HGDIOBJ *)&hmf, NULL );
260 metaObj->on_disk = on_disk;
261 GDI_ReleaseObj( hmf );
266 /****************************************************************************
267 * EMF_Delete_HENHMETAFILE
269 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
271 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
273 if(!metaObj) return FALSE;
276 UnmapViewOfFile( metaObj->emh );
278 HeapFree( GetProcessHeap(), 0, metaObj->emh );
279 return GDI_FreeObject( hmf, metaObj );
282 /******************************************************************
283 * EMF_GetEnhMetaHeader
285 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
287 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
289 ENHMETAHEADER *ret = NULL;
290 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
291 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
295 GDI_ReleaseObj( hmf );
300 /*****************************************************************************
304 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
309 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
310 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
311 CloseHandle( hMapping );
315 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
316 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
317 emh->iType, emh->dSignature);
321 /* refuse to load unaligned EMF as Windows does */
324 WARN("Refusing to load unaligned EMF\n");
328 return EMF_Create_HENHMETAFILE( emh, TRUE );
331 UnmapViewOfFile( emh );
336 /*****************************************************************************
337 * GetEnhMetaFileA (GDI32.@)
341 HENHMETAFILE WINAPI GetEnhMetaFileA(
342 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
348 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
349 OPEN_EXISTING, 0, 0);
350 if (hFile == INVALID_HANDLE_VALUE) {
351 WARN("could not open %s\n", lpszMetaFile);
354 hmf = EMF_GetEnhMetaFile( hFile );
355 CloseHandle( hFile );
359 /*****************************************************************************
360 * GetEnhMetaFileW (GDI32.@)
362 HENHMETAFILE WINAPI GetEnhMetaFileW(
363 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
368 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
369 OPEN_EXISTING, 0, 0);
370 if (hFile == INVALID_HANDLE_VALUE) {
371 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
374 hmf = EMF_GetEnhMetaFile( hFile );
375 CloseHandle( hFile );
379 /*****************************************************************************
380 * GetEnhMetaFileHeader (GDI32.@)
382 * Retrieves the record containing the header for the specified
383 * enhanced-format metafile.
386 * If buf is NULL, returns the size of buffer required.
387 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
390 UINT WINAPI GetEnhMetaFileHeader(
391 HENHMETAFILE hmf, /* [in] enhanced metafile */
392 UINT bufsize, /* [in] size of buffer */
393 LPENHMETAHEADER buf /* [out] buffer */
399 emh = EMF_GetEnhMetaHeader(hmf);
400 if(!emh) return FALSE;
402 if (!buf) return size;
403 size = min(size, bufsize);
404 memmove(buf, emh, size);
409 /*****************************************************************************
410 * GetEnhMetaFileDescriptionA (GDI32.@)
412 * See GetEnhMetaFileDescriptionW.
414 UINT WINAPI GetEnhMetaFileDescriptionA(
415 HENHMETAFILE hmf, /* [in] enhanced metafile */
416 UINT size, /* [in] size of buf */
417 LPSTR buf /* [out] buffer to receive description */
420 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
424 if(!emh) return FALSE;
425 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
426 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
427 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
429 if (!buf || !size ) return len;
431 len = min( size, len );
432 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
436 /*****************************************************************************
437 * GetEnhMetaFileDescriptionW (GDI32.@)
439 * Copies the description string of an enhanced metafile into a buffer
443 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
444 * number of characters copied.
446 UINT WINAPI GetEnhMetaFileDescriptionW(
447 HENHMETAFILE hmf, /* [in] enhanced metafile */
448 UINT size, /* [in] size of buf */
449 LPWSTR buf /* [out] buffer to receive description */
452 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
454 if(!emh) return FALSE;
455 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
456 if (!buf || !size ) return emh->nDescription;
458 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
459 return min(size, emh->nDescription);
462 /****************************************************************************
463 * SetEnhMetaFileBits (GDI32.@)
465 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
467 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
469 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
470 memmove(emh, buf, bufsize);
471 return EMF_Create_HENHMETAFILE( emh, FALSE );
474 /*****************************************************************************
475 * GetEnhMetaFileBits (GDI32.@)
478 UINT WINAPI GetEnhMetaFileBits(
484 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
490 if( buf == NULL ) return size;
492 size = min( size, bufsize );
493 memmove(buf, emh, size);
497 typedef struct enum_emh_data
500 XFORM init_transform;
501 XFORM world_transform;
512 #define ENUM_GET_PRIVATE_DATA(ht) \
513 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
515 #define WIDTH(rect) ( (rect).right - (rect).left )
516 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
518 #define IS_WIN9X() (GetVersion()&0x80000000)
520 static void EMF_Update_MF_Xform(HDC hdc, enum_emh_data *info)
522 XFORM mapping_mode_trans, final_trans;
523 FLOAT scaleX, scaleY;
525 scaleX = (FLOAT)info->vportExtX / (FLOAT)info->wndExtX;
526 scaleY = (FLOAT)info->vportExtY / (FLOAT)info->wndExtY;
527 mapping_mode_trans.eM11 = scaleX;
528 mapping_mode_trans.eM12 = 0.0;
529 mapping_mode_trans.eM21 = 0.0;
530 mapping_mode_trans.eM22 = scaleY;
531 mapping_mode_trans.eDx = (FLOAT)info->vportOrgX - scaleX * (FLOAT)info->wndOrgX;
532 mapping_mode_trans.eDy = (FLOAT)info->vportOrgY - scaleY * (FLOAT)info->wndOrgY;
534 CombineTransform(&final_trans, &info->world_transform, &mapping_mode_trans);
535 CombineTransform(&final_trans, &final_trans, &info->init_transform);
537 if (!SetWorldTransform(hdc, &final_trans))
539 ERR("World transform failed!\n");
543 static void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
545 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
546 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
547 INT horzRes = GetDeviceCaps( hdc, HORZRES );
548 INT vertRes = GetDeviceCaps( hdc, VERTRES );
550 TRACE("%d\n",info->mode);
562 info->wndExtX = horzSize * 10;
563 info->wndExtY = vertSize * 10;
564 info->vportExtX = horzRes;
565 info->vportExtY = -vertRes;
568 info->wndExtX = horzSize * 100;
569 info->wndExtY = vertSize * 100;
570 info->vportExtX = horzRes;
571 info->vportExtY = -vertRes;
574 info->wndExtX = MulDiv(1000, horzSize, 254);
575 info->wndExtY = MulDiv(1000, vertSize, 254);
576 info->vportExtX = horzRes;
577 info->vportExtY = -vertRes;
580 info->wndExtX = MulDiv(10000, horzSize, 254);
581 info->wndExtY = MulDiv(10000, vertSize, 254);
582 info->vportExtX = horzRes;
583 info->vportExtY = -vertRes;
586 info->wndExtX = MulDiv(14400, horzSize, 254);
587 info->wndExtY = MulDiv(14400, vertSize, 254);
588 info->vportExtX = horzRes;
589 info->vportExtY = -vertRes;
598 /*****************************************************************************
599 * emr_produces_output
601 * Returns TRUE if the record type writes something to the dc. Used by
602 * PlayEnhMetaFileRecord to determine whether it needs to update the
603 * dc's xform when in win9x mode.
605 * FIXME: need to test which records should be here.
607 static BOOL emr_produces_output(int type)
613 case EMR_POLYBEZIERTO:
615 case EMR_POLYPOLYLINE:
616 case EMR_POLYPOLYGON:
619 case EMR_EXCLUDECLIPRECT:
620 case EMR_INTERSECTCLIPRECT:
621 case EMR_SELECTOBJECT:
629 case EMR_EXTFLOODFILL:
641 case EMR_SETDIBITSTODEVICE:
642 case EMR_STRETCHDIBITS:
643 case EMR_EXTTEXTOUTA:
644 case EMR_EXTTEXTOUTW:
645 case EMR_POLYBEZIER16:
648 case EMR_POLYBEZIERTO16:
649 case EMR_POLYLINETO16:
650 case EMR_POLYPOLYLINE16:
651 case EMR_POLYPOLYGON16:
653 case EMR_POLYTEXTOUTA:
654 case EMR_POLYTEXTOUTW:
655 case EMR_SMALLTEXTOUT:
657 case EMR_TRANSPARENTBLT:
665 /*****************************************************************************
666 * PlayEnhMetaFileRecord (GDI32.@)
668 * Render a single enhanced metafile record in the device context hdc.
671 * TRUE (non zero) on success, FALSE on error.
673 * Many unimplemented records.
674 * No error handling on record play failures (ie checking return codes)
677 * WinNT actually updates the current world transform in this function
678 * whereas Win9x does not.
680 BOOL WINAPI PlayEnhMetaFileRecord(
681 HDC hdc, /* [in] device context in which to render EMF record */
682 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
683 const ENHMETARECORD *mr, /* [in] EMF record to render */
684 UINT handles /* [in] size of handle array */
689 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
691 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
692 hdc, handletable, mr, handles);
693 if (!mr) return FALSE;
697 /* In Win9x mode we update the xform if the record will produce output */
698 if ( IS_WIN9X() && emr_produces_output(type) )
699 EMF_Update_MF_Xform(hdc, info);
701 TRACE("record %s\n", get_emr_name(type));
710 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
711 /* In an enhanced metafile, there can be both public and private GDI comments */
712 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
717 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
719 if(info->mode == pSetMapMode->iMode && (info->mode == MM_ISOTROPIC || info->mode == MM_ANISOTROPIC))
721 info->mode = pSetMapMode->iMode;
722 EMF_SetMapMode(hdc, info);
727 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
728 SetBkMode(hdc, pSetBkMode->iMode);
733 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
734 SetBkColor(hdc, pSetBkColor->crColor);
737 case EMR_SETPOLYFILLMODE:
739 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
740 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
745 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
746 SetROP2(hdc, pSetROP2->iMode);
749 case EMR_SETSTRETCHBLTMODE:
751 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
752 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
755 case EMR_SETTEXTALIGN:
757 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
758 SetTextAlign(hdc, pSetTextAlign->iMode);
761 case EMR_SETTEXTCOLOR:
763 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
764 SetTextColor(hdc, pSetTextColor->crColor);
774 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
775 TRACE("EMR_RESTORE: %ld\n", pRestoreDC->iRelative);
776 RestoreDC(hdc, pRestoreDC->iRelative);
779 case EMR_INTERSECTCLIPRECT:
781 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
782 TRACE("EMR_INTERSECTCLIPRECT: rect %ld,%ld - %ld, %ld\n",
783 pClipRect->rclClip.left, pClipRect->rclClip.top,
784 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
785 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
786 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
789 case EMR_SELECTOBJECT:
791 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
792 if( pSelectObject->ihObject & 0x80000000 ) {
793 /* High order bit is set - it's a stock object
794 * Strip the high bit to get the index.
795 * See MSDN article Q142319
797 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
800 /* High order bit wasn't set - not a stock object
803 (handletable->objectHandle)[pSelectObject->ihObject] );
807 case EMR_DELETEOBJECT:
809 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
810 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
811 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
814 case EMR_SETWINDOWORGEX:
816 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
818 info->wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
819 info->wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
821 TRACE("SetWindowOrgEx: %d,%d\n",info->wndOrgX,info->wndOrgY);
824 case EMR_SETWINDOWEXTEX:
826 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
828 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
830 info->wndExtX = pSetWindowExtEx->szlExtent.cx;
831 info->wndExtY = pSetWindowExtEx->szlExtent.cy;
833 TRACE("SetWindowExtEx: %d,%d\n",info->wndExtX,info->wndExtY);
836 case EMR_SETVIEWPORTORGEX:
838 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
839 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
841 info->vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
842 info->vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
843 TRACE("SetViewportOrgEx: %d,%d\n",info->vportOrgX,info->vportOrgY);
846 case EMR_SETVIEWPORTEXTEX:
848 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
849 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
851 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
853 info->vportExtX = pSetViewportExtEx->szlExtent.cx;
854 info->vportExtY = pSetViewportExtEx->szlExtent.cy;
855 TRACE("SetViewportExtEx: %d,%d\n",info->vportExtX,info->vportExtY);
860 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
861 (handletable->objectHandle)[pCreatePen->ihPen] =
862 CreatePenIndirect(&pCreatePen->lopn);
865 case EMR_EXTCREATEPEN:
867 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
869 lb.lbStyle = pPen->elp.elpBrushStyle;
870 lb.lbColor = pPen->elp.elpColor;
871 lb.lbHatch = pPen->elp.elpHatch;
873 if(pPen->offBmi || pPen->offBits)
874 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
876 (handletable->objectHandle)[pPen->ihPen] =
877 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
878 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
881 case EMR_CREATEBRUSHINDIRECT:
883 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
885 brush.lbStyle = pBrush->lb.lbStyle;
886 brush.lbColor = pBrush->lb.lbColor;
887 brush.lbHatch = pBrush->lb.lbHatch;
888 (handletable->objectHandle)[pBrush->ihBrush] = CreateBrushIndirect(&brush);
891 case EMR_EXTCREATEFONTINDIRECTW:
893 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
894 (handletable->objectHandle)[pFont->ihFont] =
895 CreateFontIndirectW(&pFont->elfw.elfLogFont);
900 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
901 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
906 PEMRLINETO pLineTo = (PEMRLINETO) mr;
907 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
912 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
913 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
914 pRect->rclBox.right, pRect->rclBox.bottom);
919 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
920 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
921 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
926 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
927 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
928 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
929 pPoly->cpts * sizeof(POINT) );
931 for(i = 0; i < pPoly->cpts; i++)
933 pts[i].x = pPoly->apts[i].x;
934 pts[i].y = pPoly->apts[i].y;
936 Polygon(hdc, pts, pPoly->cpts);
937 HeapFree( GetProcessHeap(), 0, pts );
942 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
943 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
944 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
945 pPoly->cpts * sizeof(POINT) );
947 for(i = 0; i < pPoly->cpts; i++)
949 pts[i].x = pPoly->apts[i].x;
950 pts[i].y = pPoly->apts[i].y;
952 Polyline(hdc, pts, pPoly->cpts);
953 HeapFree( GetProcessHeap(), 0, pts );
956 case EMR_POLYLINETO16:
958 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
959 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
960 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
961 pPoly->cpts * sizeof(POINT) );
963 for(i = 0; i < pPoly->cpts; i++)
965 pts[i].x = pPoly->apts[i].x;
966 pts[i].y = pPoly->apts[i].y;
968 PolylineTo(hdc, pts, pPoly->cpts);
969 HeapFree( GetProcessHeap(), 0, pts );
972 case EMR_POLYBEZIER16:
974 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
975 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
976 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
977 pPoly->cpts * sizeof(POINT) );
979 for(i = 0; i < pPoly->cpts; i++)
981 pts[i].x = pPoly->apts[i].x;
982 pts[i].y = pPoly->apts[i].y;
984 PolyBezier(hdc, pts, pPoly->cpts);
985 HeapFree( GetProcessHeap(), 0, pts );
988 case EMR_POLYBEZIERTO16:
990 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
991 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
992 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
993 pPoly->cpts * sizeof(POINT) );
995 for(i = 0; i < pPoly->cpts; i++)
997 pts[i].x = pPoly->apts[i].x;
998 pts[i].y = pPoly->apts[i].y;
1000 PolyBezierTo(hdc, pts, pPoly->cpts);
1001 HeapFree( GetProcessHeap(), 0, pts );
1004 case EMR_POLYPOLYGON16:
1006 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
1007 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1008 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1010 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1011 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1013 for(i = 0; i < pPolyPoly->cpts; i++)
1015 pts[i].x = pts16[i].x;
1016 pts[i].y = pts16[i].y;
1018 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1019 HeapFree( GetProcessHeap(), 0, pts );
1022 case EMR_POLYPOLYLINE16:
1024 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
1025 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1026 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1028 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1029 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1031 for(i = 0; i < pPolyPoly->cpts; i++)
1033 pts[i].x = pts16[i].x;
1034 pts[i].y = pts16[i].y;
1036 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1037 HeapFree( GetProcessHeap(), 0, pts );
1041 case EMR_STRETCHDIBITS:
1043 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
1046 pStretchDIBits->xDest,
1047 pStretchDIBits->yDest,
1048 pStretchDIBits->cxDest,
1049 pStretchDIBits->cyDest,
1050 pStretchDIBits->xSrc,
1051 pStretchDIBits->ySrc,
1052 pStretchDIBits->cxSrc,
1053 pStretchDIBits->cySrc,
1054 (BYTE *)mr + pStretchDIBits->offBitsSrc,
1055 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
1056 pStretchDIBits->iUsageSrc,
1057 pStretchDIBits->dwRop);
1061 case EMR_EXTTEXTOUTA:
1063 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
1067 rc.left = pExtTextOutA->emrtext.rcl.left;
1068 rc.top = pExtTextOutA->emrtext.rcl.top;
1069 rc.right = pExtTextOutA->emrtext.rcl.right;
1070 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
1071 TRACE("EMR_EXTTEXTOUTA: x,y = %ld, %ld. rect = %ld, %ld - %ld, %ld. flags %08lx\n",
1072 pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1073 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutA->emrtext.fOptions);
1075 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1076 * These files can be enumerated and played under Win98 just
1077 * fine, but at least Win2k chokes on them.
1079 if (pExtTextOutA->emrtext.offDx)
1080 dx = (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx);
1082 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1083 pExtTextOutA->emrtext.fOptions, &rc,
1084 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
1089 case EMR_EXTTEXTOUTW:
1091 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
1095 rc.left = pExtTextOutW->emrtext.rcl.left;
1096 rc.top = pExtTextOutW->emrtext.rcl.top;
1097 rc.right = pExtTextOutW->emrtext.rcl.right;
1098 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
1099 TRACE("EMR_EXTTEXTOUTW: x,y = %ld, %ld. rect = %ld, %ld - %ld, %ld. flags %08lx\n",
1100 pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1101 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutW->emrtext.fOptions);
1103 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1104 * These files can be enumerated and played under Win98 just
1105 * fine, but at least Win2k chokes on them.
1107 if (pExtTextOutW->emrtext.offDx)
1108 dx = (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx);
1110 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1111 pExtTextOutW->emrtext.fOptions, &rc,
1112 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
1117 case EMR_CREATEPALETTE:
1119 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
1121 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
1122 CreatePalette( &lpCreatePal->lgpl );
1127 case EMR_SELECTPALETTE:
1129 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
1131 if( lpSelectPal->ihPal & 0x80000000 ) {
1132 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
1134 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
1135 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
1140 case EMR_REALIZEPALETTE:
1142 RealizePalette( hdc );
1146 case EMR_EXTSELECTCLIPRGN:
1149 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
1150 HRGN hRgn = ExtCreateRegion(NULL, lpRgn->cbRgnData, (RGNDATA *)lpRgn->RgnData);
1152 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
1153 /* ExtSelectClipRgn created a copy of the region */
1156 FIXME("ExtSelectClipRgn\n");
1160 case EMR_SETMETARGN:
1166 case EMR_SETWORLDTRANSFORM:
1168 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
1169 info->world_transform = lpXfrm->xform;
1173 case EMR_POLYBEZIER:
1175 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
1176 PolyBezier(hdc, (const POINT*)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
1182 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
1183 Polygon( hdc, (const POINT*)lpPoly->aptl, (UINT)lpPoly->cptl );
1189 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
1190 Polyline(hdc, (const POINT*)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
1194 case EMR_POLYBEZIERTO:
1196 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
1197 PolyBezierTo( hdc, (const POINT*)lpPolyBezierTo->aptl,
1198 (UINT)lpPolyBezierTo->cptl );
1202 case EMR_POLYLINETO:
1204 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
1205 PolylineTo( hdc, (const POINT*)lpPolyLineTo->aptl,
1206 (UINT)lpPolyLineTo->cptl );
1210 case EMR_POLYPOLYLINE:
1212 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
1213 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1215 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
1216 pPolyPolyline->nPolys),
1217 pPolyPolyline->aPolyCounts,
1218 pPolyPolyline->nPolys );
1223 case EMR_POLYPOLYGON:
1225 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
1227 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1229 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
1230 pPolyPolygon->nPolys),
1231 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
1235 case EMR_SETBRUSHORGEX:
1237 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
1240 (INT)lpSetBrushOrgEx->ptlOrigin.x,
1241 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1249 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
1252 (INT)lpSetPixelV->ptlPixel.x,
1253 (INT)lpSetPixelV->ptlPixel.y,
1254 lpSetPixelV->crColor );
1259 case EMR_SETMAPPERFLAGS:
1261 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
1263 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1268 case EMR_SETCOLORADJUSTMENT:
1270 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
1272 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1277 case EMR_OFFSETCLIPRGN:
1279 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
1282 (INT)lpOffsetClipRgn->ptlOffset.x,
1283 (INT)lpOffsetClipRgn->ptlOffset.y );
1284 FIXME("OffsetClipRgn\n");
1289 case EMR_EXCLUDECLIPRECT:
1291 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
1293 ExcludeClipRect( hdc,
1294 lpExcludeClipRect->rclClip.left,
1295 lpExcludeClipRect->rclClip.top,
1296 lpExcludeClipRect->rclClip.right,
1297 lpExcludeClipRect->rclClip.bottom );
1298 FIXME("ExcludeClipRect\n");
1303 case EMR_SCALEVIEWPORTEXTEX:
1305 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
1307 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1309 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1310 !lpScaleViewportExtEx->yNum || !lpScaleViewportExtEx->yDenom)
1312 info->vportExtX = (info->vportExtX * lpScaleViewportExtEx->xNum) /
1313 lpScaleViewportExtEx->xDenom;
1314 info->vportExtY = (info->vportExtY * lpScaleViewportExtEx->yNum) /
1315 lpScaleViewportExtEx->yDenom;
1316 if (info->vportExtX == 0) info->vportExtX = 1;
1317 if (info->vportExtY == 0) info->vportExtY = 1;
1318 if (info->mode == MM_ISOTROPIC)
1319 FIXME("EMRSCALEVIEWPORTEXTEX MM_ISOTROPIC mapping\n");
1320 /* MAPPING_FixIsotropic( dc ); */
1322 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1323 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1324 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1329 case EMR_SCALEWINDOWEXTEX:
1331 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
1333 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1335 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1336 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1338 info->wndExtX = (info->wndExtX * lpScaleWindowExtEx->xNum) /
1339 lpScaleWindowExtEx->xDenom;
1340 info->wndExtY = (info->wndExtY * lpScaleWindowExtEx->yNum) /
1341 lpScaleWindowExtEx->yDenom;
1342 if (info->wndExtX == 0) info->wndExtX = 1;
1343 if (info->wndExtY == 0) info->wndExtY = 1;
1344 if (info->mode == MM_ISOTROPIC)
1345 FIXME("EMRSCALEWINDOWEXTEX MM_ISOTROPIC mapping\n");
1346 /* MAPPING_FixIsotropic( dc ); */
1348 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1349 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1350 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1355 case EMR_MODIFYWORLDTRANSFORM:
1357 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
1359 switch(lpModifyWorldTrans->iMode) {
1361 info->world_transform.eM11 = info->world_transform.eM22 = 1;
1362 info->world_transform.eM12 = info->world_transform.eM21 = 0;
1363 info->world_transform.eDx = info->world_transform.eDy = 0;
1365 case MWT_LEFTMULTIPLY:
1366 CombineTransform(&info->world_transform, &lpModifyWorldTrans->xform,
1367 &info->world_transform);
1369 case MWT_RIGHTMULTIPLY:
1370 CombineTransform(&info->world_transform, &info->world_transform,
1371 &lpModifyWorldTrans->xform);
1374 FIXME("Unknown imode %ld\n", lpModifyWorldTrans->iMode);
1382 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
1385 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1386 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1387 lpAngleArc->eSweepAngle );
1394 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
1397 lpRoundRect->rclBox.left,
1398 lpRoundRect->rclBox.top,
1399 lpRoundRect->rclBox.right,
1400 lpRoundRect->rclBox.bottom,
1401 lpRoundRect->szlCorner.cx,
1402 lpRoundRect->szlCorner.cy );
1409 PEMRARC lpArc = (PEMRARC)mr;
1412 (INT)lpArc->rclBox.left,
1413 (INT)lpArc->rclBox.top,
1414 (INT)lpArc->rclBox.right,
1415 (INT)lpArc->rclBox.bottom,
1416 (INT)lpArc->ptlStart.x,
1417 (INT)lpArc->ptlStart.y,
1418 (INT)lpArc->ptlEnd.x,
1419 (INT)lpArc->ptlEnd.y );
1426 PEMRCHORD lpChord = (PEMRCHORD)mr;
1429 (INT)lpChord->rclBox.left,
1430 (INT)lpChord->rclBox.top,
1431 (INT)lpChord->rclBox.right,
1432 (INT)lpChord->rclBox.bottom,
1433 (INT)lpChord->ptlStart.x,
1434 (INT)lpChord->ptlStart.y,
1435 (INT)lpChord->ptlEnd.x,
1436 (INT)lpChord->ptlEnd.y );
1443 PEMRPIE lpPie = (PEMRPIE)mr;
1446 (INT)lpPie->rclBox.left,
1447 (INT)lpPie->rclBox.top,
1448 (INT)lpPie->rclBox.right,
1449 (INT)lpPie->rclBox.bottom,
1450 (INT)lpPie->ptlStart.x,
1451 (INT)lpPie->ptlStart.y,
1452 (INT)lpPie->ptlEnd.x,
1453 (INT)lpPie->ptlEnd.y );
1460 PEMRARC lpArcTo = (PEMRARC)mr;
1463 (INT)lpArcTo->rclBox.left,
1464 (INT)lpArcTo->rclBox.top,
1465 (INT)lpArcTo->rclBox.right,
1466 (INT)lpArcTo->rclBox.bottom,
1467 (INT)lpArcTo->ptlStart.x,
1468 (INT)lpArcTo->ptlStart.y,
1469 (INT)lpArcTo->ptlEnd.x,
1470 (INT)lpArcTo->ptlEnd.y );
1475 case EMR_EXTFLOODFILL:
1477 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
1480 (INT)lpExtFloodFill->ptlStart.x,
1481 (INT)lpExtFloodFill->ptlStart.y,
1482 lpExtFloodFill->crColor,
1483 (UINT)lpExtFloodFill->iMode );
1490 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
1492 (const POINT*)lpPolyDraw->aptl,
1493 lpPolyDraw->abTypes,
1494 (INT)lpPolyDraw->cptl );
1499 case EMR_SETARCDIRECTION:
1501 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1502 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1506 case EMR_SETMITERLIMIT:
1508 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1509 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1525 case EMR_CLOSEFIGURE:
1533 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1538 case EMR_STROKEANDFILLPATH:
1540 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1541 StrokeAndFillPath( hdc );
1545 case EMR_STROKEPATH:
1547 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1552 case EMR_FLATTENPATH:
1564 case EMR_SELECTCLIPPATH:
1566 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1567 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1577 case EMR_CREATECOLORSPACE:
1579 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1580 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1581 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1585 case EMR_SETCOLORSPACE:
1587 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1589 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1593 case EMR_DELETECOLORSPACE:
1595 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1596 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1600 case EMR_SETICMMODE:
1602 PEMRSETICMMODE lpSetICMMode = (PEMRSETICMMODE)mr;
1603 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1607 case EMR_PIXELFORMAT:
1610 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1612 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1613 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1618 case EMR_SETPALETTEENTRIES:
1620 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1622 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1623 (UINT)lpSetPaletteEntries->iStart,
1624 (UINT)lpSetPaletteEntries->cEntries,
1625 lpSetPaletteEntries->aPalEntries );
1630 case EMR_RESIZEPALETTE:
1632 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1634 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1635 (UINT)lpResizePalette->cEntries );
1640 case EMR_CREATEDIBPATTERNBRUSHPT:
1642 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1643 LPVOID lpPackedStruct;
1645 /* check that offsets and data are contained within the record */
1646 if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
1647 (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
1648 ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
1649 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
1651 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1655 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1656 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1657 lpCreate->cbBmi + lpCreate->cbBits );
1660 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1664 /* Now pack this structure */
1665 memcpy( lpPackedStruct,
1666 ((BYTE*)lpCreate) + lpCreate->offBmi,
1668 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1669 ((BYTE*)lpCreate) + lpCreate->offBits,
1672 (handletable->objectHandle)[lpCreate->ihBrush] =
1673 CreateDIBPatternBrushPt( lpPackedStruct,
1674 (UINT)lpCreate->iUsage );
1676 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1680 case EMR_CREATEMONOBRUSH:
1682 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1683 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1686 /* Need to check if the bitmap is monochrome, and if the
1687 two colors are really black and white */
1688 if (pCreateMonoBrush->iUsage == DIB_PAL_MONO)
1692 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1693 * aligned to 32 rather than 16 bits.
1696 bm.bmWidth = pbi->bmiHeader.biWidth;
1697 bm.bmHeight = abs(pbi->bmiHeader.biHeight);
1698 bm.bmWidthBytes = 4 * ((pbi->bmiHeader.biWidth + 31) / 32);
1699 bm.bmPlanes = pbi->bmiHeader.biPlanes;
1700 bm.bmBitsPixel = pbi->bmiHeader.biBitCount;
1701 bm.bmBits = (BYTE *)mr + pCreateMonoBrush->offBits;
1702 hBmp = CreateBitmapIndirect(&bm);
1704 else if (is_dib_monochrome(pbi))
1706 /* Top-down DIBs have a negative height */
1707 LONG height = pbi->bmiHeader.biHeight;
1709 hBmp = CreateBitmap(pbi->bmiHeader.biWidth, abs(height), 1, 1, NULL);
1710 SetDIBits(hdc, hBmp, 0, pbi->bmiHeader.biHeight,
1711 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1715 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1716 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1719 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1721 /* CreatePatternBrush created a copy of the bitmap */
1728 PEMRBITBLT pBitBlt = (PEMRBITBLT)mr;
1730 if(pBitBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1731 PatBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1733 } else { /* BitBlt */
1734 HDC hdcSrc = CreateCompatibleDC(hdc);
1735 HBRUSH hBrush, hBrushOld;
1736 HBITMAP hBmp = 0, hBmpOld = 0;
1737 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pBitBlt->offBmiSrc);
1739 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1741 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1742 hBrushOld = SelectObject(hdcSrc, hBrush);
1743 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1744 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1745 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1746 SelectObject(hdcSrc, hBrushOld);
1747 DeleteObject(hBrush);
1749 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1750 (BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1751 hBmpOld = SelectObject(hdcSrc, hBmp);
1753 BitBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1754 hdcSrc, pBitBlt->xSrc, pBitBlt->ySrc, pBitBlt->dwRop);
1756 SelectObject(hdcSrc, hBmpOld);
1763 case EMR_STRETCHBLT:
1765 PEMRSTRETCHBLT pStretchBlt= (PEMRSTRETCHBLT)mr;
1767 TRACE("EMR_STRETCHBLT: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. rop %08lx offBitsSrc %ld\n",
1768 pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1769 pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1770 pStretchBlt->dwRop, pStretchBlt->offBitsSrc);
1772 if(pStretchBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1773 PatBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1774 pStretchBlt->dwRop);
1775 } else { /* StretchBlt */
1776 HDC hdcSrc = CreateCompatibleDC(hdc);
1777 HBRUSH hBrush, hBrushOld;
1778 HBITMAP hBmp = 0, hBmpOld = 0;
1779 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pStretchBlt->offBmiSrc);
1781 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1783 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1784 hBrushOld = SelectObject(hdcSrc, hBrush);
1785 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1786 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1787 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1788 SelectObject(hdcSrc, hBrushOld);
1789 DeleteObject(hBrush);
1791 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1792 (BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1793 hBmpOld = SelectObject(hdcSrc, hBmp);
1795 StretchBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1796 hdcSrc, pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1797 pStretchBlt->dwRop);
1799 SelectObject(hdcSrc, hBmpOld);
1806 case EMR_ALPHABLEND:
1808 PEMRALPHABLEND pAlphaBlend= (PEMRALPHABLEND)mr;
1810 TRACE("EMR_ALPHABLEND: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. blendfn %08lx offBitsSrc %ld\n",
1811 pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1812 pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1813 pAlphaBlend->dwRop, pAlphaBlend->offBitsSrc);
1815 if(pAlphaBlend->offBmiSrc == 0) {
1816 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1818 HDC hdcSrc = CreateCompatibleDC(hdc);
1819 HBITMAP hBmp = 0, hBmpOld = 0;
1820 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pAlphaBlend->offBmiSrc);
1821 BLENDFUNCTION blendfn;
1824 SetWorldTransform(hdcSrc, &pAlphaBlend->xformSrc);
1826 hBmp = CreateDIBSection(hdc, pbi, pAlphaBlend->iUsageSrc, &bits, NULL, 0);
1827 memcpy(bits, (BYTE*)mr + pAlphaBlend->offBitsSrc, pAlphaBlend->cbBitsSrc);
1828 hBmpOld = SelectObject(hdcSrc, hBmp);
1830 blendfn.BlendOp = (pAlphaBlend->dwRop >> 24) & 0xff;
1831 blendfn.BlendFlags = (pAlphaBlend->dwRop >> 16) & 0xff;
1832 blendfn.SourceConstantAlpha = (pAlphaBlend->dwRop >> 8) & 0xff;
1833 blendfn.AlphaFormat = (pAlphaBlend->dwRop) & 0xff;
1835 GdiAlphaBlend(hdc, pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1836 hdcSrc, pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1839 SelectObject(hdcSrc, hBmpOld);
1848 PEMRMASKBLT pMaskBlt= (PEMRMASKBLT)mr;
1849 HDC hdcSrc = CreateCompatibleDC(hdc);
1850 HBRUSH hBrush, hBrushOld;
1851 HBITMAP hBmp, hBmpOld, hBmpMask;
1854 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1856 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1857 hBrushOld = SelectObject(hdcSrc, hBrush);
1858 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1859 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1860 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1861 SelectObject(hdcSrc, hBrushOld);
1862 DeleteObject(hBrush);
1864 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiMask);
1865 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1867 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1868 (BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1870 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiSrc);
1871 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1872 (BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1873 hBmpOld = SelectObject(hdcSrc, hBmp);
1886 SelectObject(hdcSrc, hBmpOld);
1888 DeleteObject(hBmpMask);
1895 PEMRPLGBLT pPlgBlt= (PEMRPLGBLT)mr;
1896 HDC hdcSrc = CreateCompatibleDC(hdc);
1897 HBRUSH hBrush, hBrushOld;
1898 HBITMAP hBmp, hBmpOld, hBmpMask;
1902 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1904 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1905 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1906 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1908 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1909 hBrushOld = SelectObject(hdcSrc, hBrush);
1910 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1911 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1912 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1913 SelectObject(hdcSrc, hBrushOld);
1914 DeleteObject(hBrush);
1916 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiMask);
1917 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1919 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1920 (BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1922 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiSrc);
1923 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1924 (BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1925 hBmpOld = SelectObject(hdcSrc, hBmp);
1936 SelectObject(hdcSrc, hBmpOld);
1938 DeleteObject(hBmpMask);
1943 case EMR_SETDIBITSTODEVICE:
1945 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice = (PEMRSETDIBITSTODEVICE)mr;
1947 SetDIBitsToDevice(hdc,
1948 pSetDIBitsToDevice->xDest,
1949 pSetDIBitsToDevice->yDest,
1950 pSetDIBitsToDevice->cxSrc,
1951 pSetDIBitsToDevice->cySrc,
1952 pSetDIBitsToDevice->xSrc,
1953 pSetDIBitsToDevice->ySrc,
1954 pSetDIBitsToDevice->iStartScan,
1955 pSetDIBitsToDevice->cScans,
1956 (BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
1957 (BITMAPINFO *)((BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
1958 pSetDIBitsToDevice->iUsageSrc);
1962 case EMR_POLYTEXTOUTA:
1964 PEMRPOLYTEXTOUTA pPolyTextOutA = (PEMRPOLYTEXTOUTA)mr;
1965 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
1967 XFORM xform, xformOld;
1970 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
1971 GetWorldTransform(hdc, &xformOld);
1973 xform.eM11 = pPolyTextOutA->exScale;
1976 xform.eM22 = pPolyTextOutA->eyScale;
1979 SetWorldTransform(hdc, &xform);
1981 /* Set up POLYTEXTA structures */
1982 for(i = 0; i < pPolyTextOutA->cStrings; i++)
1984 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
1985 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
1986 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
1987 polytextA[i].lpstr = (LPSTR)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
1988 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
1989 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
1990 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
1991 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
1992 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
1993 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
1995 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
1996 HeapFree(GetProcessHeap(), 0, polytextA);
1998 SetWorldTransform(hdc, &xformOld);
1999 SetGraphicsMode(hdc, gModeOld);
2003 case EMR_POLYTEXTOUTW:
2005 PEMRPOLYTEXTOUTW pPolyTextOutW = (PEMRPOLYTEXTOUTW)mr;
2006 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
2008 XFORM xform, xformOld;
2011 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
2012 GetWorldTransform(hdc, &xformOld);
2014 xform.eM11 = pPolyTextOutW->exScale;
2017 xform.eM22 = pPolyTextOutW->eyScale;
2020 SetWorldTransform(hdc, &xform);
2022 /* Set up POLYTEXTW structures */
2023 for(i = 0; i < pPolyTextOutW->cStrings; i++)
2025 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
2026 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
2027 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
2028 polytextW[i].lpstr = (LPWSTR)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
2029 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
2030 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
2031 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
2032 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
2033 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
2034 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
2036 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
2037 HeapFree(GetProcessHeap(), 0, polytextW);
2039 SetWorldTransform(hdc, &xformOld);
2040 SetGraphicsMode(hdc, gModeOld);
2046 PEMRFILLRGN pFillRgn = (PEMRFILLRGN)mr;
2047 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
2050 (handletable->objectHandle)[pFillRgn->ihBrush]);
2057 PEMRFRAMERGN pFrameRgn = (PEMRFRAMERGN)mr;
2058 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
2061 (handletable->objectHandle)[pFrameRgn->ihBrush],
2062 pFrameRgn->szlStroke.cx,
2063 pFrameRgn->szlStroke.cy);
2070 PEMRINVERTRGN pInvertRgn = (PEMRINVERTRGN)mr;
2071 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
2072 InvertRgn(hdc, hRgn);
2079 PEMRPAINTRGN pPaintRgn = (PEMRPAINTRGN)mr;
2080 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
2081 PaintRgn(hdc, hRgn);
2086 case EMR_SETTEXTJUSTIFICATION:
2088 PEMRSETTEXTJUSTIFICATION pSetTextJust = (PEMRSETTEXTJUSTIFICATION)mr;
2089 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
2095 PEMRSETLAYOUT pSetLayout = (PEMRSETLAYOUT)mr;
2096 SetLayout(hdc, pSetLayout->iMode);
2100 case EMR_POLYDRAW16:
2102 case EMR_GLSBOUNDEDRECORD:
2103 case EMR_DRAWESCAPE :
2106 case EMR_SMALLTEXTOUT:
2107 case EMR_FORCEUFIMAPPING:
2108 case EMR_NAMEDESCAPE:
2109 case EMR_COLORCORRECTPALETTE:
2110 case EMR_SETICMPROFILEA:
2111 case EMR_SETICMPROFILEW:
2112 case EMR_TRANSPARENTBLT:
2113 case EMR_GRADIENTFILL:
2114 case EMR_SETLINKEDUFI:
2115 case EMR_COLORMATCHTOTARGETW:
2116 case EMR_CREATECOLORSPACEW:
2119 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2120 record then ignore and return TRUE. */
2121 FIXME("type %d is unimplemented\n", type);
2124 tmprc.left = tmprc.top = 0;
2125 tmprc.right = tmprc.bottom = 1000;
2126 LPtoDP(hdc, (POINT*)&tmprc, 2);
2127 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", tmprc.left,
2128 tmprc.top, tmprc.right, tmprc.bottom);
2132 /* WinNT - update the transform (win9x updates when the next graphics output
2133 record is played). */
2134 EMF_Update_MF_Xform(hdc, info);
2141 /*****************************************************************************
2143 * EnumEnhMetaFile (GDI32.@)
2145 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2147 * record. Returns when either every record has been used or
2148 * when _EnhMetaFunc_ returns FALSE.
2152 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2159 * This function behaves differently in Win9x and WinNT.
2161 * In WinNT, the DC's world transform is updated as the EMF changes
2162 * the Window/Viewport Extent and Origin or it's world transform.
2163 * The actual Window/Viewport Extent and Origin are left untouched.
2165 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2166 * updates the scaling itself but only just before a record that
2167 * writes anything to the DC.
2169 * I'm not sure where the data (enum_emh_data) is stored in either
2170 * version. For this implementation, it is stored before the handle
2171 * table, but it could be stored in the DC, in the EMF handle or in
2175 BOOL WINAPI EnumEnhMetaFile(
2176 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
2177 HENHMETAFILE hmf, /* [in] EMF to walk */
2178 ENHMFENUMPROC callback, /* [in] callback function */
2179 LPVOID data, /* [in] optional data for callback function */
2180 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
2192 HBRUSH hBrush = NULL;
2194 enum_emh_data *info;
2195 SIZE vp_size, win_size;
2196 POINT vp_org, win_org;
2197 INT mapMode = MM_TEXT, old_align = 0, old_rop2 = 0, old_arcdir = 0, old_polyfill = 0, old_stretchblt = 0;
2198 COLORREF old_text_color = 0, old_bk_color = 0;
2202 SetLastError(ERROR_INVALID_PARAMETER);
2206 emh = EMF_GetEnhMetaHeader(hmf);
2208 SetLastError(ERROR_INVALID_HANDLE);
2212 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2213 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
2216 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2223 info->vportOrgX = 0;
2224 info->vportOrgY = 0;
2225 info->vportExtX = 1;
2226 info->vportExtY = 1;
2227 info->world_transform.eM11 = info->world_transform.eM22 = 1;
2228 info->world_transform.eM12 = info->world_transform.eM21 = 0;
2229 info->world_transform.eDx = info->world_transform.eDy = 0;
2231 ht = (HANDLETABLE*) &info[1];
2232 ht->objectHandle[0] = hmf;
2236 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
2237 GetWorldTransform(hdc, &savedXform);
2238 GetViewportExtEx(hdc, &vp_size);
2239 GetWindowExtEx(hdc, &win_size);
2240 GetViewportOrgEx(hdc, &vp_org);
2241 GetWindowOrgEx(hdc, &win_org);
2242 mapMode = GetMapMode(hdc);
2244 /* save the current pen, brush and font */
2245 hPen = GetCurrentObject(hdc, OBJ_PEN);
2246 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
2247 hFont = GetCurrentObject(hdc, OBJ_FONT);
2249 old_text_color = SetTextColor(hdc, RGB(0,0,0));
2250 old_bk_color = SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
2251 old_align = SetTextAlign(hdc, 0);
2252 old_rop2 = SetROP2(hdc, R2_COPYPEN);
2253 old_arcdir = SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
2254 old_polyfill = SetPolyFillMode(hdc, ALTERNATE);
2255 old_stretchblt = SetStretchBltMode(hdc, BLACKONWHITE);
2258 info->mode = MM_TEXT;
2262 /* Win95 leaves the vp/win ext/org info alone */
2263 info->init_transform.eM11 = 1.0;
2264 info->init_transform.eM12 = 0.0;
2265 info->init_transform.eM21 = 0.0;
2266 info->init_transform.eM22 = 1.0;
2267 info->init_transform.eDx = 0.0;
2268 info->init_transform.eDy = 0.0;
2272 /* WinNT combines the vp/win ext/org info into a transform */
2273 FLOAT xscale, yscale;
2274 xscale = (FLOAT)vp_size.cx / (FLOAT)win_size.cx;
2275 yscale = (FLOAT)vp_size.cy / (FLOAT)win_size.cy;
2276 info->init_transform.eM11 = xscale;
2277 info->init_transform.eM12 = 0.0;
2278 info->init_transform.eM21 = 0.0;
2279 info->init_transform.eM22 = yscale;
2280 info->init_transform.eDx = (FLOAT)vp_org.x - xscale * (FLOAT)win_org.x;
2281 info->init_transform.eDy = (FLOAT)vp_org.y - yscale * (FLOAT)win_org.y;
2283 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
2286 if ( lpRect && WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
2288 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
2291 TRACE("rect: %ld,%ld - %ld,%ld. rclFrame: %ld,%ld - %ld,%ld\n",
2292 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
2293 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
2294 emh->rclFrame.bottom);
2296 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
2297 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
2298 xscale = (FLOAT) WIDTH(*lpRect) * 100.0 /
2299 WIDTH(emh->rclFrame) * xSrcPixSize;
2300 yscale = (FLOAT) HEIGHT(*lpRect) * 100.0 /
2301 HEIGHT(emh->rclFrame) * ySrcPixSize;
2302 TRACE("xscale = %f, yscale = %f\n", xscale, yscale);
2304 xform.eM11 = xscale;
2307 xform.eM22 = yscale;
2308 xform.eDx = (FLOAT) lpRect->left - (FLOAT) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
2309 xform.eDy = (FLOAT) lpRect->top - (FLOAT) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
2311 CombineTransform(&info->init_transform, &xform, &info->init_transform);
2314 /* WinNT resets the current vp/win org/ext */
2315 if ( !IS_WIN9X() && hdc )
2317 SetMapMode(hdc, MM_TEXT);
2318 SetWindowOrgEx(hdc, 0, 0, NULL);
2319 SetViewportOrgEx(hdc, 0, 0, NULL);
2320 EMF_Update_MF_Xform(hdc, info);
2325 while(ret && offset < emh->nBytes)
2327 emr = (ENHMETARECORD *)((char *)emh + offset);
2328 TRACE("Calling EnumFunc with record %s, size %ld\n", get_emr_name(emr->iType), emr->nSize);
2329 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2330 offset += emr->nSize;
2335 SetStretchBltMode(hdc, old_stretchblt);
2336 SetPolyFillMode(hdc, old_polyfill);
2337 SetArcDirection(hdc, old_arcdir);
2338 SetROP2(hdc, old_rop2);
2339 SetTextAlign(hdc, old_align);
2340 SetBkColor(hdc, old_bk_color);
2341 SetTextColor(hdc, old_text_color);
2343 /* restore pen, brush and font */
2344 SelectObject(hdc, hBrush);
2345 SelectObject(hdc, hPen);
2346 SelectObject(hdc, hFont);
2348 SetWorldTransform(hdc, &savedXform);
2350 SetGraphicsMode(hdc, savedMode);
2351 SetMapMode(hdc, mapMode);
2352 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2353 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2354 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2355 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2358 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2359 if( (ht->objectHandle)[i] )
2360 DeleteObject( (ht->objectHandle)[i] );
2362 HeapFree( GetProcessHeap(), 0, info );
2366 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2367 const ENHMETARECORD *emr,
2368 INT handles, LPARAM data)
2370 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2373 /**************************************************************************
2374 * PlayEnhMetaFile (GDI32.@)
2376 * Renders an enhanced metafile into a specified rectangle *lpRect
2377 * in device context hdc.
2383 BOOL WINAPI PlayEnhMetaFile(
2384 HDC hdc, /* [in] DC to render into */
2385 HENHMETAFILE hmf, /* [in] metafile to render */
2386 const RECT *lpRect /* [in] rectangle to place metafile inside */
2389 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2393 /*****************************************************************************
2394 * DeleteEnhMetaFile (GDI32.@)
2396 * Deletes an enhanced metafile and frees the associated storage.
2398 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2400 return EMF_Delete_HENHMETAFILE( hmf );
2403 /*****************************************************************************
2404 * CopyEnhMetaFileA (GDI32.@)
2406 * Duplicate an enhanced metafile.
2410 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2411 HENHMETAFILE hmfSrc,
2414 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2415 HENHMETAFILE hmfDst;
2417 if(!emrSrc) return FALSE;
2419 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2420 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2421 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2425 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2426 NULL, CREATE_ALWAYS, 0, 0);
2427 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2428 CloseHandle( hFile );
2429 /* Reopen file for reading only, so that apps can share
2430 read access to the file while hmf is still valid */
2431 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2432 NULL, OPEN_EXISTING, 0, 0);
2433 if(hFile == INVALID_HANDLE_VALUE) {
2434 ERR("Can't reopen emf for reading\n");
2437 hmfDst = EMF_GetEnhMetaFile( hFile );
2438 CloseHandle( hFile );
2443 /*****************************************************************************
2444 * CopyEnhMetaFileW (GDI32.@)
2446 * See CopyEnhMetaFileA.
2450 HENHMETAFILE WINAPI CopyEnhMetaFileW(
2451 HENHMETAFILE hmfSrc,
2454 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2455 HENHMETAFILE hmfDst;
2457 if(!emrSrc) return FALSE;
2459 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2460 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2461 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2465 hFile = CreateFileW( file, GENERIC_WRITE | GENERIC_READ, 0,
2466 NULL, CREATE_ALWAYS, 0, 0);
2467 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2468 CloseHandle( hFile );
2469 /* Reopen file for reading only, so that apps can share
2470 read access to the file while hmf is still valid */
2471 hFile = CreateFileW( file, GENERIC_READ, FILE_SHARE_READ,
2472 NULL, OPEN_EXISTING, 0, 0);
2473 if(hFile == INVALID_HANDLE_VALUE) {
2474 ERR("Can't reopen emf for reading\n");
2477 hmfDst = EMF_GetEnhMetaFile( hFile );
2478 CloseHandle( hFile );
2484 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2485 typedef struct tagEMF_PaletteCopy
2488 LPPALETTEENTRY lpPe;
2491 /***************************************************************
2492 * Find the EMR_EOF record and then use it to find the
2493 * palette entries for this enhanced metafile.
2494 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2495 * which contains the max number of elements to copy and where
2498 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2500 static INT CALLBACK cbEnhPaletteCopy( HDC a,
2502 const ENHMETARECORD *lpEMR,
2507 if ( lpEMR->iType == EMR_EOF )
2509 PEMREOF lpEof = (PEMREOF)lpEMR;
2510 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2511 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2513 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
2515 memcpy( (LPVOID)info->lpPe,
2516 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
2517 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2519 /* Update the passed data as a return code */
2520 info->lpPe = NULL; /* Palettes were copied! */
2521 info->cEntries = (UINT)dwNumPalToCopy;
2523 return FALSE; /* That's all we need */
2529 /*****************************************************************************
2530 * GetEnhMetaFilePaletteEntries (GDI32.@)
2532 * Copy the palette and report size
2534 * BUGS: Error codes (SetLastError) are not set on failures
2536 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2538 LPPALETTEENTRY lpPe )
2540 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2541 EMF_PaletteCopy infoForCallBack;
2543 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2545 /* First check if there are any palettes associated with
2547 if ( enhHeader->nPalEntries == 0 ) return 0;
2549 /* Is the user requesting the number of palettes? */
2550 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
2552 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2553 infoForCallBack.cEntries = cEntries;
2554 infoForCallBack.lpPe = lpPe;
2556 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2557 &infoForCallBack, 0 ) )
2560 /* Verify that the callback executed correctly */
2561 if ( infoForCallBack.lpPe != NULL )
2563 /* Callback proc had error! */
2564 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2568 return infoForCallBack.cEntries;
2571 typedef struct gdi_mf_comment
2578 DWORD cbWinMetaFile;
2581 /******************************************************************
2582 * SetWinMetaFileBits (GDI32.@)
2584 * Translate from old style to new style.
2587 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2588 CONST BYTE *lpbBuffer,
2590 CONST METAFILEPICT *lpmfp
2593 static const WCHAR szDisplayW[] = { 'D','I','S','P','L','A','Y','\0' };
2594 HMETAFILE hmf = NULL;
2595 HENHMETAFILE ret = NULL;
2596 HDC hdc = NULL, hdcdisp = NULL;
2597 RECT rc, *prcFrame = NULL;
2598 gdi_mf_comment *mfcomment;
2599 UINT mfcomment_size;
2601 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2603 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2606 WARN("SetMetaFileBitsEx failed\n");
2611 hdcRef = hdcdisp = CreateDCW(szDisplayW, NULL, NULL, NULL);
2614 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2616 if (lpmfp && (lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC))
2618 rc.left = rc.top = 0;
2619 rc.right = lpmfp->xExt;
2620 rc.bottom = lpmfp->yExt;
2624 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL)))
2626 ERR("CreateEnhMetaFile fails?\n");
2631 * Write the original METAFILE into the enhanced metafile.
2632 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2634 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2635 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2638 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2639 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2640 mfcomment->nVersion = 0x00000300;
2641 mfcomment->nChecksum = 0; /* FIXME */
2642 mfcomment->fFlags = 0;
2643 mfcomment->cbWinMetaFile = cbBuffer;
2644 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2645 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2646 HeapFree(GetProcessHeap(), 0, mfcomment);
2649 if(lpmfp && lpmfp->mm != MM_TEXT)
2650 SetMapMode(hdc, lpmfp->mm);
2652 if (lpmfp && (lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC))
2654 INT horzres, vertres, horzsize, vertsize, xext, yext;
2656 horzres = GetDeviceCaps(hdcRef, HORZRES);
2657 vertres = GetDeviceCaps(hdcRef, VERTRES);
2658 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2659 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2661 /* set the initial viewport:window ratio as 1:1 */
2662 xext = lpmfp->xExt*horzres/(100*horzsize);
2663 yext = lpmfp->yExt*vertres/(100*vertsize);
2664 SetViewportExtEx(hdc, xext, yext, NULL);
2665 SetWindowExtEx(hdc, xext, yext, NULL);
2668 PlayMetaFile(hdc, hmf);
2670 ret = CloseEnhMetaFile(hdc);
2672 if (hdcdisp) DeleteDC(hdcdisp);
2673 DeleteMetaFile(hmf);