Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string fName = ConfigurationManager.AppSettings["Code39Barcode.FontFamily"];

        PrivateFontCollection fCollection = new PrivateFontCollection();
        fCollection.AddFontFile(ConfigurationManager.AppSettings["Code39Barcode.FontFile"]);
        FontFamily fFamily = new FontFamily(fName, fCollection);
        Font f = new Font(fFamily, FontSize);

        Bitmap bmp = new Bitmap(Width, Height);
        Graphics g = Graphics.FromImage(bmp);
        g.Clear(Color.White);
        Brush b = new SolidBrush(Color.Black);
        g.DrawString("*" + strPortfolioID + "*", f, b, 0, 0);

        //PNG format has no visible compression artifacts like JPEG or GIF, so use this format, but it needs you to copy the bitmap into a new bitmap inorder to display the image properly.  Weird MS bug.
        Bitmap bm = new Bitmap(bmp);
        System.IO.MemoryStream ms = new System.IO.MemoryStream();

        Response.ContentType = "image/png";
        bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        ms.WriteTo(Response.OutputStream);

        b.Dispose();
        bm.Dispose();
        Response.End();
    }
Ejemplo n.º 2
0
        public static void CreateTextureFontFiles(string fileName, float size, FontStyle style, QFontBuilderConfiguration config, string newFontName)
        {
            QFontData fontData = null;

            if (config == null)
            {
                config = new QFontBuilderConfiguration();
            }


            //dont move this into a separate method - it needs to stay in scope!
            PrivateFontCollection pfc = new PrivateFontCollection();

            pfc.AddFontFile(fileName);
            var fontFamily = pfc.Families[0];

            if (!fontFamily.IsStyleAvailable(style))
            {
                throw new ArgumentException("Font file: " + fileName + " does not support style: " + style);
            }

            var font = new Font(fontFamily, size * config.SuperSampleLevels, style);

            //var font = ObtainFont(fileName, size * config.SuperSampleLevels, style);
            try
            {
                fontData = BuildFont(font, config, newFontName);
            }
            finally
            {
                if (font != null)
                {
                    font.Dispose();
                }
            }

            Builder.SaveQFontDataToFile(fontData, newFontName);
        }
Ejemplo n.º 3
0
        //CUSTOM FONT
        public void InitCustomLabelFont()
        {
            //LABEL LIST
            List <Label> labelList = new List <Label>();

            foreach (var lbl in Controls)
            {
                if (lbl.GetType() == typeof(Label))
                {
                    labelList.Add((Label)lbl);
                }
            }

            //Create your private font collection object.
            PrivateFontCollection pfc = new PrivateFontCollection();

            //Select your font from the resources.
            //My font here is "Starjedi.ttf"
            int fontLength = Properties.Resources.Starjedi.Length;

            // create a buffer to read in to
            byte[] fontdata = Properties.Resources.Starjedi;

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

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

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

            //After that we can create font and assign font to label
            foreach (var label in labelList)
            {
                label.Font = new Font(pfc.Families[0], label.Font.Size);
            }
        }
Ejemplo n.º 4
0
        public QFont(string fontname, byte[] fontresource, float size, FontStyle style, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig)
        {
            // This should be probably a field of some class
            PrivateFontCollection pfc = new PrivateFontCollection();

            // allocate memory and copy byte[] to the location
            IntPtr data = Marshal.AllocCoTaskMem(fontresource.Length);

            Marshal.Copy(fontresource, 0, data, fontresource.Length);

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

            var fontFamily = pfc.Families[0];

            if (!fontFamily.IsStyleAvailable(style))
            {
                throw new ArgumentException("Font Resource: " + fontname + " does not support style: " + style);
            }

            if (config == null)
            {
                config = new QFontBuilderConfiguration();
            }

            using (var font = new Font(fontFamily, size * config.SuperSampleLevels, style))
            {
                fontData = BuildFont(font, config, shadowConfig, null);
            }

            if (shadowConfig != null)
            {
                options.DropShadowActive = true;
            }

            // Free the unsafe memory
            Marshal.FreeCoTaskMem(data);
        }
Ejemplo n.º 5
0
        public QFont(string fileName, float size, FontStyle style, QFontBuilderConfiguration config)
        {
            PrivateFontCollection pfc = new PrivateFontCollection();

            pfc.AddFontFile(fileName);
            var fontFamily = pfc.Families[0];

            if (!fontFamily.IsStyleAvailable(style))
            {
                throw new ArgumentException("Font file: " + fileName + " does not support style: " + style);
            }

            if (config == null)
            {
                config = new QFontBuilderConfiguration();
            }

            TransformViewport?transToVp = null;
            float             fontScale = 1f;

            if (config.TransformToCurrentOrthogProjection)
            {
                transToVp = OrthogonalTransform(out fontScale);
            }

            using (var font = new Font(fontFamily, size * fontScale * config.SuperSampleLevels, style)){
                fontData = BuildFont(font, config, null);
            }

            if (config.ShadowConfig != null)
            {
                Options.DropShadowActive = true;
            }
            if (transToVp != null)
            {
                Options.TransformToViewport = transToVp;
            }
        }
Ejemplo n.º 6
0
        // Initializes custom 'Digital' font
        private void InitCustomLabelFont()
        {
            //Create your private font collection object.
            PrivateFontCollection pfc = new PrivateFontCollection();

            //Select your font from the resources.
            //My font here is "Open24DisplaySt.ttf"
            int fontLength = Properties.Resources.Open24DisplaySt.Length;

            // create a buffer to read in to
            byte[] fontdata = Properties.Resources.Open24DisplaySt;

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

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

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

            l_Timer.Font = new Font(pfc.Families[0], l_Timer.Font.Size);
        }
Ejemplo n.º 7
0
        public UserInterface(Vector2 pos, Vector2 dir, Size size) : base(pos, dir, size)
        {
            _pfc       = LoadFont(Resources.FutureFont);
            _font      = new Font(_pfc.Families[0], 20);
            _smallFont = new Font(_pfc.Families[0], 10);

            _rectangle    = new Rectangle(0, 0, Game.Width, Game.Height);
            _centerFormat = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };
            _bottomFormat = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Far
            };
            _topRightFormat = new StringFormat
            {
                Alignment     = StringAlignment.Far,
                LineAlignment = StringAlignment.Near
            };
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Installs font on the user's system and adds it to the registry so it's available on the next session
        /// Your font must be included in your project with its build path set to 'Content' and its Copy property
        /// set to 'Copy Always'
        /// </summary>
        /// <param name="contentFontName">Your font to be passed as a resource (i.e. "myfont.tff")</param>
        private void RegisterFont(string contentFontName)
        {
            // Creates the full path where your font will be installed
            Directory.CreateDirectory("C:\\MY_FONT_LOC");
            var fontDestination = Path.Combine("C:\\MY_FONT_LOC", contentFontName);

            if (!System.IO.File.Exists(fontDestination))
            {
                // Copies font to destination
                System.IO.File.Copy(Path.Combine(Server.MapPath("/fonts"), contentFontName), fontDestination, false);

                // Retrieves font name
                // Makes sure you reference System.Drawing
                PrivateFontCollection fontCol = new PrivateFontCollection();
                fontCol.AddFontFile(fontDestination);
                var actualFontName = fontCol.Families[0].Name;

                //Add font
                AddFontResource(fontDestination);
                //Add registry entry
                // Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", actualFontName, contentFontName, RegistryValueKind.String);
            }
        }
Ejemplo n.º 9
0
        public static void LoadFontIntoMemory()
        {
            try
            {
                // Add a font provided by the client application without installing it
                // SNIPPET CREDIT: Shibumi
                fontCollection = new PrivateFontCollection();
                var fontLength    = Properties.Resources.Raleway_Light.Length;
                var fontData      = Properties.Resources.Raleway_Light;
                var memoryPointer = Marshal.AllocCoTaskMem(fontLength);

                Marshal.Copy(fontData, 0, memoryPointer, fontLength);

                // Add the font contained in system memory to the PrivateFontCollection
                fontCollection.AddMemoryFont(memoryPointer, fontLength);
                Marshal.FreeCoTaskMem(memoryPointer);
            }
            catch (Exception up)
            {
                up = new Exception(up.Message);
                throw up;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initialises the custom font.
        /// </summary>
        public static void InitFont()
        {
            // create private font collection object.
            var pfc = new PrivateFontCollection();

            // select font from the resources.
            int fontLength = Properties.Resources.ZCOOL.Length;

            // create a buffer to read in to
            byte[] fontdata = Properties.Resources.ZCOOL;

            // create an unsafe memory block for the font data
            System.IntPtr data = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontLength);

            // copy the bytes to the unsafe memory block
            System.Runtime.InteropServices.Marshal.Copy(fontdata, 0, data, fontLength);

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

            // set variable
            gameFont = pfc.Families[0];
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Source: https://stackoverflow.com/questions/1297264/using-custom-fonts-on-a-label-on-winforms
        /// </summary>
        public static void InitSpaceInvadersFont()
        {
            //Create your private font collection object.
            PrivateFontCollection pfc = new PrivateFontCollection();

            //Select your font from the resources.
            //My font here is "Digireu.ttf"
            int fontLength = Properties.Resources.space_invaders.Length;

            // create a buffer to read in to
            byte[] fontdata = Properties.Resources.space_invaders;

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

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

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

            SpaceInvadersFamily = pfc.Families[0];
        }
Ejemplo n.º 12
0
        private static void GetCustomFonts()
        {
            mathFontCollection      = new PrivateFontCollection();
            scriptingFontCollection = new PrivateFontCollection();

            var pathToFont  = GlobalConfig.FullPath("Static", "fonts", "CAMBRIA.TTC");
            var pathToFont2 = GlobalConfig.FullPath("Static", "fonts", "consola.ttf");

            try
            {
                mathFontCollection.AddFontFile(pathToFont);
                scriptingFontCollection.AddFontFile(pathToFont2);
            }
            catch (Exception ex)
            {
                var nex =
                    new Exception(
                        "Probably missing " + pathToFont + " or " + pathToFont2 + " file\nDetails:" + ex.Message, ex);
                logger.MethodName = MethodBase.GetCurrentMethod().Name;
                logger.Log("Probably missing " + pathToFont + " file\nDetails:" + ex.Message, ErrorType.General, nex);
                throw nex;
            }
        }
Ejemplo n.º 13
0
        public void initFont()
        {
            Sunny.UI.UISymbolButton[] btnArr = { randInsert, randDel, dataView, dataInsert, dataUpdate, dataDel };
            PrivateFontCollection     pFont  = new PrivateFontCollection();

            pFont.AddFontFile("Ghanachocolate.ttf");
            Font font = new Font(pFont.Families[0], 13f);

            #region 버튼 폰트 적용
            //randInsert.Font = font;
            //randDel.Font = font;
            //dataView.Font = font;
            //dataInsert.Font = font;
            //dataUpdate.Font = font;
            //dataDel.Font = font;
            #endregion

            foreach (var n in btnArr)
            {
                n.Font = font;
            }
            mainTitle.Font = font;
        }
Ejemplo n.º 14
0
        public Form1()
        {
            InitializeComponent();
            PrivateFontCollection pfc = new PrivateFontCollection();

            //Select your font from the resources.
            //My font here is "Digireu.ttf"
            int fontLength = Properties.Resources.CHILLER.Length;

            // create a buffer to read in to
            byte[] fontdata = Properties.Resources.CHILLER;

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

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

            // pass the font to the font collection
            pfc.AddMemoryFont(data, fontLength);
            label1.Font = new Font(pfc.Families[0], label1.Font.Size);
            label1.Text = "MAD";
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 加载字体
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static FontFamily LoadFontFamily(String path)
        {
            /*
             * FileStream fs = new FileStream(path,FileMode.Open);
             * int fontSize = (int)fs.Length;
             * byte[] fontData = new byte[fontSize];
             * fs.Read(fontData, 0, fontSize);
             * 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 _fonts.Families[0];
             */
            PrivateFontCollection fc = new PrivateFontCollection();

            fc.AddFontFile(path);
            if (fc.Families.Length > 0)
            {
                return(fc.Families[0]);
            }
            return(null);
        }
Ejemplo n.º 16
0
        protected PrivateFontCollection LoadFont(byte[] font)
        {
            PrivateFontCollection pfc = new PrivateFontCollection();


            Stream fontStream = new MemoryStream(font);

            System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);

            Byte[] fontData = new Byte[fontStream.Length];
            fontStream.Read(fontData, 0, (int)fontStream.Length);
            Marshal.Copy(fontData, 0, data, (int)fontStream.Length);

            uint cFonts = 0;

            AddFontMemResourceEx(data, (uint)fontData.Length, IntPtr.Zero, ref cFonts);
            pfc.AddMemoryFont(data, (int)fontStream.Length);
            fontStream.Close();

            Marshal.FreeCoTaskMem(data);

            return(pfc);
        }
Ejemplo n.º 17
0
        public void initCustomLabelFont()
        {
            //Create your private font collection object.
            PrivateFontCollection fontCol = new PrivateFontCollection();

            //Select your font from the resources.
            //My font here is "Digireu.ttf"
            int fontLength = AlarmClock.Properties.Resources.DSDIGI.Length;

            // create a buffer to read in to
            byte[] fontdata = Properties.Resources.DSDIGI;

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

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

            // pass the font to the font collection
            fontCol.AddMemoryFont(data, fontLength);
            timeLabel.Font = new Font(fontCol.Families[0], timeLabel.Font.Size);
            dateLabel.Font = new Font(fontCol.Families[0], dateLabel.Font.Size);
        }
        public static Font SetRoomControlsFont()
        {
            PrivateFontCollection pfc = new PrivateFontCollection();
            ResourceManager       rm  = new ResourceManager("SYS.Core.Resource", Assembly.GetExecutingAssembly());
            Assembly assembly         = Assembly.GetExecutingAssembly();
            Stream   stream           = assembly.GetManifestResourceStream("SYS.Core.Resources.GFont.otf");

            byte[] fontData = new byte[stream.Length];
            stream.Read(fontData, 0, (int)stream.Length);
            stream.Close();

            unsafe
            {
                fixed(byte *pFontData = fontData)
                {
                    pfc.AddMemoryFont((System.IntPtr)pFontData, fontData.Length);
                }
            }
            FontFamily family = new FontFamily(pfc.Families[0].Name);
            Font       myFont = new Font(family, 10);

            return(myFont);
        }
Ejemplo n.º 19
0
        public void SetFont()
        {
            string AppPath = Application.StartupPath;

            try
            {
                PrivateFontCollection font = new PrivateFontCollection();
                font.AddFontFile(AppPath + @"\font\造字工房映力黑规体.otf");
                Font titleFont20 = new Font(font.Families[0], 20F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
                Font titleFont12 = new Font(font.Families[0], 12F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));

                //设置窗体控件字体,哪些控件要更改都写到下面
                Lbl_site.Font          = titleFont12;
                Lbl_timeForArrive.Font = titleFont12;
                Lbl_timeForLeave.Font  = titleFont12;
                Lbl_title.Font         = titleFont20;
                Lbl_vehicle.Font       = titleFont12;
            }
            catch
            {
                MessageBox.Show("字体不存在或加载失败\n程序将以默认字体显示", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Ejemplo n.º 20
0
        private void frmBack_Load(object sender, EventArgs e)
        {
            String year  = DateTime.Now.ToString("yyyy-MM-dd").ToString().Split('-')[0];
            String month = DateTime.Now.ToString("yyyy-MM-dd").ToString().Split('-')[1];

            PrivateFontCollection privateFonts = new PrivateFontCollection();

            this.DoubleBuffered = true;
            pic_banner.BackgroundImageLayout = ImageLayout.Zoom;

            txt_alram_Size_Temp     = txt_alram.Size;
            txt_alram_Lacation_Temp = txt_alram.Location;

            배너세팅();
            바로가기();
            마지막공지();
            북마크();
            자주사용한메뉴();
            프로그램알람();

            timer2.Interval = 5000;
            timer2.Enabled  = true;
        }
Ejemplo n.º 21
0
        private Font GetFont(string fontFamilyName, int fontSize, string fontStyleName)
        {
            var resourceManager = Properties.Resources.ResourceManager;
            var ttf             = resourceManager.GetObject(string.Format("{0}_{1}", fontFamilyName, fontStyleName), Properties.Resources.Culture) as byte[];

            using (var pfc = new PrivateFontCollection())
            {
                unsafe
                {
                    fixed(Byte *pFontData = ttf)
                    {
                        pfc.AddMemoryFont((IntPtr)pFontData, ttf.Length);
                        uint InstallCount = 1;

                        AddFontMemResourceEx((IntPtr)pFontData, (uint)ttf.Length, IntPtr.Zero, ref InstallCount);
                    }
                }

                var font = new Font(pfc.Families[0], fontSize);

                return(font);
            }
        }
Ejemplo n.º 22
0
        public void LoadFont(byte[] FontResource)
        {
            // Use this if you can not find your resource System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();

            byte[] fontArray  = FontResource;
            int    dataLength = FontResource.Length; //use font array length instead

            IntPtr ptr = Marshal.AllocCoTaskMem(dataLength);

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

            uint cFont = 0;

            AddFontMemResourceEx(ptr, (uint)fontArray.Length, IntPtr.Zero, ref cFont);
            PrivateFontCollection pfc = new PrivateFontCollection();

            pfc.AddMemoryFont(ptr, dataLength);

            Marshal.FreeCoTaskMem(ptr);

            ff   = pfc.Families[0];
            font = new Font(ff, 20f, FontStyle.Regular);
        }
Ejemplo n.º 23
0
        // vytvoření menu
        public Menu(PictureBox canvas, Item start, int fontSize = 30)
        {
            height = canvas.Height;
            width  = canvas.Width;

            this.canvas = canvas;

            this.start    = start;
            this.fontSize = fontSize;

            items = new string[] { "Start", "Quit" };

            // načteme písmo
            pfc = new PrivateFontCollection();

            byte[] fontBytes = Properties.Resources.FreePixel;
            var    fontData  = Marshal.AllocCoTaskMem(fontBytes.Length);

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

            Draw();
        }
Ejemplo n.º 24
0
        private static String getFontName(String fontfilename)
        {
            String ext = fontfilename.Substring(fontfilename.LastIndexOf(".") + 1).ToUpper();

            //MessageBox.Show(fontfilename + "\n" + ext);
            if (ext.CompareTo("TTF") == 0)
            {
                PrivateFontCollection pfc = new PrivateFontCollection();
                try
                {
                    pfc.AddFontFile(fontfilename);
                }
                catch (Exception)
                {
                    // return "";
                }
                return(pfc.Families[0].GetName(0));
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 25
0
        public GLFont(string fileName, float size, GLFontBuilderConfiguration config, FontStyle style = FontStyle.Regular)
        {
            PrivateFontCollection pfc = new PrivateFontCollection();

            pfc.AddFontFile(fileName);
            var fontFamily = pfc.Families[0];

            if (!fontFamily.IsStyleAvailable(style))
            {
                throw new ArgumentException("Font file: " + fileName + " does not support style: " + style);
            }

            if (config == null)
            {
                config = new GLFontBuilderConfiguration();
            }

            using (var font = new Font(fontFamily, size * config.SuperSampleLevels, style))
            {
                fontData = new GLFontBuilder(font, config).BuildFontData();
            }
            pfc.Dispose();
        }
Ejemplo n.º 26
0
        private void newfont()
        {
            PrivateFontCollection pfc = new PrivateFontCollection();  //读取字体文件

            pfc.AddFontFile(@"youyun.ttf");
            //Font f =new Font(pfc .Families[0],16);    //实例化字体
            foreach (Control control in this.Controls)
            {
                control.Font = new Font(pfc.Families[0], 26, control.Font.Style);;
            }
            foreach (Control control in this.panel1.Controls)
            {
                control.Font = new Font(pfc.Families[0], 30, control.Font.Style);
            }
            foreach (Control control in this.panel2.Controls)
            {
                control.Font = new Font(pfc.Families[0], 16, control.Font.Style);
            }
            foreach (Control control in this.panel3.Controls)
            {
                control.Font = new Font(pfc.Families[0], 14, control.Font.Style);
            }
        }
Ejemplo n.º 27
0
        private static void PrintPage(object o, PrintPageEventArgs e)
        {
            System.Drawing.Text.PrivateFontCollection privateFonts = new PrivateFontCollection();
            privateFonts.AddFontFile("Slike/msgothic.ttc");
            System.Drawing.Font font = new Font(privateFonts.Families[0], 10);

            //header
            String       drawString = tekst;
            Font         drawFont   = font;
            SolidBrush   drawBrush  = new SolidBrush(Color.Black);
            StringFormat drawFormat = new StringFormat();

            e.Graphics.DrawString(drawString, drawFont, drawBrush, 0, 0, drawFormat);
            SizeF stringSize = new SizeF();

            stringSize = e.Graphics.MeasureString(tekst, drawFont);

            drawFont = font;
            float y = 0.0F;
            float x = 0.0F;

            e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
        }
Ejemplo n.º 28
0
        public static Image ToImage(this string text, string fontPath, float fontSize, Color textColor, Color backColor)
        {
            var privateFontCollection = new PrivateFontCollection();

            privateFontCollection.AddFontFile(fontPath);
            var   myCustomFont       = new Font(privateFontCollection.Families[0], fontSize);
            Image funalImageFromText = new Bitmap(1, 1);
            var   drawing            = Graphics.FromImage(funalImageFromText);
            var   textSize           = drawing.MeasureString(text, myCustomFont);

            funalImageFromText.Dispose();
            drawing.Dispose();
            funalImageFromText = new Bitmap((int)textSize.Width, (int)textSize.Height);
            drawing            = Graphics.FromImage(funalImageFromText);
            drawing.Clear(backColor);
            Brush textBrush = new SolidBrush(textColor);

            drawing.DrawString(text, myCustomFont, textBrush, 0, 0);
            drawing.Save();
            textBrush.Dispose();
            drawing.Dispose();
            return(funalImageFromText);
        }
Ejemplo n.º 29
0
        private FontFamily CarregarFontePadraoNfceNativa(string font = null)
        {
            PrivateFontCollection colecaoDeFontes = null;

            try
            {
                if (!string.IsNullOrWhiteSpace(font))
                {
                    return(new FontFamily(font));
                }

                var openSans = Fonte.CarregarDeByteArray(Resources.OpenSans_CondBold, out colecaoDeFontes);

                return(openSans);
            }
            finally
            {
                if (colecaoDeFontes != null)
                {
                    colecaoDeFontes.Dispose();
                }
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Creates a <see cref="Font"/> based on the provided byte array.
        /// </summary>
        /// <param name="fontData">The data to create the <see cref="Font"/> from.</param>
        /// <param name="privateFontCollection">The container that will become the owner of the created <see cref="Font"/>.</param>
        /// <returns>The created <see cref="Font"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        /// <remarks>The <paramref name="privateFontCollection"/> should be in scope (alive) at the calling side in order to prevent unintended garbage collection.</remarks>
        public static Font CreateFont(byte[] fontData, PrivateFontCollection privateFontCollection)
        {
            if (fontData == null)
            {
                throw new ArgumentNullException(nameof(fontData));
            }

            if (privateFontCollection == null)
            {
                throw new ArgumentNullException(nameof(privateFontCollection));
            }

            uint dummy = 0;

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

            Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
            privateFontCollection.AddMemoryFont(fontPtr, fontData.Length);
            AddFontMemResourceEx(fontPtr, (uint)fontData.Length, IntPtr.Zero, ref dummy);
            Marshal.FreeCoTaskMem(fontPtr);

            return(new Font(privateFontCollection.Families.Last(), 14.0F));
        }
Ejemplo n.º 31
0
        internal SvgFontManager()
        {
            families.AddRange(FontFamily.Families);

#if !NETSTANDARD
            using (var privateFontCollection = new PrivateFontCollection())
            {
                foreach (var path in PrivateFontPathList)
                {
                    privateFontCollection.AddFontFile(path);
                }

                foreach (var data in PrivateFontDataList)
                {
                    var memory = IntPtr.Zero;
                    try
                    {
                        memory = Marshal.AllocCoTaskMem(data.Length);
                        Marshal.Copy(data, 0, memory, data.Length);
                        privateFontCollection.AddMemoryFont(memory, data.Length);
                    }
                    finally
                    {
                        if (memory != IntPtr.Zero)
                        {
                            Marshal.FreeCoTaskMem(memory);
                        }
                    }
                }

                families.AddRange(privateFontCollection.Families);
            }
#endif

            localizedFamilyNames.AddRange(LocalizedFamilyNames);
            localizedFamilyNames.AddRange(defaultLocalizedFamilyNames);
        }
Ejemplo n.º 32
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);
                }
            }
        }
    }
Ejemplo n.º 33
0
    //Generate Tire Barcode Image
    private bool GenerateBarCodeImage(Guid g)
    {
        try
        {
            if (hdnBarCodeImageFileName.Value != "")
            {
                if (System.IO.File.Exists(Server.MapPath(String.Format("/Images/temp/{0}", hdnBarCodeImageFileName.Value))))
                {
                    System.IO.File.Delete(Server.MapPath(String.Format("/Images/temp/{0}", hdnBarCodeImageFileName.Value)));
                }
                hdnBarCodeImageFileName.Value = "";
            }
            string Code = txtDOTPlant.Text.Trim() + "-" + txtDOTSize.Text.Trim() + "-" + txtDOTBrand.Text.Trim() + "-" + txtDOTWeek.Text.Trim() + "-" + txtDOTYear.Text.Trim();

            Bitmap oBitmap = new Bitmap((Code.Length * 30), 110);

            Graphics oGraphics = Graphics.FromImage(oBitmap);
            oGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, (Code.Length * 30), 110);

            PrivateFontCollection pfc = new PrivateFontCollection();
            pfc.AddFontFile(Server.MapPath("/Font/IDAutomationHC39M.ttf"));
            Font oFont = new Font(pfc.Families[0], 18);

            oGraphics.DrawString("*" + Code + "*", oFont, new SolidBrush(Color.Black), 20, 10);

            oBitmap.Save(Server.MapPath(String.Format("/Images/temp/{0}.Gif", g)), System.Drawing.Imaging.ImageFormat.Gif);

            oBitmap.Dispose();
            oGraphics.Dispose();
            oFont.Dispose();
            pfc.Dispose();

            oBitmap = null;
            oGraphics = null;
            oFont = null;
            pfc = null;
        }
        catch (Exception ex)
        {
            new SqlLog().InsertSqlLog(currentUserInfo.UserId, "GenerateBarCodeImageAndBytes", ex);
            return false;
        }

        return true;
    }
 public static void Reload()
 {
     PrivateFontCollection f = new PrivateFontCollection();
     f.AddFontFile(FontAwesomeTTF);
     FontAwesome = new Font(f.Families[0], Size, Style);
 }