Collect subtitles at the same time before emitting them from
authorCarl Hetherington <cth@carlh.net>
Tue, 16 Oct 2018 15:02:39 +0000 (16:02 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 16 Oct 2018 15:02:39 +0000 (16:02 +0100)
DCPDecoder.  Prevents overlaid text in, for example, lines with
partial italic.

src/lib/dcp_decoder.cc

index 72db5369c81e9dd162457d5636bb0c3b420b44fa..71a7e42d035cc5e8f40b3387f99e6fda51229b40 100644 (file)
@@ -228,18 +228,24 @@ DCPDecoder::pass_texts (ContentTime next, shared_ptr<dcp::SubtitleAsset> asset,
                        true
                        );
 
+               list<dcp::SubtitleString> strings;
+
                BOOST_FOREACH (shared_ptr<dcp::Subtitle> i, subs) {
                        shared_ptr<dcp::SubtitleString> is = dynamic_pointer_cast<dcp::SubtitleString> (i);
                        if (is) {
-                               list<dcp::SubtitleString> s;
-                               s.push_back (*is);
-                               decoder->emit_plain (
-                                       ContentTimePeriod (
-                                               ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (i->in().as_seconds ()),
-                                               ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (i->out().as_seconds ())
-                                               ),
-                                       s
-                                       );
+                               if (!strings.empty() && (strings.back().in() != is->in() || strings.back().out() != is->out())) {
+                                       dcp::SubtitleString b = strings.back();
+                                       decoder->emit_plain (
+                                               ContentTimePeriod (
+                                                       ContentTime::from_frames(_offset - entry_point, vfr) + ContentTime::from_seconds(b.in().as_seconds()),
+                                                       ContentTime::from_frames(_offset - entry_point, vfr) + ContentTime::from_seconds(b.out().as_seconds())
+                                                       ),
+                                               strings
+                                               );
+                                       strings.clear ();
+                               }
+
+                               strings.push_back (*is);
                        }
 
                        shared_ptr<dcp::SubtitleImage> ii = dynamic_pointer_cast<dcp::SubtitleImage> (i);
@@ -284,6 +290,18 @@ DCPDecoder::pass_texts (ContentTime next, shared_ptr<dcp::SubtitleAsset> asset,
                                        );
                        }
                }
+
+               if (!strings.empty()) {
+                       dcp::SubtitleString b = strings.back();
+                       decoder->emit_plain (
+                               ContentTimePeriod (
+                                       ContentTime::from_frames(_offset - entry_point, vfr) + ContentTime::from_seconds(b.in().as_seconds()),
+                                       ContentTime::from_frames(_offset - entry_point, vfr) + ContentTime::from_seconds(b.out().as_seconds())
+                                       ),
+                               strings
+                               );
+                       strings.clear ();
+               }
        }
 }