Commit bfa9e5bb authored by Rafaël Carré's avatar Rafaël Carré

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

parent 55f476f5
......@@ -111,6 +111,8 @@ Interfaces:
interface for media players that intends to become an xdg standard when
finished: http://wiki.xmms2.xmms.se/index.php/Media_Player_Interfaces .
* Motion module use disk accelerometers to keep video horizontal
* Ncurses interface now uses ncursesw to correctly display wide characters
when using an UTF-8 locale.
Linux Port:
* VLC now complies with the XDG Base Directory Specification version 0.6
......
......@@ -5313,7 +5313,7 @@ AC_ARG_ENABLE(ncurses,
[ --enable-ncurses ncurses interface support (default disabled)],
[if test "${enable_ncurses}" = "yes"; then
VLC_ADD_PLUGINS([ncurses])
VLC_ADD_LDFLAGS([ncurses],[-lncurses])
VLC_ADD_LDFLAGS([ncurses],[-lncursesw])
fi])
dnl
......
......@@ -32,7 +32,7 @@
#include <errno.h> /* ENOMEM */
#include <time.h>
#include <curses.h>
#include <ncursesw/curses.h>
#include <vlc_interface.h>
#include <vlc_vout.h>
......@@ -1125,46 +1125,59 @@ static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
va_list vl_args;
char *p_buf = NULL;
int i_len;
size_t i_char_len; /* UCS character length */
size_t i_width; /* Display width */
wchar_t *psz_wide; /* wchar_t representation of p_buf */
va_start( vl_args, p_fmt );
vasprintf( &p_buf, p_fmt, vl_args );
va_end( vl_args );
if( p_buf == NULL )
{
if( ( p_buf == NULL ) || ( w <= 0 ) )
return;
}
if( w > 0 )
i_len = strlen( p_buf );
psz_wide = (wchar_t *) malloc( sizeof( wchar_t ) * ( i_len + 1 ) );
i_char_len = mbstowcs( psz_wide, p_buf, i_len );
if( i_char_len == -1 ) /* an invalid character was encountered */
i_width = i_len;
else
{
if( ( i_len = strlen( p_buf ) ) > w )
{
char *psz_local;
int i_cut = i_len - w;
int x1 = i_len/2 - i_cut/2;
int x2 = x1 + i_cut;
i_width = wcswidth( psz_wide, i_char_len );
if( i_width == -1 ) /* a non printable character was encountered */
i_width = i_len;
}
if( i_len > x2 )
{
memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
}
p_buf[w] = '\0';
if( w > 7 )
{
p_buf[w/2-1] = '.';
p_buf[w/2 ] = '.';
p_buf[w/2+1] = '.';
}
psz_local = ToLocale( p_buf );
mvprintw( y, x, "%s", psz_local );
LocaleFree( p_buf );
if( i_width > w )
{ /* FIXME: ellipsize psz_wide while keeping the width in mind */
char *psz_local;
int i_cut = i_len - w;
int x1 = i_len/2 - i_cut/2;
int x2 = x1 + i_cut;
if( i_len > x2 )
{
memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
}
else
p_buf[w] = '\0';
if( w > 7 )
{
char *psz_local = ToLocale( p_buf );
mvprintw( y, x, "%s", psz_local );
LocaleFree( p_buf );
mvhline( y, x + i_len, ' ', w - i_len );
p_buf[w/2-1] = '.';
p_buf[w/2 ] = '.';
p_buf[w/2+1] = '.';
}
psz_local = ToLocale( p_buf );
mvprintw( y, x, "%s", psz_local );
LocaleFree( p_buf );
}
else
{
char *psz_local = ToLocale( p_buf );
mvprintw( y, x, "%s", psz_local );
LocaleFree( p_buf );
mvhline( y, x + i_width, ' ', w - i_width );
}
}
static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment