ofTrueTypeFont: How to get the current spaceSize after loading

Hi, I found out ofTrueTypeFont::getSpaceSize() returns zero after loading the font. It only seemed to work once I manually set it with setSpaceSize().
I tried it with several fonts but the results were always the same.

void ofApp::setup(){

    font.load("font.ttf", 50);
    cout << "First : " << font.getSpaceSize() << endl;
    font.setSpaceSize(20);
    cout << "Second : " << font.getSpaceSize() << endl;
}

result :

First : 0
Second : 20

Is there a specific reason why it returns zero after loading or could this be a bug?

space size is a legacy api cause in the past instead of using the real space size we used the size of a p (if i remember well) so we allowed to set the space size by yourself, when we moved to using the real space size as defined by the font we probably forgot to either remove this function or set it to the correct value when loading the font type.

you can figure out the size of the space using font.getBoundingBox(" ",0,0).width but can you open an issue on github pointing to this post? thanks!

1 Like

I just did. Thanks @arturo

https://github.com/openframeworks/openFrameworks/issues/5547

I tried your suggestion but it doesn’t seemed to be working correctly.
font.getStringBoundingBox(" ", 0.0f, 0.0f).width returns weird value.

Here’s my test code,

font.load("font.ttf", 50);
font.setSpaceSize(font.getStringBoundingBox(" ", 0.0f, 0.0f).width);
cout << font.getStringBoundingBox(" ", 0.0f, 0.0f).width << endl;

and the result is as below and I see no space between letters.

-3.40282e+38

Could this be a bug ?