Sign in to follow this  
Erzengeldeslichtes

ID3DXFont: formatted string?

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


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Erzengeldeslichtes
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.

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


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Erzengeldeslichtes
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?

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_string
while 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

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