* subsdec.c : text subtitles decoder
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
- * $Id: subsdec.c,v 1.17 2004/01/25 20:40:59 gbazin Exp $
+ * $Id$
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Samuel Hocevar <sam@zoy.org>
static void DecodeBlock ( decoder_t *, block_t ** );
static void ParseText ( decoder_t *, block_t *, vout_thread_t * );
+static void StripTags ( char * );
#define DEFAULT_NAME "System Default"
#define ENCODING_TEXT N_("Subtitles text encoding")
#define ENCODING_LONGTEXT N_("Set the encoding used in text subtitles")
#define ALIGN_TEXT N_("Subtitles justification")
-#define ALIGN_LONGTEXT N_("Set the justification of substitles")
+#define ALIGN_LONGTEXT N_("Set the justification of subtitles")
vlc_module_begin();
set_description( _("text subtitles decoder") );
*****************************************************************************/
static int OpenDecoder( vlc_object_t *p_this )
{
- decoder_t *p_dec = (decoder_t*)p_this;
+ decoder_t *p_dec = (decoder_t*)p_this;
decoder_sys_t *p_sys;
vlc_value_t val;
- if( p_dec->fmt_in.i_codec != VLC_FOURCC('s','u','b','t') &&
+ if( p_dec->fmt_in.i_codec != VLC_FOURCC('s','u','b','t') &&
p_dec->fmt_in.i_codec != VLC_FOURCC('s','s','a',' ') )
{
return VLC_EGENERIC;
p_sys->i_align = val.i_int;
#if defined(HAVE_ICONV)
- var_Create( p_dec, "subsdec-encoding",
- VLC_VAR_STRING | VLC_VAR_DOINHERIT );
- var_Get( p_dec, "subsdec-encoding", &val );
- if( !strcmp( val.psz_string, DEFAULT_NAME ) )
+ if( p_dec->fmt_in.subs.psz_encoding && *p_dec->fmt_in.subs.psz_encoding )
{
- char *psz_charset =(char*)malloc( 100 );
- vlc_current_charset( &psz_charset );
- p_sys->iconv_handle = iconv_open( "UTF-8", psz_charset );
- msg_Dbg( p_dec, "using character encoding: %s", psz_charset );
- free( psz_charset );
+ msg_Dbg( p_dec, "using character encoding: %s",
+ p_dec->fmt_in.subs.psz_encoding );
+ p_sys->iconv_handle = iconv_open( "UTF-8",
+ p_dec->fmt_in.subs.psz_encoding );
}
- else if( val.psz_string )
+ else
{
- msg_Dbg( p_dec, "using character encoding: %s", val.psz_string );
- p_sys->iconv_handle = iconv_open( "UTF-8", val.psz_string );
- }
+ var_Create( p_dec, "subsdec-encoding",
+ VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+ var_Get( p_dec, "subsdec-encoding", &val );
+ if( !strcmp( val.psz_string, DEFAULT_NAME ) )
+ {
+ char *psz_charset =(char*)malloc( 100 );
+ vlc_current_charset( &psz_charset );
+ p_sys->iconv_handle = iconv_open( "UTF-8", psz_charset );
+ msg_Dbg( p_dec, "using character encoding: %s", psz_charset );
+ free( psz_charset );
+ }
+ else if( val.psz_string )
+ {
+ msg_Dbg( p_dec, "using character encoding: %s", val.psz_string );
+ p_sys->iconv_handle = iconv_open( "UTF-8", val.psz_string );
+ }
- if( p_sys->iconv_handle == (iconv_t)-1 )
- {
- msg_Warn( p_dec, "unable to do requested conversion" );
- }
+ if( p_sys->iconv_handle == (iconv_t)-1 )
+ {
+ msg_Warn( p_dec, "unable to do requested conversion" );
+ }
- if( val.psz_string ) free( val.psz_string );
+ if( val.psz_string ) free( val.psz_string );
+ }
#else
msg_Dbg( p_dec, "no iconv support available" );
#endif
-#if 0
- if( p_demux_data )
- msg_Dbg( p_dec, p_demux_data->psz_header );
-#endif
-
return VLC_SUCCESS;
}
break;
}
}
-
- vout_ShowTextAbsolute( p_vout, psz_subtitle, NULL,
- OSD_ALIGN_BOTTOM | p_sys->i_align,
- i_align_h, i_align_v,
- p_block->i_pts, p_block->i_dts );
+ StripTags( psz_subtitle );
+ vout_ShowTextAbsolute( p_vout, SUBT1_CHAN, psz_subtitle, NULL,
+ OSD_ALIGN_BOTTOM | p_sys->i_align, i_align_h,
+ i_align_v, p_block->i_pts,
+ p_block->i_length ? p_block->i_pts + p_block->i_length : 0 );
free( psz_subtitle );
}
+
+static void StripTags( char *psz_text )
+{
+ int i_left_moves = 0;
+ vlc_bool_t b_inside_tag = VLC_FALSE;
+ int i = 0;
+ int i_tag_start = -1;
+ while( psz_text[ i ] )
+ {
+ if( !b_inside_tag )
+ {
+ if( psz_text[ i ] == '<' )
+ {
+ b_inside_tag = VLC_TRUE;
+ i_tag_start = i;
+ }
+ psz_text[ i - i_left_moves ] = psz_text[ i ];
+ }
+ else
+ {
+ if( ( psz_text[ i ] == ' ' ) ||
+ ( psz_text[ i ] == '\t' ) ||
+ ( psz_text[ i ] == '\n' ) ||
+ ( psz_text[ i ] == '\r' ) )
+ {
+ b_inside_tag = VLC_FALSE;
+ i_tag_start = -1;
+ }
+ else if( psz_text[ i ] == '>' )
+ {
+ i_left_moves += i - i_tag_start + 1;
+ i_tag_start = -1;
+ b_inside_tag = VLC_FALSE;
+ }
+ else
+ {
+ psz_text[ i - i_left_moves ] = psz_text[ i ];
+ }
+ }
+ i++;
+ }
+ psz_text[ i - i_left_moves ] = '\0';
+}
+