2 // System.Drawing.Imaging.MetafileHeader.cs
4 // Author: Everaldo Canuto
5 // eMail: everaldo.canuto@bol.com.br
6 // Dennis Hayes (dennish@raytek.com)
8 // (C) 2002 Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
31 using System.Drawing.Drawing2D;
32 using System.Runtime.InteropServices;
34 namespace System.Drawing.Imaging {
36 [StructLayout(LayoutKind.Sequential, Pack=2)]
37 struct EnhMetafileHeader {
40 public Rectangle bounds;
41 public Rectangle frame;
47 public short reserved;
48 public int description;
49 public int off_description;
50 public int palette_entires;
52 public Size millimeters;
55 // hack: keep public type as Sequential while making it possible to get the required union
56 [StructLayout(LayoutKind.Explicit)]
57 struct MonoMetafileHeader {
59 public MetafileType type;
65 public int emf_plus_flags;
79 public WmfMetaHeader wmf_header;
81 public EnhMetafileHeader emf_header;
83 public int emfplus_header_size;
85 public int logical_dpi_x;
87 public int logical_dpi_y;
90 [MonoTODO ("Metafiles, both WMF and EMF formats, aren't supported.")]
92 [StructLayout(LayoutKind.Sequential)]
94 public sealed class MetafileHeader {
96 private MonoMetafileHeader header;
100 internal MetafileHeader (IntPtr henhmetafile)
102 Marshal.PtrToStructure (henhmetafile, this);
107 [MonoTODO ("always returns false")]
108 public bool IsDisplay ()
115 return (Type == MetafileType.Emf);
118 public bool IsEmfOrEmfPlus ()
120 return (Type >= MetafileType.Emf);
123 public bool IsEmfPlus ()
125 return (Type >= MetafileType.EmfPlusOnly);
128 public bool IsEmfPlusDual ()
130 return (Type == MetafileType.EmfPlusDual);
133 public bool IsEmfPlusOnly ()
135 return (Type == MetafileType.EmfPlusOnly);
140 return (Type <= MetafileType.WmfPlaceable);
143 public bool IsWmfPlaceable ()
145 return (Type == MetafileType.WmfPlaceable);
150 public Rectangle Bounds {
151 get { return new Rectangle (header.x, header.y, header.width, header.height); }
155 get { return header.dpi_x; }
159 get { return header.dpi_y; }
162 public int EmfPlusHeaderSize {
163 get { return header.emfplus_header_size; }
166 public int LogicalDpiX {
167 get { return header.logical_dpi_x; }
170 public int LogicalDpiY {
171 get { return header.logical_dpi_y; }
174 public int MetafileSize {
175 get { return header.size; }
178 public MetafileType Type {
179 get { return header.type; }
183 get { return header.version; }
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 {
191 return new MetaHeader (header.wmf_header);
192 throw new ArgumentException ("WmfHeader only available on WMF files.");