Changeset bfa9e5bbeb20aa3e734c9a5629f139a973154a9b

Show
Ignore:
Timestamp:
09/13/07 19:53:40 (10 months ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1189706020 +0000
git-parent:

[55f476f55ba4e1aa123fc73be33340e18fde8c72]

git-author:
Rafaël Carré <funman@videolan.org> 1189706020 +0000
Message:

ncurses: Use ncursesw to correctly display wide characters on UTF-8 locale

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • NEWS

    r16f32e1 rbfa9e5b  
    112112     finished: http://wiki.xmms2.xmms.se/index.php/Media_Player_Interfaces . 
    113113   * Motion module use disk accelerometers to keep video horizontal 
     114   * Ncurses interface now uses ncursesw to correctly display wide characters 
     115     when using an UTF-8 locale. 
    114116 
    115117Linux Port: 
  • configure.ac

    r55f476f rbfa9e5b  
    53145314  [if test "${enable_ncurses}" = "yes"; then 
    53155315     VLC_ADD_PLUGINS([ncurses]) 
    5316      VLC_ADD_LDFLAGS([ncurses],[-lncurses]) 
     5316     VLC_ADD_LDFLAGS([ncurses],[-lncursesw]) 
    53175317   fi]) 
    53185318 
  • modules/gui/ncurses.c

    r7f37f93 rbfa9e5b  
    3333#include <time.h> 
    3434 
    35 #include <curses.h> 
     35#include <ncursesw/curses.h> 
    3636 
    3737#include <vlc_interface.h> 
     
    11261126    char    *p_buf = NULL; 
    11271127    int      i_len; 
     1128    size_t   i_char_len;    /* UCS character length */ 
     1129    size_t   i_width;       /* Display width */ 
     1130    wchar_t *psz_wide;      /* wchar_t representation of p_buf */ 
    11281131 
    11291132    va_start( vl_args, p_fmt ); 
     
    11311134    va_end( vl_args ); 
    11321135 
    1133     if( p_buf == NULL ) 
    1134     { 
     1136    if( ( p_buf == NULL ) || ( w <= 0 ) ) 
    11351137        return; 
    1136     } 
    1137     if(  w > 0 ) 
    1138     { 
    1139         if( ( i_len = strlen( p_buf ) ) > w ) 
    1140         { 
    1141             char *psz_local; 
    1142             int i_cut = i_len - w; 
    1143             int x1 = i_len/2 - i_cut/2; 
    1144             int x2 = x1 + i_cut; 
    1145  
    1146             if( i_len > x2 ) 
    1147             { 
    1148                 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 ); 
    1149             } 
    1150             p_buf[w] = '\0'; 
    1151             if( w > 7 ) 
    1152             { 
    1153                 p_buf[w/2-1] = '.'; 
    1154                 p_buf[w/2  ] = '.'; 
    1155                 p_buf[w/2+1] = '.'; 
    1156             } 
    1157             psz_local = ToLocale( p_buf ); 
    1158             mvprintw( y, x, "%s", psz_local ); 
    1159             LocaleFree( p_buf ); 
    1160         } 
    1161         else 
    1162         { 
    1163             char *psz_local = ToLocale( p_buf ); 
    1164             mvprintw( y, x, "%s", psz_local ); 
    1165             LocaleFree( p_buf ); 
    1166             mvhline( y, x + i_len, ' ', w - i_len ); 
    1167         } 
     1138 
     1139    i_len = strlen( p_buf ); 
     1140    psz_wide = (wchar_t *) malloc( sizeof( wchar_t ) * ( i_len + 1 ) ); 
     1141 
     1142    i_char_len = mbstowcs( psz_wide, p_buf, i_len ); 
     1143 
     1144    if( i_char_len == -1 ) /* an invalid character was encountered */ 
     1145        i_width = i_len; 
     1146    else 
     1147    { 
     1148        i_width = wcswidth( psz_wide, i_char_len ); 
     1149        if( i_width == -1 ) /* a non printable character was encountered */ 
     1150            i_width = i_len; 
     1151    } 
     1152 
     1153    if( i_width > w ) 
     1154    { /* FIXME: ellipsize psz_wide while keeping the width in mind */ 
     1155        char *psz_local; 
     1156        int i_cut = i_len - w; 
     1157        int x1 = i_len/2 - i_cut/2; 
     1158        int x2 = x1 + i_cut; 
     1159 
     1160        if( i_len > x2 ) 
     1161        { 
     1162            memmove( &p_buf[x1], &p_buf[x2], i_len - x2 ); 
     1163        } 
     1164        p_buf[w] = '\0'; 
     1165        if( w > 7 ) 
     1166        { 
     1167            p_buf[w/2-1] = '.'; 
     1168            p_buf[w/2  ] = '.'; 
     1169            p_buf[w/2+1] = '.'; 
     1170        } 
     1171        psz_local = ToLocale( p_buf ); 
     1172        mvprintw( y, x, "%s", psz_local ); 
     1173        LocaleFree( p_buf ); 
     1174    } 
     1175    else 
     1176    { 
     1177        char *psz_local = ToLocale( p_buf ); 
     1178        mvprintw( y, x, "%s", psz_local ); 
     1179        LocaleFree( p_buf ); 
     1180        mvhline( y, x + i_width, ' ', w - i_width ); 
    11681181    } 
    11691182}