Пример #1
0
 public static string GetFontName(string fontFileName)
 {
     try
     {
         byte[] data  = File.ReadAllBytes(fontFileName);
         IntPtr hGlob = Marshal.AllocCoTaskMem(data.Length);
         Marshal.Copy(data, 0, hGlob, data.Length);
         PrivateFontCollection fontCol = new PrivateFontCollection();
         fontCol.AddMemoryFont(hGlob, data.Length);
         return(fontCol.Families[0].Name);
     }
     catch (Exception) { }
     return(null);
 }
Пример #2
0
 public static bool IsValidFont(string fontFileName)
 {
     try
     {
         byte[] data  = File.ReadAllBytes(fontFileName);
         IntPtr hGlob = Marshal.AllocCoTaskMem(data.Length);
         Marshal.Copy(data, 0, hGlob, data.Length);
         PrivateFontCollection fontCol = new PrivateFontCollection();
         fontCol.AddMemoryFont(hGlob, data.Length);
         return(!string.IsNullOrEmpty(fontCol.Families[0].Name));
     }
     catch (Exception) { }
     return(false);
 }
Пример #3
0
        private void Initialize()
        {
            byte[] fontData = AshaWeighing.Properties.Resources.IRANSans_FaNum_;
            IntPtr fontPtr  = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);

            System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
            uint dummy = 0;

            fonts.AddMemoryFont(fontPtr, AshaWeighing.Properties.Resources.IRANSans_FaNum_.Length);
            AddFontMemResourceEx(fontPtr, (uint)AshaWeighing.Properties.Resources.IRANSans_FaNum_.Length, IntPtr.Zero, ref dummy);
            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);

            myFont = new Font(fonts.Families[0], 10F);
        }
Пример #4
0
        private void registerFont(ref Font font, byte[] res, float size)
        {
            PrivateFontCollection pfc = new PrivateFontCollection();
            int fontLength            = res.Length;

            byte[] fontdata = res;
            IntPtr data     = Marshal.AllocCoTaskMem(fontLength);

            Marshal.Copy(fontdata, 0, data, fontLength);
            pfc.AddMemoryFont(data, fontLength);
            Marshal.FreeCoTaskMem(data);

            font = new Font(pfc.Families[0], size);
        }
        private void SetUpCustomFont()
        {
            byte[] fontData = Properties.Resources.Square_Dot_Matrix_Font;
            IntPtr fontPtr  = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);

            System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
            uint dummy = 0;

            fonts.AddMemoryFont(fontPtr, Properties.Resources.Square_Dot_Matrix_Font.Length);
            AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.Square_Dot_Matrix_Font.Length, IntPtr.Zero, ref dummy);
            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);

            segFont = new Font(fonts.Families[0], 32.0F);
        }
Пример #6
0
        // load font family from byte array
        public static FontFamily LoadFontFamily(byte[] buffer)
        {
            var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            try {
                var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
                using (var pvc = new PrivateFontCollection()) {
                    pvc.AddMemoryFont(ptr, buffer.Length);
                    return(pvc.Families[0]);
                }
            } finally {
                handle.Free();
            }
        }
Пример #7
0
        public static unsafe void AddFont(this PrivateFontCollection fonts, string fontFile,
                                          Assembly assembly = null, string path = "fonts")
        {
            var fontBytes = GetFontBytes(fontFile, assembly, path);

            fixed(byte *pFontData = fontBytes)
            {
                fonts.AddMemoryFont((IntPtr)pFontData, fontBytes.Length);
                uint dummy = 0;

                NativeMethods.AddFontMemResourceEx((IntPtr)pFontData, (uint)fontBytes.Length, IntPtr.Zero,
                                                   ref dummy);
            }
        }
Пример #8
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            PrivateFontCollection font = new PrivateFontCollection();
            int fontLength             = Properties.Resources.Lato_Regular.Length;

            byte[] fontData = Properties.Resources.Lato_Regular;
            IntPtr data     = Marshal.AllocCoTaskMem(fontLength);

            Marshal.Copy(fontData, 0, data, fontLength);
            font.AddMemoryFont(data, fontLength);
            Application.Run(new Launcher());
        }
Пример #9
0
        public static Font LoadCustomFont(byte[] fontData)
        {
            PrivateFontCollection _fonts = new PrivateFontCollection();

            IntPtr fontPtr = Marshal.AllocCoTaskMem(fontData.Length);

            Marshal.Copy(fontData, 0, fontPtr, fontData.Length);

            _fonts.AddMemoryFont(fontPtr, fontData.Length);

            Marshal.FreeCoTaskMem(fontPtr);

            return(new Font(_fonts.Families[0], 6.0F));
        }
Пример #10
0
        private void EditArea_Load(object sender, EventArgs e)
        {
            byte[] fontData = Properties.Resources.blocktext;
            IntPtr fontPtr  = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);

            System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
            uint dummy = 0;

            fonts.AddMemoryFont(fontPtr, Properties.Resources.blocktext.Length);
            AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.blocktext.Length, IntPtr.Zero, ref dummy);
            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);
            bfont = fonts;
            //if (File.Exists(Directory.GetCurrentDirectory() + @"\blocktext.ttf")) bfont.AddFontFile(Directory.GetCurrentDirectory() + @"\blocktext.ttf");
        }
Пример #11
0
        /// <summary>
        /// Register font in Resources to the PrivateFontCollection to use them in IconGenerator or other stuff
        /// </summary>
        public static void SetFont()
        {
            _fontLength = Resources.BurbankBigCondensed_Bold.Length;
            _fontdata   = Resources.BurbankBigCondensed_Bold;
            IntPtr weirdData = Marshal.AllocCoTaskMem(_fontLength);

            Marshal.Copy(_fontdata, 0, weirdData, _fontLength);
            pfc.AddMemoryFont(weirdData, _fontLength);

            _fontLength = Resources.BurbankBigCondensed_Black.Length;
            _fontdata   = Resources.BurbankBigCondensed_Black;
            IntPtr weirdData2 = Marshal.AllocCoTaskMem(_fontLength);

            Marshal.Copy(_fontdata, 0, weirdData2, _fontLength);
            pfc.AddMemoryFont(weirdData2, _fontLength);

            centeredString.Alignment = StringAlignment.Center;
            rightString.Alignment    = StringAlignment.Far;
            leftString.Alignment     = StringAlignment.Near;

            centeredStringLine.LineAlignment = StringAlignment.Center;
            centeredStringLine.Alignment     = StringAlignment.Center;
        }
Пример #12
0
        //Inizializza un nuovo font richiamabile da codice senza installarlo nel sistema a partire da un file ttf presente nelle risorse del progetto.
        //Non applicabile (almeno non con la Dll che ho importato, penso ci sia un suo Shared Object equivalente) su Linux/Mac.
        FontFamily InitCustomFont(byte[] font)
        {
            PrivateFontCollection pfc = new PrivateFontCollection();
            int    fontLength         = font.Length;
            IntPtr data = Marshal.AllocCoTaskMem(fontLength);

            Marshal.Copy(font, 0, data, fontLength);
            uint cFonts = 0;

            AddFontMemResourceEx(data, (uint)font.Length, IntPtr.Zero, ref cFonts);
            pfc.AddMemoryFont(data, fontLength);
            //Marshal.FreeCoTaskMem(data);
            return(pfc.Families[0]);
        }
Пример #13
0
        static FontFamily LoadRawFonts(byte[] buffer)
        {
            var f = new PrivateFontCollection();

            unsafe
            {
                fixed(byte *pfont04b = buffer)
                {
                    f.AddMemoryFont((IntPtr)pfont04b, buffer.Length);
                }
            }

            return(f.Families[0]);
        }
Пример #14
0
        private static PrivateFontCollection Setting(byte[] fontData)
        {
            PrivateFontCollection fonts = new PrivateFontCollection();
            IntPtr fontPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);

            System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
            uint dummy = 0;

            fonts.AddMemoryFont(fontPtr, fontData.Length);
            AddFontMemResourceEx(fontPtr, (uint)fontData.Length, IntPtr.Zero, ref dummy);
            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);

            return(fonts);
        }
Пример #15
0
        public static void AddFont(byte[] fontBytes)
        {
            var    handle  = GCHandle.Alloc(fontBytes, GCHandleType.Pinned);
            IntPtr pointer = handle.AddrOfPinnedObject();

            try
            {
                _privateFontCollection.AddMemoryFont(pointer, fontBytes.Length);
            }
            finally
            {
                handle.Free();
            }
        }
Пример #16
0
        /// <summary>
        ///     Adds a font from memory/resource store.
        /// </summary>
        /// <param name="name">The name of the font to use for the store.</param>
        /// <param name="fontBytes"></param>
        public static void AddFont(string name, byte[] fontBytes)
        {
            var fontData = Marshal.AllocCoTaskMem(fontBytes.Length);

            Marshal.Copy(fontBytes, 0, fontData, fontBytes.Length);

            var fontCollection = new PrivateFontCollection();

            fontCollection.AddMemoryFont(fontData, fontBytes.Length);

            CustomFonts.Add(name, new FontStore(name, fontCollection.Families[0]));

            fontCollection.Dispose();
        }
Пример #17
0
        /// <summary>
        /// Loads font from byte array
        /// </summary>
        /// <param name="data">Byte array containing font data</param>
        /// <returns><see cref="PrivateFontCollection"/> containing fonts</returns>
        public static PrivateFontCollection AddFontFromMemory(byte[] data)
        {
            PrivateFontCollection pfc = new PrivateFontCollection();

            unsafe
            {
                fixed(byte *pFontData = data)
                {
                    pfc.AddMemoryFont((System.IntPtr)pFontData, data.Length);
                }
            }

            return(pfc);
        }
Пример #18
0
        public void SetupFont()
        {
            pfc = new PrivateFontCollection();

            int fontLength = Resources.MONOPOLY.Length;

            byte[] fontdata = Resources.MONOPOLY;

            IntPtr data = Marshal.AllocCoTaskMem(fontLength);

            Marshal.Copy(fontdata, 0, data, fontLength);

            pfc.AddMemoryFont(data, fontLength);
        }
Пример #19
0
        private FontFamily LoadFont(byte[] fontResource)
        {
            int    dataLength = fontResource.Length;
            IntPtr fontPtr    = Marshal.AllocCoTaskMem(dataLength);

            Marshal.Copy(fontResource, 0, fontPtr, dataLength);

            uint cFonts = 0;

            AddFontMemResourceEx(fontPtr, (uint)fontResource.Length, IntPtr.Zero, ref cFonts);
            privateFontCollection.AddMemoryFont(fontPtr, dataLength);

            return(privateFontCollection.Families.Last());
        }
Пример #20
0
        private static void addFontToCollection(byte[] font)
        {
            // create an unsafe memory block for the font data
            System.IntPtr data = Marshal.AllocCoTaskMem(font.Length);

            // copy the bytes to the unsafe memory block
            Marshal.Copy(font, 0, data, font.Length);

            // pass the font to the font collection
            pfc.AddMemoryFont(data, font.Length);

            // free up the unsafe memory
            Marshal.FreeCoTaskMem(data);
        }
Пример #21
0
 private void LoadRalewayFont()
 {
     // Load the Raleway font into the application...
     byte[]        FontResource = Properties.Resources.Raleway_Regular;
     System.IntPtr data         = Marshal.AllocCoTaskMem((int)FontResource.Length);
     Marshal.Copy(FontResource, 0, data, (int)FontResource.Length);
     PrivateFonts.AddMemoryFont(data, (int)FontResource.Length);
     Marshal.FreeCoTaskMem(data);
     RalewayFont10 = new Font(PrivateFonts.Families[0], 10);
     RalewayFont11 = new Font(PrivateFonts.Families[0], 11);
     RalewayFont12 = new Font(PrivateFonts.Families[0], 12);
     RalewayFont16 = new Font(PrivateFonts.Families[0], 16);
     RalewayFont20 = new Font(PrivateFonts.Families[0], 20);
 }
Пример #22
0
    public static PrivateFontCollection Load(MemoryStream stream)
    {
        byte[] streamData = new byte[stream.Length];
        stream.Read(streamData, 0, streamData.Length);
        IntPtr data = Marshal.AllocCoTaskMem(streamData.Length); // Very important.

        Marshal.Copy(streamData, 0, data, streamData.Length);
        PrivateFontCollection pfc = new PrivateFontCollection();

        pfc.AddMemoryFont(data, streamData.Length);
        // MemoryFonts.Add(pfc); // Your own collection of fonts here.
        Marshal.FreeCoTaskMem(data); // Very important.
        return(pfc);
    }
Пример #23
0
        public dashboard()
        {
            InitializeComponent();
            this.MinimumSize = this.Size;
            answerTexts      = new List <Bunifu.Framework.UI.BunifuMetroTextbox>()
            {
                txt_answer_1,
                txt_answer_2,
                txt_answer_3,
                txt_answer_4,
                txt_answer_5,
                txt_answer_6,
                txt_answer_7,
                txt_answer_8
            };
            this.answerTexts.ForEach((txt) => txt.OnValueChanged += Txt_OnValueChanged);
            this.AllowDrop       = true;
            this.DragEnter      += new DragEventHandler(dash_DragEnter);
            this.DragDrop       += new DragEventHandler(dash_DragDrop);
            this.FormBorderStyle = FormBorderStyle.None;
            this.DoubleBuffered  = true;
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            PrivateFontCollection pfc = new PrivateFontCollection();
            int fontLength            = Properties.Resources.circular_font.Length;

            byte[]        fontdata = Properties.Resources.circular_font;
            System.IntPtr data     = Marshal.AllocCoTaskMem(fontLength);
            Marshal.Copy(fontdata, 0, data, fontLength);
            pfc.AddMemoryFont(data, fontLength);
            foreach (var c in this.Controls)
            {
                if (c.GetType() == typeof(Label))
                {
                    ((Label)c).Font = new Font(pfc.Families[0], ((Label)c).Font.Size);
                }
                else if (c.GetType() == typeof(Bunifu.Framework.UI.BunifuMetroTextbox))
                {
                    ((Bunifu.Framework.UI.BunifuMetroTextbox)c).Font = new Font(pfc.Families[0], ((Bunifu.Framework.UI.BunifuMetroTextbox)c).Font.Size);
                }
                else if (c.GetType() == typeof(TreeView))
                {
                    ((TreeView)c).Font = new Font(pfc.Families[0], ((TreeView)c).Font.Size);
                }
                else if (c.GetType() == typeof(RichTextBox))
                {
                    ((RichTextBox)c).Font = new Font(pfc.Families[0], ((RichTextBox)c).Font.Size);
                }
            }
        }
Пример #24
0
        private void MemoryViewer_Load(object sender, EventArgs e)
        {
            int fontLength = Properties.Resources.Hack.Length;

            byte[] fontdata = Properties.Resources.Hack;

            IntPtr data = Marshal.AllocCoTaskMem(fontLength);

            Marshal.Copy(fontdata, 0, data, fontLength);

            uint cFonts = 0;

            AddFontMemResourceEx(data, (uint)fontLength, IntPtr.Zero, ref cFonts);

            pfc.AddMemoryFont(data, fontLength);

            Marshal.FreeCoTaskMem(data);

            object[] fontObjects = { memBox, offset };

            foreach (var f in fontObjects)
            {
                if (f is TextBox)
                {
                    TextBox fd = f as TextBox;
                    fd.Font = new Font(pfc.Families[0], fd.Font.Size);
                }
                if (f is Label)
                {
                    Label fd = f as Label;
                    fd.Font = new Font(pfc.Families[0], fd.Font.Size);
                }
                if (f is HexBox)
                {
                    HexBox fd = f as HexBox;
                    fd.Font = new Font(pfc.Families[0], fd.Font.Size);
                }
            }

            memBox.Font         = Fonts.Fonts.Create(Fonts.FontFamily.Hack, 12);
            memBox.ByteProvider = MPU.memory.provider;

            offset.Font = Fonts.Fonts.Create(Fonts.FontFamily.Hack, 12);

            offset.GotFocus += (sndr, args) => {
                offset.Select(offset.TextLength, 0);
                HideCaret(offset.Handle);
            };
        }
Пример #25
0
    /////////////////////////////////////
    //
    // The GetSpecialFont procedure takes a size and
    // create a font of that size using the hardcoded
    // special font name it knows about.
    //
    /////////////////////////////////////
    public Font GetSpecialFont(float size)
    {
        Font fnt = null;

        if (null == m_pfc)
        {
            // First load the font as a memory stream
            Stream stmFont = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "WindowsApplication1.MyPrivateFont.ttf");

            if (null != stmFont)
            {
                //
                // GDI+ wants a pointer to memory, GDI wants the memory.
                // We will make them both happy.
                //

                // First read the font into a buffer
                byte[] rgbyt = new Byte[stmFont.Length];
                stmFont.Read(rgbyt, 0, rgbyt.Length);

                // Then do the unmanaged font (Windows 2000 and later)
                // The reason this works is that GDI+ will create a font object for
                // controls like the RichTextBox and this call will make sure that GDI
                // recognizes the font name, later.
                uint cFonts;
                AddFontMemResourceEx(rgbyt, rgbyt.Length, IntPtr.Zero, ref cFonts);

                // Now do the managed font
                IntPtr pbyt = Marshal.AllocCoTaskMem(rgbyt.Length);
                if (null != pbyt)
                {
                    Marshal.Copy(rgbyt, 0, pbyt, rgbyt.Length);
                    m_pfc = new PrivateFontCollection();
                    m_pfc.AddMemoryFont(pbyt, rgbyt.Length);
                    Marshal.FreeCoTaskMem(pbyt);
                }
            }
        }

        if (m_pfc.Families.Length > 0)
        {
            // Handy how one of the Font constructors takes a
            // FontFamily object, huh? :-)
            fnt = new Font(m_pfc.Families[0], size);
        }

        return(fnt);
    }
Пример #26
0
        /*
         * -----------------------------------------
         *              CUSTOM FONTS
         * -----------------------------------------
         */

        private void LoadFont(String type)
        {
            // Get data for regular font
            if (type == "Regular")
            {
                byte[] fontArray  = Approved.Properties.Resources.gadugi;
                int    dataLength = Approved.Properties.Resources.gadugi.Length;

                IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);

                Marshal.Copy(fontArray, 0, ptrData, dataLength);

                uint cFonts = 0;

                AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);

                PrivateFontCollection pfc = new PrivateFontCollection();

                pfc.AddMemoryFont(ptrData, dataLength);

                Marshal.FreeCoTaskMem(ptrData);

                ff   = pfc.Families[0];
                font = new Font(ff, 15f, FontStyle.Regular);
            }
            // Get data for bold font
            else if (type == "Bold")
            {
                byte[] fontArray  = Approved.Properties.Resources.gadugi;
                int    dataLength = Approved.Properties.Resources.gadugi.Length;

                IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);

                Marshal.Copy(fontArray, 0, ptrData, dataLength);

                uint cFonts = 0;

                AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);

                PrivateFontCollection pfc = new PrivateFontCollection();

                pfc.AddMemoryFont(ptrData, dataLength);

                Marshal.FreeCoTaskMem(ptrData);

                ff   = pfc.Families[0];
                font = new Font(ff, 15f, FontStyle.Bold);
            }
        }
Пример #27
0
        private void AddFont(PrivateFontCollection collection, byte[] data)
        {
            int length = data.Length;

            IntPtr hFont = Marshal.AllocHGlobal(length);

            Marshal.Copy(data, 0, hFont, length);

            uint pcFonts = 0;

            NativeMethods.AddFontMemResourceEx(hFont, (uint)length, IntPtr.Zero, ref pcFonts);
            collection.AddMemoryFont(hFont, length);

            Marshal.FreeHGlobal(hFont);
        }
        private Logger()
        {
            PrivateFontCollection pfc = new PrivateFontCollection();
            Stream fontStream         = this.GetType().Assembly.GetManifestResourceStream("Gotham-Light.ttf");

            byte[] fontdata = Applicatie_Risicoanalyse.Properties.Resources.Gotham_Light;
            unsafe
            {
                fixed(byte *pFontData = fontdata)
                {
                    pfc.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
                    ARA_Globals.ARA_Font = pfc.Families[0];
                }
            }
        }
Пример #29
0
 private void LoadFont()
 {
     if (myFonts == null)
     {
         myFonts = new PrivateFontCollection();
         byte[] font = Properties.Resources.shablagoo;
         fontBuffer = Marshal.AllocCoTaskMem(font.Length);
         Marshal.Copy(font, 0, fontBuffer, font.Length);
         myFonts.AddMemoryFont(fontBuffer, font.Length);
     }
     fontFamily    = myFonts.Families[0];
     UpBoardFont   = new Font(fontFamily, 28f, FontStyle.Bold);
     GameOverFont  = new Font(fontFamily, 60f, FontStyle.Bold);
     MainTitleFont = new Font(fontFamily, 70f);
 }
Пример #30
0
        private PrivateFontCollection LoadFontFromResourcesToFontCollection()
        {
            PrivateFontCollection pfc = new PrivateFontCollection();

            byte[] fontArray = Properties.Resources.barcodeFont;
            //allocate memory for the file
            IntPtr dataPtr = Marshal.AllocCoTaskMem(fontArray.Length);

            Marshal.Copy(fontArray, 0, dataPtr, fontArray.Length);
            //pass font to the font collection
            pfc.AddMemoryFont(dataPtr, fontArray.Length);
            //free allocated memory
            Marshal.FreeCoTaskMem(dataPtr);
            return(pfc);
        }
Пример #31
0
    private static void InstallFont(Stream font_stream, string font_resource_name)
    {
        if (s_fonts == null)
        {
            // First load the font as a memory stream
            if (font_stream != null)
            {
                //
                // GDI+ wants a pointer to memory,
                // GDI wants the memory.
                // We will make them both happy.
                //

                // First read the font into a buffer
                byte[] buffer = new Byte[font_stream.Length];
                font_stream.Read(buffer, 0, buffer.Length);

                // Then do the unmanaged font (Windows 2000 and later)
                // The reason this works is that GDI+ will create a font object for
                // controls like the RichTextBox and this call will make sure that GDI
                // recognizes the font name, later.
                uint font_count;
                AddFontMemResourceEx(buffer, buffer.Length, IntPtr.Zero, out font_count);

                // Now do the managed font
                IntPtr p_buffer = Marshal.AllocCoTaskMem(buffer.Length);
                if (p_buffer != null)
                {
                    Marshal.Copy(buffer, 0, p_buffer, buffer.Length);
                    s_fonts = new PrivateFontCollection();
                    s_fonts.AddMemoryFont(p_buffer, buffer.Length);
                    Marshal.FreeCoTaskMem(p_buffer);
                }
            }
        }
    }