ID3DXFont: formatted string?

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

Recommended Posts

I'm trying to make a string where I can italicize, underline, bold, and change colors in the middle of the text. With the limitations of ID3DXFont (only 1 font, italics and weight on creation, color per text drawing), I figure that the only way to draw changing formating is to create multiple fonts with the desired options. During drawing, slice and dice the added text into its formatted components. Finally draw each peice of text using the font and color for it's formatting. The problem is that I have lines that wrap around, so DT_CALCRECT will tell me how many lines it is, but not where the last character ended (if I have a single line DT_CALCRECT will change the right side, giving me the number I want). If I could find out what the last line of text is, then I could use DT_CALCRECT on that line to get the correct right side, but I don't know of any way to find out the last line--It doesn't break words and the font is variable character sizes, so I can't count my way to the end. Has anyone dealt with this? Anyone have any suggestions? Thank you for any help.

Share on other sites
Get the font metric (using ID3DXFont::GetTextMetrics) and use that with ::GetTextExtent32(). ::GetTextExtent32() computes the width and height of the given text string.
Using these 2, you can do your own wrapping/breaking/whatever.

Share on other sites
Thanks for the info, but I can't find a GetTextExtent32 in the DX Docs, Platform Docs, or Help, but I do find a GetTextExtentPoint32 in Platform Docs. However, it doesn't take a TEXTMETRIC. Does GetTextMetrics automatically set the font as the "currently selected font", or do I have to find the GDI Function to change the metric to the currently selected font?

Share on other sites
Quote:
 Original post by ErzengeldeslichtesThanks for the info, but I can't find a GetTextExtent32 in the DX Docs, Platform Docs, or Help, but I do find a GetTextExtentPoint32 in Platform Docs. However, it doesn't take a TEXTMETRIC.

You're right, I should've double-checked instead of writing from memory. Sorry [smile]

Quote:
 Does GetTextMetrics automatically set the font as the "currently selected font", or do I have to find the GDI Function to change the metric to the currently selected font?

No, it doesn't. You'll need to use ID3DXFont::GetDC (which returns a DC that has the font set) and use that with GetTextExtentPoint32()

Share on other sites
Ah, I see then. But... how is it different from DT_CALCRECT? From what I can tell from the docs, it sets lpSize to the height and width, which is just like DT_CALCRECT | DT_SINGLELINE. So... what should I do, DrawText with DT_CALCRECT on a per character basis (or perhaps per space/tab) until I go to a second line and then back off to the last space/tab I passed?

Share on other sites
Quote:
 Original post by ErzengeldeslichtesAh, I see then. But... how is it different from DT_CALCRECT? From what I can tell from the docs, it sets lpSize to the height and width, which is just like DT_CALCRECT | DT_SINGLELINE. So... what should I do, DrawText with DT_CALCRECT on a per character basis (or perhaps per space/tab) until I go to a second line and then back off to the last space/tab I passed?

What I had in mind is emulating DT_CALCRECT with multiple-lines, except that you'd also calculate where the last line ends.

Off the top of my head, something like:
calc width and height of given_stringwhile width >= requested_width    approxNumCharsOnFirstLine = strlen - ((width - requested_width)/TextMetrics.AvgCharWidth)    break the string at the last word boundary before approxNum*     store width of current line    given_string = next_line_in_string    calc width and height of given_string

Not terribly helpful or accurate, but I hope you get the idea

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• Forum Statistics

• Total Topics
633771
• Total Posts
3013763
×