+ FcObjectSetDestroy (object_set);
+ FcPatternDestroy (pattern);
+
+ fc_config_fonts.push_back (make_pair (font_files, font_name));
+ }
+
+ FcConfigSetCurrent (fc_config);
+
+ Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
+
+ layout->set_alignment (Pango::ALIGN_LEFT);
+
+ context->set_line_width (1);
+
+ /* Compute fade factor */
+ float fade_factor = 1;
+
+ /* Round the fade start/end to the nearest frame start. Otherwise if a subtitle starts just after
+ the start of a frame it will be faded out.
+ */
+ DCPTime const fade_in_start = DCPTime::from_seconds(subtitles.front().in().as_seconds()).round(frame_rate);
+ DCPTime const fade_in_end = fade_in_start + DCPTime::from_seconds (subtitles.front().fade_up_time().as_seconds ());
+ DCPTime const fade_out_end = DCPTime::from_seconds (subtitles.front().out().as_seconds()).round(frame_rate);
+ DCPTime const fade_out_start = fade_out_end - DCPTime::from_seconds (subtitles.front().fade_down_time().as_seconds ());
+
+ if (fade_in_start <= time && time <= fade_in_end && fade_in_start != fade_in_end) {
+ fade_factor *= DCPTime(time - fade_in_start).seconds() / DCPTime(fade_in_end - fade_in_start).seconds();
+ }
+ if (fade_out_start <= time && time <= fade_out_end && fade_out_start != fade_out_end) {
+ fade_factor *= 1 - DCPTime(time - fade_out_start).seconds() / DCPTime(fade_out_end - fade_out_start).seconds();
+ }
+ if (time < fade_in_start || time > fade_out_end) {
+ fade_factor = 0;
+ }
+
+ /* Render the subtitle at the top left-hand corner of image */
+
+ Pango::FontDescription font (font_name);
+ layout->set_font_description (font);
+ layout->set_markup (marked_up (subtitles, target.height, fade_factor));
+
+ 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;
+ /* Move down a bit so that accents on capital letters can be seen */
+ int const y_offset = target.height / 100.0;
+
+ if (subtitles.front().effect() == dcp::SHADOW) {
+ /* Drop-shadow effect */
+ set_source_rgba (context, subtitles.front().effect_colour(), fade_factor);
+ context->move_to (x_offset + 4, y_offset + 4);