# How can I get the exact width of a character ???

## Recommended Posts

ArthY303    1153
I am using the ID3DXFONT interface and I want to find the exact width of a character no matter the font. Or the width of the widest character in the font. Can someone help me or at least point me in the right direction ???

##### Share on other sites
Evil Steve    2017
Calling DrawText() with the DT_CALCRECT flag will cause ID3DXFont to update the RECT you passed in with the size of the text, so you can just use that flag and call DrawText() with a single character.

##### Share on other sites
ArthY303    1153
Does calling DrawText() with DT_CALCRECT result in displaying text on the screen or is it just used to get the width of a string ???

##### Share on other sites
Evil Steve    2017
Quote:
 Original post by ArthY303Does calling DrawText() with DT_CALCRECT result in displaying text on the screen or is it just used to get the width of a string ???
No, it just gets the size of the string.

##### Share on other sites
ArthY303    1153
Thanks for the quick response ... and it actually solved my problem.
I have another question though : is there any way to find out how many pixels does the DrawText() function puts between lines ???

##### Share on other sites
Evil Steve    2017
This should do it:
TEXTMETRIC tm;GetTextMetrics(pFont->GetDC(), &tm);// tm.tmHeight is the height of one line of text

I'm not entirely sure if that's correct though, you'd have to try it and see (I use my own font renderer rather than ID3DXFont).