0
\$\begingroup\$

I'm loading a number of characters (using SDL2_ttf) into a texture atlas to improve performance.

The glyphs can be separately rendered correctly, however, how can you find the kerning distance between two characters that will sit next to each other?

As a follow up, are there any other variables that impact font rendering?

\$\endgroup\$
1
  • \$\begingroup\$ I edited my answer. New version of SDL_TTF has functionality to get kerning. \$\endgroup\$
    – akaltar
    Commented Aug 16, 2015 at 18:52

2 Answers 2

1
\$\begingroup\$

Documentation linked by akaltar has something to say about kerning support in SDL_ttf: https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#IDX24

Most important for you is last sentence:

There's currently no method to retrieve the kerning for a pair of characters from SDL_ttf, However correct kerning will be applied when a string of text is rendered instead of individual glyphs.

It seems that only method would be to use FreeType directly. As there is no way to get FT_Face from SDL_ttf context you would have to open font yourself and use FT_Get_Index and FT_Get_Kerning (http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html).

Maybe it would not be that hard to add such functionality to SDL_ttf and then push it upstream.

Problem is SDL_ttf seems to not have separate user callable shaping phase - where placing glyphs is separate process to rendering them. It's just simpler API.

\$\endgroup\$
0
\$\begingroup\$

The current implementation from mercurial has this function in the headers:

int TTF_GetFontKerningSize(TTF_Font *font, Uint16 previous_ch, Uint16 ch);

And I believe this is exactly what you are looking for.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .