FontCollection.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // System.Drawing.Text.XrImpl.FontCollection.cs
  3. //
  4. // Author:
  5. // Alexandre Pigolkine ([email protected])
  6. //
  7. //
  8. using System;
  9. using System.Text;
  10. using System.Runtime.InteropServices;
  11. using System.Collections;
  12. // FIXME: this factory is in the System.Drawing namespace to keep code in System.Drawing/Factories.cs as it is.
  13. // May be the following changes are needed:
  14. // - implement a new Factories in the System.Drawing.Text or
  15. // - modify code in existing Factories.cs to operate not only on System.Drawing namespace
  16. //
  17. namespace System.Drawing {
  18. namespace XrImpl {
  19. internal class FontCollectionFactory : System.Drawing.Text.IFontCollectionFactory {
  20. System.Drawing.Text.IFontCollection System.Drawing.Text.IFontCollectionFactory.InstalledFontCollection(){
  21. return new System.Drawing.Text.XrImpl.InstalledFontCollection();
  22. }
  23. System.Drawing.Text.IFontCollection System.Drawing.Text.IFontCollectionFactory.PrivateFontCollection() {
  24. return new System.Drawing.Text.XrImpl.PrivateFontCollection();
  25. }
  26. }
  27. }
  28. }
  29. namespace System.Drawing.Text {
  30. namespace XrImpl {
  31. internal sealed class InstalledFontCollection : IFontCollection
  32. {
  33. ArrayList families;
  34. public void Dispose () {
  35. }
  36. public InstalledFontCollection(){
  37. families = new ArrayList();
  38. IntPtr fontSetPtr = Xft.XftListFontFamilies(IntPtr.Zero, 0, 0, Fontconfig.FC_FAMILY_PTR, 0);
  39. if( fontSetPtr != IntPtr.Zero) {
  40. FcFontSet fontSet = (FcFontSet)Marshal.PtrToStructure( fontSetPtr, typeof(FcFontSet));
  41. if( fontSet.nfont > 0) {
  42. int[] fontFamilyNamePtrs = new int[fontSet.nfont];
  43. Marshal.Copy( fontSet.fonts, fontFamilyNamePtrs, 0, fontFamilyNamePtrs.Length);
  44. IntPtr namePtr = IntPtr.Zero;
  45. for( int i = 0; i < fontFamilyNamePtrs.Length; i++) {
  46. int res = Fontconfig.FcPatternGetString(fontFamilyNamePtrs[i], Fontconfig.FC_FAMILY_PTR, 0, ref namePtr);
  47. string name = Marshal.PtrToStringAnsi(namePtr);
  48. //Console.WriteLine("InstalledFont : " + name);
  49. families.Add( new FontFamily(name));
  50. }
  51. }
  52. }
  53. }
  54. public FontFamily[] Families {
  55. get { return (FontFamily[])families.ToArray(typeof(FontFamily)); }
  56. }
  57. }
  58. internal sealed class PrivateFontCollection : IFontCollection
  59. {
  60. public void Dispose () {
  61. }
  62. public PrivateFontCollection(){
  63. }
  64. public FontFamily[] Families {
  65. get { throw new NotImplementedException(); }
  66. }
  67. }
  68. }
  69. }