Exemplo n.º 1
0
        public static float FitStringHeight(string s, Font f, Graphics g, float height)
        {
            CoolFont cf = new CoolFont(f, f.Style);

            cf.Text = s;

            SizeF sf = GetStringSize(cf, g);

            cf.FontSize = Math.Abs(sf.Height - height) / cf.Text.Length;
            sf          = GetStringSize(cf, g);

            if (sf.Height > height)
            {
                while (sf.Height > height)
                {
                    cf.FontSize -= 0.1F;
                    sf           = GetStringSize(cf, g);
                }
            }
            else if (sf.Height < height)
            {
                while (sf.Height < height)
                {
                    cf.FontSize += 0.1F;
                    sf           = GetStringSize(cf, g);
                }
                cf.FontSize -= 0.1F;
            }
            return(cf.FontSize);
        }
Exemplo n.º 2
0
        public static float FitStringWidth(string s, Font f, Graphics g, float width)
        {
            CoolFont cf = new CoolFont(f, f.Style);

            cf.Text = s;

            SizeF sf = GetStringSize(cf, g);

            cf.FontSize = Math.Abs(sf.Width - width) / cf.Text.Length;
            sf          = GetStringSize(cf, g);

            if (sf.Width > width)
            {
                while (sf.Width > width)
                {
                    cf.FontSize -= 0.1F;

                    sf = GetStringSize(cf, g);
                }
            }
            else if (sf.Width < width)
            {
                while (sf.Width < width)
                {
                    cf.FontSize += 0.1F;
                    sf           = GetStringSize(cf, g);
                }
                cf.FontSize -= 0.1F;
            }

            return(cf.FontSize);
        }
Exemplo n.º 3
0
        public static void DrawStringFit(string s, Font f, Graphics g, Brush brush, Rectangle rt, StringAlignment alignment, StringAlignment alignmentV)
        {
            CoolFont cf = new CoolFont(f, f.Style);

            cf.Text = s;

            SizeF sf = GetStringSize(cf, g);

            cf.FontSize = Math.Abs(sf.Width - rt.Width) / cf.Text.Length;
            sf          = GetStringSize(cf, g);

            if (sf.Width > rt.Width)
            {
                while (sf.Width > rt.Width)
                {
                    cf.FontSize -= 0.1F;

                    sf = GetStringSize(cf, g);
                }
            }
            else if (sf.Width < rt.Width)
            {
                while (sf.Width < rt.Width)
                {
                    cf.FontSize += 0.1F;
                    sf           = GetStringSize(cf, g);
                }
                cf.FontSize -= 0.1F;
            }

            if (sf.Height > rt.Height)
            {
                while (sf.Height > rt.Height)
                {
                    cf.FontSize -= 0.1F;
                    sf           = GetStringSize(cf, g);
                }
            }


            StringFormat format = new StringFormat();

            format.FormatFlags   = StringFormatFlags.NoClip;
            format.Alignment     = alignment;
            format.LineAlignment = alignmentV;

            g.DrawString(cf.Text, cf.Font, brush, rt, format);
        }
Exemplo n.º 4
0
        public static float FitStringRect(string s, Font f, Graphics g, Rectangle rt)
        {
            CoolFont cf = new CoolFont(f, f.Style);

            cf.Text = s;

            SizeF sf = GetStringSize(cf, g);

            cf.FontSize = (sf.Width - rt.Width) / cf.Text.Length;
            sf          = GetStringSize(cf, g);

            if (sf.Width > rt.Width)
            {
                while (sf.Width > rt.Width)
                {
                    cf.FontSize -= 0.1F;

                    sf = GetStringSize(cf, g);
                }
            }
            else if (sf.Width < rt.Width)
            {
                while (sf.Width < rt.Width)
                {
                    cf.FontSize += 0.1F;
                    sf           = GetStringSize(cf, g);
                }
                cf.FontSize -= 0.1F;
            }


            if (sf.Height > rt.Height)
            {
                while (sf.Height > rt.Height)
                {
                    cf.FontSize -= 0.1F;
                    sf           = GetStringSize(cf, g);
                }
            }

            return(cf.FontSize);
        }
Exemplo n.º 5
0
 public static void DrawStringFit(CoolFont cf, Graphics g, Brush brush, Rectangle rt, StringAlignment alignment, StringAlignment alignmentV)
 {
     DrawStringFit(cf.Text, cf.Font, g, brush, rt, alignment, alignmentV);
 }
Exemplo n.º 6
0
 public static void DrawStringFit(CoolFont cf, Graphics g, Brush brush, Rectangle rt)
 {
     DrawStringFit(cf.Text, cf.Font, g, brush, rt);
 }
Exemplo n.º 7
0
 public static float FitStringRect(CoolFont cf, Graphics g, Rectangle rt)
 {
     return(FitStringRect(cf.Text, cf.Font, g, rt));
 }
Exemplo n.º 8
0
 public static float FitStringHeight(CoolFont cf, Graphics g, float height)
 {
     return(FitStringHeight(cf.Text, cf.Font, g, height));
 }
Exemplo n.º 9
0
 public static float FitStringWidth(CoolFont cf, Graphics g, float width)
 {
     return(FitStringWidth(cf.Text, cf.Font, g, width));
 }
Exemplo n.º 10
0
 public static SizeF GetStringSize(CoolFont cf, Graphics g)
 {
     return(g.MeasureString(cf.Text, cf.Font));
 }