[vlc-commits] codec: ttml: compute sizes from cells (fix #18347)
Francois Cartegnie
git at videolan.org
Tue May 23 12:06:11 CEST 2017
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue May 23 11:07:16 2017 +0200| [8654ef67a995b21c689b603b0996ad08c4e718e5] | committer: Francois Cartegnie
codec: ttml: compute sizes from cells (fix #18347)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8654ef67a995b21c689b603b0996ad08c4e718e5
---
modules/codec/ttml/substtml.c | 38 +++++++++++++++++++++++++++++++-------
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/modules/codec/ttml/substtml.c b/modules/codec/ttml/substtml.c
index e7be874639..ed7a79e36b 100644
--- a/modules/codec/ttml/substtml.c
+++ b/modules/codec/ttml/substtml.c
@@ -46,6 +46,7 @@
typedef struct
{
text_style_t* font_style;
+ unsigned i_cell_height;
int i_text_align;
int i_direction;
bool b_direction_set;
@@ -104,6 +105,7 @@ static ttml_style_t * ttml_style_New( )
if( unlikely( !p_ttml_style ) )
return NULL;
+ p_ttml_style->i_cell_height = 15;
p_ttml_style->font_style = text_style_Create( STYLE_NO_DEFAULTS );
if( unlikely( !p_ttml_style->font_style ) )
{
@@ -199,7 +201,7 @@ static tt_node_t * FindNode( tt_node_t *p_node, const char *psz_nodename,
}
static void FillTextStyle( const char *psz_attr, const char *psz_val,
- text_style_t *p_text_style )
+ const ttml_style_t *p_ttml_style, text_style_t *p_text_style )
{
if( !strcasecmp ( "tts:fontFamily", psz_attr ) )
{
@@ -216,10 +218,15 @@ static void FillTextStyle( const char *psz_attr, const char *psz_val,
{
char* psz_end = NULL;
float size = us_strtof( psz_val, &psz_end );
- if( *psz_end == '%' )
- p_text_style->f_font_relsize = STYLE_DEFAULT_REL_FONT_SIZE * size / 100.0;
- else
- p_text_style->i_font_size = (int)( size + 0.5 );
+ if( size > 0.0 )
+ {
+ if( *psz_end == 'c' )
+ p_text_style->f_font_relsize = 100.0 * size / p_ttml_style->i_cell_height;
+ else if( *psz_end == '%' )
+ p_text_style->f_font_relsize = size / p_ttml_style->i_cell_height;
+ else
+ p_text_style->i_font_size = (int)( size + 0.5 );
+ }
}
else if( !strcasecmp( "tts:color", psz_attr ) )
{
@@ -334,6 +341,19 @@ static void FillRegionStyle( const char *psz_attr, const char *psz_val,
}
}
+static void FillTTMLStylePrio( const vlc_dictionary_t *p_dict,
+ ttml_style_t *p_ttml_style )
+{
+ void *value = vlc_dictionary_value_for_key( p_dict, "ttp:cellResolution" );
+ if( value != kVLCDictionaryNotFound )
+ {
+ const char *psz_val = value;
+ unsigned w, h;
+ if( sscanf( psz_val, "%u %u", &w, &h) == 2 && w && h )
+ p_ttml_style->i_cell_height = h;
+ }
+}
+
static void FillTTMLStyle( const char *psz_attr, const char *psz_val,
ttml_style_t *p_ttml_style )
{
@@ -396,7 +416,7 @@ static void FillTTMLStyle( const char *psz_attr, const char *psz_val,
{
p_ttml_style->b_preserve_space = !strcmp( "preserve", psz_val );
}
- else FillTextStyle( psz_attr, psz_val, p_ttml_style->font_style );
+ else FillTextStyle( psz_attr, psz_val, p_ttml_style, p_ttml_style->font_style );
}
static void DictionaryMerge( const vlc_dictionary_t *p_src, vlc_dictionary_t *p_dst )
@@ -406,7 +426,9 @@ static void DictionaryMerge( const vlc_dictionary_t *p_src, vlc_dictionary_t *p_
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 ) &&
+ 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 );
}
@@ -459,6 +481,8 @@ static void DictMergeWithRegionID( ttml_context_t *p_ctx, const char *psz_id,
static void DictToTTMLStyle( const vlc_dictionary_t *p_dict, ttml_style_t *p_ttml_style )
{
+ /* Units, defaults, that must be set first to compute styles */
+ FillTTMLStylePrio( p_dict, p_ttml_style );
for( int i = 0; i < p_dict->i_size; ++i )
{
for ( vlc_dictionary_entry_t* p_entry = p_dict->p_entries[i];
More information about the vlc-commits
mailing list