diff options
author | Chris Bass <floobleflam@gmail.com> | 2017-03-22 10:21:28 +0000 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2017-04-09 10:42:08 +0300 |
commit | 0288ee24e9527bb488e551e3f40d48db71f3d8ec (patch) | |
tree | 12ec1a5de76d733f0e03cd25d4755483980f68be /ext/ttml | |
parent | f28df30a8b8fb840c9173c8d727d152bde99f149 (diff) |
ttml: correctly implement lineHeight behaviour
The specified behaviour in TTML when lineHeight is "normal" is different
from the behaviour when a percentage is given. In the former case, the
line height is a percentage (the TTML spec recommends 125%) of the largest
font size that is applied to the spans within the block; in the latter
case, the line height is the given percentage of the font size that is
applied to the block itself.
The code doesn't correctly implement this behaviour; this patch fixes
that.
https://bugzilla.gnome.org/show_bug.cgi?id=780402
Diffstat (limited to 'ext/ttml')
-rw-r--r-- | ext/ttml/gstttmlrender.c | 47 | ||||
-rw-r--r-- | ext/ttml/subtitle.c | 2 | ||||
-rw-r--r-- | ext/ttml/ttmlparse.c | 4 |
3 files changed, 42 insertions, 11 deletions
diff --git a/ext/ttml/gstttmlrender.c b/ext/ttml/gstttmlrender.c index ba18a1b8e..b3d696bdb 100644 --- a/ext/ttml/gstttmlrender.c +++ b/ext/ttml/gstttmlrender.c @@ -2194,14 +2194,47 @@ static BlockMetrics gst_ttml_render_get_block_metrics (GstTtmlRender * render, UnifiedBlock * block) { BlockMetrics ret; - guint descender = gst_ttml_render_get_most_frequent_descender (render, block); - guint font_size = (guint) ceil (block->style_set->font_size * render->height); - ret.line_height = (guint) ceil (font_size * block->style_set->line_height); - ret.baseline_offset = (guint) ((font_size + ret.line_height) / 2.0) - - descender; - GST_CAT_DEBUG (ttmlrender_debug, - "Got most frequent descender value of %u pixels.", descender); + /* + * The specified behaviour in TTML when lineHeight is "normal" is different + * from the behaviour when a percentage is given. In the former case, the + * line height is a percentage (the TTML spec recommends 125%) of the largest + * font size that is applied to the spans within the block; in the latter + * case, the line height is the given percentage of the font size that is + * applied to the block itself. + */ + if (block->style_set->line_height < 0) { /* lineHeight="normal" case */ + guint max_text_height = 0; + guint descender = 0; + guint i; + + for (i = 0; i < gst_ttml_render_unified_block_element_count (block); ++i) { + UnifiedElement *ue = gst_ttml_render_unified_block_get_element (block, i); + + if (ue->pango_font_metrics.height > max_text_height) { + max_text_height = ue->pango_font_metrics.height; + descender = + ue->pango_font_metrics.height - ue->pango_font_metrics.baseline; + } + } + + GST_CAT_LOG (ttmlrender_debug, "Max descender: %u Max text height: %u", + descender, max_text_height); + ret.line_height = (guint) ceil (max_text_height * 1.25); + ret.baseline_offset = (guint) ((max_text_height + ret.line_height) / 2.0) + - descender; + } else { + guint descender; + guint font_size; + + descender = gst_ttml_render_get_most_frequent_descender (render, block); + GST_CAT_LOG (ttmlrender_debug, + "Got most frequent descender value of %u pixels.", descender); + font_size = (guint) ceil (block->style_set->font_size * render->height); + ret.line_height = (guint) ceil (font_size * block->style_set->line_height); + ret.baseline_offset = (guint) ((font_size + ret.line_height) / 2.0) + - descender; + } return ret; } diff --git a/ext/ttml/subtitle.c b/ext/ttml/subtitle.c index 51724ca21..b8843a379 100644 --- a/ext/ttml/subtitle.c +++ b/ext/ttml/subtitle.c @@ -68,7 +68,7 @@ gst_subtitle_style_set_new (void) ret->font_family = g_strdup ("default"); ret->font_size = 1.0; - ret->line_height = 1.25; + ret->line_height = -1; ret->color = white; ret->background_color = transparent; ret->line_padding = 0.0; diff --git a/ext/ttml/ttmlparse.c b/ext/ttml/ttmlparse.c index 181474ccd..535fde1b2 100644 --- a/ext/ttml/ttmlparse.c +++ b/ext/ttml/ttmlparse.c @@ -463,10 +463,8 @@ ttml_update_style_set (GstSubtitleStyleSet * style_set, TtmlStyleSet * tss, style_set->font_size *= (1.0 / cellres_y); if ((attr = ttml_style_set_get_attr (tss, "lineHeight"))) { - /* The TTML spec (section 8.2.12) recommends using a line height of 125% - * when "normal" is specified. */ if (g_strcmp0 (attr, "normal") == 0) - style_set->line_height = 1.25; + style_set->line_height = -1; else style_set->line_height = g_ascii_strtod (attr, NULL) / 100.0; } |