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),
63 ENHMETAFILE_MAGIC, &hmf, NULL );
67 metaObj->on_disk = on_disk;
68 GDI_ReleaseObj( hmf );
73 /****************************************************************************
74 * EMF_Delete_HENHMETAFILE
76 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
78 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
80 if(!metaObj) return FALSE;
83 UnmapViewOfFile( metaObj->emh );
85 HeapFree( GetProcessHeap(), 0, metaObj->emh );
86 return GDI_FreeObject( hmf, metaObj );
89 /******************************************************************
90 * EMF_GetEnhMetaHeader
92 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
94 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
96 ENHMETAHEADER *ret = NULL;
97 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
98 TRACE("hmf %04x -> enhmetaObj %p\n", hmf, metaObj);
102 GDI_ReleaseObj( hmf );
107 /*****************************************************************************
111 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
116 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
117 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
118 CloseHandle( hMapping );
122 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
123 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
124 emh->iType, emh->dSignature);
125 UnmapViewOfFile( emh );
128 return EMF_Create_HENHMETAFILE( emh, TRUE );
132 /*****************************************************************************
133 * GetEnhMetaFileA (GDI32.@)
137 HENHMETAFILE WINAPI GetEnhMetaFileA(
138 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
144 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
145 OPEN_EXISTING, 0, 0);
146 if (hFile == INVALID_HANDLE_VALUE) {
147 WARN("could not open %s\n", lpszMetaFile);
150 hmf = EMF_GetEnhMetaFile( hFile );
151 CloseHandle( hFile );
155 /*****************************************************************************
156 * GetEnhMetaFileW (GDI32.@)
158 HENHMETAFILE WINAPI GetEnhMetaFileW(
159 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
164 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
165 OPEN_EXISTING, 0, 0);
166 if (hFile == INVALID_HANDLE_VALUE) {
167 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
170 hmf = EMF_GetEnhMetaFile( hFile );
171 CloseHandle( hFile );
175 /*****************************************************************************
176 * GetEnhMetaFileHeader (GDI32.@)
178 * If buf is NULL, returns the size of buffer required.
179 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
182 UINT WINAPI GetEnhMetaFileHeader(
183 HENHMETAFILE hmf, /* [in] enhanced metafile */
184 UINT bufsize, /* [in] size of buffer */
185 LPENHMETAHEADER buf /* [out] buffer */
191 emh = EMF_GetEnhMetaHeader(hmf);
192 if(!emh) return FALSE;
194 if (!buf) return size;
195 size = min(size, bufsize);
196 memmove(buf, emh, size);
201 /*****************************************************************************
202 * GetEnhMetaFileDescriptionA (GDI32.@)
204 UINT WINAPI GetEnhMetaFileDescriptionA(
205 HENHMETAFILE hmf, /* [in] enhanced metafile */
206 UINT size, /* [in] size of buf */
207 LPSTR buf /* [out] buffer to receive description */
210 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
214 if(!emh) return FALSE;
215 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
216 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
217 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
219 if (!buf || !size ) return len;
221 len = min( size, len );
222 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
226 /*****************************************************************************
227 * GetEnhMetaFileDescriptionW (GDI32.@)
229 * Copies the description string of an enhanced metafile into a buffer
232 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
233 * number of characters copied.
235 UINT WINAPI GetEnhMetaFileDescriptionW(
236 HENHMETAFILE hmf, /* [in] enhanced metafile */
237 UINT size, /* [in] size of buf */
238 LPWSTR buf /* [out] buffer to receive description */
241 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
243 if(!emh) return FALSE;
244 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
245 if (!buf || !size ) return emh->nDescription;
247 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
248 return min(size, emh->nDescription);
251 /****************************************************************************
252 * SetEnhMetaFileBits (GDI32.@)
254 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
256 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
258 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
259 memmove(emh, buf, bufsize);
260 return EMF_Create_HENHMETAFILE( emh, FALSE );
263 /*****************************************************************************
264 * GetEnhMetaFileBits (GDI32.@)
267 UINT WINAPI GetEnhMetaFileBits(
273 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
279 if( buf == NULL ) return size;
281 size = min( size, bufsize );
282 memmove(buf, emh, size);
286 /*****************************************************************************
287 * PlayEnhMetaFileRecord (GDI32.@)
289 * Render a single enhanced metafile record in the device context hdc.
292 * TRUE (non zero) on success, FALSE on error.
294 * Many unimplemented records.
295 * No error handling on record play failures (ie checking return codes)
297 BOOL WINAPI PlayEnhMetaFileRecord(
298 HDC hdc, /* [in] device context in which to render EMF record */
299 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
300 const ENHMETARECORD *mr, /* [in] EMF record to render */
301 UINT handles /* [in] size of handle array */
308 "hdc = %08x, handletable = %p, record = %p, numHandles = %d\n",
309 hdc, handletable, mr, handles);
310 if (!mr) return FALSE;
314 TRACE(" type=%d\n", type);
323 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
324 /* In an enhanced metafile, there can be both public and private GDI comments */
325 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
330 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
331 SetMapMode(hdc, pSetMapMode->iMode);
336 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
337 SetBkMode(hdc, pSetBkMode->iMode);
342 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
343 SetBkColor(hdc, pSetBkColor->crColor);
346 case EMR_SETPOLYFILLMODE:
348 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
349 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
354 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
355 SetROP2(hdc, pSetROP2->iMode);
358 case EMR_SETSTRETCHBLTMODE:
360 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
361 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
364 case EMR_SETTEXTALIGN:
366 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
367 SetTextAlign(hdc, pSetTextAlign->iMode);
370 case EMR_SETTEXTCOLOR:
372 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
373 SetTextColor(hdc, pSetTextColor->crColor);
383 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
384 RestoreDC(hdc, pRestoreDC->iRelative);
387 case EMR_INTERSECTCLIPRECT:
389 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
390 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
391 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
394 case EMR_SELECTOBJECT:
396 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
397 if( pSelectObject->ihObject & 0x80000000 ) {
398 /* High order bit is set - it's a stock object
399 * Strip the high bit to get the index.
400 * See MSDN article Q142319
402 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
405 /* High order bit wasn't set - not a stock object
408 (handletable->objectHandle)[pSelectObject->ihObject] );
412 case EMR_DELETEOBJECT:
414 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
415 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
416 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
419 case EMR_SETWINDOWORGEX:
422 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
428 xform.eDx = -pSetWindowOrgEx->ptlOrigin.x;
429 xform.eDy = -pSetWindowOrgEx->ptlOrigin.y;
431 ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
434 case EMR_SETWINDOWEXTEX:
436 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
437 SetWindowExtEx(hdc, pSetWindowExtEx->szlExtent.cx,
438 pSetWindowExtEx->szlExtent.cy, NULL);
441 case EMR_SETVIEWPORTORGEX:
443 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
444 SetViewportOrgEx(hdc, pSetViewportOrgEx->ptlOrigin.x,
445 pSetViewportOrgEx->ptlOrigin.y, NULL);
448 case EMR_SETVIEWPORTEXTEX:
450 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
451 SetViewportExtEx(hdc, pSetViewportExtEx->szlExtent.cx,
452 pSetViewportExtEx->szlExtent.cy, NULL);
457 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
458 (handletable->objectHandle)[pCreatePen->ihPen] =
459 CreatePenIndirect(&pCreatePen->lopn);
462 case EMR_EXTCREATEPEN:
464 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
466 lb.lbStyle = pPen->elp.elpBrushStyle;
467 lb.lbColor = pPen->elp.elpColor;
468 lb.lbHatch = pPen->elp.elpHatch;
470 if(pPen->offBmi || pPen->offBits)
471 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
473 (handletable->objectHandle)[pPen->ihPen] =
474 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
475 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
478 case EMR_CREATEBRUSHINDIRECT:
480 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
481 (handletable->objectHandle)[pBrush->ihBrush] =
482 CreateBrushIndirect(&pBrush->lb);
485 case EMR_EXTCREATEFONTINDIRECTW:
487 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
488 (handletable->objectHandle)[pFont->ihFont] =
489 CreateFontIndirectW(&pFont->elfw.elfLogFont);
494 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
495 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
500 PEMRLINETO pLineTo = (PEMRLINETO) mr;
501 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
506 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
507 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
508 pRect->rclBox.right, pRect->rclBox.bottom);
513 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
514 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
515 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
520 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
521 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
522 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
523 pPoly->cpts * sizeof(POINT) );
525 for(i = 0; i < pPoly->cpts; i++)
526 CONV_POINT16TO32(pPoly->apts + i, pts + i);
527 Polygon(hdc, pts, pPoly->cpts);
528 HeapFree( GetProcessHeap(), 0, pts );
533 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
534 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
535 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
536 pPoly->cpts * sizeof(POINT) );
538 for(i = 0; i < pPoly->cpts; i++)
539 CONV_POINT16TO32(pPoly->apts + i, pts + i);
540 Polyline(hdc, pts, pPoly->cpts);
541 HeapFree( GetProcessHeap(), 0, pts );
544 case EMR_POLYLINETO16:
546 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
547 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
548 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
549 pPoly->cpts * sizeof(POINT) );
551 for(i = 0; i < pPoly->cpts; i++)
552 CONV_POINT16TO32(pPoly->apts + i, pts + i);
553 PolylineTo(hdc, pts, pPoly->cpts);
554 HeapFree( GetProcessHeap(), 0, pts );
557 case EMR_POLYBEZIER16:
559 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
560 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
561 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
562 pPoly->cpts * sizeof(POINT) );
564 for(i = 0; i < pPoly->cpts; i++)
565 CONV_POINT16TO32(pPoly->apts + i, pts + i);
566 PolyBezier(hdc, pts, pPoly->cpts);
567 HeapFree( GetProcessHeap(), 0, pts );
570 case EMR_POLYBEZIERTO16:
572 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
573 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
574 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
575 pPoly->cpts * sizeof(POINT) );
577 for(i = 0; i < pPoly->cpts; i++)
578 CONV_POINT16TO32(pPoly->apts + i, pts + i);
579 PolyBezierTo(hdc, pts, pPoly->cpts);
580 HeapFree( GetProcessHeap(), 0, pts );
583 case EMR_POLYPOLYGON16:
585 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
586 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
587 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
589 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
590 pPolyPoly->cpts * sizeof(POINT) );
592 for(i = 0; i < pPolyPoly->cpts; i++)
593 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
594 pPolyPoly->nPolys) + i, pts + i);
596 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
597 HeapFree( GetProcessHeap(), 0, pts );
600 case EMR_POLYPOLYLINE16:
602 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
603 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
604 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
606 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
607 pPolyPoly->cpts * sizeof(POINT) );
609 for(i = 0; i < pPolyPoly->cpts; i++)
610 CONV_POINT16TO32((POINT16*) (pPolyPoly->aPolyCounts +
611 pPolyPoly->nPolys) + i, pts + i);
613 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
614 HeapFree( GetProcessHeap(), 0, pts );
618 case EMR_STRETCHDIBITS:
620 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
623 pStretchDIBits->xDest,
624 pStretchDIBits->yDest,
625 pStretchDIBits->cxDest,
626 pStretchDIBits->cyDest,
627 pStretchDIBits->xSrc,
628 pStretchDIBits->ySrc,
629 pStretchDIBits->cxSrc,
630 pStretchDIBits->cySrc,
631 (BYTE *)mr + pStretchDIBits->offBitsSrc,
632 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
633 pStretchDIBits->iUsageSrc,
634 pStretchDIBits->dwRop);
638 case EMR_EXTTEXTOUTA:
640 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
643 rc.left = pExtTextOutA->emrtext.rcl.left;
644 rc.top = pExtTextOutA->emrtext.rcl.top;
645 rc.right = pExtTextOutA->emrtext.rcl.right;
646 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
647 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
648 pExtTextOutA->emrtext.fOptions, &rc,
649 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
650 (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx));
654 case EMR_EXTTEXTOUTW:
656 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
659 rc.left = pExtTextOutW->emrtext.rcl.left;
660 rc.top = pExtTextOutW->emrtext.rcl.top;
661 rc.right = pExtTextOutW->emrtext.rcl.right;
662 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
663 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
664 pExtTextOutW->emrtext.fOptions, &rc,
665 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
666 (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx));
670 case EMR_CREATEPALETTE:
672 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
674 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
675 CreatePalette( &lpCreatePal->lgpl );
680 case EMR_SELECTPALETTE:
682 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
684 if( lpSelectPal->ihPal & 0x80000000 ) {
685 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
687 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
688 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
693 case EMR_REALIZEPALETTE:
695 RealizePalette( hdc );
699 case EMR_EXTSELECTCLIPRGN:
701 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
702 HRGN hRgn = ExtCreateRegion(NULL, lpRgn->cbRgnData, (RGNDATA *)lpRgn->RgnData);
703 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
704 /* ExtSelectClipRgn created a copy of the region */
715 case EMR_SETWORLDTRANSFORM:
717 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
718 SetWorldTransform( hdc, &lpXfrm->xform );
724 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
725 PolyBezier(hdc, (const LPPOINT)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
731 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
732 Polygon( hdc, (const LPPOINT)lpPoly->aptl, (UINT)lpPoly->cptl );
738 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
739 Polyline(hdc, (const LPPOINT)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
743 case EMR_POLYBEZIERTO:
745 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
746 PolyBezierTo( hdc, (const LPPOINT)lpPolyBezierTo->aptl,
747 (UINT)lpPolyBezierTo->cptl );
753 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
754 PolylineTo( hdc, (const LPPOINT)lpPolyLineTo->aptl,
755 (UINT)lpPolyLineTo->cptl );
759 case EMR_POLYPOLYLINE:
761 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
762 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
764 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
765 pPolyPolyline->nPolys),
766 pPolyPolyline->aPolyCounts,
767 pPolyPolyline->nPolys );
772 case EMR_POLYPOLYGON:
774 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
776 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
778 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
779 pPolyPolygon->nPolys),
780 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
784 case EMR_SETBRUSHORGEX:
786 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
789 (INT)lpSetBrushOrgEx->ptlOrigin.x,
790 (INT)lpSetBrushOrgEx->ptlOrigin.y,
798 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
801 (INT)lpSetPixelV->ptlPixel.x,
802 (INT)lpSetPixelV->ptlPixel.y,
803 lpSetPixelV->crColor );
808 case EMR_SETMAPPERFLAGS:
810 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
812 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
817 case EMR_SETCOLORADJUSTMENT:
819 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
821 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
826 case EMR_OFFSETCLIPRGN:
828 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
831 (INT)lpOffsetClipRgn->ptlOffset.x,
832 (INT)lpOffsetClipRgn->ptlOffset.y );
837 case EMR_EXCLUDECLIPRECT:
839 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
841 ExcludeClipRect( hdc,
842 lpExcludeClipRect->rclClip.left,
843 lpExcludeClipRect->rclClip.top,
844 lpExcludeClipRect->rclClip.right,
845 lpExcludeClipRect->rclClip.bottom );
850 case EMR_SCALEVIEWPORTEXTEX:
852 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
854 ScaleViewportExtEx( hdc,
855 lpScaleViewportExtEx->xNum,
856 lpScaleViewportExtEx->xDenom,
857 lpScaleViewportExtEx->yNum,
858 lpScaleViewportExtEx->yDenom,
864 case EMR_SCALEWINDOWEXTEX:
866 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
868 ScaleWindowExtEx( hdc,
869 lpScaleWindowExtEx->xNum,
870 lpScaleWindowExtEx->xDenom,
871 lpScaleWindowExtEx->yNum,
872 lpScaleWindowExtEx->yDenom,
878 case EMR_MODIFYWORLDTRANSFORM:
880 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
882 ModifyWorldTransform( hdc, &lpModifyWorldTrans->xform,
883 lpModifyWorldTrans->iMode );
890 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
893 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
894 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
895 lpAngleArc->eSweepAngle );
902 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
905 lpRoundRect->rclBox.left,
906 lpRoundRect->rclBox.top,
907 lpRoundRect->rclBox.right,
908 lpRoundRect->rclBox.bottom,
909 lpRoundRect->szlCorner.cx,
910 lpRoundRect->szlCorner.cy );
917 PEMRARC lpArc = (PEMRARC)mr;
920 (INT)lpArc->rclBox.left,
921 (INT)lpArc->rclBox.top,
922 (INT)lpArc->rclBox.right,
923 (INT)lpArc->rclBox.bottom,
924 (INT)lpArc->ptlStart.x,
925 (INT)lpArc->ptlStart.y,
926 (INT)lpArc->ptlEnd.x,
927 (INT)lpArc->ptlEnd.y );
934 PEMRCHORD lpChord = (PEMRCHORD)mr;
937 (INT)lpChord->rclBox.left,
938 (INT)lpChord->rclBox.top,
939 (INT)lpChord->rclBox.right,
940 (INT)lpChord->rclBox.bottom,
941 (INT)lpChord->ptlStart.x,
942 (INT)lpChord->ptlStart.y,
943 (INT)lpChord->ptlEnd.x,
944 (INT)lpChord->ptlEnd.y );
951 PEMRPIE lpPie = (PEMRPIE)mr;
954 (INT)lpPie->rclBox.left,
955 (INT)lpPie->rclBox.top,
956 (INT)lpPie->rclBox.right,
957 (INT)lpPie->rclBox.bottom,
958 (INT)lpPie->ptlStart.x,
959 (INT)lpPie->ptlStart.y,
960 (INT)lpPie->ptlEnd.x,
961 (INT)lpPie->ptlEnd.y );
968 PEMRARC lpArcTo = (PEMRARC)mr;
971 (INT)lpArcTo->rclBox.left,
972 (INT)lpArcTo->rclBox.top,
973 (INT)lpArcTo->rclBox.right,
974 (INT)lpArcTo->rclBox.bottom,
975 (INT)lpArcTo->ptlStart.x,
976 (INT)lpArcTo->ptlStart.y,
977 (INT)lpArcTo->ptlEnd.x,
978 (INT)lpArcTo->ptlEnd.y );
983 case EMR_EXTFLOODFILL:
985 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
988 (INT)lpExtFloodFill->ptlStart.x,
989 (INT)lpExtFloodFill->ptlStart.y,
990 lpExtFloodFill->crColor,
991 (UINT)lpExtFloodFill->iMode );
998 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
1000 (const LPPOINT)lpPolyDraw->aptl,
1001 lpPolyDraw->abTypes,
1002 (INT)lpPolyDraw->cptl );
1007 case EMR_SETARCDIRECTION:
1009 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1010 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1014 case EMR_SETMITERLIMIT:
1016 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1017 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1033 case EMR_CLOSEFIGURE:
1041 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1046 case EMR_STROKEANDFILLPATH:
1048 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1049 StrokeAndFillPath( hdc );
1053 case EMR_STROKEPATH:
1055 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1060 case EMR_FLATTENPATH:
1072 case EMR_SELECTCLIPPATH:
1074 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1075 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1085 case EMR_CREATECOLORSPACE:
1087 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1088 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1089 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1093 case EMR_SETCOLORSPACE:
1095 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1097 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1101 case EMR_DELETECOLORSPACE:
1103 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1104 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1108 case EMR_SETICMMODE:
1110 PERMSETICMMODE lpSetICMMode = (PERMSETICMMODE)mr;
1111 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1115 case EMR_PIXELFORMAT:
1118 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1120 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1121 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1126 case EMR_SETPALETTEENTRIES:
1128 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1130 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1131 (UINT)lpSetPaletteEntries->iStart,
1132 (UINT)lpSetPaletteEntries->cEntries,
1133 lpSetPaletteEntries->aPalEntries );
1138 case EMR_RESIZEPALETTE:
1140 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1142 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1143 (UINT)lpResizePalette->cEntries );
1148 case EMR_CREATEDIBPATTERNBRUSHPT:
1150 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1151 LPVOID lpPackedStruct;
1153 /* check that offsets and data are contained within the record */
1154 if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
1155 (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
1156 ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
1157 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
1159 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1163 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1164 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1165 lpCreate->cbBmi + lpCreate->cbBits );
1168 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1172 /* Now pack this structure */
1173 memcpy( lpPackedStruct,
1174 ((BYTE*)lpCreate) + lpCreate->offBmi,
1176 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1177 ((BYTE*)lpCreate) + lpCreate->offBits,
1180 (handletable->objectHandle)[lpCreate->ihBrush] =
1181 CreateDIBPatternBrushPt( lpPackedStruct,
1182 (UINT)lpCreate->iUsage );
1184 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1189 case EMR_CREATEMONOBRUSH:
1191 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1192 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1193 HBITMAP hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1194 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1195 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1196 /* CreatePatternBrush created a copy of the bitmap */
1203 PEMRBITBLT pBitBlt = (PEMRBITBLT)mr;
1204 HDC hdcSrc = CreateCompatibleDC(hdc);
1205 HBRUSH hBrush, hBrushOld;
1206 HBITMAP hBmp = 0, hBmpOld = 0;
1207 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pBitBlt->offBmiSrc);
1209 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1211 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1212 hBrushOld = SelectObject(hdcSrc, hBrush);
1213 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1214 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1215 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1216 SelectObject(hdcSrc, hBrushOld);
1217 DeleteObject(hBrush);
1219 if (pBitBlt->offBmiSrc > 0)
1221 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1222 (BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1223 hBmpOld = SelectObject(hdcSrc, hBmp);
1236 if (pBitBlt->offBmiSrc > 0)
1238 SelectObject(hdcSrc, hBmpOld);
1245 case EMR_STRETCHBLT:
1247 PEMRSTRETCHBLT pStretchBlt= (PEMRSTRETCHBLT)mr;
1248 HDC hdcSrc = CreateCompatibleDC(hdc);
1249 HBRUSH hBrush, hBrushOld;
1250 HBITMAP hBmp = 0, hBmpOld = 0;
1251 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pStretchBlt->offBmiSrc);
1253 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1255 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1256 hBrushOld = SelectObject(hdcSrc, hBrush);
1257 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1258 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1259 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1260 SelectObject(hdcSrc, hBrushOld);
1261 DeleteObject(hBrush);
1263 if (pStretchBlt->offBmiSrc)
1265 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1266 (BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1267 hBmpOld = SelectObject(hdcSrc, hBmp);
1273 pStretchBlt->cxDest,
1274 pStretchBlt->cyDest,
1280 pStretchBlt->dwRop);
1283 if (pStretchBlt->offBmiSrc)
1285 SelectObject(hdcSrc, hBmpOld);
1295 PEMRMASKBLT pMaskBlt= (PEMRMASKBLT)mr;
1296 HDC hdcSrc = CreateCompatibleDC(hdc);
1297 HBRUSH hBrush, hBrushOld;
1298 HBITMAP hBmp, hBmpOld, hBmpMask;
1301 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1303 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1304 hBrushOld = SelectObject(hdcSrc, hBrush);
1305 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1306 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1307 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1308 SelectObject(hdcSrc, hBrushOld);
1309 DeleteObject(hBrush);
1311 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiMask);
1312 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1313 (BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1315 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiSrc);
1316 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1317 (BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1318 hBmpOld = SelectObject(hdcSrc, hBmp);
1331 SelectObject(hdcSrc, hBmpOld);
1333 DeleteObject(hBmpMask);
1340 PEMRPLGBLT pPlgBlt= (PEMRPLGBLT)mr;
1341 HDC hdcSrc = CreateCompatibleDC(hdc);
1342 HBRUSH hBrush, hBrushOld;
1343 HBITMAP hBmp, hBmpOld, hBmpMask;
1347 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1349 pts[0].x = pPlgBlt->aptlDst[0].x; pts[0].y = pPlgBlt->aptlDst[0].y;
1350 pts[1].x = pPlgBlt->aptlDst[1].x; pts[1].y = pPlgBlt->aptlDst[1].y;
1351 pts[2].x = pPlgBlt->aptlDst[2].x; pts[2].y = pPlgBlt->aptlDst[2].y;
1353 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1354 hBrushOld = SelectObject(hdcSrc, hBrush);
1355 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1356 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1357 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1358 SelectObject(hdcSrc, hBrushOld);
1359 DeleteObject(hBrush);
1361 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiMask);
1362 hBmpMask = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1363 (BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1365 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiSrc);
1366 hBmp = CreateDIBitmap(0, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1367 (BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1368 hBmpOld = SelectObject(hdcSrc, hBmp);
1379 SelectObject(hdcSrc, hBmpOld);
1381 DeleteObject(hBmpMask);
1386 case EMR_SETDIBITSTODEVICE:
1388 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice = (PEMRSETDIBITSTODEVICE)mr;
1390 SetDIBitsToDevice(hdc,
1391 pSetDIBitsToDevice->xDest,
1392 pSetDIBitsToDevice->yDest,
1393 pSetDIBitsToDevice->cxSrc,
1394 pSetDIBitsToDevice->cySrc,
1395 pSetDIBitsToDevice->xSrc,
1396 pSetDIBitsToDevice->ySrc,
1397 pSetDIBitsToDevice->iStartScan,
1398 pSetDIBitsToDevice->cScans,
1399 (BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
1400 (BITMAPINFO *)((BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
1401 pSetDIBitsToDevice->iUsageSrc);
1405 case EMR_POLYTEXTOUTA:
1407 PEMRPOLYTEXTOUTA pPolyTextOutA = (PEMRPOLYTEXTOUTA)mr;
1408 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
1410 XFORM xform, xformOld;
1413 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
1414 GetWorldTransform(hdc, &xformOld);
1416 xform.eM11 = pPolyTextOutA->exScale;
1419 xform.eM22 = pPolyTextOutA->eyScale;
1422 SetWorldTransform(hdc, &xform);
1424 /* Set up POLYTEXTA structures */
1425 for(i = 0; i < pPolyTextOutA->cStrings; i++)
1427 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
1428 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
1429 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
1430 polytextA[i].lpstr = (LPSTR)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
1431 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
1432 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
1433 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
1434 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
1435 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
1436 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
1438 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
1439 HeapFree(GetProcessHeap(), 0, polytextA);
1441 SetWorldTransform(hdc, &xformOld);
1442 SetGraphicsMode(hdc, gModeOld);
1446 case EMR_POLYTEXTOUTW:
1448 PEMRPOLYTEXTOUTW pPolyTextOutW = (PEMRPOLYTEXTOUTW)mr;
1449 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
1451 XFORM xform, xformOld;
1454 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
1455 GetWorldTransform(hdc, &xformOld);
1457 xform.eM11 = pPolyTextOutW->exScale;
1460 xform.eM22 = pPolyTextOutW->eyScale;
1463 SetWorldTransform(hdc, &xform);
1465 /* Set up POLYTEXTW structures */
1466 for(i = 0; i < pPolyTextOutW->cStrings; i++)
1468 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
1469 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
1470 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
1471 polytextW[i].lpstr = (LPWSTR)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
1472 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
1473 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
1474 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
1475 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
1476 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
1477 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
1479 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
1480 HeapFree(GetProcessHeap(), 0, polytextW);
1482 SetWorldTransform(hdc, &xformOld);
1483 SetGraphicsMode(hdc, gModeOld);
1489 PEMRFILLRGN pFillRgn = (PEMRFILLRGN)mr;
1490 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
1493 (handletable->objectHandle)[pFillRgn->ihBrush]);
1500 PEMRFRAMERGN pFrameRgn = (PEMRFRAMERGN)mr;
1501 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
1504 (handletable->objectHandle)[pFrameRgn->ihBrush],
1505 pFrameRgn->szlStroke.cx,
1506 pFrameRgn->szlStroke.cy);
1513 PEMRINVERTRGN pInvertRgn = (PEMRINVERTRGN)mr;
1514 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
1515 InvertRgn(hdc, hRgn);
1522 PEMRPAINTRGN pPaintRgn = (PEMRPAINTRGN)mr;
1523 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
1524 PaintRgn(hdc, hRgn);
1529 case EMR_SETTEXTJUSTIFICATION:
1531 PEMRSETTEXTJUSTIFICATION pSetTextJust = (PEMRSETTEXTJUSTIFICATION)mr;
1532 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
1538 PEMRSETLAYOUT pSetLayout = (PEMRSETLAYOUT)mr;
1539 SetLayout(hdc, pSetLayout->iMode);
1543 case EMR_POLYDRAW16:
1545 case EMR_GLSBOUNDEDRECORD:
1546 case EMR_DRAWESCAPE :
1549 case EMR_SMALLTEXTOUT:
1550 case EMR_FORCEUFIMAPPING:
1551 case EMR_NAMEDESCAPE:
1552 case EMR_COLORCORRECTPALETTE:
1553 case EMR_SETICMPROFILEA:
1554 case EMR_SETICMPROFILEW:
1555 case EMR_ALPHABLEND:
1556 case EMR_TRANSPARENTBLT:
1557 case EMR_GRADIENTFILL:
1558 case EMR_SETLINKEDUFI:
1559 case EMR_COLORMATCHTOTARGETW:
1560 case EMR_CREATECOLORSPACEW:
1563 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
1564 record then ignore and return TRUE. */
1565 FIXME("type %d is unimplemented\n", type);
1568 tmprc.left = tmprc.top = 0;
1569 tmprc.right = tmprc.bottom = 1000;
1570 LPtoDP(hdc, (POINT*)&tmprc, 2);
1571 TRACE("L:0,0 - 1000,1000 -> D:%d,%d - %d,%d\n", tmprc.left,
1572 tmprc.top, tmprc.right, tmprc.bottom);
1577 /*****************************************************************************
1579 * EnumEnhMetaFile (GDI32.@)
1581 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1583 * record. Returns when either every record has been used or
1584 * when _EnhMetaFunc_ returns FALSE.
1588 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1594 BOOL WINAPI EnumEnhMetaFile(
1595 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
1596 HENHMETAFILE hmf, /* [in] EMF to walk */
1597 ENHMFENUMPROC callback, /* [in] callback function */
1598 LPVOID data, /* [in] optional data for callback function */
1599 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
1609 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1610 XFORM savedXform, xform;
1611 HPEN hPen = (HPEN)NULL;
1612 HBRUSH hBrush = (HBRUSH)NULL;
1613 HFONT hFont = (HFONT)NULL;
1618 SetLastError(ERROR_INVALID_PARAMETER);
1622 emh = EMF_GetEnhMetaHeader(hmf);
1624 SetLastError(ERROR_INVALID_HANDLE);
1628 ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1629 sizeof(HANDLETABLE) * emh->nHandles );
1632 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1635 ht->objectHandle[0] = hmf;
1637 if (hdc && (emh->rclFrame.right - emh->rclFrame.left) && (emh->rclFrame.bottom - emh->rclFrame.top))
1639 TRACE("rect: %d,%d - %d,%d. rclFrame: %ld,%ld - %ld,%ld\n",
1640 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
1641 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
1642 emh->rclFrame.bottom);
1644 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
1645 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
1646 xscale = (FLOAT)(lpRect->right - lpRect->left) * 100.0 /
1647 (emh->rclFrame.right - emh->rclFrame.left) * xSrcPixSize;
1648 yscale = (FLOAT)(lpRect->bottom - lpRect->top) * 100.0 /
1649 (emh->rclFrame.bottom - emh->rclFrame.top) * ySrcPixSize;
1651 xform.eM11 = xscale;
1654 xform.eM22 = yscale;
1655 xform.eDx = (FLOAT) lpRect->left - (lpRect->right - lpRect->left) *
1656 emh->rclFrame.left / (emh->rclFrame.right - emh->rclFrame.left);
1657 xform.eDy = (FLOAT) lpRect->top - (lpRect->bottom - lpRect->top) *
1658 emh->rclFrame.top / (emh->rclFrame.bottom - emh->rclFrame.top);
1660 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1661 GetWorldTransform(hdc, &savedXform);
1663 if (!ModifyWorldTransform(hdc, &xform, MWT_RIGHTMULTIPLY)) {
1664 ERR("World transform failed!\n");
1667 /* save the current pen, brush and font */
1668 hPen = GetCurrentObject(hdc, OBJ_PEN);
1669 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
1670 hFont = GetCurrentObject(hdc, OBJ_FONT);
1673 tmprc.left = tmprc.top = 0;
1674 tmprc.right = tmprc.bottom = 1000;
1675 LPtoDP(hdc, (POINT*)&tmprc, 2);
1676 TRACE("L:0,0-1000,1000 maps to D:%d,%d - %d,%d\n", tmprc.left, tmprc.top,
1677 tmprc.right, tmprc.bottom);
1678 TRACE("nSize = %ld, nBytes = %ld, nHandles = %d, nRecords = %ld, nPalEntries = %ld\n",
1679 emh->nSize, emh->nBytes, emh->nHandles, emh->nRecords, emh->nPalEntries);
1683 while(ret && offset < emh->nBytes)
1685 emr = (ENHMETARECORD *)((char *)emh + offset);
1686 TRACE("Calling EnumFunc with record type %ld, size %ld\n", emr->iType, emr->nSize);
1687 ret = (*callback)(hdc, ht, emr, emh->nHandles, data);
1688 offset += emr->nSize;
1693 /* restore pen, brush and font */
1694 SelectObject(hdc, hBrush);
1695 SelectObject(hdc, hPen);
1696 SelectObject(hdc, hFont);
1698 SetWorldTransform(hdc, &savedXform);
1700 SetGraphicsMode(hdc, savedMode);
1703 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
1704 if( (ht->objectHandle)[i] )
1705 DeleteObject( (ht->objectHandle)[i] );
1707 HeapFree( GetProcessHeap(), 0, ht );
1711 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
1713 INT handles, LPVOID data)
1715 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
1718 /**************************************************************************
1719 * PlayEnhMetaFile (GDI32.@)
1721 * Renders an enhanced metafile into a specified rectangle *lpRect
1722 * in device context hdc.
1725 BOOL WINAPI PlayEnhMetaFile(
1726 HDC hdc, /* [in] DC to render into */
1727 HENHMETAFILE hmf, /* [in] metafile to render */
1728 const RECT *lpRect /* [in] rectangle to place metafile inside */
1731 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
1735 /*****************************************************************************
1736 * DeleteEnhMetaFile (GDI32.@)
1738 * Deletes an enhanced metafile and frees the associated storage.
1740 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
1742 return EMF_Delete_HENHMETAFILE( hmf );
1745 /*****************************************************************************
1746 * CopyEnhMetaFileA (GDI32.@) Duplicate an enhanced metafile
1750 HENHMETAFILE WINAPI CopyEnhMetaFileA(
1751 HENHMETAFILE hmfSrc,
1754 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
1755 HENHMETAFILE hmfDst;
1757 if(!emrSrc) return FALSE;
1759 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
1760 memcpy( emrDst, emrSrc, emrSrc->nBytes );
1761 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
1764 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
1765 NULL, CREATE_ALWAYS, 0, 0);
1766 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
1767 CloseHandle( hFile );
1768 /* Reopen file for reading only, so that apps can share
1769 read access to the file while hmf is still valid */
1770 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
1771 NULL, OPEN_EXISTING, 0, 0);
1772 if(hFile == INVALID_HANDLE_VALUE) {
1773 ERR("Can't reopen emf for reading\n");
1776 hmfDst = EMF_GetEnhMetaFile( hFile );
1777 CloseHandle( hFile );
1783 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1784 typedef struct tagEMF_PaletteCopy
1787 LPPALETTEENTRY lpPe;
1790 /***************************************************************
1791 * Find the EMR_EOF record and then use it to find the
1792 * palette entries for this enhanced metafile.
1793 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1794 * which contains the max number of elements to copy and where
1797 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1799 INT CALLBACK cbEnhPaletteCopy( HDC a,
1801 LPENHMETARECORD lpEMR,
1806 if ( lpEMR->iType == EMR_EOF )
1808 PEMREOF lpEof = (PEMREOF)lpEMR;
1809 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
1810 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
1812 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
1814 memcpy( (LPVOID)info->lpPe,
1815 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
1816 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
1818 /* Update the passed data as a return code */
1819 info->lpPe = NULL; /* Palettes were copied! */
1820 info->cEntries = (UINT)dwNumPalToCopy;
1822 return FALSE; /* That's all we need */
1828 /*****************************************************************************
1829 * GetEnhMetaFilePaletteEntries (GDI32.@)
1831 * Copy the palette and report size
1833 * BUGS: Error codes (SetLastError) are not set on failures
1835 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
1837 LPPALETTEENTRY lpPe )
1839 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
1840 EMF_PaletteCopy infoForCallBack;
1842 TRACE( "(%04x,%d,%p)\n", hEmf, cEntries, lpPe );
1844 /* First check if there are any palettes associated with
1846 if ( enhHeader->nPalEntries == 0 ) return 0;
1848 /* Is the user requesting the number of palettes? */
1849 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
1851 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1852 infoForCallBack.cEntries = cEntries;
1853 infoForCallBack.lpPe = lpPe;
1855 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
1856 &infoForCallBack, NULL ) )
1859 /* Verify that the callback executed correctly */
1860 if ( infoForCallBack.lpPe != NULL )
1862 /* Callback proc had error! */
1863 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1867 return infoForCallBack.cEntries;
1870 /******************************************************************
1871 * SetWinMetaFileBits (GDI32.@)
1873 * Translate from old style to new style.
1876 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
1877 CONST BYTE *lpbBuffer,
1879 CONST METAFILEPICT *lpmfp
1883 HENHMETAFILE ret = 0;
1884 HDC hdc = 0, hdcdisp = 0;
1885 INT horzres, vertres;
1887 RECT rc, *prcFrame = NULL;
1889 TRACE("(%d, %p, %08x, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
1891 if(!(hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer))) {
1892 WARN("SetMetaFileBitsEx fails\n");
1897 hdcRef = hdcdisp = CreateDCA("DISPLAY", NULL, NULL, NULL);
1901 mfp.mm = MM_ANISOTROPIC;
1904 FIXME("Correct Exts from dc\n");
1906 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
1908 horzres = GetDeviceCaps(hdcRef, HORZRES);
1909 vertres = GetDeviceCaps(hdcRef, VERTRES);
1911 if(lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC) {
1912 rc.left = rc.top = 0;
1913 rc.right = lpmfp->xExt;
1914 rc.bottom = lpmfp->yExt;
1918 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL))) {
1919 ERR("CreateEnhMetaFile fails?\n");
1928 if(lpmfp->mm != MM_TEXT)
1929 SetMapMode(hdc, lpmfp->mm);
1931 SetViewportExtEx(hdc, horzres, vertres, NULL);
1932 SetWindowExtEx(hdc, horzres, vertres, NULL);
1934 PlayMetaFile(hdc, hmf); /* It's got to be harder than this... */
1936 ret = CloseEnhMetaFile(hdc);
1938 DeleteMetaFile(hmf);