diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-05-19 22:33:44 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-05-30 19:59:06 +0200 |
| commit | 09f35415304afc127f50edfe4357a28c5a0e2ff9 (patch) | |
| tree | 7f55e8e3a0eaac33e3378ec730b2fe015f19c962 /src/lib | |
| parent | 5708ccdd531c72ff9e43106d354464adf6afa699 (diff) | |
Render subtitles using show_in_cairo_context() instead of add_to_cairo_context().
This helps with #2813 and should fix #2474.
We started using add_to_cairo_context() again in
72c3a5f0f32f553a1f8abee2494f31d29b976383
because the rendering looked better. However colour changes within
lines cannot easily be rendered using add_to_cairo_context() it seems,
as the text is just added as a path and then you can stroke/fill it
with a single colour.
I hope that this change, which reverts 72c3a5 but also adds some calls
to enable hinting and use better anti-aliasing, looks OK. I looked
at some white-on-black subs close-up and the hinting seems to help.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/render_text.cc | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index 52830dcf3..41652d32d 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -72,6 +72,16 @@ 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); @@ -430,17 +440,8 @@ render_line(vector<StringText> subtitles, dcp::Size target, DCPTime time, int fr } /* 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); |
