Exemple #1
0
        private static Font GetFont(byte[] fontData, float emSize, FontStyle fontStyle, GraphicsUnit graphicsUnit, byte gdiCharSet, bool gdiVerticalFont)
        {
            IntPtr unsafeMemoryBlock = Marshal.AllocCoTaskMem(fontData.Length);

            Marshal.Copy(fontData, 0, unsafeMemoryBlock, fontData.Length);
            uint pcFont = 0;

            Gdi32.AddFontMemResourceEx(unsafeMemoryBlock, (uint)fontData.Length, IntPtr.Zero, ref pcFont);
            PrivateFontCollection privateFonts = new PrivateFontCollection();

            privateFonts.AddMemoryFont(unsafeMemoryBlock, fontData.Length);
            Font font = new Font(privateFonts.Families[0], emSize, fontStyle, graphicsUnit, gdiCharSet, gdiVerticalFont);

            privateFonts.Dispose();
            Marshal.FreeCoTaskMem(unsafeMemoryBlock);
            return(font);
        }