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

Create Font

Hello everybody,

In the SDK, there is this example :

fontReg.Register("pkg:/fonts/LCDMono.ttf")
font = fontReg.Get("LCDMono",36,50,false) ' 36pt, 50 is normal weight, no italics


I suppose the second figure represents the fact that the font is bold or not. Am i wrong? If no, why a value, and not a boolean like italics? How do you know which value to chose?

Thank you.

Denis


EDIT:
I managed to get text shown on a roScreen with default settings, but when i create my font nothing appears. Is there something i am missing? I created a "fonts" folder and copied the ttf files from my windows in it.

my_font = CreateObject("roFontRegistry")
my_font.Register("pkg:/fonts/calibri.ttf")
my_font.Get("calibri", 14, 50, false)
bitmap.DrawRect(x, y, 300, 50, &h00000000)
bitmap.DrawText(Final_Array[i][j], x, y, &hFFFFFFFF, my_font)
screen.DrawObject(0, 0, bitmap)
screen.Finish()


Thank you.
0 Kudos
7 REPLIES 7
DLC
Visitor

Re: Create Font

Well it looks like roScreen doesn't use the roFontRegistry even if it uses the DrawText function from ifDraw2D, so i changed for a roImageCanvas, and it works fine so i'll go on with canvas.
0 Kudos
DLC
Visitor

Re: Create Font

Nobody knows how to chose the second figure when creating the font?
I tried with 1, 50 and 100, and i can't see any difference.
Thank you.
0 Kudos
TheEndless
Channel Surfer

Re: Create Font

I think it depends on the font. Some fonts have multiple different weights. If the font you're using does, then the number you provide determines which weight to use. If your font only has one weight for bold, then any value you supply will return the same.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
DLC
Visitor

Re: Create Font

"TheEndless" wrote:
Some fonts have multiple different weights. If the font you're using does, ...


Ok, but how can I know if my font does or not please? I have opened the ttf files of my font, which is times for the moment, but i don't see anything concerning the weight, only examples of sizes.
0 Kudos
TheEndless
Channel Surfer

Re: Create Font

"DLC" wrote:
"TheEndless" wrote:
Some fonts have multiple different weights. If the font you're using does, ...

Ok, but how can I know if my font does or not please? I have opened the ttf files of my font, which is times for the moment, but i don't see anything concerning the weight, only examples of sizes.

I'm not sure. I imagine, if you're licensing a font for use in your channel, the documentation for that font should tell you. Chances are, if you're not seeing a difference, then either the font you're using doesn't have different weights, or it's not actually implemented in the firmware.. For what it's worth, the roScreen version of GetFont() only accepts a True/False for the boldness parameter.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos

Re: Create Font

"DLC" wrote:


my_font = CreateObject("roFontRegistry")
my_font.Register("pkg:/fonts/calibri.ttf")
my_font.Get("calibri", 14, 50, false)
bitmap.DrawRect(x, y, 300, 50, &h00000000)
bitmap.DrawText(Final_Array[i][j], x, y, &hFFFFFFFF, my_font)
screen.DrawObject(0, 0, bitmap)
screen.Finish()


Thank you.


In my code I do something like this:

frg = CreateObject("roFontRegistry")
frg.Register("pkg:/fonts/myfont.ttf")
fonts = frg.GetFamilies()
font = frg.GetFont(fonts[0], 32, false, false)
bmp.DrawText("My Text", 0, 0, &h000000FF, font)


Hope that helps. Note that this pulls the first font variation. Some fonts will have multiple variations (i.e. condensed). It looks like the mistake in your code is that you are trying to use an roFontRegistry object in the place of an roFont object in your DrawText function.
0 Kudos
DLC
Visitor

Re: Create Font

Well I corrected and I can now chose my font and its size, though I still cannot find how to use boldness, but that will be ok.
Thanks to both of you 😄
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.