关于Windows字体高度计算

LOGFONT lf;
strcpy(lf.lfFaceName,TextFaceName);
lf.lfCharSet=TextCharFormat;
lf.lfWeight=TextWeight;
lf.lfWidth=TextSize;
lf.lfHeight=-MulDiv(TextSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
lf.lfItalic=TextItalic;
lf.lfUnderline=TextUnderline;
lf.lfStrikeOut=TextStrikeOut;

上述代码描述字体的结构体

本文主要研究字体高度的计算。lf.lfHeight=-MulDiv(TextSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);

其中 

1. TextSize是字体大小,单位是(pt)

2. GetDeviceCaps(hDC, LOGPIXELSY)是获取屏幕垂直方向的DPI(像素密度)单位是(像素点个数/英寸)

3. 72是是1pt的值,即1pt=1/72英寸

MulDiv(a,b,c)作用是计算a*b/c

即 TextSize*GetDeviceCaps(hDC, LOGPIXELSY)/72得到字体高度(像素个数)

猜你喜欢

转载自blog.csdn.net/Mr_sandman1994/article/details/83027692
今日推荐