2 * Dump an Enhanced Meta File
4 * Copyright 2005 Mike McCormack
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
38 #include "gdiplusenums.h"
46 } EmfPlusRecordHeader
;
48 static const char *debugstr_wn(const WCHAR
*wstr
, unsigned int n
)
54 if (!wstr
) return "(null)";
59 while (i
< n
&& i
< sizeof(buf
) - 2 && wstr
[i
])
61 if (wstr
[i
] < 127) *p
++ = wstr
[i
];
70 static unsigned int read_int(const unsigned char *buffer
)
78 #define EMRCASE(x) case x: printf("%-20s %08x\n", #x, length); break
79 #define EMRPLUSCASE(x) case x: printf(" %-20s %04x %08x %08x\n", #x, header->Flags, header->Size, header->DataSize); break
81 static unsigned offset
= 0;
83 static int dump_emfrecord(void)
85 const unsigned char* ptr
;
86 unsigned int type
, length
, i
;
92 length
= read_int(ptr
+ 4);
98 const ENHMETAHEADER
*header
= PRD(offset
, sizeof(*header
));
100 printf("%-20s %08x\n", "EMR_HEADER", length
);
101 printf("bounds (%d,%d - %d,%d) frame (%d,%d - %d,%d) signature %#x version %#x bytes %#x records %#x\n"
102 "handles %#x reserved %#x palette entries %#x px %dx%d mm %dx%d μm %dx%d opengl %d description %s\n",
103 header
->rclBounds
.left
, header
->rclBounds
.top
, header
->rclBounds
.right
, header
->rclBounds
.bottom
,
104 header
->rclFrame
.left
, header
->rclFrame
.top
, header
->rclFrame
.right
, header
->rclFrame
.bottom
,
105 header
->dSignature
, header
->nVersion
, header
->nBytes
, header
->nRecords
, header
->nHandles
, header
->sReserved
,
106 header
->nPalEntries
, header
->szlDevice
.cx
, header
->szlDevice
.cy
, header
->szlMillimeters
.cx
,
107 header
->szlMillimeters
.cy
, header
->szlMicrometers
.cx
, header
->szlMicrometers
.cy
, header
->bOpenGL
,
108 debugstr_wn((LPCWSTR
)((const BYTE
*)header
+ header
->offDescription
), header
->nDescription
));
112 EMRCASE(EMR_POLYBEZIER
);
113 EMRCASE(EMR_POLYGON
);
114 EMRCASE(EMR_POLYLINE
);
115 EMRCASE(EMR_POLYBEZIERTO
);
116 EMRCASE(EMR_POLYLINETO
);
117 EMRCASE(EMR_POLYPOLYLINE
);
118 EMRCASE(EMR_POLYPOLYGON
);
119 EMRCASE(EMR_SETWINDOWEXTEX
);
120 EMRCASE(EMR_SETWINDOWORGEX
);
121 EMRCASE(EMR_SETVIEWPORTEXTEX
);
122 EMRCASE(EMR_SETVIEWPORTORGEX
);
123 EMRCASE(EMR_SETBRUSHORGEX
);
125 EMRCASE(EMR_SETPIXELV
);
126 EMRCASE(EMR_SETMAPPERFLAGS
);
127 EMRCASE(EMR_SETMAPMODE
);
128 EMRCASE(EMR_SETBKMODE
);
129 EMRCASE(EMR_SETPOLYFILLMODE
);
130 EMRCASE(EMR_SETROP2
);
131 EMRCASE(EMR_SETSTRETCHBLTMODE
);
132 EMRCASE(EMR_SETTEXTALIGN
);
133 EMRCASE(EMR_SETCOLORADJUSTMENT
);
134 EMRCASE(EMR_SETTEXTCOLOR
);
135 EMRCASE(EMR_SETBKCOLOR
);
136 EMRCASE(EMR_OFFSETCLIPRGN
);
137 EMRCASE(EMR_MOVETOEX
);
138 EMRCASE(EMR_SETMETARGN
);
139 EMRCASE(EMR_EXCLUDECLIPRECT
);
141 case EMR_INTERSECTCLIPRECT
:
143 const EMRINTERSECTCLIPRECT
*clip
= PRD(offset
, sizeof(*clip
));
145 printf("%-20s %08x\n", "EMR_INTERSECTCLIPRECT", length
);
146 printf("rect %d,%d - %d, %d\n",
147 clip
->rclClip
.left
, clip
->rclClip
.top
,
148 clip
->rclClip
.right
, clip
->rclClip
.bottom
);
152 EMRCASE(EMR_SCALEVIEWPORTEXTEX
);
153 EMRCASE(EMR_SCALEWINDOWEXTEX
);
155 EMRCASE(EMR_RESTOREDC
);
156 EMRCASE(EMR_SETWORLDTRANSFORM
);
157 EMRCASE(EMR_MODIFYWORLDTRANSFORM
);
158 EMRCASE(EMR_SELECTOBJECT
);
159 EMRCASE(EMR_CREATEPEN
);
160 EMRCASE(EMR_CREATEBRUSHINDIRECT
);
161 EMRCASE(EMR_DELETEOBJECT
);
162 EMRCASE(EMR_ANGLEARC
);
163 EMRCASE(EMR_ELLIPSE
);
164 EMRCASE(EMR_RECTANGLE
);
165 EMRCASE(EMR_ROUNDRECT
);
169 EMRCASE(EMR_SELECTPALETTE
);
170 EMRCASE(EMR_CREATEPALETTE
);
171 EMRCASE(EMR_SETPALETTEENTRIES
);
172 EMRCASE(EMR_RESIZEPALETTE
);
173 EMRCASE(EMR_REALIZEPALETTE
);
174 EMRCASE(EMR_EXTFLOODFILL
);
177 EMRCASE(EMR_POLYDRAW
);
178 EMRCASE(EMR_SETARCDIRECTION
);
179 EMRCASE(EMR_SETMITERLIMIT
);
180 EMRCASE(EMR_BEGINPATH
);
181 EMRCASE(EMR_ENDPATH
);
182 EMRCASE(EMR_CLOSEFIGURE
);
183 EMRCASE(EMR_FILLPATH
);
184 EMRCASE(EMR_STROKEANDFILLPATH
);
185 EMRCASE(EMR_STROKEPATH
);
186 EMRCASE(EMR_FLATTENPATH
);
187 EMRCASE(EMR_WIDENPATH
);
188 EMRCASE(EMR_SELECTCLIPPATH
);
189 EMRCASE(EMR_ABORTPATH
);
193 printf("%-20s %08x\n", "EMR_GDICOMMENT", length
);
195 /* Handle EMF+ records */
196 if (length
>= 16 && !memcmp((char*)PRD(offset
+ 12, sizeof(unsigned int)), "EMF+", 4))
198 const EmfPlusRecordHeader
*header
;
199 const unsigned int *data_size
;
203 data_size
= PRD(offset
, sizeof(*data_size
));
204 printf("data size = %x\n", *data_size
);
208 while (length
>= sizeof(*header
))
210 header
= PRD(offset
, sizeof(*header
));
213 EMRPLUSCASE(EmfPlusRecordTypeInvalid
);
214 EMRPLUSCASE(EmfPlusRecordTypeHeader
);
215 EMRPLUSCASE(EmfPlusRecordTypeEndOfFile
);
216 EMRPLUSCASE(EmfPlusRecordTypeComment
);
217 EMRPLUSCASE(EmfPlusRecordTypeGetDC
);
218 EMRPLUSCASE(EmfPlusRecordTypeMultiFormatStart
);
219 EMRPLUSCASE(EmfPlusRecordTypeMultiFormatSection
);
220 EMRPLUSCASE(EmfPlusRecordTypeMultiFormatEnd
);
221 EMRPLUSCASE(EmfPlusRecordTypeObject
);
222 EMRPLUSCASE(EmfPlusRecordTypeClear
);
223 EMRPLUSCASE(EmfPlusRecordTypeFillRects
);
224 EMRPLUSCASE(EmfPlusRecordTypeDrawRects
);
225 EMRPLUSCASE(EmfPlusRecordTypeFillPolygon
);
226 EMRPLUSCASE(EmfPlusRecordTypeDrawLines
);
227 EMRPLUSCASE(EmfPlusRecordTypeFillEllipse
);
228 EMRPLUSCASE(EmfPlusRecordTypeDrawEllipse
);
229 EMRPLUSCASE(EmfPlusRecordTypeFillPie
);
230 EMRPLUSCASE(EmfPlusRecordTypeDrawPie
);
231 EMRPLUSCASE(EmfPlusRecordTypeDrawArc
);
232 EMRPLUSCASE(EmfPlusRecordTypeFillRegion
);
233 EMRPLUSCASE(EmfPlusRecordTypeFillPath
);
234 EMRPLUSCASE(EmfPlusRecordTypeDrawPath
);
235 EMRPLUSCASE(EmfPlusRecordTypeFillClosedCurve
);
236 EMRPLUSCASE(EmfPlusRecordTypeDrawClosedCurve
);
237 EMRPLUSCASE(EmfPlusRecordTypeDrawCurve
);
238 EMRPLUSCASE(EmfPlusRecordTypeDrawBeziers
);
239 EMRPLUSCASE(EmfPlusRecordTypeDrawImage
);
240 EMRPLUSCASE(EmfPlusRecordTypeDrawImagePoints
);
241 EMRPLUSCASE(EmfPlusRecordTypeDrawString
);
242 EMRPLUSCASE(EmfPlusRecordTypeSetRenderingOrigin
);
243 EMRPLUSCASE(EmfPlusRecordTypeSetAntiAliasMode
);
244 EMRPLUSCASE(EmfPlusRecordTypeSetTextRenderingHint
);
245 EMRPLUSCASE(EmfPlusRecordTypeSetTextContrast
);
246 EMRPLUSCASE(EmfPlusRecordTypeSetInterpolationMode
);
247 EMRPLUSCASE(EmfPlusRecordTypeSetPixelOffsetMode
);
248 EMRPLUSCASE(EmfPlusRecordTypeSetCompositingMode
);
249 EMRPLUSCASE(EmfPlusRecordTypeSetCompositingQuality
);
250 EMRPLUSCASE(EmfPlusRecordTypeSave
);
251 EMRPLUSCASE(EmfPlusRecordTypeRestore
);
252 EMRPLUSCASE(EmfPlusRecordTypeBeginContainer
);
253 EMRPLUSCASE(EmfPlusRecordTypeBeginContainerNoParams
);
254 EMRPLUSCASE(EmfPlusRecordTypeEndContainer
);
255 EMRPLUSCASE(EmfPlusRecordTypeSetWorldTransform
);
256 EMRPLUSCASE(EmfPlusRecordTypeResetWorldTransform
);
257 EMRPLUSCASE(EmfPlusRecordTypeMultiplyWorldTransform
);
258 EMRPLUSCASE(EmfPlusRecordTypeTranslateWorldTransform
);
259 EMRPLUSCASE(EmfPlusRecordTypeScaleWorldTransform
);
260 EMRPLUSCASE(EmfPlusRecordTypeRotateWorldTransform
);
261 EMRPLUSCASE(EmfPlusRecordTypeSetPageTransform
);
262 EMRPLUSCASE(EmfPlusRecordTypeResetClip
);
263 EMRPLUSCASE(EmfPlusRecordTypeSetClipRect
);
264 EMRPLUSCASE(EmfPlusRecordTypeSetClipPath
);
265 EMRPLUSCASE(EmfPlusRecordTypeSetClipRegion
);
266 EMRPLUSCASE(EmfPlusRecordTypeOffsetClip
);
267 EMRPLUSCASE(EmfPlusRecordTypeDrawDriverString
);
268 EMRPLUSCASE(EmfPlusRecordTypeStrokeFillPath
);
269 EMRPLUSCASE(EmfPlusRecordTypeSerializableObject
);
270 EMRPLUSCASE(EmfPlusRecordTypeSetTSGraphics
);
271 EMRPLUSCASE(EmfPlusRecordTypeSetTSClip
);
272 EMRPLUSCASE(EmfPlusRecordTotal
);
275 printf(" unknown EMF+ record %x %04x %08x\n", header
->Type
, header
->Flags
, header
->Size
);
279 if (length
<sizeof(*header
) || header
->Size
%4)
282 length
-= sizeof(*header
);
283 offset
+= sizeof(*header
);
285 for (i
=0; i
<header
->Size
-sizeof(*header
); i
+=4)
289 if (!(ptr
= PRD(offset
, 4))) return -1;
292 printf("%08x ", read_int(ptr
));
293 if ((i
% 16 == 12) || (i
+ 4 == header
->Size
- sizeof(*header
)))
304 EMRCASE(EMR_FILLRGN
);
305 EMRCASE(EMR_FRAMERGN
);
306 EMRCASE(EMR_INVERTRGN
);
307 EMRCASE(EMR_PAINTRGN
);
309 case EMR_EXTSELECTCLIPRGN
:
311 const EMREXTSELECTCLIPRGN
*clip
= PRD(offset
, sizeof(*clip
));
312 const RGNDATA
*data
= (const RGNDATA
*)clip
->RgnData
;
313 DWORD i
, rc_count
= 0;
316 if (length
>= sizeof(*clip
) + sizeof(*data
))
317 rc_count
= data
->rdh
.nCount
;
319 printf("%-20s %08x\n", "EMR_EXTSELECTCLIPRGN", length
);
320 printf("mode %d, rects %d\n", clip
->iMode
, rc_count
);
321 for (i
= 0, rc
= (const RECT
*)data
->Buffer
; i
< rc_count
; i
++, rc
++)
322 printf(" (%d,%d)-(%d,%d)", rc
->left
, rc
->top
, rc
->right
, rc
->bottom
);
323 if (rc_count
!= 0) printf("\n");
331 const EMRSTRETCHBLT
*blt
= PRD(offset
, sizeof(*blt
));
332 const BITMAPINFOHEADER
*bmih
= (const BITMAPINFOHEADER
*)((const unsigned char *)blt
+ blt
->offBmiSrc
);
334 printf("%-20s %08x\n", "EMR_STRETCHBLT", length
);
335 printf("bounds (%d,%d - %d,%d) dst %d,%d %dx%d src %d,%d %dx%d rop %#x xform (%f, %f, %f, %f, %f, %f)\n"
336 "bk_color %#x usage %#x bmi_offset %#x bmi_size %#x bits_offset %#x bits_size %#x\n",
337 blt
->rclBounds
.left
, blt
->rclBounds
.top
, blt
->rclBounds
.right
, blt
->rclBounds
.bottom
,
338 blt
->xDest
, blt
->yDest
, blt
->cxDest
, blt
->cyDest
,
339 blt
->xSrc
, blt
->ySrc
, blt
->cxSrc
, blt
->cySrc
, blt
->dwRop
,
340 blt
->xformSrc
.eM11
, blt
->xformSrc
.eM12
, blt
->xformSrc
.eM21
,
341 blt
->xformSrc
.eM22
, blt
->xformSrc
.eDx
, blt
->xformSrc
.eDy
,
342 blt
->crBkColorSrc
, blt
->iUsageSrc
, blt
->offBmiSrc
, blt
->cbBmiSrc
,
343 blt
->offBitsSrc
, blt
->cbBitsSrc
);
344 printf("BITMAPINFOHEADER biSize %#x biWidth %d biHeight %d biPlanes %d biBitCount %d biCompression %#x\n"
345 "biSizeImage %#x biXPelsPerMeter %d biYPelsPerMeter %d biClrUsed %#x biClrImportant %#x\n",
346 bmih
->biSize
, bmih
->biWidth
, bmih
->biHeight
, bmih
->biPlanes
, bmih
->biBitCount
,
347 bmih
->biCompression
, bmih
->biSizeImage
, bmih
->biXPelsPerMeter
, bmih
->biYPelsPerMeter
,
348 bmih
->biClrUsed
, bmih
->biClrImportant
);
352 EMRCASE(EMR_MASKBLT
);
354 EMRCASE(EMR_SETDIBITSTODEVICE
);
355 EMRCASE(EMR_STRETCHDIBITS
);
357 case EMR_EXTCREATEFONTINDIRECTW
:
359 const EMREXTCREATEFONTINDIRECTW
*pf
= PRD(offset
, sizeof(*pf
));
360 const LOGFONTW
*plf
= &pf
->elfw
.elfLogFont
;
362 printf("%-20s %08x\n", "EMR_EXTCREATEFONTINDIRECTW", length
);
363 printf("(%d %d %d %d %x out %d clip %x quality %d charset %d) %s %s %s %s\n",
364 plf
->lfHeight
, plf
->lfWidth
,
365 plf
->lfEscapement
, plf
->lfOrientation
,
366 plf
->lfPitchAndFamily
,
367 plf
->lfOutPrecision
, plf
->lfClipPrecision
,
368 plf
->lfQuality
, plf
->lfCharSet
,
369 debugstr_wn(plf
->lfFaceName
, LF_FACESIZE
),
370 plf
->lfWeight
> 400 ? "Bold" : "",
371 plf
->lfItalic
? "Italic" : "",
372 plf
->lfUnderline
? "Underline" : "");
376 EMRCASE(EMR_EXTTEXTOUTA
);
378 case EMR_EXTTEXTOUTW
:
380 const EMREXTTEXTOUTW
*etoW
= PRD(offset
, sizeof(*etoW
));
381 const int *dx
= (const int *)((const BYTE
*)etoW
+ etoW
->emrtext
.offDx
);
383 printf("%-20s %08x\n", "EMR_EXTTEXTOUTW", length
);
384 printf("bounds (%d,%d - %d,%d) mode %#x x_scale %f y_scale %f pt (%d,%d) rect (%d,%d - %d,%d) flags %#x, %s\n",
385 etoW
->rclBounds
.left
, etoW
->rclBounds
.top
, etoW
->rclBounds
.right
, etoW
->rclBounds
.bottom
,
386 etoW
->iGraphicsMode
, etoW
->exScale
, etoW
->eyScale
,
387 etoW
->emrtext
.ptlReference
.x
, etoW
->emrtext
.ptlReference
.y
,
388 etoW
->emrtext
.rcl
.left
, etoW
->emrtext
.rcl
.top
,
389 etoW
->emrtext
.rcl
.right
, etoW
->emrtext
.rcl
.bottom
,
390 etoW
->emrtext
.fOptions
,
391 debugstr_wn((LPCWSTR
)((const BYTE
*)etoW
+ etoW
->emrtext
.offString
), etoW
->emrtext
.nChars
));
392 printf("dx_offset %u {", etoW
->emrtext
.offDx
);
393 for (i
= 0; i
< etoW
->emrtext
.nChars
; ++i
)
396 if (i
!= etoW
->emrtext
.nChars
- 1)
403 EMRCASE(EMR_POLYBEZIER16
);
404 EMRCASE(EMR_POLYGON16
);
405 EMRCASE(EMR_POLYLINE16
);
406 EMRCASE(EMR_POLYBEZIERTO16
);
407 EMRCASE(EMR_POLYLINETO16
);
408 EMRCASE(EMR_POLYPOLYLINE16
);
409 EMRCASE(EMR_POLYPOLYGON16
);
410 EMRCASE(EMR_POLYDRAW16
);
411 EMRCASE(EMR_CREATEMONOBRUSH
);
412 EMRCASE(EMR_CREATEDIBPATTERNBRUSHPT
);
413 EMRCASE(EMR_EXTCREATEPEN
);
414 EMRCASE(EMR_POLYTEXTOUTA
);
415 EMRCASE(EMR_POLYTEXTOUTW
);
416 EMRCASE(EMR_SETICMMODE
);
417 EMRCASE(EMR_CREATECOLORSPACE
);
418 EMRCASE(EMR_SETCOLORSPACE
);
419 EMRCASE(EMR_DELETECOLORSPACE
);
420 EMRCASE(EMR_GLSRECORD
);
421 EMRCASE(EMR_GLSBOUNDEDRECORD
);
422 EMRCASE(EMR_PIXELFORMAT
);
423 EMRCASE(EMR_DRAWESCAPE
);
424 EMRCASE(EMR_EXTESCAPE
);
425 EMRCASE(EMR_STARTDOC
);
426 EMRCASE(EMR_SMALLTEXTOUT
);
427 EMRCASE(EMR_FORCEUFIMAPPING
);
428 EMRCASE(EMR_NAMEDESCAPE
);
429 EMRCASE(EMR_COLORCORRECTPALETTE
);
430 EMRCASE(EMR_SETICMPROFILEA
);
431 EMRCASE(EMR_SETICMPROFILEW
);
435 const EMRALPHABLEND
*blend
= PRD(offset
, sizeof(*blend
));
436 const BITMAPINFOHEADER
*bmih
= (const BITMAPINFOHEADER
*)((const unsigned char *)blend
+ blend
->offBmiSrc
);
438 printf("%-20s %08x\n", "EMR_ALPHABLEND", length
);
439 printf("bounds (%d,%d - %d,%d) dst %d,%d %dx%d src %d,%d %dx%d rop %#x xform (%f, %f, %f, %f, %f, %f)\n"
440 "bk_color %#x usage %#x bmi_offset %#x bmi_size %#x bits_offset %#x bits_size %#x\n",
441 blend
->rclBounds
.left
, blend
->rclBounds
.top
, blend
->rclBounds
.right
, blend
->rclBounds
.bottom
,
442 blend
->xDest
, blend
->yDest
, blend
->cxDest
, blend
->cyDest
,
443 blend
->xSrc
, blend
->ySrc
, blend
->cxSrc
, blend
->cySrc
, blend
->dwRop
,
444 blend
->xformSrc
.eM11
, blend
->xformSrc
.eM12
, blend
->xformSrc
.eM21
,
445 blend
->xformSrc
.eM22
, blend
->xformSrc
.eDx
, blend
->xformSrc
.eDy
,
446 blend
->crBkColorSrc
, blend
->iUsageSrc
, blend
->offBmiSrc
, blend
->cbBmiSrc
,
447 blend
->offBitsSrc
, blend
->cbBitsSrc
);
448 printf("BITMAPINFOHEADER biSize %#x biWidth %d biHeight %d biPlanes %d biBitCount %d biCompression %#x\n"
449 "biSizeImage %#x biXPelsPerMeter %d biYPelsPerMeter %d biClrUsed %#x biClrImportant %#x\n",
450 bmih
->biSize
, bmih
->biWidth
, bmih
->biHeight
, bmih
->biPlanes
, bmih
->biBitCount
,
451 bmih
->biCompression
, bmih
->biSizeImage
, bmih
->biXPelsPerMeter
, bmih
->biYPelsPerMeter
,
452 bmih
->biClrUsed
, bmih
->biClrImportant
);
456 EMRCASE(EMR_SETLAYOUT
);
457 EMRCASE(EMR_TRANSPARENTBLT
);
458 EMRCASE(EMR_RESERVED_117
);
459 EMRCASE(EMR_GRADIENTFILL
);
460 EMRCASE(EMR_SETLINKEDUFI
);
461 EMRCASE(EMR_SETTEXTJUSTIFICATION
);
462 EMRCASE(EMR_COLORMATCHTOTARGETW
);
463 EMRCASE(EMR_CREATECOLORSPACEW
);
466 printf("%u %08x\n", type
, length
);
470 if ( (length
< 8) || (length
% 4) )
477 for(i
=0; i
<length
; i
+=4)
481 if (!(ptr
= PRD(offset
, 4))) return -1;
483 printf("%08x ", read_int(ptr
));
484 if ( (i
% 16 == 12) || (i
+ 4 == length
))
491 enum FileSig
get_kind_emf(void)
493 const ENHMETAHEADER
* hdr
;
495 hdr
= PRD(0, sizeof(*hdr
));
496 if (hdr
&& hdr
->iType
== EMR_HEADER
&& hdr
->dSignature
== ENHMETA_SIGNATURE
)
504 while (!dump_emfrecord());