Explorar o código

first version

svn path=/trunk/mcs/; revision=15554
Alexandre Pigolkine %!s(int64=22) %!d(string=hai) anos
pai
achega
78a8d6a17d

+ 2 - 0
mcs/class/System.Drawing/System.Drawing.Text/impl/ChangeLog

@@ -0,0 +1,2 @@
+2003-06-21 Alexandre Pigolkine ([email protected]) 
+	* ItfFontCollection.cs added

+ 17 - 0
mcs/class/System.Drawing/System.Drawing.Text/impl/ItfFontCollection.cs

@@ -0,0 +1,17 @@
+//
+// System.Drawing.Text.IFontCollection.cs
+//
+// Author: Alexandre Pigolkine ([email protected])
+//
+using System;
+
+namespace System.Drawing.Text {
+	internal interface IFontCollectionFactory {
+		IFontCollection InstalledFontCollection();
+		IFontCollection PrivateFontCollection();
+	}
+	
+	internal interface IFontCollection : IDisposable {
+		FontFamily[] Families { get; }
+	}
+}

+ 4 - 0
mcs/class/System.Drawing/System.Drawing.Text/impl/Xr/ChangeLog

@@ -0,0 +1,4 @@
+2003-06-21 Alexandre Pigolkine ([email protected]) 
+	* FontCollection.cs
+	* externLibs.cs	
+			added to CVS

+ 83 - 0
mcs/class/System.Drawing/System.Drawing.Text/impl/Xr/FontCollection.cs

@@ -0,0 +1,83 @@
+//
+// System.Drawing.Text.XrImpl.FontCollection.cs
+//
+// Author:
+//   Alexandre Pigolkine ([email protected])
+//
+//
+
+using System;
+using System.Text;
+using System.Runtime.InteropServices;
+using System.Collections;
+
+// FIXME: this factory is in the System.Drawing namespace to keep code in System.Drawing/Factories.cs as it is.
+// May be the following changes are needed:
+//    - implement a new Factories in the System.Drawing.Text or
+//    - modify code in existing Factories.cs to operate not only on System.Drawing namespace
+//
+
+namespace System.Drawing {
+	namespace XrImpl {
+
+		internal class FontCollectionFactory : System.Drawing.Text.IFontCollectionFactory {
+
+			System.Drawing.Text.IFontCollection System.Drawing.Text.IFontCollectionFactory.InstalledFontCollection(){
+				return new System.Drawing.Text.XrImpl.InstalledFontCollection();
+			}
+
+			System.Drawing.Text.IFontCollection System.Drawing.Text.IFontCollectionFactory.PrivateFontCollection() {
+				return new System.Drawing.Text.XrImpl.PrivateFontCollection();
+			}
+		}
+	}
+}
+
+namespace System.Drawing.Text {
+	namespace XrImpl	{
+
+		internal sealed class InstalledFontCollection : IFontCollection
+		{
+			ArrayList families;
+			
+			public void Dispose () {
+			}
+
+			public InstalledFontCollection(){
+				families = new ArrayList();
+				IntPtr fontSetPtr = Xft.XftListFontFamilies(IntPtr.Zero, 0, 0, Fontconfig.FC_FAMILY_PTR, 0);
+				if( fontSetPtr != IntPtr.Zero) {
+					FcFontSet fontSet = (FcFontSet)Marshal.PtrToStructure( fontSetPtr, typeof(FcFontSet));
+					if( fontSet.nfont > 0) {
+						int[] fontFamilyNamePtrs = new int[fontSet.nfont];
+						Marshal.Copy( fontSet.fonts, fontFamilyNamePtrs, 0, fontFamilyNamePtrs.Length);
+						IntPtr namePtr = IntPtr.Zero;
+						for( int i = 0; i < fontFamilyNamePtrs.Length; i++) {
+							int res = Fontconfig.FcPatternGetString(fontFamilyNamePtrs[i], Fontconfig.FC_FAMILY_PTR, 0, ref namePtr);
+							string name = Marshal.PtrToStringAnsi(namePtr);
+							//Console.WriteLine("InstalledFont : " + name);
+							families.Add( new FontFamily(name));
+						}
+					}
+				}
+			}
+			
+			public FontFamily[] Families {
+				get { return (FontFamily[])families.ToArray(typeof(FontFamily)); }
+			}
+		}
+		
+		internal sealed class PrivateFontCollection : IFontCollection
+		{
+			public void Dispose () {
+			}
+
+			public PrivateFontCollection(){
+			}
+			
+			public FontFamily[] Families {
+				get { throw new NotImplementedException(); }
+			}
+		}
+	}
+}

+ 53 - 0
mcs/class/System.Drawing/System.Drawing.Text/impl/Xr/externLibs.cs

@@ -0,0 +1,53 @@
+//
+// System.Drawing.Text.XrImpl.externLibs.cs
+//
+// Author:
+//   Alexandre Pigolkine ([email protected])
+//
+//
+
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace System.Drawing.Text {
+	namespace XrImpl	{
+	
+		[StructLayout(LayoutKind.Sequential)]
+		internal struct FcFontSet {
+			internal int nfont;
+            internal int sfont;
+            internal IntPtr fonts; // FcPattern **fonts;
+		}
+
+		internal enum FcResult : int {
+		    FcResultMatch, FcResultNoMatch, FcResultTypeMismatch, FcResultNoId
+		}
+
+		class Xft {
+		
+			const string XftImp = "Xft";
+		
+			[DllImport(XftImp, EntryPoint="XftListFonts")]
+			internal static extern IntPtr XftListFontFamilies (IntPtr dpy, int screen, int zero1, IntPtr FC_FAMILY_PTR, int zero2 );
+
+		}
+		
+		class Fontconfig {
+			const string FontconfigImp = "fontconfig";
+			
+			internal static string FC_FAMILY = "family";
+			internal static IntPtr FC_FAMILY_PTR;
+			
+			static Fontconfig() {
+				FC_FAMILY_PTR = Marshal.StringToHGlobalAnsi(FC_FAMILY);
+			}
+
+			[DllImport(FontconfigImp, CharSet = CharSet.Ansi)]
+			internal static extern int FcPatternGetString(IntPtr fcPattern, IntPtr obj, int n, ref IntPtr val);
+		
+			[DllImport(FontconfigImp, CharSet = CharSet.Ansi)]
+			internal static extern int FcPatternGetString(int fcPattern, IntPtr obj, int n, ref IntPtr val);
+		}
+	}
+}