Add a comment.
[dcpomatic.git] / src / lib / dcp_examiner.cc
index f2ec68bddd8786a9a73f6258dc8d757c8600b50b..af9e38873f83688c989e55ab226f4ad9cb326e99 100644 (file)
 
 using std::cout;
 using std::dynamic_pointer_cast;
+using std::make_shared;
 using std::shared_ptr;
 using std::string;
+using std::vector;
 using boost::optional;
 
 
@@ -63,19 +65,15 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
 {
        shared_ptr<dcp::CPL> cpl;
 
-       for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
-               _text_count[i] = 0;
-       }
-
        auto cpls = dcp::find_and_resolve_cpls (content->directories(), tolerant);
 
        if (content->cpl ()) {
-               /* Use the CPL that the content was using before */
-               for (auto i: cpls) {
-                       if (i->id() == content->cpl().get()) {
-                               cpl = i;
-                       }
+               /* Use the CPL that was specified, or that the content was using before */
+               auto iter = std::find_if(cpls.begin(), cpls.end(), [content](shared_ptr<dcp::CPL> cpl) { return cpl->id() == content->cpl().get(); });
+               if (iter == cpls.end()) {
+                       throw CPLNotFoundError(content->cpl().get());
                }
+               cpl = *iter;
        } else {
                /* Choose the CPL with the fewest unsatisfied references */
 
@@ -132,6 +130,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
 
        for (auto i: cpl->reels()) {
                LOG_GENERAL ("Reel %1", i->id());
+               vector<shared_ptr<dcpomatic::Font>> reel_fonts;
 
                if (i->main_picture ()) {
                        if (!i->main_picture()->asset_ref().resolved()) {
@@ -201,8 +200,12 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
 
                        LOG_GENERAL ("Main subtitle %1 of reel %2 found", i->main_subtitle()->id(), i->id());
 
-                       _text_count[static_cast<int>(TextType::OPEN_SUBTITLE)] = 1;
+                       _text_count[TextType::OPEN_SUBTITLE] = 1;
                        _open_subtitle_language = try_to_parse_language (i->main_subtitle()->language());
+
+                       for (auto const& font: i->main_subtitle()->asset()->font_data()) {
+                               reel_fonts.push_back(make_shared<dcpomatic::Font>(font.first, font.second));
+                       }
                }
 
                for (auto j: i->closed_captions()) {
@@ -215,7 +218,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
 
                        LOG_GENERAL ("Closed caption %1 of reel %2 found", j->id(), i->id());
 
-                       _text_count[static_cast<int>(TextType::CLOSED_CAPTION)]++;
+                       _text_count[TextType::CLOSED_CAPTION]++;
                        _dcp_text_tracks.push_back (DCPTextTrack(j->annotation_text().get_value_or(""), try_to_parse_language(j->language())));
                }
 
@@ -244,6 +247,12 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
                } else if (!i->atmos()) {
                        _reel_lengths.push_back (i->atmos()->actual_duration());
                }
+
+               if (reel_fonts.empty()) {
+                       reel_fonts.push_back(make_shared<dcpomatic::Font>(""));
+               }
+
+               _fonts.push_back(reel_fonts);
        }
 
        _encrypted = cpl->any_encrypted ();