MetaHeader.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // System.Drawing.Imaging.MetaHeader.cs
  3. //
  4. // Authors:
  5. // Everaldo Canuto ([email protected])
  6. // Andreas Nahr ([email protected])
  7. // Dennis Hayes ([email protected])
  8. // Sebastien Pouliot <[email protected]>
  9. //
  10. // (C) 2002 Ximian, Inc. http://www.ximian.com
  11. // Copyright (C) 2004, 2006-2007 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System.Runtime.InteropServices;
  33. namespace System.Drawing.Imaging {
  34. [StructLayout (LayoutKind.Sequential, Pack=2)]
  35. internal struct WmfMetaHeader {
  36. // field order match: http://wvware.sourceforge.net/caolan/ora-wmf.html
  37. // for WMFHEAD structure
  38. public short file_type;
  39. public short header_size;
  40. public short version;
  41. // this is unaligned and fails on the SPARC architecture - http://bugzilla.ximian.com/show_bug.cgi?id=81254
  42. // public int file_size;
  43. public ushort file_size_low;
  44. public short file_size_high;
  45. public short num_of_objects;
  46. public int max_record_size;
  47. public short num_of_params;
  48. }
  49. [StructLayout (LayoutKind.Sequential)]
  50. public sealed class MetaHeader {
  51. private WmfMetaHeader wmf;
  52. public MetaHeader ()
  53. {
  54. }
  55. internal MetaHeader (WmfMetaHeader header)
  56. {
  57. wmf.file_type = header.file_type;
  58. wmf.header_size = header.header_size;
  59. wmf.version = header.version;
  60. wmf.file_size_low = header.file_size_low;
  61. wmf.file_size_high = header.file_size_high;
  62. wmf.num_of_objects = header.num_of_objects;
  63. wmf.max_record_size = header.max_record_size;
  64. wmf.num_of_params = header.num_of_params;
  65. }
  66. public short HeaderSize {
  67. get { return wmf.header_size; }
  68. set { wmf.header_size = value; }
  69. }
  70. public int MaxRecord {
  71. get { return wmf.max_record_size; }
  72. set { wmf.max_record_size = value; }
  73. }
  74. public short NoObjects {
  75. get { return wmf.num_of_objects; }
  76. set { wmf.num_of_objects = value; }
  77. }
  78. public short NoParameters {
  79. get { return wmf.num_of_params; }
  80. set { wmf.num_of_params = value; }
  81. }
  82. public int Size {
  83. get { return (wmf.file_size_high << 16) | wmf.file_size_low; }
  84. set {
  85. wmf.file_size_high = (short)(value >> 16);
  86. wmf.file_size_low = (ushort)value;
  87. }
  88. }
  89. public short Type {
  90. get { return wmf.file_type; }
  91. set { wmf.file_type = value; }
  92. }
  93. public short Version {
  94. get { return wmf.version; }
  95. set { wmf.version = value; }
  96. }
  97. }
  98. }