[vlc-commits] codec: ttml: apply tokenized style refs (fix #19956)

Francois Cartegnie git at videolan.org
Wed Mar 7 14:28:07 CET 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Mar  7 13:35:03 2018 +0100| [f6122dc0dc44e1633112cff8a9e064b757aeb5dd] | committer: Francois Cartegnie

codec: ttml: apply tokenized style refs (fix #19956)

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

 modules/codec/ttml/substtml.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/modules/codec/ttml/substtml.c b/modules/codec/ttml/substtml.c
index 9361098b01..edbc79a955 100644
--- a/modules/codec/ttml/substtml.c
+++ b/modules/codec/ttml/substtml.c
@@ -583,17 +583,36 @@ static void DictionaryMerge( const vlc_dictionary_t *p_src, vlc_dictionary_t *p_
     }
 }
 
-static void DictMergeWithStyleID( ttml_context_t *p_ctx, const char *psz_id,
+static void DictMergeWithStyleID( ttml_context_t *p_ctx, const char *psz_styles,
                                   vlc_dictionary_t *p_dst )
 {
     assert(p_ctx->p_rootnode);
-    if( psz_id && p_ctx->p_rootnode )
+    char *psz_dup;
+    if( psz_styles && p_ctx->p_rootnode && (psz_dup = strdup( psz_styles )) )
     {
-        /* Lookup referenced style 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, false );
+        /* Use temp dict instead of reverse token processing to
+         * resolve styles in specified order */
+        vlc_dictionary_t tempdict;
+        vlc_dictionary_init( &tempdict, 0 );
+
+        char *saveptr;
+        char *psz_id = strtok_r( psz_dup, " ", &saveptr );
+        while( psz_id )
+        {
+            /* Lookup referenced style ID */
+            const tt_node_t *p_node = FindNode( p_ctx->p_rootnode,
+                                                "style", -1, psz_id );
+            if( p_node )
+                DictionaryMerge( &p_node->attr_dict, &tempdict, true );
+
+            psz_id = strtok_r( NULL, " ", &saveptr );
+        }
+
+        if( !vlc_dictionary_is_empty( &tempdict ) )
+            DictionaryMerge( &tempdict, p_dst, false );
+
+        vlc_dictionary_clear( &tempdict, NULL, NULL );
+        free( psz_dup );
     }
 }
 



More information about the vlc-commits mailing list