opcon / QuickFont

A Modern OpenGL Font Rendering Library for OpenTK

Home Page:https://github.com/opcon/QuickFont

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variable size font

MCVitzz opened this issue · comments

Hello, not sure if here is the best place to ask this, but is there any way to make the font scale according to it's bounding box?

Hi @MCVitzz,

No, there is no functionality for this built in.
You can get the width & height of some text with the Measure method on QFont (within some bounding box maxSize), but that doesn't really help as generating a new QFont object with a different font size is a reasonably expensive operation.

What is your use case for the font scaling? If it is scaling the GUI to match different resolutions then you can set the projection matrix on QFontDrawing to match your GUI projection matrix and scale with that.

Otherwise if you need to dynamically scale your font size to fit either a changing amount of text, or a changing bounding box size, it is a bit trickier.
One thing you could try is setting a few font sizes as "breakpoints", and switching between them as the bounding box gets filled up? e.g., have QFont objects for, say, 12, 16, 20, 24, 28pt, start at the largest size & work your way down when the bounding box is full?

Hello,
Yes, it's the GUI Scaling issue, I'm trying to have scaling GUI and variable resolution screens, I'm using the projection matrix already and updating it to the current resolution, I also have a follow up question, is it possible to center the text vertically with the bounding box? I've search for it in the options but I might have missed something...
Thank you for all the help!

To center the text vertically you will need to get the text height (from a Measure call) and then apply the offset manually