Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
7.9 KiB

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