Advertisement
atillabyte

Untitled

Jun 13th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1.  
  2.         #region Font Import
  3.         [DllImport("gdi32.dll")]
  4.         private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
  5.         FontFamily ff;
  6.         Font Font9;
  7.         Font Font7;
  8.         Font DaFont;
  9.         int Percent = 0;
  10.         private void CargoPrivateFontCollection()
  11.         {
  12.             // Create the byte array and get its length
  13.  
  14.             byte[] fontArray = EEWorldViewer.Properties.Resources.nokiafc22;
  15.             int dataLength = EEWorldViewer.Properties.Resources.nokiafc22.Length;
  16.  
  17.  
  18.             // ASSIGN MEMORY AND COPY  BYTE[] ON THAT MEMORY ADDRESS
  19.             IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
  20.             Marshal.Copy(fontArray, 0, ptrData, dataLength);
  21.  
  22.  
  23.             uint cFonts = 0;
  24.             AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);
  25.  
  26.             PrivateFontCollection pfc = new PrivateFontCollection();
  27.             //PASS THE FONT TO THE  PRIVATEFONTCOLLECTION OBJECT
  28.             pfc.AddMemoryFont(ptrData, dataLength);
  29.  
  30.             //FREE THE  "UNSAFE" MEMORY
  31.             Marshal.FreeCoTaskMem(ptrData);
  32.  
  33.             ff = pfc.Families[0];
  34.             Font9 = new Font(ff, 9);
  35.             Font7 = new Font(ff, 7);
  36.             DaFont = new Font(ff, 12);
  37.         }
  38.         #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement