Exemple #1
0
        private float GetFactor(char chr, TextFormatFlags flags)
        {
            if (CFonts.Style == EStyle.Normal)
            {
                return(1f);
            }

            EStyle style = CFonts.Style;

            CFonts.Style  = EStyle.Normal;
            CFonts.Height = SIZEh;
            Bitmap bmp = new Bitmap(10, 10);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

            Font fo    = CFonts.GetFont();
            Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
            //SizeF size = g.MeasureString(chr.ToString(), fo);
            float h_normal = sizeB.Height;

            CFonts.Style = style;
            bmp          = new Bitmap(10, 10);
            g            = System.Drawing.Graphics.FromImage(bmp);

            fo    = CFonts.GetFont();
            sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
            //size = g.MeasureString(chr.ToString(), fo);
            float h_style = sizeB.Height;

            g.Dispose();
            return(h_normal / h_style);
        }
Exemple #2
0
        public CGlyph(char chr, float MaxHigh)
        {
            _SIZEh = MaxHigh;

            float           outline = CFonts.Outline;
            TextFormatFlags flags   = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix;

            float factor = GetFactor(chr, flags);

            CFonts.Height = SIZEh * factor;
            Bitmap bmp = new Bitmap(10, 10);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

            Font fo    = CFonts.GetFont();
            Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);

            SizeF size = g.MeasureString(chr.ToString(), fo);

            g.Dispose();
            bmp.Dispose();

            bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height);
            g   = System.Drawing.Graphics.FromImage(bmp);
            g.Clear(System.Drawing.Color.Transparent);

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            CFonts.Height       = SIZEh;
            fo = CFonts.GetFont();

            PointF point = new PointF(
                outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + SIZEh / 5f,
                (sizeB.Height - size.Height - (size.Height + SIZEh / 4f) * (1f - factor)) / 2f);

            GraphicsPath path = new GraphicsPath();

            path.AddString(
                chr.ToString(),
                fo.FontFamily,
                (int)fo.Style,
                SIZEh,
                point,
                new StringFormat());

            Pen pen = new Pen(
                Color.FromArgb(
                    (int)CFonts.OutlineColor.A * 255,
                    (int)CFonts.OutlineColor.R * 255,
                    (int)CFonts.OutlineColor.G * 255,
                    (int)CFonts.OutlineColor.B * 255),
                SIZEh * outline);

            pen.LineJoin = LineJoin.Round;
            g.DrawPath(pen, path);
            g.FillPath(Brushes.White, path);

            /*
             * g.DrawString(
             *  chr.ToString(),
             *  fo,
             *  Brushes.White,
             *  point);
             * */

            Texture = CDraw.AddTexture(bmp);
            //bmp.Save("test.png", ImageFormat.Png);
            Chr   = chr;
            width = (int)((1f + outline / 2f) * sizeB.Width * Texture.width / factor / bmp.Width);

            bmp.Dispose();
            g.Dispose();
            fo.Dispose();
        }