- if (i->effect() == dcp::BORDER) {
- /* Border effect */
- context->move_to (x, y);
- dcp::Color ec = i->effect_color ();
- context->set_source_rgba (float(ec.r) / 255, float(ec.g) / 255, float(ec.b) / 255, fade_factor);
- layout->add_to_cairo_context (context);
- context->stroke ();
- }
+ /* The actual subtitle */
+
+ dcp::Colour const c = subtitle.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 (subtitle.effect() == dcp::BORDER) {
+ /* Border effect */
+ dcp::Colour ec = subtitle.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);
+ layout->add_to_cairo_context (context);
+ context->stroke ();
+ }
+
+ int layout_width;
+ int layout_height;
+ layout->get_size (layout_width, layout_height);
+
+ int x = 0;
+ switch (subtitle.h_align ()) {
+ case dcp::HALIGN_LEFT:
+ /* h_position is distance between left of frame and left of subtitle */
+ x = subtitle.h_position() * target.width;
+ break;
+ case dcp::HALIGN_CENTER:
+ /* h_position is distance between centre of frame and centre of subtitle */
+ x = (0.5 + subtitle.h_position()) * target.width - layout_width / (PANGO_SCALE * 2);
+ break;
+ case dcp::HALIGN_RIGHT:
+ /* h_position is distance between right of frame and right of subtitle */
+ x = (1.0 - subtitle.h_position()) * target.width - layout_width / PANGO_SCALE;
+ break;
+ }
+
+ int y = 0;
+ switch (subtitle.v_align ()) {
+ case dcp::VALIGN_TOP:
+ /* v_position is distance between top of frame and top of subtitle */
+ y = subtitle.v_position() * target.height;
+ break;
+ case dcp::VALIGN_CENTER:
+ /* v_position is distance between centre of frame and centre of subtitle */
+ y = (0.5 + subtitle.v_position()) * target.height - layout_height / (PANGO_SCALE * 2);
+ break;
+ case dcp::VALIGN_BOTTOM:
+ /* v_position is distance between bottom of frame and bottom of subtitle */
+ y = (1.0 - subtitle.v_position()) * target.height - layout_height / PANGO_SCALE;
+ break;