[Tux4kids-commits] r928 - in tuxmath/trunk: doc src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Thu Mar 5 20:16:56 UTC 2009
Author: dbruce-guest
Date: 2009-03-05 20:16:56 +0000 (Thu, 05 Mar 2009)
New Revision: 928
Modified:
tuxmath/trunk/doc/changelog
tuxmath/trunk/src/SDL_extras.c
tuxmath/trunk/src/globals.h
tuxmath/trunk/src/options.c
tuxmath/trunk/src/options.h
Log:
use correct font when locale changes
Modified: tuxmath/trunk/doc/changelog
===================================================================
--- tuxmath/trunk/doc/changelog 2009-03-05 20:16:07 UTC (rev 927)
+++ tuxmath/trunk/doc/changelog 2009-03-05 20:16:56 UTC (rev 928)
@@ -1,3 +1,10 @@
+2009.Mar.03 (svn.debian.org/tux4kids - revision 922)
+ Text drawing - implemented Set_SDL_Pango_Font_Size() in SDL_extras.c so
+ that BlackOutline() e.g. now use the font size argument, albeit still with
+ a slight hack.
+
+ David Bruce <davidstuartbruce at gmail.com>
+
2009.Mar.03 (svn.debian.org/tux4kids - revision 919)
i18n - marking of some additional strings in campaign.c and credits.c for
translation.
Modified: tuxmath/trunk/src/SDL_extras.c
===================================================================
--- tuxmath/trunk/src/SDL_extras.c 2009-03-05 20:16:07 UTC (rev 927)
+++ tuxmath/trunk/src/SDL_extras.c 2009-03-05 20:16:56 UTC (rev 928)
@@ -15,6 +15,7 @@
#include "tuxmath.h"
#include "loaders.h"
#include "pixels.h"
+#include "options.h"
@@ -591,11 +592,13 @@
#define MAX_FONT_SIZE 40
+//Uncomment to test program with SDL_ttf:
+//#undef HAVE_LIBSDL_PANGO
+
/*-- 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 int current_pango_font_size = 0;
static SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color* cl);
static int Set_SDL_Pango_Font_Size(int size);
@@ -896,13 +899,18 @@
/* Local functions when using SDL_Pango: */
-/* FIXME the '0.7' a few lines down is to compensate for the larger font size */
-/* that SDL_Pango generates relative to a TTF_Font of the same numerical size - */
-/* this was picked by trial and error, ought to understand this better - DSB */
+/* NOTE the scaling by 3/4 a few lines down represents a conversion from */
+/* the usual text dpi of 72 to the typical screen dpi of 96. It gives */
+/* font sizes fairly similar to a SDL_ttf font with the same numerical value. */
static int Set_SDL_Pango_Font_Size(int size)
{
- /* Do nothing unless we need to change size: */
- if (size == current_pango_font_size)
+ /* static so we can "remember" values from previous time through: */
+ static int prev_pango_font_size;
+ static char prev_font_name[FONT_NAME_LENGTH];
+ /* Do nothing unless we need to change size or font: */
+ if ((size == prev_pango_font_size)
+ &&
+ (0 == strncmp(prev_font_name, Opts_FontName(), sizeof(prev_font_name))))
return 1;
else
{
@@ -913,7 +921,7 @@
if(context != NULL)
SDLPango_FreeContext(context);
context = NULL;
- snprintf(buf, sizeof(buf), "%s %d", DEFAULT_FONT_NAME, (int)(size * 0.7));
+ snprintf(buf, sizeof(buf), "%s %d", Opts_FontName(), (int)((size * 3)/4));
context = SDLPango_CreateContext_GivenFontDesc(buf);
}
@@ -921,7 +929,8 @@
return 0;
else
{
- current_pango_font_size = size;
+ prev_pango_font_size = size;
+ strncpy(prev_font_name, Opts_FontName(), sizeof(prev_font_name));
return 1;
}
}
Modified: tuxmath/trunk/src/globals.h
===================================================================
--- tuxmath/trunk/src/globals.h 2009-03-05 20:16:07 UTC (rev 927)
+++ tuxmath/trunk/src/globals.h 2009-03-05 20:16:56 UTC (rev 928)
@@ -91,6 +91,7 @@
#define MAX_MAX_COMETS 100
#define DEFAULT_FONT_NAME "AndikaDesRevG.ttf"
+#define FONT_NAME_LENGTH 64
#define DEFAULT_MENU_FONT_SIZE 18
#define DEFAULT_HELP_FONT_SIZE 32
Modified: tuxmath/trunk/src/options.c
===================================================================
--- tuxmath/trunk/src/options.c 2009-03-05 20:16:07 UTC (rev 927)
+++ tuxmath/trunk/src/options.c 2009-03-05 20:16:56 UTC (rev 928)
@@ -96,6 +96,7 @@
global_options->iopts[FULLSCREEN] = DEFAULT_FULLSCREEN;
global_options->iopts[USE_KEYPAD] = DEFAULT_USE_KEYPAD;
global_options->iopts[USE_IGLOOS] = DEFAULT_USE_IGLOOS;
+ strncpy(game_options->current_font_name, DEFAULT_FONT_NAME, sizeof(game_options->current_font_name));
game_options->use_bkgd = DEFAULT_USE_BKGD;
game_options->help_mode = DEFAULT_HELP_MODE;
game_options->demo_mode = DEFAULT_DEMO_MODE;
@@ -153,6 +154,7 @@
tmdprintf("'%s' isn't a global option\n", text);
return -1;
}
+
int Opts_GetGlobalOp(const char* text)
{
int index = Opts_MapTextToIndex(text);
@@ -160,6 +162,7 @@
return Opts_GetGlobalOpt(index);
return 0;
}
+
int Opts_GetGlobalOpt(unsigned int index)
{
if (index < NUM_GLOBAL_OPTS)
@@ -218,6 +221,11 @@
// global_options->iopts[FULLSCREEN] = int_to_bool(val);
//}
+void Opts_SetFontName(char* font_name)
+{
+ if (font_name && font_name[0] != '\0')
+ strncpy(game_options->current_font_name, font_name, sizeof(game_options->current_font_name));
+}
void Opts_SetUseBkgd(int val)
{
@@ -580,6 +588,15 @@
// return global_options->iopts[FULLSCREEN];
//}
+const char* Opts_FontName(void)
+{
+ if (!game_options)
+ {
+ fprintf(stderr, "\nOpts_FontName(): game_options not valid!\n");
+ return NULL;
+ }
+ return (const char*) game_options->current_font_name;
+}
int Opts_UseBkgd(void)
{
Modified: tuxmath/trunk/src/options.h
===================================================================
--- tuxmath/trunk/src/options.h 2009-03-05 20:16:07 UTC (rev 927)
+++ tuxmath/trunk/src/options.h 2009-03-05 20:16:56 UTC (rev 928)
@@ -48,6 +48,7 @@
/* gameplay but not having to do with math questions per se */
typedef struct game_option_type {
/* general game options */
+ char current_font_name[FONT_NAME_LENGTH];
int use_bkgd;
int help_mode;
int demo_mode;
@@ -119,6 +120,7 @@
int Opts_GetGlobalOpt(unsigned int index);
void Opts_SetGlobalOpt(unsigned int index, int val);
+void Opts_SetFontName(char* font_name);
void Opts_SetUseBkgd(int val);
void Opts_SetHelpMode(int val);
void Opts_SetDemoMode(int val);
@@ -151,6 +153,7 @@
void Opts_SetKeepScore(int val);
/* "Get" functions for tuxmath options struct: */
+const char* Opts_FontName(void);
int Opts_UseBkgd(void);
int Opts_HelpMode(void);
int Opts_DemoMode(void);
More information about the Tux4kids-commits
mailing list