changeset 32835:19cc523b8e15

Enlarge uchar buffer, because GLib implements 31-bit UTF-8, and define length of an UTF-8 encoding sequence allowed in the font definition file as a constant.
author ib
date Thu, 17 Feb 2011 13:35:58 +0000
parents 4224bc9b72ca
children 2af511e2575e
files gui/skin/font.c gui/skin/font.h
diffstat 2 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/gui/skin/font.c	Thu Feb 17 11:15:19 2011 +0000
+++ b/gui/skin/font.c	Thu Feb 17 13:35:58 2011 +0000
@@ -103,7 +103,7 @@
         {
          if ( !Fonts[id]->nonASCIIidx[i][0] )
           {
-           strncpy( Fonts[id]->nonASCIIidx[i], command, 4 );
+           strncpy( Fonts[id]->nonASCIIidx[i], command, UTF8LENGTH );
            break;
           }
         }
@@ -151,7 +151,7 @@
 // then move pointer to next/previous character
 int fntGetCharIndex( int id, unsigned char **str, gboolean utf8, int direction )
 {
- unsigned char *p, uchar[4] = {'\0'};
+ unsigned char *p, uchar[6] = "";   // glib implements 31-bit UTF-8
  int i, c = -1;
 
  if ( **str & 0x80 )
@@ -172,7 +172,7 @@
 
    for ( i = 0; ( i < EXTRA_CHRS ) && Fonts[id]->nonASCIIidx[i][0]; i++ )
     {
-     if ( strncmp( Fonts[id]->nonASCIIidx[i], uchar, 4 ) == 0 ) return i + ASCII_CHRS;
+     if ( strncmp( Fonts[id]->nonASCIIidx[i], uchar, UTF8LENGTH ) == 0 ) return i + ASCII_CHRS;
      if ( !utf8 && ( Fonts[id]->nonASCIIidx[i][0] == (*uchar >> 6 | 0xc0) && Fonts[id]->nonASCIIidx[i][1] == (*uchar & 0x3f | 0x80) && Fonts[id]->nonASCIIidx[i][2] == 0 ) ) c = i + ASCII_CHRS;
     }
   }
--- a/gui/skin/font.h	Thu Feb 17 11:15:19 2011 +0000
+++ b/gui/skin/font.h	Thu Feb 17 13:35:58 2011 +0000
@@ -25,6 +25,7 @@
 
 #define ASCII_CHRS 128   // number of ASCII characters
 #define EXTRA_CHRS 128   // (arbitrary) number of non-ASCII characters
+#define UTF8LENGTH 4     // length of an UTF-8 encoding according to RFC 3629
 
 #define MAX_FONT_NAME 128
 #define MAX_FONTS 25
@@ -42,7 +43,7 @@
 typedef struct
 {
  fntChar         Fnt[ASCII_CHRS + EXTRA_CHRS];
- unsigned char   nonASCIIidx[EXTRA_CHRS][4];
+ unsigned char   nonASCIIidx[EXTRA_CHRS][UTF8LENGTH];
  txSample        Bitmap;
  char            name[MAX_FONT_NAME];
 } bmpFont;