diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-08-09 01:12:59 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-08-09 01:12:59 +0100 |
| commit | fc40b77302f2fc2bb89b88b62013b855525720ac (patch) | |
| tree | 745ac234938b1c9f9590d3812492302aa39660f9 | |
| parent | 86815157be975d143b9e1bdbcb777303d105bcb8 (diff) | |
Bit of a hack to make rendering of outlined subtitles more pleasing.
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | src/lib/render_subtitles.cc | 31 |
2 files changed, 24 insertions, 11 deletions
@@ -1,3 +1,7 @@ +2016-08-09 Carl Hetherington <cth@carlh.net> + + * Improve rendering of outlined burnt-in subtitles a bit. + 2016-08-04 Carl Hetherington <cth@carlh.net> * Version 2.9.9 released. diff --git a/src/lib/render_subtitles.cc b/src/lib/render_subtitles.cc index 782d06532..5c8cf13ee 100644 --- a/src/lib/render_subtitles.cc +++ b/src/lib/render_subtitles.cc @@ -254,32 +254,41 @@ render_line (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts, context->scale (xscale, yscale); layout->update_from_cairo_context (context); + /* Shuffle the subtitle over very slightly if it has a border so that the left-hand + side of the first character's border is not cut off. + */ + int const x_offset = subtitles.front().effect() == dcp::BORDER ? (target.width / 600.0) : 0; + if (subtitles.front().effect() == dcp::SHADOW) { /* Drop-shadow effect */ dcp::Colour const ec = subtitles.front().effect_colour (); context->set_source_rgba (float(ec.r) / 255, float(ec.g) / 255, float(ec.b) / 255, fade_factor); - context->move_to (4, 4); + context->move_to (x_offset + 4, 4); layout->add_to_cairo_context (context); context->fill (); } - /* The actual subtitle */ - - dcp::Colour const c = subtitles.front().colour (); - context->set_source_rgba (float(c.r) / 255, float(c.g) / 255, float(c.b) / 255, fade_factor); - context->move_to (0, 0); - layout->add_to_cairo_context (context); - context->fill (); - if (subtitles.front().effect() == dcp::BORDER) { - /* Border effect */ + /* Border effect; stroke the subtitle with a large (arbitrarily chosen) line width */ dcp::Colour ec = subtitles.front().effect_colour (); context->set_source_rgba (float(ec.r) / 255, float(ec.g) / 255, float(ec.b) / 255, fade_factor); - context->move_to (0, 0); + /* This 300.0 is a magic number chosen to make the outline look good */ + context->set_line_width (target.width / 300.0); + context->set_line_join (Cairo::LINE_JOIN_ROUND); + context->move_to (x_offset, 0); layout->add_to_cairo_context (context); context->stroke (); } + /* The actual subtitle */ + + dcp::Colour const c = subtitles.front().colour (); + context->set_source_rgba (float(c.r) / 255, float(c.g) / 255, float(c.b) / 255, fade_factor); + context->set_line_width (0); + context->move_to (x_offset, 0); + layout->add_to_cairo_context (context); + context->fill (); + int layout_width; int layout_height; layout->get_pixel_size (layout_width, layout_height); |
