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); }
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); }
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); }
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); }
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); }
public static void DrawStringFit(CoolFont cf, Graphics g, Brush brush, Rectangle rt) { DrawStringFit(cf.Text, cf.Font, g, brush, rt); }
public static float FitStringRect(CoolFont cf, Graphics g, Rectangle rt) { return(FitStringRect(cf.Text, cf.Font, g, rt)); }
public static float FitStringHeight(CoolFont cf, Graphics g, float height) { return(FitStringHeight(cf.Text, cf.Font, g, height)); }
public static float FitStringWidth(CoolFont cf, Graphics g, float width) { return(FitStringWidth(cf.Text, cf.Font, g, width)); }
public static SizeF GetStringSize(CoolFont cf, Graphics g) { return(g.MeasureString(cf.Text, cf.Font)); }