[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / class / System.Drawing / System.Drawing.Imaging / MetafileHeader.cs
1 //
2 // System.Drawing.Imaging.MetafileHeader.cs
3 //
4 // Author: Everaldo Canuto
5 // eMail: everaldo.canuto@bol.com.br
6 // Dennis Hayes (dennish@raytek.com)
7 //
8 // (C) 2002 Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Drawing.Drawing2D;
32 using System.Runtime.InteropServices;
33
34 namespace System.Drawing.Imaging {
35
36         [StructLayout(LayoutKind.Sequential, Pack=2)]
37         struct EnhMetafileHeader {
38                 public int              type;
39                 public int              size;
40                 public Rectangle        bounds;
41                 public Rectangle        frame;
42                 public int              signature;
43                 public int              version;
44                 public int              bytes;
45                 public int              records;
46                 public short            handles;
47                 public short            reserved;
48                 public int              description;
49                 public int              off_description;
50                 public int              palette_entires;
51                 public Size             device;
52                 public Size             millimeters;
53         }
54
55         // hack: keep public type as Sequential while making it possible to get the required union
56         [StructLayout(LayoutKind.Explicit)]
57         struct MonoMetafileHeader {
58                 [FieldOffset (0)]
59                 public MetafileType     type;
60                 [FieldOffset (4)]
61                 public int              size;
62                 [FieldOffset (8)]
63                 public int              version;
64                 [FieldOffset (12)]
65                 public int              emf_plus_flags;
66                 [FieldOffset (16)]
67                 public float            dpi_x;
68                 [FieldOffset (20)]
69                 public float            dpi_y;
70                 [FieldOffset (24)]
71                 public int              x;
72                 [FieldOffset (28)]
73                 public int              y;
74                 [FieldOffset (32)]
75                 public int              width;
76                 [FieldOffset (36)]
77                 public int              height;
78                 [FieldOffset (40)]
79                 public WmfMetaHeader    wmf_header;
80                 [FieldOffset (40)]
81                 public EnhMetafileHeader emf_header;
82                 [FieldOffset (128)]
83                 public int              emfplus_header_size;
84                 [FieldOffset (132)]
85                 public int              logical_dpi_x;
86                 [FieldOffset (136)]
87                 public int              logical_dpi_y;
88         }
89
90         [MonoTODO ("Metafiles, both WMF and EMF formats, aren't supported.")]
91 #if !TARGET_JVM
92         [StructLayout(LayoutKind.Sequential)]
93 #endif
94         public sealed class MetafileHeader {
95
96                 private MonoMetafileHeader header;
97                 
98                 //constructor
99
100                 internal MetafileHeader (IntPtr henhmetafile)
101                 {
102                         Marshal.PtrToStructure (henhmetafile, this);
103                 }
104
105                 // methods
106
107                 [MonoTODO ("always returns false")]
108                 public bool IsDisplay ()
109                 {
110                         return false;
111                 }
112
113                 public bool IsEmf ()
114                 {
115                         return (Type == MetafileType.Emf);
116                 }
117
118                 public bool IsEmfOrEmfPlus ()
119                 {
120                         return (Type >= MetafileType.Emf);
121                 }
122
123                 public bool IsEmfPlus ()
124                 {
125                         return (Type >= MetafileType.EmfPlusOnly);
126                 }
127
128                 public bool IsEmfPlusDual ()
129                 {
130                         return (Type == MetafileType.EmfPlusDual);
131                 }
132
133                 public bool IsEmfPlusOnly ()
134                 {
135                         return (Type == MetafileType.EmfPlusOnly);
136                 }
137
138                 public bool IsWmf ()
139                 {
140                         return (Type <= MetafileType.WmfPlaceable);
141                 }
142
143                 public bool IsWmfPlaceable ()
144                 {
145                         return (Type == MetafileType.WmfPlaceable);
146                 }
147
148                 // properties
149
150                 public Rectangle Bounds {
151                         get { return new Rectangle (header.x, header.y, header.width, header.height); }
152                 }
153
154                 public float DpiX {
155                         get { return header.dpi_x; }
156                 }
157                 
158                 public float DpiY {
159                         get { return header.dpi_y; }
160                 }
161                 
162                 public int EmfPlusHeaderSize {
163                         get { return header.emfplus_header_size; }
164                 }
165
166                 public int LogicalDpiX {
167                         get { return header.logical_dpi_x; }
168                 }
169                 
170                 public int LogicalDpiY {
171                         get { return header.logical_dpi_y; }
172                 }
173
174                 public int MetafileSize {
175                         get { return header.size; }
176                 }
177
178                 public MetafileType Type {
179                         get { return header.type; }
180                 }
181
182                 public int Version {
183                         get { return header.version; }
184                 }
185
186                 // note: this always returns a new instance (where we can change
187                 // properties even if they don't seems to affect anything)
188                 public MetaHeader WmfHeader {
189                         get {
190                                 if (IsWmf ())
191                                          return new MetaHeader (header.wmf_header);
192                                 throw new ArgumentException ("WmfHeader only available on WMF files.");
193                         }
194                 }
195         }
196 }