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

Using custom fonts (.ttf files) in XML

I am trying to use 2 fonts (I have their ttf files saved in a folder within my project called "fonts"), and am having trouble incorporating them properly in my nodes in my xml files. 

I've tried including this in my nodes:


font="pkg:/fonts/font:Muli-ExtraLight.ttf"


but that doesn't work.

I've read that fonts need to be included in the fonts directory in a package file, following this example: https://sdkdocs.roku.com/display/sdkdoc/Font

Is there something I am doing wrong??

UPDATE:

I've also tried putting this directly in one of my .brs files

[b]font[/b]  = [i]CreateObject[/i]("roSGNode", "Font")
    font.uri = "pkg:/fonts/font:Muli-ExtraLight.ttf"

but I get an Error message saying this is an invalid path!
My fonts directory is top-level, as in it's the same level as my components folder. I don't understand why this path would be invalid!!
0 Kudos
9 REPLIES 9
squirreltown
Roku Guru

Re: Using custom fonts (.ttf files) in XML

font  = CreateObject("roSGNode", "Font")
font.uri = "pkg:/images/optima.otf"
font.size = 42
font.color="0xFFFFFFFF"

I don't use the xml but this works fine in the  init() function in my .brs file.
Kinetics Screensavers
0 Kudos
RokuBen
Community Moderator
Community Moderator

Re: Using custom fonts (.ttf files) in XML

Using a colon in the filename might be a problem and prevent the system from opening the file.  There are filename checks in the Roku OS to filter out things that affect FAT filesystems, and colon is a reserved character there.
0 Kudos
lisakb140
Visitor

Re: Using custom fonts (.ttf files) in XML

Thanks-- I think I got this working actually-- turns out my node needed to be:


                    <Label
id="Title"
translation="[60, 135]"
color="0xf5f5f5"
font="font:Muli-ExtraLight">
<Font role="font"uri = "pkg:/fonts/Muli-ExtraLight.ttf" size="24"/>
                      </Label>

 Which was a little different.

Thank you for double checking the .brs code-- I have a question, though..I just put a secondary font in my XML file (in a node), just for a section with a different font treatment. However, I didn't put that font in my brs file, and it still works. If that's so, then what is the point of putting it in the brs file? Is that necessary??
0 Kudos
squirreltown
Roku Guru

Re: Using custom fonts (.ttf files) in XML

"lisakb140" wrote:
However, I didn't put that font in my brs file, and it still works. If that's so, then what is the point of putting it in the brs file? Is that necessary??

If you're asking me,  It only needs to be in one place. I don't use the xml file, so for me everything is in the .brs file.
Kinetics Screensavers
0 Kudos
lisakb140
Visitor

Re: Using custom fonts (.ttf files) in XML

OK, thank you!
0 Kudos
norcaljohnny
Roku Guru

Re: Using custom fonts (.ttf files) in XML

Have you considered something like this?


      label = CreateObject("roSGNode", "Label")
      font  = CreateObject("roSGNode", "Font")
      font.uri = "pkg:/fonts/yourFont.ttf"
      font.size = 20
      label.font = font

Now all your label fonts will use your font. Assuming you want to reuse your font for the labels and not duplicate font codes.
0 Kudos
oa24153
Binge Watcher

Re: Using custom fonts (.ttf files) in XML

It gives me error on role?

cvc-complex-type.3.2.2: Attribute 'role' is not allowed to appear in element 'Font'.

0 Kudos

Re: Using custom fonts (.ttf files) in XML

you wouldnt believe that using the font file in the images instead of the fonts directory would be the solution for me, isnt the folder of fonts being included to the bundle ? where is that even defined ?

0 Kudos
renojim
Community Streaming Expert

Re: Using custom fonts (.ttf files) in XML

@random_user, you can put the font file anywhere you want - you just have to use the proper path in your code/XML.  It sounds like however you're creating your zip file it isn't pulling in the fonts directory.

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
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.