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"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
52 BOOL on_disk; /* true if metafile is on disk */
56 /****************************************************************************
57 * EMF_Create_HENHMETAFILE
59 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk )
62 ENHMETAFILEOBJ *metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
64 (HGDIOBJ *)&hmf, NULL );
68 metaObj->on_disk = on_disk;
69 GDI_ReleaseObj( hmf );
74 /****************************************************************************
75 * EMF_Delete_HENHMETAFILE
77 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
79 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
81 if(!metaObj) return FALSE;
84 UnmapViewOfFile( metaObj->emh );
86 HeapFree( GetProcessHeap(), 0, metaObj->emh );
87 return GDI_FreeObject( hmf, metaObj );
90 /******************************************************************
91 * EMF_GetEnhMetaHeader
93 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
95 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
97 ENHMETAHEADER *ret = NULL;
98 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
99 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
103 GDI_ReleaseObj( hmf );
108 /*****************************************************************************
112 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
117 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
118 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
119 CloseHandle( hMapping );
123 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
124 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
125 emh->iType, emh->dSignature);
129 /* refuse to load unaligned EMF as Windows does */
132 WARN("Refusing to load unaligned EMF\n");
136 return EMF_Create_HENHMETAFILE( emh, TRUE );
139 UnmapViewOfFile( emh );
144 /*****************************************************************************
145 * GetEnhMetaFileA (GDI32.@)
149 HENHMETAFILE WINAPI GetEnhMetaFileA(
150 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
156 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
157 OPEN_EXISTING, 0, 0);
158 if (hFile == INVALID_HANDLE_VALUE) {
159 WARN("could not open %s\n", lpszMetaFile);
162 hmf = EMF_GetEnhMetaFile( hFile );
163 CloseHandle( hFile );
167 /*****************************************************************************
168 * GetEnhMetaFileW (GDI32.@)
170 HENHMETAFILE WINAPI GetEnhMetaFileW(
171 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
176 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
177 OPEN_EXISTING, 0, 0);
178 if (hFile == INVALID_HANDLE_VALUE) {
179 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
182 hmf = EMF_GetEnhMetaFile( hFile );
183 CloseHandle( hFile );
187 /*****************************************************************************
188 * GetEnhMetaFileHeader (GDI32.@)
190 * If buf is NULL, returns the size of buffer required.
191 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
194 UINT WINAPI GetEnhMetaFileHeader(
195 HENHMETAFILE hmf, /* [in] enhanced metafile */
196 UINT bufsize, /* [in] size of buffer */
197 LPENHMETAHEADER buf /* [out] buffer */
203 emh = EMF_GetEnhMetaHeader(hmf);
204 if(!emh) return FALSE;
206 if (!buf) return size;
207 size = min(size, bufsize);
208 memmove(buf, emh, size);
213 /*****************************************************************************
214 * GetEnhMetaFileDescriptionA (GDI32.@)
216 UINT WINAPI GetEnhMetaFileDescriptionA(
217 HENHMETAFILE hmf, /* [in] enhanced metafile */
218 UINT size, /* [in] size of buf */
219 LPSTR buf /* [out] buffer to receive description */
222 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
226 if(!emh) return FALSE;
227 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
228 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
229 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
231 if (!buf || !size ) return len;
233 len = min( size, len );
234 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
238 /*****************************************************************************
239 * GetEnhMetaFileDescriptionW (GDI32.@)
241 * Copies the description string of an enhanced metafile into a buffer
244 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
245 * number of characters copied.
247 UINT WINAPI GetEnhMetaFileDescriptionW(
248 HENHMETAFILE hmf, /* [in] enhanced metafile */
249 UINT size, /* [in] size of buf */
250 LPWSTR buf /* [out] buffer to receive description */
253 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
255 if(!emh) return FALSE;
256 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
257 if (!buf || !size ) return emh->nDescription;
259 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
260 return min(size, emh->nDescription);
263 /****************************************************************************
264 * SetEnhMetaFileBits (GDI32.@)
266 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
268 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
270 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
271 memmove(emh, buf, bufsize);
272 return EMF_Create_HENHMETAFILE( emh, FALSE );
275 /*****************************************************************************
276 * GetEnhMetaFileBits (GDI32.@)
279 UINT WINAPI GetEnhMetaFileBits(
285 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
291 if( buf == NULL ) return size;
293 size = min( size, bufsize );
294 memmove(buf, emh, size);
298 typedef struct enum_emh_data
301 XFORM init_transform;
302 XFORM world_transform;
313 #define ENUM_GET_PRIVATE_DATA(ht) \
314 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
316 #define WIDTH(rect) ( (rect).right - (rect).left )
317 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
319 #define IS_WIN9X() (GetVersion()&0x80000000)
321 void EMF_Update_MF_Xform(HDC hdc, enum_emh_data *info)
323 XFORM mapping_mode_trans, final_trans;
324 FLOAT scaleX, scaleY;
326 scaleX = (FLOAT)info->vportExtX / (FLOAT)info->wndExtX;
327 scaleY = (FLOAT)info->vportExtY / (FLOAT)info->wndExtY;
328 mapping_mode_trans.eM11 = scaleX;
329 mapping_mode_trans.eM12 = 0.0;
330 mapping_mode_trans.eM21 = 0.0;
331 mapping_mode_trans.eM22 = scaleY;
332 mapping_mode_trans.eDx = (FLOAT)info->vportOrgX - scaleX * (FLOAT)info->wndOrgX;
333 mapping_mode_trans.eDy = (FLOAT)info->vportOrgY - scaleY * (FLOAT)info->wndOrgY;
335 CombineTransform(&final_trans, &info->world_transform, &mapping_mode_trans);
336 CombineTransform(&final_trans, &final_trans, &info->init_transform);
338 if (!SetWorldTransform(hdc, &final_trans))
340 ERR("World transform failed!\n");
344 void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
346 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
347 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
348 INT horzRes = GetDeviceCaps( hdc, HORZRES );
349 INT vertRes = GetDeviceCaps( hdc, VERTRES );
351 TRACE("%d\n",info->mode);
363 info->wndExtX = horzSize;
364 info->wndExtY = vertSize;
365 info->vportExtX = horzRes / 10;
366 info->vportExtY = vertRes / -10;
369 info->wndExtX = horzSize * 10;
370 info->wndExtY = vertSize * 10;
371 info->vportExtX = horzRes / 10;
372 info->vportExtY = vertRes / -10;
375 info->wndExtX = horzSize;
376 info->wndExtY = vertSize;
377 info->vportExtX = 254L * horzRes / 1000;
378 info->vportExtY = -254L * vertRes / 1000;
381 info->wndExtX = horzSize * 10;
382 info->wndExtY = vertSize * 10;
383 info->vportExtX = 254L * horzRes / 1000;
384 info->vportExtY = -254L * vertRes / 1000;
387 info->wndExtX = 144L * horzSize / 10;
388 info->wndExtY = 144L * vertSize / 10;
389 info->vportExtX = 254L * horzRes / 1000;
390 info->vportExtY = -254L * vertRes / 1000;
399 /*****************************************************************************
400 * emr_produces_output
402 * Returns TRUE if the record type writes something to the dc. Used by
403 * PlayEnhMetaFileRecord to determine whether it needs to update the
404 * dc's xform when in win9x mode.
406 * FIXME: need to test which records should be here.
408 static BOOL emr_produces_output(int type)
414 case EMR_POLYBEZIERTO:
416 case EMR_POLYPOLYLINE:
417 case EMR_POLYPOLYGON:
420 case EMR_EXCLUDECLIPRECT:
421 case EMR_INTERSECTCLIPRECT:
422 case EMR_SELECTOBJECT:
430 case EMR_EXTFLOODFILL:
442 case EMR_SETDIBITSTODEVICE:
443 case EMR_STRETCHDIBITS:
444 case EMR_EXTTEXTOUTA:
445 case EMR_EXTTEXTOUTW:
446 case EMR_POLYBEZIER16:
449 case EMR_POLYBEZIERTO16:
450 case EMR_POLYLINETO16:
451 case EMR_POLYPOLYLINE16:
452 case EMR_POLYPOLYGON16:
454 case EMR_POLYTEXTOUTA:
455 case EMR_POLYTEXTOUTW:
456 case EMR_SMALLTEXTOUT:
457 case EMR_TRANSPARENTBLT:
465 /*****************************************************************************
466 * PlayEnhMetaFileRecord (GDI32.@)
468 * Render a single enhanced metafile record in the device context hdc.
471 * TRUE (non zero) on success, FALSE on error.
473 * Many unimplemented records.
474 * No error handling on record play failures (ie checking return codes)
477 * WinNT actually updates the current world transform in this function
478 * whereas Win9x does not.
480 BOOL WINAPI PlayEnhMetaFileRecord(
481 HDC hdc, /* [in] device context in which to render EMF record */
482 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
483 const ENHMETARECORD *mr, /* [in] EMF record to render */
484 UINT handles /* [in] size of handle array */
489 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
491 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
492 hdc, handletable, mr, handles);
493 if (!mr) return FALSE;
497 /* In Win9x mode we update the xform if the record will produce output */
498 if ( IS_WIN9X() && emr_produces_output(type) )
499 EMF_Update_MF_Xform(hdc, info);
501 TRACE(" type=%d\n", type);
510 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
511 /* In an enhanced metafile, there can be both public and private GDI comments */
512 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
517 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
519 if(info->mode == pSetMapMode->iMode)
521 info->mode = pSetMapMode->iMode;
522 EMF_SetMapMode(hdc, info);
527 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
528 SetBkMode(hdc, pSetBkMode->iMode);
533 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
534 SetBkColor(hdc, pSetBkColor->crColor);
537 case EMR_SETPOLYFILLMODE:
539 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
540 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
545 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
546 SetROP2(hdc, pSetROP2->iMode);
549 case EMR_SETSTRETCHBLTMODE:
551 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
552 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
555 case EMR_SETTEXTALIGN:
557 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
558 SetTextAlign(hdc, pSetTextAlign->iMode);
561 case EMR_SETTEXTCOLOR:
563 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
564 SetTextColor(hdc, pSetTextColor->crColor);
574 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
575 RestoreDC(hdc, pRestoreDC->iRelative);
578 case EMR_INTERSECTCLIPRECT:
580 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
581 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
582 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
585 case EMR_SELECTOBJECT:
587 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
588 if( pSelectObject->ihObject & 0x80000000 ) {
589 /* High order bit is set - it's a stock object
590 * Strip the high bit to get the index.
591 * See MSDN article Q142319
593 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
596 /* High order bit wasn't set - not a stock object
599 (handletable->objectHandle)[pSelectObject->ihObject] );
603 case EMR_DELETEOBJECT:
605 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
606 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
607 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
610 case EMR_SETWINDOWORGEX:
612 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
614 info->wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
615 info->wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
617 TRACE("SetWindowOrgEx: %d,%d\n",info->wndOrgX,info->wndOrgY);
620 case EMR_SETWINDOWEXTEX:
622 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
624 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
626 info->wndExtX = pSetWindowExtEx->szlExtent.cx;
627 info->wndExtY = pSetWindowExtEx->szlExtent.cy;
629 TRACE("SetWindowExtEx: %d,%d\n",info->wndExtX,info->wndExtY);
632 case EMR_SETVIEWPORTORGEX:
634 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
635 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
637 info->vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
638 info->vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
639 TRACE("SetViewportOrgEx: %d,%d\n",info->vportOrgX,info->vportOrgY);
642 case EMR_SETVIEWPORTEXTEX:
644 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
645 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
647 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
649 info->vportExtX = pSetViewportExtEx->szlExtent.cx;
650 info->vportExtY = pSetViewportExtEx->szlExtent.cy;
651 TRACE("SetViewportExtEx: %d,%d\n",info->vportExtX,info->vportExtY);
656 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
657 (handletable->objectHandle)[pCreatePen->ihPen] =
658 CreatePenIndirect(&pCreatePen->lopn);
661 case EMR_EXTCREATEPEN:
663 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
665 lb.lbStyle = pPen->elp.elpBrushStyle;
666 lb.lbColor = pPen->elp.elpColor;
667 lb.lbHatch = pPen->elp.elpHatch;
669 if(pPen->offBmi || pPen->offBits)
670 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
672 (handletable->objectHandle)[pPen->ihPen] =
673 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
674 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
677 case EMR_CREATEBRUSHINDIRECT:
679 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
680 (handletable->objectHandle)[pBrush->ihBrush] =
681 CreateBrushIndirect(&pBrush->lb);
684 case EMR_EXTCREATEFONTINDIRECTW:
686 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
687 (handletable->objectHandle)[pFont->ihFont] =
688 CreateFontIndirectW(&pFont->elfw.elfLogFont);
693 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
694 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
699 PEMRLINETO pLineTo = (PEMRLINETO) mr;
700 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
705 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
706 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
707 pRect->rclBox.right, pRect->rclBox.bottom);
712 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
713 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
714 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
719 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
720 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
721 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
722 pPoly->cpts * sizeof(POINT) );
724 for(i = 0; i < pPoly->cpts; i++)
725 CONV_POINT16TO32(pPoly->apts + i, pts + i);
726 Polygon(hdc, pts, pPoly->cpts);
727 HeapFree( GetProcessHeap(), 0, pts );
732 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
733 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
734 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
735 pPoly->cpts * sizeof(POINT) );
737 for(i = 0; i < pPoly->cpts; i++)
738 CONV_POINT16TO32(pPoly->apts + i, pts + i);
739 Polyline(hdc, pts, pPoly->cpts);
740 HeapFree( GetProcessHeap(), 0, pts );
743 case EMR_POLYLINETO16:
745 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
746 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
747 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
748 pPoly->cpts * sizeof(POINT) );
750 for(i = 0; i < pPoly->cpts; i++)
751 CONV_POINT16TO32(pPoly->apts + i, pts + i);
752 PolylineTo(hdc, pts, pPoly->cpts);
753 HeapFree( GetProcessHeap(), 0, pts );
756 case EMR_POLYBEZIER16:
758 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
759 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
760 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
761 pPoly->cpts * sizeof(POINT) );
763 for(i = 0; i < pPoly->cpts; i++)
764 CONV_POINT16TO32(pPoly->apts + i, pts + i);
765 PolyBezier(hdc, pts, pPoly->cpts);
766 HeapFree( GetProcessHeap(), 0, pts );
769 case EMR_POLYBEZIERTO16:
771 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
772 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
773 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
774 pPoly->cpts * sizeof(POINT) );
776 for(i = 0; i < pPoly->cpts; i++)
777 CONV_POINT16TO32(pPoly->apts + i, pts + i);
778 PolyBezierTo(hdc, pts, pPoly->cpts);
779 HeapFree( GetProcessHeap(), 0, pts );
782 case EMR_POLYPOLYGON16:
784 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
785 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
786 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
788 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
789 pPolyPoly->cpts * sizeof(POINT) );
791 for(i = 0; i < pPolyPoly->cpts; i++)
792 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
793 pPolyPoly->nPolys) + i, pts + i);
795 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
796 HeapFree( GetProcessHeap(), 0, pts );
799 case EMR_POLYPOLYLINE16:
801 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
802 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
803 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
805 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
806 pPolyPoly->cpts * sizeof(POINT) );
808 for(i = 0; i < pPolyPoly->cpts; i++)
809 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
810 pPolyPoly->nPolys) + i, pts + i);
812 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
813 HeapFree( GetProcessHeap(), 0, pts );
817 case EMR_STRETCHDIBITS:
819 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
822 pStretchDIBits->xDest,
823 pStretchDIBits->yDest,
824 pStretchDIBits->cxDest,
825 pStretchDIBits->cyDest,
826 pStretchDIBits->xSrc,
827 pStretchDIBits->ySrc,
828 pStretchDIBits->cxSrc,
829 pStretchDIBits->cySrc,
830 (BYTE *)mr + pStretchDIBits->offBitsSrc,
831 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
832 pStretchDIBits->iUsageSrc,
833 pStretchDIBits->dwRop);
837 case EMR_EXTTEXTOUTA:
839 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
842 rc.left = pExtTextOutA->emrtext.rcl.left;
843 rc.top = pExtTextOutA->emrtext.rcl.top;
844 rc.right = pExtTextOutA->emrtext.rcl.right;
845 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
846 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
847 pExtTextOutA->emrtext.fOptions, &rc,
848 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
849 (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx));
853 case EMR_EXTTEXTOUTW:
855 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
858 rc.left = pExtTextOutW->emrtext.rcl.left;
859 rc.top = pExtTextOutW->emrtext.rcl.top;
860 rc.right = pExtTextOutW->emrtext.rcl.right;
861 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
862 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
863 pExtTextOutW->emrtext.fOptions, &rc,
864 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
865 (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx));
869 case EMR_CREATEPALETTE:
871 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
873 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
874 CreatePalette( &lpCreatePal->lgpl );
879 case EMR_SELECTPALETTE:
881 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
883 if( lpSelectPal->ihPal & 0x80000000 ) {
884 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
886 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
887 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
892 case EMR_REALIZEPALETTE:
894 RealizePalette( hdc );
898 case EMR_EXTSELECTCLIPRGN:
901 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
902 HRGN hRgn = ExtCreateRegion(NULL, lpRgn->cbRgnData, (RGNDATA *)lpRgn->RgnData);
903 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
904 /* ExtSelectClipRgn created a copy of the region */
907 FIXME("ExtSelectClipRgn\n");
917 case EMR_SETWORLDTRANSFORM:
919 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
920 info->world_transform = lpXfrm->xform;
926 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
927 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
933 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
934 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
940 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
941 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
945 case EMR_POLYBEZIERTO:
947 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
948 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
949 (UINT)lpPolyBezierTo->cptl );
955 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
956 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
957 (UINT)lpPolyLineTo->cptl );
961 case EMR_POLYPOLYLINE:
963 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
964 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
966 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
967 pPolyPolyline->nPolys),
968 pPolyPolyline->aPolyCounts,
969 pPolyPolyline->nPolys );
974 case EMR_POLYPOLYGON:
976 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
978 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
980 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
981 pPolyPolygon->nPolys),
982 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
986 case EMR_SETBRUSHORGEX:
988 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
991 (INT)lpSetBrushOrgEx->ptlOrigin.x,
992 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1000 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
1003 (INT)lpSetPixelV->ptlPixel.x,
1004 (INT)lpSetPixelV->ptlPixel.y,
1005 lpSetPixelV->crColor );
1010 case EMR_SETMAPPERFLAGS:
1012 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
1014 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1019 case EMR_SETCOLORADJUSTMENT:
1021 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
1023 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1028 case EMR_OFFSETCLIPRGN:
1030 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
1033 (INT)lpOffsetClipRgn->ptlOffset.x,
1034 (INT)lpOffsetClipRgn->ptlOffset.y );
1035 FIXME("OffsetClipRgn\n");
1040 case EMR_EXCLUDECLIPRECT:
1042 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
1044 ExcludeClipRect( hdc,
1045 lpExcludeClipRect->rclClip.left,
1046 lpExcludeClipRect->rclClip.top,
1047 lpExcludeClipRect->rclClip.right,
1048 lpExcludeClipRect->rclClip.bottom );
1049 FIXME("ExcludeClipRect\n");
1054 case EMR_SCALEVIEWPORTEXTEX:
1056 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
1058 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1060 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1061 !lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->yDenom)
1063 info->vportExtX = (info->vportExtX * lpScaleViewportExtEx->xNum) /
1064 lpScaleViewportExtEx->xDenom;
1065 info->vportExtY = (info->vportExtY * lpScaleViewportExtEx->yNum) /
1066 lpScaleViewportExtEx->yDenom;
1067 if (info->vportExtX == 0) info->vportExtX = 1;
1068 if (info->vportExtY == 0) info->vportExtY = 1;
1069 if (info->mode == MM_ISOTROPIC)
1070 FIXME("EMRSCALEVIEWPORTEXTEX MM_ISOTROPIC mapping\n");
1071 /* MAPPING_FixIsotropic( dc ); */
1073 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1074 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1075 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1080 case EMR_SCALEWINDOWEXTEX:
1082 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
1084 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1086 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1087 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1089 info->wndExtX = (info->wndExtX * lpScaleWindowExtEx->xNum) /
1090 lpScaleWindowExtEx->xDenom;
1091 info->wndExtY = (info->wndExtY * lpScaleWindowExtEx->yNum) /
1092 lpScaleWindowExtEx->yDenom;
1093 if (info->wndExtX == 0) info->wndExtX = 1;
1094 if (info->wndExtY == 0) info->wndExtY = 1;
1095 if (info->mode == MM_ISOTROPIC)
1096 FIXME("EMRSCALEWINDOWEXTEX MM_ISOTROPIC mapping\n");
1097 /* MAPPING_FixIsotropic( dc ); */
1099 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1100 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1101 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1106 case EMR_MODIFYWORLDTRANSFORM:
1108 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
1110 switch(lpModifyWorldTrans->iMode) {
1112 info->world_transform.eM11 = info->world_transform.eM22 = 1;
1113 info->world_transform.eM12 = info->world_transform.eM21 = 0;
1114 info->world_transform.eDx = info->world_transform.eDy = 0;
1116 case MWT_LEFTMULTIPLY:
1117 CombineTransform(&info->world_transform, &lpModifyWorldTrans->xform,
1118 &info->world_transform);
1120 case MWT_RIGHTMULTIPLY:
1121 CombineTransform(&info->world_transform, &info->world_transform,
1122 &lpModifyWorldTrans->xform);
1125 FIXME("Unknown imode %ld\n", lpModifyWorldTrans->iMode);
1133 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
1136 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1137 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1138 lpAngleArc->eSweepAngle );
1145 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
1148 lpRoundRect->rclBox.left,
1149 lpRoundRect->rclBox.top,
1150 lpRoundRect->rclBox.right,
1151 lpRoundRect->rclBox.bottom,
1152 lpRoundRect->szlCorner.cx,
1153 lpRoundRect->szlCorner.cy );
1160 PEMRARC lpArc = (PEMRARC)mr;
1163 (INT)lpArc->rclBox.left,
1164 (INT)lpArc->rclBox.top,
1165 (INT)lpArc->rclBox.right,
1166 (INT)lpArc->rclBox.bottom,
1167 (INT)lpArc->ptlStart.x,
1168 (INT)lpArc->ptlStart.y,
1169 (INT)lpArc->ptlEnd.x,
1170 (INT)lpArc->ptlEnd.y );
1177 PEMRCHORD lpChord = (PEMRCHORD)mr;
1180 (INT)lpChord->rclBox.left,
1181 (INT)lpChord->rclBox.top,
1182 (INT)lpChord->rclBox.right,
1183 (INT)lpChord->rclBox.bottom,
1184 (INT)lpChord->ptlStart.x,
1185 (INT)lpChord->ptlStart.y,
1186 (INT)lpChord->ptlEnd.x,
1187 (INT)lpChord->ptlEnd.y );
1194 PEMRPIE lpPie = (PEMRPIE)mr;
1197 (INT)lpPie->rclBox.left,
1198 (INT)lpPie->rclBox.top,
1199 (INT)lpPie->rclBox.right,
1200 (INT)lpPie->rclBox.bottom,
1201 (INT)lpPie->ptlStart.x,
1202 (INT)lpPie->ptlStart.y,
1203 (INT)lpPie->ptlEnd.x,
1204 (INT)lpPie->ptlEnd.y );
1211 PEMRARC lpArcTo = (PEMRARC)mr;
1214 (INT)lpArcTo->rclBox.left,
1215 (INT)lpArcTo->rclBox.top,
1216 (INT)lpArcTo->rclBox.right,
1217 (INT)lpArcTo->rclBox.bottom,
1218 (INT)lpArcTo->ptlStart.x,
1219 (INT)lpArcTo->ptlStart.y,
1220 (INT)lpArcTo->ptlEnd.x,
1221 (INT)lpArcTo->ptlEnd.y );
1226 case EMR_EXTFLOODFILL:
1228 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
1231 (INT)lpExtFloodFill->ptlStart.x,
1232 (INT)lpExtFloodFill->ptlStart.y,
1233 lpExtFloodFill->crColor,
1234 (UINT)lpExtFloodFill->iMode );
1241 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
1243 (const LPPOINT)lpPolyDraw->aptl,
1244 lpPolyDraw->abTypes,
1245 (INT)lpPolyDraw->cptl );
1250 case EMR_SETARCDIRECTION:
1252 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1253 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1257 case EMR_SETMITERLIMIT:
1259 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1260 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1276 case EMR_CLOSEFIGURE:
1284 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1289 case EMR_STROKEANDFILLPATH:
1291 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1292 StrokeAndFillPath( hdc );
1296 case EMR_STROKEPATH:
1298 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1303 case EMR_FLATTENPATH:
1315 case EMR_SELECTCLIPPATH:
1317 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1318 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1328 case EMR_CREATECOLORSPACE:
1330 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1331 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1332 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1336 case EMR_SETCOLORSPACE:
1338 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1340 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1344 case EMR_DELETECOLORSPACE:
1346 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1347 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1351 case EMR_SETICMMODE:
1353 PEMRSETICMMODE lpSetICMMode = (PEMRSETICMMODE)mr;
1354 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1358 case EMR_PIXELFORMAT:
1361 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1363 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1364 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1369 case EMR_SETPALETTEENTRIES:
1371 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1373 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1374 (UINT)lpSetPaletteEntries->iStart,
1375 (UINT)lpSetPaletteEntries->cEntries,
1376 lpSetPaletteEntries->aPalEntries );
1381 case EMR_RESIZEPALETTE:
1383 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1385 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1386 (UINT)lpResizePalette->cEntries );
1391 case EMR_CREATEDIBPATTERNBRUSHPT:
1393 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1394 LPVOID lpPackedStruct;
1396 /* check that offsets and data are contained within the record */
1397 if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
1398 (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
1399 ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
1400 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
1402 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1406 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1407 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1408 lpCreate->cbBmi + lpCreate->cbBits );
1411 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1415 /* Now pack this structure */
1416 memcpy( lpPackedStruct,
1417 ((BYTE*)lpCreate) + lpCreate->offBmi,
1419 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1420 ((BYTE*)lpCreate) + lpCreate->offBits,
1423 (handletable->objectHandle)[lpCreate->ihBrush] =
1424 CreateDIBPatternBrushPt( lpPackedStruct,
1425 (UINT)lpCreate->iUsage );
1427 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1432 case EMR_CREATEMONOBRUSH:
1434 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1435 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1436 HBITMAP hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1437 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1438 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1439 /* CreatePatternBrush created a copy of the bitmap */
1446 PEMRBITBLT pBitBlt = (PEMRBITBLT)mr;
1447 HDC hdcSrc = CreateCompatibleDC(hdc);
1448 HBRUSH hBrush, hBrushOld;
1449 HBITMAP hBmp = 0, hBmpOld = 0;
1450 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pBitBlt->offBmiSrc);
1452 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1454 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1455 hBrushOld = SelectObject(hdcSrc, hBrush);
1456 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1457 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1458 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1459 SelectObject(hdcSrc, hBrushOld);
1460 DeleteObject(hBrush);
1462 if (pBitBlt->offBmiSrc > 0)
1464 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1465 (BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1466 hBmpOld = SelectObject(hdcSrc, hBmp);
1479 if (pBitBlt->offBmiSrc > 0)
1481 SelectObject(hdcSrc, hBmpOld);
1488 case EMR_STRETCHBLT:
1490 PEMRSTRETCHBLT pStretchBlt= (PEMRSTRETCHBLT)mr;
1491 HDC hdcSrc = CreateCompatibleDC(hdc);
1492 HBRUSH hBrush, hBrushOld;
1493 HBITMAP hBmp = 0, hBmpOld = 0;
1494 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pStretchBlt->offBmiSrc);
1496 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1498 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1499 hBrushOld = SelectObject(hdcSrc, hBrush);
1500 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1501 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1502 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1503 SelectObject(hdcSrc, hBrushOld);
1504 DeleteObject(hBrush);
1506 if (pStretchBlt->offBmiSrc)
1508 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1509 (BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1510 hBmpOld = SelectObject(hdcSrc, hBmp);
1516 pStretchBlt->cxDest,
1517 pStretchBlt->cyDest,
1523 pStretchBlt->dwRop);
1526 if (pStretchBlt->offBmiSrc)
1528 SelectObject(hdcSrc, hBmpOld);
1538 PEMRMASKBLT pMaskBlt= (PEMRMASKBLT)mr;
1539 HDC hdcSrc = CreateCompatibleDC(hdc);
1540 HBRUSH hBrush, hBrushOld;
1541 HBITMAP hBmp, hBmpOld, hBmpMask;
1544 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1546 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1547 hBrushOld = SelectObject(hdcSrc, hBrush);
1548 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1549 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1550 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1551 SelectObject(hdcSrc, hBrushOld);
1552 DeleteObject(hBrush);
1554 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiMask);
1555 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1556 (BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1558 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiSrc);
1559 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1560 (BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1561 hBmpOld = SelectObject(hdcSrc, hBmp);
1574 SelectObject(hdcSrc, hBmpOld);
1576 DeleteObject(hBmpMask);
1583 PEMRPLGBLT pPlgBlt= (PEMRPLGBLT)mr;
1584 HDC hdcSrc = CreateCompatibleDC(hdc);
1585 HBRUSH hBrush, hBrushOld;
1586 HBITMAP hBmp, hBmpOld, hBmpMask;
1590 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1592 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1593 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1594 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1596 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1597 hBrushOld = SelectObject(hdcSrc, hBrush);
1598 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1599 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1600 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1601 SelectObject(hdcSrc, hBrushOld);
1602 DeleteObject(hBrush);
1604 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiMask);
1605 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1606 (BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1608 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiSrc);
1609 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1610 (BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1611 hBmpOld = SelectObject(hdcSrc, hBmp);
1622 SelectObject(hdcSrc, hBmpOld);
1624 DeleteObject(hBmpMask);
1629 case EMR_SETDIBITSTODEVICE:
1631 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice = (PEMRSETDIBITSTODEVICE)mr;
1633 SetDIBitsToDevice(hdc,
1634 pSetDIBitsToDevice->xDest,
1635 pSetDIBitsToDevice->yDest,
1636 pSetDIBitsToDevice->cxSrc,
1637 pSetDIBitsToDevice->cySrc,
1638 pSetDIBitsToDevice->xSrc,
1639 pSetDIBitsToDevice->ySrc,
1640 pSetDIBitsToDevice->iStartScan,
1641 pSetDIBitsToDevice->cScans,
1642 (BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
1643 (BITMAPINFO *)((BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
1644 pSetDIBitsToDevice->iUsageSrc);
1648 case EMR_POLYTEXTOUTA:
1650 PEMRPOLYTEXTOUTA pPolyTextOutA = (PEMRPOLYTEXTOUTA)mr;
1651 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
1653 XFORM xform, xformOld;
1656 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
1657 GetWorldTransform(hdc, &xformOld);
1659 xform.eM11 = pPolyTextOutA->exScale;
1662 xform.eM22 = pPolyTextOutA->eyScale;
1665 SetWorldTransform(hdc, &xform);
1667 /* Set up POLYTEXTA structures */
1668 for(i = 0; i < pPolyTextOutA->cStrings; i++)
1670 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
1671 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
1672 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
1673 polytextA[i].lpstr = (LPSTR)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
1674 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
1675 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
1676 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
1677 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
1678 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
1679 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
1681 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
1682 HeapFree(GetProcessHeap(), 0, polytextA);
1684 SetWorldTransform(hdc, &xformOld);
1685 SetGraphicsMode(hdc, gModeOld);
1689 case EMR_POLYTEXTOUTW:
1691 PEMRPOLYTEXTOUTW pPolyTextOutW = (PEMRPOLYTEXTOUTW)mr;
1692 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
1694 XFORM xform, xformOld;
1697 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
1698 GetWorldTransform(hdc, &xformOld);
1700 xform.eM11 = pPolyTextOutW->exScale;
1703 xform.eM22 = pPolyTextOutW->eyScale;
1706 SetWorldTransform(hdc, &xform);
1708 /* Set up POLYTEXTW structures */
1709 for(i = 0; i < pPolyTextOutW->cStrings; i++)
1711 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
1712 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
1713 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
1714 polytextW[i].lpstr = (LPWSTR)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
1715 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
1716 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
1717 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
1718 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
1719 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
1720 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
1722 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
1723 HeapFree(GetProcessHeap(), 0, polytextW);
1725 SetWorldTransform(hdc, &xformOld);
1726 SetGraphicsMode(hdc, gModeOld);
1732 PEMRFILLRGN pFillRgn = (PEMRFILLRGN)mr;
1733 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
1736 (handletable->objectHandle)[pFillRgn->ihBrush]);
1743 PEMRFRAMERGN pFrameRgn = (PEMRFRAMERGN)mr;
1744 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
1747 (handletable->objectHandle)[pFrameRgn->ihBrush],
1748 pFrameRgn->szlStroke.cx,
1749 pFrameRgn->szlStroke.cy);
1756 PEMRINVERTRGN pInvertRgn = (PEMRINVERTRGN)mr;
1757 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
1758 InvertRgn(hdc, hRgn);
1765 PEMRPAINTRGN pPaintRgn = (PEMRPAINTRGN)mr;
1766 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
1767 PaintRgn(hdc, hRgn);
1772 case EMR_SETTEXTJUSTIFICATION:
1774 PEMRSETTEXTJUSTIFICATION pSetTextJust = (PEMRSETTEXTJUSTIFICATION)mr;
1775 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
1781 PEMRSETLAYOUT pSetLayout = (PEMRSETLAYOUT)mr;
1782 SetLayout(hdc, pSetLayout->iMode);
1786 case EMR_POLYDRAW16:
1788 case EMR_GLSBOUNDEDRECORD:
1789 case EMR_DRAWESCAPE :
1792 case EMR_SMALLTEXTOUT:
1793 case EMR_FORCEUFIMAPPING:
1794 case EMR_NAMEDESCAPE:
1795 case EMR_COLORCORRECTPALETTE:
1796 case EMR_SETICMPROFILEA:
1797 case EMR_SETICMPROFILEW:
1798 case EMR_ALPHABLEND:
1799 case EMR_TRANSPARENTBLT:
1800 case EMR_GRADIENTFILL:
1801 case EMR_SETLINKEDUFI:
1802 case EMR_COLORMATCHTOTARGETW:
1803 case EMR_CREATECOLORSPACEW:
1806 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1807 record then ignore and return TRUE. */
1808 FIXME("type %d is unimplemented\n", type);
1811 tmprc.left = tmprc.top = 0;
1812 tmprc.right = tmprc.bottom = 1000;
1813 LPtoDP(hdc, (POINT*)&tmprc, 2);
1814 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", tmprc.left,
1815 tmprc.top, tmprc.right, tmprc.bottom);
1819 /* WinNT - update the transform (win9x updates when the next graphics output
1820 record is played). */
1821 EMF_Update_MF_Xform(hdc, info);
1828 /*****************************************************************************
1830 * EnumEnhMetaFile (GDI32.@)
1832 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1834 * record. Returns when either every record has been used or
1835 * when _EnhMetaFunc_ returns FALSE.
1839 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1846 * This function behaves differently in Win9x and WinNT.
1848 * In WinNT, the DC's world transform is updated as the EMF changes
1849 * the Window/Viewport Extent and Origin or it's world transform.
1850 * The actual Window/Viewport Extent and Origin are left untouched.
1852 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
1853 * updates the scaling itself but only just before a record that
1854 * writes anything to the DC.
1856 * I'm not sure where the data (enum_emh_data) is stored in either
1857 * version. For this implementation, it is stored before the handle
1858 * table, but it could be stored in the DC, in the EMF handle or in
1862 BOOL WINAPI EnumEnhMetaFile(
1863 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
1864 HENHMETAFILE hmf, /* [in] EMF to walk */
1865 ENHMFENUMPROC callback, /* [in] callback function */
1866 LPVOID data, /* [in] optional data for callback function */
1867 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
1879 HBRUSH hBrush = NULL;
1881 enum_emh_data *info;
1882 SIZE vp_size, win_size;
1883 POINT vp_org, win_org;
1884 INT mapMode = MM_TEXT;
1888 SetLastError(ERROR_INVALID_PARAMETER);
1892 emh = EMF_GetEnhMetaHeader(hmf);
1894 SetLastError(ERROR_INVALID_HANDLE);
1898 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1899 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
1902 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1909 info->vportOrgX = 0;
1910 info->vportOrgY = 0;
1911 info->vportExtX = 1;
1912 info->vportExtY = 1;
1913 info->world_transform.eM11 = info->world_transform.eM22 = 1;
1914 info->world_transform.eM12 = info->world_transform.eM21 = 0;
1915 info->world_transform.eDx = info->world_transform.eDy = 0;
1917 ht = (HANDLETABLE*) &info[1];
1918 ht->objectHandle[0] = hmf;
1922 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1923 GetWorldTransform(hdc, &savedXform);
1924 GetViewportExtEx(hdc, &vp_size);
1925 GetWindowExtEx(hdc, &win_size);
1926 GetViewportOrgEx(hdc, &vp_org);
1927 GetWindowOrgEx(hdc, &win_org);
1928 mapMode = GetMapMode(hdc);
1930 /* save the current pen, brush and font */
1931 hPen = GetCurrentObject(hdc, OBJ_PEN);
1932 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
1933 hFont = GetCurrentObject(hdc, OBJ_FONT);
1936 info->mode = MM_TEXT;
1940 /* Win95 leaves the vp/win ext/org info alone */
1941 info->init_transform.eM11 = 1.0;
1942 info->init_transform.eM12 = 0.0;
1943 info->init_transform.eM21 = 0.0;
1944 info->init_transform.eM22 = 1.0;
1945 info->init_transform.eDx = 0.0;
1946 info->init_transform.eDy = 0.0;
1950 /* WinNT combines the vp/win ext/org info into a transform */
1951 FLOAT xscale, yscale;
1952 xscale = (FLOAT)vp_size.cx / (FLOAT)win_size.cx;
1953 yscale = (FLOAT)vp_size.cy / (FLOAT)win_size.cy;
1954 info->init_transform.eM11 = xscale;
1955 info->init_transform.eM12 = 0.0;
1956 info->init_transform.eM21 = 0.0;
1957 info->init_transform.eM22 = yscale;
1958 info->init_transform.eDx = (FLOAT)vp_org.x - xscale * (FLOAT)win_org.x;
1959 info->init_transform.eDy = (FLOAT)vp_org.y - yscale * (FLOAT)win_org.y;
1961 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
1964 if ( WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
1966 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1969 TRACE("rect: %ld,%ld - %ld,%ld. rclFrame: %ld,%ld - %ld,%ld\n",
1970 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
1971 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
1972 emh->rclFrame.bottom);
1974 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
1975 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
1976 xscale = (FLOAT) WIDTH(*lpRect) * 100.0 /
1977 WIDTH(emh->rclFrame) * xSrcPixSize;
1978 yscale = (FLOAT) HEIGHT(*lpRect) * 100.0 /
1979 HEIGHT(emh->rclFrame) * ySrcPixSize;
1981 xform.eM11 = xscale;
1984 xform.eM22 = yscale;
1985 xform.eDx = (FLOAT) lpRect->left - (FLOAT) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
1986 xform.eDy = (FLOAT) lpRect->top - (FLOAT) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
1988 CombineTransform(&info->init_transform, &xform, &info->init_transform);
1991 /* WinNT resets the current vp/win org/ext */
1994 SetMapMode(hdc, MM_TEXT);
1995 SetWindowOrgEx(hdc, 0, 0, NULL);
1996 SetViewportOrgEx(hdc, 0, 0, NULL);
1997 EMF_Update_MF_Xform(hdc, info);
2002 while(ret && offset < emh->nBytes)
2004 emr = (ENHMETARECORD *)((char *)emh + offset);
2005 TRACE("Calling EnumFunc with record type %ld, size %ld\n", emr->iType, emr->nSize);
2006 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2007 offset += emr->nSize;
2012 /* restore pen, brush and font */
2013 SelectObject(hdc, hBrush);
2014 SelectObject(hdc, hPen);
2015 SelectObject(hdc, hFont);
2017 SetWorldTransform(hdc, &savedXform);
2019 SetGraphicsMode(hdc, savedMode);
2020 SetMapMode(hdc, mapMode);
2021 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2022 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2023 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2024 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2027 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2028 if( (ht->objectHandle)[i] )
2029 DeleteObject( (ht->objectHandle)[i] );
2031 HeapFree( GetProcessHeap(), 0, info );
2035 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2036 const ENHMETARECORD *emr,
2037 INT handles, LPARAM data)
2039 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2042 /**************************************************************************
2043 * PlayEnhMetaFile (GDI32.@)
2045 * Renders an enhanced metafile into a specified rectangle *lpRect
2046 * in device context hdc.
2049 BOOL WINAPI PlayEnhMetaFile(
2050 HDC hdc, /* [in] DC to render into */
2051 HENHMETAFILE hmf, /* [in] metafile to render */
2052 const RECT *lpRect /* [in] rectangle to place metafile inside */
2055 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2059 /*****************************************************************************
2060 * DeleteEnhMetaFile (GDI32.@)
2062 * Deletes an enhanced metafile and frees the associated storage.
2064 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2066 return EMF_Delete_HENHMETAFILE( hmf );
2069 /*****************************************************************************
2070 * CopyEnhMetaFileA (GDI32.@) Duplicate an enhanced metafile
2074 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2075 HENHMETAFILE hmfSrc,
2078 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2079 HENHMETAFILE hmfDst;
2081 if(!emrSrc) return FALSE;
2083 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2084 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2085 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2088 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2089 NULL, CREATE_ALWAYS, 0, 0);
2090 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
2091 CloseHandle( hFile );
2092 /* Reopen file for reading only, so that apps can share
2093 read access to the file while hmf is still valid */
2094 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2095 NULL, OPEN_EXISTING, 0, 0);
2096 if(hFile == INVALID_HANDLE_VALUE) {
2097 ERR("Can't reopen emf for reading\n");
2100 hmfDst = EMF_GetEnhMetaFile( hFile );
2101 CloseHandle( hFile );
2107 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2108 typedef struct tagEMF_PaletteCopy
2111 LPPALETTEENTRY lpPe;
2114 /***************************************************************
2115 * Find the EMR_EOF record and then use it to find the
2116 * palette entries for this enhanced metafile.
2117 * The lpData is actually a pointer to a EMF_PaletteCopy struct
2118 * which contains the max number of elements to copy and where
2121 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2123 INT CALLBACK cbEnhPaletteCopy( HDC a,
2125 const ENHMETARECORD *lpEMR,
2130 if ( lpEMR->iType == EMR_EOF )
2132 PEMREOF lpEof = (PEMREOF)lpEMR;
2133 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2134 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2136 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
2138 memcpy( (LPVOID)info->lpPe,
2139 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
2140 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2142 /* Update the passed data as a return code */
2143 info->lpPe = NULL; /* Palettes were copied! */
2144 info->cEntries = (UINT)dwNumPalToCopy;
2146 return FALSE; /* That's all we need */
2152 /*****************************************************************************
2153 * GetEnhMetaFilePaletteEntries (GDI32.@)
2155 * Copy the palette and report size
2157 * BUGS: Error codes (SetLastError) are not set on failures
2159 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2161 LPPALETTEENTRY lpPe )
2163 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2164 EMF_PaletteCopy infoForCallBack;
2166 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2168 /* First check if there are any palettes associated with
2170 if ( enhHeader->nPalEntries == 0 ) return 0;
2172 /* Is the user requesting the number of palettes? */
2173 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
2175 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2176 infoForCallBack.cEntries = cEntries;
2177 infoForCallBack.lpPe = lpPe;
2179 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2180 &infoForCallBack, 0 ) )
2183 /* Verify that the callback executed correctly */
2184 if ( infoForCallBack.lpPe != NULL )
2186 /* Callback proc had error! */
2187 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2191 return infoForCallBack.cEntries;
2194 typedef struct gdi_mf_comment
2201 DWORD cbWinMetaFile;
2204 /******************************************************************
2205 * SetWinMetaFileBits (GDI32.@)
2207 * Translate from old style to new style.
2210 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2211 CONST BYTE *lpbBuffer,
2213 CONST METAFILEPICT *lpmfp
2217 HENHMETAFILE ret = 0;
2218 HDC hdc = 0, hdcdisp = 0;
2220 RECT rc, *prcFrame = NULL;
2221 gdi_mf_comment *mfcomment;
2222 UINT mfcomment_size;
2223 INT horzres, vertres, horzsize, vertsize, xext, yext;
2225 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2227 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2230 WARN("SetMetaFileBitsEx failed\n");
2235 hdcRef = hdcdisp = CreateDCA("DISPLAY", NULL, NULL, NULL);
2239 mfp.mm = MM_ANISOTROPIC;
2242 FIXME("Correct Exts from dc\n");
2246 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2247 if ( ( mfp.xExt < 0 ) || ( mfp.yExt < 0) )
2248 FIXME("Negative coordinates!\n");
2251 if(lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC) {
2252 rc.left = rc.top = 0;
2253 rc.right = lpmfp->xExt;
2254 rc.bottom = lpmfp->yExt;
2258 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL))) {
2259 ERR("CreateEnhMetaFile fails?\n");
2263 horzres = GetDeviceCaps(hdcRef, HORZRES);
2264 vertres = GetDeviceCaps(hdcRef, VERTRES);
2265 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2266 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2274 * Write the original METAFILE into the enhanced metafile.
2275 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2277 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2278 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2281 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2282 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2283 mfcomment->nVersion = 0x00000300;
2284 mfcomment->nChecksum = 0; /* FIXME */
2285 mfcomment->fFlags = 0;
2286 mfcomment->cbWinMetaFile = cbBuffer;
2287 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2288 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2289 HeapFree(GetProcessHeap(), 0, mfcomment);
2292 if(lpmfp->mm != MM_TEXT)
2293 SetMapMode(hdc, lpmfp->mm);
2295 /* set the initial viewport:window ratio as 1:1 */
2296 xext = lpmfp->xExt*horzres/(100*horzsize);
2297 yext = lpmfp->yExt*vertres/(100*vertsize);
2298 SetViewportExtEx(hdc, xext, yext, NULL);
2299 SetWindowExtEx(hdc, xext, yext, NULL);
2301 PlayMetaFile(hdc, hmf);
2303 ret = CloseEnhMetaFile(hdc);
2305 DeleteMetaFile(hmf);