From 931aa567b5435ae15877547b6030a583e1b19881 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 28 Dec 2025 01:21:04 +0100 Subject: Extract text_positions_close(). --- src/lib/render_text.cc | 6 +++--- src/lib/util.cc | 7 +++++++ src/lib/util.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index fe8ebf38d..3dcc317fa 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -472,8 +472,8 @@ render_text(vector subtitles, dcp::Size target, DCPTime time, int fr for (auto const& i: subtitles) { if (!pending.empty()) { auto const last = pending.back(); - auto const different_v = i.v_align() != last.v_align() || fabs(i.v_position() - last.v_position()) > 1e-4; - auto const different_h = i.h_align() != last.h_align() || fabs(i.h_position() - pending.back().h_position()) > 1e-4; + auto const different_v = i.v_align() != last.v_align() || !text_positions_close(i.v_position(), last.v_position()); + auto const different_h = i.h_align() != last.h_align() || !text_positions_close(i.h_position(), pending.back().h_position()); if (different_v || different_h) { /* We need a new line if any new positioning (horizontal or vertical) changes for this section */ images.push_back(render_line(pending, target, time, frame_rate)); @@ -509,7 +509,7 @@ bounding_box(vector subtitles, dcp::Size target, optional 1e-4)) { + if (!pending.empty() && (i.v_align() != pending.back().v_align() || !text_positions_close(i.v_position(), pending.back().v_position()))) { use_pending(); pending.clear(); } diff --git a/src/lib/util.cc b/src/lib/util.cc index ebac8c0e7..e53dc30c0 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1192,3 +1192,10 @@ relative_path(boost::filesystem::path const& path, boost::filesystem::path const return relative; } + +bool +text_positions_close(float a, float b) +{ + return std::abs(a - b) < 1e-4; +} + diff --git a/src/lib/util.h b/src/lib/util.h index f6c8e573f..aa003ff00 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -102,6 +102,7 @@ extern std::string join_strings(std::vector const& in, std::string extern std::string rfc_2822_date(time_t time); bool paths_exist(std::vector const& paths); std::function force(AVPixelFormat format); +bool text_positions_close(float a, float b); /** @param path Some path. * @param base Some base path. -- cgit v1.2.3