Why do commas, periods count as separate words?  
Author Message
Brandon Amoroso





PostPosted: Game Technologies: Graphics, Why do commas, periods count as separate words? Top

I'm using the Direct3D Font object to draw a paragraph of text to the screen, and I'm finding that for some reason the lines don't break on punctuation like they should...

// _msg = the string to draw, _size is a vector2, x/y are integers
_font.DrawText(null, _msg, new Rectangle(_x, _y, (int)_size.X, (int)_size.Y), D3D.DrawTextFormat.Left | D3D.DrawTextFormat.WordBreak, _shadowColor);

It beats me why this is happening, but i get the following kind of line break:

Joey went to the store
, and then he realized that this line starts with a comma.

Standard line breaking suggests that either the comma should appear right after the word "store", or else the entire word "store" should appear on the next line, with the comma right after it. Either way, the comma should never be separated from the word it follows...

...so, um, how can I fix it




Game Technologies: DirectX, XNA, XACT, etc.9  
 
 
Jack Hoxley





PostPosted: Game Technologies: Graphics, Why do commas, periods count as separate words? Top

I'd hazard a guess this is more likely a bug than a "feature" - maybe something as simple as getting the index wrong and splitting before the "," rather than after...

as a potential bug report. Be sure to include details and a reproduction sample if possible.

As a work-around you could manually implement your own line-breaking by pre-processing the string before calling DrawText(). I've seen it suggested that "MeasureString()" be used to calculate dimensions - so stepping through the string and inserting line-breaks shouldn't be too hard. Not being an MDX programmer I'm not sure of the exact details for this - I've only written it in C++

hth
Jack



 
 
Brandon Amoroso





PostPosted: Game Technologies: Graphics, Why do commas, periods count as separate words? Top

Okay, I've fired off an email to them.

In the meantime, I've basically decided to work around the bug by adding an extra couple of spaces before the offending word, to shove the whole thing down to the next line.

It's kind of a lame solution, but it's not a big deal, because those particular strings are only ever going to be used in the context described above, anyway. And they're always going to be the same.



 
 
Ross Ridge





PostPosted: Game Technologies: Graphics, Why do commas, periods count as separate words? Top

I'm using the Direct3D Font object to draw a paragraph of text to the screen, and I'm finding that for some reason the lines don't break on punctuation like they should...

It's a known bug. Apparently it's actually a bug in the Uniscribe API that they use to handle internationalized text. Because of that I'm not sure if they have any plans to fix it.

The only way to work around the problem is to wrap your text yourself. You can use DT_CALCRECT to measure the length of your text.