0
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

0
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.

0
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

0
101 Feb 09, 2004 at 23:33

Yes there has been an update.