Merge pull request #1506 from akoeplinger/fix-paste-test
[mono.git] / mcs / class / System.Drawing / System.Drawing.Imaging / MetaHeader.cs
index 76f127fe30a0235b12e954c220b50b437b23ba97..c49a9628539fb2643b1503a0c9bfebd03fbc3c29 100644 (file)
@@ -8,7 +8,7 @@
 //   Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2002 Ximian, Inc.  http://www.ximian.com
-// Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2006-2007 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -34,58 +34,90 @@ using System.Runtime.InteropServices;
 
 namespace System.Drawing.Imaging {
 
-       [StructLayout (LayoutKind.Sequential)]
-       public sealed class MetaHeader {
-
+       [StructLayout (LayoutKind.Sequential, Pack=2)]
+       internal struct WmfMetaHeader {
                // field order match: http://wvware.sourceforge.net/caolan/ora-wmf.html
                // for WMFHEAD structure
-               private short file_type;
-               private short header_size;
-               private short version;
-               private int file_size;
-               private short num_of_objects;
-               private int max_record_size;
-               private short num_of_params;
+               public short file_type;
+               public short header_size;
+               public short version;
+               // this is unaligned and fails on the SPARC architecture (see bug #81254 for details)
+               // public int file_size;
+               public ushort file_size_low;
+               public ushort file_size_high;
+               public short num_of_objects;
+               public int max_record_size;
+               public short num_of_params;
+       }
+
+       [StructLayout (LayoutKind.Sequential)]
+       public sealed class MetaHeader {
 
+               private WmfMetaHeader wmf;
 
                public MetaHeader ()
                {
                }
 
+               internal MetaHeader (WmfMetaHeader header)
+               {
+                       wmf.file_type = header.file_type;
+                       wmf.header_size = header.header_size;
+                       wmf.version = header.version;
+                       wmf.file_size_low = header.file_size_low;
+                       wmf.file_size_high = header.file_size_high;
+                       wmf.num_of_objects = header.num_of_objects;
+                       wmf.max_record_size = header.max_record_size;
+                       wmf.num_of_params = header.num_of_params;
+               }
+
 
                public short HeaderSize {
-                       get { return header_size; }
-                       set { header_size = value; }
+                       get { return wmf.header_size; }
+                       set { wmf.header_size = value; }
                }
                
                public int MaxRecord {
-                       get { return max_record_size; }
-                       set { max_record_size = value; }
+                       get { return wmf.max_record_size; }
+                       set { wmf.max_record_size = value; }
                }
                
                public short NoObjects {
-                       get { return num_of_objects; }
-                       set { num_of_objects = value; }
+                       get { return wmf.num_of_objects; }
+                       set { wmf.num_of_objects = value; }
                }
                
                public short NoParameters {
-                       get { return num_of_params; }
-                       set { num_of_params = value; }
+                       get { return wmf.num_of_params; }
+                       set { wmf.num_of_params = value; }
                }
                
                public int Size {
-                       get { return file_size; }
-                       set { file_size = value; }
+                       get {
+                               if (BitConverter.IsLittleEndian)
+                                       return (wmf.file_size_high << 16) | wmf.file_size_low;
+                               else
+                                       return (wmf.file_size_low << 16) | wmf.file_size_high;
+                       }
+                       set {
+                               if (BitConverter.IsLittleEndian) {
+                                       wmf.file_size_high = (ushort)(value >> 16);
+                                       wmf.file_size_low = (ushort)value;
+                               } else {
+                                       wmf.file_size_high = (ushort)value;
+                                       wmf.file_size_low = (ushort)(value >> 16);
+                               }
+                       }
                }
 
                public short Type {
-                       get { return file_type; }
-                       set { file_type = value; }
+                       get { return wmf.file_type; }
+                       set { wmf.file_type = value; }
                }
 
                public short Version {
-                       get { return version; }
-                       set { version = value; }
+                       get { return wmf.version; }
+                       set { wmf.version = value; }
                }
        }
 }