Proposal to SDL_ttf

Applications in which the user selects font files and specifies text to
render, a method to check for the presence of a certain character in the
font file is very useful. The application should be able to prevent
itself from drawing these ugly boxes…
As far as i can see, there’s no way to do that with the current SDL_ttf
library. I was wondering, if nobody else ran into these problems, too.
freetype has this functionality: FT_Get_Char_Index does it by returning
zero to indicate, that there is no character in the font file
representing the given character code.

The implementation is tiny:
int TTF_GlyphProvided(TTF_Font *font, Uint16 ch)
{
return FT_Get_Char_Index(font->face, ch);
}

Comments please. Thanks!

Matthias Weigand <weigole gmx.de> writes:

The implementation is tiny:
int TTF_GlyphProvided(TTF_Font *font, Uint16 ch)
{
return FT_Get_Char_Index(font->face, ch);
}

Comments please. Thanks!

Matthias, that’s a great idea. I ended up writing my own font file for my game -
after trying to use a downloaded font and then getting those stupid boxes
everywhere because it didn’t implement anything other than the letters and
numbers and a few punctuation marks.

Could we perhaps have a second function, where you provide a string instead of a
single character? That way you could check your whole character set in one call.
Here’s the code I envisage:

int TTF_GlyphsProvided(TTF_Font *font, Uint16 *str)
{
int i=0;
for( ; str[i] != ‘\0’ ; ++i)
{
int retval = TTF_GlyphProvided(font, str[i]);
if(retval != 0) // I’m assuming non-zero for failure!
{
return retval;
}
}
return 0; // Assuming zero is OK. If not, swap it for something else!
}

-J

Applications in which the user selects font files and specifies text to
render, a method to check for the presence of a certain character in the
font file is very useful.

That’s not a bad idea, though how would you recover from that?

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Applications in which the user selects font files and specifies text to
render, a method to check for the presence of a certain character in the
font file is very useful.

That’s not a bad idea, though how would you recover from that?

Use a fallback font and/or display a useful diagnostic to the user about
the font the user chose being incomplete.On Tue, 2007-07-17 at 13:15 -0700, Sam Lantinga wrote:

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Sean Middleditch <@Sean_Middleditch>

Sam Lantinga wrote:

Applications in which the user selects font files and specifies text to
render, a method to check for the presence of a certain character in the
font file is very useful.

That’s not a bad idea, though how would you recover from that?

The typed character will not be appended to the input string. The main
problem was to allow umlaut and accentuated characters. But some font
files did not provide all of these, so this was the only solution.> See ya,

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi,

to pick up the issue again and to convince you to enhance the SDL_ttf
API i attached this straighforward piece of code. Its a patch made with
the current SDL_ttf-2.0.9 code from SVN.

I’ve build and testet with freetype-2.2.1, SDL-1.2.11, and zlib-1.2.3.

I would be very happy, if it would find a way into upcoming releases of
SDL_ttf.

Thanks!
Matthias

Sean Middleditch wrote:> On Tue, 2007-07-17 at 13:15 -0700, Sam Lantinga wrote:

Applications in which the user selects font files and specifies text to
render, a method to check for the presence of a certain character in the
font file is very useful.

That’s not a bad idea, though how would you recover from that?

Use a fallback font and/or display a useful diagnostic to the user about
the font the user chose being incomplete.

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: ttfGlyphProv.diff
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070723/2e25ac67/attachment.txt

I would be very happy, if it would find a way into upcoming releases of
SDL_ttf.

You got it. It’s in subversion. :slight_smile:

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Wow, that’s great! Now i am very happy indeed. Thanks!

Sam Lantinga wrote:>> I would be very happy, if it would find a way into upcoming releases of

SDL_ttf.

You got it. It’s in subversion. :slight_smile:

Wow, that’s great! Now i am very happy indeed. Thanks!

You’re welcome!

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment