PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Font question

is there any way to know how many pixels a string will take with a certain font?
I'm trying to do a centeredPrint function, but I can't figure how many pixels the string will take without printing it twice

TIA :)
Sure is -

Code:

HRESULT hr = surface.DrawText(0, 0, &str;, &m;_font, GDDRAWTEXT_CALCWIDTH, 0, NULL, &dwStrWidth;);
if(hr != GD_OK) return hr;


where:
str is a TCHAR * to your text string
m_font is a pointer to a CGapiBitmapFont surface
dwStrWidth is a pointer to a DWORD
The point of interest is GDDRAWTEXT_CALCWIDTH, RTM.
grrr... I was so blind searching a string size function that I didn't realize the very same printing function had a flag to center the text :)

I think I deserve a RTFM! ;)