Commit d3c4e780 authored by Pierre Ynard's avatar Pierre Ynard

quartztext: update XML parsing

parent 4a5b1b08
...@@ -483,6 +483,7 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader, ...@@ -483,6 +483,7 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
uint32_t i_font_color = 0xffffff; uint32_t i_font_color = 0xffffff;
int i_font_alpha = 0; int i_font_alpha = 0;
int i_font_size = 24; int i_font_size = 24;
const char *attr;
// Default all attributes to the top font in the stack -- in case not // Default all attributes to the top font in the stack -- in case not
// all attributes are specified in the sub-font // all attributes are specified in the sub-font
...@@ -497,19 +498,19 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader, ...@@ -497,19 +498,19 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_alpha = (i_font_color >> 24) & 0xff; i_font_alpha = (i_font_color >> 24) & 0xff;
i_font_color &= 0x00ffffff; i_font_color &= 0x00ffffff;
while ( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS ) while ( (attr = xml_ReaderNextAttr( p_xml_reader )) )
{ {
char *psz_name = xml_ReaderName( p_xml_reader );
char *psz_value = xml_ReaderValue( p_xml_reader ); char *psz_value = xml_ReaderValue( p_xml_reader );
if( psz_name && psz_value ) if( !psz_value )
{ continue;
if( !strcasecmp( "face", psz_name ) )
if( !strcasecmp( "face", attr ) )
{ {
free( psz_fontname ); free( psz_fontname );
psz_fontname = strdup( psz_value ); psz_fontname = strdup( psz_value );
} }
else if( !strcasecmp( "size", psz_name ) ) else if( !strcasecmp( "size", attr ) )
{ {
if( ( *psz_value == '+' ) || ( *psz_value == '-' ) ) if( ( *psz_value == '+' ) || ( *psz_value == '-' ) )
{ {
...@@ -525,22 +526,21 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader, ...@@ -525,22 +526,21 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
else else
i_font_size = atoi( psz_value ); i_font_size = atoi( psz_value );
} }
else if( !strcasecmp( "color", psz_name ) && else if( !strcasecmp( "color", attr ) &&
( psz_value[0] == '#' ) ) ( psz_value[0] == '#' ) )
{ {
i_font_color = strtol( psz_value + 1, NULL, 16 ); i_font_color = strtol( psz_value + 1, NULL, 16 );
i_font_color &= 0x00ffffff; i_font_color &= 0x00ffffff;
} }
else if( !strcasecmp( "alpha", psz_name ) && else if( !strcasecmp( "alpha", attr ) &&
( psz_value[0] == '#' ) ) ( psz_value[0] == '#' ) )
{ {
i_font_alpha = strtol( psz_value + 1, NULL, 16 ); i_font_alpha = strtol( psz_value + 1, NULL, 16 );
i_font_alpha &= 0xff; i_font_alpha &= 0xff;
} }
free( psz_name );
free( psz_value ); free( psz_value );
} }
}
rv = PushFont( p_fonts, rv = PushFont( p_fonts,
psz_fontname, psz_fontname,
i_font_size * i_scale / 1000, i_font_size * i_scale / 1000,
...@@ -662,7 +662,8 @@ static int ProcessNodes( filter_t *p_filter, ...@@ -662,7 +662,8 @@ static int ProcessNodes( filter_t *p_filter,
vlc_value_t val; vlc_value_t val;
int i_scale = 1000; int i_scale = 1000;
char *psz_node = NULL; int type;
const char *node;
bool b_italic = false; bool b_italic = false;
bool b_bold = false; bool b_bold = false;
...@@ -696,42 +697,31 @@ static int ProcessNodes( filter_t *p_filter, ...@@ -696,42 +697,31 @@ static int ProcessNodes( filter_t *p_filter,
if( rv != VLC_SUCCESS ) if( rv != VLC_SUCCESS )
return rv; return rv;
while ( ( xml_ReaderRead( p_xml_reader ) == 1 ) ) while ( ( type = xml_ReaderNextNode( p_xml_reader, &node ) ) > 0 )
{ {
switch ( xml_ReaderNodeType( p_xml_reader ) ) switch ( type )
{ {
case XML_READER_NONE:
break;
case XML_READER_ENDELEM: case XML_READER_ENDELEM:
psz_node = xml_ReaderName( p_xml_reader ); if( !strcasecmp( "font", node ) )
if( psz_node )
{
if( !strcasecmp( "font", psz_node ) )
PopFont( &p_fonts ); PopFont( &p_fonts );
else if( !strcasecmp( "b", psz_node ) ) else if( !strcasecmp( "b", node ) )
b_bold = false; b_bold = false;
else if( !strcasecmp( "i", psz_node ) ) else if( !strcasecmp( "i", node ) )
b_italic = false; b_italic = false;
else if( !strcasecmp( "u", psz_node ) ) else if( !strcasecmp( "u", node ) )
b_uline = false; b_uline = false;
free( psz_node );
}
break; break;
case XML_READER_STARTELEM: case XML_READER_STARTELEM:
psz_node = xml_ReaderName( p_xml_reader ); if( !strcasecmp( "font", node ) )
if( psz_node )
{
if( !strcasecmp( "font", psz_node ) )
rv = HandleFontAttributes( p_xml_reader, &p_fonts, i_scale ); rv = HandleFontAttributes( p_xml_reader, &p_fonts, i_scale );
else if( !strcasecmp( "b", psz_node ) ) else if( !strcasecmp( "b", node ) )
b_bold = true; b_bold = true;
else if( !strcasecmp( "i", psz_node ) ) else if( !strcasecmp( "i", node ) )
b_italic = true; b_italic = true;
else if( !strcasecmp( "u", psz_node ) ) else if( !strcasecmp( "u", node ) )
b_uline = true; b_uline = true;
else if( !strcasecmp( "br", psz_node ) ) else if( !strcasecmp( "br", node ) )
{ {
CFMutableAttributedStringRef p_attrnode = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0); CFMutableAttributedStringRef p_attrnode = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
CFAttributedStringReplaceString( p_attrnode, CFRangeMake(0, 0), CFSTR("\n") ); CFAttributedStringReplaceString( p_attrnode, CFRangeMake(0, 0), CFSTR("\n") );
...@@ -744,18 +734,13 @@ static int ProcessNodes( filter_t *p_filter, ...@@ -744,18 +734,13 @@ static int ProcessNodes( filter_t *p_filter,
p_attrnode); p_attrnode);
CFRelease( p_attrnode ); CFRelease( p_attrnode );
} }
free( psz_node );
}
break; break;
case XML_READER_TEXT: case XML_READER_TEXT:
psz_node = xml_ReaderValue( p_xml_reader );
if( psz_node )
{
CFStringRef p_cfString; CFStringRef p_cfString;
int len; int len;
// Turn any multiple-whitespaces into single spaces // Turn any multiple-whitespaces into single spaces
char *s = strpbrk( psz_node, "\t\r\n " ); char *s = strpbrk( node, "\t\r\n " );
while( s ) while( s )
{ {
int i_whitespace = strspn( s, "\t\r\n " ); int i_whitespace = strspn( s, "\t\r\n " );
...@@ -771,7 +756,7 @@ static int ProcessNodes( filter_t *p_filter, ...@@ -771,7 +756,7 @@ static int ProcessNodes( filter_t *p_filter,
CFMutableAttributedStringRef p_attrnode = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0); CFMutableAttributedStringRef p_attrnode = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
p_cfString = CFStringCreateWithCString( NULL, psz_node, kCFStringEncodingUTF8 ); p_cfString = CFStringCreateWithCString( NULL, node, kCFStringEncodingUTF8 );
CFAttributedStringReplaceString( p_attrnode, CFRangeMake(0, 0), p_cfString ); CFAttributedStringReplaceString( p_attrnode, CFRangeMake(0, 0), p_cfString );
CFRelease( p_cfString ); CFRelease( p_cfString );
len = CFAttributedStringGetLength( p_attrnode ); len = CFAttributedStringGetLength( p_attrnode );
...@@ -784,8 +769,7 @@ static int ProcessNodes( filter_t *p_filter, ...@@ -784,8 +769,7 @@ static int ProcessNodes( filter_t *p_filter,
CFRangeMake(CFAttributedStringGetLength(p_attrString), 0), CFRangeMake(CFAttributedStringGetLength(p_attrString), 0),
p_attrnode); p_attrnode);
CFRelease( p_attrnode ); CFRelease( p_attrnode );
free( psz_node );
}
break; break;
} }
} }
...@@ -824,11 +808,11 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out, ...@@ -824,11 +808,11 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
if( p_xml_reader ) if( p_xml_reader )
{ {
/* Look for Root Node */ /* Look for Root Node */
if( xml_ReaderRead( p_xml_reader ) == 1 ) const char *name;
if( xml_ReaderNextNode( p_xml_reader, &name )
== XML_READER_STARTELEM )
{ {
char *psz_node = xml_ReaderName( p_xml_reader ); if( !strcasecmp( "karaoke", name ) )
if( !strcasecmp( "karaoke", psz_node ) )
{ {
/* We're going to have to render the text a number /* We're going to have to render the text a number
* of times to show the progress marker on the text. * of times to show the progress marker on the text.
...@@ -836,7 +820,7 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out, ...@@ -836,7 +820,7 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
var_SetBool( p_filter, "text-rerender", true ); var_SetBool( p_filter, "text-rerender", true );
b_karaoke = true; b_karaoke = true;
} }
else if( !strcasecmp( "text", psz_node ) ) else if( !strcasecmp( "text", name ) )
{ {
b_karaoke = false; b_karaoke = false;
} }
...@@ -847,8 +831,6 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out, ...@@ -847,8 +831,6 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
p_xml_reader = NULL; p_xml_reader = NULL;
rv = VLC_EGENERIC; rv = VLC_EGENERIC;
} }
free( psz_node );
} }
} }
......
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