+ if (subtitles.front().effect() == dcp::BORDER) {
+ /* Border effect; stroke the subtitle with a large (arbitrarily chosen) line width */
+ set_source_rgba (context, subtitles.front().effect_colour(), fade_factor);
+ context->set_line_width (subtitles.front().outline_width * target.width / 2048.0);
+ context->set_line_join (Cairo::LINE_JOIN_ROUND);
+ context->move_to (x_offset, y_offset);
+ layout->add_to_cairo_context (context);
+ context->stroke ();
+ }
+
+ /* The actual subtitle */
+
+ context->set_line_width (0);
+ context->move_to (x_offset, y_offset);
+#ifdef DCPOMATIC_HAVE_SHOW_IN_CAIRO_CONTEXT
+ layout->show_in_cairo_context (context);
+#else
+ pango_cairo_show_layout (context->cobj(), layout->gobj());
+#endif
+
+ int layout_width;
+ int layout_height;
+ layout->get_pixel_size (layout_width, layout_height);
+ layout_width *= xscale;
+ layout_height *= yscale;
+
+ int x = 0;
+ switch (subtitles.front().h_align ()) {
+ case dcp::HALIGN_LEFT:
+ /* h_position is distance between left of frame and left of subtitle */
+ x = subtitles.front().h_position() * target.width;
+ break;
+ case dcp::HALIGN_CENTER:
+ /* h_position is distance between centre of frame and centre of subtitle */
+ x = (0.5 + subtitles.front().h_position()) * target.width - layout_width / 2;
+ break;
+ case dcp::HALIGN_RIGHT:
+ /* h_position is distance between right of frame and right of subtitle */
+ x = (1.0 - subtitles.front().h_position()) * target.width - layout_width;
+ break;
+ }
+
+ int y = 0;
+ switch (subtitles.front().v_align ()) {
+ case dcp::VALIGN_TOP:
+ /* SMPTE says that v_position is the distance between top
+ of frame and top of subtitle, but this doesn't always seem to be
+ the case in practice; Gunnar Ásgeirsson's Dolby server appears
+ to put VALIGN_TOP subs with v_position as the distance between top
+ of frame and bottom of subtitle.
+ */
+ y = subtitles.front().v_position() * target.height - layout_height;
+ break;
+ case dcp::VALIGN_CENTER:
+ /* v_position is distance between centre of frame and centre of subtitle */
+ y = (0.5 + subtitles.front().v_position()) * target.height - layout_height / 2;
+ break;
+ case dcp::VALIGN_BOTTOM:
+ /* v_position is distance between bottom of frame and bottom of subtitle */
+ y = (1.0 - subtitles.front().v_position()) * target.height - layout_height;
+ break;