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);
126 UnmapViewOfFile( emh );
129 return EMF_Create_HENHMETAFILE( emh, TRUE );
133 /*****************************************************************************
134 * GetEnhMetaFileA (GDI32.@)
138 HENHMETAFILE WINAPI GetEnhMetaFileA(
139 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
145 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
146 OPEN_EXISTING, 0, 0);
147 if (hFile == INVALID_HANDLE_VALUE) {
148 WARN("could not open %s\n", lpszMetaFile);
151 hmf = EMF_GetEnhMetaFile( hFile );
152 CloseHandle( hFile );
156 /*****************************************************************************
157 * GetEnhMetaFileW (GDI32.@)
159 HENHMETAFILE WINAPI GetEnhMetaFileW(
160 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
165 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
166 OPEN_EXISTING, 0, 0);
167 if (hFile == INVALID_HANDLE_VALUE) {
168 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
171 hmf = EMF_GetEnhMetaFile( hFile );
172 CloseHandle( hFile );
176 /*****************************************************************************
177 * GetEnhMetaFileHeader (GDI32.@)
179 * If buf is NULL, returns the size of buffer required.
180 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
183 UINT WINAPI GetEnhMetaFileHeader(
184 HENHMETAFILE hmf, /* [in] enhanced metafile */
185 UINT bufsize, /* [in] size of buffer */
186 LPENHMETAHEADER buf /* [out] buffer */
192 emh = EMF_GetEnhMetaHeader(hmf);
193 if(!emh) return FALSE;
195 if (!buf) return size;
196 size = min(size, bufsize);
197 memmove(buf, emh, size);
202 /*****************************************************************************
203 * GetEnhMetaFileDescriptionA (GDI32.@)
205 UINT WINAPI GetEnhMetaFileDescriptionA(
206 HENHMETAFILE hmf, /* [in] enhanced metafile */
207 UINT size, /* [in] size of buf */
208 LPSTR buf /* [out] buffer to receive description */
211 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
215 if(!emh) return FALSE;
216 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
217 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
218 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
220 if (!buf || !size ) return len;
222 len = min( size, len );
223 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
227 /*****************************************************************************
228 * GetEnhMetaFileDescriptionW (GDI32.@)
230 * Copies the description string of an enhanced metafile into a buffer
233 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
234 * number of characters copied.
236 UINT WINAPI GetEnhMetaFileDescriptionW(
237 HENHMETAFILE hmf, /* [in] enhanced metafile */
238 UINT size, /* [in] size of buf */
239 LPWSTR buf /* [out] buffer to receive description */
242 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
244 if(!emh) return FALSE;
245 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
246 if (!buf || !size ) return emh->nDescription;
248 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
249 return min(size, emh->nDescription);
252 /****************************************************************************
253 * SetEnhMetaFileBits (GDI32.@)
255 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
257 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
259 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
260 memmove(emh, buf, bufsize);
261 return EMF_Create_HENHMETAFILE( emh, FALSE );
264 /*****************************************************************************
265 * GetEnhMetaFileBits (GDI32.@)
268 UINT WINAPI GetEnhMetaFileBits(
274 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
280 if( buf == NULL ) return size;
282 size = min( size, bufsize );
283 memmove(buf, emh, size);
287 /*****************************************************************************
288 * PlayEnhMetaFileRecord (GDI32.@)
290 * Render a single enhanced metafile record in the device context hdc.
293 * TRUE (non zero) on success, FALSE on error.
295 * Many unimplemented records.
296 * No error handling on record play failures (ie checking return codes)
298 BOOL WINAPI PlayEnhMetaFileRecord(
299 HDC hdc, /* [in] device context in which to render EMF record */
300 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
301 const ENHMETARECORD *mr, /* [in] EMF record to render */
302 UINT handles /* [in] size of handle array */
308 TRACE("hdc = %p, 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 PEMRSETICMMODE lpSetICMMode = (PEMRSETICMMODE)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->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1350 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1351 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[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);
1569 pt[0].x = pt[0].y = 0;
1570 pt[1].x = pt[1].y = 1000;
1572 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", pt[0].x, pt[0].y,
1578 /*****************************************************************************
1580 * EnumEnhMetaFile (GDI32.@)
1582 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
1584 * record. Returns when either every record has been used or
1585 * when _EnhMetaFunc_ returns FALSE.
1589 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
1595 BOOL WINAPI EnumEnhMetaFile(
1596 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
1597 HENHMETAFILE hmf, /* [in] EMF to walk */
1598 ENHMFENUMPROC callback, /* [in] callback function */
1599 LPVOID data, /* [in] optional data for callback function */
1600 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
1610 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
1611 XFORM savedXform, xform;
1613 HBRUSH hBrush = NULL;
1619 SetLastError(ERROR_INVALID_PARAMETER);
1623 emh = EMF_GetEnhMetaHeader(hmf);
1625 SetLastError(ERROR_INVALID_HANDLE);
1629 ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
1630 sizeof(HANDLETABLE) * emh->nHandles );
1633 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1636 ht->objectHandle[0] = hmf;
1638 if (hdc && (emh->rclFrame.right - emh->rclFrame.left) && (emh->rclFrame.bottom - emh->rclFrame.top))
1640 TRACE("rect: %ld,%ld - %ld,%ld. rclFrame: %ld,%ld - %ld,%ld\n",
1641 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
1642 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
1643 emh->rclFrame.bottom);
1645 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
1646 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
1647 xscale = (FLOAT)(lpRect->right - lpRect->left) * 100.0 /
1648 (emh->rclFrame.right - emh->rclFrame.left) * xSrcPixSize;
1649 yscale = (FLOAT)(lpRect->bottom - lpRect->top) * 100.0 /
1650 (emh->rclFrame.bottom - emh->rclFrame.top) * ySrcPixSize;
1652 xform.eM11 = xscale;
1655 xform.eM22 = yscale;
1656 xform.eDx = (FLOAT) lpRect->left - (lpRect->right - lpRect->left) *
1657 emh->rclFrame.left / (emh->rclFrame.right - emh->rclFrame.left);
1658 xform.eDy = (FLOAT) lpRect->top - (lpRect->bottom - lpRect->top) *
1659 emh->rclFrame.top / (emh->rclFrame.bottom - emh->rclFrame.top);
1661 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
1662 GetWorldTransform(hdc, &savedXform);
1664 if (!ModifyWorldTransform(hdc, &xform, MWT_RIGHTMULTIPLY)) {
1665 ERR("World transform failed!\n");
1668 /* save the current pen, brush and font */
1669 hPen = GetCurrentObject(hdc, OBJ_PEN);
1670 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
1671 hFont = GetCurrentObject(hdc, OBJ_FONT);
1674 pt[0].x = pt[0].y = 0;
1675 pt[1].x = pt[1].y = 1000;
1677 TRACE("L:0,0-1000,1000 maps to D:%ld,%ld - %ld,%ld\n", pt[0].x, pt[0].y,
1679 TRACE("nSize = %ld, nBytes = %ld, nHandles = %d, nRecords = %ld, nPalEntries = %ld\n",
1680 emh->nSize, emh->nBytes, emh->nHandles, emh->nRecords, emh->nPalEntries);
1684 while(ret && offset < emh->nBytes)
1686 emr = (ENHMETARECORD *)((char *)emh + offset);
1687 TRACE("Calling EnumFunc with record type %ld, size %ld\n", emr->iType, emr->nSize);
1688 ret = (*callback)(hdc, ht, emr, emh->nHandles, data);
1689 offset += emr->nSize;
1694 /* restore pen, brush and font */
1695 SelectObject(hdc, hBrush);
1696 SelectObject(hdc, hPen);
1697 SelectObject(hdc, hFont);
1699 SetWorldTransform(hdc, &savedXform);
1701 SetGraphicsMode(hdc, savedMode);
1704 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
1705 if( (ht->objectHandle)[i] )
1706 DeleteObject( (ht->objectHandle)[i] );
1708 HeapFree( GetProcessHeap(), 0, ht );
1712 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
1714 INT handles, LPVOID data)
1716 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
1719 /**************************************************************************
1720 * PlayEnhMetaFile (GDI32.@)
1722 * Renders an enhanced metafile into a specified rectangle *lpRect
1723 * in device context hdc.
1726 BOOL WINAPI PlayEnhMetaFile(
1727 HDC hdc, /* [in] DC to render into */
1728 HENHMETAFILE hmf, /* [in] metafile to render */
1729 const RECT *lpRect /* [in] rectangle to place metafile inside */
1732 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
1736 /*****************************************************************************
1737 * DeleteEnhMetaFile (GDI32.@)
1739 * Deletes an enhanced metafile and frees the associated storage.
1741 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
1743 return EMF_Delete_HENHMETAFILE( hmf );
1746 /*****************************************************************************
1747 * CopyEnhMetaFileA (GDI32.@) Duplicate an enhanced metafile
1751 HENHMETAFILE WINAPI CopyEnhMetaFileA(
1752 HENHMETAFILE hmfSrc,
1755 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
1756 HENHMETAFILE hmfDst;
1758 if(!emrSrc) return FALSE;
1760 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
1761 memcpy( emrDst, emrSrc, emrSrc->nBytes );
1762 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
1765 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
1766 NULL, CREATE_ALWAYS, 0, 0);
1767 WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0);
1768 CloseHandle( hFile );
1769 /* Reopen file for reading only, so that apps can share
1770 read access to the file while hmf is still valid */
1771 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
1772 NULL, OPEN_EXISTING, 0, 0);
1773 if(hFile == INVALID_HANDLE_VALUE) {
1774 ERR("Can't reopen emf for reading\n");
1777 hmfDst = EMF_GetEnhMetaFile( hFile );
1778 CloseHandle( hFile );
1784 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
1785 typedef struct tagEMF_PaletteCopy
1788 LPPALETTEENTRY lpPe;
1791 /***************************************************************
1792 * Find the EMR_EOF record and then use it to find the
1793 * palette entries for this enhanced metafile.
1794 * The lpData is actually a pointer to a EMF_PaletteCopy struct
1795 * which contains the max number of elements to copy and where
1798 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
1800 INT CALLBACK cbEnhPaletteCopy( HDC a,
1802 LPENHMETARECORD lpEMR,
1807 if ( lpEMR->iType == EMR_EOF )
1809 PEMREOF lpEof = (PEMREOF)lpEMR;
1810 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
1811 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
1813 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
1815 memcpy( (LPVOID)info->lpPe,
1816 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
1817 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
1819 /* Update the passed data as a return code */
1820 info->lpPe = NULL; /* Palettes were copied! */
1821 info->cEntries = (UINT)dwNumPalToCopy;
1823 return FALSE; /* That's all we need */
1829 /*****************************************************************************
1830 * GetEnhMetaFilePaletteEntries (GDI32.@)
1832 * Copy the palette and report size
1834 * BUGS: Error codes (SetLastError) are not set on failures
1836 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
1838 LPPALETTEENTRY lpPe )
1840 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
1841 EMF_PaletteCopy infoForCallBack;
1843 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
1845 /* First check if there are any palettes associated with
1847 if ( enhHeader->nPalEntries == 0 ) return 0;
1849 /* Is the user requesting the number of palettes? */
1850 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
1852 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
1853 infoForCallBack.cEntries = cEntries;
1854 infoForCallBack.lpPe = lpPe;
1856 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
1857 &infoForCallBack, NULL ) )
1860 /* Verify that the callback executed correctly */
1861 if ( infoForCallBack.lpPe != NULL )
1863 /* Callback proc had error! */
1864 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
1868 return infoForCallBack.cEntries;
1871 /******************************************************************
1872 * SetWinMetaFileBits (GDI32.@)
1874 * Translate from old style to new style.
1877 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
1878 CONST BYTE *lpbBuffer,
1880 CONST METAFILEPICT *lpmfp
1884 HENHMETAFILE ret = 0;
1885 HDC hdc = 0, hdcdisp = 0;
1886 INT horzres, vertres;
1888 RECT rc, *prcFrame = NULL;
1890 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
1892 if(!(hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer))) {
1893 WARN("SetMetaFileBitsEx fails\n");
1898 hdcRef = hdcdisp = CreateDCA("DISPLAY", NULL, NULL, NULL);
1902 mfp.mm = MM_ANISOTROPIC;
1905 FIXME("Correct Exts from dc\n");
1907 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
1909 horzres = GetDeviceCaps(hdcRef, HORZRES);
1910 vertres = GetDeviceCaps(hdcRef, VERTRES);
1912 if(lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC) {
1913 rc.left = rc.top = 0;
1914 rc.right = lpmfp->xExt;
1915 rc.bottom = lpmfp->yExt;
1919 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL))) {
1920 ERR("CreateEnhMetaFile fails?\n");
1929 if(lpmfp->mm != MM_TEXT)
1930 SetMapMode(hdc, lpmfp->mm);
1932 SetViewportExtEx(hdc, horzres, vertres, NULL);
1933 SetWindowExtEx(hdc, horzres, vertres, NULL);
1935 PlayMetaFile(hdc, hmf); /* It's got to be harder than this... */
1937 ret = CloseEnhMetaFile(hdc);
1939 DeleteMetaFile(hmf);