[Tux4kids-commits] r184 - in tuxtype/trunk: . tuxtype tuxtype/data/fonts

dbruce-guest at alioth.debian.org dbruce-guest at alioth.debian.org
Tue May 29 21:53:02 UTC 2007


Author: dbruce-guest
Date: 2007-05-29 21:53:02 +0000 (Tue, 29 May 2007)
New Revision: 184

Added:
   tuxtype/trunk/tuxtype/data/fonts/DoulosSILR.ttf
Modified:
   tuxtype/trunk/ChangeLog
   tuxtype/trunk/tuxtype/alphabet.c
   tuxtype/trunk/tuxtype/funcs.h
   tuxtype/trunk/tuxtype/globals.h
   tuxtype/trunk/tuxtype/laser.c
   tuxtype/trunk/tuxtype/loaders.c
   tuxtype/trunk/tuxtype/playgame.c
   tuxtype/trunk/tuxtype/practice.c
   tuxtype/trunk/tuxtype/theme.c
Log:
Fixed vertical alignment of non-US chars


Modified: tuxtype/trunk/ChangeLog
===================================================================
--- tuxtype/trunk/ChangeLog	2007-05-24 21:29:34 UTC (rev 183)
+++ tuxtype/trunk/ChangeLog	2007-05-29 21:53:02 UTC (rev 184)
@@ -1,3 +1,15 @@
+29 May 2007
+[ David Bruce]
+       - Fixed vertical alignment problem with certain non-US characters
+         such as "Å" by checking max_y of each glyph and adjusting
+         appropriately.
+       - Added Doulos font to svn to accomodate Russian, although no code
+         yet to use this font when it is needed.
+       - Added utility function to print keymap - it appears that the
+         existing keymap code is broken, as the KEYMAP[] array winds
+         up with KEYMAP[i] == i for all values no matter what the
+         keyboard.lst file says.
+
 24 May 2007
 [ David Bruce]
        - Additional work on UTF-8/Unicode issues - program now scans

Modified: tuxtype/trunk/tuxtype/alphabet.c
===================================================================
--- tuxtype/trunk/tuxtype/alphabet.c	2007-05-24 21:29:34 UTC (rev 183)
+++ tuxtype/trunk/tuxtype/alphabet.c	2007-05-29 21:53:02 UTC (rev 184)
@@ -40,6 +40,7 @@
 /* Local function prototypes: */
 void WORDS_scan_chars(void);
 int add_unicode(wchar_t uc);
+void print_keymap(void);
 
 /* --- setup the alphabet --- */
 void set_letters(unsigned char *t) {
@@ -78,6 +79,8 @@
 		sprintf( fn , "%s/keyboard.lst", realPath[l]);
 		if (CheckFile(fn)) {
 			unsigned char str[255];
+			wchar_t wide_str[255];
+
 			FILE *f;
 			int i,j;
 
@@ -89,26 +92,29 @@
 
 			do {
 				fscanf( f, "%[^\n]\n", str);
-				if (strlen(str) > 3) {
+                                /* Convert to wcs from UTF-8, if needed; */
+                                mbstowcs(wide_str, str, strlen(str) + 1);
 
+				if (wcslen(wide_str) > 3) {
+
 					/* format is: FINGER(s)|Char(s) Upper/Lower */
 
 					/* advance past the fingers */
 
-					for (i=0; i<strlen(str) && str[i] != '|'; i++);
+					for (i=0; i<wcslen(wide_str) && wide_str[i] != '|'; i++);
 
 					i++; // pass the '|'
 					j = i; 
-					ALPHABET[(int)str[j]] = 1;  // first character is default
+					ALPHABET[(int)wide_str[j]] = 1;  // first character is default
 
-					for (i++; i<strlen(str); i++)
-						KEYMAP[(int)str[i]] = str[j];
+					for (i++; i<wcslen(wide_str); i++)
+						KEYMAP[(int)wide_str[i]] = wide_str[j];
 
 					/* set the fingers for this letter */
 
 					for (i=0; i<j-1; i++)
-						if (str[i]>='0' && str[i]<='9')
-							FINGER[str[j]][(int)(str[i]-'0')]=1;
+						if (wide_str[i]>='0' && wide_str[i]<='9')
+							FINGER[wide_str[j]][(int)(wide_str[i]-'0')]=1;
 
 					ALPHABET_SIZE++;
 				}
@@ -117,10 +123,15 @@
 
 			fclose(f);
 
+			DEBUGCODE
+			{
+			  fprintf(stderr, "printing keymap for %s\n", fn);
+        		  print_keymap();
+			}
+
 			return;
 		}
 	}
-
 	fprintf( stderr, "Error finding file for keyboard setup!\n" );
 }
 
@@ -599,7 +610,35 @@
 }
 
 
+/* Since SDL drawing just uses the upper left corner, but text needs to be drawn relative to */
+/* the glyph origin (i.e. the lower left corner for a character that doesn't go below        */
+/* the baseline), we need to convert them - basically just subtracting the max_y, which is   */
+/* the glyph's height above the baseline.  So - 'x' and 'y' before the function should be    */
+/* the coords where the *origin* is supposed to be, and after the function they will contain */
+/* the coords where the upper left of this particular glyph needs to be to put the origin    */
+/* in the right place. OK?                                                                   */
+int GetGlyphCoords(wchar_t t, int* x, int* y)
+{
+  int i;
 
+  for (i = 0;
+       char_glyphs[i].unicode_value != t && i <= num_chars_used;
+       i++)
+  {}
+
+  if (i > num_chars_used)
+  {
+    /* Didn't find character: */
+    fprintf(stderr, "Could not find glyph for unicode character %lc\n", t);
+    return 1;
+  }
+  
+  /* Set "upper left" coordinates for blitting (currently, don't need to */
+  /* do anything to x):                                                  */
+  *y -= char_glyphs[i].max_y;
+  return 1;
+}
+
 /****************************************************/
 /*                                                  */
 /*       Local ("private") functions:               */
@@ -673,3 +712,15 @@
     return -1;
   }
 }
+
+/* For debugging purposes: */
+void print_keymap(void)
+{
+  int i;
+
+  for(i = 0; i < 256; i++)
+  {
+    fprintf(stderr, "i = %d\t(int)KEYMAP[i] = %d\tKEYMAP[i] = %lc\n",
+            i, KEYMAP[i], KEYMAP[i]); 
+  }
+}

Added: tuxtype/trunk/tuxtype/data/fonts/DoulosSILR.ttf
===================================================================
(Binary files differ)


Property changes on: tuxtype/trunk/tuxtype/data/fonts/DoulosSILR.ttf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: tuxtype/trunk/tuxtype/funcs.h
===================================================================
--- tuxtype/trunk/tuxtype/funcs.h	2007-05-24 21:29:34 UTC (rev 183)
+++ tuxtype/trunk/tuxtype/funcs.h	2007-05-29 21:53:02 UTC (rev 184)
@@ -86,6 +86,7 @@
 extern SDL_Surface* black_outline_wchar(wchar_t t, TTF_Font* font, SDL_Color* c);
 extern SDL_Surface* GetWhiteGlyph(wchar_t t);
 extern SDL_Surface* GetRedGlyph(wchar_t t);
+extern int GetGlyphCoords(wchar_t t, int* x, int* y);
 extern int RenderLetters(TTF_Font* letter_font);
 extern void FreeLetters(void);
 /* WORD FUNCTIONS (also in alphabet.c) */

Modified: tuxtype/trunk/tuxtype/globals.h
===================================================================
--- tuxtype/trunk/tuxtype/globals.h	2007-05-24 21:29:34 UTC (rev 183)
+++ tuxtype/trunk/tuxtype/globals.h	2007-05-29 21:53:02 UTC (rev 184)
@@ -167,8 +167,8 @@
 extern SDL_Surface *bkg;
 extern SDL_Surface *letters[255];
 
-extern unsigned char ALPHABET[256];
-extern unsigned char KEYMAP[256];
+extern wchar_t ALPHABET[256];
+extern wchar_t KEYMAP[256];
 extern unsigned char FINGER[256][10];
 extern int ALPHABET_SIZE;
 extern wchar_t unicode_chars_used[MAX_UNICODES];

Modified: tuxtype/trunk/tuxtype/laser.c
===================================================================
--- tuxtype/trunk/tuxtype/laser.c	2007-05-24 21:29:34 UTC (rev 183)
+++ tuxtype/trunk/tuxtype/laser.c	2007-05-29 21:53:02 UTC (rev 184)
@@ -21,11 +21,11 @@
 #include "funcs.h"
 #include "laser.h"
 
-sprite * shield;
-SDL_Surface * images[NUM_IMAGES];
-Mix_Chunk * sounds[NUM_SOUNDS];
-Mix_Music * musics[NUM_MUSICS];
-SDL_Surface * bkgd;
+sprite* shield;
+SDL_Surface* images[NUM_IMAGES];
+Mix_Chunk* sounds[NUM_SOUNDS];
+Mix_Music* musics[NUM_MUSICS];
+SDL_Surface* bkgd;
 
 /* --- unload all media --- */
 void laser_unload_data(void) {
@@ -845,8 +845,10 @@
 void laser_draw_let(wchar_t c, int x, int y)
 {
 	SDL_Rect dst;
-	dst.y = y-35;
+	dst.y = y - 10;
 	dst.x = x - (GetWhiteGlyph(c)->w/2);
+        /* Correct for varying height of glyphs: */
+	GetGlyphCoords(c, &dst.x, &dst.y);
 	SDL_BlitSurface(GetWhiteGlyph(c), NULL, screen, &dst); 
 }
 

Modified: tuxtype/trunk/tuxtype/loaders.c
===================================================================
--- tuxtype/trunk/tuxtype/loaders.c	2007-05-24 21:29:34 UTC (rev 183)
+++ tuxtype/trunk/tuxtype/loaders.c	2007-05-29 21:53:02 UTC (rev 184)
@@ -20,8 +20,7 @@
 #include "globals.h"
 #include "funcs.h"
 
-/* check to see if file exists, if so return true            */
-/* Will work if "file" is a dir, also */
+/* Returns 1 if valid file, 2 if valid dir, 0 if neither: */
 int CheckFile(const char* file)
 {
   FILE* fp = NULL;
@@ -41,7 +40,7 @@
     LOG("Opened successfully as DIR\n");
 
     closedir(dp);
-    return 1;
+    return 2;
   }
 
   fp = fopen(file, "r");

Modified: tuxtype/trunk/tuxtype/playgame.c
===================================================================
--- tuxtype/trunk/tuxtype/playgame.c	2007-05-24 21:29:34 UTC (rev 183)
+++ tuxtype/trunk/tuxtype/playgame.c	2007-05-29 21:53:02 UTC (rev 184)
@@ -734,11 +734,16 @@
 /*        LOG ("Entering DrawFish()\n");*/
 	int j = 0;
 	int red_letters = 0;
-	int x_offset = 0;
-        int y_offset = 0;
+	int current_letter;
+	/* 'x_origin' and 'y_origin' are where the glyph origin should be          */
+	/* located relative to the fishy graphic (lower left corner of most chars) */
+	const int x_origin = 10;
+        const int y_origin = 30;
+	/* letter_x and letter_y are where the upper left corner of the glyph needs */
+        /* to be located - (e.g. how SDL blitting understands locations)           */
         int letter_x = 0;
         int letter_y = 0;
-	int current_letter;
+
         SDL_Surface* letter_surface;
 
 	/* Make sure needed pointers are valid - if not, return: */
@@ -748,10 +753,8 @@
           return;
 	}
 	    
-        // To have letters more centered in fish:
-	x_offset = 10;
-        y_offset = 10;
 
+
 	/* Draw the fishies: */
 	for (j = 0; j < fish_object[which].len; j++)
         {
@@ -791,21 +794,17 @@
 		{
 		  current_letter = (int)fish_object[which].word[j];
 
-		  letter_x = fish_object[which].x + (j * fishy->frame[0]->w) + x_offset;
-		  letter_y = fish_object[which].y + y_offset;
- 
-// 		  DEBUGCODE
-// 		  {
-// 		    fprintf(stderr, "wchar is: %lc\n(int)wchar is: %d\n",
-// 				     fish_object[which].word[j],
-//                                      current_letter);
-// 		  }
-		  //if (fish_object[which].word[j] != 32) /* Don't understand this */
 		  if (j < red_letters)
                     letter_surface = GetRedGlyph(current_letter);
                   else
                     letter_surface = GetWhiteGlyph(current_letter);
 
+		  /* Set "letter_x" and "letter_y to where we want the *origin* drawn: */
+		  letter_x = fish_object[which].x + (j * fishy->frame[0]->w) + x_origin;
+		  letter_y = fish_object[which].y + y_origin;
+		  /* Now get correct upper-left coords for this particular glyph: */
+		  GetGlyphCoords(current_letter, &letter_x, &letter_y);
+
 		  DrawObject(letter_surface, letter_x, letter_y);
 
 		}

Modified: tuxtype/trunk/tuxtype/practice.c
===================================================================
--- tuxtype/trunk/tuxtype/practice.c	2007-05-24 21:29:34 UTC (rev 183)
+++ tuxtype/trunk/tuxtype/practice.c	2007-05-29 21:53:02 UTC (rev 184)
@@ -30,6 +30,8 @@
 /*local function prototypes: */
 void print_at( char *pphrase, int wrap, int x, int y );
 
+
+/* FIXME use RenderLetters(), etc */
 void practice_load_media(void) {
 	int i;	
 	unsigned char fn[FNLEN];

Modified: tuxtype/trunk/tuxtype/theme.c
===================================================================
--- tuxtype/trunk/tuxtype/theme.c	2007-05-24 21:29:34 UTC (rev 183)
+++ tuxtype/trunk/tuxtype/theme.c	2007-05-29 21:53:02 UTC (rev 184)
@@ -29,8 +29,8 @@
 };
 
 SDL_Surface *letters[255] = { NULL };
-unsigned char ALPHABET[256];
-unsigned char KEYMAP[256];
+wchar_t ALPHABET[256];
+wchar_t KEYMAP[256];
 unsigned char FINGER[256][10];
 int ALPHABET_SIZE;
 unsigned char realPath[2][FNLEN];
@@ -122,7 +122,7 @@
 
 	DIR *themesDir;
 	struct dirent *themesFile;
-	struct stat fileStats;
+//	struct stat fileStats;
 
 	old_useEnglish = useEnglish;
 	strncpy( old_realPath, realPath[0], FNLEN-1 );
@@ -146,12 +146,15 @@
 		/* check to see if it is a directory */
 		sprintf( fn, "%s/themes/%s", realPath[1], themesFile->d_name);
 
-		fileStats.st_mode=0;
-		stat( fn, &fileStats );
+//		fileStats.st_mode=0;
+//		stat( fn, &fileStats );
 
-		if (S_IFDIR & fileStats.st_mode) {
+		/* CheckFile() returns 2 if dir, 1 if file, 0 if neither: */
+		if (CheckFile(fn) == 2) {
 		    /* HACK: we should get the names from file :) */
 		    strncpy( themeNames[themes], themesFile->d_name, FNLEN-1);
+		    /* Make sure theme name is capitalized: */
+                    themeNames[themes][0] = toupper(themeNames[themes][0]);
 		    strncpy( themePaths[themes++], themesFile->d_name, FNLEN-1 );
 		}
 	} while (1);
@@ -162,8 +165,8 @@
         // HACK: is font empty now???
 	font = LoadFont( ttf_font, ttf_font_size );
 
-	titles[0] = black_outline( "english", font, &white );
-	select[0] = black_outline( "english", font, &yellow);
+	titles[0] = black_outline( "English", font, &white );
+	select[0] = black_outline( "English", font, &yellow);
 	for (i = 1; i<themes; i++) {
 		titles[i] = black_outline( themeNames[i], font, &white );
 		select[i] = black_outline( themeNames[i], font, &yellow);




More information about the Tux4kids-commits mailing list