GdiPlusMetaHeader.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //Download by http://www.NewXing.com
  2. /**************************************************************************\
  3. *
  4. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  5. *
  6. * Module Name:
  7. *
  8. * Metafile headers
  9. *
  10. * Abstract:
  11. *
  12. * GDI+ Metafile Related Structures
  13. *
  14. \**************************************************************************/
  15. #ifndef _GDIPLUSMETAHEADER_H
  16. #define _GDIPLUSMETAHEADER_H
  17. typedef struct
  18. {
  19. DWORD iType; // Record type EMR_HEADER
  20. DWORD nSize; // Record size in bytes. This may be greater
  21. // than the sizeof(ENHMETAHEADER).
  22. RECTL rclBounds; // Inclusive-inclusive bounds in device units
  23. RECTL rclFrame; // Inclusive-inclusive Picture Frame .01mm unit
  24. DWORD dSignature; // Signature. Must be ENHMETA_SIGNATURE.
  25. DWORD nVersion; // Version number
  26. DWORD nBytes; // Size of the metafile in bytes
  27. DWORD nRecords; // Number of records in the metafile
  28. WORD nHandles; // Number of handles in the handle table
  29. // Handle index zero is reserved.
  30. WORD sReserved; // Reserved. Must be zero.
  31. DWORD nDescription; // Number of chars in the unicode desc string
  32. // This is 0 if there is no description string
  33. DWORD offDescription; // Offset to the metafile description record.
  34. // This is 0 if there is no description string
  35. DWORD nPalEntries; // Number of entries in the metafile palette.
  36. SIZEL szlDevice; // Size of the reference device in pels
  37. SIZEL szlMillimeters; // Size of the reference device in millimeters
  38. } ENHMETAHEADER3;
  39. // Placeable WMFs
  40. // Placeable Metafiles were created as a non-standard way of specifying how
  41. // a metafile is mapped and scaled on an output device.
  42. // Placeable metafiles are quite wide-spread, but not directly supported by
  43. // the Windows API. To playback a placeable metafile using the Windows API,
  44. // you will first need to strip the placeable metafile header from the file.
  45. // This is typically performed by copying the metafile to a temporary file
  46. // starting at file offset 22 (0x16). The contents of the temporary file may
  47. // then be used as input to the Windows GetMetaFile(), PlayMetaFile(),
  48. // CopyMetaFile(), etc. GDI functions.
  49. // Each placeable metafile begins with a 22-byte header,
  50. // followed by a standard metafile:
  51. #include <pshpack2.h> // set structure packing to 2
  52. typedef struct
  53. {
  54. INT16 Left;
  55. INT16 Top;
  56. INT16 Right;
  57. INT16 Bottom;
  58. } PWMFRect16;
  59. typedef struct
  60. {
  61. UINT32 Key; // GDIP_WMF_PLACEABLEKEY
  62. INT16 Hmf; // Metafile HANDLE number (always 0)
  63. PWMFRect16 BoundingBox; // Coordinates in metafile units
  64. INT16 Inch; // Number of metafile units per inch
  65. UINT32 Reserved; // Reserved (always 0)
  66. INT16 Checksum; // Checksum value for previous 10 WORDs
  67. } WmfPlaceableFileHeader;
  68. #include <poppack.h>
  69. // Key contains a special identification value that indicates the presence
  70. // of a placeable metafile header and is always 0x9AC6CDD7.
  71. // Handle is used to stored the handle of the metafile in memory. When written
  72. // to disk, this field is not used and will always contains the value 0.
  73. // Left, Top, Right, and Bottom contain the coordinates of the upper-left
  74. // and lower-right corners of the image on the output device. These are
  75. // measured in twips.
  76. // A twip (meaning "twentieth of a point") is the logical unit of measurement
  77. // used in Windows Metafiles. A twip is equal to 1/1440 of an inch. Thus 720
  78. // twips equal 1/2 inch, while 32,768 twips is 22.75 inches.
  79. // Inch contains the number of twips per inch used to represent the image.
  80. // Normally, there are 1440 twips per inch; however, this number may be
  81. // changed to scale the image. A value of 720 indicates that the image is
  82. // double its normal size, or scaled to a factor of 2:1. A value of 360
  83. // indicates a scale of 4:1, while a value of 2880 indicates that the image
  84. // is scaled down in size by a factor of two. A value of 1440 indicates
  85. // a 1:1 scale ratio.
  86. // Reserved is not used and is always set to 0.
  87. // Checksum contains a checksum value for the previous 10 WORDs in the header.
  88. // This value can be used in an attempt to detect if the metafile has become
  89. // corrupted. The checksum is calculated by XORing each WORD value to an
  90. // initial value of 0.
  91. // If the metafile was recorded with a reference Hdc that was a display.
  92. #define GDIP_EMFPLUSFLAGS_DISPLAY 0x00000001
  93. class MetafileHeader
  94. {
  95. public:
  96. MetafileType Type;
  97. UINT Size; // Size of the metafile (in bytes)
  98. UINT Version; // EMF+, EMF, or WMF version
  99. UINT EmfPlusFlags;
  100. REAL DpiX;
  101. REAL DpiY;
  102. INT X; // Bounds in device units
  103. INT Y;
  104. INT Width;
  105. INT Height;
  106. union
  107. {
  108. METAHEADER WmfHeader;
  109. ENHMETAHEADER3 EmfHeader;
  110. };
  111. INT EmfPlusHeaderSize; // size of the EMF+ header in file
  112. INT LogicalDpiX; // Logical Dpi of reference Hdc
  113. INT LogicalDpiY; // usually valid only for EMF+
  114. public:
  115. MetafileType GetType() const { return Type; }
  116. UINT GetMetafileSize() const { return Size; }
  117. // If IsEmfPlus, this is the EMF+ version; else it is the WMF or EMF ver
  118. UINT GetVersion() const { return Version; }
  119. // Get the EMF+ flags associated with the metafile
  120. UINT GetEmfPlusFlags() const { return EmfPlusFlags; }
  121. REAL GetDpiX() const { return DpiX; }
  122. REAL GetDpiY() const { return DpiY; }
  123. VOID GetBounds (OUT Rect *rect) const
  124. {
  125. rect->X = X;
  126. rect->Y = Y;
  127. rect->Width = Width;
  128. rect->Height = Height;
  129. }
  130. // Is it any type of WMF (standard or Placeable Metafile)?
  131. BOOL IsWmf() const
  132. {
  133. return ((Type == MetafileTypeWmf) || (Type == MetafileTypeWmfPlaceable));
  134. }
  135. // Is this an Placeable Metafile?
  136. BOOL IsWmfPlaceable() const { return (Type == MetafileTypeWmfPlaceable); }
  137. // Is this an EMF (not an EMF+)?
  138. BOOL IsEmf() const { return (Type == MetafileTypeEmf); }
  139. // Is this an EMF or EMF+ file?
  140. BOOL IsEmfOrEmfPlus() const { return (Type >= MetafileTypeEmf); }
  141. // Is this an EMF+ file?
  142. BOOL IsEmfPlus() const { return (Type >= MetafileTypeEmfPlusOnly); }
  143. // Is this an EMF+ dual (has dual, down-level records) file?
  144. BOOL IsEmfPlusDual() const { return (Type == MetafileTypeEmfPlusDual); }
  145. // Is this an EMF+ only (no dual records) file?
  146. BOOL IsEmfPlusOnly() const { return (Type == MetafileTypeEmfPlusOnly); }
  147. // If it's an EMF+ file, was it recorded against a display Hdc?
  148. BOOL IsDisplay() const
  149. {
  150. return (IsEmfPlus() &&
  151. ((EmfPlusFlags & GDIP_EMFPLUSFLAGS_DISPLAY) != 0));
  152. }
  153. // Get the WMF header of the metafile (if it is a WMF)
  154. const METAHEADER * GetWmfHeader() const
  155. {
  156. if (IsWmf())
  157. {
  158. return &WmfHeader;
  159. }
  160. return NULL;
  161. }
  162. // Get the EMF header of the metafile (if it is an EMF)
  163. const ENHMETAHEADER3 * GetEmfHeader() const
  164. {
  165. if (IsEmfOrEmfPlus())
  166. {
  167. return &EmfHeader;
  168. }
  169. return NULL;
  170. }
  171. };
  172. #endif