mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / tools / winedump / emf.c
blobd44f7a806a5b07ad69e3d7be431e1d867a67c20a
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
23 #include "winedump.h"
25 #include <stdio.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
31 #endif
32 #include <fcntl.h>
33 #include <stdarg.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "wingdi.h"
38 #include "gdiplusenums.h"
40 typedef struct
42 WORD Type;
43 WORD Flags;
44 DWORD Size;
45 DWORD DataSize;
46 } EmfPlusRecordHeader;
48 static const char *debugstr_wn(const WCHAR *wstr, unsigned int n)
50 static char buf[80];
51 char *p;
52 unsigned int i;
54 if (!wstr) return "(null)";
56 i = 0;
57 p = buf;
58 *p++ = '\"';
59 while (i < n && i < sizeof(buf) - 2 && wstr[i])
61 if (wstr[i] < 127) *p++ = wstr[i];
62 else *p++ = '.';
63 i++;
65 *p++ = '\"';
66 *p = 0;
67 return buf;
70 static unsigned int read_int(const unsigned char *buffer)
72 return buffer[0]
73 + (buffer[1]<<8)
74 + (buffer[2]<<16)
75 + (buffer[3]<<24);
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;
88 ptr = PRD(offset, 8);
89 if (!ptr) return -1;
91 type = read_int(ptr);
92 length = read_int(ptr + 4);
94 switch(type)
96 case EMR_HEADER:
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));
109 break;
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);
124 EMRCASE(EMR_EOF);
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);
149 break;
152 EMRCASE(EMR_SCALEVIEWPORTEXTEX);
153 EMRCASE(EMR_SCALEWINDOWEXTEX);
154 EMRCASE(EMR_SAVEDC);
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);
166 EMRCASE(EMR_ARC);
167 EMRCASE(EMR_CHORD);
168 EMRCASE(EMR_PIE);
169 EMRCASE(EMR_SELECTPALETTE);
170 EMRCASE(EMR_CREATEPALETTE);
171 EMRCASE(EMR_SETPALETTEENTRIES);
172 EMRCASE(EMR_RESIZEPALETTE);
173 EMRCASE(EMR_REALIZEPALETTE);
174 EMRCASE(EMR_EXTFLOODFILL);
175 EMRCASE(EMR_LINETO);
176 EMRCASE(EMR_ARCTO);
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);
191 case EMR_GDICOMMENT:
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;
201 offset += 8;
202 length -= 8;
203 data_size = PRD(offset, sizeof(*data_size));
204 printf("data size = %x\n", *data_size);
205 offset += 8;
206 length -= 8;
208 while (length >= sizeof(*header))
210 header = PRD(offset, sizeof(*header));
211 switch(header->Type)
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);
274 default:
275 printf(" unknown EMF+ record %x %04x %08x\n", header->Type, header->Flags, header->Size);
276 break;
279 if (length<sizeof(*header) || header->Size%4)
280 return -1;
282 length -= sizeof(*header);
283 offset += sizeof(*header);
285 for (i=0; i<header->Size-sizeof(*header); i+=4)
287 if (i%16 == 0)
288 printf(" ");
289 if (!(ptr = PRD(offset, 4))) return -1;
290 length -= 4;
291 offset += 4;
292 printf("%08x ", read_int(ptr));
293 if ((i % 16 == 12) || (i + 4 == header->Size - sizeof(*header)))
294 printf("\n");
298 return 0;
301 break;
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;
314 const RECT *rc;
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");
324 break;
327 EMRCASE(EMR_BITBLT);
328 EMRCASE(EMR_STRETCHBLT);
329 EMRCASE(EMR_MASKBLT);
330 EMRCASE(EMR_PLGBLT);
331 EMRCASE(EMR_SETDIBITSTODEVICE);
332 EMRCASE(EMR_STRETCHDIBITS);
334 case EMR_EXTCREATEFONTINDIRECTW:
336 const EMREXTCREATEFONTINDIRECTW *pf = PRD(offset, sizeof(*pf));
337 const LOGFONTW *plf = &pf->elfw.elfLogFont;
339 printf("%-20s %08x\n", "EMR_EXTCREATEFONTINDIRECTW", length);
340 printf("(%d %d %d %d %x out %d clip %x quality %d charset %d) %s %s %s %s\n",
341 plf->lfHeight, plf->lfWidth,
342 plf->lfEscapement, plf->lfOrientation,
343 plf->lfPitchAndFamily,
344 plf->lfOutPrecision, plf->lfClipPrecision,
345 plf->lfQuality, plf->lfCharSet,
346 debugstr_wn(plf->lfFaceName, LF_FACESIZE),
347 plf->lfWeight > 400 ? "Bold" : "",
348 plf->lfItalic ? "Italic" : "",
349 plf->lfUnderline ? "Underline" : "");
350 break;
353 EMRCASE(EMR_EXTTEXTOUTA);
355 case EMR_EXTTEXTOUTW:
357 const EMREXTTEXTOUTW *etoW = PRD(offset, sizeof(*etoW));
359 printf("%-20s %08x\n", "EMR_EXTTEXTOUTW", length);
360 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",
361 etoW->rclBounds.left, etoW->rclBounds.top, etoW->rclBounds.right, etoW->rclBounds.bottom,
362 etoW->iGraphicsMode, etoW->exScale, etoW->eyScale,
363 etoW->emrtext.ptlReference.x, etoW->emrtext.ptlReference.y,
364 etoW->emrtext.rcl.left, etoW->emrtext.rcl.top,
365 etoW->emrtext.rcl.right, etoW->emrtext.rcl.bottom,
366 etoW->emrtext.fOptions,
367 debugstr_wn((LPCWSTR)((const BYTE *)etoW + etoW->emrtext.offString), etoW->emrtext.nChars));
368 break;
371 EMRCASE(EMR_POLYBEZIER16);
372 EMRCASE(EMR_POLYGON16);
373 EMRCASE(EMR_POLYLINE16);
374 EMRCASE(EMR_POLYBEZIERTO16);
375 EMRCASE(EMR_POLYLINETO16);
376 EMRCASE(EMR_POLYPOLYLINE16);
377 EMRCASE(EMR_POLYPOLYGON16);
378 EMRCASE(EMR_POLYDRAW16);
379 EMRCASE(EMR_CREATEMONOBRUSH);
380 EMRCASE(EMR_CREATEDIBPATTERNBRUSHPT);
381 EMRCASE(EMR_EXTCREATEPEN);
382 EMRCASE(EMR_POLYTEXTOUTA);
383 EMRCASE(EMR_POLYTEXTOUTW);
384 EMRCASE(EMR_SETICMMODE);
385 EMRCASE(EMR_CREATECOLORSPACE);
386 EMRCASE(EMR_SETCOLORSPACE);
387 EMRCASE(EMR_DELETECOLORSPACE);
388 EMRCASE(EMR_GLSRECORD);
389 EMRCASE(EMR_GLSBOUNDEDRECORD);
390 EMRCASE(EMR_PIXELFORMAT);
391 EMRCASE(EMR_DRAWESCAPE);
392 EMRCASE(EMR_EXTESCAPE);
393 EMRCASE(EMR_STARTDOC);
394 EMRCASE(EMR_SMALLTEXTOUT);
395 EMRCASE(EMR_FORCEUFIMAPPING);
396 EMRCASE(EMR_NAMEDESCAPE);
397 EMRCASE(EMR_COLORCORRECTPALETTE);
398 EMRCASE(EMR_SETICMPROFILEA);
399 EMRCASE(EMR_SETICMPROFILEW);
400 EMRCASE(EMR_ALPHABLEND);
401 EMRCASE(EMR_SETLAYOUT);
402 EMRCASE(EMR_TRANSPARENTBLT);
403 EMRCASE(EMR_RESERVED_117);
404 EMRCASE(EMR_GRADIENTFILL);
405 EMRCASE(EMR_SETLINKEDUFI);
406 EMRCASE(EMR_SETTEXTJUSTIFICATION);
407 EMRCASE(EMR_COLORMATCHTOTARGETW);
408 EMRCASE(EMR_CREATECOLORSPACEW);
410 default:
411 printf("%u %08x\n", type, length);
412 break;
415 if ( (length < 8) || (length % 4) )
416 return -1;
418 length -= 8;
420 offset += 8;
422 for(i=0; i<length; i+=4)
424 if (i%16 == 0)
425 printf(" ");
426 if (!(ptr = PRD(offset, 4))) return -1;
427 offset += 4;
428 printf("%08x ", read_int(ptr));
429 if ( (i % 16 == 12) || (i + 4 == length))
430 printf("\n");
433 return 0;
436 enum FileSig get_kind_emf(void)
438 const ENHMETAHEADER* hdr;
440 hdr = PRD(0, sizeof(*hdr));
441 if (hdr && hdr->iType == EMR_HEADER && hdr->dSignature == ENHMETA_SIGNATURE)
442 return SIG_EMF;
443 return SIG_UNKNOWN;
446 void emf_dump(void)
448 offset = 0;
449 while (!dump_emfrecord());