Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mike_ryan
Visitor

Truncate Text on ImageCanvas

The docs say: "The text is drawn into the TargetRect. If it doesn't fit, then it will be clipped."

But my tests seem to indicate otherwise. Should text be clipped if it overflows the Target rectangle?
0 Kudos
13 REPLIES 13
TheEndless
Channel Surfer

Re: Truncate Text on ImageCanvas

Your tests results would mirror mine. I've found that text will wrap, but not truncate. One way around it would be to use roFontMetrics and a custom font (the metrics don't work with the built in fonts for some reason) to measure and clip the string yourself, but there is a definite performance penalty doing that, so you'll probably want to do some local caching.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
renojim
Community Streaming Expert

Re: Truncate Text on ImageCanvas

"TheEndless"the metrics don't work with the built in fonts for some reason[/quote wrote:

I've asked that support be added for the built-in fonts for just this reason. It shouldn't be necessary to use a custom font just for the ability to get the length of a displayed string.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
TheEndless
Channel Surfer

Re: Truncate Text on ImageCanvas

"renojim" wrote:
"TheEndless" wrote:
the metrics don't work with the built in fonts for some reason

I've asked that support be added for the built-in fonts for just this reason. It shouldn't be necessary to use a custom font just for the ability to get the length of a displayed string.

-JT

Agreed. In MainSqueeze I bounced back and forth between custom and system fonts. I ended up coming up with an average character width for each of the different system fonts, and calculate based on that. It can be wildly off on occasion, but it works for the most part.

If it helps, this is what I came up with...
If font = "Small" Then
letterWidth = 11
Else If font = "Medium" Then
letterWidth = 15
Else If font = "Large" Then
letterWidth = 21
Else If font = "Huge" Then
letterWidth = 35
End If
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
kbenson
Visitor

Re: Truncate Text on ImageCanvas

I actually spent a while one night mapping the exact character pixel widths for the Medium font in HD one night. Haven't bothered to use the results yet. Maybe we should just crowdsource this and be done with it? If I supply code to step through the characters and make it obvious to note the pixel length, is anyone interesting in running it for a font size/definition and submitting the results? If so, I'll put together a librokudev library to compute the size of a string (and lines required given a bounding box, etc)
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
TheEndless
Channel Surfer

Re: Truncate Text on ImageCanvas

"kbenson" wrote:
I actually spent a while one night mapping the exact character pixel widths for the Medium font in HD one night. Haven't bothered to use the results yet. Maybe we should just crowdsource this and be done with it? If I supply code to step through the characters and make it obvious to note the pixel length, is anyone interesting in running it for a font size/definition and submitting the results? If so, I'll put together a librokudev library to compute the size of a string (and lines required given a bounding box, etc)

I was going to do that, then I got lazy.. 😛
It should be pretty easy to draw each letter on a background image that has "registration marks" if you want to do it manually. Save a screenshot as a bitmap, and it should actually be possible to write a simple script that runs through the byte array and measures every one for you... Sounds like awfully tedious work just to workaround something that should be pretty straightforward for Roku to implement, though, especially since the built-in screens already truncate text.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
kbenson
Visitor

Re: Truncate Text on ImageCanvas

"TheEndless" wrote:

I was going to do that, then I got lazy.. 😛
It should be pretty easy to draw each letter on a background image that has "registration marks" if you want to do it manually. Save a screenshot as a bitmap, and it should actually be possible to write a simple script that runs through the byte array and measures every one for you... Sounds like awfully tedious work just to workaround something that should be pretty straightforward for Roku to implement, though, especially since the built-in screens already truncate text.


Yeah, that's sort of what I did for the medium font. I scripted a loop that displayed a few characters (x10 for each one) at a time, each overlaid onto some standard size ImageCanvas background colors. It was pretty easy to determine the sizes. Displaying 10 characters at a time makes it trivial, since the last character will end on a 10 pixel border, which is fairly easy to distinguish visually.

It wouldn't be hard to script something let you choose the font, and to do a screen per char (cycled with a button press) with the background boxes to make it obvious exactly what size the character is.
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
kbenson
Visitor

Re: Truncate Text on ImageCanvas

In an exercise in stupidity, I took my own challenge, and wrote a channel to crowd source this like I suggested I would. I could have just found all the sizes in that time, but that wouldn't have been as much fun (err, I guess).

https://owner.roku.com/Account/ChannelC ... =FONTSIZER

Size the fonts, and when done (or you've had enough), press PLAY to submit the stored data to a server. If enough people do it, I'll sanitize the data and post the results. It submits the data separated for SD and HD running sets, so numbers for both would be good (although I haven't run it on SD yet, so it may look funky).

Blah. Time to watch some Netflix.
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
RokuKevin
Visitor

Re: Truncate Text on ImageCanvas

Thanks for pointing out the issue of getting fontmetrics from system fonts.... I'm not sure why we can't do this, but we'll investigate.

--Kevin
0 Kudos
jbrave
Channel Surfer

Re: Truncate Text on ImageCanvas

Just a couple of comments: targetrect clipping may be the documented way it is supposed to work, but most programs that draw text in a scaleable rectangle wrap the text (microsoft word, adobe photoshop etc etc), so this is expected behavior for anyone who didn't read that page of the manual. I would hope that the wrap behavior does not change or you will probably break lots of channnels. Maybe add a wrap/clip switch with wrap as a default.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos