c++ - Making DrawText break a string -
so can make drawtext break string if string has spaces, or if put in \r\n @ end of string. however, long string has no spaces or line breaks in continues past drawing rectangle , gets clipped. prevent this, if possible.
nothing in format flags drawtext stood out me make happen. ideas?
what normally use dt_wordbreak
flag. drawtext documentation on msdn, this:
breaks words. lines automatically broken between words if word extend past edge of rectangle specified lprect parameter. carriage return-line feed sequence breaks line.
if not specified, output on 1 line.
however, have single unbreakable line - is, there no words. you need after breaks yourself. can solve 2 ways:
use
drawtext
dt_calcrect
calculate size of rectangle - loop, shortening string, until you've found string first line, repeat remaining string. is, find subset index 0-n fits horizontally in width of drawing area; find string n+1-m fits horizontally again; repeat until hit end of string. concatenate these substrings\r\n
between each force manual break, drawdrawtext
, wrap correctly.use
drawtextex
, pass in pointerdrawtextparams
structure. hasuilengthdrawn
member "the number of characters processed drawtextex, including white-space characters. number can length of string or index of first line falls below drawing area." should not pass indt_noclip
. (without testing it) work give same information first method without looping: key bit makes me uncertain phrase "below" drawing area, , if line unbreakable may think processed entire text.
the first method work , simple version of use own rich text processing.
Comments
Post a Comment