diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-12-28 01:21:04 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-12-30 12:22:30 +0100 |
| commit | 931aa567b5435ae15877547b6030a583e1b19881 (patch) | |
| tree | 1fe39996aba0d4ea8b1482b47677c7abd401786b | |
| parent | 4edfd9afa0fdfea1fa6d86409e5696d90a580018 (diff) | |
Extract text_positions_close().
| -rw-r--r-- | src/lib/render_text.cc | 6 | ||||
| -rw-r--r-- | src/lib/util.cc | 7 | ||||
| -rw-r--r-- | 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<StringText> 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<StringText> subtitles, dcp::Size target, optional<dcp::Subti }; for (auto const& i: subtitles) { - if (!pending.empty() && (i.v_align() != pending.back().v_align() || fabs(i.v_position() - pending.back().v_position()) > 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<std::string> const& in, std::string extern std::string rfc_2822_date(time_t time); bool paths_exist(std::vector<boost::filesystem::path> const& paths); std::function<AVPixelFormat (AVPixelFormat)> force(AVPixelFormat format); +bool text_positions_close(float a, float b); /** @param path Some path. * @param base Some base path. |
