2 Enhanced metafile functions
3 Copyright 1998, Douglas Ridgway
10 #include "wine/winestring.h"
14 /*****************************************************************************
15 * GetEnhMetaFile32A (GDI32.174)
19 HENHMETAFILE WINAPI
GetEnhMetaFileA(
20 LPCSTR lpszMetaFile
/* filename of enhanced metafile */
27 HFILE hf
= CreateFileA(lpszMetaFile
, GENERIC_READ
, 0, 0,
29 if (hf
== INVALID_HANDLE_VALUE
) {
30 FIXME(metafile
,"could not open %s\n",lpszMetaFile
);
33 if (!ReadFile(hf
, &h
, sizeof(ENHMETAHEADER
), &read
, NULL
)) {
34 FIXME(metafile
,"%s can't be read.\n",lpszMetaFile
);
38 if (read
!=sizeof(ENHMETAHEADER
)) {
39 FIXME(metafile
,"%s is not long enough.\n",lpszMetaFile
);
44 FIXME(metafile
,"%s has invalid emf header (type 0x%08lx).\n",lpszMetaFile
,h
.iType
);
48 if (memcmp(&(h
.dSignature
)," EMF",4)) {
49 FIXME(metafile
,"%s has invalid EMF header (dSignature 0x%08lx).\n",lpszMetaFile
,h
.dSignature
);
53 SetFilePointer(hf
, 0, NULL
, FILE_BEGIN
);
54 /* hmf = CreateFileMapping32A( hf, NULL, NULL, NULL, NULL, "temp"); */
55 hmf
= GlobalAlloc(GPTR
, h
.nBytes
);
57 if (!ReadFile(hf
, p
, h
.nBytes
, &read
, NULL
)) {
58 FIXME(metafile
,"%s could not be read.\n",lpszMetaFile
);
64 FIXME(metafile
,"%s is not long enough (%ld expected, %ld got).\n",lpszMetaFile
,h
.nBytes
,read
);
73 /*****************************************************************************
74 * GetEnhMetaFile32W (GDI32.180)
76 HENHMETAFILE WINAPI
GetEnhMetaFileW(
77 LPCWSTR lpszMetaFile
) /* filename of enhanced metafile */
79 FIXME(metafile
, "(%p): stub\n", lpszMetaFile
);
83 /*****************************************************************************
84 * GetEnhMetaFileHeader (GDI32.178)
86 * If _buf_ is NULL, returns the size of buffer required.
87 * Otherwise, copy up to _bufsize_ bytes of enhanced metafile header into
90 UINT WINAPI
GetEnhMetaFileHeader(
91 HENHMETAFILE hmf
, /* enhanced metafile */
92 UINT bufsize
, /* size of buffer */
93 LPENHMETAHEADER buf
/* buffer */
96 LPENHMETAHEADER p
= GlobalLock(hmf
);
97 if (!buf
) return sizeof(ENHMETAHEADER
);
98 memmove(buf
, p
, MIN(sizeof(ENHMETAHEADER
), bufsize
));
100 return MIN(sizeof(ENHMETAHEADER
), bufsize
);
104 /*****************************************************************************
105 * GetEnhMetaFileDescription32A (GDI32.176)
107 UINT WINAPI
GetEnhMetaFileDescriptionA(
108 HENHMETAFILE hmf
, /* enhanced metafile */
109 UINT size
, /* size of buf */
110 LPSTR buf
/* buffer to receive description */
113 LPENHMETAHEADER p
= GlobalLock(hmf
);
114 INT first
= lstrlenW( (void *)p
+p
->offDescription
);
116 if (!buf
|| !size
) return p
->nDescription
;
118 lstrcpynWtoA(buf
, (void *)p
+p
->offDescription
, size
);
120 lstrcpynWtoA(buf
, (void *)p
+p
->offDescription
+2*(first
+1), size
-first
-1);
122 /* memmove(buf, (void *)p+p->offDescription, MIN(size,p->nDescription)); */
124 return MIN(size
,p
->nDescription
);
127 /*****************************************************************************
128 * GetEnhMetaFileDescription32W (GDI32.177)
130 * Copies the description string of an enhanced metafile into a buffer
133 * If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
134 * number of characters copied.
136 UINT WINAPI
GetEnhMetaFileDescriptionW(
137 HENHMETAFILE hmf
, /* enhanced metafile */
138 UINT size
, /* size of buf */
139 LPWSTR buf
/* buffer to receive description */
142 LPENHMETAHEADER p
= GlobalLock(hmf
);
144 if (!buf
|| !size
) return p
->nDescription
;
146 memmove(buf
, (void *)p
+p
->offDescription
, MIN(size
,p
->nDescription
));
148 return MIN(size
,p
->nDescription
);
151 /****************************************************************************
152 * SetEnhMetaFileBits (GDI32.315)
154 * Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
156 HENHMETAFILE WINAPI
SetEnhMetaFileBits(UINT bufsize
, const BYTE
*buf
)
158 HENHMETAFILE hmf
= GlobalAlloc(GPTR
, bufsize
);
159 LPENHMETAHEADER h
= GlobalLock(hmf
);
160 memmove(h
, buf
, bufsize
);
165 /*****************************************************************************
166 * GetEnhMetaFileBits (GDI32.175)
169 UINT WINAPI
GetEnhMetaFileBits(
177 /*****************************************************************************
178 * PlayEnhMetaFileRecord (GDI32.264)
180 * Render a single enhanced metafile record in the device context hdc.
183 * TRUE on success, FALSE on error.
185 * Many unimplemented records.
187 BOOL WINAPI
PlayEnhMetaFileRecord(
188 HDC hdc
, /* device context in which to render EMF record */
189 LPHANDLETABLE handletable
, /* array of handles to be used in rendering record */
190 const ENHMETARECORD
*mr
, /* EMF record to render */
191 UINT handles
/* size of handle array */
196 "hdc = %08x, handletable = %p, record = %p, numHandles = %d\n",
197 hdc
, handletable
, mr
, handles
);
198 if (!mr
) return FALSE
;
202 TRACE(metafile
, " type=%d\n", type
);
207 /* ENHMETAHEADER *h = (LPENHMETAHEADER) mr; */
213 /* application defined and processed */
217 DWORD mode
= mr
->dParm
[0];
218 SetMapMode(hdc
, mode
);
223 DWORD mode
= mr
->dParm
[0];
224 SetBkMode(hdc
, mode
);
229 DWORD mode
= mr
->dParm
[0];
230 SetBkColor(hdc
, mode
);
233 case EMR_SETPOLYFILLMODE
:
235 DWORD mode
= mr
->dParm
[0];
236 SetPolyFillMode(hdc
, mode
);
241 DWORD mode
= mr
->dParm
[0];
245 case EMR_SETSTRETCHBLTMODE
:
247 DWORD mode
= mr
->dParm
[0];
248 SetStretchBltMode(hdc
, mode
);
251 case EMR_SETTEXTALIGN
:
253 DWORD align
= mr
->dParm
[0];
254 SetTextAlign(hdc
, align
);
257 case EMR_SETTEXTCOLOR
:
259 DWORD color
= mr
->dParm
[0];
260 SetTextColor(hdc
, color
);
270 RestoreDC(hdc
, mr
->dParm
[0]);
273 case EMR_INTERSECTCLIPRECT
:
275 INT left
= mr
->dParm
[0], top
= mr
->dParm
[1], right
= mr
->dParm
[2],
276 bottom
= mr
->dParm
[3];
277 IntersectClipRect(hdc
, left
, top
, right
, bottom
);
280 case EMR_SELECTOBJECT
:
282 DWORD obj
= mr
->dParm
[0];
283 SelectObject(hdc
, (handletable
->objectHandle
)[obj
]);
286 case EMR_DELETEOBJECT
:
288 DWORD obj
= mr
->dParm
[0];
289 DeleteObject( (handletable
->objectHandle
)[obj
]);
290 (handletable
->objectHandle
)[obj
] = 0;
293 case EMR_SETWINDOWORGEX
:
295 DWORD x
= mr
->dParm
[0], y
= mr
->dParm
[1];
296 SetWindowOrgEx(hdc
, x
, y
, NULL
);
299 case EMR_SETWINDOWEXTEX
:
301 DWORD x
= mr
->dParm
[0], y
= mr
->dParm
[1];
302 SetWindowExtEx(hdc
, x
, y
, NULL
);
305 case EMR_SETVIEWPORTORGEX
:
307 DWORD x
= mr
->dParm
[0], y
= mr
->dParm
[1];
308 SetViewportOrgEx(hdc
, x
, y
, NULL
);
311 case EMR_SETVIEWPORTEXTEX
:
313 DWORD x
= mr
->dParm
[0], y
= mr
->dParm
[1];
314 SetViewportExtEx(hdc
, x
, y
, NULL
);
319 DWORD obj
= mr
->dParm
[0];
320 (handletable
->objectHandle
)[obj
] =
321 CreatePenIndirect((LOGPEN
*) &(mr
->dParm
[1]));
324 case EMR_EXTCREATEPEN
:
326 DWORD obj
= mr
->dParm
[0];
327 DWORD style
= mr
->dParm
[1], brush
= mr
->dParm
[2];
328 LOGBRUSH
*b
= (LOGBRUSH
*) &mr
->dParm
[3];
329 FIXME(metafile
, "Some ExtCreatePen args not handled\n");
330 (handletable
->objectHandle
)[obj
] =
331 ExtCreatePen(style
, brush
, b
, 0, NULL
);
334 case EMR_CREATEBRUSHINDIRECT
:
336 DWORD obj
= mr
->dParm
[0];
337 (handletable
->objectHandle
)[obj
] =
338 CreateBrushIndirect((LOGBRUSH
*) &(mr
->dParm
[1]));
341 case EMR_EXTCREATEFONTINDIRECTW
:
343 DWORD obj
= mr
->dParm
[0];
344 (handletable
->objectHandle
)[obj
] =
345 CreateFontIndirectW((LOGFONTW
*) &(mr
->dParm
[1]));
350 DWORD x
= mr
->dParm
[0], y
= mr
->dParm
[1];
351 MoveToEx(hdc
, x
, y
, NULL
);
356 DWORD x
= mr
->dParm
[0], y
= mr
->dParm
[1];
362 INT left
= mr
->dParm
[0], top
= mr
->dParm
[1], right
= mr
->dParm
[2],
363 bottom
= mr
->dParm
[3];
364 Rectangle(hdc
, left
, top
, right
, bottom
);
369 INT left
= mr
->dParm
[0], top
= mr
->dParm
[1], right
= mr
->dParm
[2],
370 bottom
= mr
->dParm
[3];
371 Ellipse(hdc
, left
, top
, right
, bottom
);
376 /* 0-3 : a bounding rectangle? */
377 INT count
= mr
->dParm
[4];
378 FIXME(metafile
, "Some Polygon16 args not handled\n");
379 Polygon16(hdc
, (POINT16
*)&mr
->dParm
[5], count
);
384 /* 0-3 : a bounding rectangle? */
385 INT count
= mr
->dParm
[4];
386 FIXME(metafile
, "Some Polyline16 args not handled\n");
387 Polyline16(hdc
, (POINT16
*)&mr
->dParm
[5], count
);
392 case EMR_POLYPOLYGON16
:
394 INT polygons
= mr
->dParm
[z
];
395 LPPOINT16 pts
= (LPPOINT16
) &mr
->dParm
[x
];
396 LPINT16 counts
= (LPINT16
) &mr
->dParm
[y
];
397 PolyPolygon16(hdc
, pts
, counts
, polygons
);
401 case EMR_STRETCHDIBITS
:
403 LONG xDest
= mr
->dParm
[4];
404 LONG yDest
= mr
->dParm
[5];
405 LONG xSrc
= mr
->dParm
[6];
406 LONG ySrc
= mr
->dParm
[7];
407 LONG cxSrc
= mr
->dParm
[8];
408 LONG cySrc
= mr
->dParm
[9];
409 DWORD offBmiSrc
= mr
->dParm
[10];
410 DWORD offBitsSrc
= mr
->dParm
[12];
411 DWORD iUsageSrc
= mr
->dParm
[14];
412 DWORD dwRop
= mr
->dParm
[15];
413 LONG cxDest
= mr
->dParm
[16];
414 LONG cyDest
= mr
->dParm
[17];
416 StretchDIBits(hdc
,xDest
,yDest
,cxDest
,cyDest
,
417 xSrc
,ySrc
,cxSrc
,cySrc
,
418 ((char *)mr
)+offBitsSrc
,
419 (const BITMAPINFO
*)(((char *)mr
)+offBmiSrc
),
423 case EMR_EXTTEXTOUTW
:
426 DWORD flags
= mr
->dParm
[4];
428 DWORD x
= mr
->dParm
[7], y
= mr
->dParm
[8];
429 DWORD count
= mr
->dParm
[9];
431 LPWSTR str
= (LPWSTR
)& mr
->dParm
[17];
432 /* trailing info: dx array? */
433 FIXME(metafile
, "Many ExtTextOut args not handled\n");
434 ExtTextOutW(hdc
, x
, y
, flags
, /* lpRect */ NULL
,
435 str
, count
, /* lpDx */ NULL
);
440 FIXME(metafile
, "type %d is unimplemented\n", type
);
441 /* SetLastError(E_NOTIMPL); */
448 /*****************************************************************************
450 * EnumEnhMetaFile32 (GDI32.79)
452 * Walk an enhanced metafile, calling a user-specified function _EnhMetaFunc_
454 * record. Returns when either every record has been used or
455 * when _EnhMetaFunc_ returns FALSE.
459 * TRUE if every record is used, FALSE if any invocation of _EnhMetaFunc_
465 BOOL WINAPI
EnumEnhMetaFile(
466 HDC hdc
, /* device context to pass to _EnhMetaFunc_ */
467 HENHMETAFILE hmf
, /* EMF to walk */
468 ENHMFENUMPROC callback
, /* callback function */
469 LPVOID data
, /* optional data for callback function */
470 const RECT
*rect
/* bounding rectangle for rendered metafile */
474 LPENHMETARECORD p
= GlobalLock(hmf
);
475 INT count
= ((LPENHMETAHEADER
) p
)->nHandles
;
476 HANDLETABLE
*ht
= (HANDLETABLE
*)GlobalAlloc(GPTR
, sizeof(HANDLETABLE
)*count
);
477 ht
->objectHandle
[0] = hmf
;
479 ret
= (*callback
)(hdc
, ht
, p
, count
, data
);
480 if (p
->iType
== EMR_EOF
) break;
481 p
= (void *) p
+ p
->nSize
;
483 GlobalFree((HGLOBAL
)ht
);
489 /**************************************************************************
490 * PlayEnhMetaFile (GDI32.263)
492 * Renders an enhanced metafile into a specified rectangle *lpRect
493 * in device context hdc.
496 * Almost entirely unimplemented
499 BOOL WINAPI
PlayEnhMetaFile(
500 HDC hdc
, /* DC to render into */
501 HENHMETAFILE hmf
, /* metafile to render */
502 const RECT
*lpRect
/* rectangle to place metafile inside */
505 LPENHMETARECORD p
= GlobalLock(hmf
);
506 INT count
= ((LPENHMETAHEADER
) p
)->nHandles
;
507 HANDLETABLE
*ht
= (HANDLETABLE
*)GlobalAlloc(GPTR
,
508 sizeof(HANDLETABLE
)*count
);
512 LPENHMETAHEADER h
= (LPENHMETAHEADER
) p
;
513 FLOAT xscale
= (h
->rclBounds
.right
-h
->rclBounds
.left
)/(lpRect
->right
-lpRect
->left
);
514 FLOAT yscale
= (h
->rclBounds
.bottom
-h
->rclBounds
.top
)/(lpRect
->bottom
-lpRect
->top
);
515 XFORM xform
= {xscale
, 0, 0, yscale
, 0, 0};
516 xform
.eDx
= lpRect
->left
;
517 xform
.eDy
= lpRect
->top
;
518 FIXME(metafile
, "play into rect doesn't work\n");
519 savedMode
= SetGraphicsMode(hdc
, GM_ADVANCED
);
520 if (!SetWorldTransform(hdc
, &xform
)) {
521 WARN(metafile
, "World transform failed!\n");
525 ht
->objectHandle
[0] = hmf
;
527 PlayEnhMetaFileRecord(hdc
, ht
, p
, count
);
528 if (p
->iType
== EMR_EOF
) break;
529 p
= (void *) p
+ p
->nSize
; /* casted so that arithmetic is in bytes */
532 if (savedMode
) SetGraphicsMode(hdc
, savedMode
);
533 ret
= TRUE
; /* FIXME: calculate a more accurate return value */
537 /*****************************************************************************
538 * DeleteEnhMetaFile (GDI32.68)
540 * Deletes an enhanced metafile and frees the associated storage.
542 BOOL WINAPI
DeleteEnhMetaFile(HENHMETAFILE hmf
) {
543 return !GlobalFree(hmf
);
546 /*****************************************************************************
547 * CopyEnhMetaFileA (GDI32.21) Duplicate an enhanced metafile
551 HENHMETAFILE WINAPI
CopyEnhMetaFileA(
556 LPENHMETAHEADER h
= GlobalLock(hmf
);
557 HENHMETAFILE hmf2
= GlobalAlloc(GPTR
, h
->nBytes
);
558 LPENHMETAHEADER h2
= GlobalLock(hmf2
);
560 memmove(h2
, h
, h
->nBytes
);
565 FIXME(metafile
, "write to file not implemented\n");
570 /*****************************************************************************
571 * GetEnhMetaFilePaletteEntries (GDI32.179)
573 * Copy the palette and report size
576 UINT WINAPI
GetEnhMetaFilePaletteEntries(HENHMETAFILE hemf
,
580 LPENHMETAHEADER h
= GlobalLock(hemf
);
586 if ((lppe
)&&(cEntries
>0)){
587 FIXME(metafile
,"Stub\n");
599 /******************************************************************
600 * SetWinMetaFileBits (GDI32.343)
602 * Translate from old style to new style.
605 HENHMETAFILE WINAPI
SetWinMetaFileBits(UINT cbBuffer
,
606 CONST BYTE
*lpbBuffer
,
608 CONST METAFILEPICT
*lpmfp
611 FIXME(metafile
,"Stub\n");