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 | |
| 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.
| -rw-r--r-- | src/lib/render_text.cc | 21 | ||||
| -rw-r--r-- | test/burnt_subtitle_test.cc | 12 | ||||
| m--------- | test/data | 0 |
3 files changed, 20 insertions, 13 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); diff --git a/test/burnt_subtitle_test.cc b/test/burnt_subtitle_test.cc index c3c253d51..2be712262 100644 --- a/test/burnt_subtitle_test.cc +++ b/test/burnt_subtitle_test.cc @@ -68,8 +68,10 @@ BOOST_AUTO_TEST_CASE (burnt_subtitle_test_subrip) { dcp::VerificationNote::Code::MISSING_CPL_METADATA } ); -#ifdef DCPOMATIC_WINDOWS +#if defined(DCPOMATIC_WINDOWS) check_dcp("test/data/windows/burnt_subtitle_test_subrip", film); +#elif defined(DCPOMATIC_OSX) + check_dcp("test/data/mac/burnt_subtitle_test_subrip", film); #else check_dcp("test/data/burnt_subtitle_test_subrip", film); #endif @@ -129,8 +131,10 @@ BOOST_AUTO_TEST_CASE (burnt_subtitle_test_onto_dcp) BOOST_CHECK_EQUAL (xyz->size().width, 1998); BOOST_CHECK_EQUAL (xyz->size().height, 1080); -#ifdef DCPOMATIC_WINDOWS +#if defined(DCPOMATIC_WINDOWS) check_dcp("test/data/windows/burnt_subtitle_test_onto_dcp2", film2); +#elif defined(DCPOMATIC_OSX) + check_dcp("test/data/mac/burnt_subtitle_test_onto_dcp2", film2); #else check_dcp("test/data/burnt_subtitle_test_onto_dcp2", film2); #endif @@ -156,8 +160,10 @@ BOOST_AUTO_TEST_CASE(burnt_subtitle_test_position) dcp::VerificationNote::Code::MISSING_CPL_METADATA }); -#ifdef DCPOMATIC_WINDOWS +#if defined(DCPOMATIC_WINDOWS) check_dcp(String::compose("test/data/windows/%1", name), film); +#elif defined(DCPOMATIC_OSX) + check_dcp(String::compose("test/data/mac/%1", name), film); #else check_dcp(String::compose("test/data/%1", name), film); #endif diff --git a/test/data b/test/data -Subproject f647e9364406f7934acd4c248c77287a810f59c +Subproject 27a4c1a8fbb90dca275ca94cdd86f9f14536e41 |
