您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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