Jump to content

Changing fontsize of loaded font


Phodex Games
 Share

Recommended Posts

Hi :)

I am heavily working on my own user interface system at them moment and I wonder if there is a easy way to resize a loaded font. Example pseudo code for the functionality I am searching for:

--Pseudo Code
self.font = Font:Load("Arial", 6, Font.Smooth) --Load Font
self.font:SetSize(10) --Change size during runtime

I have a solution for this by preloading the font in all sizes and then change the rendered font. But this isn't memory efficient, or are Fonts so small that it makes no diffrence, either way it does create a lot of code :( Thanks for ideas in advance

Markus from Phodex

Link to comment
Share on other sites

I do the same thing in my UI system. I don't give a real font number in my UI. Instead I just do ex_small, small, medium, large, ex_large, and fill. Each "label" is a ui widget that is basically a rectangle area and I load the font for all various sizes and then I use the text functions to figure out which size is best given the ui widget area which scales by screen resolution. This way the font always "scales" as well. Yes, it's a pain, and yes you have to load various sizes (I go by 2's) but I couldn't find any way around it to get scaling fonts that don't look all stretched if you wrote to a texture and scaled the texture.

Link to comment
Share on other sites

3 minutes ago, Rick said:

I do the same thing in my UI system. I don't give a real font number in my UI. Instead I just do ex_small, small, medium, large, ex_large, and fill. Each "label" is a ui widget that is basically a rectangle area and I load the font for all various sizes and then I use the text functions to figure out which size is best given the ui widget area which scales by screen resolution. This way the font always "scales" as well. Yes, it's a pain, and yes you have to load various sizes (I go by 2's) but I couldn't find any way around it to get scaling fonts that don't look all stretched if you wrote to a texture and scaled the texture.

Hi Rick thanks for your answer, you got me an idea. I do it very similar within my system, but I could implement something so my UI system calculates all needed font sizes and then I only load those font sizes, instead of loading all fontsizes at once. But then, if you ever resize during runtime, you may need to load a new font, which I would like to prevent if happening during runtime, but that is not such a big deal, I guess I am just a little bit too perfectionist :D. Either way thanks for your input. Have a nice day!

  • Upvote 1
Link to comment
Share on other sites

When a font is loaded, the vector image is rasterized into a texture and the vector data is dumped. So it can't really be resized without reloading the file. I would like to create similar functionality for loading SVG vector images.

  • Like 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...