FontCollection.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // System.Drawing.Text.FontCollection.cs
  3. //
  4. // (C) 2002 Ximian, Inc. http://www.ximian.com
  5. // Author: Everaldo Canuto [email protected]
  6. // Sanjay Gupta ([email protected])
  7. //
  8. using System;
  9. using System.Drawing;
  10. using System.Runtime.InteropServices;
  11. namespace System.Drawing.Text {
  12. public abstract class FontCollection : IDisposable {
  13. internal IntPtr nativeFontCollection = IntPtr.Zero;
  14. internal FontFamily[] families;
  15. internal FontCollection ()
  16. {
  17. }
  18. internal FontCollection ( IntPtr ptr )
  19. {
  20. nativeFontCollection = ptr;
  21. }
  22. // methods
  23. public void Dispose()
  24. {
  25. //Dispose ( true );
  26. if ( families != null ) {
  27. int length = families.Length;
  28. Status status;
  29. for ( int i = 0; i < length; i++){
  30. status = GDIPlus.GdipDeleteFontFamily ( families[i].NativeObject );
  31. GDIPlus.CheckStatus ( status );
  32. }
  33. }
  34. System.GC.SuppressFinalize ( this );
  35. }
  36. [MonoTODO]
  37. protected virtual void Dispose ( bool disposing )
  38. {
  39. //Nothing for now
  40. }
  41. // properties
  42. public FontFamily[] Families
  43. {
  44. get {
  45. int found;
  46. int returned;
  47. Status status;
  48. status = GDIPlus.GdipGetFontCollectionFamilyCount ( nativeFontCollection, out found );
  49. GDIPlus.CheckStatus ( status );
  50. int nSize = Marshal.SizeOf ( IntPtr.Zero );
  51. IntPtr dest = Marshal.AllocHGlobal ( nSize * found );
  52. status = GDIPlus.GdipGetFontCollectionFamilyList( nativeFontCollection, found, dest, out returned );
  53. GDIPlus.CheckStatus ( status );
  54. IntPtr[] ptrAr = new IntPtr [ returned ];
  55. int pos = dest.ToInt32 ();
  56. for ( int i = 0; i < returned ; i++, pos+=nSize )
  57. ptrAr[i] = (IntPtr)Marshal.PtrToStructure ( (IntPtr)pos, typeof(IntPtr) );
  58. Marshal.FreeHGlobal ( dest );
  59. families = new FontFamily [ returned ];
  60. for ( int i = 0; i < returned; i++ )
  61. families[i] = new FontFamily ( ptrAr[i] );
  62. return families;
  63. }
  64. }
  65. ~FontCollection()
  66. {
  67. Dispose ( false );
  68. }
  69. }
  70. }