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
22 #include "wine/port.h"
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
;
57 type
= read_word(ptr
);
58 /* mtHeaderSize is in words */
59 size
= read_word(ptr
+ 2) * 2;
64 /* rdSize is in words */
65 size
= read_int(ptr
) * 2;
66 type
= read_word(ptr
+ 4);
71 printf("%-20s %08x\n", #x, size); \
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
);
88 MRCASE(META_SETBKCOLOR
);
89 MRCASE(META_SETBKMODE
);
90 MRCASE(META_SETMAPMODE
);
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
);
108 MRCASE(META_EXCLUDECLIPRECT
);
109 MRCASE(META_INTERSECTCLIPRECT
);
111 MRCASE(META_ELLIPSE
);
112 MRCASE(META_FLOODFILL
);
114 MRCASE(META_RECTANGLE
);
115 MRCASE(META_ROUNDRECT
);
118 MRCASE(META_SETPIXEL
);
119 MRCASE(META_OFFSETCLIPRGN
);
120 MRCASE(META_TEXTOUT
);
122 MRCASE(META_STRETCHBLT
);
123 MRCASE(META_POLYGON
);
124 MRCASE(META_POLYLINE
);
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
);
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
);
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
);
171 printf("%u %08x\n", type
, size
);
177 if ((size
< 6) || (size
% 2))
187 for (i
= 0; i
< size
; i
+= 2)
191 if (!(ptr
= PRD(offset
, 2)))
194 printf("%04x ", read_word(ptr
));
195 if ((i
% 16 == 14) || (i
+ 2 == size
))
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))
217 while (!dump_mfrecord())