fixes font collection
[mono.git] / mcs / class / System.Drawing / System.Drawing.Text / FontCollection.cs
index 1b299d81687be47968501d0172612c0e77341478..7454fdbfd90e1d7b03dd56b0024b3b46478fe9ef 100644 (file)
@@ -7,6 +7,7 @@
 //
 using System;
 using System.Drawing;
+using System.Runtime.InteropServices;
 
 namespace System.Drawing.Text {
 
@@ -54,20 +55,31 @@ namespace System.Drawing.Text {
                                
                                Console.WriteLine("FamilyFont count returned in Families method of FontCollection " + found);
                                
-                               IntPtr [] family = new IntPtr [found];
-                               //FontFamily [] familyList = new FontFamily[found];
+                               int nSize =  Marshal.SizeOf(IntPtr.Zero);
+                               IntPtr dest = Marshal.AllocHGlobal(nSize* found);                       
                                
-                               status = GDIPlus.GdipGetFontCollectionFamilyList( nativeFontCollection, found, out family, out returned);
+                               status = GDIPlus.GdipGetFontCollectionFamilyList( nativeFontCollection, found, dest, out returned);
                                if (status != Status.Ok){
                                        Console.WriteLine("Error calling GDIPlus.GdipGetFontCollectionFamilyList: " +status);
                                        throw new Exception ("Error calling GDIPlus.GdipGetFontCollectionFamilyList: " +status);                                        
                                }
                                
+                               IntPtr[] ptrAr = new IntPtr[returned];
+                       
+                               int pos = dest.ToInt32();
+                               for (int i=0; i<returned; i++, pos+=nSize)
+                                       ptrAr[i] = (IntPtr) Marshal.PtrToStructure((IntPtr)pos, typeof(IntPtr));
+                       
+                               Marshal.FreeHGlobal(dest);                      
+                               
                                FontFamily [] familyList = new FontFamily[returned];
                                Console.WriteLine("No of FontFamilies returned in Families method of FontCollection " + returned);
                                for( int i = 0 ; i < returned ; i++ )
-                                       familyList [i] = new FontFamily( family[i] );
-                               //return implementation.Families;
+                               {
+                                       Console.WriteLine("Handle returned " + ptrAr[i]);
+                                       familyList [i] = new FontFamily(ptrAr[i]);
+                               }
+                               
                                return familyList; 
                        }
                }