Microsoft Office 在字体缩放方面做得非常好。它们几乎可以以 0.5 点的步长线性缩放(见下图)。
使用Graphics.DrawString
我无法重现这一点,但在缩放字体大小时我看到了不同的步骤。
使用下面的代码,我得到以下输出,这表明我无法绘制 Office 可以绘制的尽可能多的文本。有什么想法可以绘制那些中间字体大小吗?
Dim baseSize As Single = 16.0F
Dim inputText As String = "MMMMMMMMMMMMMM"
Dim stringFormat As Drawing.StringFormat = Drawing.StringFormat.GenericTypographic()
Dim pos As Single
Dim i As Integer
Do
Using font As Drawing.Font = New Drawing.Font("Calibri", (baseSize + i / 10.0F), FontStyle.Regular, GraphicsUnit.Pixel)
Dim text As String = inputText & " " & font.Size.ToString() & "px"
Dim textSize As SizeF = e.Graphics.MeasureString(text, font, New PointF(0, 0), stringFormat)
e.Graphics.DrawString(text, font, Brushes.Black, New Drawing.RectangleF(10, pos, textSize.Width, textSize.Height), stringFormat)
pos += font.Height
End Using
i += 1
Loop While pos < ClientRectangle.Height