Wrap path/data in a struct.
[dcpomatic.git] / src / lib / font.h
index ed3ecc38f3075498d2051545a38df5ab4c2382fb..b9e90f65e07e0052df4d5f4afa7da5f52c1c7e03 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2023 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -23,6 +23,7 @@
 #define DCPOMATIC_FONT_H
 
 
+#include <dcp/array_data.h>
 #include <libcxml/cxml.h>
 #include <boost/optional.hpp>
 #include <boost/signals2.hpp>
@@ -41,27 +42,57 @@ public:
 
        explicit Font (cxml::NodePtr node);
 
+       Font (std::string id, boost::filesystem::path file)
+               : _id (id)
+       {
+               _content.file = file;
+       }
+
+       Font (std::string id, dcp::ArrayData data)
+               : _id (id)
+       {
+               _content.data = data;
+       }
+
        void as_xml (xmlpp::Node* node);
 
        std::string id () const {
                return _id;
        }
 
+       void set_id (std::string id) {
+               _id = id;
+       }
+
        boost::optional<boost::filesystem::path> file () const {
-               return _file;
+               return _content.file;
        }
 
        void set_file (boost::filesystem::path file) {
-               _file = file;
+               _content.file = file;
                Changed ();
        }
 
+       /** @return the data set passed to the dcp::ArrayData constructor,
+        *  otherwise the contents of _file, otherwise boost::none.
+        */
+       boost::optional<dcp::ArrayData> data() const;
+
+       /** The actual TTF/OTF font data, as either a filename or the raw data itself */
+       struct Content
+       {
+               boost::optional<dcp::ArrayData> data;
+               boost::optional<boost::filesystem::path> file;
+       };
+
        boost::signals2::signal<void()> Changed;
 
 private:
-       /** Font ID, used to describe it in the subtitle content */
+       /** Font ID, used to describe it in the subtitle content; could be either a
+        *  font family name or an ID from some DCP font XML.
+        */
        std::string _id;
-       boost::optional<boost::filesystem::path> _file;
+       Content _content;
 };