How to implement a ttf font file in C source code or binary executable file?

I would like to use also text in my current program,
so I downloaded the TTF library.
Unfortunality I must give a valid path for my font file, this is a problem,
because there a good chances that the users will only copy the binary executable file,
and not the specific path where is located the font file.

I tried this:
$ cat my_prog david.ttf > my_new_prog

And then I toke the example program showfont:
$ showfont -solid ./my_new_prog

It didn’t worked, he doesn’t parse the file to find a right font.

It’s not the best method, but if this worked, I could load my font by doing this:

int main(int ac, char **av)
{
[…]
TTF_OpenFont(av[0], ptsize);
}

But I think the best would be if it could be possible to load it directly from memory, and to
convert the font ttf file to a C file, and to have a new interface as like:

TTF_Font* TTF_OpenFont_raw( const unsigned char *raw_data, int ptsize );

Personnally I think programs are more portable if all files are together in one executable file,
but I don’t know what the professionals would say about that. :-)–
saf at trashmail.net
http://TrashMail.net/
Free disposable email addresses.

Hi!
I found the perl script bin2hex on the web here:
http://www.chami.com/tips/delphi/052098D.html

I used that script to convert my font file to a c header file.

Then to load that font with SDL_TTF I did it like this:
#include “myfont_header.h”

SDL_RWops* rw = SDL_RWFromMem(font_name, sizeof(font_name));
TTF_Font* font = TTF_OpenFontRw(rw, 1, myfontsize);

Ofcourse I’m skipping some steps but that was how I made it work.

The variable font_name is the name of the char array in the myfont_header.h.

Hope that this helped you.

// Alexander Bussman

Stephan Ferraro wrote:>I would like to use also text in my current program,

so I downloaded the TTF library.
Unfortunality I must give a valid path for my font file, this is a problem,
because there a good chances that the users will only copy the binary executable file,
and not the specific path where is located the font file.

I tried this:
$ cat my_prog david.ttf > my_new_prog

And then I toke the example program showfont:
$ showfont -solid ./my_new_prog

It didn’t worked, he doesn’t parse the file to find a right font.

It’s not the best method, but if this worked, I could load my font by doing this:

int main(int ac, char **av)
{
[…]
TTF_OpenFont(av[0], ptsize);
}

But I think the best would be if it could be possible to load it directly from memory, and to
convert the font ttf file to a C file, and to have a new interface as like:

TTF_Font* TTF_OpenFont_raw( const unsigned char *raw_data, int ptsize );

Personnally I think programs are more portable if all files are together in one executable file,
but I don’t know what the professionals would say about that. :slight_smile: