[vlc-commits] codec: webvtt: fix regionless cues position
vlc/vlc-3.0 | branch: master | Francois Cartegnie| Fri Jan 19 16:18:48 2018 +0100| [2e19bb27ddc25cc5b78ae9c7bff07f60c120741b] | committer: Francois Cartegnie codec: webvtt: fix regionless cues position somehow limited (cherry picked from commit 8c861a3c4913da41fda7bab1980d445e93d03a5f) > http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=2e19bb27ddc25cc5b78ae9c7bff07f60c120741b --- modules/codec/webvtt/subsvtt.c | 133 + 1 file changed, 121 insertions(+), 12 deletions(-) diff --git a/modules/codec/webvtt/subsvtt.c b/modules/codec/webvtt/subsvtt.c index e1a9fdfceb..df0633a100 100644 --- a/modules/codec/webvtt/subsvtt.c +++ b/modules/codec/webvtt/subsvtt.c @@ -86,7 +86,7 @@ typedef struct enum webvtt_align_e linealign; float position; enum webvtt_align_e positionalign; -float size; +webvtt_auto_value_t size; enum webvtt_align_e align; } webvtt_cue_settings_t; @@ -203,6 +203,89 @@ static bool parse_percent_tuple( const char *psz, float *x, float *y ) return false; } +typedef struct +{ +float x,y,w,h; +} webvtt_rect_t; + +static void webvtt_get_cueboxrect( const webvtt_cue_settings_t *p_settings, + webvtt_rect_t *p_rect ) +{ +float extent; +float indent_anchor_position; +enum webvtt_align_e alignment_on_indent_anchor; + +/* Position of top or left depending on writing direction */ +float line_offset; +if( !p_settings->line.b_auto ) /* numerical */ +{ +if( p_settings->b_snap_to_lines ) /* line # */ +line_offset = p_settings->line.value / + (WEBVTT_REGION_LINES_COUNT * WEBVTT_LINE_TO_HEIGHT_RATIO); +else +line_offset = p_settings->line.value; +} +else line_offset = 1.0; + +if( p_settings->position < 0 ) +{ +if( p_settings->align == WEBVTT_ALIGN_LEFT ) +indent_anchor_position = 0; +else if( p_settings->align == WEBVTT_ALIGN_RIGHT ) +indent_anchor_position = 1.0; +else +indent_anchor_position = 0.5; /* center */ +} +else indent_anchor_position = p_settings->position; + +if( p_settings->positionalign == WEBVTT_ALIGN_AUTO ) +{ +/* text align */ +if( p_settings->align == WEBVTT_ALIGN_LEFT || +p_settings->align == WEBVTT_ALIGN_RIGHT ) +alignment_on_indent_anchor = p_settings->align; +else +alignment_on_indent_anchor = WEBVTT_ALIGN_CENTER; +} +else alignment_on_indent_anchor = p_settings->positionalign; + +if( !p_settings->size.b_auto ) +extent = p_settings->size.value; +else +extent = 0.0; + +/* apply */ + +/* we need 100% or size for inner_align to work on writing direction */ +if( p_settings->vertical == WEBVTT_ALIGN_AUTO ) /* Horizontal text */ +{ +p_rect->y = line_offset > 0 ? line_offset : 1.0 + line_offset; +p_rect->w = (extent) ? extent : 1.0; +if( indent_anchor_position > 0 && +(alignment_on_indent_anchor == WEBVTT_ALIGN_LEFT || + alignment_on_indent_anchor == WEBVTT_ALIGN_START) ) +{ +p_rect->x = indent_anchor_position; +p_rect->w -= p_rect->x; +} +} +else /* Vertical text */ +{ +if( p_settings->vertical == WEBVTT_ALIGN_LEFT ) +p_rect->x = line_offset > 0 ? 1.0 - line_offset : -line_offset; +else +p_rect->x = line_offset > 0 ? line_offset : 1.0 + line_offset; +p_rect->y = (extent) ? extent : 1.0; + +if( indent_anchor_position > 0 && +alignment_on_indent_anchor == WEBVTT_ALIGN_START ) +{ +p_rect->y = indent_anchor_position; +p_rect->h -= p_rect->y; +} +} +} + static void webvtt_cue_settings_ParseTuple( webvtt_cue_settings_t *p_settings, const char *psz_key, const char *psz_value ) { @@ -217,6 +300,7 @@ static void webvtt_cue_settings_ParseTuple( webvtt_cue_settings_t *p_settings, } else if( !strcmp( psz_key, "line" ) ) { +p_settings->line.b_auto = false; if( strchr( psz_value, '%' ) ) { parse_percent( psz_value, _settings->line.value ); @@ -224,7 +308,6 @@ static void webvtt_cue_settings_ParseTuple( webvtt_cue_settings_t *p_settings, } else p_settings->line.value = us_strtof( psz_value, NULL ); - /* else auto */ const char *psz_align = strchr( psz_value, ',' ); @@ -256,7 +339,8 @@ static void webvtt_cue_settings_ParseTuple( webvtt_cue_settings_t *p_settings, } else if( !strcmp( psz_key, "size" ) ) { -parse_percent( psz_value, _settings->size ); +parse_percent( psz_value, _settings->size.value ); +p_settings->size.b_auto = false; } else if( !strcmp(
[vlc-commits] codec: webvtt: fix regionless cues position
vlc | branch: master | Francois Cartegnie| Fri Jan 19 16:18:48 2018 +0100| [8c861a3c4913da41fda7bab1980d445e93d03a5f] | committer: Francois Cartegnie codec: webvtt: fix regionless cues position somehow limited > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8c861a3c4913da41fda7bab1980d445e93d03a5f --- modules/codec/webvtt/subsvtt.c | 133 + 1 file changed, 121 insertions(+), 12 deletions(-) diff --git a/modules/codec/webvtt/subsvtt.c b/modules/codec/webvtt/subsvtt.c index bb0cb60c34..d22d80d94a 100644 --- a/modules/codec/webvtt/subsvtt.c +++ b/modules/codec/webvtt/subsvtt.c @@ -86,7 +86,7 @@ typedef struct enum webvtt_align_e linealign; float position; enum webvtt_align_e positionalign; -float size; +webvtt_auto_value_t size; enum webvtt_align_e align; } webvtt_cue_settings_t; @@ -203,6 +203,89 @@ static bool parse_percent_tuple( const char *psz, float *x, float *y ) return false; } +typedef struct +{ +float x,y,w,h; +} webvtt_rect_t; + +static void webvtt_get_cueboxrect( const webvtt_cue_settings_t *p_settings, + webvtt_rect_t *p_rect ) +{ +float extent; +float indent_anchor_position; +enum webvtt_align_e alignment_on_indent_anchor; + +/* Position of top or left depending on writing direction */ +float line_offset; +if( !p_settings->line.b_auto ) /* numerical */ +{ +if( p_settings->b_snap_to_lines ) /* line # */ +line_offset = p_settings->line.value / + (WEBVTT_REGION_LINES_COUNT * WEBVTT_LINE_TO_HEIGHT_RATIO); +else +line_offset = p_settings->line.value; +} +else line_offset = 1.0; + +if( p_settings->position < 0 ) +{ +if( p_settings->align == WEBVTT_ALIGN_LEFT ) +indent_anchor_position = 0; +else if( p_settings->align == WEBVTT_ALIGN_RIGHT ) +indent_anchor_position = 1.0; +else +indent_anchor_position = 0.5; /* center */ +} +else indent_anchor_position = p_settings->position; + +if( p_settings->positionalign == WEBVTT_ALIGN_AUTO ) +{ +/* text align */ +if( p_settings->align == WEBVTT_ALIGN_LEFT || +p_settings->align == WEBVTT_ALIGN_RIGHT ) +alignment_on_indent_anchor = p_settings->align; +else +alignment_on_indent_anchor = WEBVTT_ALIGN_CENTER; +} +else alignment_on_indent_anchor = p_settings->positionalign; + +if( !p_settings->size.b_auto ) +extent = p_settings->size.value; +else +extent = 0.0; + +/* apply */ + +/* we need 100% or size for inner_align to work on writing direction */ +if( p_settings->vertical == WEBVTT_ALIGN_AUTO ) /* Horizontal text */ +{ +p_rect->y = line_offset > 0 ? line_offset : 1.0 + line_offset; +p_rect->w = (extent) ? extent : 1.0; +if( indent_anchor_position > 0 && +(alignment_on_indent_anchor == WEBVTT_ALIGN_LEFT || + alignment_on_indent_anchor == WEBVTT_ALIGN_START) ) +{ +p_rect->x = indent_anchor_position; +p_rect->w -= p_rect->x; +} +} +else /* Vertical text */ +{ +if( p_settings->vertical == WEBVTT_ALIGN_LEFT ) +p_rect->x = line_offset > 0 ? 1.0 - line_offset : -line_offset; +else +p_rect->x = line_offset > 0 ? line_offset : 1.0 + line_offset; +p_rect->y = (extent) ? extent : 1.0; + +if( indent_anchor_position > 0 && +alignment_on_indent_anchor == WEBVTT_ALIGN_START ) +{ +p_rect->y = indent_anchor_position; +p_rect->h -= p_rect->y; +} +} +} + static void webvtt_cue_settings_ParseTuple( webvtt_cue_settings_t *p_settings, const char *psz_key, const char *psz_value ) { @@ -217,6 +300,7 @@ static void webvtt_cue_settings_ParseTuple( webvtt_cue_settings_t *p_settings, } else if( !strcmp( psz_key, "line" ) ) { +p_settings->line.b_auto = false; if( strchr( psz_value, '%' ) ) { parse_percent( psz_value, _settings->line.value ); @@ -224,7 +308,6 @@ static void webvtt_cue_settings_ParseTuple( webvtt_cue_settings_t *p_settings, } else p_settings->line.value = us_strtof( psz_value, NULL ); - /* else auto */ const char *psz_align = strchr( psz_value, ',' ); @@ -256,7 +339,8 @@ static void webvtt_cue_settings_ParseTuple( webvtt_cue_settings_t *p_settings, } else if( !strcmp( psz_key, "size" ) ) { -parse_percent( psz_value, _settings->size ); +parse_percent( psz_value, _settings->size.value ); +p_settings->size.b_auto = false; } else if( !strcmp( psz_key, "region" ) ) { @@ -318,7 +402,8 @@ static void webvtt_cue_settings_Init(