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"
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 %ld\n", type);
199 /****************************************************************************
200 * EMF_Create_HENHMETAFILE
202 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk )
204 HENHMETAFILE hmf = 0;
205 ENHMETAFILEOBJ *metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
207 (HGDIOBJ *)&hmf, NULL );
211 metaObj->on_disk = on_disk;
212 GDI_ReleaseObj( hmf );
217 /****************************************************************************
218 * EMF_Delete_HENHMETAFILE
220 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
222 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
224 if(!metaObj) return FALSE;
227 UnmapViewOfFile( metaObj->emh );
229 HeapFree( GetProcessHeap(), 0, metaObj->emh );
230 return GDI_FreeObject( hmf, metaObj );
233 /******************************************************************
234 * EMF_GetEnhMetaHeader
236 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
238 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
240 ENHMETAHEADER *ret = NULL;
241 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
242 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
246 GDI_ReleaseObj( hmf );
251 /*****************************************************************************
255 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
260 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
261 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
262 CloseHandle( hMapping );
266 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
267 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
268 emh->iType, emh->dSignature);
272 /* refuse to load unaligned EMF as Windows does */
275 WARN("Refusing to load unaligned EMF\n");
279 return EMF_Create_HENHMETAFILE( emh, TRUE );
282 UnmapViewOfFile( emh );
287 /*****************************************************************************
288 * GetEnhMetaFileA (GDI32.@)
292 HENHMETAFILE WINAPI GetEnhMetaFileA(
293 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
299 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
300 OPEN_EXISTING, 0, 0);
301 if (hFile == INVALID_HANDLE_VALUE) {
302 WARN("could not open %s\n", lpszMetaFile);
305 hmf = EMF_GetEnhMetaFile( hFile );
306 CloseHandle( hFile );
310 /*****************************************************************************
311 * GetEnhMetaFileW (GDI32.@)
313 HENHMETAFILE WINAPI GetEnhMetaFileW(
314 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
319 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
320 OPEN_EXISTING, 0, 0);
321 if (hFile == INVALID_HANDLE_VALUE) {
322 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
325 hmf = EMF_GetEnhMetaFile( hFile );
326 CloseHandle( hFile );
330 /*****************************************************************************
331 * GetEnhMetaFileHeader (GDI32.@)
333 * If buf is NULL, returns the size of buffer required.
334 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
337 UINT WINAPI GetEnhMetaFileHeader(
338 HENHMETAFILE hmf, /* [in] enhanced metafile */
339 UINT bufsize, /* [in] size of buffer */
340 LPENHMETAHEADER buf /* [out] buffer */
346 emh = EMF_GetEnhMetaHeader(hmf);
347 if(!emh) return FALSE;
349 if (!buf) return size;
350 size = min(size, bufsize);
351 memmove(buf, emh, size);
356 /*****************************************************************************
357 * GetEnhMetaFileDescriptionA (GDI32.@)
359 UINT WINAPI GetEnhMetaFileDescriptionA(
360 HENHMETAFILE hmf, /* [in] enhanced metafile */
361 UINT size, /* [in] size of buf */
362 LPSTR buf /* [out] buffer to receive description */
365 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
369 if(!emh) return FALSE;
370 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
371 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
372 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
374 if (!buf || !size ) return len;
376 len = min( size, len );
377 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
381 /*****************************************************************************
382 * GetEnhMetaFileDescriptionW (GDI32.@)
384 * Copies the description string of an enhanced metafile into a buffer
387 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
388 * number of characters copied.
390 UINT WINAPI GetEnhMetaFileDescriptionW(
391 HENHMETAFILE hmf, /* [in] enhanced metafile */
392 UINT size, /* [in] size of buf */
393 LPWSTR buf /* [out] buffer to receive description */
396 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
398 if(!emh) return FALSE;
399 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
400 if (!buf || !size ) return emh->nDescription;
402 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
403 return min(size, emh->nDescription);
406 /****************************************************************************
407 * SetEnhMetaFileBits (GDI32.@)
409 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
411 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
413 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
414 memmove(emh, buf, bufsize);
415 return EMF_Create_HENHMETAFILE( emh, FALSE );
418 /*****************************************************************************
419 * GetEnhMetaFileBits (GDI32.@)
422 UINT WINAPI GetEnhMetaFileBits(
428 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
434 if( buf == NULL ) return size;
436 size = min( size, bufsize );
437 memmove(buf, emh, size);
441 typedef struct enum_emh_data
444 XFORM init_transform;
445 XFORM world_transform;
456 #define ENUM_GET_PRIVATE_DATA(ht) \
457 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
459 #define WIDTH(rect) ( (rect).right - (rect).left )
460 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
462 #define IS_WIN9X() (GetVersion()&0x80000000)
464 void EMF_Update_MF_Xform(HDC hdc, enum_emh_data *info)
466 XFORM mapping_mode_trans, final_trans;
467 FLOAT scaleX, scaleY;
469 scaleX = (FLOAT)info->vportExtX / (FLOAT)info->wndExtX;
470 scaleY = (FLOAT)info->vportExtY / (FLOAT)info->wndExtY;
471 mapping_mode_trans.eM11 = scaleX;
472 mapping_mode_trans.eM12 = 0.0;
473 mapping_mode_trans.eM21 = 0.0;
474 mapping_mode_trans.eM22 = scaleY;
475 mapping_mode_trans.eDx = (FLOAT)info->vportOrgX - scaleX * (FLOAT)info->wndOrgX;
476 mapping_mode_trans.eDy = (FLOAT)info->vportOrgY - scaleY * (FLOAT)info->wndOrgY;
478 CombineTransform(&final_trans, &info->world_transform, &mapping_mode_trans);
479 CombineTransform(&final_trans, &final_trans, &info->init_transform);
481 if (!SetWorldTransform(hdc, &final_trans))
483 ERR("World transform failed!\n");
487 void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
489 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
490 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
491 INT horzRes = GetDeviceCaps( hdc, HORZRES );
492 INT vertRes = GetDeviceCaps( hdc, VERTRES );
494 TRACE("%d\n",info->mode);
506 info->wndExtX = horzSize * 10;
507 info->wndExtY = vertSize * 10;
508 info->vportExtX = horzRes;
509 info->vportExtY = -vertRes;
512 info->wndExtX = horzSize * 100;
513 info->wndExtY = vertSize * 100;
514 info->vportExtX = horzRes;
515 info->vportExtY = -vertRes;
518 info->wndExtX = MulDiv(1000, horzSize, 254);
519 info->wndExtY = MulDiv(1000, vertSize, 254);
520 info->vportExtX = horzRes;
521 info->vportExtY = -vertRes;
524 info->wndExtX = MulDiv(10000, horzSize, 254);
525 info->wndExtY = MulDiv(10000, vertSize, 254);
526 info->vportExtX = horzRes;
527 info->vportExtY = -vertRes;
530 info->wndExtX = MulDiv(14400, horzSize, 254);
531 info->wndExtY = MulDiv(14400, vertSize, 254);
532 info->vportExtX = horzRes;
533 info->vportExtY = -vertRes;
542 /*****************************************************************************
543 * emr_produces_output
545 * Returns TRUE if the record type writes something to the dc. Used by
546 * PlayEnhMetaFileRecord to determine whether it needs to update the
547 * dc's xform when in win9x mode.
549 * FIXME: need to test which records should be here.
551 static BOOL emr_produces_output(int type)
557 case EMR_POLYBEZIERTO:
559 case EMR_POLYPOLYLINE:
560 case EMR_POLYPOLYGON:
563 case EMR_EXCLUDECLIPRECT:
564 case EMR_INTERSECTCLIPRECT:
565 case EMR_SELECTOBJECT:
573 case EMR_EXTFLOODFILL:
585 case EMR_SETDIBITSTODEVICE:
586 case EMR_STRETCHDIBITS:
587 case EMR_EXTTEXTOUTA:
588 case EMR_EXTTEXTOUTW:
589 case EMR_POLYBEZIER16:
592 case EMR_POLYBEZIERTO16:
593 case EMR_POLYLINETO16:
594 case EMR_POLYPOLYLINE16:
595 case EMR_POLYPOLYGON16:
597 case EMR_POLYTEXTOUTA:
598 case EMR_POLYTEXTOUTW:
599 case EMR_SMALLTEXTOUT:
600 case EMR_TRANSPARENTBLT:
608 /*****************************************************************************
609 * PlayEnhMetaFileRecord (GDI32.@)
611 * Render a single enhanced metafile record in the device context hdc.
614 * TRUE (non zero) on success, FALSE on error.
616 * Many unimplemented records.
617 * No error handling on record play failures (ie checking return codes)
620 * WinNT actually updates the current world transform in this function
621 * whereas Win9x does not.
623 BOOL WINAPI PlayEnhMetaFileRecord(
624 HDC hdc, /* [in] device context in which to render EMF record */
625 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
626 const ENHMETARECORD *mr, /* [in] EMF record to render */
627 UINT handles /* [in] size of handle array */
632 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
634 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
635 hdc, handletable, mr, handles);
636 if (!mr) return FALSE;
640 /* In Win9x mode we update the xform if the record will produce output */
641 if ( IS_WIN9X() && emr_produces_output(type) )
642 EMF_Update_MF_Xform(hdc, info);
644 TRACE("record %s\n", get_emr_name(type));
653 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
654 /* In an enhanced metafile, there can be both public and private GDI comments */
655 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
660 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
662 if(info->mode == pSetMapMode->iMode && (info->mode == MM_ISOTROPIC || info->mode == MM_ANISOTROPIC))
664 info->mode = pSetMapMode->iMode;
665 EMF_SetMapMode(hdc, info);
670 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
671 SetBkMode(hdc, pSetBkMode->iMode);
676 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
677 SetBkColor(hdc, pSetBkColor->crColor);
680 case EMR_SETPOLYFILLMODE:
682 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
683 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
688 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
689 SetROP2(hdc, pSetROP2->iMode);
692 case EMR_SETSTRETCHBLTMODE:
694 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
695 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
698 case EMR_SETTEXTALIGN:
700 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
701 SetTextAlign(hdc, pSetTextAlign->iMode);
704 case EMR_SETTEXTCOLOR:
706 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
707 SetTextColor(hdc, pSetTextColor->crColor);
717 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
718 TRACE("EMR_RESTORE: %ld\n", pRestoreDC->iRelative);
719 RestoreDC(hdc, pRestoreDC->iRelative);
722 case EMR_INTERSECTCLIPRECT:
724 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
725 TRACE("EMR_INTERSECTCLIPRECT: rect %ld,%ld - %ld, %ld\n",
726 pClipRect->rclClip.left, pClipRect->rclClip.top,
727 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
728 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
729 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
732 case EMR_SELECTOBJECT:
734 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
735 if( pSelectObject->ihObject & 0x80000000 ) {
736 /* High order bit is set - it's a stock object
737 * Strip the high bit to get the index.
738 * See MSDN article Q142319
740 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
743 /* High order bit wasn't set - not a stock object
746 (handletable->objectHandle)[pSelectObject->ihObject] );
750 case EMR_DELETEOBJECT:
752 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
753 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
754 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
757 case EMR_SETWINDOWORGEX:
759 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
761 info->wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
762 info->wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
764 TRACE("SetWindowOrgEx: %d,%d\n",info->wndOrgX,info->wndOrgY);
767 case EMR_SETWINDOWEXTEX:
769 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
771 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
773 info->wndExtX = pSetWindowExtEx->szlExtent.cx;
774 info->wndExtY = pSetWindowExtEx->szlExtent.cy;
776 TRACE("SetWindowExtEx: %d,%d\n",info->wndExtX,info->wndExtY);
779 case EMR_SETVIEWPORTORGEX:
781 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
782 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
784 info->vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
785 info->vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
786 TRACE("SetViewportOrgEx: %d,%d\n",info->vportOrgX,info->vportOrgY);
789 case EMR_SETVIEWPORTEXTEX:
791 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
792 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
794 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
796 info->vportExtX = pSetViewportExtEx->szlExtent.cx;
797 info->vportExtY = pSetViewportExtEx->szlExtent.cy;
798 TRACE("SetViewportExtEx: %d,%d\n",info->vportExtX,info->vportExtY);
803 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
804 (handletable->objectHandle)[pCreatePen->ihPen] =
805 CreatePenIndirect(&pCreatePen->lopn);
808 case EMR_EXTCREATEPEN:
810 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
812 lb.lbStyle = pPen->elp.elpBrushStyle;
813 lb.lbColor = pPen->elp.elpColor;
814 lb.lbHatch = pPen->elp.elpHatch;
816 if(pPen->offBmi || pPen->offBits)
817 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
819 (handletable->objectHandle)[pPen->ihPen] =
820 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
821 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
824 case EMR_CREATEBRUSHINDIRECT:
826 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
827 (handletable->objectHandle)[pBrush->ihBrush] =
828 CreateBrushIndirect(&pBrush->lb);
831 case EMR_EXTCREATEFONTINDIRECTW:
833 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
834 (handletable->objectHandle)[pFont->ihFont] =
835 CreateFontIndirectW(&pFont->elfw.elfLogFont);
840 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
841 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
846 PEMRLINETO pLineTo = (PEMRLINETO) mr;
847 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
852 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
853 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
854 pRect->rclBox.right, pRect->rclBox.bottom);
859 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
860 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
861 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
866 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
867 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
868 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
869 pPoly->cpts * sizeof(POINT) );
871 for(i = 0; i < pPoly->cpts; i++)
873 pts[i].x = pPoly->apts[i].x;
874 pts[i].y = pPoly->apts[i].y;
876 Polygon(hdc, pts, pPoly->cpts);
877 HeapFree( GetProcessHeap(), 0, pts );
882 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
883 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
884 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
885 pPoly->cpts * sizeof(POINT) );
887 for(i = 0; i < pPoly->cpts; i++)
889 pts[i].x = pPoly->apts[i].x;
890 pts[i].y = pPoly->apts[i].y;
892 Polyline(hdc, pts, pPoly->cpts);
893 HeapFree( GetProcessHeap(), 0, pts );
896 case EMR_POLYLINETO16:
898 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
899 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
900 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
901 pPoly->cpts * sizeof(POINT) );
903 for(i = 0; i < pPoly->cpts; i++)
905 pts[i].x = pPoly->apts[i].x;
906 pts[i].y = pPoly->apts[i].y;
908 PolylineTo(hdc, pts, pPoly->cpts);
909 HeapFree( GetProcessHeap(), 0, pts );
912 case EMR_POLYBEZIER16:
914 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
915 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
916 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
917 pPoly->cpts * sizeof(POINT) );
919 for(i = 0; i < pPoly->cpts; i++)
921 pts[i].x = pPoly->apts[i].x;
922 pts[i].y = pPoly->apts[i].y;
924 PolyBezier(hdc, pts, pPoly->cpts);
925 HeapFree( GetProcessHeap(), 0, pts );
928 case EMR_POLYBEZIERTO16:
930 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
931 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
932 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
933 pPoly->cpts * sizeof(POINT) );
935 for(i = 0; i < pPoly->cpts; i++)
937 pts[i].x = pPoly->apts[i].x;
938 pts[i].y = pPoly->apts[i].y;
940 PolyBezierTo(hdc, pts, pPoly->cpts);
941 HeapFree( GetProcessHeap(), 0, pts );
944 case EMR_POLYPOLYGON16:
946 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
947 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
948 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
950 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
951 pPolyPoly->cpts * sizeof(POINT) );
953 for(i = 0; i < pPolyPoly->cpts; i++)
954 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
955 pPolyPoly->nPolys) + i, pts + i);
957 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
958 HeapFree( GetProcessHeap(), 0, pts );
961 case EMR_POLYPOLYLINE16:
963 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
964 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
965 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
967 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
968 pPolyPoly->cpts * sizeof(POINT) );
970 for(i = 0; i < pPolyPoly->cpts; i++)
971 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
972 pPolyPoly->nPolys) + i, pts + i);
974 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
975 HeapFree( GetProcessHeap(), 0, pts );
979 case EMR_STRETCHDIBITS:
981 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
984 pStretchDIBits->xDest,
985 pStretchDIBits->yDest,
986 pStretchDIBits->cxDest,
987 pStretchDIBits->cyDest,
988 pStretchDIBits->xSrc,
989 pStretchDIBits->ySrc,
990 pStretchDIBits->cxSrc,
991 pStretchDIBits->cySrc,
992 (BYTE *)mr + pStretchDIBits->offBitsSrc,
993 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
994 pStretchDIBits->iUsageSrc,
995 pStretchDIBits->dwRop);
999 case EMR_EXTTEXTOUTA:
1001 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
1005 rc.left = pExtTextOutA->emrtext.rcl.left;
1006 rc.top = pExtTextOutA->emrtext.rcl.top;
1007 rc.right = pExtTextOutA->emrtext.rcl.right;
1008 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
1009 TRACE("EMR_EXTTEXTOUTA: x,y = %ld, %ld. rect = %ld, %ld - %ld, %ld. flags %08lx\n",
1010 pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1011 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutA->emrtext.fOptions);
1013 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1014 * These files can be enumerated and played under Win98 just
1015 * fine, but at least Win2k chokes on them.
1017 if (pExtTextOutA->emrtext.offDx)
1018 dx = (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx);
1020 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1021 pExtTextOutA->emrtext.fOptions, &rc,
1022 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
1027 case EMR_EXTTEXTOUTW:
1029 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
1033 rc.left = pExtTextOutW->emrtext.rcl.left;
1034 rc.top = pExtTextOutW->emrtext.rcl.top;
1035 rc.right = pExtTextOutW->emrtext.rcl.right;
1036 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
1037 TRACE("EMR_EXTTEXTOUTW: x,y = %ld, %ld. rect = %ld, %ld - %ld, %ld. flags %08lx\n",
1038 pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1039 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutW->emrtext.fOptions);
1041 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1042 * These files can be enumerated and played under Win98 just
1043 * fine, but at least Win2k chokes on them.
1045 if (pExtTextOutW->emrtext.offDx)
1046 dx = (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx);
1048 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1049 pExtTextOutW->emrtext.fOptions, &rc,
1050 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
1055 case EMR_CREATEPALETTE:
1057 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
1059 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
1060 CreatePalette( &lpCreatePal->lgpl );
1065 case EMR_SELECTPALETTE:
1067 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
1069 if( lpSelectPal->ihPal & 0x80000000 ) {
1070 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
1072 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
1073 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
1078 case EMR_REALIZEPALETTE:
1080 RealizePalette( hdc );
1084 case EMR_EXTSELECTCLIPRGN:
1087 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
1088 HRGN hRgn = ExtCreateRegion(NULL, lpRgn->cbRgnData, (RGNDATA *)lpRgn->RgnData);
1089 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
1090 /* ExtSelectClipRgn created a copy of the region */
1093 FIXME("ExtSelectClipRgn\n");
1097 case EMR_SETMETARGN:
1103 case EMR_SETWORLDTRANSFORM:
1105 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
1106 info->world_transform = lpXfrm->xform;
1110 case EMR_POLYBEZIER:
1112 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
1113 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
1119 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
1120 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
1126 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
1127 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
1131 case EMR_POLYBEZIERTO:
1133 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
1134 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
1135 (UINT)lpPolyBezierTo->cptl );
1139 case EMR_POLYLINETO:
1141 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
1142 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
1143 (UINT)lpPolyLineTo->cptl );
1147 case EMR_POLYPOLYLINE:
1149 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
1150 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1152 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
1153 pPolyPolyline->nPolys),
1154 pPolyPolyline->aPolyCounts,
1155 pPolyPolyline->nPolys );
1160 case EMR_POLYPOLYGON:
1162 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
1164 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1166 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
1167 pPolyPolygon->nPolys),
1168 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
1172 case EMR_SETBRUSHORGEX:
1174 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
1177 (INT)lpSetBrushOrgEx->ptlOrigin.x,
1178 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1186 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
1189 (INT)lpSetPixelV->ptlPixel.x,
1190 (INT)lpSetPixelV->ptlPixel.y,
1191 lpSetPixelV->crColor );
1196 case EMR_SETMAPPERFLAGS:
1198 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
1200 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1205 case EMR_SETCOLORADJUSTMENT:
1207 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
1209 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1214 case EMR_OFFSETCLIPRGN:
1216 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
1219 (INT)lpOffsetClipRgn->ptlOffset.x,
1220 (INT)lpOffsetClipRgn->ptlOffset.y );
1221 FIXME("OffsetClipRgn\n");
1226 case EMR_EXCLUDECLIPRECT:
1228 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
1230 ExcludeClipRect( hdc,
1231 lpExcludeClipRect->rclClip.left,
1232 lpExcludeClipRect->rclClip.top,
1233 lpExcludeClipRect->rclClip.right,
1234 lpExcludeClipRect->rclClip.bottom );
1235 FIXME("ExcludeClipRect\n");
1240 case EMR_SCALEVIEWPORTEXTEX:
1242 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
1244 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1246 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1247 !lpScaleViewportExtEx->yNum || !lpScaleViewportExtEx->yDenom)
1249 info->vportExtX = (info->vportExtX * lpScaleViewportExtEx->xNum) /
1250 lpScaleViewportExtEx->xDenom;
1251 info->vportExtY = (info->vportExtY * lpScaleViewportExtEx->yNum) /
1252 lpScaleViewportExtEx->yDenom;
1253 if (info->vportExtX == 0) info->vportExtX = 1;
1254 if (info->vportExtY == 0) info->vportExtY = 1;
1255 if (info->mode == MM_ISOTROPIC)
1256 FIXME("EMRSCALEVIEWPORTEXTEX MM_ISOTROPIC mapping\n");
1257 /* MAPPING_FixIsotropic( dc ); */
1259 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1260 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1261 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1266 case EMR_SCALEWINDOWEXTEX:
1268 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
1270 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1272 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1273 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1275 info->wndExtX = (info->wndExtX * lpScaleWindowExtEx->xNum) /
1276 lpScaleWindowExtEx->xDenom;
1277 info->wndExtY = (info->wndExtY * lpScaleWindowExtEx->yNum) /
1278 lpScaleWindowExtEx->yDenom;
1279 if (info->wndExtX == 0) info->wndExtX = 1;
1280 if (info->wndExtY == 0) info->wndExtY = 1;
1281 if (info->mode == MM_ISOTROPIC)
1282 FIXME("EMRSCALEWINDOWEXTEX MM_ISOTROPIC mapping\n");
1283 /* MAPPING_FixIsotropic( dc ); */
1285 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1286 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1287 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1292 case EMR_MODIFYWORLDTRANSFORM:
1294 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
1296 switch(lpModifyWorldTrans->iMode) {
1298 info->world_transform.eM11 = info->world_transform.eM22 = 1;
1299 info->world_transform.eM12 = info->world_transform.eM21 = 0;
1300 info->world_transform.eDx = info->world_transform.eDy = 0;
1302 case MWT_LEFTMULTIPLY:
1303 CombineTransform(&info->world_transform, &lpModifyWorldTrans->xform,
1304 &info->world_transform);
1306 case MWT_RIGHTMULTIPLY:
1307 CombineTransform(&info->world_transform, &info->world_transform,
1308 &lpModifyWorldTrans->xform);
1311 FIXME("Unknown imode %ld\n", lpModifyWorldTrans->iMode);
1319 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
1322 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1323 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1324 lpAngleArc->eSweepAngle );
1331 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
1334 lpRoundRect->rclBox.left,
1335 lpRoundRect->rclBox.top,
1336 lpRoundRect->rclBox.right,
1337 lpRoundRect->rclBox.bottom,
1338 lpRoundRect->szlCorner.cx,
1339 lpRoundRect->szlCorner.cy );
1346 PEMRARC lpArc = (PEMRARC)mr;
1349 (INT)lpArc->rclBox.left,
1350 (INT)lpArc->rclBox.top,
1351 (INT)lpArc->rclBox.right,
1352 (INT)lpArc->rclBox.bottom,
1353 (INT)lpArc->ptlStart.x,
1354 (INT)lpArc->ptlStart.y,
1355 (INT)lpArc->ptlEnd.x,
1356 (INT)lpArc->ptlEnd.y );
1363 PEMRCHORD lpChord = (PEMRCHORD)mr;
1366 (INT)lpChord->rclBox.left,
1367 (INT)lpChord->rclBox.top,
1368 (INT)lpChord->rclBox.right,
1369 (INT)lpChord->rclBox.bottom,
1370 (INT)lpChord->ptlStart.x,
1371 (INT)lpChord->ptlStart.y,
1372 (INT)lpChord->ptlEnd.x,
1373 (INT)lpChord->ptlEnd.y );
1380 PEMRPIE lpPie = (PEMRPIE)mr;
1383 (INT)lpPie->rclBox.left,
1384 (INT)lpPie->rclBox.top,
1385 (INT)lpPie->rclBox.right,
1386 (INT)lpPie->rclBox.bottom,
1387 (INT)lpPie->ptlStart.x,
1388 (INT)lpPie->ptlStart.y,
1389 (INT)lpPie->ptlEnd.x,
1390 (INT)lpPie->ptlEnd.y );
1397 PEMRARC lpArcTo = (PEMRARC)mr;
1400 (INT)lpArcTo->rclBox.left,
1401 (INT)lpArcTo->rclBox.top,
1402 (INT)lpArcTo->rclBox.right,
1403 (INT)lpArcTo->rclBox.bottom,
1404 (INT)lpArcTo->ptlStart.x,
1405 (INT)lpArcTo->ptlStart.y,
1406 (INT)lpArcTo->ptlEnd.x,
1407 (INT)lpArcTo->ptlEnd.y );
1412 case EMR_EXTFLOODFILL:
1414 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
1417 (INT)lpExtFloodFill->ptlStart.x,
1418 (INT)lpExtFloodFill->ptlStart.y,
1419 lpExtFloodFill->crColor,
1420 (UINT)lpExtFloodFill->iMode );
1427 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
1429 (const LPPOINT)lpPolyDraw->aptl,
1430 lpPolyDraw->abTypes,
1431 (INT)lpPolyDraw->cptl );
1436 case EMR_SETARCDIRECTION:
1438 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1439 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1443 case EMR_SETMITERLIMIT:
1445 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1446 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1462 case EMR_CLOSEFIGURE:
1470 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1475 case EMR_STROKEANDFILLPATH:
1477 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1478 StrokeAndFillPath( hdc );
1482 case EMR_STROKEPATH:
1484 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1489 case EMR_FLATTENPATH:
1501 case EMR_SELECTCLIPPATH:
1503 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1504 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1514 case EMR_CREATECOLORSPACE:
1516 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1517 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1518 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1522 case EMR_SETCOLORSPACE:
1524 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1526 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1530 case EMR_DELETECOLORSPACE:
1532 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1533 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1537 case EMR_SETICMMODE:
1539 PEMRSETICMMODE lpSetICMMode = (PEMRSETICMMODE)mr;
1540 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1544 case EMR_PIXELFORMAT:
1547 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1549 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1550 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1555 case EMR_SETPALETTEENTRIES:
1557 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1559 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1560 (UINT)lpSetPaletteEntries->iStart,
1561 (UINT)lpSetPaletteEntries->cEntries,
1562 lpSetPaletteEntries->aPalEntries );
1567 case EMR_RESIZEPALETTE:
1569 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1571 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1572 (UINT)lpResizePalette->cEntries );
1577 case EMR_CREATEDIBPATTERNBRUSHPT:
1579 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1580 LPVOID lpPackedStruct;
1582 /* check that offsets and data are contained within the record */
1583 if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
1584 (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
1585 ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
1586 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
1588 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1592 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1593 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1594 lpCreate->cbBmi + lpCreate->cbBits );
1597 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1601 /* Now pack this structure */
1602 memcpy( lpPackedStruct,
1603 ((BYTE*)lpCreate) + lpCreate->offBmi,
1605 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1606 ((BYTE*)lpCreate) + lpCreate->offBits,
1609 (handletable->objectHandle)[lpCreate->ihBrush] =
1610 CreateDIBPatternBrushPt( lpPackedStruct,
1611 (UINT)lpCreate->iUsage );
1613 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1618 case EMR_CREATEMONOBRUSH:
1620 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1621 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1622 HBITMAP hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1623 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1624 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1625 /* CreatePatternBrush created a copy of the bitmap */
1632 PEMRBITBLT pBitBlt = (PEMRBITBLT)mr;
1634 if(pBitBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1635 PatBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1637 } else { /* BitBlt */
1638 HDC hdcSrc = CreateCompatibleDC(hdc);
1639 HBRUSH hBrush, hBrushOld;
1640 HBITMAP hBmp = 0, hBmpOld = 0;
1641 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pBitBlt->offBmiSrc);
1643 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1645 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1646 hBrushOld = SelectObject(hdcSrc, hBrush);
1647 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1648 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1649 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1650 SelectObject(hdcSrc, hBrushOld);
1651 DeleteObject(hBrush);
1653 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1654 (BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1655 hBmpOld = SelectObject(hdcSrc, hBmp);
1657 BitBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1658 hdcSrc, pBitBlt->xSrc, pBitBlt->ySrc, pBitBlt->dwRop);
1660 SelectObject(hdcSrc, hBmpOld);
1667 case EMR_STRETCHBLT:
1669 PEMRSTRETCHBLT pStretchBlt= (PEMRSTRETCHBLT)mr;
1671 TRACE("EMR_STRETCHBLT: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. rop %08lx offBitsSrc %ld\n",
1672 pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1673 pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1674 pStretchBlt->dwRop, pStretchBlt->offBitsSrc);
1676 if(pStretchBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1677 PatBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1678 pStretchBlt->dwRop);
1679 } else { /* StretchBlt */
1680 HDC hdcSrc = CreateCompatibleDC(hdc);
1681 HBRUSH hBrush, hBrushOld;
1682 HBITMAP hBmp = 0, hBmpOld = 0;
1683 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pStretchBlt->offBmiSrc);
1685 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1687 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1688 hBrushOld = SelectObject(hdcSrc, hBrush);
1689 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1690 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1691 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1692 SelectObject(hdcSrc, hBrushOld);
1693 DeleteObject(hBrush);
1695 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1696 (BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1697 hBmpOld = SelectObject(hdcSrc, hBmp);
1699 StretchBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1700 hdcSrc, pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1701 pStretchBlt->dwRop);
1703 SelectObject(hdcSrc, hBmpOld);
1712 PEMRMASKBLT pMaskBlt= (PEMRMASKBLT)mr;
1713 HDC hdcSrc = CreateCompatibleDC(hdc);
1714 HBRUSH hBrush, hBrushOld;
1715 HBITMAP hBmp, hBmpOld, hBmpMask;
1718 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1720 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1721 hBrushOld = SelectObject(hdcSrc, hBrush);
1722 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1723 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1724 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1725 SelectObject(hdcSrc, hBrushOld);
1726 DeleteObject(hBrush);
1728 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiMask);
1729 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1730 (BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1732 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiSrc);
1733 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1734 (BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1735 hBmpOld = SelectObject(hdcSrc, hBmp);
1748 SelectObject(hdcSrc, hBmpOld);
1750 DeleteObject(hBmpMask);
1757 PEMRPLGBLT pPlgBlt= (PEMRPLGBLT)mr;
1758 HDC hdcSrc = CreateCompatibleDC(hdc);
1759 HBRUSH hBrush, hBrushOld;
1760 HBITMAP hBmp, hBmpOld, hBmpMask;
1764 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1766 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1767 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1768 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1770 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1771 hBrushOld = SelectObject(hdcSrc, hBrush);
1772 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1773 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1774 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1775 SelectObject(hdcSrc, hBrushOld);
1776 DeleteObject(hBrush);
1778 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiMask);
1779 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1780 (BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1782 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiSrc);
1783 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1784 (BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1785 hBmpOld = SelectObject(hdcSrc, hBmp);
1796 SelectObject(hdcSrc, hBmpOld);
1798 DeleteObject(hBmpMask);
1803 case EMR_SETDIBITSTODEVICE:
1805 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice = (PEMRSETDIBITSTODEVICE)mr;
1807 SetDIBitsToDevice(hdc,
1808 pSetDIBitsToDevice->xDest,
1809 pSetDIBitsToDevice->yDest,
1810 pSetDIBitsToDevice->cxSrc,
1811 pSetDIBitsToDevice->cySrc,
1812 pSetDIBitsToDevice->xSrc,
1813 pSetDIBitsToDevice->ySrc,
1814 pSetDIBitsToDevice->iStartScan,
1815 pSetDIBitsToDevice->cScans,
1816 (BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
1817 (BITMAPINFO *)((BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
1818 pSetDIBitsToDevice->iUsageSrc);
1822 case EMR_POLYTEXTOUTA:
1824 PEMRPOLYTEXTOUTA pPolyTextOutA = (PEMRPOLYTEXTOUTA)mr;
1825 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
1827 XFORM xform, xformOld;
1830 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
1831 GetWorldTransform(hdc, &xformOld);
1833 xform.eM11 = pPolyTextOutA->exScale;
1836 xform.eM22 = pPolyTextOutA->eyScale;
1839 SetWorldTransform(hdc, &xform);
1841 /* Set up POLYTEXTA structures */
1842 for(i = 0; i < pPolyTextOutA->cStrings; i++)
1844 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
1845 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
1846 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
1847 polytextA[i].lpstr = (LPSTR)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
1848 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
1849 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
1850 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
1851 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
1852 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
1853 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
1855 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
1856 HeapFree(GetProcessHeap(), 0, polytextA);
1858 SetWorldTransform(hdc, &xformOld);
1859 SetGraphicsMode(hdc, gModeOld);
1863 case EMR_POLYTEXTOUTW:
1865 PEMRPOLYTEXTOUTW pPolyTextOutW = (PEMRPOLYTEXTOUTW)mr;
1866 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
1868 XFORM xform, xformOld;
1871 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
1872 GetWorldTransform(hdc, &xformOld);
1874 xform.eM11 = pPolyTextOutW->exScale;
1877 xform.eM22 = pPolyTextOutW->eyScale;
1880 SetWorldTransform(hdc, &xform);
1882 /* Set up POLYTEXTW structures */
1883 for(i = 0; i < pPolyTextOutW->cStrings; i++)
1885 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
1886 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
1887 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
1888 polytextW[i].lpstr = (LPWSTR)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
1889 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
1890 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
1891 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
1892 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
1893 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
1894 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
1896 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
1897 HeapFree(GetProcessHeap(), 0, polytextW);
1899 SetWorldTransform(hdc, &xformOld);
1900 SetGraphicsMode(hdc, gModeOld);
1906 PEMRFILLRGN pFillRgn = (PEMRFILLRGN)mr;
1907 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
1910 (handletable->objectHandle)[pFillRgn->ihBrush]);
1917 PEMRFRAMERGN pFrameRgn = (PEMRFRAMERGN)mr;
1918 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
1921 (handletable->objectHandle)[pFrameRgn->ihBrush],
1922 pFrameRgn->szlStroke.cx,
1923 pFrameRgn->szlStroke.cy);
1930 PEMRINVERTRGN pInvertRgn = (PEMRINVERTRGN)mr;
1931 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
1932 InvertRgn(hdc, hRgn);
1939 PEMRPAINTRGN pPaintRgn = (PEMRPAINTRGN)mr;
1940 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
1941 PaintRgn(hdc, hRgn);
1946 case EMR_SETTEXTJUSTIFICATION:
1948 PEMRSETTEXTJUSTIFICATION pSetTextJust = (PEMRSETTEXTJUSTIFICATION)mr;
1949 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
1955 PEMRSETLAYOUT pSetLayout = (PEMRSETLAYOUT)mr;
1956 SetLayout(hdc, pSetLayout->iMode);
1960 case EMR_POLYDRAW16:
1962 case EMR_GLSBOUNDEDRECORD:
1963 case EMR_DRAWESCAPE :
1966 case EMR_SMALLTEXTOUT:
1967 case EMR_FORCEUFIMAPPING:
1968 case EMR_NAMEDESCAPE:
1969 case EMR_COLORCORRECTPALETTE:
1970 case EMR_SETICMPROFILEA:
1971 case EMR_SETICMPROFILEW:
1972 case EMR_ALPHABLEND:
1973 case EMR_TRANSPARENTBLT:
1974 case EMR_GRADIENTFILL:
1975 case EMR_SETLINKEDUFI:
1976 case EMR_COLORMATCHTOTARGETW:
1977 case EMR_CREATECOLORSPACEW:
1980 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1981 record then ignore and return TRUE. */
1982 FIXME("type %d is unimplemented\n", type);
1985 tmprc.left = tmprc.top = 0;
1986 tmprc.right = tmprc.bottom = 1000;
1987 LPtoDP(hdc, (POINT*)&tmprc, 2);
1988 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", tmprc.left,
1989 tmprc.top, tmprc.right, tmprc.bottom);
1993 /* WinNT - update the transform (win9x updates when the next graphics output
1994 record is played). */
1995 EMF_Update_MF_Xform(hdc, info);
2002 /*****************************************************************************
2004 * EnumEnhMetaFile (GDI32.@)
2006 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2008 * record. Returns when either every record has been used or
2009 * when _EnhMetaFunc_ returns FALSE.
2013 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2020 * This function behaves differently in Win9x and WinNT.
2022 * In WinNT, the DC's world transform is updated as the EMF changes
2023 * the Window/Viewport Extent and Origin or it's world transform.
2024 * The actual Window/Viewport Extent and Origin are left untouched.
2026 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2027 * updates the scaling itself but only just before a record that
2028 * writes anything to the DC.
2030 * I'm not sure where the data (enum_emh_data) is stored in either
2031 * version. For this implementation, it is stored before the handle
2032 * table, but it could be stored in the DC, in the EMF handle or in
2036 BOOL WINAPI EnumEnhMetaFile(
2037 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
2038 HENHMETAFILE hmf, /* [in] EMF to walk */
2039 ENHMFENUMPROC callback, /* [in] callback function */
2040 LPVOID data, /* [in] optional data for callback function */
2041 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
2053 HBRUSH hBrush = NULL;
2055 enum_emh_data *info;
2056 SIZE vp_size, win_size;
2057 POINT vp_org, win_org;
2058 INT mapMode = MM_TEXT;
2059 COLORREF old_text_color = 0, old_bk_color = 0;
2063 SetLastError(ERROR_INVALID_PARAMETER);
2067 emh = EMF_GetEnhMetaHeader(hmf);
2069 SetLastError(ERROR_INVALID_HANDLE);
2073 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2074 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
2077 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2084 info->vportOrgX = 0;
2085 info->vportOrgY = 0;
2086 info->vportExtX = 1;
2087 info->vportExtY = 1;
2088 info->world_transform.eM11 = info->world_transform.eM22 = 1;
2089 info->world_transform.eM12 = info->world_transform.eM21 = 0;
2090 info->world_transform.eDx = info->world_transform.eDy = 0;
2092 ht = (HANDLETABLE*) &info[1];
2093 ht->objectHandle[0] = hmf;
2097 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
2098 GetWorldTransform(hdc, &savedXform);
2099 GetViewportExtEx(hdc, &vp_size);
2100 GetWindowExtEx(hdc, &win_size);
2101 GetViewportOrgEx(hdc, &vp_org);
2102 GetWindowOrgEx(hdc, &win_org);
2103 mapMode = GetMapMode(hdc);
2105 /* save the current pen, brush and font */
2106 hPen = GetCurrentObject(hdc, OBJ_PEN);
2107 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
2108 hFont = GetCurrentObject(hdc, OBJ_FONT);
2110 old_text_color = SetTextColor(hdc, RGB(0,0,0));
2111 old_bk_color = SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
2114 info->mode = MM_TEXT;
2118 /* Win95 leaves the vp/win ext/org info alone */
2119 info->init_transform.eM11 = 1.0;
2120 info->init_transform.eM12 = 0.0;
2121 info->init_transform.eM21 = 0.0;
2122 info->init_transform.eM22 = 1.0;
2123 info->init_transform.eDx = 0.0;
2124 info->init_transform.eDy = 0.0;
2128 /* WinNT combines the vp/win ext/org info into a transform */
2129 FLOAT xscale, yscale;
2130 xscale = (FLOAT)vp_size.cx / (FLOAT)win_size.cx;
2131 yscale = (FLOAT)vp_size.cy / (FLOAT)win_size.cy;
2132 info->init_transform.eM11 = xscale;
2133 info->init_transform.eM12 = 0.0;
2134 info->init_transform.eM21 = 0.0;
2135 info->init_transform.eM22 = yscale;
2136 info->init_transform.eDx = (FLOAT)vp_org.x - xscale * (FLOAT)win_org.x;
2137 info->init_transform.eDy = (FLOAT)vp_org.y - yscale * (FLOAT)win_org.y;
2139 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
2142 if ( WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
2144 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
2147 TRACE("rect: %ld,%ld - %ld,%ld. rclFrame: %ld,%ld - %ld,%ld\n",
2148 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
2149 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
2150 emh->rclFrame.bottom);
2152 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
2153 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
2154 xscale = (FLOAT) WIDTH(*lpRect) * 100.0 /
2155 WIDTH(emh->rclFrame) * xSrcPixSize;
2156 yscale = (FLOAT) HEIGHT(*lpRect) * 100.0 /
2157 HEIGHT(emh->rclFrame) * ySrcPixSize;
2159 xform.eM11 = xscale;
2162 xform.eM22 = yscale;
2163 xform.eDx = (FLOAT) lpRect->left - (FLOAT) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
2164 xform.eDy = (FLOAT) lpRect->top - (FLOAT) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
2166 CombineTransform(&info->init_transform, &xform, &info->init_transform);
2169 /* WinNT resets the current vp/win org/ext */
2172 SetMapMode(hdc, MM_TEXT);
2173 SetWindowOrgEx(hdc, 0, 0, NULL);
2174 SetViewportOrgEx(hdc, 0, 0, NULL);
2175 EMF_Update_MF_Xform(hdc, info);
2180 while(ret && offset < emh->nBytes)
2182 emr = (ENHMETARECORD *)((char *)emh + offset);
2183 TRACE("Calling EnumFunc with record %s, size %ld\n", get_emr_name(emr->iType), emr->nSize);
2184 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2185 offset += emr->nSize;
2190 SetBkColor(hdc, old_bk_color);
2191 SetTextColor(hdc, old_text_color);
2193 /* restore pen, brush and font */
2194 SelectObject(hdc, hBrush);
2195 SelectObject(hdc, hPen);
2196 SelectObject(hdc, hFont);
2198 SetWorldTransform(hdc, &savedXform);
2200 SetGraphicsMode(hdc, savedMode);
2201 SetMapMode(hdc, mapMode);
2202 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2203 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2204 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2205 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2208 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2209 if( (ht->objectHandle)[i] )
2210 DeleteObject( (ht->objectHandle)[i] );
2212 HeapFree( GetProcessHeap(), 0, info );
2216 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2217 const ENHMETARECORD *emr,
2218 INT handles, LPARAM data)
2220 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2223 /**************************************************************************
2224 * PlayEnhMetaFile (GDI32.@)
2226 * Renders an enhanced metafile into a specified rectangle *lpRect
2227 * in device context hdc.
2230 BOOL WINAPI PlayEnhMetaFile(
2231 HDC hdc, /* [in] DC to render into */
2232 HENHMETAFILE hmf, /* [in] metafile to render */
2233 const RECT *lpRect /* [in] rectangle to place metafile inside */
2236 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2240 /*****************************************************************************
2241 * DeleteEnhMetaFile (GDI32.@)
2243 * Deletes an enhanced metafile and frees the associated storage.
2245 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2247 return EMF_Delete_HENHMETAFILE( hmf );
2250 /*****************************************************************************
2251 * CopyEnhMetaFileA (GDI32.@)
2253 * Duplicate an enhanced metafile.
2257 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2258 HENHMETAFILE hmfSrc,
2261 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2262 HENHMETAFILE hmfDst;
2264 if(!emrSrc) return FALSE;
2266 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2267 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2268 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2271 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2272 NULL, CREATE_ALWAYS, 0, 0);
2273 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
2274 CloseHandle( hFile );
2275 /* Reopen file for reading only, so that apps can share
2276 read access to the file while hmf is still valid */
2277 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2278 NULL, OPEN_EXISTING, 0, 0);
2279 if(hFile == INVALID_HANDLE_VALUE) {
2280 ERR("Can't reopen emf for reading\n");
2283 hmfDst = EMF_GetEnhMetaFile( hFile );
2284 CloseHandle( hFile );
2289 /*****************************************************************************
2290 * CopyEnhMetaFileW (GDI32.@)
2292 * See CopyEnhMetaFileA.
2296 HENHMETAFILE WINAPI CopyEnhMetaFileW(
2297 HENHMETAFILE hmfSrc,
2300 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2301 HENHMETAFILE hmfDst;
2303 if(!emrSrc) return FALSE;
2305 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2306 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2307 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2310 hFile = CreateFileW( file, GENERIC_WRITE | GENERIC_READ, 0,
2311 NULL, CREATE_ALWAYS, 0, 0);
2312 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
2313 CloseHandle( hFile );
2314 /* Reopen file for reading only, so that apps can share
2315 read access to the file while hmf is still valid */
2316 hFile = CreateFileW( file, GENERIC_READ, FILE_SHARE_READ,
2317 NULL, OPEN_EXISTING, 0, 0);
2318 if(hFile == INVALID_HANDLE_VALUE) {
2319 ERR("Can't reopen emf for reading\n");
2322 hmfDst = EMF_GetEnhMetaFile( hFile );
2323 CloseHandle( hFile );
2329 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2330 typedef struct tagEMF_PaletteCopy
2333 LPPALETTEENTRY lpPe;
2336 /***************************************************************
2337 * Find the EMR_EOF record and then use it to find the
2338 * palette entries for this enhanced metafile.
2339 * The lpData is actually a pointer to a EMF_PaletteCopy struct
2340 * which contains the max number of elements to copy and where
2343 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2345 INT CALLBACK cbEnhPaletteCopy( HDC a,
2347 const ENHMETARECORD *lpEMR,
2352 if ( lpEMR->iType == EMR_EOF )
2354 PEMREOF lpEof = (PEMREOF)lpEMR;
2355 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2356 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2358 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
2360 memcpy( (LPVOID)info->lpPe,
2361 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
2362 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2364 /* Update the passed data as a return code */
2365 info->lpPe = NULL; /* Palettes were copied! */
2366 info->cEntries = (UINT)dwNumPalToCopy;
2368 return FALSE; /* That's all we need */
2374 /*****************************************************************************
2375 * GetEnhMetaFilePaletteEntries (GDI32.@)
2377 * Copy the palette and report size
2379 * BUGS: Error codes (SetLastError) are not set on failures
2381 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2383 LPPALETTEENTRY lpPe )
2385 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2386 EMF_PaletteCopy infoForCallBack;
2388 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2390 /* First check if there are any palettes associated with
2392 if ( enhHeader->nPalEntries == 0 ) return 0;
2394 /* Is the user requesting the number of palettes? */
2395 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
2397 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2398 infoForCallBack.cEntries = cEntries;
2399 infoForCallBack.lpPe = lpPe;
2401 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2402 &infoForCallBack, 0 ) )
2405 /* Verify that the callback executed correctly */
2406 if ( infoForCallBack.lpPe != NULL )
2408 /* Callback proc had error! */
2409 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2413 return infoForCallBack.cEntries;
2416 typedef struct gdi_mf_comment
2423 DWORD cbWinMetaFile;
2426 /******************************************************************
2427 * SetWinMetaFileBits (GDI32.@)
2429 * Translate from old style to new style.
2432 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2433 CONST BYTE *lpbBuffer,
2435 CONST METAFILEPICT *lpmfp
2439 HENHMETAFILE ret = 0;
2440 HDC hdc = 0, hdcdisp = 0;
2442 RECT rc, *prcFrame = NULL;
2443 gdi_mf_comment *mfcomment;
2444 UINT mfcomment_size;
2445 INT horzres, vertres;
2447 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2449 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2452 WARN("SetMetaFileBitsEx failed\n");
2457 hdcRef = hdcdisp = CreateDCA("DISPLAY", NULL, NULL, NULL);
2461 mfp.mm = MM_ANISOTROPIC;
2466 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2468 if((lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC) &&
2469 mfp.xExt > 0 && mfp.yExt > 0) {
2470 rc.left = rc.top = 0;
2471 rc.right = lpmfp->xExt;
2472 rc.bottom = lpmfp->yExt;
2476 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL))) {
2477 ERR("CreateEnhMetaFile fails?\n");
2481 horzres = GetDeviceCaps(hdcRef, HORZRES);
2482 vertres = GetDeviceCaps(hdcRef, VERTRES);
2490 * Write the original METAFILE into the enhanced metafile.
2491 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2493 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2494 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2497 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2498 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2499 mfcomment->nVersion = 0x00000300;
2500 mfcomment->nChecksum = 0; /* FIXME */
2501 mfcomment->fFlags = 0;
2502 mfcomment->cbWinMetaFile = cbBuffer;
2503 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2504 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2505 HeapFree(GetProcessHeap(), 0, mfcomment);
2508 if(lpmfp->mm != MM_TEXT)
2509 SetMapMode(hdc, lpmfp->mm);
2511 /* set the initial viewport:window ratio as 1:1 */
2512 SetViewportExtEx(hdc, horzres, vertres, NULL);
2513 SetWindowExtEx(hdc, horzres, vertres, NULL);
2515 PlayMetaFile(hdc, hmf);
2517 ret = CloseEnhMetaFile(hdc);
2519 DeleteMetaFile(hmf);