[Tux4kids-commits] r918 - in tuxmath/trunk: doc src

dbruce-guest at alioth.debian.org dbruce-guest at alioth.debian.org
Tue Mar 3 12:51:14 UTC 2009


Author: dbruce-guest
Date: 2009-03-03 12:51:14 +0000 (Tue, 03 Mar 2009)
New Revision: 918

Modified:
   tuxmath/trunk/doc/changelog
   tuxmath/trunk/src/SDL_extras.c
   tuxmath/trunk/src/SDL_extras.h
   tuxmath/trunk/src/credits.c
   tuxmath/trunk/src/fileops.h
   tuxmath/trunk/src/fileops_media.c
   tuxmath/trunk/src/highscore.c
   tuxmath/trunk/src/loaders.c
   tuxmath/trunk/src/loaders.h
   tuxmath/trunk/src/setup.c
   tuxmath/trunk/src/titlescreen.h
   tuxmath/trunk/src/tuxmath.h
Log:
completion of move of all SDL_Pango/SD_ttf -specific code to within SDL_extras.



Modified: tuxmath/trunk/doc/changelog
===================================================================
--- tuxmath/trunk/doc/changelog	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/doc/changelog	2009-03-03 12:51:14 UTC (rev 918)
@@ -1,3 +1,10 @@
+2009.Mar.03 (svn.debian.org/tux4kids - revision 918)
+        Text drawing - all of text drawing now encapsulated within SDL_extras.
+        Other code no longer has any SDL_ttf-specific data or includes. Tuxmath no
+        longer depends on any specific fonts as long as SDL_Pango is available.
+
+	David Bruce <davidstuartbruce at gmail.com>
+
 2009.Feb.28 
         Text drawing - as all of this is handled by functions within SDL_extras,
         there isn't any need for code elsewhere in the program to have to know 

Modified: tuxmath/trunk/src/SDL_extras.c
===================================================================
--- tuxmath/trunk/src/SDL_extras.c	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/SDL_extras.c	2009-03-03 12:51:14 UTC (rev 918)
@@ -589,21 +589,32 @@
 /* which library is used to do the actual rendering.                    */
 /************************************************************************/
 
+#define MAX_FONT_SIZE 40
 
+/*-- file-scope variables and local file prototypes for SDL_Pango-based code: */
 #ifdef HAVE_LIBSDL_PANGO
 #include "SDL_Pango.h"
 SDLPango_Context* context = NULL;
 static SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color* cl);
+
+
+/*-- file-scope variables and local file prototypes for SDL_ttf-based code: */
 #else
 #include "SDL_ttf.h"
-TTF_Font* menu_font = NULL;
-TTF_Font* help_font = NULL;
-TTF_Font* HS_title_font = NULL;
-TTF_Font* HS_player_font = NULL;
+/* We cache fonts here once loaded to improve performance: */
+TTF_Font* font_list[MAX_FONT_SIZE] = {NULL};
+static void free_font_list(void);
+static TTF_Font* get_font(int size);
+static TTF_Font* load_font(const char* font_name, int font_size);
 #endif
 
+
+/* "Public" functions called from other files that use either */
+/*SDL_Pango or SDL_ttf:                                       */
+
+
 /* For setup, we either initialize SDL_Pango and set its context, */
-/* or we initialize SDL_ttf and load required fonts:              */
+/* or we initialize SDL_ttf:                                      */
 int Setup_SDL_Text(void)
 {
 #ifdef HAVE_LIBSDL_PANGO
@@ -628,78 +639,22 @@
     fprintf(stderr, "\nError: I could not initialize SDL_ttf\n");
     return 0;
   }
-
-
+  return 1;
 #endif
 }
 
 
-
+void Cleanup_SDL_Text(void)
+{
 #ifdef HAVE_LIBSDL_PANGO
-/* NOTE these functions are wrapped within SDL_extras.c/h because there */
-/* appears to be a bug in SDL_Pango that causes symbol collision errors */
-/* on some compilers if more than one file has #include "SDL_Pango.h"   */
-
-void init_SDLPango_Context()
-{
-   char buf[64];
-   snprintf(buf, 64, "[%s][][%d]", DEFAULT_FONT_NAME, DEFAULT_MENU_FONT_SIZE);
-   context =  SDLPango_CreateContext_GivenFontDesc(buf);
-}
-
-void free_SDLPango_Context()
-{
   if(context != NULL)
     SDLPango_FreeContext(context);
   context = NULL;
+#else
+  free_font_list();
+  TTF_Quit();
+#endif
 }
-
-
-void SetupSDL_Pango()
-{
-  if (SDLPango_Init () < 0)
-  {
-      fprintf(stderr,
-            "\nWarning: I could not initialize SDL_Pango !\n"
-            "%s\n\n", SDL_GetError());
-  }
-  else 
-  {
-    init_SDLPango_Context();
-  }
-}
-
-
-SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color *cl)
-{
-  int k = 0;
-  SDLPango_Matrix* colour = NULL;
-
-  if (!cl)
-  {
-    fprintf(stderr, "Invalid SDL_Color* arg\n");
-    return NULL;
-  }
-
-  colour = (SDLPango_Matrix*)malloc(sizeof(SDLPango_Matrix));
-
-  for(k = 0; k < 4; k++)
-  {
-    (*colour).m[0][k] = (*cl).r;
-    (*colour).m[1][k] = (*cl).g;
-    (*colour).m[2][k] = (*cl).b;
-  }
-  (*colour).m[3][0] = 0;
-  (*colour).m[3][1] = 255;
-  (*colour).m[3][2] = 0;
-  (*colour).m[3][3] = 0;
-
-  return colour;
-}
-
-#endif
-
-
 /* BlackOutline() creates a surface containing text of the designated */
 /* foreground color, surrounded by a black shadow, on a transparent    */
 /* background.  The appearance can be tuned by adjusting the number of */
@@ -715,17 +670,18 @@
   SDL_Rect dstrect;
   Uint32 color_key;
 
-#ifndef HAVE_LIBSDL_PANGO
-  TTF_Font* font = LoadFont(DEFAULT_FONT_NAME, size);
-  if (!font)
+/* Make sure everything is sane before we proceed: */
+#ifdef HAVE_LIBSDL_PANGO
+  if (!context)
   {
-    fprintf(stderr, "BlackOutline(): could not load needed font - returning.");
+    fprintf(stderr, "BlackOutline(): invalid SDL_Pango context - returning.");
     return NULL;
   }
 #else
-  if (!context)
+  TTF_Font* font = get_font(DEFAULT_FONT_NAME, size);
+  if (!font)
   {
-    fprintf(stderr, "BlackOutline(): invalid SDL_Pango context - returning.");
+    fprintf(stderr, "BlackOutline(): could not load needed font - returning.");
     return NULL;
   }
 #endif
@@ -747,12 +703,12 @@
   fprintf( stderr, "BlackOutline of \"%s\"\n", t );
 #endif
 
-#ifndef HAVE_LIBSDL_PANGO
-  black_letters = TTF_RenderUTF8_Blended(font, t, black);
-#else
+#ifdef HAVE_LIBSDL_PANGO
   SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_BLACK_LETTER);
   SDLPango_SetText(context, t, -1);
   black_letters = SDLPango_CreateSurfaceDraw(context);
+#else
+  black_letters = TTF_RenderUTF8_Blended(font, t, black);
 #endif
 
   if (!black_letters)
@@ -783,10 +739,7 @@
   SDL_FreeSurface(black_letters);
 
   /* --- Put the color version of the text on top! --- */
-#ifndef HAVE_LIBSDL_PANGO
-  white_letters = TTF_RenderUTF8_Blended(font, t, *c);
-  TTF_CloseFont(font);
-#else
+#ifdef HAVE_LIBSDL_PANGO
   /* convert color arg: */
   SDLPango_Matrix* color_matrix = SDL_Colour_to_SDLPango_Matrix(c);
 
@@ -799,6 +752,9 @@
     SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_WHITE_LETTER);
 
   white_letters = SDLPango_CreateSurfaceDraw(context);
+
+#else
+  white_letters = TTF_RenderUTF8_Blended(font, t, *c);
 #endif
 
   if (!white_letters)
@@ -826,79 +782,212 @@
 
 
 /* This (fast) function just returns a non-outlined surf */
-/* using SDL_Pango if available, SDL_ttf as fallback     */
-SDL_Surface* SimpleText(const char *t, TTF_Font* font, SDL_Color* col)
+/* using either SDL_Pango or SDL_ttf                     */
+SDL_Surface* SimpleText(const char *t, int size, SDL_Color* col)
 {
   SDL_Surface* surf = NULL;
-  int using_pango = 0;
 
-#ifdef HAVE_LIBSDL_PANGO
-  using_pango = (context != NULL);
-#endif
+  if (!t||!col)
+    return NULL;
 
-  if (using_pango) {
 #ifdef HAVE_LIBSDL_PANGO
-  SDLPango_Matrix colormatrix = {
-    col->r,  col->r,  0,  0,
-    col->g,  col->g,  0,  0,
-    col->b,  col->b,  0,  0,
-    0,      255,      0,  0,
-  };
-  SDLPango_SetDefaultColor(context, &colormatrix );
-  SDLPango_SetText(context, t, -1);
-  surf = SDLPango_CreateSurfaceDraw(context);
-#endif
+  if (!context)
+  {
+    fprintf(stderr, "SimpleText() - context not valid!\n");
+    return NULL;
   }
-  else {
+  else
+  {
+    SDLPango_Matrix colormatrix = 
+    {
+      col->r,  col->r,  0,  0,
+      col->g,  col->g,  0,  0,
+      col->b,  col->b,  0,  0,
+      0,      255,      0,  0,
+    };
+    SDLPango_SetDefaultColor(context, &colormatrix );
+    SDLPango_SetText(context, t, -1);
+    surf = SDLPango_CreateSurfaceDraw(context);
+  }
+
+#else
+  {
+    TTF_Font* font = get_font(DEFAULT_FONT_NAME, size);
+    if (!font)
+      return NULL;
     surf = TTF_RenderUTF8_Blended(font, t, *col);
   }
+#endif
 
   return surf;
 }
 
-
 /* This (fast) function just returns a non-outlined surf */
 /* using SDL_Pango if available, SDL_ttf as fallback     */
-SDL_Surface* SimpleTextWithOffset(const char *t, TTF_Font* font, SDL_Color* col, int *glyph_offset)
+SDL_Surface* SimpleTextWithOffset(const char *t, int size, SDL_Color* col, int *glyph_offset)
 {
   SDL_Surface* surf = NULL;
-  int using_pango = 0;
 
-#ifdef HAVE_LIBSDL_PANGO
-  using_pango = (context != NULL);
-#endif
+  if (!t||!col)
+    return NULL;
 
-  if (using_pango) {
 #ifdef HAVE_LIBSDL_PANGO
-  SDLPango_Matrix colormatrix = {
-    col->r,  col->r,  0,  0,
-    col->g,  col->g,  0,  0,
-    col->b,  col->b,  0,  0,
-    0,      255,      0,  0,
-  };
-  SDLPango_SetDefaultColor(context, &colormatrix );
-  SDLPango_SetText(context, t, -1);
-  surf = SDLPango_CreateSurfaceDraw(context);
-  *glyph_offset = 0; // fixme?
-#endif
+  if (!context)
+  {
+    fprintf(stderr, "SimpleText() - context not valid!\n");
+    return NULL;
   }
-  else {
+  else
+  {
+    SDLPango_Matrix colormatrix = 
+    {
+      col->r,  col->r,  0,  0,
+      col->g,  col->g,  0,  0,
+      col->b,  col->b,  0,  0,
+      0,      255,      0,  0,
+    };
+    SDLPango_SetDefaultColor(context, &colormatrix );
+    SDLPango_SetText(context, t, -1);
+    surf = SDLPango_CreateSurfaceDraw(context);
+    *glyph_offset = 0; // fixme?
+  }
+
+#else
+  {
+    TTF_Font* font = get_font(DEFAULT_FONT_NAME, size);
+    if (!font)
+      return NULL;
     surf = TTF_RenderUTF8_Blended(font, t, *col);
-    int h;
-    int hmax = 0;
-    int len = strlen(t);
-    int i;
-    for (i = 0; i < len; i++) {
-      TTF_GlyphMetrics(font, t[i], NULL, NULL, NULL, &h, NULL);
-      if (h > hmax)
-	hmax = h;
+    {
+      int h;
+      int hmax = 0;
+      int len = strlen(t);
+      int i;
+      for (i = 0; i < len; i++)
+      {
+        TTF_GlyphMetrics(font, t[i], NULL, NULL, NULL, &h, NULL);
+        if (h > hmax)
+	  hmax = h;
+      }
+      *glyph_offset = hmax - TTF_FontAscent(font);
     }
-    *glyph_offset = hmax - TTF_FontAscent(font);
   }
+#endif
 
   return surf;
 }
 
 
 
+/*-----------------------------------------------------------*/
+/* Local functions, callable only within SDL_extras, divided */
+/* according with which text lib we are using:               */
+/*-----------------------------------------------------------*/
 
+
+
+#ifdef HAVE_LIBSDL_PANGO
+/* Local functions when using SDL_Pango:   */
+
+SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color *cl)
+{
+  int k = 0;
+  SDLPango_Matrix* colour = NULL;
+
+  if (!cl)
+  {
+    fprintf(stderr, "Invalid SDL_Color* arg\n");
+    return NULL;
+  }
+
+  colour = (SDLPango_Matrix*)malloc(sizeof(SDLPango_Matrix));
+
+  for(k = 0; k < 4; k++)
+  {
+    (*colour).m[0][k] = (*cl).r;
+    (*colour).m[1][k] = (*cl).g;
+    (*colour).m[2][k] = (*cl).b;
+  }
+  (*colour).m[3][0] = 0;
+  (*colour).m[3][1] = 255;
+  (*colour).m[3][2] = 0;
+  (*colour).m[3][3] = 0;
+
+  return colour;
+}
+
+#else
+/* Local functions when using SDL_ttf: */
+
+free_font_list(void)
+{
+  int i;
+  for(i = 0; i < MAX_FONT_SIZE; i++);
+  {
+    if(font_list[i])
+    {
+      TTF_CloseFont(font_list[i]);
+      font_list[i] = NULL;
+    }
+  }
+}
+
+
+/* Loads and caches fonts in each size as they are requested: */
+/* We use the font size as an array index, keeping each size  */
+/* font in memory once loaded until cleanup.                  */
+static TTF_Font* get_font(int size)
+{
+  if (size < 0 || size > MAX_FONT_SIZE)
+  {
+    fprintf(stderr, "Error - requested font size %d is invalid\n", size);
+    return NULL;
+  }
+
+  if(font_list[size] == NULL)
+    font_list[size] = LoadFont(DEFAULT_FONT_NAME, size);
+  return font_list[size];
+}
+
+
+/* FIXME: I think we need to provide a single default font with the program data, */
+/* then more flexible code to try to locate or load system fonts. DSB             */
+/* Returns ptr to loaded font if successful, NULL otherwise. */
+static TTF_Font* load_font(const char* font_name, int font_size)
+{
+  TTF_Font* f;
+  char fontfile[PATH_MAX];
+  sprintf(fontfile, "%s/fonts/%s", DATA_PREFIX, font_name);
+
+  f = TTF_OpenFont(fontfile, font_size);
+
+  /* HACK - better font searching needed! */
+  /* This should mean that font wasn't bundled into data path, which for  */
+  /* now means we are using Debian, so grab from Debian installation loc: */
+  if (!f)
+  { 
+    sprintf(fontfile, "/usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevG.ttf");
+    f = TTF_OpenFont(fontfile, font_size);
+  }
+
+
+  if (f)
+  {
+#ifdef TUXMATH_DEBUG
+    fprintf(stderr, "LoadFont(): %s loaded successfully\n\n", fontfile);
+#endif
+    return f;
+  }
+  else
+  {
+   fprintf(stderr, "LoadFont(): %s NOT loaded successfully.\n", fontfile);
+   return NULL;
+  }
+}
+#endif
+
+
+
+
+
+

Modified: tuxmath/trunk/src/SDL_extras.h
===================================================================
--- tuxmath/trunk/src/SDL_extras.h	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/SDL_extras.h	2009-03-03 12:51:14 UTC (rev 918)
@@ -29,12 +29,6 @@
 #endif
 
 
-#ifdef HAVE_LIBSDL_PANGO
-void init_SDLPango_Context();
-void free_SDLPango_Context();
-void SetupSDL_Pango(void);
-#endif
-
 /* Non-text graphics functions: */
 void DrawButton(SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
 void RoundCorners(SDL_Surface* s, Uint16 radius);
@@ -47,10 +41,11 @@
 SDL_Surface* zoom(SDL_Surface* src, int new_w, int new_h);
 
 /*Text rendering functions: */
-int Setup_SDL_Text();
+int Setup_SDL_Text(void);
+void Cleanup_SDL_Text(void);
 SDL_Surface* BlackOutline(const char* t, int size, SDL_Color* c);
-SDL_Surface* SimpleText(const char *t, TTF_Font* font, SDL_Color* col);
-SDL_Surface* SimpleTextWithOffset(const char *t, TTF_Font* font, SDL_Color* col, int *glyph_offset);
-int Cleanup_SDL_Text();
+SDL_Surface* SimpleText(const char *t, int size, SDL_Color* col);
+SDL_Surface* SimpleTextWithOffset(const char *t, int size, SDL_Color* col, int *glyph_offset);
 
+
 #endif

Modified: tuxmath/trunk/src/credits.c
===================================================================
--- tuxmath/trunk/src/credits.c	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/credits.c	2009-03-03 12:51:14 UTC (rev 918)
@@ -461,7 +461,7 @@
       dest.h = 1;
       draw_text(text[line], dest);  // translation should have already occurred
 
-      if (scroll * speed >= TTF_FontHeight(default_font) )
+      if (scroll * speed >= DEFAULT_MENU_FONT_SIZE)
       {
         scroll = 0;
         line++;
@@ -600,7 +600,7 @@
 
   /* This func from SDL_extras draws with SDL_Pango if avail, */
   /* with SDL_ttf as fallback:                                */
-  surf =  SimpleText(str, default_font, &col);
+  surf =  SimpleText(str, DEFAULT_MENU_FONT_SIZE, &col);
 
   dest.x -= surf->w / 2; //center text
   SDL_BlitSurface(surf, NULL, screen, &dest);

Modified: tuxmath/trunk/src/fileops.h
===================================================================
--- tuxmath/trunk/src/fileops.h	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/fileops.h	2009-03-03 12:51:14 UTC (rev 918)
@@ -262,7 +262,6 @@
 int write_postgame_summary(void);
 
 int load_image_data();
-int load_default_font();
 
 
 #ifndef NOSOUND

Modified: tuxmath/trunk/src/fileops_media.c
===================================================================
--- tuxmath/trunk/src/fileops_media.c	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/fileops_media.c	2009-03-03 12:51:14 UTC (rev 918)
@@ -4,8 +4,6 @@
 #include "options.h"
 #include "SDL_extras.h"
 
-TTF_Font  *default_font;
-TTF_Font  *help_font;
 int glyph_offset;
 
 /*****************************************************************/
@@ -184,47 +182,21 @@
 
 #ifdef REPLACE_WAVESCORE  
   /* Replace the "WAVE" and "SCORE" with translate-able versions */
-  TTF_Font *wavescore_font;
-  wavescore_font = LoadFont(DEFAULT_FONT_NAME, 28);
   SDL_FreeSurface(images[IMG_WAVE]);
-  images[IMG_WAVE] = SimpleTextWithOffset(_("WAVE"), wavescore_font, &white, &glyph_offset);
+  images[IMG_WAVE] = SimpleTextWithOffset(_("WAVE"), 28, &white, &glyph_offset);
   SDL_FreeSurface(images[IMG_SCORE]);
-  images[IMG_SCORE] = SimpleTextWithOffset(_("SCORE"), wavescore_font, &white, &glyph_offset);
+  images[IMG_SCORE] = SimpleTextWithOffset(_("SCORE"), 28, &white, &glyph_offset);
   glyph_offset++;
-  TTF_CloseFont(wavescore_font);
 #endif
 
   /* If we make it to here OK, return 1: */
   return 1;
 }
 
-/* returns 1 if default font successfully loaded, 0 otherwise. */
-int load_default_font()
-{
-  default_font = LoadFont( DEFAULT_FONT_NAME,
-                           DEFAULT_MENU_FONT_SIZE);
-  help_font = LoadFont(    DEFAULT_FONT_NAME,
-                           DEFAULT_HELP_FONT_SIZE);
 
-  if (default_font && help_font)
-  {
-#ifdef TUXMATH_DEBUG
-    fprintf(stderr, "load_default_font(): %s loaded successfully\n\n",
-            DEFAULT_FONT_NAME);
-#endif
-    return 1;
-  }
-  else
-  {
-    fprintf(stderr, "LoadFont(): %s NOT loaded successfully. TTF: %s\n",
-            DEFAULT_FONT_NAME, TTF_GetError() );
-    return 0;
-  }
-}
 
 
 
-
 #ifndef NOSOUND
 int load_sound_data(void)
 {

Modified: tuxmath/trunk/src/highscore.c
===================================================================
--- tuxmath/trunk/src/highscore.c	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/highscore.c	2009-03-03 12:51:14 UTC (rev 918)
@@ -369,7 +369,6 @@
   Uint32 frame = 0;
   Uint32 start = 0;
   wchar_t wchar_buf[HIGH_SCORE_NAME_LENGTH + 1] = {'\0'};
-//  TTF_Font* name_font = NULL;
   const int NAME_FONT_SIZE = 32;
   const int BG_Y = 100;
   const int BG_WIDTH = 400;

Modified: tuxmath/trunk/src/loaders.c
===================================================================
--- tuxmath/trunk/src/loaders.c	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/loaders.c	2009-03-03 12:51:14 UTC (rev 918)
@@ -93,43 +93,10 @@
 
 
 
-/* FIXME: I think we need to provide a single default font with the program data, */
-/* then more flexible code to try to locate or load system fonts. DSB             */
-/* Returns ptr to loaded font if successful, NULL otherwise. */
-TTF_Font* LoadFont(const char* font_name, int font_size)
-{
-  TTF_Font* f;
-  char fontfile[PATH_MAX];
-  sprintf(fontfile, "%s/fonts/%s", DATA_PREFIX, font_name);
 
-  f = TTF_OpenFont(fontfile, font_size);
 
-  /* HACK - better font searching needed! */
-  /* This should mean that font wasn't bundled into data path, which for  */
-  /* now means we are using Debian, so grab from Debian installation loc: */
-  if (!f)
-  { 
-    sprintf(fontfile, "/usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevG.ttf");
-    f = TTF_OpenFont(fontfile, font_size);
-  }
 
 
-  if (f)
-  {
-#ifdef TUXMATH_DEBUG
-    fprintf(stderr, "LoadFont(): %s loaded successfully\n\n", fontfile);
-#endif
-    return f;
-  }
-  else
-  {
-   fprintf(stderr, "LoadFont(): %s NOT loaded successfully.\n", fontfile);
-   return NULL;
-  }
-}
-
-
-
 /* FIXME checkFile() not working right in Win32 - skipping. */
 /***********************
         LoadImage : Load an image and set transparent if requested

Modified: tuxmath/trunk/src/loaders.h
===================================================================
--- tuxmath/trunk/src/loaders.h	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/loaders.h	2009-03-03 12:51:14 UTC (rev 918)
@@ -41,7 +41,6 @@
 
 /* in loaders.c (from tuxtype): */
 int         checkFile( const char *file );
-TTF_Font*    LoadFont(const char* font_name, int font_size);
 Mix_Chunk*   LoadSound( char* datafile );
 SDL_Surface* LoadImage( char* datafile, int mode );
 SDL_Surface* LoadBkgd(char* datafile);

Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/setup.c	2009-03-03 12:51:14 UTC (rev 918)
@@ -439,24 +439,17 @@
     exit(1);
   }
 
-
-  if (TTF_Init() < 0)
+  if (!Setup_SDL_Text())
   {
-    fprintf( stderr, "Couldn't initialize SDL_ttf\n"
-           "The Simple DirectMedia error that occured was:\n"
-           "%s\n\n", SDL_GetError());
+    fprintf( stderr, "Couldn't initialize text (SDL_ttf or SDL_Pango)\n");
     cleanup_on_error();
     exit(2);
   }
 
-  atexit(TTF_Quit); // Maybe this is redundant?
+//  atexit(TTF_Quit); // Maybe this is redundant?
 
 
-#ifdef HAVE_LIBSDL_PANGO
-  SetupSDL_Pango();
-#endif
 
-
   #ifndef NOSOUND
   /* Init SDL Audio: */
   Opts_SetSoundHWAvailable(0);  // By default no sound HW
@@ -568,15 +561,9 @@
     Opts_SetSoundHWAvailable(0);
   }
 
-   if (!load_default_font())
-  {
-    fprintf(stderr, "\nCould not load default font - exiting!\n");
-    cleanup_on_error();
-    exit(1);
-  }
-   
   /* This now has to come after loading the font, because it replaces
      a couple of images with translatable versions. */
+  /* NOTE now the text code will load the font if it isn't already loaded */
   if (!load_image_data())
   {
     fprintf(stderr, "\nCould not load image file - exiting!\n");
@@ -662,12 +649,7 @@
   Uint16 format;
 
   /* Free all images and sounds used by SDL: */
-  if(default_font)
-  {
-    TTF_CloseFont(default_font);
-    default_font = NULL;
-    TTF_Quit();
-  }
+  Cleanup_SDL_Text();
 
   for (i = 0; i < NUM_IMAGES; i++)
   {
@@ -732,11 +714,7 @@
     n_timesopened--;
   }
 
-#ifdef HAVE_LIBSDL_PANGO
-   free_SDLPango_Context();
-#endif
 
-
   // Finally, quit SDL
   SDL_Quit();
 

Modified: tuxmath/trunk/src/titlescreen.h
===================================================================
--- tuxmath/trunk/src/titlescreen.h	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/titlescreen.h	2009-03-03 12:51:14 UTC (rev 918)
@@ -62,14 +62,6 @@
 } menu_options;
 
 
-
-
-#define menu_font  "AndikaDesRevA.ttf"  /*  "GenAI102.ttf" */
-#define menu_font_size       18
-
-#define ttf_font  "AndikaDesRevA.ttf"  /*   "GenAI102.ttf" */
-#define ttf_font_size        18
-
 #define MAX_LESSONS 100
 #define MAX_NUM_WORDS   500
 #define MAX_WORD_SIZE   8
@@ -94,11 +86,8 @@
 
 
 
-//extern SDL_Surface *screen;
-//extern TTF_Font  *font;
 extern SDL_Event  event;
 
-SDL_Surface* current_bkg(); //appropriate background for current video mode
 
 #define MUSIC_FADE_OUT_MS        80
 
@@ -148,6 +137,7 @@
                      menu_options* custom_mo, 
                      void (*set_custom_menu_opts)(menu_options*) );
 void set_default_menu_options(menu_options *);
+SDL_Surface* current_bkg(); //appropriate background for current video mode
 
 
 

Modified: tuxmath/trunk/src/tuxmath.h
===================================================================
--- tuxmath/trunk/src/tuxmath.h	2009-03-02 20:54:09 UTC (rev 917)
+++ tuxmath/trunk/src/tuxmath.h	2009-03-03 12:51:14 UTC (rev 918)
@@ -34,7 +34,6 @@
 #include <wchar.h>
 
 #include "SDL.h"
-#include "SDL_ttf.h"
 #include "SDL_image.h"
 
 #ifndef NOSOUND
@@ -63,8 +62,6 @@
 extern SDL_Surface* blended_igloos[];
 extern int flipped_img_lookup[];
 
-extern TTF_Font  *default_font;
-extern TTF_Font  *help_font;
 extern int glyph_offset;
 
 




More information about the Tux4kids-commits mailing list