diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-01-01 21:34:27 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-01-07 22:49:28 +0100 |
| commit | 2bd88621084ef86a2710b70aea4f6ee9e39e0b63 (patch) | |
| tree | b9002b34abb1f8fb9b3444fdcf2da73b28d2fcdd /src | |
| parent | 02fc2c110a9e8b338e05388aa59cc52ea85fbf3f (diff) | |
Expose all font information from SubtitleAsset.
Diffstat (limited to 'src')
| -rw-r--r-- | src/combine.cc | 6 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 24 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 52 | ||||
| -rw-r--r-- | src/verify.cc | 6 |
4 files changed, 34 insertions, 54 deletions
diff --git a/src/combine.cc b/src/combine.cc index 05ad519e..fc98e7e8 100644 --- a/src/combine.cc +++ b/src/combine.cc @@ -147,9 +147,11 @@ dcp::combine ( * and re-write the font XML file since the font URI might have changed if it's a duplicate * with another DCP. */ - auto fonts = sub->font_filenames (); + auto fonts = sub->fonts(); for (auto const& k: fonts) { - sub->set_font_file (k.first, make_unique(output / k.second.filename())); + if (k.file) { + sub->set_font_file(k.load_id, make_unique(output / k.file->filename())); + } } auto file = sub->file(); DCP_ASSERT (file); diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index f707c665..c25368c0 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -752,30 +752,6 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, S } -map<string, ArrayData> -SubtitleAsset::font_data () const -{ - map<string, ArrayData> out; - for (auto const& i: _fonts) { - out[i.load_id] = i.data; - } - return out; -} - - -map<string, boost::filesystem::path> -SubtitleAsset::font_filenames () const -{ - map<string, boost::filesystem::path> out; - for (auto const& i: _fonts) { - if (i.file) { - out[i.load_id] = *i.file; - } - } - return out; -} - - /** Replace empty IDs in any <LoadFontId> and <Font> tags with * a dummy string. Some systems give errors with empty font IDs * (see DCP-o-matic bug #1689). diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index aebf3fd9..6e71322b 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -110,8 +110,33 @@ public: virtual void add (std::shared_ptr<Subtitle>); virtual void add_font(std::string id, dcp::ArrayData data, boost::optional<std::string> font_uuid = boost::none) = 0; - std::map<std::string, ArrayData> font_data () const; - std::map<std::string, boost::filesystem::path> font_filenames () const; + + class Font + { + public: + Font (std::string load_id_, std::string uuid_, boost::filesystem::path file_) + : load_id (load_id_) + , uuid (uuid_) + , data (file_) + , file (file_) + {} + + Font (std::string load_id_, std::string uuid_, ArrayData data_) + : load_id (load_id_) + , uuid (uuid_) + , data (data_) + {} + + std::string load_id; + std::string uuid; + ArrayData data; + /** .ttf file that this data was last written to, if applicable */ + mutable boost::optional<boost::filesystem::path> file; + }; + + std::vector<Font> fonts() const { + return _fonts; + } virtual void write (boost::filesystem::path) const = 0; virtual std::string xml_as_string () const = 0; @@ -179,29 +204,6 @@ protected: /** All our subtitles, in no particular order */ std::vector<std::shared_ptr<Subtitle>> _subtitles; - class Font - { - public: - Font (std::string load_id_, std::string uuid_, boost::filesystem::path file_) - : load_id (load_id_) - , uuid (uuid_) - , data (file_) - , file (file_) - {} - - Font (std::string load_id_, std::string uuid_, ArrayData data_) - : load_id (load_id_) - , uuid (uuid_) - , data (data_) - {} - - std::string load_id; - std::string uuid; - ArrayData data; - /** .ttf file that this data was last written to, if applicable */ - mutable boost::optional<boost::filesystem::path> file; - }; - /** TTF font data that we need */ std::vector<Font> _fonts; diff --git a/src/verify.cc b/src/verify.cc index bfa697da..1cab7491 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -660,10 +660,10 @@ verify_smpte_timed_text_asset ( /* XXX: I'm not sure what Bv2.1_7.2.1 means when it says "the font resource shall not be larger than 10MB" * but I'm hoping that checking for the total size of all fonts being <= 10MB will do. */ - auto fonts = asset->font_data (); + auto fonts = asset->fonts(); int total_size = 0; - for (auto i: fonts) { - total_size += i.second.size(); + for (auto const& i: fonts) { + total_size += i.data.size(); } if (total_size > 10 * 1024 * 1024) { notes.push_back ({ VerificationNote::Type::BV21_ERROR, VerificationNote::Code::INVALID_TIMED_TEXT_FONT_SIZE_IN_BYTES, raw_convert<string>(total_size), asset->file().get() }); |
