Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
lisakb140
Level 8

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
7 REPLIES 7
squirreltown
Level 9

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
Roku Employee
Roku Employee

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
Level 8

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
Level 9

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
Level 8

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

OK, thank you!
0 Kudos
norcaljohnny
Level 11

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
Level 8

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