- Timestamp:
- Nov 27, 2007, 1:58:27 AM (13 years ago)
- Location:
- libcaca/trunk/csharp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/csharp/Cucul.cs
r2080 r2081 718 718 /* </FIXME> */ 719 719 } 720 721 public class CuculFont : IDisposable 722 { 723 private IntPtr _font; 724 private GCHandle _gch; 725 726 [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), 727 SuppressUnmanagedCodeSecurity] 728 private static extern IntPtr cucul_load_font(IntPtr data, int len); 729 public CuculFont(string s) 730 { 731 IntPtr name = Marshal.StringToHGlobalAnsi(s); 732 _font = cucul_load_font(name, 0); 733 Marshal.FreeHGlobal(name); 734 } 735 736 public CuculFont(byte[] buf) 737 { 738 GCHandle _gch = GCHandle.Alloc(buf, GCHandleType.Pinned); 739 _font = cucul_load_font(_gch.AddrOfPinnedObject(), buf.Length); 740 } 741 742 [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), 743 SuppressUnmanagedCodeSecurity] 744 private static extern int cucul_free_font(IntPtr d); 745 public void Dispose() 746 { 747 cucul_free_font(_font); 748 _gch.Free(); 749 GC.SuppressFinalize(this); 750 } 751 752 [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), 753 SuppressUnmanagedCodeSecurity] 754 private static extern IntPtr cucul_get_font_list(); 755 public static string[] getList() 756 { 757 IntPtr l = cucul_get_font_list(); 758 759 int size; 760 for(size = 0; true; size++) 761 if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero) 762 break; 763 764 string[] ret = new string[size]; 765 for(int i = 0; i < size; i++) 766 { 767 IntPtr s = Marshal.ReadIntPtr(l, IntPtr.Size * i); 768 ret[i] = Marshal.PtrToStringAnsi(s); 769 } 770 771 return ret; 772 } 773 774 [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), 775 SuppressUnmanagedCodeSecurity] 776 private static extern int cucul_get_font_width(IntPtr font); 777 [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), 778 SuppressUnmanagedCodeSecurity] 779 private static extern int cucul_get_font_height(IntPtr font); 780 public Size Size 781 { 782 get { return new Size(cucul_get_font_width(_font), 783 cucul_get_font_height(_font)); } 784 } 785 786 [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), 787 SuppressUnmanagedCodeSecurity] 788 private static extern IntPtr cucul_get_font_blocks(IntPtr font); 789 public int[,] getBlocks() 790 { 791 IntPtr l = cucul_get_font_blocks(_font); 792 793 int size; 794 for(size = 1; true; size += 2) 795 if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero) 796 break; 797 798 int[,] ret = new int[size,2]; 799 for(int i = 0; i < size; i++) 800 { 801 ret[i,0] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2); 802 ret[i,1] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2 + 1); 803 } 804 805 return ret; 806 } 807 } 720 808 } 721 809 -
libcaca/trunk/csharp/test.cs
r2080 r2081 28 28 private DateTime startTime; 29 29 private CuculDither d; 30 private CuculFont f; 30 31 31 32 public DemoCanvas() … … 36 37 d = new CuculDither(32, new Size(16, 16), 16 * 4, 37 38 0xff0000, 0xff00, 0xff, 0x0); 39 f = new CuculFont(CuculFont.getList()[0]); 40 f.getBlocks(); 38 41 } 39 42
Note: See TracChangeset
for help on using the changeset viewer.