PrivateFontCollection.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. if ( status != Status.Ok ){
  22. nativeFontCollection = IntPtr.Zero;
  23. throw new Exception ( "Error calling GDIPlus.GdipNewPrivateFontCollection: " + status );
  24. }
  25. }
  26. // methods
  27. [ComVisible(false)]
  28. public void AddFontFile( string filename )
  29. {
  30. if ( filename == null )
  31. throw new Exception ( "Value cannot be null, Parameter name : filename" );
  32. bool exists = File.Exists( filename );
  33. if ( !exists )
  34. throw new Exception ( "The path is not of a legal form" );
  35. Status status = GDIPlus.GdipPrivateAddFontFile ( nativeFontCollection, filename );
  36. if ( status != Status.Ok )
  37. throw new Exception ( "Error calling GDIPlus.GdipPrivateAddFontFile: " + status );
  38. }
  39. [ComVisible(false)]
  40. public void AddMemoryFont ( IntPtr memory, int length )
  41. {
  42. Status status = GDIPlus.GdipPrivateAddMemoryFont ( nativeFontCollection, memory, length );
  43. if ( status != Status.Ok )
  44. throw new Exception ( "Error calling GDIPlus.GdipPrivateAddFontFile: " + status );
  45. }
  46. }
  47. }