Displaying as much text as possible
-
Hello folks! Am looking for a way to do this: i have a rectangle that specifies the available space for some text. I want to display as much as possible of this text. What i mean is, if the text fits nicely in the rectangle, it should be displayed as usual, centered with wordbreaks as needed (DrawText with DT_WORDBREAK | DT_CENTER). However, when the specified rectangle is too small, the text doesn't fit into it even with wordbreaks (e.g. there are a few long words) then i'd like the text to e.g wrap around at positions where the long words would "hang out" of the rectangle. First i tried DT_CALCRECT with DrawText to check if the text fits, if yes then i simply draw it with DrawText and go on, if not, then i tokenized the string using space as separator/delimiter. Then i iterated trough the words and checked the widths of the words and if they were too wide then i'd find the character inside the word which would hang out of the rectange and inserted a space. After this, i used DrawText again with DT_WORDBREAK to display the string. This works reasonably well but not well enough because it produces things like this: (the text is "This is somewhat longer" and there's space for 3 lines)
---------
|This is|
|somewha|
| t | <- a whole word is lost ("longer")I guess one alternative i can go for is wrapping the whole string
---------
|This is|
|somewha|
|t longe| <- i see more of "longer" herebut am not sure if doing this is the only/best way, and also i don't know how to wrap text aside of writing it character by character myself checking before each letter if it would hang out or not and "linefeeding" as needed + handling spaces specially (something like not display them if they are at a linebreak position). I have a faint memory from the good old times that something like DT_WORDWRAP or somesuch existed but i see no trace of it now so it's either gone or it never had existed at all and i have a few bit errors in my memory. Any suggestions before i go into implementing the char-by-char thing? There should be a better way (i don't wish to go into dynamically selecting font sizes, let us assume the font is fixed)... P.S: Am using GDI (CDC::DrawText and friends...)
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got bet
-
Hello folks! Am looking for a way to do this: i have a rectangle that specifies the available space for some text. I want to display as much as possible of this text. What i mean is, if the text fits nicely in the rectangle, it should be displayed as usual, centered with wordbreaks as needed (DrawText with DT_WORDBREAK | DT_CENTER). However, when the specified rectangle is too small, the text doesn't fit into it even with wordbreaks (e.g. there are a few long words) then i'd like the text to e.g wrap around at positions where the long words would "hang out" of the rectangle. First i tried DT_CALCRECT with DrawText to check if the text fits, if yes then i simply draw it with DrawText and go on, if not, then i tokenized the string using space as separator/delimiter. Then i iterated trough the words and checked the widths of the words and if they were too wide then i'd find the character inside the word which would hang out of the rectange and inserted a space. After this, i used DrawText again with DT_WORDBREAK to display the string. This works reasonably well but not well enough because it produces things like this: (the text is "This is somewhat longer" and there's space for 3 lines)
---------
|This is|
|somewha|
| t | <- a whole word is lost ("longer")I guess one alternative i can go for is wrapping the whole string
---------
|This is|
|somewha|
|t longe| <- i see more of "longer" herebut am not sure if doing this is the only/best way, and also i don't know how to wrap text aside of writing it character by character myself checking before each letter if it would hang out or not and "linefeeding" as needed + handling spaces specially (something like not display them if they are at a linebreak position). I have a faint memory from the good old times that something like DT_WORDWRAP or somesuch existed but i see no trace of it now so it's either gone or it never had existed at all and i have a few bit errors in my memory. Any suggestions before i go into implementing the char-by-char thing? There should be a better way (i don't wish to go into dynamically selecting font sizes, let us assume the font is fixed)... P.S: Am using GDI (CDC::DrawText and friends...)
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got bet
Don't know who downvoted you, but have my 5 in compensation. It's an interesting question (even if the answer is going to be WAAAAY too long). I suspect you're going to be forced into "measure each char and draw it somewhere" stuff. Cheers, Peter
Software rusts. Simon Stephenson, ca 1994.
-
Don't know who downvoted you, but have my 5 in compensation. It's an interesting question (even if the answer is going to be WAAAAY too long). I suspect you're going to be forced into "measure each char and draw it somewhere" stuff. Cheers, Peter
Software rusts. Simon Stephenson, ca 1994.
Thank you very much. I don't know what the problem is with my question that it needed a downvote. Anyways, for now i went with the following aproach: if the text doesn't fit, i go char by char, calculate sizes, when i hit the "line-end" then i insert a linefeed ('\n') in the string and after i hit the end of the string, i output it with DrawText without DT_WORDBREAK.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got better resolution than the real world <
-
Hello folks! Am looking for a way to do this: i have a rectangle that specifies the available space for some text. I want to display as much as possible of this text. What i mean is, if the text fits nicely in the rectangle, it should be displayed as usual, centered with wordbreaks as needed (DrawText with DT_WORDBREAK | DT_CENTER). However, when the specified rectangle is too small, the text doesn't fit into it even with wordbreaks (e.g. there are a few long words) then i'd like the text to e.g wrap around at positions where the long words would "hang out" of the rectangle. First i tried DT_CALCRECT with DrawText to check if the text fits, if yes then i simply draw it with DrawText and go on, if not, then i tokenized the string using space as separator/delimiter. Then i iterated trough the words and checked the widths of the words and if they were too wide then i'd find the character inside the word which would hang out of the rectange and inserted a space. After this, i used DrawText again with DT_WORDBREAK to display the string. This works reasonably well but not well enough because it produces things like this: (the text is "This is somewhat longer" and there's space for 3 lines)
---------
|This is|
|somewha|
| t | <- a whole word is lost ("longer")I guess one alternative i can go for is wrapping the whole string
---------
|This is|
|somewha|
|t longe| <- i see more of "longer" herebut am not sure if doing this is the only/best way, and also i don't know how to wrap text aside of writing it character by character myself checking before each letter if it would hang out or not and "linefeeding" as needed + handling spaces specially (something like not display them if they are at a linebreak position). I have a faint memory from the good old times that something like DT_WORDWRAP or somesuch existed but i see no trace of it now so it's either gone or it never had existed at all and i have a few bit errors in my memory. Any suggestions before i go into implementing the char-by-char thing? There should be a better way (i don't wish to go into dynamically selecting font sizes, let us assume the font is fixed)... P.S: Am using GDI (CDC::DrawText and friends...)
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got bet
-
Isn't this why we have scrollbars?
Just say 'NO' to evaluated arguments for diadic functions! Ash
No, this is why we have larger monitors. :laugh:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Isn't this why we have scrollbars?
Just say 'NO' to evaluated arguments for diadic functions! Ash
Thanks for the suggestion but not in this situation. Basicly what i have is (something similar to) a "grid" of rectangular cells, each cell displaying textual information for the user, the user can resize this "grid", and i would like to present him as much information as i can when he "shrinks" the whole thing. Displaying a scrollbar wouldn'd be really usefull here i guess. The user will have tooltips to aid him but the more he can determine by just looking at the thing the better it should be.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got better resolution than the real world <