我想在指定的矩形中绘制字符串,但问题是具有指定字体的字符串可能在矩形的边界之外。如何缩放字体以适合指定的矩形
所以我想要一种方法来缩放字符串字体以适应指定矩形区域中的字符串。
public Font scaleFont(String text, RectangleF rect, Graphics graphics, Font pFont)
{
float fontSize = 20.0f;
Font font = pFont;
float width = graphics.MeasureString(text, pFont).Width;
float height = graphics.MeasureString(text, pFont).Height;
fontSize = ((rect.Width/width) * pFont.Size);
float heig = (rect.Height/height);
return new Font(pFont.FontFamily, fontSize);
}
上面的代码给我缩放字体,以适应在长方形的顶部区域的字符串,但我想,以适应整个区域(附加了上述算法中的认沽)
但我想要以下输出。
换句话说,你想单词被包装的框。我理解你了吗? –
@ AndreyAtapin,我已经更新了这个问题。 – user2528012
你为什么要做'Font font = pFont',然后永远不要使用它? –