Bit of a hack to make rendering of outlined subtitles more pleasing.
authorCarl Hetherington <cth@carlh.net>
Tue, 9 Aug 2016 00:12:59 +0000 (01:12 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 9 Aug 2016 00:12:59 +0000 (01:12 +0100)
ChangeLog
src/lib/render_subtitles.cc

index 4795375d867a8f6a89563509c5939c10593418b8..0b522f653d3a12a9453f5ed42770e6cc0867180c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 782d06532e378d240699419c3031ae41fe04191a..5c8cf13eedc32e98d68c059ead8f3be083b2a616 100644 (file)
@@ -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);