PrivateFontCollection.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // System.Drawing.Text.PrivateFontCollection.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.IO;
  10. using System.Drawing;
  11. using System.Runtime.InteropServices;
  12. namespace System.Drawing.Text {
  13. [ComVisible(false)]
  14. public sealed class PrivateFontCollection : FontCollection {
  15. // constructors
  16. internal PrivateFontCollection (IntPtr ptr): base (ptr)
  17. {}
  18. public PrivateFontCollection()
  19. {
  20. Status status = GDIPlus.GdipNewPrivateFontCollection (out nativeFontCollection);
  21. GDIPlus.CheckStatus (status);
  22. }
  23. // methods
  24. public void AddFontFile(string filename)
  25. {
  26. if ( filename == null )
  27. throw new Exception ("Value cannot be null, Parameter name : filename");
  28. bool exists = File.Exists(filename);
  29. if (!exists)
  30. throw new Exception ("The path is not of a legal form");
  31. Status status = GDIPlus.GdipPrivateAddFontFile (nativeFontCollection, filename);
  32. GDIPlus.CheckStatus (status);
  33. }
  34. public void AddMemoryFont(IntPtr memory, int length)
  35. {
  36. Status status = GDIPlus.GdipPrivateAddMemoryFont (nativeFontCollection, memory, length);
  37. GDIPlus.CheckStatus (status);
  38. }
  39. // methods
  40. protected override void Dispose(bool disposing)
  41. {
  42. if (nativeFontCollection!=IntPtr.Zero){
  43. GDIPlus.GdipDeletePrivateFontCollection (nativeFontCollection);
  44. GC.SuppressFinalize(this);
  45. }
  46. }
  47. }
  48. }