From 4f7ca87dce869899687ba7d867557e0e3b833ef0 Mon Sep 17 00:00:00 2001
From: basOS G <noxelia 4t gmail , com>
Date: Mon, 29 Dec 2008 23:11:05 +0200
Subject: [PATCH] ADD/CLEAN Added text_style_* methods. Cleaned modules

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 sout* functions.
---
 include/vlc_osd.h                                  |   21 ++-
 modules/codec/subtitles/subsass.c                  |  156 ++++++++++----------
 modules/codec/subtitles/subsusf.c                  |  137 +++++++++--------
 modules/gui/fbosd.c                                |    9 +-
 .../video_filter/dynamicoverlay/dynamicoverlay.c   |    4 +-
 .../video_filter/dynamicoverlay/dynamicoverlay.h   |    2 +-
 .../dynamicoverlay/dynamicoverlay_commands.c       |   15 +-
 modules/video_filter/marq.c                        |   11 +-
 modules/video_filter/rss.c                         |   14 +-
 src/libvlccore.sym                                 |    4 +
 src/video_output/video_text.c                      |    4 +-
 src/video_output/vout_subpictures.c                |   60 ++++++++-
 12 files changed, 258 insertions(+), 179 deletions(-)

diff --git a/include/vlc_osd.h b/include/vlc_osd.h
index df855f6..c2b8a18 100644
--- a/include/vlc_osd.h
+++ b/include/vlc_osd.h
@@ -265,8 +265,21 @@ struct text_style_t
 #define STYLE_UNDERLINE   32
 #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 };
+/**
+ * text_style manipulation
+ * text_style_
+ *   New : creates default text style
+ *   Dup : creates new from another allocating storage
+ *   Copy : copies data without allocating
+ *   Delete : Dealocates all data
+ */
+VLC_EXPORT( text_style_t*, text_style_New, ( void ) );
+
+VLC_EXPORT( text_style_t*, text_style_Dup, ( const text_style_t* ) ) ;
+
+VLC_EXPORT( text_style_t*, text_style_Copy, ( text_style_t*, const text_style_t* ) ) ;
+
+VLC_EXPORT( void, text_style_Delete, ( text_style_t* ) ) ;
 
 /**
  * OSD menu button states
@@ -616,7 +629,7 @@ VLC_EXPORT( int, osd_Icon, ( vlc_object_t *, spu_t *, int, int, int, int, int, s
  * \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 p_style Pointer to a struct with text style info (struct is copied)
  * \param i_flags flags for alignment and such
  * \param i_hmargin horizontal margin in pixels
  * \param i_vmargin vertical margin in pixels
@@ -629,7 +642,7 @@ VLC_EXPORT( int, vout_ShowTextRelative, ( vout_thread_t *, int, char *, text_sty
  * \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 p_style Pointer to a struct with text style info (struct is copied )
  * \param i_flags flags for alignment and such
  * \param i_hmargin horizontal margin in pixels
  * \param i_vmargin vertical margin in pixels
diff --git a/modules/codec/subtitles/subsass.c b/modules/codec/subtitles/subsass.c
index e642673..c37c016 100644
--- a/modules/codec/subtitles/subsass.c
+++ b/modules/codec/subtitles/subsass.c
@@ -38,7 +38,7 @@ void ParseSSAString( decoder_t *p_dec,
      * MarginV, Effect, Text */
     decoder_sys_t   *p_sys = p_dec->p_sys;
     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_buffer_sub = NULL;
     char            *psz_style = NULL;
@@ -118,12 +118,12 @@ void ParseSSAString( decoder_t *p_dec,
     for( i = 0; i < p_sys->i_ssa_styles; i++ )
     {
         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 );
 
     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_x = p_sys->i_align ? 20 : 0;
@@ -131,18 +131,18 @@ void ParseSSAString( decoder_t *p_dec,
     }
     else
     {
-        msg_Dbg( p_dec, "style is: %s", p_style->psz_stylename);
-        p_spu->p_region->p_style = &p_style->font_style;
-        p_spu->p_region->i_align = p_style->i_align;
-        if( p_style->i_align & SUBPICTURE_ALIGN_LEFT )
+        msg_Dbg( p_dec, "style is: %s", p_ssa_style->psz_stylename);
+        p_spu->p_region->p_style = text_style_Dup( &p_ssa_style->font_style ) ;
+        p_spu->p_region->i_align = p_ssa_style->i_align;
+        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 )
                     &i_border, &i_outline, &i_shadow, &i_align, &i_margin_l,
                     &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_style->font_style.psz_fontname = strdup( psz_temp_fontname );
-                    p_style->font_style.i_font_size = i_font_size;
+                    p_ssa_style->psz_stylename = strdup( psz_temp_stylename );
+                    p_ssa_style->font_style.psz_fontname = strdup( psz_temp_fontname );
+                    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_color4, &p_style->font_style.i_shadow_color, NULL );
-                    p_style->font_style.i_outline_color = p_style->font_style.i_shadow_color;
-                    p_style->font_style.i_font_alpha = p_style->font_style.i_outline_alpha
-                                                     = p_style->font_style.i_shadow_alpha = 0x00;
-                    p_style->font_style.i_style_flags = 0;
-                    if( i_bold ) p_style->font_style.i_style_flags |= STYLE_BOLD;
-                    if( i_italic ) p_style->font_style.i_style_flags |= STYLE_ITALIC;
+                    ParseColor( psz_temp_color1, &p_ssa_style->font_style.i_font_color, NULL );
+                    ParseColor( psz_temp_color4, &p_ssa_style->font_style.i_shadow_color, NULL );
+                    p_ssa_style->font_style.i_outline_color = p_ssa_style->font_style.i_shadow_color;
+                    p_ssa_style->font_style.i_font_alpha = p_ssa_style->font_style.i_outline_alpha
+                                                     = p_ssa_style->font_style.i_shadow_alpha = 0x00;
+                    p_ssa_style->font_style.i_style_flags = 0;
+                    if( i_bold ) p_ssa_style->font_style.i_style_flags |= STYLE_BOLD;
+                    if( i_italic ) p_ssa_style->font_style.i_style_flags |= STYLE_ITALIC;
 
                     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 )
                     {
-                        p_style->font_style.i_style_flags |= STYLE_BACKGROUND;
-                        p_style->font_style.i_background_color = p_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_style_flags |= STYLE_BACKGROUND;
+                        p_ssa_style->font_style.i_background_color = p_ssa_style->font_style.i_shadow_color;
+                        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_style->font_style.i_outline_width = i_outline;
+                    p_ssa_style->font_style.i_shadow_width = i_shadow;
+                    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 )
-                        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 )
-                        p_style->i_align |= SUBPICTURE_ALIGN_RIGHT;
+                        p_ssa_style->i_align |= SUBPICTURE_ALIGN_RIGHT;
                     if( i_align < 4 )
-                        p_style->i_align |= SUBPICTURE_ALIGN_BOTTOM;
+                        p_ssa_style->i_align |= SUBPICTURE_ALIGN_BOTTOM;
                     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;
-                    p_style->i_margin_v = i_margin_v;
-                    p_style->i_margin_percent_h = 0;
-                    p_style->i_margin_percent_v = 0;
+                    p_ssa_style->i_margin_v = i_margin_v;
+                    p_ssa_style->i_margin_percent_h = 0;
+                    p_ssa_style->i_margin_percent_v = 0;
 
-                    p_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_color = 0xffffff;
+                    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" );
             }
@@ -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_shadow, &i_align, &i_margin_l, &i_margin_r, &i_margin_v ) == 21 )
                 {
-                    ssa_style_t *p_style = malloc( sizeof(ssa_style_t) );
-
-                    p_style->psz_stylename = strdup( psz_temp_stylename );
-                    p_style->font_style.psz_fontname = strdup( psz_temp_fontname );
-                    p_style->font_style.i_font_size = i_font_size;
-                    ParseColor( psz_temp_color1, &p_style->font_style.i_font_color,
-                                &p_style->font_style.i_font_alpha );
-                    ParseColor( psz_temp_color3, &p_style->font_style.i_outline_color,
-                                &p_style->font_style.i_outline_alpha );
-                    ParseColor( psz_temp_color4, &p_style->font_style.i_shadow_color,
-                                &p_style->font_style.i_shadow_alpha );
-
-                    p_style->font_style.i_style_flags = 0;
-                    if( i_bold ) p_style->font_style.i_style_flags |= STYLE_BOLD;
-                    if( i_italic ) p_style->font_style.i_style_flags |= STYLE_ITALIC;
-                    if( i_underline ) p_style->font_style.i_style_flags |= STYLE_UNDERLINE;
-                    if( i_strikeout ) p_style->font_style.i_style_flags |= STYLE_STRIKEOUT;
-                    if( i_border == 1 ) p_style->font_style.i_style_flags |= (STYLE_ITALIC | STYLE_OUTLINE);
+                    ssa_style_t *p_ssa_style = malloc( sizeof(ssa_style_t) );
+
+                    p_ssa_style->psz_stylename = strdup( psz_temp_stylename );
+                    p_ssa_style->font_style.psz_fontname = strdup( psz_temp_fontname );
+                    p_ssa_style->font_style.i_font_size = i_font_size;
+                    ParseColor( psz_temp_color1, &p_ssa_style->font_style.i_font_color,
+                                &p_ssa_style->font_style.i_font_alpha );
+                    ParseColor( psz_temp_color3, &p_ssa_style->font_style.i_outline_color,
+                                &p_ssa_style->font_style.i_outline_alpha );
+                    ParseColor( psz_temp_color4, &p_ssa_style->font_style.i_shadow_color,
+                                &p_ssa_style->font_style.i_shadow_alpha );
+
+                    p_ssa_style->font_style.i_style_flags = 0;
+                    if( i_bold ) p_ssa_style->font_style.i_style_flags |= STYLE_BOLD;
+                    if( i_italic ) p_ssa_style->font_style.i_style_flags |= STYLE_ITALIC;
+                    if( i_underline ) p_ssa_style->font_style.i_style_flags |= STYLE_UNDERLINE;
+                    if( i_strikeout ) p_ssa_style->font_style.i_style_flags |= STYLE_STRIKEOUT;
+                    if( i_border == 1 ) p_ssa_style->font_style.i_style_flags |= (STYLE_ITALIC | STYLE_OUTLINE);
                     else if( i_border == 3 )
                     {
-                        p_style->font_style.i_style_flags |= STYLE_BACKGROUND;
-                        p_style->font_style.i_background_color = p_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_style_flags |= STYLE_BACKGROUND;
+                        p_ssa_style->font_style.i_background_color = p_ssa_style->font_style.i_shadow_color;
+                        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_style->font_style.i_outline_width = ( i_border == 1 ) ? i_outline : 0;
-                    p_style->font_style.i_spacing = i_spacing;
-                    //p_style->font_style.f_angle = f_angle;
+                    p_ssa_style->font_style.i_shadow_width  = ( i_border == 1 ) ? i_shadow : 0;
+                    p_ssa_style->font_style.i_outline_width = ( i_border == 1 ) ? i_outline : 0;
+                    p_ssa_style->font_style.i_spacing = i_spacing;
+                    //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 )
-                        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 )
-                        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 )
-                        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 )
-                        p_style->i_align |= SUBPICTURE_ALIGN_BOTTOM;
-                    p_style->i_margin_h = ( p_style->i_align & SUBPICTURE_ALIGN_RIGHT ) ?
+                        p_ssa_style->i_align |= SUBPICTURE_ALIGN_BOTTOM;
+                    p_ssa_style->i_margin_h = ( p_ssa_style->i_align & SUBPICTURE_ALIGN_RIGHT ) ?
                                             i_margin_r : i_margin_l;
-                    p_style->i_margin_v = i_margin_v;
-                    p_style->i_margin_percent_h = 0;
-                    p_style->i_margin_percent_v = 0;
+                    p_ssa_style->i_margin_v = i_margin_v;
+                    p_ssa_style->i_margin_percent_h = 0;
+                    p_ssa_style->i_margin_percent_v = 0;
 
-                    p_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_color = 0xffffff;
+                    p_ssa_style->font_style.i_karaoke_background_alpha = 0xff;
 
                     /*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" );
             }
diff --git a/modules/codec/subtitles/subsusf.c b/modules/codec/subtitles/subsusf.c
index ab7756b..52325bb 100644
--- a/modules/codec/subtitles/subsusf.c
+++ b/modules/codec/subtitles/subsusf.c
@@ -144,6 +144,7 @@ static void CloseDecoder( vlc_object_t *p_this )
                 continue;
 
             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] );
         }
@@ -259,7 +260,7 @@ static char *GrabAttributeValue( const char *psz_attribute,
 
 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 );
 
     if( psz_style )
@@ -269,11 +270,11 @@ static ssa_style_t *ParseStyle( decoder_sys_t *p_sys, char *psz_subtitle )
         for( i = 0; i < p_sys->i_ssa_styles; i++ )
         {
             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 );
     }
-    return p_style;
+    return p_ssa_style;
 }
 
 static int ParsePositionAttributeList( char *psz_subtitle, int *i_align,
@@ -388,7 +389,7 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec,
 
     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_html = strndup( psz_subtitle, i_len );
@@ -398,34 +399,36 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec,
             return NULL;
         }
 
-        p_style = ParseStyle( p_sys, p_text_region->psz_html );
-        if( !p_style )
+        p_ssa_style = ParseStyle( p_sys, p_text_region->psz_html );
+        if( !p_ssa_style )
         {
             int i;
 
             for( i = 0; i < p_sys->i_ssa_styles; i++ )
             {
                 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->i_align = p_style->i_align;
+            /* basos g: region->p_style is freed by the vout. Decoder may live shorter.
+            */
+            p_text_region->p_style = text_style_Dup( &p_ssa_style->font_style ) ;
+            p_text_region->i_align = p_ssa_style->i_align;
 
             /* TODO: Setup % based offsets properly, without adversely affecting
              *       everything else in vlc. Will address with separate patch,
              *       to prevent this one being any more complicated.
 
-                     * p_style->i_margin_percent_h;
-                     * p_style->i_margin_percent_v;
+                     * p_ssa_style->i_margin_percent_h;
+                     * p_ssa_style->i_margin_percent_v;
              */
-            p_text_region->i_x         = p_style->i_margin_h;
-            p_text_region->i_y         = p_style->i_margin_v;
+            p_text_region->i_x         = p_ssa_style->i_margin_h;
+            p_text_region->i_y         = p_ssa_style->i_margin_v;
 
         }
         else
@@ -559,7 +562,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     char *psz_node;
-    ssa_style_t *p_style = NULL;
+    ssa_style_t *p_ssa_style = NULL;
     int i_style_level = 0;
     int i_metadata_level = 0;
 
@@ -592,9 +595,9 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                     case 2:
                         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--;
                         }
                         break;
@@ -639,8 +642,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                 {
                     i_style_level++;
 
-                    p_style = calloc( 1, sizeof(ssa_style_t) );
-                    if( ! p_style )
+                    p_ssa_style = calloc( 1, sizeof(ssa_style_t) );
+                    if( ! p_ssa_style )
                     {
                         free( psz_node );
                         return;
@@ -657,9 +660,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];
 
-                            memcpy( p_style, p_default_style, sizeof( ssa_style_t ) );
-                            p_style->font_style.psz_fontname = strdup( p_style->font_style.psz_fontname );
-                            p_style->psz_stylename = NULL;
+                            memcpy( p_ssa_style, p_default_style, sizeof( ssa_style_t ) );
+                            //FIXME: Make font_style a pointer. Actually we double copy some data here,
+                            //   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;
                         }
                     }
 
@@ -671,7 +676,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                         if( psz_name && psz_value )
                         {
                             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_value );
@@ -688,8 +693,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                         {
                             if( !strcasecmp( "face", psz_name ) )
                             {
-                                free( p_style->font_style.psz_fontname );
-                                p_style->font_style.psz_fontname = strdup( psz_value );
+                                free( p_ssa_style->font_style.psz_fontname );
+                                p_ssa_style->font_style.psz_fontname = strdup( psz_value );
                             }
                             else if( !strcasecmp( "size", psz_name ) )
                             {
@@ -698,44 +703,44 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                                     int i_value = atoi( psz_value );
 
                                     if( ( i_value >= -5 ) && ( i_value <= 5 ) )
-                                        p_style->font_style.i_font_size  +=
-                                            ( i_value * p_style->font_style.i_font_size ) / 10;
+                                        p_ssa_style->font_style.i_font_size  +=
+                                            ( i_value * p_ssa_style->font_style.i_font_size ) / 10;
                                     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 )
-                                        p_style->font_style.i_font_size  = i_value;
+                                        p_ssa_style->font_style.i_font_size  = i_value;
                                 }
                                 else
-                                    p_style->font_style.i_font_size  = atoi( psz_value );
+                                    p_ssa_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;
+                                    p_ssa_style->font_style.i_style_flags |= STYLE_ITALIC;
                                 else
-                                    p_style->font_style.i_style_flags &= ~STYLE_ITALIC;
+                                    p_ssa_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;
+                                    p_ssa_style->font_style.i_style_flags |= STYLE_BOLD;
                                 else
-                                    p_style->font_style.i_style_flags &= ~STYLE_BOLD;
+                                    p_ssa_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;
+                                    p_ssa_style->font_style.i_style_flags |= STYLE_UNDERLINE;
                                 else
-                                    p_style->font_style.i_style_flags &= ~STYLE_UNDERLINE;
+                                    p_ssa_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);
-                                    p_style->font_style.i_font_alpha = (col >> 24) & 0xff;
+                                    p_ssa_style->font_style.i_font_color = (col & 0x00ffffff);
+                                    p_ssa_style->font_style.i_font_alpha = (col >> 24) & 0xff;
                                 }
                             }
                             else if( !strcasecmp( "outline-color", psz_name ) )
@@ -743,39 +748,39 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                                 if( *psz_value == '#' )
                                 {
                                     unsigned long col = strtol(psz_value+1, NULL, 16);
-                                    p_style->font_style.i_outline_color = (col & 0x00ffffff);
-                                    p_style->font_style.i_outline_alpha = (col >> 24) & 0xff;
+                                    p_ssa_style->font_style.i_outline_color = (col & 0x00ffffff);
+                                    p_ssa_style->font_style.i_outline_alpha = (col >> 24) & 0xff;
                                 }
                             }
                             else if( !strcasecmp( "outline-level", psz_name ) )
                             {
-                                p_style->font_style.i_outline_width = atoi( psz_value );
+                                p_ssa_style->font_style.i_outline_width = atoi( psz_value );
                             }
                             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);
-                                    p_style->font_style.i_shadow_alpha = (col >> 24) & 0xff;
+                                    p_ssa_style->font_style.i_shadow_color = (col & 0x00ffffff);
+                                    p_ssa_style->font_style.i_shadow_alpha = (col >> 24) & 0xff;
                                 }
                             }
                             else if( !strcasecmp( "shadow-level", psz_name ) )
                             {
-                                p_style->font_style.i_shadow_width = atoi( psz_value );
+                                p_ssa_style->font_style.i_shadow_width = atoi( psz_value );
                             }
                             else if( !strcasecmp( "back-color", psz_name ) )
                             {
                                 if( *psz_value == '#' )
                                 {
                                     unsigned long col = strtol(psz_value+1, NULL, 16);
-                                    p_style->font_style.i_karaoke_background_color = (col & 0x00ffffff);
-                                    p_style->font_style.i_karaoke_background_alpha = (col >> 24) & 0xff;
+                                    p_ssa_style->font_style.i_karaoke_background_color = (col & 0x00ffffff);
+                                    p_ssa_style->font_style.i_karaoke_background_alpha = (col >> 24) & 0xff;
                                 }
                             }
                             else if( !strcasecmp( "spacing", psz_name ) )
                             {
-                                p_style->font_style.i_spacing = atoi( psz_value );
+                                p_ssa_style->font_style.i_spacing = atoi( psz_value );
                             }
                         }
                         free( psz_name );
@@ -794,48 +799,48 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                             if( !strcasecmp( "alignment", psz_name ) )
                             {
                                 if( !strcasecmp( "TopLeft", psz_value ) )
-                                    p_style->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_LEFT;
+                                    p_ssa_style->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_LEFT;
                                 else if( !strcasecmp( "TopCenter", psz_value ) )
-                                    p_style->i_align = SUBPICTURE_ALIGN_TOP;
+                                    p_ssa_style->i_align = SUBPICTURE_ALIGN_TOP;
                                 else if( !strcasecmp( "TopRight", psz_value ) )
-                                    p_style->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_RIGHT;
+                                    p_ssa_style->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_RIGHT;
                                 else if( !strcasecmp( "MiddleLeft", psz_value ) )
-                                    p_style->i_align = SUBPICTURE_ALIGN_LEFT;
+                                    p_ssa_style->i_align = SUBPICTURE_ALIGN_LEFT;
                                 else if( !strcasecmp( "MiddleCenter", psz_value ) )
-                                    p_style->i_align = 0;
+                                    p_ssa_style->i_align = 0;
                                 else if( !strcasecmp( "MiddleRight", psz_value ) )
-                                    p_style->i_align = SUBPICTURE_ALIGN_RIGHT;
+                                    p_ssa_style->i_align = SUBPICTURE_ALIGN_RIGHT;
                                 else if( !strcasecmp( "BottomLeft", psz_value ) )
-                                    p_style->i_align = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_LEFT;
+                                    p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_LEFT;
                                 else if( !strcasecmp( "BottomCenter", psz_value ) )
-                                    p_style->i_align = SUBPICTURE_ALIGN_BOTTOM;
+                                    p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM;
                                 else if( !strcasecmp( "BottomRight", psz_value ) )
-                                    p_style->i_align = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_RIGHT;
+                                    p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_RIGHT;
                             }
                             else if( !strcasecmp( "horizontal-margin", psz_name ) )
                             {
                                 if( strchr( psz_value, '%' ) )
                                 {
-                                    p_style->i_margin_h = 0;
-                                    p_style->i_margin_percent_h = atoi( psz_value );
+                                    p_ssa_style->i_margin_h = 0;
+                                    p_ssa_style->i_margin_percent_h = atoi( psz_value );
                                 }
                                 else
                                 {
-                                    p_style->i_margin_h = atoi( psz_value );
-                                    p_style->i_margin_percent_h = 0;
+                                    p_ssa_style->i_margin_h = atoi( psz_value );
+                                    p_ssa_style->i_margin_percent_h = 0;
                                 }
                             }
                             else if( !strcasecmp( "vertical-margin", psz_name ) )
                             {
                                 if( strchr( psz_value, '%' ) )
                                 {
-                                    p_style->i_margin_v = 0;
-                                    p_style->i_margin_percent_v = atoi( psz_value );
+                                    p_ssa_style->i_margin_v = 0;
+                                    p_ssa_style->i_margin_percent_v = atoi( psz_value );
                                 }
                                 else
                                 {
-                                    p_style->i_margin_v = atoi( psz_value );
-                                    p_style->i_margin_percent_v = 0;
+                                    p_ssa_style->i_margin_v = atoi( psz_value );
+                                    p_ssa_style->i_margin_percent_v = 0;
                                 }
                             }
                         }
@@ -848,7 +853,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                 break;
         }
     }
-    free( p_style );
+    free( p_ssa_style );
 }
 
 
diff --git a/modules/gui/fbosd.c b/modules/gui/fbosd.c
index 002c441..b697642 100644
--- a/modules/gui/fbosd.c
+++ b/modules/gui/fbosd.c
@@ -311,20 +311,19 @@ static int Create( vlc_object_t *p_this )
         return VLC_ENOMEM;
     memset( p_sys, 0, sizeof(intf_sys_t) );
 
-    p_sys->p_style = malloc( sizeof( text_style_t ) );
+    p_sys->p_style = text_style_New() ;
     if( !p_sys->p_style )
     {
         free( p_intf->p_sys );
         return VLC_ENOMEM;
     }
-    vlc_memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ) );
 
     p_intf->pf_run = Run;
 
     p_sys->p_image = image_HandlerCreate( p_this );
     if( !p_sys->p_image )
     {
-        free( p_intf->p_sys->p_style );
+        text_style_Delete( p_intf->p_sys->p_style );
         free( p_intf->p_sys );
         return VLC_ENOMEM;
     }
@@ -521,7 +520,7 @@ static void Destroy( vlc_object_t *p_this )
     if( p_sys->p_overlay )
         picture_Release( p_sys->p_overlay );
 
-    free( p_sys->p_style );
+    text_style_Delete( p_sys->p_style ) ;
     free( p_sys );
 }
 
@@ -866,7 +865,7 @@ static picture_t *RenderText( intf_thread_t *p_intf, const char *psz_string,
             subpicture_region_Delete( p_region );
             return NULL;
         }
-        p_region->p_style = p_style;
+        p_region->p_style = text_style_Dup( p_style );
         p_region->i_align = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
 
         if( p_sys->p_text->pf_render_text )
diff --git a/modules/video_filter/dynamicoverlay/dynamicoverlay.c b/modules/video_filter/dynamicoverlay/dynamicoverlay.c
index c015c4c..8808836 100644
--- a/modules/video_filter/dynamicoverlay/dynamicoverlay.c
+++ b/modules/video_filter/dynamicoverlay/dynamicoverlay.c
@@ -358,9 +358,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         if( p_overlay->format.i_chroma == VLC_FOURCC('T','E','X','T') )
         {
             p_region->psz_text = strdup( p_overlay->data.p_text );
-            p_region->p_style = malloc( sizeof(struct text_style_t) );
-            if( p_region->p_style )
-                *p_region->p_style = p_overlay->fontstyle;
+            p_region->p_style = text_style_Dup( p_overlay->p_fontstyle ) ;
         }
         else
         {
diff --git a/modules/video_filter/dynamicoverlay/dynamicoverlay.h b/modules/video_filter/dynamicoverlay/dynamicoverlay.h
index 8eb500a..86caa18 100644
--- a/modules/video_filter/dynamicoverlay/dynamicoverlay.h
+++ b/modules/video_filter/dynamicoverlay/dynamicoverlay.h
@@ -122,7 +122,7 @@ typedef struct overlay_t
     bool b_active;
 
     video_format_t format;
-    struct text_style_t fontstyle;
+    struct text_style_t* p_fontstyle;
     union {
         picture_t *p_pic;
         char *p_text;
diff --git a/modules/video_filter/dynamicoverlay/dynamicoverlay_commands.c b/modules/video_filter/dynamicoverlay/dynamicoverlay_commands.c
index 3f3f5b8..47a1690 100644
--- a/modules/video_filter/dynamicoverlay/dynamicoverlay_commands.c
+++ b/modules/video_filter/dynamicoverlay/dynamicoverlay_commands.c
@@ -58,7 +58,7 @@ overlay_t *OverlayCreate( void )
     p_ovl->b_active = false;
     vout_InitFormat( &p_ovl->format, VLC_FOURCC( '\0','\0','\0','\0') , 0, 0,
                      VOUT_ASPECT_FACTOR );
-    memcpy( &p_ovl->fontstyle, &default_text_style, sizeof(struct text_style_t) );
+    p_ovl->p_fontstyle = text_style_New() ;
     p_ovl->data.p_text = NULL;
 
     return p_ovl;
@@ -68,6 +68,7 @@ int OverlayDestroy( overlay_t *p_ovl )
 {
     if( p_ovl->data.p_text != NULL )
         free( p_ovl->data.p_text );
+    text_style_Delete( p_ovl->p_fontstyle ) ;
 
     return VLC_SUCCESS;
 }
@@ -636,7 +637,7 @@ static int exec_GetTextAlpha( filter_t *p_filter,
     if( p_ovl == NULL )
         return VLC_EGENERIC;
 
-    p_results->fontstyle.i_font_alpha = p_ovl->fontstyle.i_font_alpha;
+    p_results->fontstyle.i_font_alpha = p_ovl->p_fontstyle->i_font_alpha;
     return VLC_SUCCESS;
 }
 
@@ -649,7 +650,7 @@ static int exec_GetTextColor( filter_t *p_filter,
     if( p_ovl == NULL )
         return VLC_EGENERIC;
 
-    p_results->fontstyle.i_font_color = p_ovl->fontstyle.i_font_color;
+    p_results->fontstyle.i_font_color = p_ovl->p_fontstyle->i_font_color;
     return VLC_SUCCESS;
 }
 
@@ -662,7 +663,7 @@ static int exec_GetTextSize( filter_t *p_filter,
     if( p_ovl == NULL )
         return VLC_EGENERIC;
 
-    p_results->fontstyle.i_font_size = p_ovl->fontstyle.i_font_size;
+    p_results->fontstyle.i_font_size = p_ovl->p_fontstyle->i_font_size;
     return VLC_SUCCESS;
 }
 
@@ -725,7 +726,7 @@ static int exec_SetTextAlpha( filter_t *p_filter,
     if( p_ovl == NULL )
         return VLC_EGENERIC;
 
-    p_ovl->fontstyle.i_font_alpha = p_params->fontstyle.i_font_alpha;
+    p_ovl->p_fontstyle->i_font_alpha = p_params->fontstyle.i_font_alpha;
     p_sys->b_updated = p_ovl->b_active;
     return VLC_SUCCESS;
 }
@@ -741,7 +742,7 @@ static int exec_SetTextColor( filter_t *p_filter,
     if( p_ovl == NULL )
         return VLC_EGENERIC;
 
-    p_ovl->fontstyle.i_font_color = p_params->fontstyle.i_font_color;
+    p_ovl->p_fontstyle->i_font_color = p_params->fontstyle.i_font_color;
     p_sys->b_updated = p_ovl->b_active;
     return VLC_SUCCESS;
 }
@@ -757,7 +758,7 @@ static int exec_SetTextSize( filter_t *p_filter,
     if( p_ovl == NULL )
         return VLC_EGENERIC;
 
-    p_ovl->fontstyle.i_font_size = p_params->fontstyle.i_font_size;
+    p_ovl->p_fontstyle->i_font_size = p_params->fontstyle.i_font_size;
     p_sys->b_updated = p_ovl->b_active;
     return VLC_SUCCESS;
 }
diff --git a/modules/video_filter/marq.c b/modules/video_filter/marq.c
index 94b3f91..4a2f710 100644
--- a/modules/video_filter/marq.c
+++ b/modules/video_filter/marq.c
@@ -200,9 +200,8 @@ static int CreateFilter( vlc_object_t *p_this )
     p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
     if( p_sys == NULL )
         return VLC_ENOMEM;
-
-    p_sys->p_style = malloc( sizeof( text_style_t ) );
-    memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ) );
+    /* NOTE: this sub filter could be a nice guide on how to use text_style_* functions */
+    p_sys->p_style = text_style_New() ;
 
     config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
                        p_filter->p_cfg );
@@ -239,7 +238,7 @@ static void DestroyFilter( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    free( p_sys->p_style );
+    text_style_Delete( p_sys->p_style );
     free( p_sys->psz_marquee );
 
     /* Delete the marquee variables */
@@ -332,7 +331,9 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
     p_spu->p_region->i_x = p_sys->i_xoff;
     p_spu->p_region->i_y = p_sys->i_yoff;
 
-    p_spu->p_region->p_style = p_sys->p_style;
+
+    //basos:: we should copy here as spu manages deletion from now and on
+    p_spu->p_region->p_style = text_style_Dup( p_sys->p_style ) ;
 
 out:
     vlc_object_unlock( p_filter );
diff --git a/modules/video_filter/rss.c b/modules/video_filter/rss.c
index 8eef177..ce0f5ff 100644
--- a/modules/video_filter/rss.c
+++ b/modules/video_filter/rss.c
@@ -272,7 +272,7 @@ static int CreateFilter( vlc_object_t *p_this )
     }
     p_sys->psz_marquee[p_sys->i_length] = '\0';
 
-    p_sys->p_style = malloc( sizeof( text_style_t ));
+    p_sys->p_style = text_style_New() ;
     if( p_sys->p_style == NULL )
     {
         free( p_sys->psz_marquee );
@@ -282,7 +282,6 @@ static int CreateFilter( vlc_object_t *p_this )
         free( p_sys );
         return VLC_ENOMEM;
     }
-    memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ));
 
     p_sys->i_xoff = var_CreateGetInteger( p_filter, CFG_PREFIX "x" );
     p_sys->i_yoff = var_CreateGetInteger( p_filter, CFG_PREFIX "y" );
@@ -299,7 +298,7 @@ static int CreateFilter( vlc_object_t *p_this )
     if( FetchRSS( p_filter ) )
     {
         msg_Err( p_filter, "failed while fetching RSS ... too bad" );
-        free( p_sys->p_style );
+        text_style_Delete( p_sys->p_style );
         free( p_sys->psz_marquee );
         vlc_mutex_unlock( &p_sys->lock );
         vlc_mutex_destroy( &p_sys->lock );
@@ -311,7 +310,7 @@ static int CreateFilter( vlc_object_t *p_this )
 
     if( p_sys->i_feeds == 0 )
     {
-        free( p_sys->p_style );
+        text_style_Delete( p_sys->p_style );
         free( p_sys->psz_marquee );
         vlc_mutex_unlock( &p_sys->lock );
         vlc_mutex_destroy( &p_sys->lock );
@@ -323,7 +322,7 @@ static int CreateFilter( vlc_object_t *p_this )
     {
         if( p_sys->p_feeds[i_feed].i_items == 0 )
         {
-            free( p_sys->p_style );
+            text_style_Delete( p_sys->p_style );
             free( p_sys->psz_marquee );
             FreeRSS( p_filter );
             vlc_mutex_unlock( &p_sys->lock );
@@ -351,7 +350,7 @@ static void DestroyFilter( vlc_object_t *p_this )
 
     vlc_mutex_lock( &p_sys->lock );
 
-    free( p_sys->p_style );
+    text_style_Delete( p_sys->p_style );
     free( p_sys->psz_marquee );
     free( p_sys->psz_urls );
     FreeRSS( p_filter );
@@ -530,7 +529,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         p_spu->b_absolute = false;
     }
 
-    p_spu->p_region->p_style = p_sys->p_style;
+    // basos:: we should copy here as style mem is managed by spu from now and on
+    p_spu->p_region->p_style = text_style_Dup( p_sys->p_style );
 
     if( p_feed->p_pic )
     {
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 1dd9549..8367f28 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -548,3 +548,7 @@ vout_UnlinkPicture
 vout_vaControlDefault
 __xml_Create
 xml_Delete
+text_style_New
+text_style_Copy
+text_style_Dup
+text_style_Delete
diff --git a/src/video_output/video_text.c b/src/video_output/video_text.c
index d0e7a0a..0c55a4c 100644
--- a/src/video_output/video_text.c
+++ b/src/video_output/video_text.c
@@ -73,10 +73,8 @@ int vout_ShowTextAbsolute( vout_thread_t *p_vout, int i_channel,
                            int i_flags, int i_hmargin, int i_vmargin,
                            mtime_t i_start, mtime_t i_stop )
 {
-    (void)p_style;
     subpicture_t *p_spu;
     video_format_t fmt;
-    /* (void)p_style; FIXME: <-- why ask for this if it's unused?!? */
 
     if( !psz_string ) return VLC_EGENERIC;
 
@@ -110,6 +108,8 @@ int vout_ShowTextAbsolute( vout_thread_t *p_vout, int i_channel,
     p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK;
     p_spu->p_region->i_x = i_hmargin;
     p_spu->p_region->i_y = i_vmargin;
+    if ( p_style )
+        p_spu->p_region->p_style = text_style_Dup( p_style );
 
     spu_DisplaySubpicture( p_vout->p_spu, p_spu );
 
diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index d20d4e0..6117281 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -52,6 +52,12 @@
 #define VLC_FOURCC_RGBA VLC_FOURCC('R','G','B','A')
 #define VLC_FOURCC_TEXT VLC_FOURCC('T','E','X','T')
 
+/* Default text style
+   DONT memcpy. Use p_style = text_style_New( ) to allocate default text style
+   and text_style_Delete( p_style ) to deallocate */
+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 };
+
 /* */
 typedef struct
 {
@@ -330,6 +336,55 @@ void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, bool b_attach )
 }
 
 /**
+ * Initialize/Copy/Delete/Dupicate a text style struct managing all the memory stuff
+ */
+text_style_t* text_style_New( )
+{
+  text_style_t* p_style_out =
+       calloc(1, sizeof( text_style_t ) ) ;
+  if ( !p_style_out )
+      return NULL ;
+  // initialize to default text style
+  text_style_Copy( p_style_out, &default_text_style ) ;
+  return p_style_out ;
+}
+
+text_style_t* text_style_Copy( text_style_t* p_style_out, const text_style_t* p_style_in )
+{
+  if ( p_style_in )
+  {
+      /* each text_style struct owns the psz_fontname, so clear old, if any, fontname */
+      if ( p_style_out->psz_fontname )
+          free( p_style_out->psz_fontname ) ;
+      memcpy( p_style_out, p_style_in, sizeof( text_style_t ) );
+      if ( p_style_out->psz_fontname )
+          p_style_out->psz_fontname = strdup( p_style_out->psz_fontname ) ;
+  }
+  return p_style_out ;
+}
+
+text_style_t* text_style_Dup( const text_style_t* p_style_in )
+{
+  if ( !p_style_in )
+      return NULL ;
+  text_style_t* p_style_out =
+       calloc( 1, sizeof( text_style_t ) ) ;
+  if ( !p_style_out )
+      return NULL ;
+  text_style_Copy( p_style_out, p_style_in ) ;
+  return p_style_out ;
+}
+
+void text_style_Delete( text_style_t* p_style )
+{
+  if ( !p_style )
+      return ;
+  if ( p_style->psz_fontname )
+      free( p_style->psz_fontname ) ;
+  free( p_style ) ;
+}
+
+/**
  * Display a subpicture
  *
  * Remove the reservation flag of a subpicture, which will cause it to be
@@ -776,7 +831,10 @@ void subpicture_region_Delete( subpicture_region_t *p_region )
 
     free( p_region->psz_text );
     free( p_region->psz_html );
-    //free( p_region->p_style ); FIXME --fenrir plugin does not allocate the memory for it. I think it might lead to segfault, video renderer can live longer than the decoder
+    // basos: p_region owns a copy of p_style (with text_style_Dup)
+    if ( p_region->p_style ) {
+        text_style_Delete( p_region->p_style ) ;
+    }
     free( p_region );
 }
 
-- 
1.5.6.5

