Your Digital Media Has Never Looked So Good

 
lisakb140
Topic Author
Posts: 23
Joined: Tue Aug 14, 2018 8:18 am

Using custom fonts (.ttf files) in XML

Wed Oct 10, 2018 12:05 pm

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

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

Wed Oct 10, 2018 12:23 pm

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
 
User avatar
RokuBen
Posts: 56
Joined: Mon Apr 21, 2014 12:35 pm
Location: Austin, TX

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

Wed Oct 10, 2018 12:33 pm

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.
 
lisakb140
Topic Author
Posts: 23
Joined: Tue Aug 14, 2018 8:18 am

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

Wed Oct 10, 2018 1:16 pm

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

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

Wed Oct 10, 2018 1:26 pm

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
 
lisakb140
Topic Author
Posts: 23
Joined: Tue Aug 14, 2018 8:18 am

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

Wed Oct 10, 2018 1:38 pm

OK, thank you!

Who is online

Users browsing this forum: No registered users and 3 guests