Cleanup: use some more vector instead of list.
authorCarl Hetherington <cth@carlh.net>
Sat, 26 Aug 2023 12:29:06 +0000 (14:29 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 29 Aug 2023 16:28:40 +0000 (18:28 +0200)
src/lib/player_text.h
src/lib/render_text.cc
src/lib/render_text.h
src/lib/util.cc
src/wx/closed_captions_dialog.cc
test/render_subtitles_test.cc

index 38affd5ef1cc0953e8bee3ad87b1df8dcc8fc94f..5921b28f6f5a1c3af9e550e86390c5d440f14ed0 100644 (file)
@@ -37,8 +37,8 @@ class PlayerText
 {
 public:
        /** BitmapTexts, with their rectangles transformed as specified by their content */
-       std::list<BitmapText> bitmap;
-       std::list<StringText> string;
+       std::vector<BitmapText> bitmap;
+       std::vector<StringText> string;
 };
 
 
index 9d154feca1fb5d47dba077f1b7778549d8ace32c..84fc8414dc6d553aea0cffc89eacd4299aa28888 100644 (file)
@@ -39,7 +39,6 @@ LIBDCP_ENABLE_WARNINGS
 
 using std::cerr;
 using std::cout;
-using std::list;
 using std::make_pair;
 using std::make_shared;
 using std::max;
@@ -47,6 +46,7 @@ using std::min;
 using std::pair;
 using std::shared_ptr;
 using std::string;
+using std::vector;
 using boost::optional;
 using namespace dcpomatic;
 
@@ -76,7 +76,7 @@ create_layout(string font_name, string markup)
 
 
 string
-marked_up (list<StringText> subtitles, int target_height, float fade_factor, string font_name)
+marked_up(vector<StringText> subtitles, int target_height, float fade_factor, string font_name)
 {
        auto constexpr pixels_to_1024ths_point = 72 * 1024 / 96;
 
@@ -296,7 +296,7 @@ struct Layout
  *  at the same time and with the same fade in/out.
  */
 static Layout
-setup_layout(list<StringText> subtitles, dcp::Size target, DCPTime time, int frame_rate)
+setup_layout(vector<StringText> subtitles, dcp::Size target, DCPTime time, int frame_rate)
 {
        DCPOMATIC_ASSERT(!subtitles.empty());
        auto const& first = subtitles.front();
@@ -314,7 +314,7 @@ setup_layout(list<StringText> subtitles, dcp::Size target, DCPTime time, int fra
  *  at the same time and with the same fade in/out.
  */
 static PositionImage
-render_line (list<StringText> subtitles, dcp::Size target, DCPTime time, int frame_rate)
+render_line(vector<StringText> subtitles, dcp::Size target, DCPTime time, int frame_rate)
 {
        /* XXX: this method can only handle italic / bold changes mid-line,
           nothing else yet.
@@ -401,11 +401,11 @@ render_line (list<StringText> subtitles, dcp::Size target, DCPTime time, int fra
  *  @param target Size of the container that this subtitle will end up in.
  *  @param frame_rate DCP frame rate.
  */
-list<PositionImage>
-render_text (list<StringText> subtitles, dcp::Size target, DCPTime time, int frame_rate)
+vector<PositionImage>
+render_text(vector<StringText> subtitles, dcp::Size target, DCPTime time, int frame_rate)
 {
-       list<StringText> pending;
-       list<PositionImage> images;
+       vector<StringText> pending;
+       vector<PositionImage> images;
 
        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)) {
@@ -423,11 +423,11 @@ render_text (list<StringText> subtitles, dcp::Size target, DCPTime time, int fra
 }
 
 
-list<dcpomatic::Rect<int>>
-bounding_box(list<StringText> subtitles, dcp::Size target, optional<dcp::SubtitleStandard> override_standard)
+vector<dcpomatic::Rect<int>>
+bounding_box(vector<StringText> subtitles, dcp::Size target, optional<dcp::SubtitleStandard> override_standard)
 {
-       list<StringText> pending;
-       list<dcpomatic::Rect<int>> rects;
+       vector<StringText> pending;
+       vector<dcpomatic::Rect<int>> rects;
 
        auto use_pending = [&pending, &rects, target, override_standard]() {
                auto const& subtitle = pending.front();
index 6d20912a278771981dd2f9299b26c4ee354fd096..ff34dc10d8c1cc4b6c687dd086c9e0443535bd32 100644 (file)
@@ -32,9 +32,9 @@ namespace dcpomatic {
 }
 
 
-std::string marked_up (std::list<StringText> subtitles, int target_height, float fade_factor, std::string font_name);
-std::list<PositionImage> render_text (std::list<StringText>, dcp::Size, dcpomatic::DCPTime, int);
-std::list<dcpomatic::Rect<int>> bounding_box(std::list<StringText> subtitles, dcp::Size target, boost::optional<dcp::SubtitleStandard> override_standard = boost::none);
+std::string marked_up(std::vector<StringText> subtitles, int target_height, float fade_factor, std::string font_name);
+std::vector<PositionImage> render_text(std::vector<StringText>, dcp::Size, dcpomatic::DCPTime, int);
+std::vector<dcpomatic::Rect<int>> bounding_box(std::vector<StringText> subtitles, dcp::Size target, boost::optional<dcp::SubtitleStandard> override_standard = boost::none);
 
 
 class FontMetrics
index 05b69644f1ed95616eb4a8e0f4cde7ebdc85e0be..4240279c694d42dd27f03e6a1c6eddcfcbf1a234 100644 (file)
@@ -461,7 +461,7 @@ LIBDCP_ENABLE_WARNINGS
 
 #if defined(DCPOMATIC_WINDOWS) || defined(DCPOMATIC_OSX)
        /* Render something to fontconfig to create its cache */
-       list<StringText> subs;
+       vector<StringText> subs;
        dcp::SubtitleString ss(
                optional<string>(), false, false, false, dcp::Colour(), 42, 1, dcp::Time(), dcp::Time(), 0, dcp::HAlign::CENTER, 0, dcp::VAlign::CENTER, 0, dcp::Direction::LTR,
                "Hello dolly", dcp::Effect::NONE, dcp::Colour(), dcp::Time(), dcp::Time(), 0
index d84ea01359966a726773db8ca4a91490bf3b36a3..9142500e0547bffa28534d21b40e584c18c9c612 100644 (file)
@@ -201,7 +201,7 @@ ClosedCaptionsDialog::update ()
                        _lines[j] = "";
                }
 
-               to_show.sort (ClosedCaptionSorter());
+               std::sort(to_show.begin(), to_show.end(), ClosedCaptionSorter());
 
                auto j = to_show.begin();
                int k = 0;
index d1c91260254cfbb623be91628ba33d3cd0931fd0..02323756802c2ca21c7464463183c6b980338098 100644 (file)
@@ -37,7 +37,7 @@ using std::shared_ptr;
 
 
 static void
-add (std::list<StringText>& s, std::string text, bool italic, bool bold, bool underline)
+add(std::vector<StringText>& s, std::string text, bool italic, bool bold, bool underline)
 {
        s.push_back (
                StringText (
@@ -74,7 +74,7 @@ add (std::list<StringText>& s, std::string text, bool italic, bool bold, bool un
 
 BOOST_AUTO_TEST_CASE (marked_up_test1)
 {
-       std::list<StringText> s;
+       std::vector<StringText> s;
        add (s, "Hello", false, false, false);
        BOOST_CHECK_EQUAL(marked_up(s, 1024, 1, ""), "<span size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
 }
@@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE (marked_up_test1)
 
 BOOST_AUTO_TEST_CASE (marked_up_test2)
 {
-       std::list<StringText> s;
+       std::vector<StringText> s;
        add (s, "Hello", false, true, false);
        BOOST_CHECK_EQUAL(marked_up(s, 1024, 1, ""), "<span weight=\"bold\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
 }
@@ -90,21 +90,21 @@ BOOST_AUTO_TEST_CASE (marked_up_test2)
 
 BOOST_AUTO_TEST_CASE (marked_up_test3)
 {
-       std::list<StringText> s;
+       std::vector<StringText> s;
        add (s, "Hello", true, true, false);
        BOOST_CHECK_EQUAL(marked_up(s, 1024, 1, ""), "<span style=\"italic\" weight=\"bold\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
 }
 
 BOOST_AUTO_TEST_CASE (marked_up_test4)
 {
-       std::list<StringText> s;
+       std::vector<StringText> s;
        add (s, "Hello", true, true, true);
        BOOST_CHECK_EQUAL(marked_up(s, 1024, 1, ""), "<span style=\"italic\" weight=\"bold\" underline=\"single\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
 }
 
 BOOST_AUTO_TEST_CASE (marked_up_test5)
 {
-       std::list<StringText> s;
+       std::vector<StringText> s;
        add (s, "Hello", false, true, false);
        add (s, " world.", false, false, false);
        BOOST_CHECK_EQUAL (marked_up(s, 1024, 1, ""), "<span weight=\"bold\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span><span size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\"> world.</span>");
@@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE (marked_up_test5)
 
 BOOST_AUTO_TEST_CASE (marked_up_test6)
 {
-       std::list<StringText> s;
+       std::vector<StringText> s;
        add (s, "Hello", true, false, false);
        add (s, " world ", false, false, false);
        add (s, "we are bold.", false, true, false);