+struct Layout
+{
+ Position<int> position;
+ int baseline_position;
+ dcp::Size size;
+ Glib::RefPtr<Pango::Layout> pango;
+
+ int baseline_to_bottom(int border_width)
+ {
+ return position.y + size.height - baseline_position - border_width;
+ }
+};
+
+
+/** @param subtitles A list of subtitles that are all on the same line,
+ * at the same time and with the same fade in/out.
+ */
+static Layout
+setup_layout(vector<StringText> subtitles, dcp::Size target, DCPTime time, int frame_rate)
+{
+ DCPOMATIC_ASSERT(!subtitles.empty());
+ auto const& first = subtitles.front();
+
+ auto const font_name = FontConfig::instance()->make_font_available(first.font);
+ auto const fade_factor = calculate_fade_factor(first, time, frame_rate);
+ auto const markup = marked_up(subtitles, target.height, fade_factor, font_name);
+ auto layout = create_layout(font_name, markup);
+ auto ink = layout->get_ink_extents();
+
+ Layout description;
+ description.position = { ink.get_x() / Pango::SCALE, ink.get_y() / Pango::SCALE };
+ description.baseline_position = layout->get_baseline() / Pango::SCALE;
+ description.size = { ink.get_width() / Pango::SCALE, ink.get_height() / Pango::SCALE };
+ description.pango = layout;
+
+ return description;
+}
+
+
+static
+int
+border_width_for_subtitle(StringText const& subtitle, dcp::Size target)
+{
+ return subtitle.effect() == dcp::Effect::BORDER ? (subtitle.outline_width * target.width / 2048.0) : 0;
+}
+
+