Commit 681ac9f1 authored by basOS G's avatar basOS G Committed by Laurent Aimar

Added and used text_style_* methods.

It had the following functions:
- text_style_New  -- allocates default text style
- text_style_Dup  -- allocates and copies text style
- text_style_Copy -- copies text style
- text_style_Delete -- deallocates text style

NOTE that the vout_ShowText* functions will take a p_style and copy
it internally so you have to free in the caller function.
 Other modules where p_style was malloced there are now fixed to
copy before calling the vout* functions.

Original patch by basOS G with a few modifications by fenrir.
Signed-off-by: default avatarLaurent Aimar <fenrir@videolan.org>
parent 768bd8a4
...@@ -265,8 +265,25 @@ struct text_style_t ...@@ -265,8 +265,25 @@ struct text_style_t
#define STYLE_UNDERLINE 32 #define STYLE_UNDERLINE 32
#define STYLE_STRIKEOUT 64 #define STYLE_STRIKEOUT 64
static const text_style_t default_text_style = { NULL, 22, 0xffffff, 0xff, STYLE_OUTLINE, /**
0x000000, 0xff, 0x000000, 0xff, 0xffffff, 0x80, 0xffffff, 0xff, 1, 0, -1 }; * Create a default text style
*/
VLC_EXPORT( text_style_t *, text_style_New, ( void ) );
/**
* Copy a text style into another
*/
VLC_EXPORT( text_style_t *, text_style_Copy, ( text_style_t *, const text_style_t * ) );
/**
* Duplicate a text style
*/
VLC_EXPORT( text_style_t *, text_style_Duplicate, ( const text_style_t * ) );
/**
* Delete a text style created by text_style_New or text_style_Duplicate
*/
VLC_EXPORT( void, text_style_Delete, ( text_style_t * ) );
/** /**
* OSD menu button states * OSD menu button states
...@@ -590,8 +607,8 @@ static inline void osd_SetMenuUpdate( osd_menu_t *p_osd, bool b_value ) ...@@ -590,8 +607,8 @@ static inline void osd_SetMenuUpdate( osd_menu_t *p_osd, bool b_value )
* object. The types are declared in the include file include/vlc_osd.h * object. The types are declared in the include file include/vlc_osd.h
* @see vlc_osd.h * @see vlc_osd.h
*/ */
VLC_EXPORT( int, osd_ShowTextRelative, ( spu_t *, int, const char *, text_style_t *, int, int, int, mtime_t ) ); VLC_EXPORT( int, osd_ShowTextRelative, ( spu_t *, int, const char *, const text_style_t *, int, int, int, mtime_t ) );
VLC_EXPORT( int, osd_ShowTextAbsolute, ( spu_t *, int, const char *, text_style_t *, int, int, int, mtime_t, mtime_t ) ); VLC_EXPORT( int, osd_ShowTextAbsolute, ( spu_t *, int, const char *, const text_style_t *, int, int, int, mtime_t, mtime_t ) );
VLC_EXPORT( void, osd_Message, ( spu_t *, int, char *, ... ) LIBVLC_FORMAT( 3, 4 ) ); VLC_EXPORT( void, osd_Message, ( spu_t *, int, char *, ... ) LIBVLC_FORMAT( 3, 4 ) );
/** /**
...@@ -611,34 +628,9 @@ VLC_EXPORT( int, osd_Icon, ( vlc_object_t *, spu_t *, int, int, int, int, int, s ...@@ -611,34 +628,9 @@ VLC_EXPORT( int, osd_Icon, ( vlc_object_t *, spu_t *, int, int, int, int, int, s
* Vout text and widget overlays * Vout text and widget overlays
**********************************************************************/ **********************************************************************/
/** VLC_EXPORT( int, vout_ShowTextRelative, ( vout_thread_t *, int, char *, const text_style_t *, int, int, int, mtime_t ) );
* Show text on the video for some time
* \param p_vout pointer to the vout the text is to be showed on
* \param i_channel Subpicture channel
* \param psz_string The text to be shown
* \param p_style Pointer to a struct with text style info
* \param i_flags flags for alignment and such
* \param i_hmargin horizontal margin in pixels
* \param i_vmargin vertical margin in pixels
* \param i_duration Amount of time the text is to be shown.
*/
VLC_EXPORT( int, vout_ShowTextRelative, ( vout_thread_t *, int, char *, text_style_t *, int, int, int, mtime_t ) );
/** VLC_EXPORT( int, vout_ShowTextAbsolute, ( vout_thread_t *, int, const char *, const text_style_t *, int, int, int, mtime_t, mtime_t ) );
* Show text on the video from a given start date to a given end date
* \param p_vout pointer to the vout the text is to be showed on
* \param i_channel Subpicture channel
* \param psz_string The text to be shown
* \param p_style Pointer to a struct with text style info
* \param i_flags flags for alignment and such
* \param i_hmargin horizontal margin in pixels
* \param i_vmargin vertical margin in pixels
* \param i_start the time when this string is to appear on the video
* \param i_stop the time when this string should stop to be displayed
* if this is 0 the string will be shown untill the next string
* is about to be shown
*/
VLC_EXPORT( int, vout_ShowTextAbsolute, ( vout_thread_t *, int, const char *, text_style_t *, int, int, int, mtime_t, mtime_t ) );
/** /**
* Write an informative message at the default location, * Write an informative message at the default location,
......
...@@ -38,7 +38,7 @@ void ParseSSAString( decoder_t *p_dec, ...@@ -38,7 +38,7 @@ void ParseSSAString( decoder_t *p_dec,
* MarginV, Effect, Text */ * MarginV, Effect, Text */
decoder_sys_t *p_sys = p_dec->p_sys; decoder_sys_t *p_sys = p_dec->p_sys;
subpicture_t *p_spu = p_spu_in; subpicture_t *p_spu = p_spu_in;
ssa_style_t *p_style = NULL; ssa_style_t *p_ssa_style = NULL;
char *psz_new_subtitle = NULL; char *psz_new_subtitle = NULL;
char *psz_buffer_sub = NULL; char *psz_buffer_sub = NULL;
char *psz_style = NULL; char *psz_style = NULL;
...@@ -118,12 +118,12 @@ void ParseSSAString( decoder_t *p_dec, ...@@ -118,12 +118,12 @@ void ParseSSAString( decoder_t *p_dec,
for( i = 0; i < p_sys->i_ssa_styles; i++ ) for( i = 0; i < p_sys->i_ssa_styles; i++ )
{ {
if( !strcmp( p_sys->pp_ssa_styles[i]->psz_stylename, psz_style ) ) if( !strcmp( p_sys->pp_ssa_styles[i]->psz_stylename, psz_style ) )
p_style = p_sys->pp_ssa_styles[i]; p_ssa_style = p_sys->pp_ssa_styles[i];
} }
free( psz_style ); free( psz_style );
p_spu->p_region->psz_text = psz_new_subtitle; p_spu->p_region->psz_text = psz_new_subtitle;
if( p_style == NULL ) if( p_ssa_style == NULL )
{ {
p_spu->p_region->i_align = SUBPICTURE_ALIGN_BOTTOM | p_sys->i_align; p_spu->p_region->i_align = SUBPICTURE_ALIGN_BOTTOM | p_sys->i_align;
p_spu->p_region->i_x = p_sys->i_align ? 20 : 0; p_spu->p_region->i_x = p_sys->i_align ? 20 : 0;
...@@ -131,18 +131,18 @@ void ParseSSAString( decoder_t *p_dec, ...@@ -131,18 +131,18 @@ void ParseSSAString( decoder_t *p_dec,
} }
else else
{ {
msg_Dbg( p_dec, "style is: %s", p_style->psz_stylename); msg_Dbg( p_dec, "style is: %s", p_ssa_style->psz_stylename );
p_spu->p_region->p_style = &p_style->font_style; p_spu->p_region->p_style = text_style_Duplicate( &p_ssa_style->font_style );
p_spu->p_region->i_align = p_style->i_align; p_spu->p_region->i_align = p_ssa_style->i_align;
if( p_style->i_align & SUBPICTURE_ALIGN_LEFT ) if( p_ssa_style->i_align & SUBPICTURE_ALIGN_LEFT )
{ {
p_spu->p_region->i_x = (i_margin_l) ? i_margin_l : p_style->i_margin_h; p_spu->p_region->i_x = (i_margin_l) ? i_margin_l : p_ssa_style->i_margin_h;
} }
else if( p_style->i_align & SUBPICTURE_ALIGN_RIGHT ) else if( p_ssa_style->i_align & SUBPICTURE_ALIGN_RIGHT )
{ {
p_spu->p_region->i_x = (i_margin_r) ? i_margin_r : p_style->i_margin_h; p_spu->p_region->i_x = (i_margin_r) ? i_margin_r : p_ssa_style->i_margin_h;
} }
p_spu->p_region->i_y = (i_margin_v) ? i_margin_v : p_style->i_margin_v; p_spu->p_region->i_y = (i_margin_v) ? i_margin_v : p_ssa_style->i_margin_v;
} }
} }
...@@ -233,52 +233,52 @@ void ParseSSAHeader( decoder_t *p_dec ) ...@@ -233,52 +233,52 @@ void ParseSSAHeader( decoder_t *p_dec )
&i_border, &i_outline, &i_shadow, &i_align, &i_margin_l, &i_border, &i_outline, &i_shadow, &i_align, &i_margin_l,
&i_margin_r, &i_margin_v ) == 16 ) &i_margin_r, &i_margin_v ) == 16 )
{ {
ssa_style_t *p_style = malloc( sizeof(ssa_style_t) ); ssa_style_t *p_ssa_style = malloc( sizeof(ssa_style_t) );
p_style->psz_stylename = strdup( psz_temp_stylename ); p_ssa_style->psz_stylename = strdup( psz_temp_stylename );
p_style->font_style.psz_fontname = strdup( psz_temp_fontname ); p_ssa_style->font_style.psz_fontname = strdup( psz_temp_fontname );
p_style->font_style.i_font_size = i_font_size; p_ssa_style->font_style.i_font_size = i_font_size;
ParseColor( psz_temp_color1, &p_style->font_style.i_font_color, NULL ); ParseColor( psz_temp_color1, &p_ssa_style->font_style.i_font_color, NULL );
ParseColor( psz_temp_color4, &p_style->font_style.i_shadow_color, NULL ); ParseColor( psz_temp_color4, &p_ssa_style->font_style.i_shadow_color, NULL );
p_style->font_style.i_outline_color = p_style->font_style.i_shadow_color; p_ssa_style->font_style.i_outline_color = p_ssa_style->font_style.i_shadow_color;
p_style->font_style.i_font_alpha = p_style->font_style.i_outline_alpha p_ssa_style->font_style.i_font_alpha = p_ssa_style->font_style.i_outline_alpha
= p_style->font_style.i_shadow_alpha = 0x00; = p_ssa_style->font_style.i_shadow_alpha = 0x00;
p_style->font_style.i_style_flags = 0; p_ssa_style->font_style.i_style_flags = 0;
if( i_bold ) p_style->font_style.i_style_flags |= STYLE_BOLD; if( i_bold ) p_ssa_style->font_style.i_style_flags |= STYLE_BOLD;
if( i_italic ) p_style->font_style.i_style_flags |= STYLE_ITALIC; if( i_italic ) p_ssa_style->font_style.i_style_flags |= STYLE_ITALIC;
if( i_border == 1 ) if( i_border == 1 )
p_style->font_style.i_style_flags |= (STYLE_ITALIC | STYLE_OUTLINE); p_ssa_style->font_style.i_style_flags |= (STYLE_ITALIC | STYLE_OUTLINE);
else if( i_border == 3 ) else if( i_border == 3 )
{ {
p_style->font_style.i_style_flags |= STYLE_BACKGROUND; p_ssa_style->font_style.i_style_flags |= STYLE_BACKGROUND;
p_style->font_style.i_background_color = p_style->font_style.i_shadow_color; p_ssa_style->font_style.i_background_color = p_ssa_style->font_style.i_shadow_color;
p_style->font_style.i_background_alpha = p_style->font_style.i_shadow_alpha; p_ssa_style->font_style.i_background_alpha = p_ssa_style->font_style.i_shadow_alpha;
} }
p_style->font_style.i_shadow_width = i_shadow; p_ssa_style->font_style.i_shadow_width = i_shadow;
p_style->font_style.i_outline_width = i_outline; p_ssa_style->font_style.i_outline_width = i_outline;
p_style->i_align = 0; p_ssa_style->i_align = 0;
if( i_align == 1 || i_align == 5 || i_align == 9 ) if( i_align == 1 || i_align == 5 || i_align == 9 )
p_style->i_align |= SUBPICTURE_ALIGN_LEFT; p_ssa_style->i_align |= SUBPICTURE_ALIGN_LEFT;
if( i_align == 3 || i_align == 7 || i_align == 11 ) if( i_align == 3 || i_align == 7 || i_align == 11 )
p_style->i_align |= SUBPICTURE_ALIGN_RIGHT; p_ssa_style->i_align |= SUBPICTURE_ALIGN_RIGHT;
if( i_align < 4 ) if( i_align < 4 )
p_style->i_align |= SUBPICTURE_ALIGN_BOTTOM; p_ssa_style->i_align |= SUBPICTURE_ALIGN_BOTTOM;
else if( i_align < 8 ) else if( i_align < 8 )
p_style->i_align |= SUBPICTURE_ALIGN_TOP; p_ssa_style->i_align |= SUBPICTURE_ALIGN_TOP;
p_style->i_margin_h = ( p_style->i_align & SUBPICTURE_ALIGN_RIGHT ) ? p_ssa_style->i_margin_h = ( p_ssa_style->i_align & SUBPICTURE_ALIGN_RIGHT ) ?
i_margin_r : i_margin_l; i_margin_r : i_margin_l;
p_style->i_margin_v = i_margin_v; p_ssa_style->i_margin_v = i_margin_v;
p_style->i_margin_percent_h = 0; p_ssa_style->i_margin_percent_h = 0;
p_style->i_margin_percent_v = 0; p_ssa_style->i_margin_percent_v = 0;
p_style->font_style.i_karaoke_background_color = 0xffffff; p_ssa_style->font_style.i_karaoke_background_color = 0xffffff;
p_style->font_style.i_karaoke_background_alpha = 0xff; p_ssa_style->font_style.i_karaoke_background_alpha = 0xff;
TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_style ); TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_ssa_style );
} }
else msg_Warn( p_dec, "SSA v4 styleline parsing failed" ); else msg_Warn( p_dec, "SSA v4 styleline parsing failed" );
} }
...@@ -294,55 +294,55 @@ void ParseSSAHeader( decoder_t *p_dec ) ...@@ -294,55 +294,55 @@ void ParseSSAHeader( decoder_t *p_dec )
&i_underline, &i_strikeout, &i_scale_x, &i_scale_y, &i_spacing, &i_border, &i_outline, &i_underline, &i_strikeout, &i_scale_x, &i_scale_y, &i_spacing, &i_border, &i_outline,
&i_shadow, &i_align, &i_margin_l, &i_margin_r, &i_margin_v ) == 21 ) &i_shadow, &i_align, &i_margin_l, &i_margin_r, &i_margin_v ) == 21 )
{ {
ssa_style_t *p_style = malloc( sizeof(ssa_style_t) ); ssa_style_t *p_ssa_style = malloc( sizeof(ssa_style_t) );
p_style->psz_stylename = strdup( psz_temp_stylename ); p_ssa_style->psz_stylename = strdup( psz_temp_stylename );
p_style->font_style.psz_fontname = strdup( psz_temp_fontname ); p_ssa_style->font_style.psz_fontname = strdup( psz_temp_fontname );
p_style->font_style.i_font_size = i_font_size; p_ssa_style->font_style.i_font_size = i_font_size;
ParseColor( psz_temp_color1, &p_style->font_style.i_font_color, ParseColor( psz_temp_color1, &p_ssa_style->font_style.i_font_color,
&p_style->font_style.i_font_alpha ); &p_ssa_style->font_style.i_font_alpha );
ParseColor( psz_temp_color3, &p_style->font_style.i_outline_color, ParseColor( psz_temp_color3, &p_ssa_style->font_style.i_outline_color,
&p_style->font_style.i_outline_alpha ); &p_ssa_style->font_style.i_outline_alpha );
ParseColor( psz_temp_color4, &p_style->font_style.i_shadow_color, ParseColor( psz_temp_color4, &p_ssa_style->font_style.i_shadow_color,
&p_style->font_style.i_shadow_alpha ); &p_ssa_style->font_style.i_shadow_alpha );
p_style->font_style.i_style_flags = 0; p_ssa_style->font_style.i_style_flags = 0;
if( i_bold ) p_style->font_style.i_style_flags |= STYLE_BOLD; if( i_bold ) p_ssa_style->font_style.i_style_flags |= STYLE_BOLD;
if( i_italic ) p_style->font_style.i_style_flags |= STYLE_ITALIC; if( i_italic ) p_ssa_style->font_style.i_style_flags |= STYLE_ITALIC;
if( i_underline ) p_style->font_style.i_style_flags |= STYLE_UNDERLINE; if( i_underline ) p_ssa_style->font_style.i_style_flags |= STYLE_UNDERLINE;
if( i_strikeout ) p_style->font_style.i_style_flags |= STYLE_STRIKEOUT; if( i_strikeout ) p_ssa_style->font_style.i_style_flags |= STYLE_STRIKEOUT;
if( i_border == 1 ) p_style->font_style.i_style_flags |= (STYLE_ITALIC | STYLE_OUTLINE); if( i_border == 1 ) p_ssa_style->font_style.i_style_flags |= (STYLE_ITALIC | STYLE_OUTLINE);
else if( i_border == 3 ) else if( i_border == 3 )
{ {
p_style->font_style.i_style_flags |= STYLE_BACKGROUND; p_ssa_style->font_style.i_style_flags |= STYLE_BACKGROUND;
p_style->font_style.i_background_color = p_style->font_style.i_shadow_color; p_ssa_style->font_style.i_background_color = p_ssa_style->font_style.i_shadow_color;
p_style->font_style.i_background_alpha = p_style->font_style.i_shadow_alpha; p_ssa_style->font_style.i_background_alpha = p_ssa_style->font_style.i_shadow_alpha;
} }
p_style->font_style.i_shadow_width = ( i_border == 1 ) ? i_shadow : 0; p_ssa_style->font_style.i_shadow_width = ( i_border == 1 ) ? i_shadow : 0;
p_style->font_style.i_outline_width = ( i_border == 1 ) ? i_outline : 0; p_ssa_style->font_style.i_outline_width = ( i_border == 1 ) ? i_outline : 0;
p_style->font_style.i_spacing = i_spacing; p_ssa_style->font_style.i_spacing = i_spacing;
//p_style->font_style.f_angle = f_angle; //p_ssa_style->font_style.f_angle = f_angle;
p_style->i_align = 0; p_ssa_style->i_align = 0;
if( i_align == 0x1 || i_align == 0x4 || i_align == 0x7 ) if( i_align == 0x1 || i_align == 0x4 || i_align == 0x7 )
p_style->i_align |= SUBPICTURE_ALIGN_LEFT; p_ssa_style->i_align |= SUBPICTURE_ALIGN_LEFT;
if( i_align == 0x3 || i_align == 0x6 || i_align == 0x9 ) if( i_align == 0x3 || i_align == 0x6 || i_align == 0x9 )
p_style->i_align |= SUBPICTURE_ALIGN_RIGHT; p_ssa_style->i_align |= SUBPICTURE_ALIGN_RIGHT;
if( i_align == 0x7 || i_align == 0x8 || i_align == 0x9 ) if( i_align == 0x7 || i_align == 0x8 || i_align == 0x9 )
p_style->i_align |= SUBPICTURE_ALIGN_TOP; p_ssa_style->i_align |= SUBPICTURE_ALIGN_TOP;
if( i_align == 0x1 || i_align == 0x2 || i_align == 0x3 ) if( i_align == 0x1 || i_align == 0x2 || i_align == 0x3 )
p_style->i_align |= SUBPICTURE_ALIGN_BOTTOM; p_ssa_style->i_align |= SUBPICTURE_ALIGN_BOTTOM;
p_style->i_margin_h = ( p_style->i_align & SUBPICTURE_ALIGN_RIGHT ) ? p_ssa_style->i_margin_h = ( p_ssa_style->i_align & SUBPICTURE_ALIGN_RIGHT ) ?
i_margin_r : i_margin_l; i_margin_r : i_margin_l;
p_style->i_margin_v = i_margin_v; p_ssa_style->i_margin_v = i_margin_v;
p_style->i_margin_percent_h = 0; p_ssa_style->i_margin_percent_h = 0;
p_style->i_margin_percent_v = 0; p_ssa_style->i_margin_percent_v = 0;
p_style->font_style.i_karaoke_background_color = 0xffffff; p_ssa_style->font_style.i_karaoke_background_color = 0xffffff;
p_style->font_style.i_karaoke_background_alpha = 0xff; p_ssa_style->font_style.i_karaoke_background_alpha = 0xff;
/*TODO: Ignored: angle i_scale_x|y (fontscaling), i_encoding */ /*TODO: Ignored: angle i_scale_x|y (fontscaling), i_encoding */
TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_style ); TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_ssa_style );
} }
else msg_Dbg( p_dec, "SSA V4+ styleline parsing failed" ); else msg_Dbg( p_dec, "SSA V4+ styleline parsing failed" );
} }
......
...@@ -146,6 +146,7 @@ static void CloseDecoder( vlc_object_t *p_this ) ...@@ -146,6 +146,7 @@ static void CloseDecoder( vlc_object_t *p_this )
continue; continue;
free( p_sys->pp_ssa_styles[i]->psz_stylename ); free( p_sys->pp_ssa_styles[i]->psz_stylename );
//FIXME: Make font_style a pointer and use text_style_* functions
free( p_sys->pp_ssa_styles[i]->font_style.psz_fontname ); free( p_sys->pp_ssa_styles[i]->font_style.psz_fontname );
free( p_sys->pp_ssa_styles[i] ); free( p_sys->pp_ssa_styles[i] );
} }
...@@ -261,7 +262,7 @@ static char *GrabAttributeValue( const char *psz_attribute, ...@@ -261,7 +262,7 @@ static char *GrabAttributeValue( const char *psz_attribute,
static ssa_style_t *ParseStyle( decoder_sys_t *p_sys, char *psz_subtitle ) static ssa_style_t *ParseStyle( decoder_sys_t *p_sys, char *psz_subtitle )
{ {
ssa_style_t *p_style = NULL; ssa_style_t *p_ssa_style = NULL;
char *psz_style = GrabAttributeValue( "style", psz_subtitle ); char *psz_style = GrabAttributeValue( "style", psz_subtitle );
if( psz_style ) if( psz_style )
...@@ -271,11 +272,11 @@ static ssa_style_t *ParseStyle( decoder_sys_t *p_sys, char *psz_subtitle ) ...@@ -271,11 +272,11 @@ static ssa_style_t *ParseStyle( decoder_sys_t *p_sys, char *psz_subtitle )
for( i = 0; i < p_sys->i_ssa_styles; i++ ) for( i = 0; i < p_sys->i_ssa_styles; i++ )
{ {
if( !strcmp( p_sys->pp_ssa_styles[i]->psz_stylename, psz_style ) ) if( !strcmp( p_sys->pp_ssa_styles[i]->psz_stylename, psz_style ) )
p_style = p_sys->pp_ssa_styles[i]; p_ssa_style = p_sys->pp_ssa_styles[i];
} }
free( psz_style ); free( psz_style );
} }
return p_style; return p_ssa_style;
} }
static int ParsePositionAttributeList( char *psz_subtitle, int *i_align, static int ParsePositionAttributeList( char *psz_subtitle, int *i_align,
...@@ -390,7 +391,7 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec, ...@@ -390,7 +391,7 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec,
if( p_text_region != NULL ) if( p_text_region != NULL )
{ {
ssa_style_t *p_style = NULL; ssa_style_t *p_ssa_style = NULL;
p_text_region->psz_text = NULL; p_text_region->psz_text = NULL;
p_text_region->psz_html = strndup( psz_subtitle, i_len ); p_text_region->psz_html = strndup( psz_subtitle, i_len );
...@@ -400,34 +401,34 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec, ...@@ -400,34 +401,34 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec,
return NULL; return NULL;
} }
p_style = ParseStyle( p_sys, p_text_region->psz_html ); p_ssa_style = ParseStyle( p_sys, p_text_region->psz_html );
if( !p_style ) if( !p_ssa_style )
{ {
int i; int i;
for( i = 0; i < p_sys->i_ssa_styles; i++ ) for( i = 0; i < p_sys->i_ssa_styles; i++ )
{ {
if( !strcasecmp( p_sys->pp_ssa_styles[i]->psz_stylename, "Default" ) ) if( !strcasecmp( p_sys->pp_ssa_styles[i]->psz_stylename, "Default" ) )
p_style = p_sys->pp_ssa_styles[i]; p_ssa_style = p_sys->pp_ssa_styles[i];
} }
} }
if( p_style ) if( p_ssa_style )
{ {
msg_Dbg( p_dec, "style is: %s", p_style->psz_stylename ); msg_Dbg( p_dec, "style is: %s", p_ssa_style->psz_stylename );
p_text_region->p_style = &p_style->font_style; p_text_region->p_style = text_style_Duplicate( &p_ssa_style->font_style );
p_text_region->i_align = p_style->i_align; p_text_region->i_align = p_ssa_style->i_align;
/* TODO: Setup % based offsets properly, without adversely affecting /* TODO: Setup % based offsets properly, without adversely affecting
* everything else in vlc. Will address with separate patch, * everything else in vlc. Will address with separate patch,
* to prevent this one being any more complicated. * to prevent this one being any more complicated.
* p_style->i_margin_percent_h; * p_ssa_style->i_margin_percent_h;
* p_style->i_margin_percent_v; * p_ssa_style->i_margin_percent_v;
*/ */
p_text_region->i_x = p_style->i_margin_h; p_text_region->i_x = p_ssa_style->i_margin_h;
p_text_region->i_y = p_style->i_margin_v; p_text_region->i_y = p_ssa_style->i_margin_v;
} }
else else
...@@ -532,7 +533,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -532,7 +533,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
{ {
decoder_sys_t *p_sys = p_dec->p_sys; decoder_sys_t *p_sys = p_dec->p_sys;
char *psz_node; char *psz_node;
ssa_style_t *p_style = NULL; ssa_style_t *p_ssa_style = NULL;
int i_style_level = 0; int i_style_level = 0;
int i_metadata_level = 0; int i_metadata_level = 0;
...@@ -565,9 +566,9 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -565,9 +566,9 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
case 2: case 2:
if( !strcasecmp( "style", psz_node ) ) if( !strcasecmp( "style", psz_node ) )
{ {
TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_style ); TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_ssa_style );
p_style = NULL; p_ssa_style = NULL;
i_style_level--; i_style_level--;
} }
break; break;
...@@ -612,8 +613,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -612,8 +613,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
{ {
i_style_level++; i_style_level++;
p_style = calloc( 1, sizeof(ssa_style_t) ); p_ssa_style = calloc( 1, sizeof(ssa_style_t) );
if( ! p_style ) if( !p_ssa_style )
{ {
free( psz_node ); free( psz_node );
return; return;
...@@ -630,9 +631,11 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -630,9 +631,11 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
{ {
ssa_style_t *p_default_style = p_sys->pp_ssa_styles[i]; ssa_style_t *p_default_style = p_sys->pp_ssa_styles[i];
memcpy( p_style, p_default_style, sizeof( ssa_style_t ) ); memcpy( p_ssa_style, p_default_style, sizeof( ssa_style_t ) );
p_style->font_style.psz_fontname = strdup( p_style->font_style.psz_fontname ); //FIXME: Make font_style a pointer. Actually we double copy some data here,
p_style->psz_stylename = NULL; // we use text_style_Copy to avoid copying psz_fontname, though .
text_style_Copy( &p_ssa_style->font_style, &p_default_style->font_style );
p_ssa_style->psz_stylename = NULL;
} }
} }
...@@ -644,7 +647,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -644,7 +647,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
if( psz_name && psz_value ) if( psz_name && psz_value )
{ {
if( !strcasecmp( "name", psz_name ) ) if( !strcasecmp( "name", psz_name ) )
p_style->psz_stylename = strdup( psz_value); p_ssa_style->psz_stylename = strdup( psz_value );
} }
free( psz_name ); free( psz_name );
free( psz_value ); free( psz_value );
...@@ -661,8 +664,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -661,8 +664,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
{ {
if( !strcasecmp( "face", psz_name ) ) if( !strcasecmp( "face", psz_name ) )
{ {
free( p_style->font_style.psz_fontname ); free( p_ssa_style->font_style.psz_fontname );
p_style->font_style.psz_fontname = strdup( psz_value ); p_ssa_style->font_style.psz_fontname = strdup( psz_value );
} }
else if( !strcasecmp( "size", psz_name ) ) else if( !strcasecmp( "size", psz_name ) )
{ {
...@@ -671,44 +674,44 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -671,44 +674,44 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
int i_value = atoi( psz_value ); int i_value = atoi( psz_value );
if( ( i_value >= -5 ) && ( i_value <= 5 ) ) if( ( i_value >= -5 ) && ( i_value <= 5 ) )
p_style->font_style.i_font_size += p_ssa_style->font_style.i_font_size +=
( i_value * p_style->font_style.i_font_size ) / 10; ( i_value * p_ssa_style->font_style.i_font_size ) / 10;
else if( i_value < -5 ) else if( i_value < -5 )
p_style->font_style.i_font_size = - i_value; p_ssa_style->font_style.i_font_size = - i_value;
else if( i_value > 5 ) else if( i_value > 5 )
p_style->font_style.i_font_size = i_value; p_ssa_style->font_style.i_font_size = i_value;
} }