Allow copy-construction of Font.
[dcpomatic.git] / src / lib / font.h
index 24d8ed2bb93103027795c838a3b800ad1668b5c0..12a14aba4e74086dee82c93d3a6464dd6159dee7 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.
 
@@ -44,13 +44,18 @@ public:
 
        Font (std::string id, boost::filesystem::path file)
                : _id (id)
-               , _file (file)
-       {}
+       {
+               _content.file = file;
+       }
 
        Font (std::string id, dcp::ArrayData data)
                : _id (id)
-               , _data (data)
-       {}
+       {
+               _content.data = data;
+       }
+
+       Font(Font const& other);
+       Font& operator=(Font const& other);
 
        void as_xml (xmlpp::Node* node);
 
@@ -63,16 +68,30 @@ public:
        }
 
        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;
+       };
+
+       Content content() const {
+               return _content;
+       }
+
        boost::signals2::signal<void()> Changed;
 
 private:
@@ -80,8 +99,7 @@ private:
         *  font family name or an ID from some DCP font XML.
         */
        std::string _id;
-       boost::optional<dcp::ArrayData> _data;
-       boost::optional<boost::filesystem::path> _file;
+       Content _content;
 };