fonts: Correct External leading for japanese small font and enable fontmetric test...
[wine] / tools / winedump / emf.c
1 /*
2  *  Dump an Enhanced Meta File
3  *
4  *  Copyright 2005 Mike McCormack
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23 #include "winedump.h"
24
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>
34
35 #include "windef.h"
36 #include "winbase.h"
37 #include "wingdi.h"
38
39 static unsigned int read_int(const unsigned char *buffer)
40 {
41     return buffer[0]
42      + (buffer[1]<<8)
43      + (buffer[2]<<16)
44      + (buffer[3]<<24);
45 }
46
47 #define EMRCASE(x) case x: printf("%-20s %08x\n", #x, length); break
48
49 static unsigned offset = 0;
50
51 static int dump_emfrecord(void)
52 {
53     const unsigned char*        ptr;
54     unsigned int type, length, i;
55
56     ptr = PRD(offset, 8);
57     if (!ptr) return -1;
58
59     type = read_int(ptr);
60     length = read_int(ptr + 4);
61
62     switch(type)
63     {
64     EMRCASE(EMR_HEADER);
65     EMRCASE(EMR_POLYGON);
66     EMRCASE(EMR_POLYLINE);
67     EMRCASE(EMR_SETWINDOWEXTEX);
68     EMRCASE(EMR_SETWINDOWORGEX);
69     EMRCASE(EMR_SETVIEWPORTEXTEX);
70     EMRCASE(EMR_EOF);
71     EMRCASE(EMR_SETMAPMODE);
72     EMRCASE(EMR_SETPOLYFILLMODE);
73     EMRCASE(EMR_SETROP2);
74     EMRCASE(EMR_SCALEWINDOWEXTEX);
75     EMRCASE(EMR_SAVEDC);
76     EMRCASE(EMR_SELECTOBJECT);
77     EMRCASE(EMR_CREATEPEN);
78     EMRCASE(EMR_CREATEBRUSHINDIRECT);
79     EMRCASE(EMR_DELETEOBJECT);
80     EMRCASE(EMR_RECTANGLE);
81     EMRCASE(EMR_SELECTPALETTE);
82     EMRCASE(EMR_GDICOMMENT);
83     EMRCASE(EMR_EXTSELECTCLIPRGN);
84     EMRCASE(EMR_EXTCREATEFONTINDIRECTW);
85     EMRCASE(EMR_EXTTEXTOUTW);
86     EMRCASE(EMR_POLYGON16);
87     EMRCASE(EMR_POLYLINE16);
88
89     default:
90         printf("%08x %08x\n",type,length);
91         break;
92     }
93
94     if ( (length < 8) || (length % 4) )
95         return -1;
96
97     length -= 8;
98
99     offset += 8;
100
101     for(i=0; i<length; i+=4)
102     {
103          if (i%16 == 0)
104              printf("   ");
105          if (!(ptr = PRD(offset, 4))) return -1;
106          offset += 4;
107          printf("%08x ", read_int(ptr));
108          if ( (i % 16 == 12) || (i + 4 == length))
109              printf("\n");
110     }
111
112     return 0;
113 }
114
115 enum FileSig get_kind_emf(void)
116 {
117     const ENHMETAHEADER*        hdr;
118
119     hdr = PRD(0, sizeof(*hdr));
120     if (hdr && hdr->iType == EMR_HEADER && hdr->dSignature == ENHMETA_SIGNATURE)
121         return SIG_EMF;
122     return SIG_UNKNOWN;
123 }
124
125 void emf_dump(void)
126 {
127     offset = 0;
128     while (!dump_emfrecord());
129 }