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.")]
91 [StructLayout(LayoutKind.Sequential)]
92 public sealed class MetafileHeader {
94 private MonoMetafileHeader header;
98 internal MetafileHeader (IntPtr henhmetafile)
100 Marshal.PtrToStructure (henhmetafile, this);
105 [MonoTODO ("always returns false")]
106 public bool IsDisplay ()
113 return (Type == MetafileType.Emf);
116 public bool IsEmfOrEmfPlus ()
118 return (Type >= MetafileType.Emf);
121 public bool IsEmfPlus ()
123 return (Type >= MetafileType.EmfPlusOnly);
126 public bool IsEmfPlusDual ()
128 return (Type == MetafileType.EmfPlusDual);
131 public bool IsEmfPlusOnly ()
133 return (Type == MetafileType.EmfPlusOnly);
138 return (Type <= MetafileType.WmfPlaceable);
141 public bool IsWmfPlaceable ()
143 return (Type == MetafileType.WmfPlaceable);
148 public Rectangle Bounds {
149 get { return new Rectangle (header.x, header.y, header.width, header.height); }
153 get { return header.dpi_x; }
157 get { return header.dpi_y; }
160 public int EmfPlusHeaderSize {
161 get { return header.emfplus_header_size; }
164 public int LogicalDpiX {
165 get { return header.logical_dpi_x; }
168 public int LogicalDpiY {
169 get { return header.logical_dpi_y; }
172 public int MetafileSize {
173 get { return header.size; }
176 public MetafileType Type {
177 get { return header.type; }
181 get { return header.version; }
184 // note: this always returns a new instance (where we can change
185 // properties even if they don't seems to affect anything)
186 public MetaHeader WmfHeader {
189 return new MetaHeader (header.wmf_header);
190 throw new ArgumentException ("WmfHeader only available on WMF files.");