LPD3DXFONT and string widths

F3ff2088fe22d64396b949f149628107
0
SpreeTree 101 Feb 08, 2004 at 20:38

Hi guys

Im using the LPD3DXFONT structure to create simple 2D fonts, but i am having problems layng out the text because I can’t find a way of pre-calculating the final width and height of the printed text.

I know that LPD3DXFONT::DrawText returns the height of the string, but I cant find anyway of getting the width of the text.

Any ideas?

Cheers

Spree

4 Replies

Please log in or register to post a reply.

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Feb 08, 2004 at 23:59

From the looks of it you can use the GetGlyphData() function of the ID3DXFont interface. Pass in the address of a RECT and the glyph identifier (should be just the character casted ti a UINT), and the RECT should get filled with the minimum character area. Alternatively, if that dosnt work, you can get the HDC of the font and then use the GetTextExtentPoint32() WIN32 function.

HDC dc = mpDXFont->GetDC();
SIZE size;
char charater = 'A';

GetTextExtentPoint32( dc, (char*)&character, 1, &size );

// size.cx // width
// size.cy // height

The Glyph function should be more reliable though (if it indeed does what it looks like it should be doing) because that’s part of the interface.

F3ff2088fe22d64396b949f149628107
0
SpreeTree 101 Feb 09, 2004 at 18:03

Has there been an update on DX9 which changes the functionality of the ID3DXFont interface? MSDN only lists a very limited interface (mainly just begin, end and draw), and these are the only functions I can access?

Spree

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Feb 09, 2004 at 23:33

Yes there has been an update.

Link to latest ID3DXFont interface

This is from the summer update SDK. It wasnt in the original dx9 SDK.

F3ff2088fe22d64396b949f149628107
0
SpreeTree 101 Feb 10, 2004 at 07:25

Thanks for that Bladder. I really should keep track of what Microsoft release. Im getting the latest update now

Spree