TTF_GlyphMetrics

Is TTF_GlyphMetrics broken in SDL_TTF_VERSION 2.0.15?

int TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
int *minx, int *maxx, int *miny, int *maxy, int *advance)
{

printf( "TTF_GlyphMetrics\n" );
printf( "%d\n", ch );

c_glyph *glyph;

TTF_CHECK_POINTER(font, -1);

if (Find_GlyphMetrics(font, ch, &glyph) < 0) {
    return -1;
}

if (minx) {
    *minx = glyph->sz_left;
}
if (maxx) {
    *maxx = glyph->sz_left + glyph->sz_width;
}
if (miny) {
    *miny = glyph->sz_top - glyph->sz_rows;
}
if (maxy) {
    *maxy = glyph->sz_top;
}
if (advance) {
    *advance = FT_CEIL(glyph->advance);
}

printf( "Values =  %d %d %d %d %d \n\n", glyph->sz_left, glyph->sz_left + glyph->sz_width, glyph->sz_top - glyph->sz_rows, glyph->sz_top, glyph->advance );

return 0;

}

returns
TTF_GlyphMetrics
61459
Values = 0 0 0 0 448

For FontAwesome (F013)

Thanks,
David

Hi,
I’ve just tried with FontAwesome, this char, and it worked.

Maybe precise exactly the font version (there are several fonts), the size you use. Even provide a test-case, if you use Hinting, Styles, etc.

Check SDL_GetError() if anything is there

Sylvain

Hi Sylvain,

Thanks for your reply, but I’m still having trouble.

I’m using the latest SDL_ttf from mercurial (updated today) and FontAwesome 5.7.2 (FontAwesome5Free-Solid) on Debian 9 (64-bit)

Here’s my test program.

#include
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>

int main(int, char**)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
}
if (TTF_Init() != 0)
{
std::cout << "TTF_Init Error: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}

TTF_Font *font = TTF_OpenFont( "FA.ttf", 36 );
if (font == nullptr)
{
	std::cout << "TTF_OpenFont Error: " << SDL_GetError() << std::endl;
	return 1;
}		

int minx, maxx, miny, maxy, adv;

TTF_GlyphMetrics( font, 61459, &minx, &maxx, &miny, &maxy, &adv );

std::cout << minx << std::endl;
std::cout << maxx << std::endl;
std::cout << miny << std::endl;
std::cout << maxy << std::endl;
std::cout << adv << std::endl;

SDL_Quit();
return 0;

}

Output SDL_ttf 2.0.15 (latest mercurial)
0
0
0
0
36

Output with SDL_ttf 2.0.14
1
35
-5
32
36

1 Like

Just tried with, fontawesome-free-5.7.2-web/webfonts/fa-solid-900.ttf
and it gives:
0
35
-5
32
36
Do you have the FreeType 2.9.1 installed ?

For other letters, it indeed gives 0/0/0/0 metrics, but it seems to be the same with previous SDL_ttf

Thanks so much Sylvain, I had an older version of FreeType. Problem sorted.

Thanks again.

I think you’re right anyway and we still should try to be compatible with older freetype version. At least the current one used on distribution. I’ll do a fix for this.

I’ve updated mercurial so that it should work without updating to freetype 2.9.1, please give a try,
Thanks for reporting this issue!

Excellent. Thanks once again.

Tested successfully against FreeType 2.6.3