I need to outline text based on a given Font. Here is code snippet:
private void DrawText(String text, Graphics graphic) { String _text = text; SizeF size = new SizeF(); Font f2 = AppropriateFont(graphic, 5, 5000, this.ClientSize, _text, fontGeneral, ref size); PointF p = new PointF( (this.ClientSize.Width - size.Width) / 2, (this.ClientSize.Height - size.Height) / 2); graphic.DrawString(_text, f2, Brushes.Red, p); } private Font AppropriateFont(Graphics g, float minFontSize, float maxFontSize, Size layoutSize, String s, Font f, ref SizeF extent) { if (maxFontSize == minFontSize) f = new Font(f.FontFamily, minFontSize, f.Style); extent = g.MeasureString(s, f); if (maxFontSize <= minFontSize) return f; float hRatio = layoutSize.Height / extent.Height; float wRatio = layoutSize.Width / extent.Width; float ratio = (hRatio < wRatio) ? hRatio : wRatio; float newSize = f.Size * ratio; if (newSize < minFontSize) newSize = minFontSize; else if (newSize > maxFontSize) newSize = maxFontSize; f = new Font(f.FontFamily, newSize, f.Style); extent = g.MeasureString(s, f); return f; }
I've found a way to do it with AddString but result is not the same as by using DrawString.
Any clues?
Thanks