ChangeLog: Modified the ChangeLog
[mono.git] / mcs / class / System.Drawing / System.Drawing / FontFamily.cs
1 //
2 // System.Drawing.FontFamily.cs
3 //
4 // Author:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Alexandre Pigolkine (pigolkine@gmx.de)
7 //   Sanjay Gupta (gsanjay@novell.com)
8 //
9 // (C) 2002/2003 Ximian, Inc
10 //
11 using System;
12 using System.Drawing.Text;
13
14 namespace System.Drawing {
15
16         public sealed class FontFamily : MarshalByRefObject, IDisposable {
17                 
18                 static FontFamily genericMonospace;
19                 static FontFamily genericSansSerif;
20                 static FontFamily genericSerif;
21
22                 string name;
23
24                 internal IntPtr nativeFontFamily = IntPtr.Zero;
25                                 
26                 internal FontFamily ( IntPtr ptr )
27                 {
28                         nativeFontFamily = ptr;
29                 }
30                 
31                 //Need to come back here, is Arial the right thing to do
32                 internal FontFamily () : this ( "Arial", null )
33                 {
34                         //FIXME                                                         
35                 }
36
37                 public FontFamily ( GenericFontFamilies genericFamily ) 
38                 {
39                 }
40                 
41                 public FontFamily ( string familyName ) : this( familyName, null )
42                 {                       
43                 }
44                 
45                 public FontFamily ( string familyName, FontCollection collection ) 
46                 {
47                         Status status;
48                         if ( collection != null )
49                                 status = GDIPlus.GdipCreateFontFamilyFromName( familyName, collection.nativeFontCollection, out nativeFontFamily );
50                         else
51                                 status = GDIPlus.GdipCreateFontFamilyFromName( familyName, IntPtr.Zero, out nativeFontFamily );
52                                                 
53                         if ( status != Status.Ok ){
54                                 nativeFontFamily = IntPtr.Zero;
55                                 throw new Exception ( "Error calling GDIPlus.GdipCreateFontFamilyFromName: " + status );
56                         }
57                         name = familyName;
58                 }
59                 
60                 public string Name {
61                         get {
62                                 return name;
63                         }
64                 }
65                 
66                 public static FontFamily GenericMonospace {
67                         get {
68                                 if ( genericMonospace == null ) {
69                                         IntPtr generic = IntPtr.Zero;
70                                         Status status = GDIPlus.GdipGetGenericFontFamilyMonospace ( out generic );
71                                         if ( status != Status.Ok ) {
72                                                 generic = IntPtr.Zero;
73                                                 throw new Exception ( "Error calling GDIPlus.GdipGetGenericFontFamilyMonospace: " + status );
74                                         }
75                                         genericMonospace = new FontFamily ( generic );
76                                         genericMonospace.name = "Courier New";                                  
77                                 }
78                                 return genericMonospace;
79                         }
80                 }
81                 
82                 public static FontFamily GenericSansSerif {
83                         get {
84                                 if ( genericSansSerif == null ) {
85                                         IntPtr generic = IntPtr.Zero;
86                                         Status status = GDIPlus.GdipGetGenericFontFamilySansSerif ( out generic );
87                                         if ( status != Status.Ok ) 
88                                         {
89                                                 generic = IntPtr.Zero;
90                                                 throw new Exception ( "Error calling GDIPlus.GdipGetGenericFontFamilySansSerif: " + status );
91                                         }
92                                         genericSansSerif = new FontFamily ( generic );
93                                         genericSansSerif.name = "Sans Serif";                                   
94                                 }
95                                 return genericSansSerif;
96                         }
97                 }
98                 
99                 public static FontFamily GenericSerif {
100                         get {
101                                 if ( genericSerif == null ) {
102                                         IntPtr generic = IntPtr.Zero;
103                                         Status status = GDIPlus.GdipGetGenericFontFamilySerif ( out generic );
104                                         if ( status != Status.Ok ) 
105                                         {
106                                                 generic = IntPtr.Zero;
107                                                 throw new Exception ( "Error calling GDIPlus.GdipGetGenericFontFamilySerif: " + status );
108                                         }
109                                         genericSerif = new FontFamily ( generic );
110                                         genericSerif.name = "Times New Roman";                                  
111                                 }
112                                 return genericSerif;
113                         }
114                 }
115                 
116                 public int GetCellAscent ( FontStyle style ) 
117                 {
118                         throw new NotImplementedException ();
119                 }
120                 
121                 public int GetCellDescent ( FontStyle style ) 
122                 {
123                         throw new NotImplementedException ();
124                 }
125                 
126                 public int GetEmHeight ( FontStyle style ) 
127                 {
128                         throw new NotImplementedException ();
129                 }
130                 
131                 public int GetLineSpacing ( FontStyle style ) 
132                 {
133                         throw new NotImplementedException ();
134                 }
135                 
136                 public bool IsStyleAvailable ( FontStyle style )
137                 {
138                         throw new NotImplementedException ();
139                 }
140                 
141                 public void Dispose() 
142                 {
143                         Status status;
144                         if ( genericSerif != null ) {
145                                 status = GDIPlus.GdipDeleteFontFamily ( genericSerif.nativeFontFamily );
146                                 if ( status != Status.Ok ) 
147                                         genericSerif.nativeFontFamily = IntPtr.Zero;                                    
148                         }
149
150                         if ( genericSansSerif != null ) 
151                         {
152                                 status = GDIPlus.GdipDeleteFontFamily ( genericSansSerif.nativeFontFamily );
153                                 if ( status != Status.Ok ) 
154                                         genericSansSerif.nativeFontFamily = IntPtr.Zero;                                        
155                         }
156
157                         if ( genericMonospace != null ) 
158                         {
159                                 status = GDIPlus.GdipDeleteFontFamily ( genericMonospace.nativeFontFamily );
160                                 if ( status != Status.Ok ) 
161                                         genericMonospace.nativeFontFamily = IntPtr.Zero;                                        
162                         }
163
164                         status = GDIPlus.GdipDeleteFontFamily ( nativeFontFamily );
165                         if ( status != Status.Ok ) 
166                                 nativeFontFamily = IntPtr.Zero;                                 
167                         
168                 }
169         }
170 }
171