ID3DXFont , DirectX 90b

Started by
6 comments, last by RenderTarget 19 years, 9 months ago
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 :)
Advertisement
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.
ID3DXFont::DrawText , returns the Height, how do i get the Width ?
The RECT structure you pass in gets modified.

xyzzy
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) ?
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.
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
It shouldn't take a perf hit based on the sprite parameter.
[sub]My spoon is too big.[/sub]

This topic is closed to new replies.

Advertisement