正文

GDI+计算文本行距等2010-09-06 16:06:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lym51/51745.html

分享到:

 FontFamily fontFamily(szFaceName/*(WCHAR*)strFaceName.GetBuffer()*/);
 Font font(&fontFamily, (REAL)m_txLogFont.lfHeight, FontStyleRegular, UnitPixel);

 // 文本
 UINT ascent;
 REAL ascentPixel;
 UINT descent;
 REAL descentPixel;
 UINT lineSpacing;
 REAL lineSpacingPixel;

 // 获取 字体上部距离
 ascent = fontFamily.GetCellAscent(FontStyleRegular);
 // 转换为像素单位
 ascentPixel = font.GetSize()*ascent/fontFamily.GetEmHeight(FontStyleRegular);

 // 获取字体下部距离
 descent = fontFamily.GetCellDescent(FontStyleRegular);
 // 转换为像素单位
 descentPixel = font.GetSize()*descent/fontFamily.GetEmHeight(FontStyleRegular);

 // 获取字体行距
 lineSpacing = fontFamily.GetLineSpacing(FontStyleRegular);
 // 转换为像素单位
 lineSpacingPixel = font.GetSize()*lineSpacing/fontFamily.GetEmHeight(FontStyleRegular);

 // 计算输出文本间行距
 REAL rSpaceLine = lineSpacingPixel - ascentPixel - descentPixel;

阅读(3850) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册