Page 1 of 2

I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 5:23 am
by Bernard51
Hello

I'm loading a .tff file and using a size of 120, How to put a second text with the same font but with a size of 50, basically I want 2 texts with the same font but with 2 different sizes ??
https://www.dropbox.com/s/nwkjaetppb99b ... 1.zip?dl=0
Thank you Bernard

Re: I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 6:58 am
by zorg
create another font with the same ttf file, but with a size of 50; assuming you assigned both of them to separate variables, you can setFont them whenever you want to switch fonts.

Re: I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 7:53 am
by Bernard51
thank you

I have to reload the same file twice with a different size?

Re: I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 9:51 am
by zorg
It seems to be that way, though i'm not sure whether there are any optimizations under the hood or not;

I wanted to say that you could cheat a bit by creating a Rasterizer instead, and then creating two differently sized fonts using that instead of the font file, but apparently the rasterizers themselves require the font size to be defined, so even if love.graphics.newFont coult take a Rasterizer object, we would not have moved forward too much.

Then again, love.graphics.newFont might accept a FileData object, so you could load the file itself into RAM only once, and use that to create two fonts with different sizes; that may be a viable solution...

Re: I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 12:55 pm
by Bernard51
thank you

do you have a tutorial on fileData?

Re: I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 1:47 pm
by zorg
Apart from clicking the link in my previous post that takes you to its wiki article, here's a quick code you can look at:

Code: Select all

myFontFileData = love.filesystem.newFileData('relative.path.to.your.font.ttf')
myFont120pt = love.graphics.newFont(myFontFileData, 120)
myFont50pt = love.graphics.newFont(myFontFileData, 50)
-- of course, you could also have just one table called myFont, and have the 50th and 120th index be the Font objects you create; it's a matter of preference only, though.
Then again, i'm making an assumption here that love.graphics.newFont being able to take a FileData as its parameter, since a lot of functions can that aren't necessarily notated on the wiki as such. If it doesn't support it, then we're back to the original solution, creating the two sizes of the same font twice from disk.

Re: I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 1:58 pm
by Bernard51
Thank you very much

Re: I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 3:15 pm
by Nelvin
Just some additional info ... if you use lots of different characters in a pretty big size your area of interest might be the required resources for the cached bitmaps/textures of the font instead of the loaded ttf-file. The bitmaps for the characters will be created and cached by love automatically (only those you actually used, so it highly depends on what you print and how many different fonts and sizes you use).

Re: I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 3:55 pm
by Bernard51
Thank you very much

Re: I want 2 texts with the same font but with 2 different sizes??

Posted: Fri Aug 10, 2018 6:21 pm
by pgimeno
"All variants which accept a filename can also accept a Data object instead." - love.graphics.newFont

A FileData object is a Data object. It's documented to work.