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: 
greubel
Visitor

Fonts are Killing Me !

This has been reported numerous times BUT here goes again. I'm having trouble finding the length of a string to display with roImageCanvas. If the string is too long for a field, I either want to reduce the size of the font or chop some words off. But the call to GetOneLineWidth() returns something smaller than the actual size. So when I think I have a good size and the line is rendered, the routine in roImageCanvas likes to arbitrarily chop off the last word and wrap it to a new line.
So I wrote a small test to show this.

The background of each character line is adjustable, so you can find the actual pixel size of a character.
This is the background width divided by the number of characters (20).

The first line displayed shows the character value and the size of the character for each of the font sizes I use.
The next six lines are the test strings with the adjustable background. The end of the line is the mnemonic and actual font index.

The "String Size" line is output from a routine I wrote to give a FASTER line width.
I found that the system's routine was upwards of 200ms to get the width. Mine around 50ms, always.

The "Actual Size" line is output from the GetOneLineWidth() routine.

Now notice that the GetOneLineWidth() routine reports "Large Font" at a size of 20, when in actuality it is 22. So for 20 "A"s, that would be 40 pixels off.
No wonder it wraps. I guess the code in roImageCanvas doesn't use the GetOneLineWidth() routine !

Test using default font - Mini(10) Small(13) Medium(17) Large(22) Big(30) Huge(36)


I don't know why an external font is a lot closer, 1 pixel ??? BUT that could still be 20 pixels off.
Test using external font
Tags (1)
0 Kudos
11 REPLIES 11
RokuJoel
Binge Watcher

Re: Fonts are Killing Me !

Well... GetOneLineWidth was created specifically for working with the roScreen component, as I understand it, not for the roImageCanvas component, but I'll pass this on to the engineers responsible for that component and see what they have to say.

- Joel
0 Kudos
RokuJoel
Binge Watcher

Re: Fonts are Killing Me !

Per the engineer:

"...that method should only be used with an RoFont to draw text onto an RoScreen."

- Joel
0 Kudos
renojim
Community Streaming Expert

Re: Fonts are Killing Me !

I would think you should be using fontMetrics() for an image canvas, but I believe you have to be using an external font.

-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
greubel
Visitor

Re: Fonts are Killing Me !

I am using roFont().

From the SDK !
"roFontMetrics (deprecated) This class is deprecated. Developers should use roFont methods (GetOneLineHeight and GetOneLineWidth)."

The example from the roFontMetrics page does show "roImageCanvas" usage.

But to me "deprecated" says NOT to use it !
0 Kudos
greubel
Visitor

Re: Fonts are Killing Me !

I changed the test routine to use FontMetrics for the default font and the results are almost the same.
The font size for Mini, Small, Medium and Huge dropped a point from GetOneLineWidth().
BUT the size is now off by 1, 2, 2, 2, 3 and 4 pixels for the character sizes.

How does roImageCanvas determine the string length and what forces him to wrap ?

I do understand that when using roScreen and then calling the size routine and it returns a value you like, YOU are going the do the draw() and it WILL fit !
But by calling the roImageCanvas routine, you are at his mercy and no telling what the screen will look like.
I do have one solution, just make the width of the rectangle the screen width.
Hopefully that will fit, without wrapping even though it may be bigger than you wanted.

The "String Size" line is generated from a table I build during font initialization from an average character size by using GetOneLineWidth().
The "Actual Size" line is the result of the FontMetrics.Size() / 20

0 Kudos
TheEndless
Channel Surfer

Re: Fonts are Killing Me !

May or may not help, but you can use "Default" as the font, and that'll use the same default font that is used on roScreen (DejaVu Sans Condensed, if I'm not mistaken), which should (??) give you more accurate GetOneLineWidth() results. I haven't tried it, but you might even be able to manipulate the string representation that roImageCanvas uses for fonts to change the size.
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
greubel
Visitor

Re: Fonts are Killing Me !

Thanks but that is what I think I am using if an external font is not supplied.

if font <> invalid
GetFont(font, size as Integer, bold as Boolean, italic as Boolean) as Object
else
GetDefaultFont(size as Integer, bold as Boolean, italic as Boolean) as Object
end if

I could almost live with the size being wrong if he didn't wrap.
He doesn't even respect my rectangle boundaries.
0 Kudos
TheEndless
Channel Surfer

Re: Fonts are Killing Me !

"greubel" wrote:
Thanks but that is what I think I am using if an external font is not supplied.

if font <> invalid
GetFont(font, size as Integer, bold as Boolean, italic as Boolean) as Object
else
GetDefaultFont(size as Integer, bold as Boolean, italic as Boolean) as Object
end if

I could almost live with the size being wrong if he didn't wrap.
He doesn't even respect my rectangle boundaries.

I thought you were using the built-in roImageCanvas fonts ("Small", "Medium", "Large", and "Huge"), which use a completely different font than "Default", but if you're using the GetDefaultFont() method, I guess not. I didn't even think GetDefaultFont() worked with roImageCanvas. The documentation states that you should use the roFontRegistry.Get() method for use with the roImageCanvas, which makes sense, since it expects a string instead of an roFont object.

Sounds like we definitely need some clarification from the Roku folk.
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
greubel
Visitor

Re: Fonts are Killing Me !

roImageCanvas will work with the "mnemonic" or a font object which I use on most of my screens.
0 Kudos