idunno
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2012
09:00 AM
How Do I Stop Text Wrapping
When I use targetRect to place text on a canvas, if the text is too long, it wraps to the next line. I have several targetRects, organized vertically with the text taken from an rss feed. This means that if the text taken from the feed is too long, the words go to the next line and get jumbled up with the text in the other targetRects, making it impossible to read, so I was wondering if there was any way to keep the text from wrapping to the next line, like somehow saying that the text can only use two horizontal lines?
6 REPLIES 6
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2012
09:11 AM
Re: How Do I Stop Text Wrapping
You could check the string length -
if len(variable)>40 then
variable=variable.left(40)
end if
This will truncate the text of the value to 40 characters.
if len(variable)>40 then
variable=variable.left(40)
end if
This will truncate the text of the value to 40 characters.
idunno
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2012
09:32 AM
Re: How Do I Stop Text Wrapping
I appreciate the suggestion, but I've already tried that. The problem is, if two long words are placed on the same line the second word is kicked down to the next line. For example, only 20 characters can be on a line, and my layout only allow two lines, so you would think I would be able to allow 40 character, however, if the words in the targetRect are Illinois Christian Association Conference Meets Tuesday, the text would appear as
Illinois Christian '19 Numbers Demonstrate number of characters on each line including "spaces"
Association '12
Conferenc '9
and go over my two line limit. I was hoping there was a way to limit number of lines used.
Illinois Christian '19 Numbers Demonstrate number of characters on each line including "spaces"
Association '12
Conferenc '9
and go over my two line limit. I was hoping there was a way to limit number of lines used.

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2012
10:30 AM
Re: How Do I Stop Text Wrapping
The most accurate way to do this would be to call GetOneLineWidth() repeatedly on successively longer substrings of the string you want to print, until you reach the rectangle width, then print that final substring. Something like this (just off the top of my head, not tested):
function GetPrintable(font as Object, str as String, width as Integer) as String
for i = 1 to Len(str)
ss = str.Left(i)
if font.GetOneLineWidth(ss, 99999) > width then return str.Left(i-1)
end for
return str
end function
idunno
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2012
08:55 AM
Re: How Do I Stop Text Wrapping
Please explain the font variable to me, for example where do I get it from?


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2012
09:16 AM
Re: How Do I Stop Text Wrapping
"idunno" wrote:
Please explain the font variable to me, for example where do I get it from?
The font variable there is an instance of the roFont component: http://sdkdocs.roku.com/display/RokuSDKv43/roFont
idunno
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2012
01:30 PM
Re: How Do I Stop Text Wrapping
This works, except for some reason whenever there is an apostrophe it messes up the length counter and just prints the whole thing. Is this a known problem, or a mistake I have made?