emf.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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. #include "config.h"
  21. #include "wine/port.h"
  22. #include "winedump.h"
  23. #include <stdio.h>
  24. #ifdef HAVE_UNISTD_H
  25. # include <unistd.h>
  26. #endif
  27. #ifdef HAVE_SYS_TYPES_H
  28. # include <sys/types.h>
  29. #endif
  30. #include <fcntl.h>
  31. #include <stdarg.h>
  32. #include "windef.h"
  33. #include "winbase.h"
  34. #include "wingdi.h"
  35. #include "gdiplusenums.h"
  36. typedef struct
  37. {
  38. WORD Type;
  39. WORD Flags;
  40. DWORD Size;
  41. DWORD DataSize;
  42. } EmfPlusRecordHeader;
  43. static const char *debugstr_wn(const WCHAR *wstr, unsigned int n)
  44. {
  45. static char buf[80];
  46. char *p;
  47. unsigned int i;
  48. if (!wstr) return "(null)";
  49. i = 0;
  50. p = buf;
  51. *p++ = '\"';
  52. while (i < n && i < sizeof(buf) - 2 && wstr[i])
  53. {
  54. if (wstr[i] < 127) *p++ = wstr[i];
  55. else *p++ = '.';
  56. i++;
  57. }
  58. *p++ = '\"';
  59. *p = 0;
  60. return buf;
  61. }
  62. static unsigned int read_int(const unsigned char *buffer)
  63. {
  64. return buffer[0]
  65. + (buffer[1]<<8)
  66. + (buffer[2]<<16)
  67. + (buffer[3]<<24);
  68. }
  69. #define EMRCASE(x) case x: printf("%-20s %08x\n", #x, length); break
  70. #define EMRPLUSCASE(x) case x: printf(" %-20s %04x %08x %08x\n", #x, header->Flags, header->Size, header->DataSize); break
  71. static unsigned offset = 0;
  72. static int dump_emfrecord(void)
  73. {
  74. const unsigned char* ptr;
  75. unsigned int type, length, i;
  76. ptr = PRD(offset, 8);
  77. if (!ptr) return -1;
  78. type = read_int(ptr);
  79. length = read_int(ptr + 4);
  80. switch(type)
  81. {
  82. case EMR_HEADER:
  83. {
  84. const ENHMETAHEADER *header = PRD(offset, sizeof(*header));
  85. printf("%-20s %08x\n", "EMR_HEADER", length);
  86. printf("bounds (%d,%d - %d,%d) frame (%d,%d - %d,%d) signature %#x version %#x bytes %#x records %#x\n"
  87. "handles %#x reserved %#x palette entries %#x px %dx%d mm %dx%d μm %dx%d opengl %d description %s\n",
  88. header->rclBounds.left, header->rclBounds.top, header->rclBounds.right, header->rclBounds.bottom,
  89. header->rclFrame.left, header->rclFrame.top, header->rclFrame.right, header->rclFrame.bottom,
  90. header->dSignature, header->nVersion, header->nBytes, header->nRecords, header->nHandles, header->sReserved,
  91. header->nPalEntries, header->szlDevice.cx, header->szlDevice.cy, header->szlMillimeters.cx,
  92. header->szlMillimeters.cy, header->szlMicrometers.cx, header->szlMicrometers.cy, header->bOpenGL,
  93. debugstr_wn((LPCWSTR)((const BYTE *)header + header->offDescription), header->nDescription));
  94. break;
  95. }
  96. EMRCASE(EMR_POLYBEZIER);
  97. EMRCASE(EMR_POLYGON);
  98. EMRCASE(EMR_POLYLINE);
  99. EMRCASE(EMR_POLYBEZIERTO);
  100. EMRCASE(EMR_POLYLINETO);
  101. EMRCASE(EMR_POLYPOLYLINE);
  102. EMRCASE(EMR_POLYPOLYGON);
  103. EMRCASE(EMR_SETWINDOWEXTEX);
  104. EMRCASE(EMR_SETWINDOWORGEX);
  105. EMRCASE(EMR_SETVIEWPORTEXTEX);
  106. EMRCASE(EMR_SETVIEWPORTORGEX);
  107. EMRCASE(EMR_SETBRUSHORGEX);
  108. EMRCASE(EMR_EOF);
  109. EMRCASE(EMR_SETPIXELV);
  110. EMRCASE(EMR_SETMAPPERFLAGS);
  111. EMRCASE(EMR_SETMAPMODE);
  112. EMRCASE(EMR_SETBKMODE);
  113. EMRCASE(EMR_SETPOLYFILLMODE);
  114. EMRCASE(EMR_SETROP2);
  115. EMRCASE(EMR_SETSTRETCHBLTMODE);
  116. EMRCASE(EMR_SETTEXTALIGN);
  117. EMRCASE(EMR_SETCOLORADJUSTMENT);
  118. EMRCASE(EMR_SETTEXTCOLOR);
  119. EMRCASE(EMR_SETBKCOLOR);
  120. EMRCASE(EMR_OFFSETCLIPRGN);
  121. EMRCASE(EMR_MOVETOEX);
  122. EMRCASE(EMR_SETMETARGN);
  123. EMRCASE(EMR_EXCLUDECLIPRECT);
  124. case EMR_INTERSECTCLIPRECT:
  125. {
  126. const EMRINTERSECTCLIPRECT *clip = PRD(offset, sizeof(*clip));
  127. printf("%-20s %08x\n", "EMR_INTERSECTCLIPRECT", length);
  128. printf("rect %d,%d - %d, %d\n",
  129. clip->rclClip.left, clip->rclClip.top,
  130. clip->rclClip.right, clip->rclClip.bottom);
  131. break;
  132. }
  133. EMRCASE(EMR_SCALEVIEWPORTEXTEX);
  134. EMRCASE(EMR_SCALEWINDOWEXTEX);
  135. EMRCASE(EMR_SAVEDC);
  136. EMRCASE(EMR_RESTOREDC);
  137. EMRCASE(EMR_SETWORLDTRANSFORM);
  138. EMRCASE(EMR_MODIFYWORLDTRANSFORM);
  139. EMRCASE(EMR_SELECTOBJECT);
  140. EMRCASE(EMR_CREATEPEN);
  141. EMRCASE(EMR_CREATEBRUSHINDIRECT);
  142. EMRCASE(EMR_DELETEOBJECT);
  143. EMRCASE(EMR_ANGLEARC);
  144. EMRCASE(EMR_ELLIPSE);
  145. EMRCASE(EMR_RECTANGLE);
  146. EMRCASE(EMR_ROUNDRECT);
  147. EMRCASE(EMR_ARC);
  148. EMRCASE(EMR_CHORD);
  149. EMRCASE(EMR_PIE);
  150. EMRCASE(EMR_SELECTPALETTE);
  151. EMRCASE(EMR_CREATEPALETTE);
  152. EMRCASE(EMR_SETPALETTEENTRIES);
  153. EMRCASE(EMR_RESIZEPALETTE);
  154. EMRCASE(EMR_REALIZEPALETTE);
  155. EMRCASE(EMR_EXTFLOODFILL);
  156. EMRCASE(EMR_LINETO);
  157. EMRCASE(EMR_ARCTO);
  158. EMRCASE(EMR_POLYDRAW);
  159. EMRCASE(EMR_SETARCDIRECTION);
  160. EMRCASE(EMR_SETMITERLIMIT);
  161. EMRCASE(EMR_BEGINPATH);
  162. EMRCASE(EMR_ENDPATH);
  163. EMRCASE(EMR_CLOSEFIGURE);
  164. EMRCASE(EMR_FILLPATH);
  165. EMRCASE(EMR_STROKEANDFILLPATH);
  166. EMRCASE(EMR_STROKEPATH);
  167. EMRCASE(EMR_FLATTENPATH);
  168. EMRCASE(EMR_WIDENPATH);
  169. EMRCASE(EMR_SELECTCLIPPATH);
  170. EMRCASE(EMR_ABORTPATH);
  171. case EMR_GDICOMMENT:
  172. {
  173. printf("%-20s %08x\n", "EMR_GDICOMMENT", length);
  174. /* Handle EMF+ records */
  175. if (length >= 16 && !memcmp((char*)PRD(offset + 12, sizeof(unsigned int)), "EMF+", 4))
  176. {
  177. const EmfPlusRecordHeader *header;
  178. const unsigned int *data_size;
  179. offset += 8;
  180. length -= 8;
  181. data_size = PRD(offset, sizeof(*data_size));
  182. printf("data size = %x\n", *data_size);
  183. offset += 8;
  184. length -= 8;
  185. while (length >= sizeof(*header))
  186. {
  187. header = PRD(offset, sizeof(*header));
  188. switch(header->Type)
  189. {
  190. EMRPLUSCASE(EmfPlusRecordTypeInvalid);
  191. EMRPLUSCASE(EmfPlusRecordTypeHeader);
  192. EMRPLUSCASE(EmfPlusRecordTypeEndOfFile);
  193. EMRPLUSCASE(EmfPlusRecordTypeComment);
  194. EMRPLUSCASE(EmfPlusRecordTypeGetDC);
  195. EMRPLUSCASE(EmfPlusRecordTypeMultiFormatStart);
  196. EMRPLUSCASE(EmfPlusRecordTypeMultiFormatSection);
  197. EMRPLUSCASE(EmfPlusRecordTypeMultiFormatEnd);
  198. EMRPLUSCASE(EmfPlusRecordTypeObject);
  199. EMRPLUSCASE(EmfPlusRecordTypeClear);
  200. EMRPLUSCASE(EmfPlusRecordTypeFillRects);
  201. EMRPLUSCASE(EmfPlusRecordTypeDrawRects);
  202. EMRPLUSCASE(EmfPlusRecordTypeFillPolygon);
  203. EMRPLUSCASE(EmfPlusRecordTypeDrawLines);
  204. EMRPLUSCASE(EmfPlusRecordTypeFillEllipse);
  205. EMRPLUSCASE(EmfPlusRecordTypeDrawEllipse);
  206. EMRPLUSCASE(EmfPlusRecordTypeFillPie);
  207. EMRPLUSCASE(EmfPlusRecordTypeDrawPie);
  208. EMRPLUSCASE(EmfPlusRecordTypeDrawArc);
  209. EMRPLUSCASE(EmfPlusRecordTypeFillRegion);
  210. EMRPLUSCASE(EmfPlusRecordTypeFillPath);
  211. EMRPLUSCASE(EmfPlusRecordTypeDrawPath);
  212. EMRPLUSCASE(EmfPlusRecordTypeFillClosedCurve);
  213. EMRPLUSCASE(EmfPlusRecordTypeDrawClosedCurve);
  214. EMRPLUSCASE(EmfPlusRecordTypeDrawCurve);
  215. EMRPLUSCASE(EmfPlusRecordTypeDrawBeziers);
  216. EMRPLUSCASE(EmfPlusRecordTypeDrawImage);
  217. EMRPLUSCASE(EmfPlusRecordTypeDrawImagePoints);
  218. EMRPLUSCASE(EmfPlusRecordTypeDrawString);
  219. EMRPLUSCASE(EmfPlusRecordTypeSetRenderingOrigin);
  220. EMRPLUSCASE(EmfPlusRecordTypeSetAntiAliasMode);
  221. EMRPLUSCASE(EmfPlusRecordTypeSetTextRenderingHint);
  222. EMRPLUSCASE(EmfPlusRecordTypeSetTextContrast);
  223. EMRPLUSCASE(EmfPlusRecordTypeSetInterpolationMode);
  224. EMRPLUSCASE(EmfPlusRecordTypeSetPixelOffsetMode);
  225. EMRPLUSCASE(EmfPlusRecordTypeSetCompositingMode);
  226. EMRPLUSCASE(EmfPlusRecordTypeSetCompositingQuality);
  227. EMRPLUSCASE(EmfPlusRecordTypeSave);
  228. EMRPLUSCASE(EmfPlusRecordTypeRestore);
  229. EMRPLUSCASE(EmfPlusRecordTypeBeginContainer);
  230. EMRPLUSCASE(EmfPlusRecordTypeBeginContainerNoParams);
  231. EMRPLUSCASE(EmfPlusRecordTypeEndContainer);
  232. EMRPLUSCASE(EmfPlusRecordTypeSetWorldTransform);
  233. EMRPLUSCASE(EmfPlusRecordTypeResetWorldTransform);
  234. EMRPLUSCASE(EmfPlusRecordTypeMultiplyWorldTransform);
  235. EMRPLUSCASE(EmfPlusRecordTypeTranslateWorldTransform);
  236. EMRPLUSCASE(EmfPlusRecordTypeScaleWorldTransform);
  237. EMRPLUSCASE(EmfPlusRecordTypeRotateWorldTransform);
  238. EMRPLUSCASE(EmfPlusRecordTypeSetPageTransform);
  239. EMRPLUSCASE(EmfPlusRecordTypeResetClip);
  240. EMRPLUSCASE(EmfPlusRecordTypeSetClipRect);
  241. EMRPLUSCASE(EmfPlusRecordTypeSetClipPath);
  242. EMRPLUSCASE(EmfPlusRecordTypeSetClipRegion);
  243. EMRPLUSCASE(EmfPlusRecordTypeOffsetClip);
  244. EMRPLUSCASE(EmfPlusRecordTypeDrawDriverString);
  245. EMRPLUSCASE(EmfPlusRecordTypeStrokeFillPath);
  246. EMRPLUSCASE(EmfPlusRecordTypeSerializableObject);
  247. EMRPLUSCASE(EmfPlusRecordTypeSetTSGraphics);
  248. EMRPLUSCASE(EmfPlusRecordTypeSetTSClip);
  249. EMRPLUSCASE(EmfPlusRecordTotal);
  250. default:
  251. printf(" unknown EMF+ record %x %04x %08x\n", header->Type, header->Flags, header->Size);
  252. break;
  253. }
  254. if (length<sizeof(*header) || header->Size%4)
  255. return -1;
  256. length -= sizeof(*header);
  257. offset += sizeof(*header);
  258. for (i=0; i<header->Size-sizeof(*header); i+=4)
  259. {
  260. if (i%16 == 0)
  261. printf(" ");
  262. if (!(ptr = PRD(offset, 4))) return -1;
  263. length -= 4;
  264. offset += 4;
  265. printf("%08x ", read_int(ptr));
  266. if ((i % 16 == 12) || (i + 4 == header->Size - sizeof(*header)))
  267. printf("\n");
  268. }
  269. }
  270. return 0;
  271. }
  272. break;
  273. }
  274. EMRCASE(EMR_FILLRGN);
  275. EMRCASE(EMR_FRAMERGN);
  276. EMRCASE(EMR_INVERTRGN);
  277. EMRCASE(EMR_PAINTRGN);
  278. case EMR_EXTSELECTCLIPRGN:
  279. {
  280. const EMREXTSELECTCLIPRGN *clip = PRD(offset, sizeof(*clip));
  281. const RGNDATA *data = (const RGNDATA *)clip->RgnData;
  282. DWORD i, rc_count = 0;
  283. const RECT *rc;
  284. if (length >= sizeof(*clip) + sizeof(*data))
  285. rc_count = data->rdh.nCount;
  286. printf("%-20s %08x\n", "EMR_EXTSELECTCLIPRGN", length);
  287. printf("mode %d, rects %d\n", clip->iMode, rc_count);
  288. for (i = 0, rc = (const RECT *)data->Buffer; i < rc_count; i++, rc++)
  289. printf(" (%d,%d)-(%d,%d)", rc->left, rc->top, rc->right, rc->bottom);
  290. if (rc_count != 0) printf("\n");
  291. break;
  292. }
  293. EMRCASE(EMR_BITBLT);
  294. EMRCASE(EMR_STRETCHBLT);
  295. EMRCASE(EMR_MASKBLT);
  296. EMRCASE(EMR_PLGBLT);
  297. EMRCASE(EMR_SETDIBITSTODEVICE);
  298. EMRCASE(EMR_STRETCHDIBITS);
  299. case EMR_EXTCREATEFONTINDIRECTW:
  300. {
  301. const EMREXTCREATEFONTINDIRECTW *pf = PRD(offset, sizeof(*pf));
  302. const LOGFONTW *plf = &pf->elfw.elfLogFont;
  303. printf("%-20s %08x\n", "EMR_EXTCREATEFONTINDIRECTW", length);
  304. printf("(%d %d %d %d %x out %d clip %x quality %d charset %d) %s %s %s %s\n",
  305. plf->lfHeight, plf->lfWidth,
  306. plf->lfEscapement, plf->lfOrientation,
  307. plf->lfPitchAndFamily,
  308. plf->lfOutPrecision, plf->lfClipPrecision,
  309. plf->lfQuality, plf->lfCharSet,
  310. debugstr_wn(plf->lfFaceName, LF_FACESIZE),
  311. plf->lfWeight > 400 ? "Bold" : "",
  312. plf->lfItalic ? "Italic" : "",
  313. plf->lfUnderline ? "Underline" : "");
  314. break;
  315. }
  316. EMRCASE(EMR_EXTTEXTOUTA);
  317. case EMR_EXTTEXTOUTW:
  318. {
  319. const EMREXTTEXTOUTW *etoW = PRD(offset, sizeof(*etoW));
  320. printf("%-20s %08x\n", "EMR_EXTTEXTOUTW", length);
  321. printf("bounds (%d,%d - %d,%d) mode %#x x_scale %f y_scale %f pt (%d,%d) rect (%d,%d - %d,%d) flags %#x, %s\n",
  322. etoW->rclBounds.left, etoW->rclBounds.top, etoW->rclBounds.right, etoW->rclBounds.bottom,
  323. etoW->iGraphicsMode, etoW->exScale, etoW->eyScale,
  324. etoW->emrtext.ptlReference.x, etoW->emrtext.ptlReference.y,
  325. etoW->emrtext.rcl.left, etoW->emrtext.rcl.top,
  326. etoW->emrtext.rcl.right, etoW->emrtext.rcl.bottom,
  327. etoW->emrtext.fOptions,
  328. debugstr_wn((LPCWSTR)((const BYTE *)etoW + etoW->emrtext.offString), etoW->emrtext.nChars));
  329. break;
  330. }
  331. EMRCASE(EMR_POLYBEZIER16);
  332. EMRCASE(EMR_POLYGON16);
  333. EMRCASE(EMR_POLYLINE16);
  334. EMRCASE(EMR_POLYBEZIERTO16);
  335. EMRCASE(EMR_POLYLINETO16);
  336. EMRCASE(EMR_POLYPOLYLINE16);
  337. EMRCASE(EMR_POLYPOLYGON16);
  338. EMRCASE(EMR_POLYDRAW16);
  339. EMRCASE(EMR_CREATEMONOBRUSH);
  340. EMRCASE(EMR_CREATEDIBPATTERNBRUSHPT);
  341. EMRCASE(EMR_EXTCREATEPEN);
  342. EMRCASE(EMR_POLYTEXTOUTA);
  343. EMRCASE(EMR_POLYTEXTOUTW);
  344. EMRCASE(EMR_SETICMMODE);
  345. EMRCASE(EMR_CREATECOLORSPACE);
  346. EMRCASE(EMR_SETCOLORSPACE);
  347. EMRCASE(EMR_DELETECOLORSPACE);
  348. EMRCASE(EMR_GLSRECORD);
  349. EMRCASE(EMR_GLSBOUNDEDRECORD);
  350. EMRCASE(EMR_PIXELFORMAT);
  351. EMRCASE(EMR_DRAWESCAPE);
  352. EMRCASE(EMR_EXTESCAPE);
  353. EMRCASE(EMR_STARTDOC);
  354. EMRCASE(EMR_SMALLTEXTOUT);
  355. EMRCASE(EMR_FORCEUFIMAPPING);
  356. EMRCASE(EMR_NAMEDESCAPE);
  357. EMRCASE(EMR_COLORCORRECTPALETTE);
  358. EMRCASE(EMR_SETICMPROFILEA);
  359. EMRCASE(EMR_SETICMPROFILEW);
  360. EMRCASE(EMR_ALPHABLEND);
  361. EMRCASE(EMR_SETLAYOUT);
  362. EMRCASE(EMR_TRANSPARENTBLT);
  363. EMRCASE(EMR_RESERVED_117);
  364. EMRCASE(EMR_GRADIENTFILL);
  365. EMRCASE(EMR_SETLINKEDUFI);
  366. EMRCASE(EMR_SETTEXTJUSTIFICATION);
  367. EMRCASE(EMR_COLORMATCHTOTARGETW);
  368. EMRCASE(EMR_CREATECOLORSPACEW);
  369. default:
  370. printf("%u %08x\n", type, length);
  371. break;
  372. }
  373. if ( (length < 8) || (length % 4) )
  374. return -1;
  375. length -= 8;
  376. offset += 8;
  377. for(i=0; i<length; i+=4)
  378. {
  379. if (i%16 == 0)
  380. printf(" ");
  381. if (!(ptr = PRD(offset, 4))) return -1;
  382. offset += 4;
  383. printf("%08x ", read_int(ptr));
  384. if ( (i % 16 == 12) || (i + 4 == length))
  385. printf("\n");
  386. }
  387. return 0;
  388. }
  389. enum FileSig get_kind_emf(void)
  390. {
  391. const ENHMETAHEADER* hdr;
  392. hdr = PRD(0, sizeof(*hdr));
  393. if (hdr && hdr->iType == EMR_HEADER && hdr->dSignature == ENHMETA_SIGNATURE)
  394. return SIG_EMF;
  395. return SIG_UNKNOWN;
  396. }
  397. void emf_dump(void)
  398. {
  399. offset = 0;
  400. while (!dump_emfrecord());
  401. }