问题描述
|
给定FontSize,如何获得字体的LineHeight?似乎它取决于字体而有所不同,并不一定连接到FontSize。我为LineStackingStrategy使用BlockLineHeight。
澄清。我了解有确定总行高的方法。在这种情况下,我正在寻找从基线到字体顶部的高度(因此减去p \的尾部等)。
在上图的情况下。我要上升。
解决方法
FontFamily fontFamily = new FontFamily(\"Arial\");
Font font = new Font(fontFamily,16,FontStyle.Regular,GraphicsUnit.Pixel);
ascent = fontFamily.GetCellAscent(FontStyle.Regular);
ascentPixel = font.Size * ascent / fontFamily.GetEmHeight(FontStyle.Regular);
从:
http://msdn.microsoft.com/zh-CN/library/xwf9s90b.aspx
, 如果要使用“ 1”对象进行绘制并具有引用,则可以执行此操作。
Font myFont = new Font(\"Verdana\",15);
SizeF fontSize = e.Graphics.MeasureString(\"my text\",myFont);
然后,这将告诉您字符串的高度和宽度。您可以将其用于单线以测试线高。
或通过此答案在这里:如何在WPF中计算字体高度?
您可以使用一些简单的计算轻松地计算线高。