I have a line that I need to calculate the Rect size (text height) when drawing. My implementation uses the DrawTextW() function with the DT_WORDBREAK or DT_CALCRECT .
An example of my line:
thisisaverylonglonglonglineoftextthatneedstofitinsideagivenrectwidth
I see in MSDN DrawTextW() that DrawTextW() indicates:
If the largest word is wider than the rectangle, the width widens. If the text is less than the width of the rectangle, the width is reduced. If there is only one line of text, DrawText changes the right side of the rectangle so that it limits the last character in the line.
however, in MSDN docs, then the DrawTextExW() method does not indicate this.
So, I tried to calculate the height using the DrawTextExW() method, however the result will be the same as with the DrawTextW() function, where it extends the width of the rectangle to fit the largest line of text.
So, how can I correctly calculate the height of a text rectangle with a given (fixed) width when drawing a large line (without spaces), where DT_WORDBREAK and DT_CALCRECT are indicated?
EDIT:
As a note, does anyone know how Microsoft Excel does drawing cell text? Is there an API request for this text drawing? This is where my original question arose, however, the way it is implemented in Excel is to draw text and wordbreak / wordwrap on any character (and not just a space).
source share