vlc | branch: master | Francois Cartegnie <fcvlc...@free.fr> | Wed Mar  7 
14:19:47 2018 +0100| [4269635e2eab120d0ab6fd37b4ccfc52b701905e] | committer: 
Francois Cartegnie

codec: ttml: allow merge with replace

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4269635e2eab120d0ab6fd37b4ccfc52b701905e
---

 modules/codec/ttml/substtml.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/modules/codec/ttml/substtml.c b/modules/codec/ttml/substtml.c
index ffdbdbffc6..9361098b01 100644
--- a/modules/codec/ttml/substtml.c
+++ b/modules/codec/ttml/substtml.c
@@ -556,18 +556,29 @@ static void FillTTMLStyle( const char *psz_attr, const 
char *psz_val,
     else FillTextStyle( psz_attr, psz_val, p_ttml_style->font_style );
 }
 
-static void DictionaryMerge( const vlc_dictionary_t *p_src, vlc_dictionary_t 
*p_dst )
+static void DictionaryMerge( const vlc_dictionary_t *p_src, vlc_dictionary_t 
*p_dst,
+                             bool b_override )
 {
     for( int i = 0; i < p_src->i_size; ++i )
     {
         for ( const vlc_dictionary_entry_t* p_entry = p_src->p_entries[i];
                                             p_entry != NULL; p_entry = 
p_entry->p_next )
         {
-            if( ( !strncmp( "tts:", p_entry->psz_key, 4 ) ||
-                  !strncmp( "ttp:", p_entry->psz_key, 4 ) ||
-                  !strcmp( "xml:space", p_entry->psz_key ) ) &&
-                !vlc_dictionary_has_key( p_dst, p_entry->psz_key ) )
-                vlc_dictionary_insert( p_dst, p_entry->psz_key, 
p_entry->p_value );
+            if( !strncmp( "tts:", p_entry->psz_key, 4 ) ||
+                !strncmp( "ttp:", p_entry->psz_key, 4 ) ||
+                !strcmp( "xml:space", p_entry->psz_key ) )
+            {
+                if( vlc_dictionary_has_key( p_dst, p_entry->psz_key ) )
+                {
+                    if( b_override )
+                    {
+                        vlc_dictionary_remove_value_for_key( p_dst, 
p_entry->psz_key, NULL, NULL );
+                        vlc_dictionary_insert( p_dst, p_entry->psz_key, 
p_entry->p_value );
+                    }
+                }
+                else
+                    vlc_dictionary_insert( p_dst, p_entry->psz_key, 
p_entry->p_value );
+            }
         }
     }
 }
@@ -582,7 +593,7 @@ static void DictMergeWithStyleID( ttml_context_t *p_ctx, 
const char *psz_id,
         const tt_node_t *p_node = FindNode( p_ctx->p_rootnode,
                                             "style", -1, psz_id );
         if( p_node )
-            DictionaryMerge( &p_node->attr_dict, p_dst );
+            DictionaryMerge( &p_node->attr_dict, p_dst, false );
     }
 }
 
@@ -597,7 +608,7 @@ static void DictMergeWithRegionID( ttml_context_t *p_ctx, 
const char *psz_id,
         if( !p_regionnode )
             return;
 
-        DictionaryMerge( &p_regionnode->attr_dict, p_dst );
+        DictionaryMerge( &p_regionnode->attr_dict, p_dst, false );
 
         const char *psz_styleid = (const char *)
                 vlc_dictionary_value_for_key( &p_regionnode->attr_dict, 
"style" );
@@ -613,7 +624,7 @@ static void DictMergeWithRegionID( ttml_context_t *p_ctx, 
const char *psz_id,
             const tt_node_t *p_node = (const tt_node_t *) p_child;
             if( !tt_node_NameCompare( p_node->psz_node_name, "style" ) )
             {
-                DictionaryMerge( &p_node->attr_dict, p_dst );
+                DictionaryMerge( &p_node->attr_dict, p_dst, false );
             }
         }
     }
@@ -643,7 +654,7 @@ static ttml_style_t * InheritTTMLStyles( ttml_context_t 
*p_ctx, tt_node_t *p_nod
     /* Merge dics backwards without overwriting */
     for( ; p_node; p_node = p_node->p_parent )
     {
-        DictionaryMerge( &p_node->attr_dict, &merged );
+        DictionaryMerge( &p_node->attr_dict, &merged, false );
 
         const char *psz_styleid = (const char *)
                 vlc_dictionary_value_for_key( &p_node->attr_dict, "style" );

_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to