2007-12-18 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / System.Drawing / System.Drawing.Imaging / MetaHeader.cs
1 //
2 // System.Drawing.Imaging.MetaHeader.cs
3 //
4 // Authors:
5 //   Everaldo Canuto (everaldo.canuto@bol.com.br)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //   Dennis Hayes (dennish@raytek.com)
8 //   Sebastien Pouliot  <sebastien@ximian.com>
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
33 using System.Runtime.InteropServices;
34
35 namespace System.Drawing.Imaging {
36
37         [StructLayout (LayoutKind.Sequential, Pack=2)]
38         internal struct WmfMetaHeader {
39                 // field order match: http://wvware.sourceforge.net/caolan/ora-wmf.html
40                 // for WMFHEAD structure
41                 public short file_type;
42                 public short header_size;
43                 public short version;
44                 // this is unaligned and fails on the SPARC architecture (see bug #81254 for details)
45                 // public int file_size;
46                 public ushort file_size_low;
47                 public ushort file_size_high;
48                 public short num_of_objects;
49                 public int max_record_size;
50                 public short num_of_params;
51         }
52
53         [StructLayout (LayoutKind.Sequential)]
54         public sealed class MetaHeader {
55
56                 private WmfMetaHeader wmf;
57
58                 public MetaHeader ()
59                 {
60                 }
61
62                 internal MetaHeader (WmfMetaHeader header)
63                 {
64                         wmf.file_type = header.file_type;
65                         wmf.header_size = header.header_size;
66                         wmf.version = header.version;
67                         wmf.file_size_low = header.file_size_low;
68                         wmf.file_size_high = header.file_size_high;
69                         wmf.num_of_objects = header.num_of_objects;
70                         wmf.max_record_size = header.max_record_size;
71                         wmf.num_of_params = header.num_of_params;
72                 }
73
74
75                 public short HeaderSize {
76                         get { return wmf.header_size; }
77                         set { wmf.header_size = value; }
78                 }
79                 
80                 public int MaxRecord {
81                         get { return wmf.max_record_size; }
82                         set { wmf.max_record_size = value; }
83                 }
84                 
85                 public short NoObjects {
86                         get { return wmf.num_of_objects; }
87                         set { wmf.num_of_objects = value; }
88                 }
89                 
90                 public short NoParameters {
91                         get { return wmf.num_of_params; }
92                         set { wmf.num_of_params = value; }
93                 }
94                 
95                 public int Size {
96                         get {
97                                 if (BitConverter.IsLittleEndian)
98                                         return (wmf.file_size_high << 16) | wmf.file_size_low;
99                                 else
100                                         return (wmf.file_size_low << 16) | wmf.file_size_high;
101                         }
102                         set {
103                                 if (BitConverter.IsLittleEndian) {
104                                         wmf.file_size_high = (ushort)(value >> 16);
105                                         wmf.file_size_low = (ushort)value;
106                                 } else {
107                                         wmf.file_size_high = (ushort)value;
108                                         wmf.file_size_low = (ushort)(value >> 16);
109                                 }
110                         }
111                 }
112
113                 public short Type {
114                         get { return wmf.file_type; }
115                         set { wmf.file_type = value; }
116                 }
117
118                 public short Version {
119                         get { return wmf.version; }
120                         set { wmf.version = value; }
121                 }
122         }
123 }