diff --git a/NEWS.md b/NEWS.md index 60e5d78c7..96b26753e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,12 @@ # Version ? +## New features and enhancements + +* mkvmerge: SRT handling: added a hack called `--engage + keep_whitespaces_in_text_subtitles` which disables stripping whitespaces + from the start & end of each line of SRT entries during muxing. Part of the + implementation of #3470. + ## Bug fixes * build system: fixed compatibility with Ruby 3.2.0 by using `FileTest.exist?` diff --git a/src/common/hacks.cpp b/src/common/hacks.cpp index 686fd2633..0ccb3a12d 100644 --- a/src/common/hacks.cpp +++ b/src/common/hacks.cpp @@ -65,6 +65,8 @@ get_list() { Y("The resulting tracks will be broken: the official FLAC tools will not be able to decode them and seeking will not work as expected.") }); hacks.emplace_back("dont_normalize_parameter_sets", svec{ Y("Normally the HEVC/H.265 code in mkvmerge and mkvextract normalizes parameter sets by prefixing all key frames with all currently active parameter sets and removes duplicates that might already be present."), Y("If this hack is enabled, the code will leave the parameter sets as they are.") }); + hacks.emplace_back("keep_whitespaces_in_text_subtitles", svec{ Y("Normally spaces & tabs are removed from the beginning & the end of each line in text subtitles."), + Y("If this hack is enabled, they won't be removed.") }); hacks.emplace_back("cow", svec{ Y("No help available.") }); diff --git a/src/common/hacks.h b/src/common/hacks.h index 4c21c41b8..cd502179e 100644 --- a/src/common/hacks.h +++ b/src/common/hacks.h @@ -45,7 +45,8 @@ constexpr unsigned int KEEP_TRACK_STATISTICS_TAGS = 20; constexpr unsigned int ALL_I_SLICES_ARE_KEY_FRAMES = 21; constexpr unsigned int APPEND_AND_SPLIT_FLAC = 22; constexpr unsigned int DONT_NORMALIZE_PARAMETER_SETS = 23; -constexpr unsigned int MAX_IDX = 23; +constexpr unsigned int KEEP_WHITESPACES_IN_TEXT_SUBTITLES = 24; +constexpr unsigned int MAX_IDX = 24; } struct hack_t { diff --git a/src/output/p_textsubs.cpp b/src/output/p_textsubs.cpp index aa98de821..353abd40c 100644 --- a/src/output/p_textsubs.cpp +++ b/src/output/p_textsubs.cpp @@ -17,6 +17,7 @@ #include "common/codec.h" #include "common/debugging.h" +#include "common/hacks.h" #include "common/qt.h" #include "common/strings/editing.h" #include "common/strings/parsing.h" @@ -33,6 +34,7 @@ textsubs_packetizer_c::textsubs_packetizer_c(generic_reader_c *p_reader, const char *codec_id, bool recode) : generic_packetizer_c(p_reader, p_ti) + , m_strip_whitespaces{!mtx::hacks::is_engaged(mtx::hacks::KEEP_WHITESPACES_IN_TEXT_SUBTITLES)} , m_codec_id{codec_id} { if (recode) { @@ -91,9 +93,12 @@ textsubs_packetizer_c::process_impl(packet_cptr const &packet) { subs = mtx::string::normalize_line_endings(subs, m_line_ending_style); auto q_subs = Q(subs); - q_subs.replace(QRegularExpression{Q("^[ \t]+|[ \t]+$"), QRegularExpression::MultilineOption}, {}); - q_subs.replace(QRegularExpression{Q("[ \t]+\r")}, Q("\r")); - q_subs.replace(QRegularExpression{Q("[\r\n]+\\z")}, {}); + + if (m_strip_whitespaces) { + q_subs.replace(QRegularExpression{Q("^[ \t]+|[ \t]+$"), QRegularExpression::MultilineOption}, {}); + q_subs.replace(QRegularExpression{Q("[ \t]+\r")}, Q("\r")); + q_subs.replace(QRegularExpression{Q("[\r\n]+\\z")}, {}); + } if (q_subs.isEmpty()) return; diff --git a/src/output/p_textsubs.h b/src/output/p_textsubs.h index cbe8710f1..bfe12b483 100644 --- a/src/output/p_textsubs.h +++ b/src/output/p_textsubs.h @@ -23,7 +23,7 @@ protected: unsigned int m_packetno{}; std::optional m_force_rerender_track_headers_on_packetno; charset_converter_cptr m_cc_utf8; - bool m_try_utf8{}, m_invalid_utf8_warned{}, m_converter_is_utf8{}; + bool m_try_utf8{}, m_invalid_utf8_warned{}, m_converter_is_utf8{}, m_strip_whitespaces{}; std::string m_codec_id; mtx::string::line_ending_style_e m_line_ending_style{mtx::string::line_ending_style_e::cr_lf}; packet_cptr m_buffered_packet;