I'm using Directwrite to display scrollable text in a render target, and I want to calculate how many lines of text will fit per screen.
I've been using this code to calculate the number of lines that will fit on the RT:
The results of the above code seem to be accurate for some fonts, but not for others, resulting in the RT "clipping" the text too early. For these other fonts, usingCode:/* pTextFormat is an IDWriteTextFormat pointer, dpi_y is the desktop's vertical dpi, and GetHeight() returns the height (in pixels) of the render target. */ float size = (pTextFormat->GetFontSize()/72.0f)*dpi_y; return (int)(GetHeight()/size);
instead seems to work.Code:float size = pTextFormat->GetFontSize(); return (int)(GetHeight()/size);
My problem is that I don't know how to tell which font should use which method, or why one method works for one font but not another.
I'm using IDWriteTextLayouts to display the text.