Fix to allow re-writing of SMPTE subtitles.
[libdcp.git] / src / subtitle_asset.h
index 1108514a3e67bbd66edbebda2198ec770b56ce1e..dff31cc69d91b78ee37d0077e89699c26cc667d8 100644 (file)
 #ifndef LIBDCP_SUBTITLE_ASSET_H
 #define LIBDCP_SUBTITLE_ASSET_H
 
+
+#include "array_data.h"
 #include "asset.h"
 #include "dcp_time.h"
 #include "subtitle_string.h"
-#include "data.h"
 #include <libcxml/cxml.h>
 #include <boost/shared_array.hpp>
 #include <map>
@@ -56,6 +57,7 @@ namespace dcp
 {
 
 class SubtitleString;
+class SubtitleImage;
 class FontNode;
 class TextNode;
 class SubtitleNode;
@@ -63,7 +65,7 @@ class LoadFontNode;
 
 namespace order {
        class Part;
-       class Context;
+       struct Context;
 }
 
 /** @class SubtitleAsset
@@ -81,26 +83,33 @@ public:
        explicit SubtitleAsset (boost::filesystem::path file);
 
        bool equals (
-               boost::shared_ptr<const Asset>,
+               std::shared_ptr<const Asset>,
                EqualityOptions,
                NoteHandler note
                ) const;
 
-       std::list<boost::shared_ptr<Subtitle> > subtitles_during (Time from, Time to, bool starting) const;
-       std::list<boost::shared_ptr<Subtitle> > const & subtitles () const {
+       std::list<std::shared_ptr<Subtitle> > subtitles_during (Time from, Time to, bool starting) const;
+       std::list<std::shared_ptr<Subtitle> > const & subtitles () const {
                return _subtitles;
        }
 
-       virtual void add (boost::shared_ptr<Subtitle>);
-       virtual void add_font (std::string id, boost::filesystem::path file) = 0;
-       std::map<std::string, Data> fonts_with_load_ids () const;
+       virtual void add (std::shared_ptr<Subtitle>);
+       virtual void add_font (std::string id, dcp::ArrayData data) = 0;
+       std::map<std::string, ArrayData> font_data () const;
+       std::map<std::string, boost::filesystem::path> font_filenames () const;
 
        virtual void write (boost::filesystem::path) const = 0;
        virtual std::string xml_as_string () const = 0;
 
        Time latest_subtitle_out () const;
 
-       virtual std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const = 0;
+       void fix_empty_font_ids ();
+
+       virtual std::list<std::shared_ptr<LoadFontNode> > load_font_nodes () const = 0;
+
+       std::string raw_xml () const {
+               return _raw_xml;
+       }
 
 protected:
        friend struct ::interop_dcp_font_test;
@@ -125,18 +134,25 @@ protected:
                boost::optional<Time> out;
                boost::optional<Time> fade_up_time;
                boost::optional<Time> fade_down_time;
+               enum Type {
+                       TEXT,
+                       IMAGE
+               };
+               boost::optional<Type> type;
        };
 
        void parse_subtitles (xmlpp::Element const * node, std::list<ParseState>& state, boost::optional<int> tcr, Standard standard);
        ParseState font_node_state (xmlpp::Element const * node, Standard standard) const;
        ParseState text_node_state (xmlpp::Element const * node) const;
+       ParseState image_node_state (xmlpp::Element const * node) const;
        ParseState subtitle_node_state (xmlpp::Element const * node, boost::optional<int> tcr) const;
        Time fade_time (xmlpp::Element const * node, std::string name, boost::optional<int> tcr) const;
+       void position_align (ParseState& ps, xmlpp::Element const * node) const;
 
        void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Standard standard) const;
 
        /** All our subtitles, in no particular order */
-       std::list<boost::shared_ptr<Subtitle> > _subtitles;
+       std::list<std::shared_ptr<Subtitle> > _subtitles;
 
        class Font
        {
@@ -148,7 +164,7 @@ protected:
                        , file (file_)
                {}
 
-               Font (std::string load_id_, std::string uuid_, Data data_)
+               Font (std::string load_id_, std::string uuid_, ArrayData data_)
                        : load_id (load_id_)
                        , uuid (uuid_)
                        , data (data_)
@@ -156,7 +172,7 @@ protected:
 
                std::string load_id;
                std::string uuid;
-               Data data;
+               ArrayData data;
                /** .ttf file that this data was last written to, if applicable */
                mutable boost::optional<boost::filesystem::path> file;
        };
@@ -164,14 +180,17 @@ protected:
        /** TTF font data that we need */
        std::list<Font> _fonts;
 
+       /** The raw XML data that we read from our asset; useful for validation */
+       std::string _raw_xml;
+
 private:
        friend struct ::pull_fonts_test1;
        friend struct ::pull_fonts_test2;
        friend struct ::pull_fonts_test3;
 
-       void maybe_add_subtitle (std::string text, std::list<ParseState> const & parse_state);
+       void maybe_add_subtitle (std::string text, std::list<ParseState> const & parse_state, Standard standard);
 
-       static void pull_fonts (boost::shared_ptr<order::Part> part);
+       static void pull_fonts (std::shared_ptr<order::Part> part);
 };
 
 }