Exemplo n.º 1
0
        unsafe static Fonts() {
            fonts = new PrivateFontCollection();

            fixed (byte* data = Resources.Ubuntu)
                fonts.AddMemoryFont((IntPtr)data, Resources.Ubuntu.Length);

            fixed (byte* data = Resources.minecraft)
                fonts.AddMemoryFont((IntPtr)data, Resources.minecraft.Length);

        }
Exemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            byte[] fontArray = Properties.Resources.OpenSans_ExtraBold;
            int dataLength = Properties.Resources.OpenSans_ExtraBold.Length;

            // ASSIGN MEMORY AND COPY  BYTE[] ON THAT MEMORY ADDRESS
            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();
            //PASS THE FONT TO THE  PRIVATEFONTCOLLECTION OBJECT
            pfc.AddMemoryFont(ptrData, dataLength);

            //FREE THE  "UNSAFE" MEMORY
            Marshal.FreeCoTaskMem(ptrData);

            StringFormat format = new StringFormat();
            format.LineAlignment = StringAlignment.Center;
            format.Alignment = StringAlignment.Center;

            Font font = new Font(pfc.Families[0], Font.Size, FontStyle.Regular);
            e.Graphics.DrawString(Text, font, new SolidBrush(this.ForeColor), new PointF(20, 17), format);
        }
Exemplo n.º 3
0
        internal static void LoadFont()
        {
            Fonts = new PrivateFontCollection();

            // specify embedded resource name
            Stream fontStream = new MemoryStream(Properties.Resources.futura_extrabold);

            // create an unsafe memory block for the font data
            System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);

            // create a buffer to read in to
            byte[] fontdata = new byte[fontStream.Length];

            //byte[] fontdata = InstagramScreenSaver.Properties.Resources.futura_extrabold;

            // read the font data from the resource
            fontStream.Read(fontdata, 0, (int)fontStream.Length);

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

            // pass the font to the font collection
            Fonts.AddMemoryFont(data, (int)fontStream.Length);

            // close the resource stream
            fontStream.Close();

            // free up the unsafe memory
            Marshal.FreeCoTaskMem(data);
        }
Exemplo n.º 4
0
        private static void EnsureFontLoaded()
        {
            if (_FontAwesome == null)
            {
                _PrivateFontCollection = new PrivateFontCollection();

                byte[] fontAwesomeBuffer = BarFunctions.LoadFont("SystemImages.FontAwesome.ttf");
                _FontAwesomeHandle = GCHandle.Alloc(fontAwesomeBuffer, GCHandleType.Pinned);
                _PrivateFontCollection.AddMemoryFont(_FontAwesomeHandle.AddrOfPinnedObject(), fontAwesomeBuffer.Length);
                uint rsxCnt = 1;
                _FontAwesomePointer = AddFontMemResourceEx(_FontAwesomeHandle.AddrOfPinnedObject(),
                                                     (uint)fontAwesomeBuffer.Length, IntPtr.Zero, ref rsxCnt);
                using (FontFamily ff = _PrivateFontCollection.Families[0])
                {
                    if (ff.IsStyleAvailable(FontStyle.Regular))
                    {
                        _FontAwesome = new Font(ff, _FontAwesomeDefaultSize, FontStyle.Regular, GraphicsUnit.Point);
                        _FontAwesomeCache.Add(_FontAwesomeDefaultSize, _FontAwesome);
                    }
                    else
                    {
                        // Error use default font...
                        _FontAwesome = SystemInformation.MenuFont;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void FontCollection()
        {
            // Create the byte array and get its length

            byte[] fontArray = Resources.gill_sans_ultra_bold_condensed;
            int dataLength = Resources.gill_sans_ultra_bold_condensed.Length;

            // ASSIGN MEMORY AND COPY  BYTE[] ON THAT MEMORY ADDRESS
            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();
            //PASS THE FONT TO THE  PRIVATEFONTCOLLECTION OBJECT
            pfc.AddMemoryFont(ptrData, dataLength);

            //FREE THE  "UNSAFE" MEMORY
            Marshal.FreeCoTaskMem(ptrData);

            ff = pfc.Families[0];
            font = new Font(ff, 15f, FontStyle.Bold);
            fontButtonRegular = new Font(ff, 25f, FontStyle.Bold);
            fontButtonSelected = new Font(ff, 30f, FontStyle.Bold);
            fontRankings = new Font(ff, 25f, FontStyle.Bold);

            MyButton._normalFont = fontButtonRegular;
            MyButton._hoverFont = fontButtonSelected;
        }
Exemplo n.º 6
0
        static unsafe ChatPreview()
        {
            Fonts = new PrivateFontCollection();
            fixed( byte* fontPointer = Resources.MinecraftFont ) {
                Fonts.AddMemoryFont( (IntPtr)fontPointer, Resources.MinecraftFont.Length );
            }
            MinecraftFont = new Font( Fonts.Families[0], 12, FontStyle.Regular );
            ColorPairs = new[]{
                new ColorPair(0,0,0,0,0,0),
                new ColorPair(0,0,191,0,0,47),
                new ColorPair(0,191,0,0,47,0),
                new ColorPair(0,191,191,0,47,47),
                new ColorPair(191,0,0,47,0,0),
                new ColorPair(191,0,191,47,0,47),
                new ColorPair(191,191,0,47,47,0),
                new ColorPair(191,191,191,47,47,47),

                new ColorPair(64,64,64,16,16,16),
                new ColorPair(64,64,255,16,16,63),
                new ColorPair(64,255,64,16,63,16),
                new ColorPair(64,255,255,16,63,63),
                new ColorPair(255,64,64,63,16,16),
                new ColorPair(255,64,255,63,16,63),
                new ColorPair(255,255,64,63,63,16),
                new ColorPair(255,255,255,63,63,63)
            };
        }
Exemplo n.º 7
0
 private void AddFontFromResource(PrivateFontCollection privateFontCollection, string fullFontResourceString)
 {
     var fontBytes = GetResourceBytes(fullFontResourceString);
     var fontData = Marshal.AllocCoTaskMem(fontBytes.Length);
     Marshal.Copy(fontBytes, 0, fontData, fontBytes.Length);
     privateFontCollection.AddMemoryFont(fontData, fontBytes.Length); // Add font to collection.
     Marshal.FreeCoTaskMem(fontData); // Do not forget to frees the memory block.
 }
Exemplo n.º 8
0
 /// <summary>
 /// Načte font ze zdrojů.
 /// </summary>
 /// <param name="fontResourceData">Dara fontu ze zdrojů.</param>
 /// <param name="fontCollection">Výstupní kolekce fontů s novým fontem.</param>
 /// <returns>Vrací FontFamily.</returns>
 public static unsafe FontFamily LoadFontFamily(byte[] fontResourceData, out PrivateFontCollection fontCollection)
 {
     fixed (byte* ptr = fontResourceData)
     {
         fontCollection = new PrivateFontCollection();
         fontCollection.AddMemoryFont(new IntPtr(ptr), fontResourceData.Length);
         return fontCollection.Families[0];
     }
 }
Exemplo n.º 9
0
        public void ProcessRequest(HttpContext context)
        {
            PrivateFontCollection pfc = new PrivateFontCollection();

            string code = context.Request.QueryString["Code"];
            if (String.IsNullOrEmpty(code)) throw new ArgumentNullException("Code");

            // Get embedded font resource stream
            Assembly aa = Assembly.GetExecutingAssembly();
            string[] resourceNames = aa.GetManifestResourceNames();
            Stream fontStream = aa.GetManifestResourceStream(resourceNames[0]);
            if (fontStream == null) throw new ArgumentNullException("fontStream");

            // Read font stream
            byte[] fontData = new Byte[fontStream.Length];
            fontStream.Read(fontData, 0, fontData.Length);
            fontStream.Close();

            // Pin array to get address
            GCHandle handle = GCHandle.Alloc(fontData, GCHandleType.Pinned);

            try {
                IntPtr memIntPtr = Marshal.UnsafeAddrOfPinnedArrayElement(fontData, 0);
                if (memIntPtr == null) throw new ArgumentNullException("memIntPtr");

                // Add font to private collection and set font for use
                pfc.AddMemoryFont(memIntPtr, fontData.Length);
                Font barcode = new Font(pfc.Families[0], 44f);

                // Determine width
                Graphics gf = Graphics.FromImage(new Bitmap(100, 100));
                SizeF size = gf.MeasureString(String.Format("*{0}*", code), barcode);
                int width = (int)size.Width + 2;
                const int height = 70;

                using (Bitmap bm = new Bitmap(width, height))
                using (Graphics g = Graphics.FromImage(bm))
                using (MemoryStream ms = new MemoryStream()) {
                    Font text = new Font("Consolas", 12f);
                    PointF barcodeStart = new PointF(2f, 2f);
                    SolidBrush black = new SolidBrush(Color.Black);
                    SolidBrush white = new SolidBrush(Color.White);
                    g.FillRectangle(white, 0, 0, width, height);
                    g.DrawString(String.Format("*{0}*", code), barcode, black, barcodeStart);
                    g.DrawString(code, text, black, new Rectangle(0, 46, width, 20), new StringFormat() { Alignment = StringAlignment.Center });
                    context.Response.ContentType = "image/png";
                    bm.Save(ms, ImageFormat.Png);
                    ms.WriteTo(context.Response.OutputStream);
                }
            } finally {
                // Don't forget to unpin the array!
                handle.Free();
            }
        }
Exemplo n.º 10
0
 public ResourceFont(byte[] rawFont)
 {
     _font = new PrivateFontCollection();
     using (var stream = new MemoryStream(rawFont))
     {
         _handle = GCHandle.Alloc(rawFont, GCHandleType.Pinned);
         _fontPointer = _handle.AddrOfPinnedObject();
         _font.AddMemoryFont(_fontPointer, (int)stream.Length);
         uint dummy = 0;
         AddFontMemResourceEx(_fontPointer, (uint)stream.Length, IntPtr.Zero, ref dummy);                
     }
 }
Exemplo n.º 11
0
 static PatternView()
 {
     pfc = new PrivateFontCollection();
     byte[] fontdata = Properties.Resources.WHITRABT;
     unsafe
     {
         fixed (byte* pFontData = fontdata)
         {
             pfc.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
         }
     }
 }
Exemplo n.º 12
0
        //Load font family from stream
        public FontFamily LoadFontFamily(Stream stream)
        {
            byte[] buffer = new byte[stream.Length];
            stream.Read(buffer, 0, buffer.Length);
            IntPtr data = Marshal.AllocCoTaskMem((int)stream.Length);

            Marshal.Copy(buffer, 0, data, (int)stream.Length);
            PrvFontCollection = new PrivateFontCollection();
            PrvFontCollection.AddMemoryFont(data, (int)stream.Length);

            Marshal.FreeCoTaskMem(data);
            return PrvFontCollection.Families[0];
        }
Exemplo n.º 13
0
 public static Font LoadFont(Assembly a, string resource)
 {
     var fontStream = a.GetManifestResourceStream(resource);
     var data = Marshal.AllocCoTaskMem((int)fontStream.Length);
     var fontdata = new byte[fontStream.Length];
     fontStream.Read(fontdata, 0, (int)fontStream.Length);
     Marshal.Copy(fontdata, 0, data, (int)fontStream.Length);
     var private_fonts = new PrivateFontCollection();
     private_fonts.AddMemoryFont(data, (int)fontStream.Length);
     fontStream.Close();
     Marshal.FreeCoTaskMem(data);
     return new Font(private_fonts.Families[0], 12);
 }
Exemplo n.º 14
0
 public void loadFont()
 {
     byte[] fontArray = Empire_World_Launcher.Properties.Resources.Diavlo2;
     int dataLength = Empire_World_Launcher.Properties.Resources.Diavlo2.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];
 }
Exemplo n.º 15
0
        private void changeToBrailleFont()
        {
            //define a private font collection
            System.Drawing.Text.PrivateFontCollection pfc2 = new System.Drawing.Text.PrivateFontCollection();
            //read your resource font into a byte array
            byte[] Bytes = Properties.Resources.SimBraille;
            //allocate some memory and get a pointer to it
            IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(Bytes.Length);

            //copy the font data byte array to memory
            System.Runtime.InteropServices.Marshal.Copy(Bytes, 0, ptr, Bytes.Length);
            //Add the font to the private font collection
            pfc2.AddMemoryFont(ptr, Bytes.Length);
            //free up the previously allocated memory
            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(ptr);
            //define a font from the private font collection
            System.Drawing.Font fnt2 = new System.Drawing.Font(pfc2.Families[0], 16);
            //dispose of the private font collection
            pfc2.Dispose();

            System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
            string path = Path.GetDirectoryName(Application.ExecutablePath) + "\\Resources\\";
            string font = "SimBraille.ttf";

            try
            {
                pfc.AddFontFile(path + font);
                System.Drawing.Font fnt = new System.Drawing.Font(pfc.Families[0], 16);

                richTextBoxEditor.Font            = fnt;
                richTextBoxEditor.SelectionStart  = 0;
                richTextBoxEditor.SelectionLength = richTextBoxEditor.TextLength;
                richTextBoxEditor.SelectionFont   = fnt;
                richTextBoxEditor.SelectionStart  = 0;
                richTextBoxEditor.SelectionLength = 0;

                int rightMargin = setRightMargin(fnt2);
                richTextBoxEditor.RightMargin = rightMargin;

                fnt.Dispose();
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }

            //return the font created from your font resource

            textToolStripMenuItem.Checked  = false;
            punktToolStripMenuItem.Checked = true;
        }
Exemplo n.º 16
0
 /* http://blog.andreloker.de/post/2008/07/03/Load-a-font-from-disk-stream-or-byte-array.aspx */
 // load font family from byte array
 public static FontFamily LoadFontFamily(byte[] buffer, out PrivateFontCollection fontCollection)
 {
     // pin array so we can get its address
     var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
     try {
         var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
         fontCollection = new PrivateFontCollection();
         fontCollection.AddMemoryFont(ptr, buffer.Length);
         return fontCollection.Families[0];
     } finally {
         // don't forget to unpin the array!
         handle.Free();
     }
 }
Exemplo n.º 17
0
        public void setFonts()
        {
            PrivateFontCollection fonts = new PrivateFontCollection();

            byte[] fontData = Properties.Resources.Neverwinter;
            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.Neverwinter.Length);
            AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.Neverwinter.Length, IntPtr.Zero, ref dummy);
            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);

            myFont = new Font(fonts.Families[0], 16.0F);
        }
Exemplo n.º 18
0
 public static FontFamily LoadFontFamily(byte[] buffer, out PrivateFontCollection fontCollection)
 {
     var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
     try
     {
         var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
         fontCollection = new PrivateFontCollection();
         fontCollection.AddMemoryFont(ptr, buffer.Length);
         return fontCollection.Families[0];
     }
     finally
     {
         handle.Free();
     }
 }
Exemplo n.º 19
0
        public static Font IranSansFont(float size)
        {
            if (fonts != null && fonts.Families.Any())
                return new Font(fonts.Families[0], size);

            fonts = new PrivateFontCollection();
            byte[] fontData = Core.Properties.Resources.irsans;
            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, Core.Properties.Resources.irsans.Length);
            AddFontMemResourceEx(fontPtr, (uint)Core.Properties.Resources.irsans.Length, IntPtr.Zero, ref dummy);
            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);

            return new Font(fonts.Families[0], size);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Reads the embedded font.
        /// </summary>
        /// <param name="fontName">Name of the font file.</param>
        /// <param name="fontData">The font data.</param>
        /// <returns>The FontFamily object to be used.</returns>
        public static FontFamily ReadEmbeddedFont(string fontName, byte[] fontData)
        {
            IntPtr memoryData = Marshal.AllocCoTaskMem(fontData.Length);
            Marshal.Copy(fontData, 0, memoryData, fontData.Length);

            PrivateFontCollection pfc = new PrivateFontCollection();
            pfc.AddMemoryFont(memoryData, fontData.Length);

            Marshal.FreeCoTaskMem(memoryData);

            string fontFilePath = Path.Combine(Path.GetTempPath(), fontName);
            File.WriteAllBytes(fontFilePath, fontData);
            PInvoke.AddFontResourceEx(fontFilePath, 0x10, IntPtr.Zero);

            return pfc.Families[0];
        }
Exemplo n.º 21
0
        private void SetWindesheimFontSheriff()
        {
            byte[] fontArray = Properties.Resources.ufonts_com_sheriff_roman;
            int dataLength = Resources.ufonts_com_sheriff_roman.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);

            windesheimFontFamily = pfc.Families[0];
            windesheimSheriffFont = new Font(windesheimFontFamily, 28f, FontStyle.Regular);
            windesheimSheriffFontSmall = new Font(windesheimFontFamily, 14f, FontStyle.Regular);
            windesheimSheriffFontXSmall = new Font(windesheimFontFamily, 12f, FontStyle.Regular);
        }
Exemplo n.º 22
0
        private CardGenerationModule()
        {
            TemplateImage = new Size(1020, 645);

            objPrivateFontCollection = new PrivateFontCollection();

            Stream fontStream = this.GetType().Assembly.GetManifestResourceStream("CardGenerationModule.free3of9.ttf");

            byte[] fontdata = new byte[fontStream.Length];
            fontStream.Read(fontdata, 0, (int)fontStream.Length);
            fontStream.Close();
            unsafe
            {
                fixed (byte* pFontData = fontdata)
                {
                    objPrivateFontCollection.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
                }
            }

            DisplayFontName = "Tahoma";
        }
Exemplo n.º 23
0
        private void LoadFont()
        {
            byte[] fontArray = Properties.Resources.Pericl;
            int dataLength = Properties.Resources.Pericl.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, 13f, FontStyle.Regular);
        }
Exemplo n.º 24
0
        /**************************************************** Constructor ****************************************************/
        public PersonalFont()
        {
            // Create the byte array and get its length
            byte[] fontArray = global::Snake.Properties.Resources.Kraboudja;
            int dataLength = global::Snake.Properties.Resources.Kraboudja.Length;

            // Assign memory and copy byte[] on that memory address
            System.IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength); //(the common language runtime must marshal ptrdata which will be passed as a parameter with AddFontMemRessourceEx).
            Marshal.Copy(fontArray, 0, ptrData, dataLength);

            uint cFonts = 0;
            AddFontMemResourceEx(ptrData, (uint)fontArray.Length, System.IntPtr.Zero, ref cFonts); // Adds the font resource from a memory image to the system (from gdi32.dll)

            PrivateFontCollection pfc = new PrivateFontCollection();
            // Pass the font to the privatefontcollection object
            pfc.AddMemoryFont(ptrData, dataLength);

            // Free the "unsafe" memory
            Marshal.FreeCoTaskMem(ptrData);

            kraboudja = (FontFamily)pfc.Families[0];
        }
Exemplo n.º 25
0
		/// <summary>
		/// Renders the <see cref="Duality.Resources.Font"/> based on its embedded TrueType representation.
		/// </summary>
		public static void RenderGlyphs(this DualityFont font)
		{
			if (font.EmbeddedTrueTypeFont == null) throw new InvalidOperationException("Can't render glyphs of a Duality Font without embedded vector Font information.");

			using (PrivateFontCollection fontManager = new PrivateFontCollection())
			{
				// Load custom font family using System.Drawing
				GCHandle handle = GCHandle.Alloc(font.EmbeddedTrueTypeFont, GCHandleType.Pinned);
				try
				{
					IntPtr fontMemPtr = handle.AddrOfPinnedObject();
					fontManager.AddMemoryFont(fontMemPtr, font.EmbeddedTrueTypeFont.Length);
				}
				finally
				{
					handle.Free();
				}

				// Render the font's glyphs
				RenderGlyphs(font, fontManager.Families.FirstOrDefault());
			}
		}
Exemplo n.º 26
0
        //Default constructor for the form
        public Form1()
        {
            InitializeComponent();

            //Get all the links
            ALL_LINKS = _sqlHelper.FindAll();

            //Embedding a font into the program
            //http://stackoverflow.com/questions/4464875/windows-forms-cant-get-font-resource-to-show-properly
            PROGRAM_FONTS = new PrivateFontCollection();

            unsafe
            {
                uint installCount = 1;

                fixed (byte* pFontData = Properties.Resources.fontawesome_webfont)
                {
                    PROGRAM_FONTS.AddMemoryFont((IntPtr)pFontData, Properties.Resources.fontawesome_webfont.Length);
                    AddFontMemResourceEx((IntPtr)pFontData, (uint)Properties.Resources.fontawesome_webfont.Length, IntPtr.Zero, ref installCount);
                }
            }
        }
Exemplo n.º 27
0
        static public void AddFontResource(this PrivateFontCollection outFontCollection, System.IO.FileInfo ttfFontFile, uint count = 0)
        {
            if (outFontCollection == null)
            {
                throw new ArgumentException();
            }

            byte[] fontData = System.IO.File.ReadAllBytes(ttfFontFile.FullName);
            IntPtr fontPtr  = Marshal.AllocCoTaskMem(fontData.Length);

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

            outFontCollection.AddMemoryFont(fontPtr, fontData.Length);
            IntPtr ptr = AddFontMemResourceEx(fontPtr, (uint)fontData.Length, IntPtr.Zero, ref count);

            if (ptr == IntPtr.Zero)
            {
                throw new NullReferenceException();
            }

            Marshal.FreeCoTaskMem(fontPtr);
            fontData = null;
        }
Exemplo n.º 28
0
        private void comboBoxTPFont_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxTPFont.SelectedIndex == -1) return;

            switch (comboBoxTPFont.SelectedIndex)
            {
                case 0:
                    if (pfc != null)
                    {
                        pfc.Dispose();
                        pfc = null;
                    }

                    //PrivateFontCollectionオブジェクトを作成する
                    pfc = new System.Drawing.Text.PrivateFontCollection();
                    byte[] fontBuf = null;
                    if (comboBoxTPFont.SelectedIndex == 0)
                    {
                        fontBuf = Properties.Resources.pirulen_rg;
                    }

                    IntPtr fontBufPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontBuf.Length);
                    System.Runtime.InteropServices.Marshal.Copy(fontBuf, 0, fontBufPtr, fontBuf.Length);

                    pfc.AddMemoryFont(fontBufPtr, fontBuf.Length);
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontBufPtr);

                    //PrivateFontCollectionの先頭のフォントのFontオブジェクトを作成する
                    System.Drawing.Font f = new System.Drawing.Font(pfc.Families[0], (int)numericUpDownFontSize.Value);

                    selectedFont = f;
                    break;
                default:
                    if (pfc != null) 
                    {
                        pfc.Dispose();
                        pfc = null; 
                    }

                    selectedFont = new Font(comboBoxTPFont.Text, (int)numericUpDownFontSize.Value);
                    break;
            }
            controller.TPFont = selectedFont;
        }
Exemplo n.º 29
0
        internal static Font getPKXFont(float fontsize)
        {
            byte[] fontData = Properties.Resources.PGLDings_NormalRegular;
            IntPtr fontPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);
            System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
            PrivateFontCollection fonts = new PrivateFontCollection();
            try
            {
                fonts.AddMemoryFont(fontPtr, Properties.Resources.PGLDings_NormalRegular.Length); uint dummy = 0;
                AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.PGLDings_NormalRegular.Length, IntPtr.Zero, ref dummy);
                System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);
            }
            catch { Util.Error("Unable to add ingame font."); }

            return new Font(fonts.Families[0], fontsize);
        }
Exemplo n.º 30
0
        private void LoadOpenSansLight()
        {
            // Create the byte array and get its length

            byte[] fontArray = Properties.Resources.opensans_light_webfont;
            int dataLength = Properties.Resources.opensans_light_webfont.Length;

            // ASSIGN MEMORY AND COPY  BYTE[] ON THAT MEMORY ADDRESS
            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();
            //PASS THE FONT TO THE  PRIVATEFONTCOLLECTION OBJECT
            pfc.AddMemoryFont(ptrData, dataLength);

            //FREE THE  "UNSAFE" MEMORY
            Marshal.FreeCoTaskMem(ptrData);

            ff = pfc.Families[0];
            openSansLight = new Font(ff, 15f, FontStyle.Regular);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Método encargado de cargar la funte personalizada
        /// </summary>
        /// 
        private void CargoPrivateFontCollection()
        {
            byte[] fontArray = RecursosHumanos.Properties.Resources.Radioland;
            int dataLength = RecursosHumanos.Properties.Resources.Radioland.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);
        }
        private void AddPrivateFont(PrivateFontCollection pfc, string name)
        {
            // Setup our font
            Stream fontStream = this.GetType().Assembly.GetManifestResourceStream(name);
            byte[] fontdata = new byte[fontStream.Length];
            fontStream.Read(fontdata, 0, (int)fontStream.Length);
            fontStream.Close();

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