shess
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2017
09:50 PM
Get Font from Label in BrightScript?
In XML, if I define a label to use a custom font:
In BrightScript, how do I get to the actual ifFont object so that I can make calls like GetOneLineWidth?
<Label>
id="label"
<Font role = "font" uri = "pkg:/fonts/font.ttf" size = "24" />
</Label>
In BrightScript, how do I get to the actual ifFont object so that I can make calls like GetOneLineWidth?
10 REPLIES 10

squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2017
07:20 AM
Re: Get Font from Label in BrightScript?
https://sdkdocs.roku.com/display/sdkdoc/roFont
for custom:
fontreg = createobject("rofontregistry")
fontreg.Register("pkg:/images/fonts/customfont.tff")
for custom:
fontreg = createobject("rofontregistry")
fontreg.Register("pkg:/images/fonts/customfont.tff")
Kinetics Screensavers
shess
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2017
09:24 PM
Re: Get Font from Label in BrightScript?
So - I can't query the node for the font - I have to look in the XML and copy out the font name and the size? I guess that works, but means every time the XML changes, you have to find any reference in code and update it, too. 😞
rymawby
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2017
02:21 AM
Re: Get Font from Label in BrightScript?
You could actually get the values from the font object using brightscript and then use these values in the getFont call.
So if you had your label like:
You could get the values of this font by doing something like:
You could then use fontURI and fontSize in your roFontRegistry getFont calls.
Hope this helps.
So if you had your label like:
<Label
id="myLabel"
text="Awesome"
translation="[300,300]" >
<Font role = "font" uri = "pkg:/components/fonts/Helvetica.otf" size = "24" />
</Label>
You could get the values of this font by doing something like:
myLabel = m.top.findNode("myLabel")
myFont = myLabel.font
fontURI = myFont.uri
fontSize = myFont.size
You could then use fontURI and fontSize in your roFontRegistry getFont calls.
Hope this helps.
joetesta
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2017
10:26 AM
Re: Get Font from Label in BrightScript?
Be warned:
A) getOneLineWidth works only in task node
B) Due to firmware upscaling on lower devices such as Roku 3 you will have incorrect values for dimensions not divisible by 3
If you are able to use boundingRect() you will have much easier time and better success.
hope it helps,
Joe
A) getOneLineWidth works only in task node
B) Due to firmware upscaling on lower devices such as Roku 3 you will have incorrect values for dimensions not divisible by 3
If you are able to use boundingRect() you will have much easier time and better success.
hope it helps,
Joe
aspiring
shess
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2017
03:59 PM
Re: Get Font from Label in BrightScript?
Please pardon my slow reply, I got pulled away for a while.
Thank you both for your replies.
At the end of the day, what I'm trying to do is to work around not being able to set the width for a RowList row label. I have a RowList that is fairly narrow, but might have a long row title. That label doesn't seem to pay attention to ItemSize. The only way I can think to work around it is to manually truncate the string if it is going to be too long for that RowList row label - unless there is a better way?
Thanks!
Thank you both for your replies.
At the end of the day, what I'm trying to do is to work around not being able to set the width for a RowList row label. I have a RowList that is fairly narrow, but might have a long row title. That label doesn't seem to pay attention to ItemSize. The only way I can think to work around it is to manually truncate the string if it is going to be too long for that RowList row label - unless there is a better way?
Thanks!
joetesta
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2017
05:44 PM
Re: Get Font from Label in BrightScript?
I have a few ideas but not sure what would actually work or best suit your needs.
1) Probably easiest to code is a brute-forcish method, check the label's boundingRect().width and compare to the rowlist width. If it's wider, peel letters off the end until it's not wider.
2) If you'd prefer to have the letters actually chopped in half at the boundary, you could wrap the label in a group with clippingRect 3rd array value equal to the rowlist width.
3) You could also probably update the label fields "ellipsisText" to get rid of the dots and set the width equal to the rowlist, then it won't have a chopped off character and would be slightly less "hack-y" than the first option
hope this helps,
Joe
1) Probably easiest to code is a brute-forcish method, check the label's boundingRect().width and compare to the rowlist width. If it's wider, peel letters off the end until it's not wider.
2) If you'd prefer to have the letters actually chopped in half at the boundary, you could wrap the label in a group with clippingRect 3rd array value equal to the rowlist width.
3) You could also probably update the label fields "ellipsisText" to get rid of the dots and set the width equal to the rowlist, then it won't have a chopped off character and would be slightly less "hack-y" than the first option
hope this helps,
Joe
aspiring
shess
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2017
11:25 PM
Re: Get Font from Label in BrightScript?
Hi Joe,
Do we have access to the RowList row label directly?
Do we have access to the RowList row label directly?
joetesta
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2017
08:16 PM
Re: Get Font from Label in BrightScript?
"shess" wrote:
Hi Joe,
Do we have access to the RowList row label directly?
looks like yes - rowlist has a field "rowTitleComponentName" that you can use to specify a custom component that is used for each row's label.
In that custom component you can add the code to do the trimming.
aspiring
shess
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2017
01:05 PM
Re: Get Font from Label in BrightScript?
Hey Joe,
Huh - that seems like an easy fix - I like it! Is there any way that could be dynamic? If I create a custom node that inherits from label and set it as that rowlist label component, I'm going to have to hardcode that width into that component, yes?
Thanks, I appreciate your time!
Huh - that seems like an easy fix - I like it! Is there any way that could be dynamic? If I create a custom node that inherits from label and set it as that rowlist label component, I'm going to have to hardcode that width into that component, yes?
Thanks, I appreciate your time!