# ID3DXFont , DirectX 90b

This topic is 5097 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello again all :) just a quick question : What is the bedst/fastest way to get the Text Width/Height of any given font ? Option 1 : Windows call - GetTextExtentPoint32(ID3DXFont::GetDC, ... Option 2 : When createing font : DC = ID3DXFont::GetDC GetTextExtentPoint32(DC, ... When Releaseing the Font, DeleteDC(DC) Option 3 : Any other way of getting the Width/Height of a text ? Note : For the upcomming release of DX90c, please build this function into the ID3DXFont, would be cool :)

##### Share on other sites
You could use the ID3DXFont::DrawText method with the DT_CALCRECT format parameter. That will allow you to calculate the sizes without drawing it. Note if your using C#/MDX, there is a bug in so you can't calculate the size this way but it appears that your using the C++ D3DX Font Stuff.

##### Share on other sites
ID3DXFont::DrawText , returns the Height, how do i get the Width ?

##### Share on other sites
The RECT structure you pass in gets modified.

xyzzy

##### Share on other sites
Thx, works fine, one more thing tho.

Dose it matter if I pass NULL (as the Sprite parm) for this, as the text is not drawen (performance) ?

##### Share on other sites
INT DrawText(          LPD3DXSPRITE pSprite,    LPCTSTR pString,    INT Count,    LPRECT pRect,    DWORD Format,    D3DCOLOR Color);

Quote:
 Format[in] Specifies the method of formatting the text. It can be any combination of the following values. DT_BOTTOMJustifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE. DT_CALCRECTDetermines the width and height of the rectangle. If there are multiple lines of text, ID3DXFont::DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, ID3DXFont::DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, ID3DXFont::DrawText returns the height of the formatted text but does not draw the text. DT_CENTERCenters text horizontally in the rectangle. DT_EXPANDTABSExpands tab characters. The default number of characters per tab is eight.DT_LEFTAligns text to the left. DT_NOCLIPDraws without clipping. ID3DXFont::DrawText is somewhat faster when DT_NOCLIP is used. DT_RIGHTAligns text to the right. DT_RTLREADINGDisplays text in right-to-left reading order for bi-directional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right. DT_SINGLELINEDisplays text on a single line only. Carriage returns and line feeds do not break the line. DT_TOPTop-justifies text. DT_VCENTERCenters text vertically (single line only). DT_WORDBREAKBreaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.

##### Share on other sites
Quote:
 Original post by MytharDose it matter if I pass NULL (as the Sprite parm) for this, as the text is not drawen (performance) ?

You can try it, since it won't make your computer explode or something.. You aren't afraid of a crashing program, are you? ;P

##### Share on other sites
It shouldn't take a perf hit based on the sprite parameter.

• 11
• 20
• 12
• 10
• 38
• ### Forum Statistics

• Total Topics
631400
• Total Posts
2999862
×