Commit 4269635e authored by François Cartegnie's avatar François Cartegnie 🤞

codec: ttml: allow merge with replace

parent 3706edb4
......@@ -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" );
......
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