我想在指定的矩形中繪製字符串,但問題是具有指定字體的字符串可能在矩形的邊界之外。如何縮放字體以適合指定的矩形
所以我想要一種方法來縮放字符串字體以適應指定矩形區域中的字符串。
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',然後永遠不要使用它? –