gdi: Device name returned from EnumDisplayDevices is valid for CreateDC.
[wine/multimedia.git] / tools / winedump / emf.c
blob34956849f5331afc303b5a23c1fff5493f02c52c
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
39 static unsigned int read_int(unsigned char *buffer)
41 return buffer[0]
42 + (buffer[1]<<8)
43 + (buffer[2]<<16)
44 + (buffer[3]<<24);
47 #define EMRCASE(x) case x: printf("%-20s %08x\n", #x, length); break
49 static int dump_emfrecord(int fd)
51 unsigned char buffer[8];
52 int r;
53 unsigned int type, length, i;
55 r = read(fd, buffer, 8);
56 if(r!=8)
57 return -1;
59 type = read_int(buffer);
60 length = read_int(buffer+4);
62 switch(type)
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);
89 default:
90 printf("%08x %08x\n",type,length);
91 break;
94 if ( (length < 8) || (length % 4) )
95 return -1;
97 length -= 8;
99 for(i=0; i<length; i+=4)
101 if (i%16 == 0)
102 printf(" ");
103 memset(buffer,0,sizeof buffer);
104 r = read(fd,buffer,4);
105 if(r!=4)
106 return -1;
107 printf("%08x ", read_int(buffer));
108 if ( (i%16 == 12) || ((i+4)==length) )
109 printf("\n");
112 return 0;
115 static int dump_emf_records(int fd)
117 while(!dump_emfrecord(fd))
119 return 0;
122 int dump_emf(const char *emf)
124 int fd;
126 fd = open(emf,O_RDONLY);
127 if (fd<0) return -1;
128 dump_emf_records(fd);
129 close(fd);
130 return 0;