diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-09-25 12:51:43 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-09-26 23:57:09 +0200 |
| commit | 492c0d0597230e680e7b59800d4f6e26d6a82e5e (patch) | |
| tree | 5a7191e2fb0f6f47994f9c8275b0b070dbe9d71e | |
| parent | 66100d5f14759220c9f25d6facfccb188ef81f12 (diff) | |
Re-order cairo context scaling and pango layout setup (#2337).
This seems to fix problems where letters were scaled individually, but
their spacing didn't change (when x scale was applied).
Big thanks to user1768761
https://stackoverflow.com/questions/58528024/pangocairo-shows-cluttered-text-when-cairo-context-is-scaled
| -rw-r--r-- | src/lib/render_text.cc | 3 | ||||
| m--------- | test/data | 0 | ||||
| -rw-r--r-- | test/render_subtitles_test.cc | 41 |
3 files changed, 43 insertions, 1 deletions
diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index 08fc8320f..fe8ebf38d 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -422,9 +422,10 @@ render_line(vector<StringText> subtitles, dcp::Size target, DCPTime time, int fr auto surface = create_surface(image); auto context = Cairo::Context::create(surface); + layout.pango->update_from_cairo_context(context); + context->set_line_width(1); context->scale(x_scale, y_scale); - layout.pango->update_from_cairo_context(context); if (first.effect() == dcp::Effect::SHADOW) { /* Drop-shadow effect */ diff --git a/test/data b/test/data -Subproject e9931b4a897f730a1dddef460a20fd17006902f +Subproject e6e96b047077c2b9094faff9eeb759d2c489768 diff --git a/test/render_subtitles_test.cc b/test/render_subtitles_test.cc index 1fe43c6d8..9155c56e4 100644 --- a/test/render_subtitles_test.cc +++ b/test/render_subtitles_test.cc @@ -36,6 +36,7 @@ using std::make_shared; +using std::pair; using std::shared_ptr; using std::string; using std::vector; @@ -183,6 +184,46 @@ BOOST_AUTO_TEST_CASE(render_text_with_newline_test) } +BOOST_AUTO_TEST_CASE(render_text_with_stretch_test) +{ + for (auto const& stretch: vector<pair<float, string>>{ { 0.5, "thin"}, { 2, "fat" }}) { + auto dcp_string = dcp::TextString( + {}, false, false, false, dcp::Colour(255, 255, 255), 42, stretch.first, + dcp::Time(0, 0, 0, 0, 24), dcp::Time(0, 0, 1, 0, 24), + 0.5, dcp::HAlign::CENTER, + 0.5, dcp::VAlign::CENTER, + 0.0, {}, + dcp::Direction::LTR, + "HÄllo jokers", + dcp::Effect::NONE, dcp::Colour(0, 0, 0), + {}, {}, + 0, + {} + ); + + auto string_text = StringText(dcp_string, 0, make_shared<dcpomatic::Font>("foo"), dcp::SubtitleStandard::SMPTE_2014); + + auto images = render_text({ string_text }, dcp::Size(1998, 1080), {}, 24); + + BOOST_CHECK_EQUAL(images.size(), 1U); + image_as_png(Image::ensure_alignment(images.front().image, Image::Alignment::PADDED)).write( + fmt::format("build/test/render_text_with_stretch_{}_test.png", stretch.second) + ); +#if PANGO_VERSION_CHECK(1, 52, 1) + check_image( + fmt::format("test/data/render_text_with_stretch_{}_test.png", stretch.second), + fmt::format("build/test/render_text_with_stretch_{}_test.png", stretch.second) + ); +#else + check_image( + fmt::format("test/data/ubuntu-22.04/render_text_with_stretch_{}_test.png", stretch.second), + fmt::format("build/test/render_text_with_stretch_{}_test.png", stretch.second) + ); +#endif + } +} + + #if 0 BOOST_AUTO_TEST_CASE (render_text_test) |
