Note that newer libsub version is required.
[dcpomatic.git] / src / lib / dcp_subtitle_decoder.cc
index 617f7ec536530b71e83558f0f871b216cfe84312..711dc77f263e6cf7d2d64ba40bc877f33a6a761d 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "dcp_subtitle_content.h"
 #include "dcp_subtitle_decoder.h"
+#include "film.h"
 #include "font.h"
 #include "text_content.h"
 #include "util.h"
@@ -42,19 +43,22 @@ DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr<const Film> film, shared_ptr<
        : Decoder (film)
 {
        /* Load the XML or MXF file */
-       auto const asset = load (content->path(0));
-       asset->fix_empty_font_ids ();
-       _subtitles = asset->subtitles ();
+       _asset = load(content->path(0));
+       _asset->fix_empty_font_ids();
+       _subtitles = _asset->subtitles();
        _next = _subtitles.begin ();
 
-       if (dynamic_pointer_cast<dcp::InteropSubtitleAsset>(asset)) {
-               _standard = dcp::Standard::INTEROP;
-       } else {
-               _standard = dcp::Standard::SMPTE;
-       }
+       _subtitle_standard = _asset->subtitle_standard();
 
        text.push_back (make_shared<TextDecoder>(this, content->only_text()));
        update_position();
+
+       FontIDAllocator font_id_allocator;
+
+       for (auto node: _asset->load_font_nodes()) {
+               _font_id_allocator.add_font(0, _asset->id(), node->id);
+       }
+       _font_id_allocator.allocate();
 }
 
 
@@ -94,7 +98,13 @@ DCPSubtitleDecoder::pass ()
        while (_next != _subtitles.end () && content_time_period (*_next) == p) {
                auto ns = dynamic_pointer_cast<const dcp::SubtitleString>(*_next);
                if (ns) {
-                       s.push_back (*ns);
+                       dcp::SubtitleString ns_copy = *ns;
+                       if (ns_copy.font()) {
+                               ns_copy.set_font(_font_id_allocator.font_id(0, _asset->id(), ns_copy.font().get()));
+                       } else {
+                               ns_copy.set_font(_font_id_allocator.default_font_id());
+                       }
+                       s.push_back(ns_copy);
                        ++_next;
                } else {
                        /* XXX: perhaps these image subs should also be collected together like the string ones are;
@@ -109,7 +119,7 @@ DCPSubtitleDecoder::pass ()
                }
        }
 
-       only_text()->emit_plain(p, s, _standard);
+       only_text()->emit_plain(p, s, _subtitle_standard);
 
        update_position();