SDL_ttf changes [patches]

I’ve included two diffs, one for SDL_ttf.h and the other for SDL_ttf.c,
apply with -p0

Is there any chance of these patches going into the offical SDL_ttf
library? otherwise I’d have to ship customized libraries with my game (
which I want to avoid ).

/Magnus

Torsten Giebl wrote:
Hello!

Post a DIFF here or a link with a DIFF.

CU

“Magnus Sj?strand” <@Magnus_Sjostrand> schrieb im Newsbeitrag news:mailman.1038491487.10286.sdl at libsdl.org

Hi,

I’ve added some code to the SDL_ttf library, which adds the ability to
load a font with RWops, something I needed for a game I’m developing. Is
there anyone else that’s interested in the code ( it’s not much really
)? I’ve tried the code in windows and linux, and it works fine for me.

/Magnus


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: SDL_ttf.c.patch
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021128/bebe024a/attachment.asc
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: SDL_ttf.h.patch
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021128/bebe024a/attachment.txt

I cut away a very important line, sorry about that. This patch should work.

Magnus Sj?strand wrote:

I’ve included two diffs, one for SDL_ttf.h and the other for
SDL_ttf.c, apply with -p0

Is there any chance of these patches going into the offical SDL_ttf
library? otherwise I’d have to ship customized libraries with my game
( which I want to avoid ).

/Magnus

Torsten Giebl wrote:
Hello!

Post a DIFF here or a link with a DIFF.

CU

“Magnus Sj?strand” <@Magnus_Sjostrand> schrieb im Newsbeitrag
news:mailman.1038491487.10286.sdl at libsdl.org

Hi,

I’ve added some code to the SDL_ttf library, which adds the ability to
load a font with RWops, something I needed for a game I’m
developing. Is
there anyone else that’s interested in the code ( it’s not much really
)? I’ve tried the code in windows and linux, and it works fine for me.

/Magnus


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


— SDL_ttf.c Fri Jan 18 22:46:04 2002
+++ …/SDL_ttf.bak/SDL_ttf.c Thu Nov 28 15:08:30 2002
@@ -149,11 +149,40 @@

TTF_Font* TTF_OpenFontIndex( const char *file, int ptsize, long index )
{

  • SDL_RWops* op;
  • TTF_Font* font;
  • if ( !( op = SDL_RWFromFile ( file, “r” ) ) ){
  •  TTF_SetError ( "Could not open file", -1 );
    
  •  return NULL;
    
  • }
  • font = TTF_OpenFontIndex_RW ( op, ptsize, index );
  • SDL_FreeRW ( op );
  • return font;
    +}

+TTF_Font* TTF_OpenFont( const char *file, int ptsize )
+{

  • return TTF_OpenFontIndex(file, ptsize, 0);
    +}

+TTF_Font* TTF_OpenFont_RW ( SDL_RWops* rw, int ptsize )
+{

  • return TTF_OpenFontIndex_RW ( rw, ptsize, 0 );
    +}

+TTF_Font* TTF_OpenFontIndex_RW ( SDL_RWops* rw, int ptsize, long index )
+{
TTF_Font* font;
FT_Error error;
FT_Face face;
FT_Fixed scale;

  • int buffsize;

  • void* buffer;

  • font = (TTF_Font*) malloc(sizeof *font);
    if ( font == NULL ) {
    TTF_SetError( “Out of memory” );
    @@ -162,7 +191,19 @@
    memset( font, 0, sizeof( *font ) );

    /* Open the font and create ancillary data */

  • error = FT_New_Face( library, file, 0, &font->face );
  • /* get the total size of the needed buffer */
  • SDL_RWseek ( rw, 0, SEEK_END );
  • buffsize = SDL_RWtell ( rw );
  • SDL_RWseek ( rw, 0, SEEK_SET );
  • if ( ( buffer = malloc ( buffsize ) ) == NULL ){
  •  TTF_SetError ( "Could not allocate enough memory for font", 0 );
    
  •  return NULL;
    
  • }
  • // error = FT_New_Face( library, file, 0, &font->face );
  • error = FT_New_Memory_Face ( library, buffer, buffsize, 0, &font->face );
    if( error ) {
    TTF_SetFTError( “Couldn’t load font file”, error);
    free( font );
    @@ -171,7 +212,8 @@
    if ( index != 0 ) {
    if ( font->face->num_faces > index ) {
    FT_Done_Face( font->face );
  •  	error = FT_New_Face( library, file, index, &font->face );
    
  •  	// error = FT_New_Face( library, file, index, &font->face );
    
  •  	error = FT_New_Memory_Face ( library, buffer, buffsize, index, &font->face );
    	if( error ) {
    		TTF_SetFTError( "Couldn't get font face", error);
    		free( font );
    

@@ -229,11 +271,7 @@
font->glyph_italics *= font->height;

return font;
-}

-TTF_Font* TTF_OpenFont( const char *file, int ptsize )
-{

  • return TTF_OpenFontIndex(file, ptsize, 0);
    }

static void Flush_Glyph( c_glyph* glyph )


— SDL_ttf.h Thu Nov 28 15:27:31 2002
+++ …/SDL_ttf.bak/SDL_ttf.h Tue Nov 26 10:32:46 2002
@@ -49,6 +49,10 @@
extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, int ptsize);
extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex(const char *file, int ptsize, long index);

+/* Open a font from a RW_ops /
+extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFont_RW ( SDL_RWops
rw, int ptsize );
+extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex_RW ( SDL_RWops* rw, int ptsize, long index );
+
/* Set and retrieve the font style
This font style is implemented by modifying the font glyphs, and
doesn’t reflect any inherent properties of the truetype font file.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: SDL_ttf.c.patch
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021128/e59c1954/attachment.asc

I cut away a very important line, sorry about that. This patch should work.

Actually, SDL_RWops support for SDL_ttf is already in CVS.
I’m adding some other stuff and then releasing a new version.

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