- case XML_READER_TEXT:
- case XML_READER_NONE:
- break;
- case XML_READER_ENDELEM:
- psz_node = xml_ReaderName( p_xml_reader );
-
- if( psz_node )
- {
- switch (i_style_level)
- {
- case 0:
- if( !strcasecmp( "metadata", psz_node ) && (i_metadata_level == 1) )
- {
- i_metadata_level--;
- }
- break;
- case 1:
- if( !strcasecmp( "styles", psz_node ) )
- {
- i_style_level--;
- }
- break;
- case 2:
- if( !strcasecmp( "style", psz_node ) )
- {
- p_style->font_style.i_text_align = p_style->i_align;
-
- TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_style );
-
- p_style = NULL;
- i_style_level--;
- }
- break;
- }
-
- free( psz_node );
- }
- break;
- case XML_READER_STARTELEM:
- psz_node = xml_ReaderName( p_xml_reader );
-
- if( psz_node )
- {
- if( !strcasecmp( "metadata", psz_node ) && (i_style_level == 0) )
- {
- i_metadata_level++;
- }
- else if( !strcasecmp( "resolution", psz_node ) && (i_metadata_level == 1) )
- {
- while ( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
- {
- char *psz_name = xml_ReaderName ( p_xml_reader );
- char *psz_value = xml_ReaderValue ( p_xml_reader );
-
- if( psz_name && psz_value )
- {
- if( !strcasecmp( "x", psz_name ) )
- p_sys->i_original_width = atoi( psz_value );
- else if( !strcasecmp( "y", psz_name ) )
- p_sys->i_original_height = atoi( psz_value );
- }
- if( psz_name ) free( psz_name );
- if( psz_value ) free( psz_value );
- }
- }
- else if( !strcasecmp( "styles", psz_node ) && (i_style_level == 0) )
- {
- i_style_level++;
- }
- else if( !strcasecmp( "style", psz_node ) && (i_style_level == 1) )
- {
- i_style_level++;
-
- p_style = calloc( 1, sizeof(ssa_style_t) );
-
- while ( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
- {
- char *psz_name = xml_ReaderName ( p_xml_reader );
- char *psz_value = xml_ReaderValue ( p_xml_reader );
-
- if( psz_name && psz_value )
- {
- if( !strcasecmp( "name", psz_name ) )
- p_style->psz_stylename = strdup( psz_value);
- }
- if( psz_name ) free( psz_name );
- if( psz_value ) free( psz_value );
- }
- }
- else if( !strcasecmp( "fontstyle", psz_node ) && (i_style_level == 2) )
- {
- while ( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
- {
- char *psz_name = xml_ReaderName ( p_xml_reader );
- char *psz_value = xml_ReaderValue ( p_xml_reader );
-
- if( psz_name && psz_value )
- {
- if( !strcasecmp( "face", psz_name ) )
- p_style->font_style.psz_fontname = strdup( psz_value);
- else if( !strcasecmp( "size", psz_name ) )
- p_style->font_style.i_font_size = atoi( psz_value);
- else if( !strcasecmp( "italic", psz_name ) )
- {
- if( !strcasecmp( "yes", psz_value ))
- p_style->font_style.i_style_flags |= STYLE_ITALIC;
- }
- else if( !strcasecmp( "weight", psz_name ) )
- {
- if( !strcasecmp( "bold", psz_value ))
- p_style->font_style.i_style_flags |= STYLE_BOLD;
- }
- else if( !strcasecmp( "underline", psz_name ) )
- {
- if( !strcasecmp( "yes", psz_value ))
- p_style->font_style.i_style_flags |= STYLE_UNDERLINE;
- }
- else if( !strcasecmp( "color", psz_name ) )
- {
- if( *psz_value == '#' )
- {
- unsigned long col = strtol(psz_value+1, NULL, 16);
- p_style->font_style.i_font_color = (col & 0x00ffffff);
- /* From DTD: <!-- alpha range = 0..100 --> */
- p_style->font_style.i_font_alpha = ((col >> 24) & 0xff) * 255 / 100;
- }
- }
- else if( !strcasecmp( "outline-color", psz_name ) )
- {
- if( *psz_value == '#' )
- {
- unsigned long col = strtol(psz_value+1, NULL, 16);
- p_style->font_style.i_outline_color = (col & 0x00ffffff);
- /* From DTD: <!-- alpha range = 0..100 --> */
- p_style->font_style.i_outline_alpha = ((col >> 24) & 0xff) * 255 / 100;
- }
- }
- else if( !strcasecmp( "shadow-color", psz_name ) )
- {
- if( *psz_value == '#' )
- {
- unsigned long col = strtol(psz_value+1, NULL, 16);
- p_style->font_style.i_shadow_color = (col & 0x00ffffff);
- /* From DTD: <!-- alpha range = 0..100 --> */
- p_style->font_style.i_shadow_alpha = ((col >> 24) & 0xff) * 255 / 100;
- }
- }
- }
- if( psz_name ) free( psz_name );
- if( psz_value ) free( psz_value );
- }
- }
- else if( !strcasecmp( "position", psz_node ) && (i_style_level == 2) )
- {
- while ( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
- {
- char *psz_name = xml_ReaderName ( p_xml_reader );
- char *psz_value = xml_ReaderValue ( p_xml_reader );
-
- if( psz_name && psz_value )
- {
- if( !strcasecmp( "alignment", psz_name ) )
- {
- if( !strcasecmp( "TopLeft", psz_value ) )
- {
- p_style->i_align |= SUBPICTURE_ALIGN_TOP;
- p_style->i_align |= SUBPICTURE_ALIGN_LEFT;
- }
- else if( !strcasecmp( "TopCenter", psz_value ) )
- {
- p_style->i_align |= SUBPICTURE_ALIGN_TOP;
- }
- else if( !strcasecmp( "TopRight", psz_value ) )
- {
- p_style->i_align |= SUBPICTURE_ALIGN_TOP;
- p_style->i_align |= SUBPICTURE_ALIGN_RIGHT;
- }
- else if( !strcasecmp( "MiddleLeft", psz_value ) )
- {
- p_style->i_align |= SUBPICTURE_ALIGN_LEFT;
- }
- else if( !strcasecmp( "MiddleCenter", psz_value ) )
- {
- p_style->i_align = 0;
- }
- else if( !strcasecmp( "MiddleRight", psz_value ) )
- {
- p_style->i_align |= SUBPICTURE_ALIGN_RIGHT;
- }
- else if( !strcasecmp( "BottomLeft", psz_value ) )
- {
- p_style->i_align |= SUBPICTURE_ALIGN_BOTTOM;
- p_style->i_align |= SUBPICTURE_ALIGN_LEFT;
- }
- else if( !strcasecmp( "BottomCenter", psz_value ) )
- {
- p_style->i_align |= SUBPICTURE_ALIGN_BOTTOM;
- }
- else if( !strcasecmp( "BottomRight", psz_value ) )
- {
- p_style->i_align |= SUBPICTURE_ALIGN_BOTTOM;
- p_style->i_align |= SUBPICTURE_ALIGN_RIGHT;
- }
- }
- }
- if( psz_name ) free( psz_name );
- if( psz_value ) free( psz_value );
- }
- }
-
- free( psz_node );
- }
- break;
- }
- }
- if( p_style ) free( p_style );
-}
-/*****************************************************************************
- * ParseSSAHeader: Retrieve global formatting information etc
- *****************************************************************************/
-static void ParseSSAHeader( decoder_t *p_dec )
-{
- decoder_sys_t *p_sys = p_dec->p_sys;
- char *psz_parser = NULL;
- char *psz_header = malloc( p_dec->fmt_in.i_extra+1 );
- int i_section_type = 1;
-
- memcpy( psz_header, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );
- psz_header[ p_dec->fmt_in.i_extra] = '\0';
-
- /* Handle [Script Info] section */
- psz_parser = strcasestr( psz_header, "[Script Info]" );
- if( psz_parser == NULL ) goto eof;
-
- psz_parser = GotoNextLine( psz_parser );