2006-03-23 Peter Dennis Bartok <pbartok@novell.com>
authorPeter Dennis Bartok <pbartok@mono-cvs.ximian.com>
Thu, 23 Mar 2006 07:34:16 +0000 (07:34 -0000)
committerPeter Dennis Bartok <pbartok@mono-cvs.ximian.com>
Thu, 23 Mar 2006 07:34:16 +0000 (07:34 -0000)
* gdipFunctions.cs:
  - GdipGetFontCollectionFamilyList: No need for complicated
    GlobalAlloc stuff, .Net marshals the IntPtr[] array just fine
  - GdipDeletePrivateFontCollection: We need to pass a ref to the
    structure. This was causing nasty crashes.
  - GdipGetFamilyName: Switched to use StringBuilder instead of
    manual marshalling
* FontFamily.cs: Simplified the refreshName method, less error-prone now

2006-03-23  Peter Dennis Bartok  <pbartok@novell.com>

* FontCollection.cs (get_Families): Now letting the runtime do the
  marshalling work for us. Easier to maintain and cleaner code.
* PrivateFontCollection.cs:
  - AddFontFile: Fixed weird english in error message
  - Dispose: Need to pass ref to the native object, we were crashing
    badly

svn path=/trunk/mcs/; revision=58338

mcs/class/System.Drawing/System.Drawing.Text/ChangeLog
mcs/class/System.Drawing/System.Drawing.Text/FontCollection.cs
mcs/class/System.Drawing/System.Drawing.Text/PrivateFontCollection.cs
mcs/class/System.Drawing/System.Drawing/ChangeLog
mcs/class/System.Drawing/System.Drawing/FontFamily.cs
mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs

index 7066c72ca510cac925c150e6efa6cb1edf69325f..c362e6019f88baee514f7ca7ca288096b1741bd6 100644 (file)
@@ -1,3 +1,12 @@
+2006-03-23  Peter Dennis Bartok  <pbartok@novell.com>
+
+       * FontCollection.cs (get_Families): Now letting the runtime do the
+         marshalling work for us. Easier to maintain and cleaner code.
+       * PrivateFontCollection.cs:
+         - AddFontFile: Fixed weird english in error message
+         - Dispose: Need to pass ref to the native object, we were crashing
+           badly
+
 2006-02-09  Peter Dennis Bartok  <pbartok@novell.com>
 
        * ChangeLog: Created, contents from deleted 'changelog' file
index 4c8782926e431d59e32a11d14b5a99e58d3c0dd7..b01d65d540575c63f0797c3d7bbed4afae4ed47c 100644 (file)
@@ -3,11 +3,11 @@
 //
 // (C) 2002 Ximian, Inc.  http://www.ximian.com
 // Author: Everaldo Canuto everaldo.canuto@bol.com.br
-//                     Sanjay Gupta (gsanjay@novell.com)
+//             Sanjay Gupta (gsanjay@novell.com)
+//             Peter Dennis Bartok (pbartok@novell.com)
 //
-
 //
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004 - 2006 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -66,19 +66,19 @@ namespace System.Drawing.Text {
                                int returned;
                                Status status;
                                FontFamily[] families;
+                               IntPtr[] result;
                                
                                status = GDIPlus.GdipGetFontCollectionFamilyCount (nativeFontCollection, out found);
                                GDIPlus.CheckStatus (status);
                                
-                               IntPtr dest = Marshal.AllocHGlobal (IntPtr.Size * found);           
-               
-                               status = GDIPlus.GdipGetFontCollectionFamilyList(nativeFontCollection, found, dest, out returned);
+                               result = new IntPtr[found];
+                               status = GDIPlus.GdipGetFontCollectionFamilyList(nativeFontCollection, found, result, out returned);
                                   
                                families = new FontFamily [returned];
-                               for ( int i = 0; i < returned ; i++)
-                                       families[i] = new FontFamily(Marshal.ReadIntPtr (dest, i * IntPtr.Size));
+                               for ( int i = 0; i < returned ; i++) {
+                                       families[i] = new FontFamily(result[i]);
+                               }
            
-                               Marshal.FreeHGlobal (dest);           
                                return families;               
                        }
                }
index 919a5dde5c188bf97e463fcdfd9fcfb32cac7f60..e332fe4c89cf5ce3c58c1acf99b3160009eca934 100644 (file)
@@ -4,10 +4,10 @@
 // (C) 2002 Ximian, Inc.  http://www.ximian.com
 // Author: Everaldo Canuto everaldo.canuto@bol.com.br
 //             Sanjay Gupta (gsanjay@novell.com)
+//             Peter Dennis Bartok (pbartok@novell.com)
 //
-
 //
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004 - 2006 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -57,7 +57,7 @@ namespace System.Drawing.Text {
                                throw new Exception ("Value cannot be null, Parameter name : filename");
                        bool exists = File.Exists(filename);
                        if (!exists)
-                               throw new Exception ("The path is not of a legal form");
+                               throw new Exception ("The specified file does not exist");
 
                        Status status = GDIPlus.GdipPrivateAddFontFile (nativeFontCollection, filename);
                        GDIPlus.CheckStatus (status);                   
@@ -72,8 +72,8 @@ namespace System.Drawing.Text {
                // methods      
                protected override void Dispose(bool disposing)
                {
-                       if (nativeFontCollection!=IntPtr.Zero){                         
-                               GDIPlus.GdipDeletePrivateFontCollection (nativeFontCollection);                                                 
+                       if (nativeFontCollection!=IntPtr.Zero){
+                               GDIPlus.GdipDeletePrivateFontCollection (ref nativeFontCollection);                                                     
                                nativeFontCollection = IntPtr.Zero;
                        }
                        
index ebc7fe1eafc0ff784e013a5a47ce0494fdd3cf6f..6ebfd20de5f6b24165d759748787762600d54a02 100644 (file)
@@ -1,3 +1,14 @@
+2006-03-23  Peter Dennis Bartok  <pbartok@novell.com>
+
+       * gdipFunctions.cs: 
+         - GdipGetFontCollectionFamilyList: No need for complicated 
+           GlobalAlloc stuff, .Net marshals the IntPtr[] array just fine
+         - GdipDeletePrivateFontCollection: We need to pass a ref to the
+           structure. This was causing nasty crashes.
+         - GdipGetFamilyName: Switched to use StringBuilder instead of
+           manual marshalling
+       * FontFamily.cs: Simplified the refreshName method, less error-prone now
+
 2006-03-21  Sebastien Pouliot  <sebastien@ximian.com> 
  
        * Brush.cs: Remove unused code.
index b164e38bbe28d51fcd0ffe6c3b32beea88b901cb..fc9704ad80a5e8f1049c49773b9ae69dec3026ae 100644 (file)
@@ -4,9 +4,10 @@
 // Author:
 //   Dennis Hayes (dennish@Raytek.com)
 //   Alexandre Pigolkine (pigolkine@gmx.de)
+//   Peter Dennis Bartok (pbartok@novell.com)
 //
 // Copyright (C) 2002/2004 Ximian, Inc http://www.ximian.com
-// Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004 - 2006 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -51,21 +52,15 @@ namespace System.Drawing {
                
                internal void refreshName()
                {
+                       StringBuilder sb;
+
                        if (nativeFontFamily == IntPtr.Zero)
                                return;
 
-                       int language = 0;                       
-                       IntPtr buffer = IntPtr.Zero;
-                       try {
-                               buffer = Marshal.AllocHGlobal(GDIPlus.FACESIZE * UnicodeEncoding.CharSize);
-                               Status status = GDIPlus.GdipGetFamilyName (nativeFontFamily, buffer, language);
-                               GDIPlus.CheckStatus (status);
-                               name = Marshal.PtrToStringUni(buffer);
-                       }
-                       finally {
-                               if (buffer != IntPtr.Zero)
-                                       Marshal.FreeHGlobal (buffer);
-                       }
+                       sb = new StringBuilder(GDIPlus.FACESIZE);
+                       Status status = GDIPlus.GdipGetFamilyName (nativeFontFamily, sb, 0);
+                       GDIPlus.CheckStatus (status);
+                       name = sb.ToString();
                }
                
                //Need to come back here, is Arial the right thing to do
index 0994898308071954604ee431a57f8361d62a7061..0236a5223b1934c0094ee2bc8aed76f9ed98beba 100644 (file)
@@ -6,8 +6,9 @@
 //     Jordi Mas i Hernandez (jordi@ximian.com)
 //     Sanjay Gupta (gsanjay@novell.com)
 //     Ravindra (rkumar@novell.com)
+//     Peter Dennis Bartok (pbartok@novell.com)
 //
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004 - 2006 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -1455,7 +1456,7 @@ namespace System.Drawing
                internal static extern Status GdipGetFontCollectionFamilyCount (IntPtr collection, out int found);
                
                [DllImport ("gdiplus.dll")]
-               internal static extern Status GdipGetFontCollectionFamilyList (IntPtr collection, int getCount, IntPtr dest, out int retCount);
+               internal static extern Status GdipGetFontCollectionFamilyList (IntPtr collection, int getCount, IntPtr[] dest, out int retCount);
                //internal static extern Status GdipGetFontCollectionFamilyList( IntPtr collection, int getCount, [Out] FontFamily [] familyList, out int retCount );
                
                [DllImport ("gdiplus.dll")]
@@ -1465,7 +1466,7 @@ namespace System.Drawing
                internal static extern Status GdipNewPrivateFontCollection (out IntPtr collection);
                
                [DllImport ("gdiplus.dll")]
-               internal static extern Status GdipDeletePrivateFontCollection (IntPtr collection);
+               internal static extern Status GdipDeletePrivateFontCollection (ref IntPtr collection);
                
                [DllImport ("gdiplus.dll", CharSet=CharSet.Auto)]
                internal static extern Status GdipPrivateAddFontFile (IntPtr collection,
@@ -1479,8 +1480,8 @@ namespace System.Drawing
                internal static extern Status GdipCreateFontFamilyFromName (
                         [MarshalAs(UnmanagedType.LPWStr)] string fName, IntPtr collection, out IntPtr fontFamily);
 
-               [DllImport ("gdiplus.dll")]
-               internal static extern Status GdipGetFamilyName(IntPtr family, IntPtr fName, int language);
+               [DllImport ("gdiplus.dll", CharSet=CharSet.Unicode)]
+               internal static extern Status GdipGetFamilyName(IntPtr family, StringBuilder name, int language);
 
                [DllImport ("gdiplus.dll")]
                internal static extern Status GdipGetGenericFontFamilySansSerif (out IntPtr fontFamily);