2 // System.Drawing.FontFamily.cs
5 // Dennis Hayes (dennish@Raytek.com)
6 // Alexandre Pigolkine (pigolkine@gmx.de)
7 // Sanjay Gupta (gsanjay@novell.com)
9 // (C) 2002/2003 Ximian, Inc
12 using System.Drawing.Text;
14 namespace System.Drawing {
16 public sealed class FontFamily : MarshalByRefObject, IDisposable {
18 static FontFamily genericMonospace;
19 static FontFamily genericSansSerif;
20 static FontFamily genericSerif;
24 internal IntPtr nativeFontFamily = IntPtr.Zero;
26 internal FontFamily ( IntPtr ptr )
28 nativeFontFamily = ptr;
31 //Need to come back here, is Arial the right thing to do
32 internal FontFamily () : this ( "Arial", null )
37 public FontFamily ( GenericFontFamilies genericFamily )
41 public FontFamily ( string familyName ) : this( familyName, null )
45 public FontFamily ( string familyName, FontCollection collection )
48 if ( collection != null )
49 status = GDIPlus.GdipCreateFontFamilyFromName( familyName, collection.nativeFontCollection, out nativeFontFamily );
51 status = GDIPlus.GdipCreateFontFamilyFromName( familyName, IntPtr.Zero, out nativeFontFamily );
53 if ( status != Status.Ok ){
54 nativeFontFamily = IntPtr.Zero;
55 throw new Exception ( "Error calling GDIPlus.GdipCreateFontFamilyFromName: " + status );
66 public static FontFamily GenericMonospace {
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 );
75 genericMonospace = new FontFamily ( generic );
76 genericMonospace.name = "Courier New";
78 return genericMonospace;
82 public static FontFamily GenericSansSerif {
84 if ( genericSansSerif == null ) {
85 IntPtr generic = IntPtr.Zero;
86 Status status = GDIPlus.GdipGetGenericFontFamilySansSerif ( out generic );
87 if ( status != Status.Ok )
89 generic = IntPtr.Zero;
90 throw new Exception ( "Error calling GDIPlus.GdipGetGenericFontFamilySansSerif: " + status );
92 genericSansSerif = new FontFamily ( generic );
93 genericSansSerif.name = "Sans Serif";
95 return genericSansSerif;
99 public static FontFamily GenericSerif {
101 if ( genericSerif == null ) {
102 IntPtr generic = IntPtr.Zero;
103 Status status = GDIPlus.GdipGetGenericFontFamilySerif ( out generic );
104 if ( status != Status.Ok )
106 generic = IntPtr.Zero;
107 throw new Exception ( "Error calling GDIPlus.GdipGetGenericFontFamilySerif: " + status );
109 genericSerif = new FontFamily ( generic );
110 genericSerif.name = "Times New Roman";
116 public int GetCellAscent ( FontStyle style )
118 throw new NotImplementedException ();
121 public int GetCellDescent ( FontStyle style )
123 throw new NotImplementedException ();
126 public int GetEmHeight ( FontStyle style )
128 throw new NotImplementedException ();
131 public int GetLineSpacing ( FontStyle style )
133 throw new NotImplementedException ();
136 public bool IsStyleAvailable ( FontStyle style )
138 throw new NotImplementedException ();
141 public void Dispose()
144 if ( genericSerif != null ) {
145 status = GDIPlus.GdipDeleteFontFamily ( genericSerif.nativeFontFamily );
146 if ( status != Status.Ok )
147 genericSerif.nativeFontFamily = IntPtr.Zero;
150 if ( genericSansSerif != null )
152 status = GDIPlus.GdipDeleteFontFamily ( genericSansSerif.nativeFontFamily );
153 if ( status != Status.Ok )
154 genericSansSerif.nativeFontFamily = IntPtr.Zero;
157 if ( genericMonospace != null )
159 status = GDIPlus.GdipDeleteFontFamily ( genericMonospace.nativeFontFamily );
160 if ( status != Status.Ok )
161 genericMonospace.nativeFontFamily = IntPtr.Zero;
164 status = GDIPlus.GdipDeleteFontFamily ( nativeFontFamily );
165 if ( status != Status.Ok )
166 nativeFontFamily = IntPtr.Zero;