ARCed.Helpers.FontHelper.AddFont C# (CSharp) Method

AddFont() public static method

Adds a private memory font from a stream
The stream will be closed automatically after the font is loaded
public static AddFont ( Stream stream ) : void
stream Stream The stream to load the font from
return void
        public static void AddFont(Stream stream)
        {
            var ptr = Marshal.AllocCoTaskMem((int)stream.Length);
            var data = new byte[stream.Length];
            stream.Read(data, 0, (int)stream.Length);
            Marshal.Copy(data, 0, ptr, (int)stream.Length);
            FontCollection.AddMemoryFont(ptr, (int)stream.Length);
            stream.Close();
            Marshal.FreeCoTaskMem(ptr);
        }