2 * Enhanced metafile functions
3 * Copyright 1998 Douglas Ridgway
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * The enhanced format consists of the following elements:
25 * A table of handles to GDI objects
26 * An array of metafile records
30 * The standard format consists of a header and an array of metafile records.
35 #include "wine/port.h"
47 #include "gdi_private.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
56 BOOL on_disk; /* true if metafile is on disk */
59 static const struct emr_name {
72 X(EMR_SETWINDOWEXTEX),
73 X(EMR_SETWINDOWORGEX),
74 X(EMR_SETVIEWPORTEXTEX),
75 X(EMR_SETVIEWPORTORGEX),
79 X(EMR_SETMAPPERFLAGS),
82 X(EMR_SETPOLYFILLMODE),
84 X(EMR_SETSTRETCHBLTMODE),
86 X(EMR_SETCOLORADJUSTMENT),
92 X(EMR_EXCLUDECLIPRECT),
93 X(EMR_INTERSECTCLIPRECT),
94 X(EMR_SCALEVIEWPORTEXTEX),
95 X(EMR_SCALEWINDOWEXTEX),
98 X(EMR_SETWORLDTRANSFORM),
99 X(EMR_MODIFYWORLDTRANSFORM),
102 X(EMR_CREATEBRUSHINDIRECT),
111 X(EMR_SELECTPALETTE),
112 X(EMR_CREATEPALETTE),
113 X(EMR_SETPALETTEENTRIES),
114 X(EMR_RESIZEPALETTE),
115 X(EMR_REALIZEPALETTE),
120 X(EMR_SETARCDIRECTION),
121 X(EMR_SETMITERLIMIT),
126 X(EMR_STROKEANDFILLPATH),
130 X(EMR_SELECTCLIPPATH),
137 X(EMR_EXTSELECTCLIPRGN),
142 X(EMR_SETDIBITSTODEVICE),
143 X(EMR_STRETCHDIBITS),
144 X(EMR_EXTCREATEFONTINDIRECTW),
150 X(EMR_POLYBEZIERTO16),
152 X(EMR_POLYPOLYLINE16),
153 X(EMR_POLYPOLYGON16),
155 X(EMR_CREATEMONOBRUSH),
156 X(EMR_CREATEDIBPATTERNBRUSHPT),
161 X(EMR_CREATECOLORSPACE),
162 X(EMR_SETCOLORSPACE),
163 X(EMR_DELETECOLORSPACE),
165 X(EMR_GLSBOUNDEDRECORD),
171 X(EMR_FORCEUFIMAPPING),
173 X(EMR_COLORCORRECTPALETTE),
174 X(EMR_SETICMPROFILEA),
175 X(EMR_SETICMPROFILEW),
178 X(EMR_TRANSPARENTBLT),
182 X(EMR_SETTEXTJUSTIFICATION),
183 X(EMR_COLORMATCHTOTARGETW),
184 X(EMR_CREATECOLORSPACEW)
188 /****************************************************************************
191 static const char *get_emr_name(DWORD type)
194 for(i = 0; i < sizeof(emr_names) / sizeof(emr_names[0]); i++)
195 if(type == emr_names[i].type) return emr_names[i].name;
196 TRACE("Unknown record type %ld\n", type);
200 /***********************************************************************
203 * Returns whether a DIB can be converted to a monochrome DDB.
205 * A DIB can be converted if its color table contains only black and
206 * white. Black must be the first color in the color table.
208 * Note : If the first color in the color table is white followed by
209 * black, we can't convert it to a monochrome DDB with
210 * SetDIBits, because black and white would be inverted.
212 static inline BOOL is_dib_monochrome( const BITMAPINFO* info )
214 if (info->bmiHeader.biBitCount != 1) return FALSE;
216 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
218 RGBTRIPLE *rgb = ((BITMAPCOREINFO *) info)->bmciColors;
220 /* Check if the first color is black */
221 if ((rgb->rgbtRed == 0) && (rgb->rgbtGreen == 0) && (rgb->rgbtBlue == 0))
224 /* Check if the second color is white */
225 return ((rgb->rgbtRed == 0xff) && (rgb->rgbtGreen == 0xff)
226 && (rgb->rgbtBlue == 0xff));
230 else /* assume BITMAPINFOHEADER */
232 const RGBQUAD *rgb = info->bmiColors;
234 /* Check if the first color is black */
235 if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) &&
236 (rgb->rgbBlue == 0) && (rgb->rgbReserved == 0))
240 /* Check if the second color is white */
241 return ((rgb->rgbRed == 0xff) && (rgb->rgbGreen == 0xff)
242 && (rgb->rgbBlue == 0xff) && (rgb->rgbReserved == 0));
248 /****************************************************************************
249 * EMF_Create_HENHMETAFILE
251 HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk )
253 HENHMETAFILE hmf = 0;
254 ENHMETAFILEOBJ *metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ),
256 (HGDIOBJ *)&hmf, NULL );
260 metaObj->on_disk = on_disk;
261 GDI_ReleaseObj( hmf );
266 /****************************************************************************
267 * EMF_Delete_HENHMETAFILE
269 static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
271 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf,
273 if(!metaObj) return FALSE;
276 UnmapViewOfFile( metaObj->emh );
278 HeapFree( GetProcessHeap(), 0, metaObj->emh );
279 return GDI_FreeObject( hmf, metaObj );
282 /******************************************************************
283 * EMF_GetEnhMetaHeader
285 * Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
287 static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
289 ENHMETAHEADER *ret = NULL;
290 ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC );
291 TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
295 GDI_ReleaseObj( hmf );
300 /*****************************************************************************
304 static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
309 hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
310 emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
311 CloseHandle( hMapping );
315 if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) {
316 WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n",
317 emh->iType, emh->dSignature);
321 /* refuse to load unaligned EMF as Windows does */
324 WARN("Refusing to load unaligned EMF\n");
328 return EMF_Create_HENHMETAFILE( emh, TRUE );
331 UnmapViewOfFile( emh );
336 /*****************************************************************************
337 * GetEnhMetaFileA (GDI32.@)
341 HENHMETAFILE WINAPI GetEnhMetaFileA(
342 LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
348 hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
349 OPEN_EXISTING, 0, 0);
350 if (hFile == INVALID_HANDLE_VALUE) {
351 WARN("could not open %s\n", lpszMetaFile);
354 hmf = EMF_GetEnhMetaFile( hFile );
355 CloseHandle( hFile );
359 /*****************************************************************************
360 * GetEnhMetaFileW (GDI32.@)
362 HENHMETAFILE WINAPI GetEnhMetaFileW(
363 LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
368 hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
369 OPEN_EXISTING, 0, 0);
370 if (hFile == INVALID_HANDLE_VALUE) {
371 WARN("could not open %s\n", debugstr_w(lpszMetaFile));
374 hmf = EMF_GetEnhMetaFile( hFile );
375 CloseHandle( hFile );
379 /*****************************************************************************
380 * GetEnhMetaFileHeader (GDI32.@)
382 * Retrieves the record containing the header for the specified
383 * enhanced-format metafile.
386 * If buf is NULL, returns the size of buffer required.
387 * Otherwise, copy up to bufsize bytes of enhanced metafile header into
390 UINT WINAPI GetEnhMetaFileHeader(
391 HENHMETAFILE hmf, /* [in] enhanced metafile */
392 UINT bufsize, /* [in] size of buffer */
393 LPENHMETAHEADER buf /* [out] buffer */
399 emh = EMF_GetEnhMetaHeader(hmf);
400 if(!emh) return FALSE;
402 if (!buf) return size;
403 size = min(size, bufsize);
404 memmove(buf, emh, size);
409 /*****************************************************************************
410 * GetEnhMetaFileDescriptionA (GDI32.@)
412 * See GetEnhMetaFileDescriptionW.
414 UINT WINAPI GetEnhMetaFileDescriptionA(
415 HENHMETAFILE hmf, /* [in] enhanced metafile */
416 UINT size, /* [in] size of buf */
417 LPSTR buf /* [out] buffer to receive description */
420 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
424 if(!emh) return FALSE;
425 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
426 descrW = (WCHAR *) ((char *) emh + emh->offDescription);
427 len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
429 if (!buf || !size ) return len;
431 len = min( size, len );
432 WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
436 /*****************************************************************************
437 * GetEnhMetaFileDescriptionW (GDI32.@)
439 * Copies the description string of an enhanced metafile into a buffer
443 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
444 * number of characters copied.
446 UINT WINAPI GetEnhMetaFileDescriptionW(
447 HENHMETAFILE hmf, /* [in] enhanced metafile */
448 UINT size, /* [in] size of buf */
449 LPWSTR buf /* [out] buffer to receive description */
452 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
454 if(!emh) return FALSE;
455 if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
456 if (!buf || !size ) return emh->nDescription;
458 memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
459 return min(size, emh->nDescription);
462 /****************************************************************************
463 * SetEnhMetaFileBits (GDI32.@)
465 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
467 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
469 ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
470 memmove(emh, buf, bufsize);
471 return EMF_Create_HENHMETAFILE( emh, FALSE );
474 /*****************************************************************************
475 * GetEnhMetaFileBits (GDI32.@)
478 UINT WINAPI GetEnhMetaFileBits(
484 LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
490 if( buf == NULL ) return size;
492 size = min( size, bufsize );
493 memmove(buf, emh, size);
497 typedef struct enum_emh_data
500 XFORM init_transform;
501 XFORM world_transform;
512 #define ENUM_GET_PRIVATE_DATA(ht) \
513 ((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
515 #define WIDTH(rect) ( (rect).right - (rect).left )
516 #define HEIGHT(rect) ( (rect).bottom - (rect).top )
518 #define IS_WIN9X() (GetVersion()&0x80000000)
520 static void EMF_Update_MF_Xform(HDC hdc, enum_emh_data *info)
522 XFORM mapping_mode_trans, final_trans;
523 FLOAT scaleX, scaleY;
525 scaleX = (FLOAT)info->vportExtX / (FLOAT)info->wndExtX;
526 scaleY = (FLOAT)info->vportExtY / (FLOAT)info->wndExtY;
527 mapping_mode_trans.eM11 = scaleX;
528 mapping_mode_trans.eM12 = 0.0;
529 mapping_mode_trans.eM21 = 0.0;
530 mapping_mode_trans.eM22 = scaleY;
531 mapping_mode_trans.eDx = (FLOAT)info->vportOrgX - scaleX * (FLOAT)info->wndOrgX;
532 mapping_mode_trans.eDy = (FLOAT)info->vportOrgY - scaleY * (FLOAT)info->wndOrgY;
534 CombineTransform(&final_trans, &info->world_transform, &mapping_mode_trans);
535 CombineTransform(&final_trans, &final_trans, &info->init_transform);
537 if (!SetWorldTransform(hdc, &final_trans))
539 ERR("World transform failed!\n");
543 static void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
545 INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
546 INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
547 INT horzRes = GetDeviceCaps( hdc, HORZRES );
548 INT vertRes = GetDeviceCaps( hdc, VERTRES );
550 TRACE("%d\n",info->mode);
562 info->wndExtX = horzSize * 10;
563 info->wndExtY = vertSize * 10;
564 info->vportExtX = horzRes;
565 info->vportExtY = -vertRes;
568 info->wndExtX = horzSize * 100;
569 info->wndExtY = vertSize * 100;
570 info->vportExtX = horzRes;
571 info->vportExtY = -vertRes;
574 info->wndExtX = MulDiv(1000, horzSize, 254);
575 info->wndExtY = MulDiv(1000, vertSize, 254);
576 info->vportExtX = horzRes;
577 info->vportExtY = -vertRes;
580 info->wndExtX = MulDiv(10000, horzSize, 254);
581 info->wndExtY = MulDiv(10000, vertSize, 254);
582 info->vportExtX = horzRes;
583 info->vportExtY = -vertRes;
586 info->wndExtX = MulDiv(14400, horzSize, 254);
587 info->wndExtY = MulDiv(14400, vertSize, 254);
588 info->vportExtX = horzRes;
589 info->vportExtY = -vertRes;
598 /***********************************************************************
601 * Fix viewport extensions for isotropic mode.
604 static void EMF_FixIsotropic(HDC hdc, enum_emh_data *info)
606 double xdim = fabs((double)info->vportExtX * GetDeviceCaps( hdc, HORZSIZE ) /
607 (GetDeviceCaps( hdc, HORZRES ) * info->wndExtX));
608 double ydim = fabs((double)info->vportExtY * GetDeviceCaps( hdc, VERTSIZE ) /
609 (GetDeviceCaps( hdc, VERTRES ) * info->wndExtY));
613 INT mincx = (info->vportExtX >= 0) ? 1 : -1;
614 info->vportExtX = floor(info->vportExtX * ydim / xdim + 0.5);
615 if (!info->vportExtX) info->vportExtX = mincx;
619 INT mincy = (info->vportExtY >= 0) ? 1 : -1;
620 info->vportExtY = floor(info->vportExtY * xdim / ydim + 0.5);
621 if (!info->vportExtY) info->vportExtY = mincy;
625 /*****************************************************************************
626 * emr_produces_output
628 * Returns TRUE if the record type writes something to the dc. Used by
629 * PlayEnhMetaFileRecord to determine whether it needs to update the
630 * dc's xform when in win9x mode.
632 * FIXME: need to test which records should be here.
634 static BOOL emr_produces_output(int type)
640 case EMR_POLYBEZIERTO:
642 case EMR_POLYPOLYLINE:
643 case EMR_POLYPOLYGON:
646 case EMR_EXCLUDECLIPRECT:
647 case EMR_INTERSECTCLIPRECT:
648 case EMR_SELECTOBJECT:
656 case EMR_EXTFLOODFILL:
668 case EMR_SETDIBITSTODEVICE:
669 case EMR_STRETCHDIBITS:
670 case EMR_EXTTEXTOUTA:
671 case EMR_EXTTEXTOUTW:
672 case EMR_POLYBEZIER16:
675 case EMR_POLYBEZIERTO16:
676 case EMR_POLYLINETO16:
677 case EMR_POLYPOLYLINE16:
678 case EMR_POLYPOLYGON16:
680 case EMR_POLYTEXTOUTA:
681 case EMR_POLYTEXTOUTW:
682 case EMR_SMALLTEXTOUT:
684 case EMR_TRANSPARENTBLT:
692 /*****************************************************************************
693 * PlayEnhMetaFileRecord (GDI32.@)
695 * Render a single enhanced metafile record in the device context hdc.
698 * TRUE (non zero) on success, FALSE on error.
700 * Many unimplemented records.
701 * No error handling on record play failures (ie checking return codes)
704 * WinNT actually updates the current world transform in this function
705 * whereas Win9x does not.
707 BOOL WINAPI PlayEnhMetaFileRecord(
708 HDC hdc, /* [in] device context in which to render EMF record */
709 LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
710 const ENHMETARECORD *mr, /* [in] EMF record to render */
711 UINT handles /* [in] size of handle array */
716 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
718 TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
719 hdc, handletable, mr, handles);
720 if (!mr) return FALSE;
724 /* In Win9x mode we update the xform if the record will produce output */
725 if ( IS_WIN9X() && emr_produces_output(type) )
726 EMF_Update_MF_Xform(hdc, info);
728 TRACE("record %s\n", get_emr_name(type));
737 PEMRGDICOMMENT lpGdiComment = (PEMRGDICOMMENT)mr;
738 /* In an enhanced metafile, there can be both public and private GDI comments */
739 GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
744 PEMRSETMAPMODE pSetMapMode = (PEMRSETMAPMODE) mr;
746 if(info->mode == pSetMapMode->iMode && (info->mode == MM_ISOTROPIC || info->mode == MM_ANISOTROPIC))
748 info->mode = pSetMapMode->iMode;
749 EMF_SetMapMode(hdc, info);
754 PEMRSETBKMODE pSetBkMode = (PEMRSETBKMODE) mr;
755 SetBkMode(hdc, pSetBkMode->iMode);
760 PEMRSETBKCOLOR pSetBkColor = (PEMRSETBKCOLOR) mr;
761 SetBkColor(hdc, pSetBkColor->crColor);
764 case EMR_SETPOLYFILLMODE:
766 PEMRSETPOLYFILLMODE pSetPolyFillMode = (PEMRSETPOLYFILLMODE) mr;
767 SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
772 PEMRSETROP2 pSetROP2 = (PEMRSETROP2) mr;
773 SetROP2(hdc, pSetROP2->iMode);
776 case EMR_SETSTRETCHBLTMODE:
778 PEMRSETSTRETCHBLTMODE pSetStretchBltMode = (PEMRSETSTRETCHBLTMODE) mr;
779 SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
782 case EMR_SETTEXTALIGN:
784 PEMRSETTEXTALIGN pSetTextAlign = (PEMRSETTEXTALIGN) mr;
785 SetTextAlign(hdc, pSetTextAlign->iMode);
788 case EMR_SETTEXTCOLOR:
790 PEMRSETTEXTCOLOR pSetTextColor = (PEMRSETTEXTCOLOR) mr;
791 SetTextColor(hdc, pSetTextColor->crColor);
801 PEMRRESTOREDC pRestoreDC = (PEMRRESTOREDC) mr;
802 TRACE("EMR_RESTORE: %ld\n", pRestoreDC->iRelative);
803 RestoreDC(hdc, pRestoreDC->iRelative);
806 case EMR_INTERSECTCLIPRECT:
808 PEMRINTERSECTCLIPRECT pClipRect = (PEMRINTERSECTCLIPRECT) mr;
809 TRACE("EMR_INTERSECTCLIPRECT: rect %ld,%ld - %ld, %ld\n",
810 pClipRect->rclClip.left, pClipRect->rclClip.top,
811 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
812 IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
813 pClipRect->rclClip.right, pClipRect->rclClip.bottom);
816 case EMR_SELECTOBJECT:
818 PEMRSELECTOBJECT pSelectObject = (PEMRSELECTOBJECT) mr;
819 if( pSelectObject->ihObject & 0x80000000 ) {
820 /* High order bit is set - it's a stock object
821 * Strip the high bit to get the index.
822 * See MSDN article Q142319
824 SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
827 /* High order bit wasn't set - not a stock object
830 (handletable->objectHandle)[pSelectObject->ihObject] );
834 case EMR_DELETEOBJECT:
836 PEMRDELETEOBJECT pDeleteObject = (PEMRDELETEOBJECT) mr;
837 DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
838 (handletable->objectHandle)[pDeleteObject->ihObject] = 0;
841 case EMR_SETWINDOWORGEX:
843 PEMRSETWINDOWORGEX pSetWindowOrgEx = (PEMRSETWINDOWORGEX) mr;
845 info->wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
846 info->wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
848 TRACE("SetWindowOrgEx: %d,%d\n",info->wndOrgX,info->wndOrgY);
851 case EMR_SETWINDOWEXTEX:
853 PEMRSETWINDOWEXTEX pSetWindowExtEx = (PEMRSETWINDOWEXTEX) mr;
855 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
857 info->wndExtX = pSetWindowExtEx->szlExtent.cx;
858 info->wndExtY = pSetWindowExtEx->szlExtent.cy;
859 if (info->mode == MM_ISOTROPIC)
860 EMF_FixIsotropic(hdc, info);
862 TRACE("SetWindowExtEx: %d,%d\n",info->wndExtX,info->wndExtY);
865 case EMR_SETVIEWPORTORGEX:
867 PEMRSETVIEWPORTORGEX pSetViewportOrgEx = (PEMRSETVIEWPORTORGEX) mr;
868 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
870 info->vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
871 info->vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
872 TRACE("SetViewportOrgEx: %d,%d\n",info->vportOrgX,info->vportOrgY);
875 case EMR_SETVIEWPORTEXTEX:
877 PEMRSETVIEWPORTEXTEX pSetViewportExtEx = (PEMRSETVIEWPORTEXTEX) mr;
878 enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
880 if(info->mode != MM_ISOTROPIC && info->mode != MM_ANISOTROPIC)
882 info->vportExtX = pSetViewportExtEx->szlExtent.cx;
883 info->vportExtY = pSetViewportExtEx->szlExtent.cy;
884 if (info->mode == MM_ISOTROPIC)
885 EMF_FixIsotropic(hdc, info);
886 TRACE("SetViewportExtEx: %d,%d\n",info->vportExtX,info->vportExtY);
891 PEMRCREATEPEN pCreatePen = (PEMRCREATEPEN) mr;
892 (handletable->objectHandle)[pCreatePen->ihPen] =
893 CreatePenIndirect(&pCreatePen->lopn);
896 case EMR_EXTCREATEPEN:
898 PEMREXTCREATEPEN pPen = (PEMREXTCREATEPEN) mr;
900 lb.lbStyle = pPen->elp.elpBrushStyle;
901 lb.lbColor = pPen->elp.elpColor;
902 lb.lbHatch = pPen->elp.elpHatch;
904 if(pPen->offBmi || pPen->offBits)
905 FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
907 (handletable->objectHandle)[pPen->ihPen] =
908 ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
909 pPen->elp.elpNumEntries, pPen->elp.elpStyleEntry);
912 case EMR_CREATEBRUSHINDIRECT:
914 PEMRCREATEBRUSHINDIRECT pBrush = (PEMRCREATEBRUSHINDIRECT) mr;
916 brush.lbStyle = pBrush->lb.lbStyle;
917 brush.lbColor = pBrush->lb.lbColor;
918 brush.lbHatch = pBrush->lb.lbHatch;
919 (handletable->objectHandle)[pBrush->ihBrush] = CreateBrushIndirect(&brush);
922 case EMR_EXTCREATEFONTINDIRECTW:
924 PEMREXTCREATEFONTINDIRECTW pFont = (PEMREXTCREATEFONTINDIRECTW) mr;
925 (handletable->objectHandle)[pFont->ihFont] =
926 CreateFontIndirectW(&pFont->elfw.elfLogFont);
931 PEMRMOVETOEX pMoveToEx = (PEMRMOVETOEX) mr;
932 MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
937 PEMRLINETO pLineTo = (PEMRLINETO) mr;
938 LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
943 PEMRRECTANGLE pRect = (PEMRRECTANGLE) mr;
944 Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
945 pRect->rclBox.right, pRect->rclBox.bottom);
950 PEMRELLIPSE pEllipse = (PEMRELLIPSE) mr;
951 Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
952 pEllipse->rclBox.right, pEllipse->rclBox.bottom);
957 PEMRPOLYGON16 pPoly = (PEMRPOLYGON16) mr;
958 /* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
959 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
960 pPoly->cpts * sizeof(POINT) );
962 for(i = 0; i < pPoly->cpts; i++)
964 pts[i].x = pPoly->apts[i].x;
965 pts[i].y = pPoly->apts[i].y;
967 Polygon(hdc, pts, pPoly->cpts);
968 HeapFree( GetProcessHeap(), 0, pts );
973 PEMRPOLYLINE16 pPoly = (PEMRPOLYLINE16) mr;
974 /* Shouldn't use Polyline16 since pPoly->cpts is DWORD */
975 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
976 pPoly->cpts * sizeof(POINT) );
978 for(i = 0; i < pPoly->cpts; i++)
980 pts[i].x = pPoly->apts[i].x;
981 pts[i].y = pPoly->apts[i].y;
983 Polyline(hdc, pts, pPoly->cpts);
984 HeapFree( GetProcessHeap(), 0, pts );
987 case EMR_POLYLINETO16:
989 PEMRPOLYLINETO16 pPoly = (PEMRPOLYLINETO16) mr;
990 /* Shouldn't use PolylineTo16 since pPoly->cpts is DWORD */
991 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
992 pPoly->cpts * sizeof(POINT) );
994 for(i = 0; i < pPoly->cpts; i++)
996 pts[i].x = pPoly->apts[i].x;
997 pts[i].y = pPoly->apts[i].y;
999 PolylineTo(hdc, pts, pPoly->cpts);
1000 HeapFree( GetProcessHeap(), 0, pts );
1003 case EMR_POLYBEZIER16:
1005 PEMRPOLYBEZIER16 pPoly = (PEMRPOLYBEZIER16) mr;
1006 /* Shouldn't use PolyBezier16 since pPoly->cpts is DWORD */
1007 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1008 pPoly->cpts * sizeof(POINT) );
1010 for(i = 0; i < pPoly->cpts; i++)
1012 pts[i].x = pPoly->apts[i].x;
1013 pts[i].y = pPoly->apts[i].y;
1015 PolyBezier(hdc, pts, pPoly->cpts);
1016 HeapFree( GetProcessHeap(), 0, pts );
1019 case EMR_POLYBEZIERTO16:
1021 PEMRPOLYBEZIERTO16 pPoly = (PEMRPOLYBEZIERTO16) mr;
1022 /* Shouldn't use PolyBezierTo16 since pPoly->cpts is DWORD */
1023 POINT *pts = HeapAlloc( GetProcessHeap(), 0,
1024 pPoly->cpts * sizeof(POINT) );
1026 for(i = 0; i < pPoly->cpts; i++)
1028 pts[i].x = pPoly->apts[i].x;
1029 pts[i].y = pPoly->apts[i].y;
1031 PolyBezierTo(hdc, pts, pPoly->cpts);
1032 HeapFree( GetProcessHeap(), 0, pts );
1035 case EMR_POLYPOLYGON16:
1037 PEMRPOLYPOLYGON16 pPolyPoly = (PEMRPOLYPOLYGON16) mr;
1038 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1039 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1041 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1042 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1044 for(i = 0; i < pPolyPoly->cpts; i++)
1046 pts[i].x = pts16[i].x;
1047 pts[i].y = pts16[i].y;
1049 PolyPolygon(hdc, pts, (INT*)pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1050 HeapFree( GetProcessHeap(), 0, pts );
1053 case EMR_POLYPOLYLINE16:
1055 PEMRPOLYPOLYLINE16 pPolyPoly = (PEMRPOLYPOLYLINE16) mr;
1056 /* NB POINTS array doesn't start at pPolyPoly->apts it's actually
1057 pPolyPoly->aPolyCounts + pPolyPoly->nPolys */
1059 POINT16 *pts16 = (POINT16 *)(pPolyPoly->aPolyCounts + pPolyPoly->nPolys);
1060 POINT *pts = HeapAlloc( GetProcessHeap(), 0, pPolyPoly->cpts * sizeof(POINT) );
1062 for(i = 0; i < pPolyPoly->cpts; i++)
1064 pts[i].x = pts16[i].x;
1065 pts[i].y = pts16[i].y;
1067 PolyPolyline(hdc, pts, pPolyPoly->aPolyCounts, pPolyPoly->nPolys);
1068 HeapFree( GetProcessHeap(), 0, pts );
1072 case EMR_STRETCHDIBITS:
1074 EMRSTRETCHDIBITS *pStretchDIBits = (EMRSTRETCHDIBITS *)mr;
1077 pStretchDIBits->xDest,
1078 pStretchDIBits->yDest,
1079 pStretchDIBits->cxDest,
1080 pStretchDIBits->cyDest,
1081 pStretchDIBits->xSrc,
1082 pStretchDIBits->ySrc,
1083 pStretchDIBits->cxSrc,
1084 pStretchDIBits->cySrc,
1085 (BYTE *)mr + pStretchDIBits->offBitsSrc,
1086 (const BITMAPINFO *)((BYTE *)mr + pStretchDIBits->offBmiSrc),
1087 pStretchDIBits->iUsageSrc,
1088 pStretchDIBits->dwRop);
1092 case EMR_EXTTEXTOUTA:
1094 PEMREXTTEXTOUTA pExtTextOutA = (PEMREXTTEXTOUTA)mr;
1098 rc.left = pExtTextOutA->emrtext.rcl.left;
1099 rc.top = pExtTextOutA->emrtext.rcl.top;
1100 rc.right = pExtTextOutA->emrtext.rcl.right;
1101 rc.bottom = pExtTextOutA->emrtext.rcl.bottom;
1102 TRACE("EMR_EXTTEXTOUTA: x,y = %ld, %ld. rect = %ld, %ld - %ld, %ld. flags %08lx\n",
1103 pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1104 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutA->emrtext.fOptions);
1106 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1107 * These files can be enumerated and played under Win98 just
1108 * fine, but at least Win2k chokes on them.
1110 if (pExtTextOutA->emrtext.offDx)
1111 dx = (INT *)((BYTE *)mr + pExtTextOutA->emrtext.offDx);
1113 ExtTextOutA(hdc, pExtTextOutA->emrtext.ptlReference.x, pExtTextOutA->emrtext.ptlReference.y,
1114 pExtTextOutA->emrtext.fOptions, &rc,
1115 (LPSTR)((BYTE *)mr + pExtTextOutA->emrtext.offString), pExtTextOutA->emrtext.nChars,
1120 case EMR_EXTTEXTOUTW:
1122 PEMREXTTEXTOUTW pExtTextOutW = (PEMREXTTEXTOUTW)mr;
1126 rc.left = pExtTextOutW->emrtext.rcl.left;
1127 rc.top = pExtTextOutW->emrtext.rcl.top;
1128 rc.right = pExtTextOutW->emrtext.rcl.right;
1129 rc.bottom = pExtTextOutW->emrtext.rcl.bottom;
1130 TRACE("EMR_EXTTEXTOUTW: x,y = %ld, %ld. rect = %ld, %ld - %ld, %ld. flags %08lx\n",
1131 pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1132 rc.left, rc.top, rc.right, rc.bottom, pExtTextOutW->emrtext.fOptions);
1134 /* Linux version of pstoedit produces EMFs with offDx set to 0.
1135 * These files can be enumerated and played under Win98 just
1136 * fine, but at least Win2k chokes on them.
1138 if (pExtTextOutW->emrtext.offDx)
1139 dx = (INT *)((BYTE *)mr + pExtTextOutW->emrtext.offDx);
1141 ExtTextOutW(hdc, pExtTextOutW->emrtext.ptlReference.x, pExtTextOutW->emrtext.ptlReference.y,
1142 pExtTextOutW->emrtext.fOptions, &rc,
1143 (LPWSTR)((BYTE *)mr + pExtTextOutW->emrtext.offString), pExtTextOutW->emrtext.nChars,
1148 case EMR_CREATEPALETTE:
1150 PEMRCREATEPALETTE lpCreatePal = (PEMRCREATEPALETTE)mr;
1152 (handletable->objectHandle)[ lpCreatePal->ihPal ] =
1153 CreatePalette( &lpCreatePal->lgpl );
1158 case EMR_SELECTPALETTE:
1160 PEMRSELECTPALETTE lpSelectPal = (PEMRSELECTPALETTE)mr;
1162 if( lpSelectPal->ihPal & 0x80000000 ) {
1163 SelectPalette( hdc, GetStockObject(lpSelectPal->ihPal & 0x7fffffff), TRUE);
1165 (handletable->objectHandle)[ lpSelectPal->ihPal ] =
1166 SelectPalette( hdc, (handletable->objectHandle)[lpSelectPal->ihPal], TRUE);
1171 case EMR_REALIZEPALETTE:
1173 RealizePalette( hdc );
1177 case EMR_EXTSELECTCLIPRGN:
1180 PEMREXTSELECTCLIPRGN lpRgn = (PEMREXTSELECTCLIPRGN)mr;
1181 HRGN hRgn = ExtCreateRegion(NULL, lpRgn->cbRgnData, (RGNDATA *)lpRgn->RgnData);
1183 ExtSelectClipRgn(hdc, hRgn, (INT)(lpRgn->iMode));
1184 /* ExtSelectClipRgn created a copy of the region */
1187 FIXME("ExtSelectClipRgn\n");
1191 case EMR_SETMETARGN:
1197 case EMR_SETWORLDTRANSFORM:
1199 PEMRSETWORLDTRANSFORM lpXfrm = (PEMRSETWORLDTRANSFORM)mr;
1200 info->world_transform = lpXfrm->xform;
1204 case EMR_POLYBEZIER:
1206 PEMRPOLYBEZIER lpPolyBez = (PEMRPOLYBEZIER)mr;
1207 PolyBezier(hdc, (const POINT*)lpPolyBez->aptl, (UINT)lpPolyBez->cptl);
1213 PEMRPOLYGON lpPoly = (PEMRPOLYGON)mr;
1214 Polygon( hdc, (const POINT*)lpPoly->aptl, (UINT)lpPoly->cptl );
1220 PEMRPOLYLINE lpPolyLine = (PEMRPOLYLINE)mr;
1221 Polyline(hdc, (const POINT*)lpPolyLine->aptl, (UINT)lpPolyLine->cptl);
1225 case EMR_POLYBEZIERTO:
1227 PEMRPOLYBEZIERTO lpPolyBezierTo = (PEMRPOLYBEZIERTO)mr;
1228 PolyBezierTo( hdc, (const POINT*)lpPolyBezierTo->aptl,
1229 (UINT)lpPolyBezierTo->cptl );
1233 case EMR_POLYLINETO:
1235 PEMRPOLYLINETO lpPolyLineTo = (PEMRPOLYLINETO)mr;
1236 PolylineTo( hdc, (const POINT*)lpPolyLineTo->aptl,
1237 (UINT)lpPolyLineTo->cptl );
1241 case EMR_POLYPOLYLINE:
1243 PEMRPOLYPOLYLINE pPolyPolyline = (PEMRPOLYPOLYLINE) mr;
1244 /* NB Points at pPolyPolyline->aPolyCounts + pPolyPolyline->nPolys */
1246 PolyPolyline(hdc, (LPPOINT)(pPolyPolyline->aPolyCounts +
1247 pPolyPolyline->nPolys),
1248 pPolyPolyline->aPolyCounts,
1249 pPolyPolyline->nPolys );
1254 case EMR_POLYPOLYGON:
1256 PEMRPOLYPOLYGON pPolyPolygon = (PEMRPOLYPOLYGON) mr;
1258 /* NB Points at pPolyPolygon->aPolyCounts + pPolyPolygon->nPolys */
1260 PolyPolygon(hdc, (LPPOINT)(pPolyPolygon->aPolyCounts +
1261 pPolyPolygon->nPolys),
1262 (INT*)pPolyPolygon->aPolyCounts, pPolyPolygon->nPolys );
1266 case EMR_SETBRUSHORGEX:
1268 PEMRSETBRUSHORGEX lpSetBrushOrgEx = (PEMRSETBRUSHORGEX)mr;
1271 (INT)lpSetBrushOrgEx->ptlOrigin.x,
1272 (INT)lpSetBrushOrgEx->ptlOrigin.y,
1280 PEMRSETPIXELV lpSetPixelV = (PEMRSETPIXELV)mr;
1283 (INT)lpSetPixelV->ptlPixel.x,
1284 (INT)lpSetPixelV->ptlPixel.y,
1285 lpSetPixelV->crColor );
1290 case EMR_SETMAPPERFLAGS:
1292 PEMRSETMAPPERFLAGS lpSetMapperFlags = (PEMRSETMAPPERFLAGS)mr;
1294 SetMapperFlags( hdc, lpSetMapperFlags->dwFlags );
1299 case EMR_SETCOLORADJUSTMENT:
1301 PEMRSETCOLORADJUSTMENT lpSetColorAdjust = (PEMRSETCOLORADJUSTMENT)mr;
1303 SetColorAdjustment( hdc, &lpSetColorAdjust->ColorAdjustment );
1308 case EMR_OFFSETCLIPRGN:
1310 PEMROFFSETCLIPRGN lpOffsetClipRgn = (PEMROFFSETCLIPRGN)mr;
1313 (INT)lpOffsetClipRgn->ptlOffset.x,
1314 (INT)lpOffsetClipRgn->ptlOffset.y );
1315 FIXME("OffsetClipRgn\n");
1320 case EMR_EXCLUDECLIPRECT:
1322 PEMREXCLUDECLIPRECT lpExcludeClipRect = (PEMREXCLUDECLIPRECT)mr;
1324 ExcludeClipRect( hdc,
1325 lpExcludeClipRect->rclClip.left,
1326 lpExcludeClipRect->rclClip.top,
1327 lpExcludeClipRect->rclClip.right,
1328 lpExcludeClipRect->rclClip.bottom );
1329 FIXME("ExcludeClipRect\n");
1334 case EMR_SCALEVIEWPORTEXTEX:
1336 PEMRSCALEVIEWPORTEXTEX lpScaleViewportExtEx = (PEMRSCALEVIEWPORTEXTEX)mr;
1338 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1340 if (!lpScaleViewportExtEx->xNum || !lpScaleViewportExtEx->xDenom ||
1341 !lpScaleViewportExtEx->yNum || !lpScaleViewportExtEx->yDenom)
1343 info->vportExtX = (info->vportExtX * lpScaleViewportExtEx->xNum) /
1344 lpScaleViewportExtEx->xDenom;
1345 info->vportExtY = (info->vportExtY * lpScaleViewportExtEx->yNum) /
1346 lpScaleViewportExtEx->yDenom;
1347 if (info->vportExtX == 0) info->vportExtX = 1;
1348 if (info->vportExtY == 0) info->vportExtY = 1;
1349 if (info->mode == MM_ISOTROPIC)
1350 EMF_FixIsotropic(hdc, info);
1352 TRACE("EMRSCALEVIEWPORTEXTEX %ld/%ld %ld/%ld\n",
1353 lpScaleViewportExtEx->xNum,lpScaleViewportExtEx->xDenom,
1354 lpScaleViewportExtEx->yNum,lpScaleViewportExtEx->yDenom);
1359 case EMR_SCALEWINDOWEXTEX:
1361 PEMRSCALEWINDOWEXTEX lpScaleWindowExtEx = (PEMRSCALEWINDOWEXTEX)mr;
1363 if ((info->mode != MM_ISOTROPIC) && (info->mode != MM_ANISOTROPIC))
1365 if (!lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->xDenom ||
1366 !lpScaleWindowExtEx->xNum || !lpScaleWindowExtEx->yDenom)
1368 info->wndExtX = (info->wndExtX * lpScaleWindowExtEx->xNum) /
1369 lpScaleWindowExtEx->xDenom;
1370 info->wndExtY = (info->wndExtY * lpScaleWindowExtEx->yNum) /
1371 lpScaleWindowExtEx->yDenom;
1372 if (info->wndExtX == 0) info->wndExtX = 1;
1373 if (info->wndExtY == 0) info->wndExtY = 1;
1374 if (info->mode == MM_ISOTROPIC)
1375 EMF_FixIsotropic(hdc, info);
1377 TRACE("EMRSCALEWINDOWEXTEX %ld/%ld %ld/%ld\n",
1378 lpScaleWindowExtEx->xNum,lpScaleWindowExtEx->xDenom,
1379 lpScaleWindowExtEx->yNum,lpScaleWindowExtEx->yDenom);
1384 case EMR_MODIFYWORLDTRANSFORM:
1386 PEMRMODIFYWORLDTRANSFORM lpModifyWorldTrans = (PEMRMODIFYWORLDTRANSFORM)mr;
1388 switch(lpModifyWorldTrans->iMode) {
1390 info->world_transform.eM11 = info->world_transform.eM22 = 1;
1391 info->world_transform.eM12 = info->world_transform.eM21 = 0;
1392 info->world_transform.eDx = info->world_transform.eDy = 0;
1394 case MWT_LEFTMULTIPLY:
1395 CombineTransform(&info->world_transform, &lpModifyWorldTrans->xform,
1396 &info->world_transform);
1398 case MWT_RIGHTMULTIPLY:
1399 CombineTransform(&info->world_transform, &info->world_transform,
1400 &lpModifyWorldTrans->xform);
1403 FIXME("Unknown imode %ld\n", lpModifyWorldTrans->iMode);
1411 PEMRANGLEARC lpAngleArc = (PEMRANGLEARC)mr;
1414 (INT)lpAngleArc->ptlCenter.x, (INT)lpAngleArc->ptlCenter.y,
1415 lpAngleArc->nRadius, lpAngleArc->eStartAngle,
1416 lpAngleArc->eSweepAngle );
1423 PEMRROUNDRECT lpRoundRect = (PEMRROUNDRECT)mr;
1426 lpRoundRect->rclBox.left,
1427 lpRoundRect->rclBox.top,
1428 lpRoundRect->rclBox.right,
1429 lpRoundRect->rclBox.bottom,
1430 lpRoundRect->szlCorner.cx,
1431 lpRoundRect->szlCorner.cy );
1438 PEMRARC lpArc = (PEMRARC)mr;
1441 (INT)lpArc->rclBox.left,
1442 (INT)lpArc->rclBox.top,
1443 (INT)lpArc->rclBox.right,
1444 (INT)lpArc->rclBox.bottom,
1445 (INT)lpArc->ptlStart.x,
1446 (INT)lpArc->ptlStart.y,
1447 (INT)lpArc->ptlEnd.x,
1448 (INT)lpArc->ptlEnd.y );
1455 PEMRCHORD lpChord = (PEMRCHORD)mr;
1458 (INT)lpChord->rclBox.left,
1459 (INT)lpChord->rclBox.top,
1460 (INT)lpChord->rclBox.right,
1461 (INT)lpChord->rclBox.bottom,
1462 (INT)lpChord->ptlStart.x,
1463 (INT)lpChord->ptlStart.y,
1464 (INT)lpChord->ptlEnd.x,
1465 (INT)lpChord->ptlEnd.y );
1472 PEMRPIE lpPie = (PEMRPIE)mr;
1475 (INT)lpPie->rclBox.left,
1476 (INT)lpPie->rclBox.top,
1477 (INT)lpPie->rclBox.right,
1478 (INT)lpPie->rclBox.bottom,
1479 (INT)lpPie->ptlStart.x,
1480 (INT)lpPie->ptlStart.y,
1481 (INT)lpPie->ptlEnd.x,
1482 (INT)lpPie->ptlEnd.y );
1489 PEMRARC lpArcTo = (PEMRARC)mr;
1492 (INT)lpArcTo->rclBox.left,
1493 (INT)lpArcTo->rclBox.top,
1494 (INT)lpArcTo->rclBox.right,
1495 (INT)lpArcTo->rclBox.bottom,
1496 (INT)lpArcTo->ptlStart.x,
1497 (INT)lpArcTo->ptlStart.y,
1498 (INT)lpArcTo->ptlEnd.x,
1499 (INT)lpArcTo->ptlEnd.y );
1504 case EMR_EXTFLOODFILL:
1506 PEMREXTFLOODFILL lpExtFloodFill = (PEMREXTFLOODFILL)mr;
1509 (INT)lpExtFloodFill->ptlStart.x,
1510 (INT)lpExtFloodFill->ptlStart.y,
1511 lpExtFloodFill->crColor,
1512 (UINT)lpExtFloodFill->iMode );
1519 PEMRPOLYDRAW lpPolyDraw = (PEMRPOLYDRAW)mr;
1521 (const POINT*)lpPolyDraw->aptl,
1522 lpPolyDraw->abTypes,
1523 (INT)lpPolyDraw->cptl );
1528 case EMR_SETARCDIRECTION:
1530 PEMRSETARCDIRECTION lpSetArcDirection = (PEMRSETARCDIRECTION)mr;
1531 SetArcDirection( hdc, (INT)lpSetArcDirection->iArcDirection );
1535 case EMR_SETMITERLIMIT:
1537 PEMRSETMITERLIMIT lpSetMiterLimit = (PEMRSETMITERLIMIT)mr;
1538 SetMiterLimit( hdc, lpSetMiterLimit->eMiterLimit, NULL );
1554 case EMR_CLOSEFIGURE:
1562 /*PEMRFILLPATH lpFillPath = (PEMRFILLPATH)mr;*/
1567 case EMR_STROKEANDFILLPATH:
1569 /*PEMRSTROKEANDFILLPATH lpStrokeAndFillPath = (PEMRSTROKEANDFILLPATH)mr;*/
1570 StrokeAndFillPath( hdc );
1574 case EMR_STROKEPATH:
1576 /*PEMRSTROKEPATH lpStrokePath = (PEMRSTROKEPATH)mr;*/
1581 case EMR_FLATTENPATH:
1593 case EMR_SELECTCLIPPATH:
1595 PEMRSELECTCLIPPATH lpSelectClipPath = (PEMRSELECTCLIPPATH)mr;
1596 SelectClipPath( hdc, (INT)lpSelectClipPath->iMode );
1606 case EMR_CREATECOLORSPACE:
1608 PEMRCREATECOLORSPACE lpCreateColorSpace = (PEMRCREATECOLORSPACE)mr;
1609 (handletable->objectHandle)[lpCreateColorSpace->ihCS] =
1610 CreateColorSpaceA( &lpCreateColorSpace->lcs );
1614 case EMR_SETCOLORSPACE:
1616 PEMRSETCOLORSPACE lpSetColorSpace = (PEMRSETCOLORSPACE)mr;
1618 (handletable->objectHandle)[lpSetColorSpace->ihCS] );
1622 case EMR_DELETECOLORSPACE:
1624 PEMRDELETECOLORSPACE lpDeleteColorSpace = (PEMRDELETECOLORSPACE)mr;
1625 DeleteColorSpace( (handletable->objectHandle)[lpDeleteColorSpace->ihCS] );
1629 case EMR_SETICMMODE:
1631 PEMRSETICMMODE lpSetICMMode = (PEMRSETICMMODE)mr;
1632 SetICMMode( hdc, (INT)lpSetICMMode->iMode );
1636 case EMR_PIXELFORMAT:
1639 PEMRPIXELFORMAT lpPixelFormat = (PEMRPIXELFORMAT)mr;
1641 iPixelFormat = ChoosePixelFormat( hdc, &lpPixelFormat->pfd );
1642 SetPixelFormat( hdc, iPixelFormat, &lpPixelFormat->pfd );
1647 case EMR_SETPALETTEENTRIES:
1649 PEMRSETPALETTEENTRIES lpSetPaletteEntries = (PEMRSETPALETTEENTRIES)mr;
1651 SetPaletteEntries( (handletable->objectHandle)[lpSetPaletteEntries->ihPal],
1652 (UINT)lpSetPaletteEntries->iStart,
1653 (UINT)lpSetPaletteEntries->cEntries,
1654 lpSetPaletteEntries->aPalEntries );
1659 case EMR_RESIZEPALETTE:
1661 PEMRRESIZEPALETTE lpResizePalette = (PEMRRESIZEPALETTE)mr;
1663 ResizePalette( (handletable->objectHandle)[lpResizePalette->ihPal],
1664 (UINT)lpResizePalette->cEntries );
1669 case EMR_CREATEDIBPATTERNBRUSHPT:
1671 PEMRCREATEDIBPATTERNBRUSHPT lpCreate = (PEMRCREATEDIBPATTERNBRUSHPT)mr;
1672 LPVOID lpPackedStruct;
1674 /* check that offsets and data are contained within the record */
1675 if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
1676 (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
1677 ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
1678 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
1680 ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");
1684 /* This is a BITMAPINFO struct followed directly by bitmap bits */
1685 lpPackedStruct = HeapAlloc( GetProcessHeap(), 0,
1686 lpCreate->cbBmi + lpCreate->cbBits );
1689 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1693 /* Now pack this structure */
1694 memcpy( lpPackedStruct,
1695 ((BYTE*)lpCreate) + lpCreate->offBmi,
1697 memcpy( ((BYTE*)lpPackedStruct) + lpCreate->cbBmi,
1698 ((BYTE*)lpCreate) + lpCreate->offBits,
1701 (handletable->objectHandle)[lpCreate->ihBrush] =
1702 CreateDIBPatternBrushPt( lpPackedStruct,
1703 (UINT)lpCreate->iUsage );
1705 HeapFree(GetProcessHeap(), 0, lpPackedStruct);
1709 case EMR_CREATEMONOBRUSH:
1711 PEMRCREATEMONOBRUSH pCreateMonoBrush = (PEMRCREATEMONOBRUSH)mr;
1712 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pCreateMonoBrush->offBmi);
1715 /* Need to check if the bitmap is monochrome, and if the
1716 two colors are really black and white */
1717 if (pCreateMonoBrush->iUsage == DIB_PAL_MONO)
1721 /* Undocumented iUsage indicates a mono bitmap with no palette table,
1722 * aligned to 32 rather than 16 bits.
1725 bm.bmWidth = pbi->bmiHeader.biWidth;
1726 bm.bmHeight = abs(pbi->bmiHeader.biHeight);
1727 bm.bmWidthBytes = 4 * ((pbi->bmiHeader.biWidth + 31) / 32);
1728 bm.bmPlanes = pbi->bmiHeader.biPlanes;
1729 bm.bmBitsPixel = pbi->bmiHeader.biBitCount;
1730 bm.bmBits = (BYTE *)mr + pCreateMonoBrush->offBits;
1731 hBmp = CreateBitmapIndirect(&bm);
1733 else if (is_dib_monochrome(pbi))
1735 /* Top-down DIBs have a negative height */
1736 LONG height = pbi->bmiHeader.biHeight;
1738 hBmp = CreateBitmap(pbi->bmiHeader.biWidth, abs(height), 1, 1, NULL);
1739 SetDIBits(hdc, hBmp, 0, pbi->bmiHeader.biHeight,
1740 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1744 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1745 (BYTE *)mr + pCreateMonoBrush->offBits, pbi, pCreateMonoBrush->iUsage);
1748 (handletable->objectHandle)[pCreateMonoBrush->ihBrush] = CreatePatternBrush(hBmp);
1750 /* CreatePatternBrush created a copy of the bitmap */
1757 PEMRBITBLT pBitBlt = (PEMRBITBLT)mr;
1759 if(pBitBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1760 PatBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1762 } else { /* BitBlt */
1763 HDC hdcSrc = CreateCompatibleDC(hdc);
1764 HBRUSH hBrush, hBrushOld;
1765 HBITMAP hBmp = 0, hBmpOld = 0;
1766 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pBitBlt->offBmiSrc);
1768 SetWorldTransform(hdcSrc, &pBitBlt->xformSrc);
1770 hBrush = CreateSolidBrush(pBitBlt->crBkColorSrc);
1771 hBrushOld = SelectObject(hdcSrc, hBrush);
1772 PatBlt(hdcSrc, pBitBlt->rclBounds.left, pBitBlt->rclBounds.top,
1773 pBitBlt->rclBounds.right - pBitBlt->rclBounds.left,
1774 pBitBlt->rclBounds.bottom - pBitBlt->rclBounds.top, PATCOPY);
1775 SelectObject(hdcSrc, hBrushOld);
1776 DeleteObject(hBrush);
1778 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1779 (BYTE *)mr + pBitBlt->offBitsSrc, pbi, pBitBlt->iUsageSrc);
1780 hBmpOld = SelectObject(hdcSrc, hBmp);
1782 BitBlt(hdc, pBitBlt->xDest, pBitBlt->yDest, pBitBlt->cxDest, pBitBlt->cyDest,
1783 hdcSrc, pBitBlt->xSrc, pBitBlt->ySrc, pBitBlt->dwRop);
1785 SelectObject(hdcSrc, hBmpOld);
1792 case EMR_STRETCHBLT:
1794 PEMRSTRETCHBLT pStretchBlt= (PEMRSTRETCHBLT)mr;
1796 TRACE("EMR_STRETCHBLT: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. rop %08lx offBitsSrc %ld\n",
1797 pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1798 pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1799 pStretchBlt->dwRop, pStretchBlt->offBitsSrc);
1801 if(pStretchBlt->offBmiSrc == 0) { /* Record is a PatBlt */
1802 PatBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1803 pStretchBlt->dwRop);
1804 } else { /* StretchBlt */
1805 HDC hdcSrc = CreateCompatibleDC(hdc);
1806 HBRUSH hBrush, hBrushOld;
1807 HBITMAP hBmp = 0, hBmpOld = 0;
1808 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pStretchBlt->offBmiSrc);
1810 SetWorldTransform(hdcSrc, &pStretchBlt->xformSrc);
1812 hBrush = CreateSolidBrush(pStretchBlt->crBkColorSrc);
1813 hBrushOld = SelectObject(hdcSrc, hBrush);
1814 PatBlt(hdcSrc, pStretchBlt->rclBounds.left, pStretchBlt->rclBounds.top,
1815 pStretchBlt->rclBounds.right - pStretchBlt->rclBounds.left,
1816 pStretchBlt->rclBounds.bottom - pStretchBlt->rclBounds.top, PATCOPY);
1817 SelectObject(hdcSrc, hBrushOld);
1818 DeleteObject(hBrush);
1820 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1821 (BYTE *)mr + pStretchBlt->offBitsSrc, pbi, pStretchBlt->iUsageSrc);
1822 hBmpOld = SelectObject(hdcSrc, hBmp);
1824 StretchBlt(hdc, pStretchBlt->xDest, pStretchBlt->yDest, pStretchBlt->cxDest, pStretchBlt->cyDest,
1825 hdcSrc, pStretchBlt->xSrc, pStretchBlt->ySrc, pStretchBlt->cxSrc, pStretchBlt->cySrc,
1826 pStretchBlt->dwRop);
1828 SelectObject(hdcSrc, hBmpOld);
1835 case EMR_ALPHABLEND:
1837 PEMRALPHABLEND pAlphaBlend= (PEMRALPHABLEND)mr;
1839 TRACE("EMR_ALPHABLEND: %ld, %ld %ldx%ld -> %ld, %ld %ldx%ld. blendfn %08lx offBitsSrc %ld\n",
1840 pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1841 pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1842 pAlphaBlend->dwRop, pAlphaBlend->offBitsSrc);
1844 if(pAlphaBlend->offBmiSrc == 0) {
1845 FIXME("EMR_ALPHABLEND: offBmiSrc == 0\n");
1847 HDC hdcSrc = CreateCompatibleDC(hdc);
1848 HBITMAP hBmp = 0, hBmpOld = 0;
1849 BITMAPINFO *pbi = (BITMAPINFO *)((BYTE *)mr + pAlphaBlend->offBmiSrc);
1850 BLENDFUNCTION blendfn;
1853 SetWorldTransform(hdcSrc, &pAlphaBlend->xformSrc);
1855 hBmp = CreateDIBSection(hdc, pbi, pAlphaBlend->iUsageSrc, &bits, NULL, 0);
1856 memcpy(bits, (BYTE*)mr + pAlphaBlend->offBitsSrc, pAlphaBlend->cbBitsSrc);
1857 hBmpOld = SelectObject(hdcSrc, hBmp);
1859 blendfn.BlendOp = (pAlphaBlend->dwRop >> 24) & 0xff;
1860 blendfn.BlendFlags = (pAlphaBlend->dwRop >> 16) & 0xff;
1861 blendfn.SourceConstantAlpha = (pAlphaBlend->dwRop >> 8) & 0xff;
1862 blendfn.AlphaFormat = (pAlphaBlend->dwRop) & 0xff;
1864 GdiAlphaBlend(hdc, pAlphaBlend->xDest, pAlphaBlend->yDest, pAlphaBlend->cxDest, pAlphaBlend->cyDest,
1865 hdcSrc, pAlphaBlend->xSrc, pAlphaBlend->ySrc, pAlphaBlend->cxSrc, pAlphaBlend->cySrc,
1868 SelectObject(hdcSrc, hBmpOld);
1877 PEMRMASKBLT pMaskBlt= (PEMRMASKBLT)mr;
1878 HDC hdcSrc = CreateCompatibleDC(hdc);
1879 HBRUSH hBrush, hBrushOld;
1880 HBITMAP hBmp, hBmpOld, hBmpMask;
1883 SetWorldTransform(hdcSrc, &pMaskBlt->xformSrc);
1885 hBrush = CreateSolidBrush(pMaskBlt->crBkColorSrc);
1886 hBrushOld = SelectObject(hdcSrc, hBrush);
1887 PatBlt(hdcSrc, pMaskBlt->rclBounds.left, pMaskBlt->rclBounds.top,
1888 pMaskBlt->rclBounds.right - pMaskBlt->rclBounds.left,
1889 pMaskBlt->rclBounds.bottom - pMaskBlt->rclBounds.top, PATCOPY);
1890 SelectObject(hdcSrc, hBrushOld);
1891 DeleteObject(hBrush);
1893 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiMask);
1894 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1896 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1897 (BYTE *)mr + pMaskBlt->offBitsMask, pbi, pMaskBlt->iUsageMask);
1899 pbi = (BITMAPINFO *)((BYTE *)mr + pMaskBlt->offBmiSrc);
1900 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1901 (BYTE *)mr + pMaskBlt->offBitsSrc, pbi, pMaskBlt->iUsageSrc);
1902 hBmpOld = SelectObject(hdcSrc, hBmp);
1915 SelectObject(hdcSrc, hBmpOld);
1917 DeleteObject(hBmpMask);
1924 PEMRPLGBLT pPlgBlt= (PEMRPLGBLT)mr;
1925 HDC hdcSrc = CreateCompatibleDC(hdc);
1926 HBRUSH hBrush, hBrushOld;
1927 HBITMAP hBmp, hBmpOld, hBmpMask;
1931 SetWorldTransform(hdcSrc, &pPlgBlt->xformSrc);
1933 pts[0].x = pPlgBlt->aptlDest[0].x; pts[0].y = pPlgBlt->aptlDest[0].y;
1934 pts[1].x = pPlgBlt->aptlDest[1].x; pts[1].y = pPlgBlt->aptlDest[1].y;
1935 pts[2].x = pPlgBlt->aptlDest[2].x; pts[2].y = pPlgBlt->aptlDest[2].y;
1937 hBrush = CreateSolidBrush(pPlgBlt->crBkColorSrc);
1938 hBrushOld = SelectObject(hdcSrc, hBrush);
1939 PatBlt(hdcSrc, pPlgBlt->rclBounds.left, pPlgBlt->rclBounds.top,
1940 pPlgBlt->rclBounds.right - pPlgBlt->rclBounds.left,
1941 pPlgBlt->rclBounds.bottom - pPlgBlt->rclBounds.top, PATCOPY);
1942 SelectObject(hdcSrc, hBrushOld);
1943 DeleteObject(hBrush);
1945 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiMask);
1946 hBmpMask = CreateBitmap(pbi->bmiHeader.biWidth, pbi->bmiHeader.biHeight,
1948 SetDIBits(hdc, hBmpMask, 0, pbi->bmiHeader.biHeight,
1949 (BYTE *)mr + pPlgBlt->offBitsMask, pbi, pPlgBlt->iUsageMask);
1951 pbi = (BITMAPINFO *)((BYTE *)mr + pPlgBlt->offBmiSrc);
1952 hBmp = CreateDIBitmap(hdc, (BITMAPINFOHEADER *)pbi, CBM_INIT,
1953 (BYTE *)mr + pPlgBlt->offBitsSrc, pbi, pPlgBlt->iUsageSrc);
1954 hBmpOld = SelectObject(hdcSrc, hBmp);
1965 SelectObject(hdcSrc, hBmpOld);
1967 DeleteObject(hBmpMask);
1972 case EMR_SETDIBITSTODEVICE:
1974 PEMRSETDIBITSTODEVICE pSetDIBitsToDevice = (PEMRSETDIBITSTODEVICE)mr;
1976 SetDIBitsToDevice(hdc,
1977 pSetDIBitsToDevice->xDest,
1978 pSetDIBitsToDevice->yDest,
1979 pSetDIBitsToDevice->cxSrc,
1980 pSetDIBitsToDevice->cySrc,
1981 pSetDIBitsToDevice->xSrc,
1982 pSetDIBitsToDevice->ySrc,
1983 pSetDIBitsToDevice->iStartScan,
1984 pSetDIBitsToDevice->cScans,
1985 (BYTE *)mr + pSetDIBitsToDevice->offBitsSrc,
1986 (BITMAPINFO *)((BYTE *)mr + pSetDIBitsToDevice->offBmiSrc),
1987 pSetDIBitsToDevice->iUsageSrc);
1991 case EMR_POLYTEXTOUTA:
1993 PEMRPOLYTEXTOUTA pPolyTextOutA = (PEMRPOLYTEXTOUTA)mr;
1994 POLYTEXTA *polytextA = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutA->cStrings * sizeof(POLYTEXTA));
1996 XFORM xform, xformOld;
1999 gModeOld = SetGraphicsMode(hdc, pPolyTextOutA->iGraphicsMode);
2000 GetWorldTransform(hdc, &xformOld);
2002 xform.eM11 = pPolyTextOutA->exScale;
2005 xform.eM22 = pPolyTextOutA->eyScale;
2008 SetWorldTransform(hdc, &xform);
2010 /* Set up POLYTEXTA structures */
2011 for(i = 0; i < pPolyTextOutA->cStrings; i++)
2013 polytextA[i].x = pPolyTextOutA->aemrtext[i].ptlReference.x;
2014 polytextA[i].y = pPolyTextOutA->aemrtext[i].ptlReference.y;
2015 polytextA[i].n = pPolyTextOutA->aemrtext[i].nChars;
2016 polytextA[i].lpstr = (LPSTR)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offString);
2017 polytextA[i].uiFlags = pPolyTextOutA->aemrtext[i].fOptions;
2018 polytextA[i].rcl.left = pPolyTextOutA->aemrtext[i].rcl.left;
2019 polytextA[i].rcl.right = pPolyTextOutA->aemrtext[i].rcl.right;
2020 polytextA[i].rcl.top = pPolyTextOutA->aemrtext[i].rcl.top;
2021 polytextA[i].rcl.bottom = pPolyTextOutA->aemrtext[i].rcl.bottom;
2022 polytextA[i].pdx = (int *)((BYTE *)mr + pPolyTextOutA->aemrtext[i].offDx);
2024 PolyTextOutA(hdc, polytextA, pPolyTextOutA->cStrings);
2025 HeapFree(GetProcessHeap(), 0, polytextA);
2027 SetWorldTransform(hdc, &xformOld);
2028 SetGraphicsMode(hdc, gModeOld);
2032 case EMR_POLYTEXTOUTW:
2034 PEMRPOLYTEXTOUTW pPolyTextOutW = (PEMRPOLYTEXTOUTW)mr;
2035 POLYTEXTW *polytextW = HeapAlloc(GetProcessHeap(), 0, pPolyTextOutW->cStrings * sizeof(POLYTEXTW));
2037 XFORM xform, xformOld;
2040 gModeOld = SetGraphicsMode(hdc, pPolyTextOutW->iGraphicsMode);
2041 GetWorldTransform(hdc, &xformOld);
2043 xform.eM11 = pPolyTextOutW->exScale;
2046 xform.eM22 = pPolyTextOutW->eyScale;
2049 SetWorldTransform(hdc, &xform);
2051 /* Set up POLYTEXTW structures */
2052 for(i = 0; i < pPolyTextOutW->cStrings; i++)
2054 polytextW[i].x = pPolyTextOutW->aemrtext[i].ptlReference.x;
2055 polytextW[i].y = pPolyTextOutW->aemrtext[i].ptlReference.y;
2056 polytextW[i].n = pPolyTextOutW->aemrtext[i].nChars;
2057 polytextW[i].lpstr = (LPWSTR)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offString);
2058 polytextW[i].uiFlags = pPolyTextOutW->aemrtext[i].fOptions;
2059 polytextW[i].rcl.left = pPolyTextOutW->aemrtext[i].rcl.left;
2060 polytextW[i].rcl.right = pPolyTextOutW->aemrtext[i].rcl.right;
2061 polytextW[i].rcl.top = pPolyTextOutW->aemrtext[i].rcl.top;
2062 polytextW[i].rcl.bottom = pPolyTextOutW->aemrtext[i].rcl.bottom;
2063 polytextW[i].pdx = (int *)((BYTE *)mr + pPolyTextOutW->aemrtext[i].offDx);
2065 PolyTextOutW(hdc, polytextW, pPolyTextOutW->cStrings);
2066 HeapFree(GetProcessHeap(), 0, polytextW);
2068 SetWorldTransform(hdc, &xformOld);
2069 SetGraphicsMode(hdc, gModeOld);
2075 PEMRFILLRGN pFillRgn = (PEMRFILLRGN)mr;
2076 HRGN hRgn = ExtCreateRegion(NULL, pFillRgn->cbRgnData, (RGNDATA *)pFillRgn->RgnData);
2079 (handletable->objectHandle)[pFillRgn->ihBrush]);
2086 PEMRFRAMERGN pFrameRgn = (PEMRFRAMERGN)mr;
2087 HRGN hRgn = ExtCreateRegion(NULL, pFrameRgn->cbRgnData, (RGNDATA *)pFrameRgn->RgnData);
2090 (handletable->objectHandle)[pFrameRgn->ihBrush],
2091 pFrameRgn->szlStroke.cx,
2092 pFrameRgn->szlStroke.cy);
2099 PEMRINVERTRGN pInvertRgn = (PEMRINVERTRGN)mr;
2100 HRGN hRgn = ExtCreateRegion(NULL, pInvertRgn->cbRgnData, (RGNDATA *)pInvertRgn->RgnData);
2101 InvertRgn(hdc, hRgn);
2108 PEMRPAINTRGN pPaintRgn = (PEMRPAINTRGN)mr;
2109 HRGN hRgn = ExtCreateRegion(NULL, pPaintRgn->cbRgnData, (RGNDATA *)pPaintRgn->RgnData);
2110 PaintRgn(hdc, hRgn);
2115 case EMR_SETTEXTJUSTIFICATION:
2117 PEMRSETTEXTJUSTIFICATION pSetTextJust = (PEMRSETTEXTJUSTIFICATION)mr;
2118 SetTextJustification(hdc, pSetTextJust->nBreakExtra, pSetTextJust->nBreakCount);
2124 PEMRSETLAYOUT pSetLayout = (PEMRSETLAYOUT)mr;
2125 SetLayout(hdc, pSetLayout->iMode);
2129 case EMR_POLYDRAW16:
2131 case EMR_GLSBOUNDEDRECORD:
2132 case EMR_DRAWESCAPE :
2135 case EMR_SMALLTEXTOUT:
2136 case EMR_FORCEUFIMAPPING:
2137 case EMR_NAMEDESCAPE:
2138 case EMR_COLORCORRECTPALETTE:
2139 case EMR_SETICMPROFILEA:
2140 case EMR_SETICMPROFILEW:
2141 case EMR_TRANSPARENTBLT:
2142 case EMR_GRADIENTFILL:
2143 case EMR_SETLINKEDUFI:
2144 case EMR_COLORMATCHTOTARGETW:
2145 case EMR_CREATECOLORSPACEW:
2148 /* From docs: If PlayEnhMetaFileRecord doesn't recognize a
2149 record then ignore and return TRUE. */
2150 FIXME("type %d is unimplemented\n", type);
2153 tmprc.left = tmprc.top = 0;
2154 tmprc.right = tmprc.bottom = 1000;
2155 LPtoDP(hdc, (POINT*)&tmprc, 2);
2156 TRACE("L:0,0 - 1000,1000 -> D:%ld,%ld - %ld,%ld\n", tmprc.left,
2157 tmprc.top, tmprc.right, tmprc.bottom);
2161 /* WinNT - update the transform (win9x updates when the next graphics output
2162 record is played). */
2163 EMF_Update_MF_Xform(hdc, info);
2170 /*****************************************************************************
2172 * EnumEnhMetaFile (GDI32.@)
2174 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
2176 * record. Returns when either every record has been used or
2177 * when _EnhMetaFunc_ returns FALSE.
2181 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
2188 * This function behaves differently in Win9x and WinNT.
2190 * In WinNT, the DC's world transform is updated as the EMF changes
2191 * the Window/Viewport Extent and Origin or it's world transform.
2192 * The actual Window/Viewport Extent and Origin are left untouched.
2194 * In Win9x, the DC is left untouched, and PlayEnhMetaFileRecord
2195 * updates the scaling itself but only just before a record that
2196 * writes anything to the DC.
2198 * I'm not sure where the data (enum_emh_data) is stored in either
2199 * version. For this implementation, it is stored before the handle
2200 * table, but it could be stored in the DC, in the EMF handle or in
2204 BOOL WINAPI EnumEnhMetaFile(
2205 HDC hdc, /* [in] device context to pass to _EnhMetaFunc_ */
2206 HENHMETAFILE hmf, /* [in] EMF to walk */
2207 ENHMFENUMPROC callback, /* [in] callback function */
2208 LPVOID data, /* [in] optional data for callback function */
2209 const RECT *lpRect /* [in] bounding rectangle for rendered metafile */
2221 HBRUSH hBrush = NULL;
2223 enum_emh_data *info;
2224 SIZE vp_size, win_size;
2225 POINT vp_org, win_org;
2226 INT mapMode = MM_TEXT, old_align = 0, old_rop2 = 0, old_arcdir = 0, old_polyfill = 0, old_stretchblt = 0;
2227 COLORREF old_text_color = 0, old_bk_color = 0;
2231 SetLastError(ERROR_INVALID_PARAMETER);
2235 emh = EMF_GetEnhMetaHeader(hmf);
2237 SetLastError(ERROR_INVALID_HANDLE);
2241 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2242 sizeof (enum_emh_data) + sizeof(HANDLETABLE) * emh->nHandles );
2245 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2252 info->vportOrgX = 0;
2253 info->vportOrgY = 0;
2254 info->vportExtX = 1;
2255 info->vportExtY = 1;
2256 info->world_transform.eM11 = info->world_transform.eM22 = 1;
2257 info->world_transform.eM12 = info->world_transform.eM21 = 0;
2258 info->world_transform.eDx = info->world_transform.eDy = 0;
2260 ht = (HANDLETABLE*) &info[1];
2261 ht->objectHandle[0] = hmf;
2265 savedMode = SetGraphicsMode(hdc, GM_ADVANCED);
2266 GetWorldTransform(hdc, &savedXform);
2267 GetViewportExtEx(hdc, &vp_size);
2268 GetWindowExtEx(hdc, &win_size);
2269 GetViewportOrgEx(hdc, &vp_org);
2270 GetWindowOrgEx(hdc, &win_org);
2271 mapMode = GetMapMode(hdc);
2273 /* save the current pen, brush and font */
2274 hPen = GetCurrentObject(hdc, OBJ_PEN);
2275 hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
2276 hFont = GetCurrentObject(hdc, OBJ_FONT);
2278 old_text_color = SetTextColor(hdc, RGB(0,0,0));
2279 old_bk_color = SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
2280 old_align = SetTextAlign(hdc, 0);
2281 old_rop2 = SetROP2(hdc, R2_COPYPEN);
2282 old_arcdir = SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
2283 old_polyfill = SetPolyFillMode(hdc, ALTERNATE);
2284 old_stretchblt = SetStretchBltMode(hdc, BLACKONWHITE);
2287 info->mode = MM_TEXT;
2291 /* Win95 leaves the vp/win ext/org info alone */
2292 info->init_transform.eM11 = 1.0;
2293 info->init_transform.eM12 = 0.0;
2294 info->init_transform.eM21 = 0.0;
2295 info->init_transform.eM22 = 1.0;
2296 info->init_transform.eDx = 0.0;
2297 info->init_transform.eDy = 0.0;
2301 /* WinNT combines the vp/win ext/org info into a transform */
2302 FLOAT xscale, yscale;
2303 xscale = (FLOAT)vp_size.cx / (FLOAT)win_size.cx;
2304 yscale = (FLOAT)vp_size.cy / (FLOAT)win_size.cy;
2305 info->init_transform.eM11 = xscale;
2306 info->init_transform.eM12 = 0.0;
2307 info->init_transform.eM21 = 0.0;
2308 info->init_transform.eM22 = yscale;
2309 info->init_transform.eDx = (FLOAT)vp_org.x - xscale * (FLOAT)win_org.x;
2310 info->init_transform.eDy = (FLOAT)vp_org.y - yscale * (FLOAT)win_org.y;
2312 CombineTransform(&info->init_transform, &savedXform, &info->init_transform);
2315 if ( lpRect && WIDTH(emh->rclFrame) && HEIGHT(emh->rclFrame) )
2317 FLOAT xSrcPixSize, ySrcPixSize, xscale, yscale;
2320 TRACE("rect: %ld,%ld - %ld,%ld. rclFrame: %ld,%ld - %ld,%ld\n",
2321 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom,
2322 emh->rclFrame.left, emh->rclFrame.top, emh->rclFrame.right,
2323 emh->rclFrame.bottom);
2325 xSrcPixSize = (FLOAT) emh->szlMillimeters.cx / emh->szlDevice.cx;
2326 ySrcPixSize = (FLOAT) emh->szlMillimeters.cy / emh->szlDevice.cy;
2327 xscale = (FLOAT) WIDTH(*lpRect) * 100.0 /
2328 WIDTH(emh->rclFrame) * xSrcPixSize;
2329 yscale = (FLOAT) HEIGHT(*lpRect) * 100.0 /
2330 HEIGHT(emh->rclFrame) * ySrcPixSize;
2331 TRACE("xscale = %f, yscale = %f\n", xscale, yscale);
2333 xform.eM11 = xscale;
2336 xform.eM22 = yscale;
2337 xform.eDx = (FLOAT) lpRect->left - (FLOAT) WIDTH(*lpRect) / WIDTH(emh->rclFrame) * emh->rclFrame.left;
2338 xform.eDy = (FLOAT) lpRect->top - (FLOAT) HEIGHT(*lpRect) / HEIGHT(emh->rclFrame) * emh->rclFrame.top;
2340 CombineTransform(&info->init_transform, &xform, &info->init_transform);
2343 /* WinNT resets the current vp/win org/ext */
2344 if ( !IS_WIN9X() && hdc )
2346 SetMapMode(hdc, MM_TEXT);
2347 SetWindowOrgEx(hdc, 0, 0, NULL);
2348 SetViewportOrgEx(hdc, 0, 0, NULL);
2349 EMF_Update_MF_Xform(hdc, info);
2354 while(ret && offset < emh->nBytes)
2356 emr = (ENHMETARECORD *)((char *)emh + offset);
2357 TRACE("Calling EnumFunc with record %s, size %ld\n", get_emr_name(emr->iType), emr->nSize);
2358 ret = (*callback)(hdc, ht, emr, emh->nHandles, (LPARAM)data);
2359 offset += emr->nSize;
2364 SetStretchBltMode(hdc, old_stretchblt);
2365 SetPolyFillMode(hdc, old_polyfill);
2366 SetArcDirection(hdc, old_arcdir);
2367 SetROP2(hdc, old_rop2);
2368 SetTextAlign(hdc, old_align);
2369 SetBkColor(hdc, old_bk_color);
2370 SetTextColor(hdc, old_text_color);
2372 /* restore pen, brush and font */
2373 SelectObject(hdc, hBrush);
2374 SelectObject(hdc, hPen);
2375 SelectObject(hdc, hFont);
2377 SetWorldTransform(hdc, &savedXform);
2379 SetGraphicsMode(hdc, savedMode);
2380 SetMapMode(hdc, mapMode);
2381 SetWindowOrgEx(hdc, win_org.x, win_org.y, NULL);
2382 SetWindowExtEx(hdc, win_size.cx, win_size.cy, NULL);
2383 SetViewportOrgEx(hdc, vp_org.x, vp_org.y, NULL);
2384 SetViewportExtEx(hdc, vp_size.cx, vp_size.cy, NULL);
2387 for(i = 1; i < emh->nHandles; i++) /* Don't delete element 0 (hmf) */
2388 if( (ht->objectHandle)[i] )
2389 DeleteObject( (ht->objectHandle)[i] );
2391 HeapFree( GetProcessHeap(), 0, info );
2395 static INT CALLBACK EMF_PlayEnhMetaFileCallback(HDC hdc, HANDLETABLE *ht,
2396 const ENHMETARECORD *emr,
2397 INT handles, LPARAM data)
2399 return PlayEnhMetaFileRecord(hdc, ht, emr, handles);
2402 /**************************************************************************
2403 * PlayEnhMetaFile (GDI32.@)
2405 * Renders an enhanced metafile into a specified rectangle *lpRect
2406 * in device context hdc.
2412 BOOL WINAPI PlayEnhMetaFile(
2413 HDC hdc, /* [in] DC to render into */
2414 HENHMETAFILE hmf, /* [in] metafile to render */
2415 const RECT *lpRect /* [in] rectangle to place metafile inside */
2418 return EnumEnhMetaFile(hdc, hmf, EMF_PlayEnhMetaFileCallback, NULL,
2422 /*****************************************************************************
2423 * DeleteEnhMetaFile (GDI32.@)
2425 * Deletes an enhanced metafile and frees the associated storage.
2427 BOOL WINAPI DeleteEnhMetaFile(HENHMETAFILE hmf)
2429 return EMF_Delete_HENHMETAFILE( hmf );
2432 /*****************************************************************************
2433 * CopyEnhMetaFileA (GDI32.@)
2435 * Duplicate an enhanced metafile.
2439 HENHMETAFILE WINAPI CopyEnhMetaFileA(
2440 HENHMETAFILE hmfSrc,
2443 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2444 HENHMETAFILE hmfDst;
2446 if(!emrSrc) return FALSE;
2448 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2449 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2450 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2454 hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0,
2455 NULL, CREATE_ALWAYS, 0, 0);
2456 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2457 CloseHandle( hFile );
2458 /* Reopen file for reading only, so that apps can share
2459 read access to the file while hmf is still valid */
2460 hFile = CreateFileA( file, GENERIC_READ, FILE_SHARE_READ,
2461 NULL, OPEN_EXISTING, 0, 0);
2462 if(hFile == INVALID_HANDLE_VALUE) {
2463 ERR("Can't reopen emf for reading\n");
2466 hmfDst = EMF_GetEnhMetaFile( hFile );
2467 CloseHandle( hFile );
2472 /*****************************************************************************
2473 * CopyEnhMetaFileW (GDI32.@)
2475 * See CopyEnhMetaFileA.
2479 HENHMETAFILE WINAPI CopyEnhMetaFileW(
2480 HENHMETAFILE hmfSrc,
2483 ENHMETAHEADER *emrSrc = EMF_GetEnhMetaHeader( hmfSrc ), *emrDst;
2484 HENHMETAFILE hmfDst;
2486 if(!emrSrc) return FALSE;
2488 emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
2489 memcpy( emrDst, emrSrc, emrSrc->nBytes );
2490 hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE );
2494 hFile = CreateFileW( file, GENERIC_WRITE | GENERIC_READ, 0,
2495 NULL, CREATE_ALWAYS, 0, 0);
2496 WriteFile( hFile, emrSrc, emrSrc->nBytes, &w, NULL);
2497 CloseHandle( hFile );
2498 /* Reopen file for reading only, so that apps can share
2499 read access to the file while hmf is still valid */
2500 hFile = CreateFileW( file, GENERIC_READ, FILE_SHARE_READ,
2501 NULL, OPEN_EXISTING, 0, 0);
2502 if(hFile == INVALID_HANDLE_VALUE) {
2503 ERR("Can't reopen emf for reading\n");
2506 hmfDst = EMF_GetEnhMetaFile( hFile );
2507 CloseHandle( hFile );
2513 /* Struct to be used to be passed in the LPVOID parameter for cbEnhPaletteCopy */
2514 typedef struct tagEMF_PaletteCopy
2517 LPPALETTEENTRY lpPe;
2520 /***************************************************************
2521 * Find the EMR_EOF record and then use it to find the
2522 * palette entries for this enhanced metafile.
2523 * The lpData is actually a pointer to an EMF_PaletteCopy struct
2524 * which contains the max number of elements to copy and where
2527 * NOTE: To be used by GetEnhMetaFilePaletteEntries only!
2529 static INT CALLBACK cbEnhPaletteCopy( HDC a,
2531 const ENHMETARECORD *lpEMR,
2536 if ( lpEMR->iType == EMR_EOF )
2538 PEMREOF lpEof = (PEMREOF)lpEMR;
2539 EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
2540 DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
2542 TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
2544 memcpy( (LPVOID)info->lpPe,
2545 (LPVOID)(((LPSTR)lpEof) + lpEof->offPalEntries),
2546 sizeof( *(info->lpPe) ) * dwNumPalToCopy );
2548 /* Update the passed data as a return code */
2549 info->lpPe = NULL; /* Palettes were copied! */
2550 info->cEntries = (UINT)dwNumPalToCopy;
2552 return FALSE; /* That's all we need */
2558 /*****************************************************************************
2559 * GetEnhMetaFilePaletteEntries (GDI32.@)
2561 * Copy the palette and report size
2563 * BUGS: Error codes (SetLastError) are not set on failures
2565 UINT WINAPI GetEnhMetaFilePaletteEntries( HENHMETAFILE hEmf,
2567 LPPALETTEENTRY lpPe )
2569 ENHMETAHEADER* enhHeader = EMF_GetEnhMetaHeader( hEmf );
2570 EMF_PaletteCopy infoForCallBack;
2572 TRACE( "(%p,%d,%p)\n", hEmf, cEntries, lpPe );
2574 /* First check if there are any palettes associated with
2576 if ( enhHeader->nPalEntries == 0 ) return 0;
2578 /* Is the user requesting the number of palettes? */
2579 if ( lpPe == NULL ) return (UINT)enhHeader->nPalEntries;
2581 /* Copy cEntries worth of PALETTEENTRY structs into the buffer */
2582 infoForCallBack.cEntries = cEntries;
2583 infoForCallBack.lpPe = lpPe;
2585 if ( !EnumEnhMetaFile( 0, hEmf, cbEnhPaletteCopy,
2586 &infoForCallBack, 0 ) )
2589 /* Verify that the callback executed correctly */
2590 if ( infoForCallBack.lpPe != NULL )
2592 /* Callback proc had error! */
2593 ERR( "cbEnhPaletteCopy didn't execute correctly\n" );
2597 return infoForCallBack.cEntries;
2600 typedef struct gdi_mf_comment
2607 DWORD cbWinMetaFile;
2610 /******************************************************************
2611 * SetWinMetaFileBits (GDI32.@)
2613 * Translate from old style to new style.
2616 HENHMETAFILE WINAPI SetWinMetaFileBits(UINT cbBuffer,
2617 CONST BYTE *lpbBuffer,
2619 CONST METAFILEPICT *lpmfp
2622 static const WCHAR szDisplayW[] = { 'D','I','S','P','L','A','Y','\0' };
2623 HMETAFILE hmf = NULL;
2624 HENHMETAFILE ret = NULL;
2625 HDC hdc = NULL, hdcdisp = NULL;
2626 RECT rc, *prcFrame = NULL;
2627 gdi_mf_comment *mfcomment;
2628 UINT mfcomment_size;
2630 TRACE("(%d, %p, %p, %p)\n", cbBuffer, lpbBuffer, hdcRef, lpmfp);
2632 hmf = SetMetaFileBitsEx(cbBuffer, lpbBuffer);
2635 WARN("SetMetaFileBitsEx failed\n");
2640 hdcRef = hdcdisp = CreateDCW(szDisplayW, NULL, NULL, NULL);
2643 TRACE("mm = %ld %ldx%ld\n", lpmfp->mm, lpmfp->xExt, lpmfp->yExt);
2645 if (lpmfp && (lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC))
2647 rc.left = rc.top = 0;
2648 rc.right = lpmfp->xExt;
2649 rc.bottom = lpmfp->yExt;
2653 if(!(hdc = CreateEnhMetaFileW(hdcRef, NULL, prcFrame, NULL)))
2655 ERR("CreateEnhMetaFile fails?\n");
2660 * Write the original METAFILE into the enhanced metafile.
2661 * It is encapsulated in a GDICOMMENT_WINDOWS_METAFILE record.
2663 mfcomment_size = sizeof (gdi_mf_comment) + cbBuffer;
2664 mfcomment = HeapAlloc(GetProcessHeap(), 0, mfcomment_size);
2667 mfcomment->ident = GDICOMMENT_IDENTIFIER;
2668 mfcomment->iComment = GDICOMMENT_WINDOWS_METAFILE;
2669 mfcomment->nVersion = 0x00000300;
2670 mfcomment->nChecksum = 0; /* FIXME */
2671 mfcomment->fFlags = 0;
2672 mfcomment->cbWinMetaFile = cbBuffer;
2673 memcpy(&mfcomment[1], lpbBuffer, cbBuffer);
2674 GdiComment(hdc, mfcomment_size, (BYTE*) mfcomment);
2675 HeapFree(GetProcessHeap(), 0, mfcomment);
2678 if(lpmfp && lpmfp->mm != MM_TEXT)
2679 SetMapMode(hdc, lpmfp->mm);
2681 if (lpmfp && (lpmfp->mm == MM_ISOTROPIC || lpmfp->mm == MM_ANISOTROPIC))
2683 INT horzres, vertres, horzsize, vertsize, xext, yext;
2685 horzres = GetDeviceCaps(hdcRef, HORZRES);
2686 vertres = GetDeviceCaps(hdcRef, VERTRES);
2687 horzsize = GetDeviceCaps(hdcRef, HORZSIZE);
2688 vertsize = GetDeviceCaps(hdcRef, VERTSIZE);
2690 /* set the initial viewport:window ratio as 1:1 */
2691 xext = lpmfp->xExt*horzres/(100*horzsize);
2692 yext = lpmfp->yExt*vertres/(100*vertsize);
2693 SetViewportExtEx(hdc, xext, yext, NULL);
2694 SetWindowExtEx(hdc, xext, yext, NULL);
2697 PlayMetaFile(hdc, hmf);
2699 ret = CloseEnhMetaFile(hdc);
2701 if (hdcdisp) DeleteDC(hdcdisp);
2702 DeleteMetaFile(hmf);