[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Freetype] Reading fonts with FT_Stream
From: |
Leiradella, Andre V Matos Da Cunha |
Subject: |
[Freetype] Reading fonts with FT_Stream |
Date: |
Fri, 09 Nov 2001 13:51:16 -0200 |
Hi All,
I'm trying to use a generic stream implementation from SDL (www.libsdl.org)
to read fonts with freetype-2.0.4. I couldn't find anywhere in the docs how
to use FT_Stream to read fonts. I looked in the freetype source code code
and I came with the following code:
-----cut here-----
static unsigned long RWread(FT_Stream stream,unsigned long offset,unsigned
char *buffer,unsigned long count) {
SDL_RWops *rwops;
rwops=(SDL_RWops *)stream->descriptor.pointer; /* retrieve SDL
stream pointer */
SDL_RWseek(rwops,(int)offset,SEEK_SET); /* posistion the SDL stream
at desired location */
/* read count bytes from stream into buffer and returns the number
of bytes read */
return SDL_RWread(rwops,(void *)buffer,1,(int)count);
}
static void RWclose(FT_Stream stream) {
SDL_RWops *rwops;
rwops=(SDL_RWops *)stream->descriptor.pointer; /* retrieve SDL
stream pointer */
SDL_RWclose(rwops);
}
FT_Face LoadFaceRW(SDL_RWops *rwops,int ptsize) {
FT_Open_Args args;
FT_Error error;
FT_Face face;
memset((void *)&args,0,sizeof(args));
args.stream=(FT_Stream)malloc(sizeof *(args.stream));
if (args.stream==NULL)
return NULL;
args.flags=ft_open_stream;
args.stream->base=NULL;
SDL_RWseek(rwops,0,SEEK_END); /* position the SDL stream at the end
of the data */
args.stream->size=SDL_RWtell(rwops); /* get number of bytes in the
stream */
SDL_RWseek(rwops,0,SEEK_SET); /* rewind stream */
args.stream->pos=0;
args.stream->descriptor.pointer=(void *)rwops; /* save the pointer
to the SDL stream */
args.stream->pathname.pointer=NULL;
args.stream->read=RWread;
args.stream->close=RWclose;
args.num_params=0;
error=FT_Open_Face(library,&args,0,&face);
if (error)
return NULL;
return face;
}
-----cut here-----
When I ran my application I got a segfault in ftobjs.c at line 61 (function
FT_Alloc). My debugger is broken, but with some printf's I saw that after
two RWread's FT_Alloc receives a NULL for the memory parameter, which
segfaults my program at '*P=memory->alloc(memory,size);'
As I didn't even know that FT_Memory exists before this problem happens I
deduced that freetype takes care of it for me behind the scenes. So maybe
it's a bug with freetype-2.0.4? Or I'm doing something wrong when I setup
the FT_Open_Args structure?
Well, I didn't give up at that point and changed lines 61, 106 and 132 of
ftobjs.c to completly bypass freetype's memory abstraction layer:
line 61: *P=malloc(size);
line 106: Q=realloc(*P,size);
line 132: free(*P);
This caused the font to load ok, but when I call FT_Done_Face or
FT_Done_FreeType my application segfaults sometimes at 0000:00000013 and
sometimes at an address that belongs to malloc's memory pool. Looks like
freetype is, at some point during the destruction of the face, trying to
call a function whose address is stored in a invalid pointer...
And just to make things clear: when I load fonts using FT_New_Face
everything works just fine. And I'm completly sure that SDL's streams are
working just fine because I'm using them in a lot of places in my
application to load graphics, sounds, musics etc.
My development system runs Windows 98 and my development tools (!!!) are
gcc, make & gdb from MinGW-1.1.
Thanks in advance for any help.
Andre de Leiradella
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freetype] Reading fonts with FT_Stream,
Leiradella, Andre V Matos Da Cunha <=