wined3d: Factor out most of the execute_command_list callback to a common function.
[wine.git] / tools / winedump / mf.c
blob37869d3bb8ae37b0228139779fce79e8882deb6c
1 /*
2 * Dump a Windows Metafile
4 * Copyright 2021 Zhiyi Zhang for CodeWeavers
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 "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
29 #define META_EOF 0
30 #define METAFILE_MEMORY 1
31 #define METAFILE_DISK 2
33 static unsigned offset = 0;
35 static unsigned short read_word(const unsigned char *buffer)
37 return buffer[0] + (buffer[1] << 8);
40 static unsigned int read_int(const unsigned char *buffer)
42 return buffer[0] + (buffer[1] << 8) + (buffer[2] << 16) + (buffer[3] << 24);
45 static int dump_mfrecord(void)
47 unsigned int type, size, i;
48 const unsigned char *ptr;
50 ptr = PRD(offset, 6);
51 if (!ptr)
52 return -1;
54 /* METAHEADER */
55 if (offset == 0)
57 type = read_word(ptr);
58 /* mtHeaderSize is in words */
59 size = read_word(ptr + 2) * 2;
61 /* METARECORD */
62 else
64 /* rdSize is in words */
65 size = read_int(ptr) * 2;
66 type = read_word(ptr + 4);
69 #define MRCASE(x) \
70 case x: \
71 printf("%-20s %08x\n", #x, size); \
72 break
74 switch (type)
76 case METAFILE_MEMORY:
77 case METAFILE_DISK:
79 const METAHEADER *header = PRD(offset, sizeof(*header));
81 printf("%-20s %08x\n", "METAHEADER", size);
82 printf("type %d header_size %#x version %#x size %#x object_count %d max_record_size %#x "
83 "parameter_count %d\n",
84 header->mtType, header->mtHeaderSize * 2, header->mtVersion, header->mtSize * 2,
85 header->mtNoObjects, header->mtMaxRecord * 2, header->mtNoParameters);
86 break;
88 MRCASE(META_SETBKCOLOR);
89 MRCASE(META_SETBKMODE);
90 MRCASE(META_SETMAPMODE);
91 MRCASE(META_SETROP2);
92 MRCASE(META_SETRELABS);
93 MRCASE(META_SETPOLYFILLMODE);
94 MRCASE(META_SETSTRETCHBLTMODE);
95 MRCASE(META_SETTEXTCHAREXTRA);
96 MRCASE(META_SETTEXTCOLOR);
97 MRCASE(META_SETTEXTJUSTIFICATION);
98 MRCASE(META_SETWINDOWORG);
99 MRCASE(META_SETWINDOWEXT);
100 MRCASE(META_SETVIEWPORTORG);
101 MRCASE(META_SETVIEWPORTEXT);
102 MRCASE(META_OFFSETWINDOWORG);
103 MRCASE(META_SCALEWINDOWEXT);
104 MRCASE(META_OFFSETVIEWPORTORG);
105 MRCASE(META_SCALEVIEWPORTEXT);
106 MRCASE(META_LINETO);
107 MRCASE(META_MOVETO);
108 MRCASE(META_EXCLUDECLIPRECT);
109 MRCASE(META_INTERSECTCLIPRECT);
110 MRCASE(META_ARC);
111 MRCASE(META_ELLIPSE);
112 MRCASE(META_FLOODFILL);
113 MRCASE(META_PIE);
114 MRCASE(META_RECTANGLE);
115 MRCASE(META_ROUNDRECT);
116 MRCASE(META_PATBLT);
117 MRCASE(META_SAVEDC);
118 MRCASE(META_SETPIXEL);
119 MRCASE(META_OFFSETCLIPRGN);
120 MRCASE(META_TEXTOUT);
121 MRCASE(META_BITBLT);
122 MRCASE(META_STRETCHBLT);
123 MRCASE(META_POLYGON);
124 MRCASE(META_POLYLINE);
125 MRCASE(META_ESCAPE);
126 MRCASE(META_RESTOREDC);
127 MRCASE(META_FILLREGION);
128 MRCASE(META_FRAMEREGION);
129 MRCASE(META_INVERTREGION);
130 MRCASE(META_PAINTREGION);
131 MRCASE(META_SELECTCLIPREGION);
132 MRCASE(META_SELECTOBJECT);
133 MRCASE(META_SETTEXTALIGN);
134 MRCASE(META_DRAWTEXT);
135 MRCASE(META_CHORD);
136 MRCASE(META_SETMAPPERFLAGS);
137 MRCASE(META_EXTTEXTOUT);
138 MRCASE(META_SETDIBTODEV);
139 MRCASE(META_SELECTPALETTE);
140 MRCASE(META_REALIZEPALETTE);
141 MRCASE(META_ANIMATEPALETTE);
142 MRCASE(META_SETPALENTRIES);
143 MRCASE(META_POLYPOLYGON);
144 MRCASE(META_RESIZEPALETTE);
145 MRCASE(META_DIBBITBLT);
146 MRCASE(META_DIBSTRETCHBLT);
147 MRCASE(META_DIBCREATEPATTERNBRUSH);
148 MRCASE(META_STRETCHDIB);
149 MRCASE(META_EXTFLOODFILL);
150 MRCASE(META_RESETDC);
151 MRCASE(META_STARTDOC);
152 MRCASE(META_STARTPAGE);
153 MRCASE(META_ENDPAGE);
154 MRCASE(META_ABORTDOC);
155 MRCASE(META_ENDDOC);
156 MRCASE(META_SETLAYOUT);
157 MRCASE(META_DELETEOBJECT);
158 MRCASE(META_CREATEPALETTE);
159 MRCASE(META_CREATEBRUSH);
160 MRCASE(META_CREATEPATTERNBRUSH);
161 MRCASE(META_CREATEPENINDIRECT);
162 MRCASE(META_CREATEFONTINDIRECT);
163 MRCASE(META_CREATEBRUSHINDIRECT);
164 MRCASE(META_CREATEBITMAPINDIRECT);
165 MRCASE(META_CREATEBITMAP);
166 MRCASE(META_CREATEREGION);
167 MRCASE(META_UNKNOWN);
168 MRCASE(META_EOF);
170 default:
171 printf("%u %08x\n", type, size);
172 break;
175 #undef MRCASE
177 if ((size < 6) || (size % 2))
178 return -1;
180 /* METARECORD */
181 if (offset)
183 size -= 6;
184 offset += 6;
187 for (i = 0; i < size; i += 2)
189 if (i % 16 == 0)
190 printf(" ");
191 if (!(ptr = PRD(offset, 2)))
192 return -1;
193 offset += 2;
194 printf("%04x ", read_word(ptr));
195 if ((i % 16 == 14) || (i + 2 == size))
196 printf("\n");
199 return 0;
202 enum FileSig get_kind_mf(void)
204 const METAHEADER *hdr;
206 hdr = PRD(0, sizeof(*hdr));
207 if (hdr && (hdr->mtType == METAFILE_MEMORY || hdr->mtType == METAFILE_DISK)
208 && hdr->mtHeaderSize == sizeof(METAHEADER) / sizeof(WORD)
209 && (hdr->mtVersion == 0x0100 || hdr->mtVersion == 0x0300))
210 return SIG_MF;
211 return SIG_UNKNOWN;
214 void mf_dump(void)
216 offset = 0;
217 while (!dump_mfrecord())