Your Digital Media Has Never Looked So Good

 
shess
Topic Author
Posts: 4
Joined: Sat Sep 09, 2017 9:55 pm

Get Font from Label in BrightScript?

Mon Oct 09, 2017 9:50 pm

In XML, if I define a label to use a custom font:

<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?
 
User avatar
squirreltown
Posts: 732
Joined: Sun Apr 21, 2013 2:20 pm

Re: Get Font from Label in BrightScript?

Tue Oct 10, 2017 7:20 am

https://sdkdocs.roku.com/display/sdkdoc/roFont
for custom:
fontreg = createobject("rofontregistry")
fontreg.Register("pkg:/images/fonts/customfont.tff")
Kinetics Screensaver (kineticsscreensaver), Kinetics³ Screensaver(kinetics3), Kinetics Painter Screensaver (kineticspainter), Kinetics Splash Screensaver (kineticssplash)
 
shess
Topic Author
Posts: 4
Joined: Sat Sep 09, 2017 9:55 pm

Re: Get Font from Label in BrightScript?

Tue Oct 10, 2017 9:24 pm

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
Posts: 15
Joined: Fri Jan 16, 2015 9:03 am
Contact:

Re: Get Font from Label in BrightScript?

Wed Oct 11, 2017 2:21 am

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:

<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.
---
Blogging Roku stuff at http://rymawby.com
---
 
joetesta
Posts: 541
Joined: Wed Apr 20, 2011 11:48 am

Re: Get Font from Label in BrightScript?

Wed Oct 11, 2017 10:26 am

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
aspiring

Who is online

Users browsing this forum: No registered users and 3 guests