use proper marshalling now that 53700 is fixed
[mono.git] / mcs / class / System.Drawing / System.Drawing / Font.cs
1 //
2 // System.Drawing.Fonts.cs
3 //
4 // (C) 2004 Ximian, Inc.  http://www.ximian.com
5 //
6 // Authors: 
7
8
9 using System.Runtime.Serialization;
10 using System.Runtime.InteropServices;
11 using System.ComponentModel;
12
13 namespace System.Drawing {
14
15         [Serializable]
16         [ComVisible (true)]
17         [Editor ("System.Drawing.Design.FontEditor, " + Consts.AssemblySystem_Drawing_Design, typeof (System.Drawing.Design.UITypeEditor))]
18         [TypeConverter(typeof(FontConverter))]
19         public sealed class Font : MarshalByRefObject, ISerializable, ICloneable, IDisposable
20         {
21                 IntPtr  fontObject = IntPtr.Zero;
22                 
23         private Font (SerializationInfo info, StreamingContext context)
24                 {
25                 }
26
27                 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
28                 {
29                 }
30
31                 public void Dispose ()
32                 {
33                         if (fontObject!=IntPtr.Zero)
34                         {
35                                 GDIPlus.GdipDeleteFont(fontObject);                     
36                                 GC.SuppressFinalize(this);
37                         }
38                 }
39                 
40                 internal void setProperties(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical)                  
41                 {
42                         //Todo: Handle unit conversions
43                         _name=family.Name;
44                         _fontFamily = family;
45                         _size = emSize;
46                         _unit = unit;
47                         _style = style;
48                         _gdiCharSet = charSet;
49                         _gdiVerticalFont = isVertical;
50                         _sizeInPoints = emSize;
51                         
52                         _bold = _italic = _strikeout = _underline = false;
53                         
54                         switch (style) {
55                         case FontStyle.Bold: 
56                                 _bold = true;
57                                 break;
58                         case FontStyle.Italic:
59                                 _italic = true;
60                                 break;
61                         case FontStyle.Regular:
62                                 break;
63                         case FontStyle.Strikeout:
64                                 _strikeout = true;
65                                 break;
66                         case FontStyle.Underline:
67                                 _underline = true;
68                                 break;
69                         default:
70                                 break;
71                         }                       
72                 }
73
74                 public static Font FromHfont(IntPtr font)
75                 {
76                         // FIXME: 
77                         Font result = new Font("Arial", (float)12.0, FontStyle.Regular);
78                         return result;
79                 }
80
81                 public IntPtr ToHfont () {      /*throw new NotImplementedException ();*/ return (IntPtr)100; }
82
83                 public Font(Font original, FontStyle style)
84                 {
85                         _bold = original.Bold;
86                         _fontFamily = original.FontFamily;
87                         _gdiCharSet = original.GdiCharSet;
88                         _gdiVerticalFont = original.GdiVerticalFont;
89                         _height = original.Height;
90                         _italic = original.Italic;
91                         _name = original.Name;
92                         _size = original.Size;
93                         _sizeInPoints = original.SizeInPoints;
94                         _strikeout = original.Strikeout;
95                         _underline = original.Underline;
96                         _unit = original.Unit;
97                         _style = style;
98                 }
99
100                 public Font(FontFamily family, float emSize)
101                         : this(family, emSize, FontStyle.Regular, GraphicsUnit.Point, (byte)0, false)
102                 {
103                 }
104
105                 public Font(FontFamily family, float emSize, FontStyle style)
106                         : this(family, emSize, style, GraphicsUnit.Point, (byte)0, false)
107                 {
108                 }
109
110                 public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit)
111                         : this(family, emSize, style, unit, (byte)0, false)
112                 {
113                 }
114
115                 public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte charSet)
116                         : this(family, emSize, style, unit, charSet, false)
117                 {
118                 }
119                 
120                 public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical)
121                 {                       
122                         GDIPlus.GdipCreateFont(family.NativeObject,     emSize,  style,   unit,  out fontObject);               
123                         setProperties(family, emSize, style, unit, charSet, isVertical);
124                 }
125
126                 public Font(string familyName, float emSize)
127                         : this(familyName, emSize, FontStyle.Regular, GraphicsUnit.Point, (byte)0, false)
128                 {
129                 }
130
131                 public Font(string familyName, float emSize, FontStyle style)
132                         : this(familyName, emSize, style, GraphicsUnit.Point, (byte)0, false)
133                 {
134                 }
135                 
136                 public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit)
137                         : this(familyName, emSize, style, unit, (byte)0, false)
138                 {
139                 }
140                 
141                 public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte charSet)
142                         : this(familyName, emSize, style, unit, charSet, false)
143                 {
144                 }
145                 
146                 public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical)                  
147                 {
148                         FontFamily family = new FontFamily(familyName);                 
149                         GDIPlus.GdipCreateFont(family.NativeObject,     emSize,  style,   unit,  out fontObject);               
150                         
151                         setProperties(family, emSize, style, unit, charSet, isVertical);
152                 }
153                 
154                 
155                 object ICloneable.Clone()
156                 {
157                         throw new NotImplementedException ();
158                 }
159                 
160                 internal IntPtr NativeObject{            
161                         get{
162                                         return fontObject;
163                         }
164                         set     {
165                                         fontObject = value;
166                         }
167                 }
168                 
169                 private bool _bold;
170                 public bool Bold {
171                         get {
172                                 return _bold;
173                         }
174                 }
175                 
176                 private FontFamily _fontFamily;
177                 public FontFamily FontFamily {
178                         get {
179                                 return _fontFamily;
180                         }
181                 }
182                 
183                 private byte _gdiCharSet;
184                 public byte GdiCharSet {
185                         get {
186                                 return _gdiCharSet;
187                         }
188                 }
189                 
190                 private bool _gdiVerticalFont;
191                 public bool GdiVerticalFont {
192                         get {
193                                 return _gdiVerticalFont;
194                         }
195                 }
196                 
197                 private int _height;
198                 public int Height {
199                         get {
200                                 return _height;
201                         }
202                 }
203
204                 private bool _italic;
205                 public bool Italic {
206                         get {
207                                 return _italic;
208                         }
209                 }
210
211                 private string _name;
212                 public string Name {
213                         get {
214                                 return _name;
215                         }
216                 }
217
218                 private float _size;
219                 public float Size {
220                         get {
221                                 return _size;
222                         }
223                 }
224
225                 private float _sizeInPoints;
226                 public float SizeInPoints {
227                         get {
228                                 return _sizeInPoints;
229                         }
230                 }
231
232                 private bool _strikeout;
233                 public bool Strikeout {
234                         get {
235                                 return _strikeout;
236                         }
237                 }
238                 
239                 private FontStyle _style;
240                 public FontStyle Style {
241                         get {
242                                 return _style;
243                         }
244                 }
245
246                 private bool _underline;
247                 public bool Underline {
248                         get {
249                                 return _underline;
250                         }
251                 }
252
253                 private GraphicsUnit _unit;
254                 public GraphicsUnit Unit {
255                         get {
256                                 return _unit;
257                         }
258                 }
259         }
260 }