7454fdbfd90e1d7b03dd56b0024b3b46478fe9ef
[mono.git] / mcs / class / System.Drawing / System.Drawing.Text / FontCollection.cs
1 //
2 // System.Drawing.Text.FontCollection.cs
3 //
4 // (C) 2002 Ximian, Inc.  http://www.ximian.com
5 // Author: Everaldo Canuto everaldo.canuto@bol.com.br
6 //                      Sanjay Gupta (gsanjay@novell.com)
7 //
8 using System;
9 using System.Drawing;
10 using System.Runtime.InteropServices;
11
12 namespace System.Drawing.Text {
13
14         public abstract class FontCollection : IDisposable {
15                 
16                 //internal IFontCollection implementation;
17                 internal IntPtr nativeFontCollection = IntPtr.Zero;
18                                 
19                 internal FontCollection ()
20                 {
21                 }
22         
23         internal FontCollection (IntPtr ptr)
24                 {
25                         nativeFontCollection = ptr;
26                 }
27
28                 // methods
29                 public void Dispose()
30                 {
31                         Dispose (true);
32                         System.GC.SuppressFinalize (this);
33                 }
34
35                 [MonoTODO]
36                 protected virtual void Dispose (bool disposing)
37                 {
38                         //Nothing for now
39                 }
40
41                 // properties
42                 public FontFamily[] Families
43                 {
44                         get { 
45                                 int found;
46                                 int returned;
47                                 Status status;
48                                 
49                                 Console.WriteLine("came to Families method of FontCollection");
50                                 
51                                 status = GDIPlus.GdipGetFontCollectionFamilyCount( nativeFontCollection, out found);
52                                 if (status != Status.Ok){
53                                         throw new Exception ("Error calling GDIPlus.GdipGetFontCollectionFamilyCount: " +status);
54                                 }
55                                 
56                                 Console.WriteLine("FamilyFont count returned in Families method of FontCollection " + found);
57                                 
58                                 int nSize =  Marshal.SizeOf(IntPtr.Zero);
59                                 IntPtr dest = Marshal.AllocHGlobal(nSize* found);                       
60                                 
61                                 status = GDIPlus.GdipGetFontCollectionFamilyList( nativeFontCollection, found, dest, out returned);
62                                 if (status != Status.Ok){
63                                         Console.WriteLine("Error calling GDIPlus.GdipGetFontCollectionFamilyList: " +status);
64                                         throw new Exception ("Error calling GDIPlus.GdipGetFontCollectionFamilyList: " +status);                                        
65                                 }
66                                 
67                                 IntPtr[] ptrAr = new IntPtr[returned];
68                         
69                                 int pos = dest.ToInt32();
70                                 for (int i=0; i<returned; i++, pos+=nSize)
71                                         ptrAr[i] = (IntPtr) Marshal.PtrToStructure((IntPtr)pos, typeof(IntPtr));
72                         
73                                 Marshal.FreeHGlobal(dest);                      
74                                 
75                                 FontFamily [] familyList = new FontFamily[returned];
76                                 Console.WriteLine("No of FontFamilies returned in Families method of FontCollection " + returned);
77                                 for( int i = 0 ; i < returned ; i++ )
78                                 {
79                                         Console.WriteLine("Handle returned " + ptrAr[i]);
80                                         familyList [i] = new FontFamily(ptrAr[i]);
81                                 }
82                                 
83                                 return familyList; 
84                         }
85                 }
86
87                 ~FontCollection()
88                 {
89                         Dispose (false);
90                 }
91
92         }
93
94 }