Commit 02aeb848 authored by Francois Cartegnie's avatar Francois Cartegnie

vlc_text_style: add text_style_Create()

removes temporary text_style_Reset() and finishes
migrating decoders.

We might want to deprecate text_style_New().
parent 32e39d70
...@@ -134,6 +134,13 @@ struct text_segment_t { ...@@ -134,6 +134,13 @@ struct text_segment_t {
*/ */
VLC_API text_style_t * text_style_New( void ); VLC_API text_style_t * text_style_New( void );
/**
* Create a text style
*
* Set feature flags as argument if you want to set style defaults
*/
VLC_API text_style_t * text_style_Create( int );
/** /**
* Copy a text style into another * Copy a text style into another
*/ */
...@@ -151,21 +158,6 @@ VLC_API text_style_t * text_style_Duplicate( const text_style_t * ); ...@@ -151,21 +158,6 @@ VLC_API text_style_t * text_style_Duplicate( const text_style_t * );
*/ */
VLC_API void text_style_Merge( text_style_t *, const text_style_t *, bool b_override ); VLC_API void text_style_Merge( text_style_t *, const text_style_t *, bool b_override );
inline void text_style_Reset( text_style_t *p_style )
{
free(p_style->psz_fontname);
p_style->psz_fontname = NULL;
free(p_style->psz_monofontname);
p_style->psz_monofontname = NULL;
p_style->i_features = STYLE_NO_DEFAULTS;
p_style->i_style_flags = 0;
p_style->f_font_relsize = 0.0;
p_style->i_font_size = 0;
p_style->i_outline_width = 0;
p_style->i_shadow_width = 0;
p_style->i_spacing = -0;
}
/** /**
* Delete a text style created by text_style_New or text_style_Duplicate * Delete a text style created by text_style_New or text_style_Duplicate
*/ */
......
...@@ -104,14 +104,15 @@ static void SubpictureTextUpdate(subpicture_t *subpic, ...@@ -104,14 +104,15 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
r->i_x = p_region->i_charleft - (p_region->i_fontwidth + p_region->i_horint / 2) + p_region->i_charleft_adj; r->i_x = p_region->i_charleft - (p_region->i_fontwidth + p_region->i_horint / 2) + p_region->i_charleft_adj;
r->i_y = p_region->i_charbottom - (p_region->i_fontheight + p_region->i_verint / 2) + p_region->i_charbottom_adj; r->i_y = p_region->i_charbottom - (p_region->i_fontheight + p_region->i_verint / 2) + p_region->i_charbottom_adj;
r->p_text->style = text_style_New(); r->p_text->style = text_style_Create( STYLE_NO_DEFAULTS );
r->p_text->style->psz_fontname = p_region->psz_fontname ? strdup( p_region->psz_fontname ) : NULL; r->p_text->style->psz_fontname = p_region->psz_fontname ? strdup( p_region->psz_fontname ) : NULL;
r->p_text->style->i_font_size = p_region->i_fontheight; r->p_text->style->i_font_size = p_region->i_fontheight;
r->p_text->style->i_font_color = p_region->i_font_color; r->p_text->style->i_font_color = p_region->i_font_color;
r->p_text->style->i_style_flags = 0; r->p_text->style->i_features |= STYLE_HAS_FONT_COLOR;
if( p_region->i_fontwidth < p_region->i_fontheight ) if( p_region->i_fontwidth < p_region->i_fontheight )
{ {
r->p_text->style->i_style_flags |= STYLE_HALFWIDTH; r->p_text->style->i_style_flags |= STYLE_HALFWIDTH;
r->p_text->style->i_features |= STYLE_HAS_FLAGS;
} }
r->p_text->style->i_spacing = p_region->i_horint; r->p_text->style->i_spacing = p_region->i_horint;
} }
......
...@@ -1013,13 +1013,12 @@ static text_segment_t * Eia608TextLine( struct eia608_screen *screen, int i_row, ...@@ -1013,13 +1013,12 @@ static text_segment_t * Eia608TextLine( struct eia608_screen *screen, int i_row,
if(!p_segment) if(!p_segment)
return NULL; return NULL;
p_segment->style = text_style_New(); p_segment->style = text_style_Create( STYLE_NO_DEFAULTS );
if(!p_segment->style) if(!p_segment->style)
{ {
text_segment_Delete(p_segment); text_segment_Delete(p_segment);
return NULL; return NULL;
} }
text_style_Reset( p_segment->style );
/* Ensure we get a monospaced font (required for accurate positioning */ /* Ensure we get a monospaced font (required for accurate positioning */
p_segment->style->i_style_flags |= STYLE_MONOSPACED; p_segment->style->i_style_flags |= STYLE_MONOSPACED;
...@@ -1056,13 +1055,12 @@ static text_segment_t * Eia608TextLine( struct eia608_screen *screen, int i_row, ...@@ -1056,13 +1055,12 @@ static text_segment_t * Eia608TextLine( struct eia608_screen *screen, int i_row,
if(!p_segment) if(!p_segment)
return p_segments_head; return p_segments_head;
p_segment->style = text_style_New(); p_segment->style = text_style_Create( STYLE_NO_DEFAULTS );
if(!p_segment->style) if(!p_segment->style)
{ {
text_segment_Delete(p_segment); text_segment_Delete(p_segment);
return p_segments_head; return p_segments_head;
} }
text_style_Reset( p_segment->style );
p_segment->style->i_style_flags |= STYLE_MONOSPACED; p_segment->style->i_style_flags |= STYLE_MONOSPACED;
/* start segment with new style */ /* start segment with new style */
......
...@@ -876,20 +876,9 @@ struct style_stack ...@@ -876,20 +876,9 @@ struct style_stack
style_stack_t* p_next; style_stack_t* p_next;
}; };
static text_style_t *CreateDefaultStyle()
{
text_style_t *p_style = text_style_New();
if( p_style )
{
text_style_Reset( p_style );
p_style->f_font_relsize = STYLE_DEFAULT_REL_FONT_SIZE;
}
return p_style;
}
static text_style_t* DuplicateAndPushStyle(style_stack_t** pp_stack) static text_style_t* DuplicateAndPushStyle(style_stack_t** pp_stack)
{ {
text_style_t* p_dup = ( *pp_stack ) ? text_style_Duplicate( (*pp_stack)->p_style ) : CreateDefaultStyle(); text_style_t* p_dup = ( *pp_stack ) ? text_style_Duplicate( (*pp_stack)->p_style ) : text_style_Create( STYLE_NO_DEFAULTS );
if ( unlikely( !p_dup ) ) if ( unlikely( !p_dup ) )
return NULL; return NULL;
style_stack_t* p_entry = malloc( sizeof( *p_entry ) ); style_stack_t* p_entry = malloc( sizeof( *p_entry ) );
...@@ -934,7 +923,7 @@ static text_segment_t* NewTextSegmentPopStyle( text_segment_t* p_segment, style_ ...@@ -934,7 +923,7 @@ static text_segment_t* NewTextSegmentPopStyle( text_segment_t* p_segment, style_
// We shouldn't have an empty stack since this happens when closing a tag, // We shouldn't have an empty stack since this happens when closing a tag,
// but better be safe than sorry if (/when) we encounter a broken subtitle file. // but better be safe than sorry if (/when) we encounter a broken subtitle file.
PopStyle( pp_stack ); PopStyle( pp_stack );
text_style_t* p_dup = ( *pp_stack ) ? text_style_Duplicate( (*pp_stack)->p_style ) : CreateDefaultStyle(); text_style_t* p_dup = ( *pp_stack ) ? text_style_Duplicate( (*pp_stack)->p_style ) : text_style_Create( STYLE_NO_DEFAULTS );
p_new->style = p_dup; p_new->style = p_dup;
p_segment->p_next = p_new; p_segment->p_next = p_new;
return p_new; return p_new;
......
...@@ -122,13 +122,12 @@ static inline subpicture_t *decoder_NewSubpictureText(decoder_t *decoder) ...@@ -122,13 +122,12 @@ static inline subpicture_t *decoder_NewSubpictureText(decoder_t *decoder)
.pf_destroy = SubpictureTextDestroy, .pf_destroy = SubpictureTextDestroy,
.p_sys = sys, .p_sys = sys,
}; };
sys->p_default_style = text_style_New(); sys->p_default_style = text_style_Create( STYLE_NO_DEFAULTS );
if(unlikely(!sys->p_default_style)) if(unlikely(!sys->p_default_style))
{ {
free(sys); free(sys);
return NULL; return NULL;
} }
text_style_Reset( sys->p_default_style );
subpicture_t *subpic = decoder_NewSubpicture(decoder, &updater); subpicture_t *subpic = decoder_NewSubpicture(decoder, &updater);
if (!subpic) if (!subpic)
{ {
......
...@@ -361,7 +361,6 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block ) ...@@ -361,7 +361,6 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
text_style_t style; text_style_t style;
memset( &style, 0, sizeof(text_style_t) ); memset( &style, 0, sizeof(text_style_t) );
text_style_Reset( &style );
style.i_style_flags = ConvertFlags( p_buf[6] ); style.i_style_flags = ConvertFlags( p_buf[6] );
style.f_font_relsize = p_buf[7] * 5 / 100; /* in % units of 0.05 height */ style.f_font_relsize = p_buf[7] * 5 / 100; /* in % units of 0.05 height */
style.i_font_color = GetDWBE(p_buf+8) >> 8;// RGBA -> RGB style.i_font_color = GetDWBE(p_buf+8) >> 8;// RGBA -> RGB
......
...@@ -616,13 +616,12 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -616,13 +616,12 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
p_ssa_style = calloc( 1, sizeof(ssa_style_t) ); p_ssa_style = calloc( 1, sizeof(ssa_style_t) );
if( unlikely(!p_ssa_style) ) if( unlikely(!p_ssa_style) )
return; return;
p_ssa_style->p_style = text_style_New(); p_ssa_style->p_style = text_style_Create( STYLE_NO_DEFAULTS );
if( unlikely(!p_ssa_style->p_style) ) if( unlikely(!p_ssa_style->p_style) )
{ {
free(p_ssa_style); free(p_ssa_style);
return; return;
} }
text_style_Reset( p_ssa_style->p_style );
/* All styles are supposed to default to Default, and then /* All styles are supposed to default to Default, and then
* one or more settings are over-ridden. * one or more settings are over-ridden.
* At the moment this only effects styles defined AFTER * At the moment this only effects styles defined AFTER
......
...@@ -786,10 +786,9 @@ int SetupSpuES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample ) ...@@ -786,10 +786,9 @@ int SetupSpuES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
{ {
p_track->fmt.i_codec = VLC_CODEC_TX3G; p_track->fmt.i_codec = VLC_CODEC_TX3G;
text_style_t *p_style = text_style_New(); text_style_t *p_style = text_style_Create( STYLE_NO_DEFAULTS );
if ( p_style ) if ( p_style )
{ {
text_style_Reset( p_style );
if ( p_text->i_font_size ) /* !WARN: in % of 5% height */ if ( p_text->i_font_size ) /* !WARN: in % of 5% height */
{ {
p_style->f_font_relsize = p_text->i_font_size * 5 / 100; p_style->f_font_relsize = p_text->i_font_size * 5 / 100;
......
...@@ -1174,7 +1174,7 @@ static int Create( vlc_object_t *p_this ) ...@@ -1174,7 +1174,7 @@ static int Create( vlc_object_t *p_this )
p_sys->p_library = 0; p_sys->p_library = 0;
/* default style to apply to uncomplete segmeents styles */ /* default style to apply to uncomplete segmeents styles */
p_sys->p_default_style = text_style_New(); p_sys->p_default_style = text_style_Create( STYLE_FULLY_SET );
if(unlikely(!p_sys->p_default_style)) if(unlikely(!p_sys->p_default_style))
{ {
free(p_sys); free(p_sys);
...@@ -1184,14 +1184,13 @@ static int Create( vlc_object_t *p_this ) ...@@ -1184,14 +1184,13 @@ static int Create( vlc_object_t *p_this )
p_sys->p_style = NULL; p_sys->p_style = NULL;
/* empty style for style overriding cases */ /* empty style for style overriding cases */
p_sys->p_forced_style = text_style_New(); p_sys->p_forced_style = text_style_Create( STYLE_NO_DEFAULTS );
if(unlikely(!p_sys->p_forced_style)) if(unlikely(!p_sys->p_forced_style))
{ {
text_style_Delete( p_sys->p_default_style ); text_style_Delete( p_sys->p_default_style );
free(p_sys); free(p_sys);
return VLC_ENOMEM; return VLC_ENOMEM;
} }
text_style_Reset( p_sys->p_forced_style );
/* fills default and forced style */ /* fills default and forced style */
FillDefaultStyles( p_filter ); FillDefaultStyles( p_filter );
......
...@@ -56,7 +56,7 @@ overlay_t *OverlayCreate( void ) ...@@ -56,7 +56,7 @@ overlay_t *OverlayCreate( void )
p_ovl->b_active = false; p_ovl->b_active = false;
video_format_Setup( &p_ovl->format, VLC_FOURCC( '\0','\0','\0','\0') , 0, 0, video_format_Setup( &p_ovl->format, VLC_FOURCC( '\0','\0','\0','\0') , 0, 0,
0, 0, 1, 1 ); 0, 0, 1, 1 );
p_ovl->p_fontstyle = text_style_New(); p_ovl->p_fontstyle = text_style_Create( STYLE_NO_DEFAULTS );
p_ovl->data.p_text = NULL; p_ovl->data.p_text = NULL;
return p_ovl; return p_ovl;
...@@ -624,6 +624,7 @@ static int exec_GetTextAlpha( filter_t *p_filter, ...@@ -624,6 +624,7 @@ static int exec_GetTextAlpha( filter_t *p_filter,
return VLC_EGENERIC; return VLC_EGENERIC;
p_results->fontstyle.i_font_alpha = p_ovl->p_fontstyle->i_font_alpha; p_results->fontstyle.i_font_alpha = p_ovl->p_fontstyle->i_font_alpha;
p_results->fontstyle.i_features |= STYLE_HAS_FONT_ALPHA;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -637,6 +638,7 @@ static int exec_GetTextColor( filter_t *p_filter, ...@@ -637,6 +638,7 @@ static int exec_GetTextColor( filter_t *p_filter,
return VLC_EGENERIC; return VLC_EGENERIC;
p_results->fontstyle.i_font_color = p_ovl->p_fontstyle->i_font_color; p_results->fontstyle.i_font_color = p_ovl->p_fontstyle->i_font_color;
p_results->fontstyle.i_features |= STYLE_HAS_FONT_COLOR;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -713,6 +715,7 @@ static int exec_SetTextAlpha( filter_t *p_filter, ...@@ -713,6 +715,7 @@ static int exec_SetTextAlpha( filter_t *p_filter,
return VLC_EGENERIC; return VLC_EGENERIC;
p_ovl->p_fontstyle->i_font_alpha = p_params->fontstyle.i_font_alpha; p_ovl->p_fontstyle->i_font_alpha = p_params->fontstyle.i_font_alpha;
p_ovl->p_fontstyle->i_features |= STYLE_HAS_FONT_ALPHA;
p_sys->b_updated = p_ovl->b_active; p_sys->b_updated = p_ovl->b_active;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -729,6 +732,7 @@ static int exec_SetTextColor( filter_t *p_filter, ...@@ -729,6 +732,7 @@ static int exec_SetTextColor( filter_t *p_filter,
return VLC_EGENERIC; return VLC_EGENERIC;
p_ovl->p_fontstyle->i_font_color = p_params->fontstyle.i_font_color; p_ovl->p_fontstyle->i_font_color = p_params->fontstyle.i_font_color;
p_ovl->p_fontstyle->i_features |= STYLE_HAS_FONT_COLOR;
p_sys->b_updated = p_ovl->b_active; p_sys->b_updated = p_ovl->b_active;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -192,12 +192,8 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -192,12 +192,8 @@ static int CreateFilter( vlc_object_t *p_this )
if( p_sys == NULL ) if( p_sys == NULL )
return VLC_ENOMEM; return VLC_ENOMEM;
p_sys->p_style = text_style_New(); p_sys->p_style = text_style_Create( STYLE_NO_DEFAULTS );
if(likely(p_sys->p_style)) if(unlikely(!p_sys->p_style))
{
text_style_Reset( p_sys->p_style );
}
else
{ {
free(p_sys); free(p_sys);
return VLC_ENOMEM; return VLC_ENOMEM;
......
...@@ -282,10 +282,9 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -282,10 +282,9 @@ static int CreateFilter( vlc_object_t *p_this )
} }
p_sys->psz_marquee[p_sys->i_length] = '\0'; p_sys->psz_marquee[p_sys->i_length] = '\0';
p_sys->p_style = text_style_New(); p_sys->p_style = text_style_Create( STYLE_NO_DEFAULTS );
if( p_sys->p_style == NULL ) if( p_sys->p_style == NULL )
goto error; goto error;
text_style_Reset( p_sys->p_style );
p_sys->i_xoff = var_CreateGetInteger( p_filter, CFG_PREFIX "x" ); p_sys->i_xoff = var_CreateGetInteger( p_filter, CFG_PREFIX "x" );
p_sys->i_yoff = var_CreateGetInteger( p_filter, CFG_PREFIX "y" ); p_sys->i_yoff = var_CreateGetInteger( p_filter, CFG_PREFIX "y" );
......
...@@ -671,6 +671,7 @@ vout_display_PlacePicture ...@@ -671,6 +671,7 @@ vout_display_PlacePicture
vout_display_SendMouseMovedDisplayCoordinates vout_display_SendMouseMovedDisplayCoordinates
xml_Create xml_Create
text_style_Copy text_style_Copy
text_style_Create
text_style_Delete text_style_Delete
text_style_Duplicate text_style_Duplicate
text_style_Merge text_style_Merge
......
...@@ -30,12 +30,20 @@ ...@@ -30,12 +30,20 @@
/* */ /* */
text_style_t *text_style_New( void ) text_style_t *text_style_New( void )
{
return text_style_Create( STYLE_FULLY_SET );
}
text_style_t *text_style_Create( int i_defaults )
{ {
text_style_t *p_style = calloc( 1, sizeof(*p_style) ); text_style_t *p_style = calloc( 1, sizeof(*p_style) );
if( !p_style ) if( !p_style )
return NULL; return NULL;
/* initialize to default text style */ if( i_defaults == STYLE_NO_DEFAULTS )
return p_style;
/* initialize to default text style (FIXME: by flag) */
p_style->psz_fontname = NULL; p_style->psz_fontname = NULL;
p_style->psz_monofontname = NULL; p_style->psz_monofontname = NULL;
p_style->i_features = STYLE_FULLY_SET; p_style->i_features = STYLE_FULLY_SET;
......
...@@ -124,14 +124,13 @@ static subpicture_region_t * vout_OSDEpgText(const char *text, ...@@ -124,14 +124,13 @@ static subpicture_region_t * vout_OSDEpgText(const char *text,
region->i_y = y; region->i_y = y;
/* Set text style */ /* Set text style */
text_style_t *p_style = text_style_New(); text_style_t *p_style = text_style_Create( STYLE_NO_DEFAULTS );
if ( unlikely( !p_style ) ) if ( unlikely( !p_style ) )
{ {
text_segment_Delete( region->p_text ); text_segment_Delete( region->p_text );
subpicture_region_Delete( region ); subpicture_region_Delete( region );
return NULL; return NULL;
} }
text_style_Reset( p_style );
region->p_text->style = p_style; region->p_text->style = p_style;
if (p_style) { if (p_style) {
p_style->f_font_relsize = __MIN( size, 0 ); p_style->f_font_relsize = __MIN( size, 0 );
......
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