-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathEMF.bt
295 lines (276 loc) · 9.07 KB
/
EMF.bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
//------------------------------------------------
//--- 010 Editor v2.1.3 Binary Template
//
// File: EMF.bt
// Authors: Dustin D. Trammell
// E-mail: [email protected]
// Contr.: Alex McDonnell
// Contr.: Harli Aquino <[email protected]>
// Version: 0.4
// Purpose: Enhanced Metafile Format (EMF) template.
// Category: Image
// File Mask: *.emf
// ID Bytes: 01 00 00 00
// History:
// 0.4 2017-03-08 Harli : Added code to show details of SETDIBITSTODEVICE structure the EMF Record parser
// Harli : Added condition to only show the optional description if offDescription is not 0x00
// 0.3 2017-02-07 AM: Fixed record types that had a size of 8 from creating a warning.
// AM: Removed extra record loop that erroneously added an extra record to every file.
// 0.2 2016-01-29 SweetScape: Updated header for repository submission.
// 0.1 2008-04-08 D Trammell: Initial version.
//
// References:
// MS-EMF: Enhanced Metafile Format Specification 2.1, Microsoft
//------------------------------------------------
typedef enum <DWORD> {
EMR_HEADER = 0x00000001,
EMR_POLYBEZIER = 0x00000002,
EMR_POLYGON = 0x00000003,
EMR_POLYLINE = 0x00000004,
EMR_POLYBEZIERTO = 0x00000005,
EMR_POLYLINETO = 0x00000006,
EMR_POLYPOLYLINE = 0x00000007,
EMR_POLYPOLYGON = 0x00000008,
EMR_SETWINDOWEXTEX = 0x00000009,
EMR_SETWINDOWORGEX = 0x0000000A,
EMR_SETVIEWPORTEXTEX = 0x0000000B,
EMR_SETVIEWPORTORGEX = 0x0000000C,
EMR_SETBRUSHORGEX = 0x0000000D,
EMR_EOF = 0x0000000E,
EMR_SETPIXELV = 0x0000000F,
EMR_SETMAPPERFLAGS = 0x00000010,
EMR_SETMAPMODE = 0x00000011,
EMR_SETBKMODE = 0x00000012,
EMR_SETPOLYFILLMODE = 0x00000013,
EMR_SETROP2 = 0x00000014,
EMR_SETSTRETCHBLTMODE = 0x00000015,
EMR_SETTEXTALIGN = 0x00000016,
EMR_SETCOLORADJUSTMENT = 0x00000017,
EMR_SETTEXTCOLOR = 0x00000018,
EMR_SETBKCOLOR = 0x00000019,
EMR_OFFSETCLIPRGN = 0x0000001A,
EMR_MOVETOEX = 0x0000001B,
EMR_SETMETARGN = 0x0000001C,
EMR_EXCLUDECLIPRECT = 0x0000001D,
EMR_INTERSECTCLIPRECT = 0x0000001E,
EMR_SCALEVIEWPORTEXTEX = 0x0000001F,
EMR_SCALEWINDOWEXTEX = 0x00000020,
EMR_SAVEDC = 0x00000021,
EMR_RESTOREDC = 0x00000022,
EMR_SETWORLDTRANSFORM = 0x00000023,
EMR_MODIFYWORLDTRANSFORM = 0x00000024,
EMR_SELECTOBJECT = 0x00000025,
EMR_CREATEPEN = 0x00000026,
EMR_CREATEBRUSHINDIRECT = 0x00000027,
EMR_DELETEOBJECT = 0x00000028,
EMR_ANGLEARC = 0x00000029,
EMR_ELLIPSE = 0x0000002A,
EMR_RECTANGLE = 0x0000002B,
EMR_ROUNDRECT = 0x0000002C,
EMR_ARC = 0x0000002D,
EMR_CHORD = 0x0000002E,
EMR_PIE = 0x0000002F,
EMR_SELECTPALETTE = 0x00000030,
EMR_CREATEPALETTE = 0x00000031,
EMR_SETPALETTEENTRIES = 0x00000032,
EMR_RESIZEPALETTE = 0x00000033,
EMR_REALIZEPALETTE = 0x00000034,
EMR_EXTFLOODFILL = 0x00000035,
EMR_LINETO = 0x00000036,
EMR_ARCTO = 0x00000037,
EMR_POLYDRAW = 0x00000038,
EMR_SETARCDIRECTION = 0x00000039,
EMR_SETMITERLIMIT = 0x0000003A,
EMR_BEGINPATH = 0x0000003B,
EMR_ENDPATH = 0x0000003C,
EMR_CLOSEFIGURE = 0x0000003D,
EMR_FILLPATH = 0x0000003E,
EMR_STROKEANDFILLPATH = 0x0000003F,
EMR_STROKEPATH = 0x00000040,
EMR_FLATTENPATH = 0x00000041,
EMR_WIDENPATH = 0x00000042,
EMR_SELECTCLIPPATH = 0x00000043,
EMR_ABORTPATH = 0x00000044,
EMR_RESERVED_69 = 0x00000045,
EMR_COMMENT = 0x00000046,
EMR_FILLRGN = 0x00000047,
EMR_FRAMERGN = 0x00000048,
EMR_INVERTRGN = 0x00000049,
EMR_PAINTRGN = 0x0000004A,
EMR_EXTSELECTCLIPRGN = 0x0000004B,
EMR_BITBLT = 0x0000004C,
EMR_STRETCHBLT = 0x0000004D,
EMR_MASKBLT = 0x0000004E,
EMR_PLGBLT = 0x0000004F,
EMR_SETDIBITSTODEVICE = 0x00000050,
EMR_STRETCHDIBITS = 0x00000051,
EMR_EXTCREATEFONTINDIRECTW = 0x00000052,
EMR_EXTTEXTOUTA = 0x00000053,
EMR_EXTTEXTOUTW = 0x00000054,
EMR_POLYBEZIER16 = 0x00000055,
EMR_POLYGON16 = 0x00000056,
EMR_POLYLINE16 = 0x00000057,
EMR_POLYBEZIERTO16 = 0x00000058,
EMR_POLYLINETO16 = 0x00000059,
EMR_POLYPOLYLINE16 = 0x0000005A,
EMR_POLYPOLYGON16 = 0x0000005B,
EMR_POLYDRAW16 = 0x0000005C,
EMR_CREATEMONOBRUSH = 0x0000005D,
EMR_CREATEDIBPATTERNBRUSHPT = 0x0000005E,
EMR_EXTCREATEPEN = 0x0000005F,
EMR_POLYTEXTOUTA = 0x00000060,
EMR_POLYTEXTOUTW = 0x00000061,
EMR_SETICMMODE = 0x00000062,
EMR_CREATECOLORSPACE = 0x00000063,
EMR_SETCOLORSPACE = 0x00000064,
EMR_DELETECOLORSPACE = 0x00000065,
EMR_GLSRECORD = 0x00000066,
EMR_GLSBOUNDEDRECORD = 0x00000067,
EMR_PIXELFORMAT = 0x00000068,
EMR_DRAWESCAPE = 0x00000069,
EMR_EXTESCAPE = 0x0000006A,
EMR_RESERVED_107 = 0x0000006B,
EMR_SMALLTEXTOUT = 0x0000006C,
EMR_FORCEUFIMAPPING = 0x0000006D,
EMR_NAMEDESCAPE = 0x0000006E,
EMR_COLORCORRECTPALETTE = 0x0000006F,
EMR_SETICMPROFILEA = 0x00000070,
EMR_SETICMPROFILEW = 0x00000071,
EMR_ALPHABLEND = 0x00000072,
EMR_SETLAYOUT = 0x00000073,
EMR_TRANSPARENTBLT = 0x00000074,
EMR_RESERVED_117 = 0x00000075,
EMR_GRADIENTFILL = 0x00000076,
EMR_SETLINKEDUFIS = 0x00000077,
EMR_SETTEXTJUSTIFICATION = 0x00000078,
EMR_COLORMATCHTOTARGETW = 0x00000079,
EMR_CREATECOLORSPACEW = 0x0000007A
} RecordType;
typedef struct {
LONG cx;
LONG cy;
} SIZEL;
typedef struct _RECTL {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECTL;
typedef struct {
RecordType iType; // Record type EMR_HEADER.
DWORD nSize; // Record size in bytes. This may be greater
// than the sizeof(ENHMETAHEADER).
RECTL rclBounds; // Inclusive-inclusive bounds in device units.
RECTL rclFrame; // Inclusive-inclusive Picture Frame of
// metafile in .01 mm units.
DWORD dSignature; // Signature. Must be ENHMETA_SIGNATURE.
DWORD nVersion; // Version number.
DWORD nBytes; // Size of the metafile in bytes.
DWORD nRecords; // Number of records in the metafile.
WORD nHandles; // Number of handles in the handle table.
// Handle index zero is reserved.
WORD sReserved; // Reserved. Must be zero.
DWORD nDescription; // Number of chars in the unicode description string.
// This is 0 if there is no description string.
DWORD offDescription; // Offset to the metafile description record.
// This is 0 if there is no description string.
DWORD nPalEntries; // Number of entries in the metafile palette.
SIZEL szlDevice; // Size of the reference device in pixels.
SIZEL szlMillimeters; // Size of the reference device in millimeters.
} Header;
typedef struct {
WORD desc[header.nDescription];
} Description;
// Harli : 3/8/2017 1:16:26
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd162938(v=vs.85).aspx
typedef struct tagRGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;
// Harli : 3/8/2017 1:16:26
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd183375(v=vs.85).aspx
typedef struct tagBITMAPINFOHEADER {
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;
// Harli : 3/8/2017 1:16:26
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO;
// Harli : 3/8/2017 1:16:26
// https://msdn.microsoft.com/en-us/library/cc230685.aspx
typedef struct {
local int EMROffset = FTell();
FSeek(EMROffset);
RecordType iType; // Record type EMR_XXX
DWORD nSize; // Record size in bytes
RECTL Bounds;
DWORD xDest;
DWORD yDest;
DWORD xSrc;
DWORD ySrc;
DWORD cxSrc;
DWORD cySrc;
DWORD offBmiSrc;
DWORD cbBmiSrc;
DWORD offBitsSrc;
DWORD cbBitsSrc;
DWORD UsageSrc;
DWORD iStartScan;
DWORD cScans;
FSeek(EMROffset+offBmiSrc);
BITMAPINFO BitMapInfo;
} EMR_SETDIBITSTODEVICE;
typedef struct {
local int _iType = ReadUInt(FTell());
if (_iType == 0x00000050){ // Harli : 3/8/2017 1:16:26
EMR_SETDIBITSTODEVICE EMR_SETDIBITSTODEVICE_Record;
}
else {
RecordType iType; // Record type EMR_XXX
DWORD nSize; // Record size in bytes
if(nSize > 8){
DWORD dParm[((nSize-8)/4)]; // DWORD Array of parameters
}
}
} Record;
typedef struct {
uchar Reserved;
uchar Blue;
uchar Green;
uchar Red;
} PaletteEntry;
// START
LittleEndian();
// Header
Header header;
// Optional Description
if (header.offDescription){ // Harli : 3/8/2017 1:16:26
FSeek(header.offDescription);
Description description;
}
// Start of Records (after header)
FSeek(header.nSize);
// Parse the number of records indicated in the header
local int recCnt = 0;
for( recCnt = 0; recCnt < header.nRecords - 1; recCnt++ ) {
Record record;
}
// Check last record or header for presence of Palette
local int palCnt = 0;
for( palCnt = 0; palCnt < header.nPalEntries; palCnt++ ) {
PaletteEntry paletteentry;
}