Sign in to follow this  
Mythar

ID3DXFont , DirectX 90b

Recommended Posts

Mythar    138
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 this post


Link to post
Share on other sites
cilcoder    122
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 this post


Link to post
Share on other sites
Mythar    138
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 this post


Link to post
Share on other sites
Pipo DeClown    804
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_BOTTOM
Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.
DT_CALCRECT
Determines 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_CENTER
Centers text horizontally in the rectangle.
DT_EXPANDTABS
Expands tab characters. The default number of characters per tab is eight.
DT_LEFT
Aligns text to the left.
DT_NOCLIP
Draws without clipping. ID3DXFont::DrawText is somewhat faster when DT_NOCLIP is used.
DT_RIGHT
Aligns text to the right.
DT_RTLREADING
Displays 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_SINGLELINE
Displays text on a single line only. Carriage returns and line feeds do not break the line.
DT_TOP
Top-justifies text.
DT_VCENTER
Centers text vertically (single line only).
DT_WORDBREAK
Breaks 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 this post


Link to post
Share on other sites
Pipo DeClown    804
Quote:
Original post by Mythar
Dose 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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this