summaryrefslogtreecommitdiff
path: root/src/lib/render_text.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/render_text.cc')
-rw-r--r--src/lib/render_text.cc56
1 files changed, 43 insertions, 13 deletions
diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc
index 870f3045d..3c3d4eed7 100644
--- a/src/lib/render_text.cc
+++ b/src/lib/render_text.cc
@@ -31,6 +31,7 @@
#include <cairomm/cairomm.h>
LIBDCP_DISABLE_WARNINGS
#include <pangomm.h>
+#include <pangommconfig.h>
LIBDCP_ENABLE_WARNINGS
#include <pango/pangocairo.h>
#include <boost/algorithm/string.hpp>
@@ -51,6 +52,15 @@ using boost::optional;
using namespace dcpomatic;
+#if CAIROMM_MAJOR_VERSION == 1 && CAIROMM_MINOR_VERSION <= 14
+#define DCPOMATIC_OLD_CAIROMM_API
+#endif
+
+#if PANGOMM_MAJOR_VERSION == 2 && PANGOMM_MINOR_VERSION <= 46
+#define DCPOMATIC_OLD_PANGOMM_API
+#endif
+
+
/** Create a Pango layout using a dummy context which we can use to calculate the size
* of the text we will render. Then we can transfer the layout over to the real context
* for the actual render.
@@ -62,11 +72,25 @@ create_layout(string font_name, string markup)
DCPOMATIC_ASSERT (c_font_map);
auto font_map = Glib::wrap (c_font_map);
auto c_context = pango_font_map_create_context (c_font_map);
+
+ cairo_font_options_t *options = cairo_font_options_create();
+ /* CAIRO_ANTIALIAS_BEST is totally broken here: see e.g.
+ * https://gitlab.freedesktop.org/cairo/cairo/-/issues/152
+ */
+ cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GOOD);
+ cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_FULL);
+ pango_cairo_context_set_font_options(c_context, options);
+ cairo_font_options_destroy(options);
+
DCPOMATIC_ASSERT (c_context);
auto context = Glib::wrap (c_context);
auto layout = Pango::Layout::create(context);
- layout->set_alignment (Pango::ALIGN_LEFT);
+#ifdef DCPOMATIC_OLD_PANGOMM_API
+ layout->set_alignment(Pango::ALIGN_LEFT);
+#else
+ layout->set_alignment(Pango::Alignment::LEFT);
+#endif
Pango::FontDescription font (font_name);
layout->set_font_description (font);
layout->set_markup (markup);
@@ -124,7 +148,7 @@ marked_up(vector<StringText> subtitles, int target_height, float fade_factor, st
int dummy;
layout->get_pixel_size(space_width, dummy);
auto spacing = ((i.space_before() * i.size_in_pixels(target_height) - space_width) / 2) * pixels_to_1024ths_point;
- out += make_span(i, " ", "letter_spacing=\"" + dcp::raw_convert<string>(spacing) + "\"");
+ out += make_span(i, " ", "letter_spacing=\"" + dcp::raw_convert<string>(std::round(spacing)) + "\"");
}
out += make_span(i, i.text(), {});
@@ -163,11 +187,22 @@ create_surface (shared_ptr<Image> image)
DCPOMATIC_ASSERT (image->pixel_format() == AV_PIX_FMT_BGRA);
return Cairo::ImageSurface::create (
image->data()[0],
+#ifdef DCPOMATIC_OLD_CAIROMM_API
Cairo::FORMAT_ARGB32,
+#else
+ Cairo::ImageSurface::Format::ARGB32,
+#endif
image->size().width,
image->size().height,
/* Cairo ARGB32 means first byte blue, second byte green, third byte red, fourth byte alpha */
- Cairo::ImageSurface::format_stride_for_width (Cairo::FORMAT_ARGB32, image->size().width)
+ Cairo::ImageSurface::format_stride_for_width(
+#ifdef DCPOMATIC_OLD_CAIROMM_API
+ Cairo::FORMAT_ARGB32,
+#else
+ Cairo::ImageSurface::Format::ARGB32,
+#endif
+ image->size().width
+ )
);
}
@@ -394,24 +429,19 @@ render_line(vector<StringText> subtitles, dcp::Size target, DCPTime time, int fr
/* Border effect */
set_source_rgba (context, first.effect_colour(), fade_factor);
context->set_line_width (border_width);
+#ifdef DCPOMATIC_OLD_CAIROMM_API
context->set_line_join (Cairo::LINE_JOIN_ROUND);
+#else
+ context->set_line_join (Cairo::Context::LineJoin::ROUND);
+#endif
context->move_to (x_offset, y_offset);
layout.pango->add_to_cairo_context (context);
context->stroke ();
}
/* The actual subtitle */
-
- set_source_rgba (context, first.colour(), fade_factor);
-
- context->move_to (x_offset, y_offset);
- layout.pango->add_to_cairo_context (context);
- context->fill ();
-
- context->set_line_width (0.5);
context->move_to (x_offset, y_offset);
- layout.pango->add_to_cairo_context (context);
- context->stroke ();
+ layout.pango->show_in_cairo_context(context);
int const x = x_position(first.h_align(), first.h_position(), target.width, layout.size.width);
int const y = y_position(first.valign_standard, first.v_align(), first.v_position(), target.height, layout.baseline_to_bottom(border_width), layout.size.height);