计算给定窗口中适合的文本行数,Directwrite&的Direct2D [英] Calculating how many lines of text will fit in a given window, Directwrite & Direct2d

查看:75
本文介绍了计算给定窗口中适合的文本行数,Directwrite&的Direct2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用Directwrite设计一个文本控件,我想弄清楚窗口中有多少行文字。


< p style ="line-height:normal; background:white"> 现在我正在使用的公式如下:


 



lines_in_window = windowheight / txtformat-> GetFontSize();



 



/ *



windowheight是rc.bottom - rc.top,其值为



rc由GetClientRect填充()



 



txtformat是一个IDWriteTextFormat *创建的字体大小为



"16.0f"



* /

解决方案

为了将来可能偶然遇到此问题的人的利益:使用IDWriteTextFormat时:: GetFontSize(),字体大小以点大小给出,在用于屏幕大小计算之前必须转换为像素。


I'm designing a text control using Directwrite, and I want to figure out how many lines of text will fit in a window.

Right now the formula I'm using looks like:

 

lines_in_window = windowheight/txtformat->GetFontSize();

 

/*

windowheight is rc.bottom - rc.top, with the values of

rc filled in by GetClientRect()

 

txtformat is an IDWriteTextFormat* created with a font size

of "16.0f"

*/

解决方案

For the benefit of those who may stumble across this problem in the future: when using IDWriteTextFormat::GetFontSize(), the font size is given as a point size and must be converted into pixels before being used in screen size calculations.


这篇关于计算给定窗口中适合的文本行数,Directwrite&amp;的Direct2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆