From c6665c157bdb6903661d21c571c7d112b54ad8fd Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 20 Dec 2020 23:49:48 +0100 Subject: Accept fonts as data blocks rather than files. --- src/interop_subtitle_asset.cc | 7 ++++--- src/interop_subtitle_asset.h | 2 +- src/smpte_subtitle_asset.cc | 4 ++-- src/smpte_subtitle_asset.h | 2 +- src/subtitle_asset.h | 2 +- test/dcp_font_test.cc | 4 ++-- test/test.cc | 3 +-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index 316fb08a..c6173a26 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -119,10 +119,11 @@ InteropSubtitleAsset::xml_as_string () const } void -InteropSubtitleAsset::add_font (string load_id, boost::filesystem::path file) +InteropSubtitleAsset::add_font (string load_id, dcp::ArrayData data) { - _fonts.push_back (Font (load_id, make_uuid(), file)); - _load_font_nodes.push_back (shared_ptr (new InteropLoadFontNode (load_id, file.leaf().string ()))); + _fonts.push_back (Font(load_id, make_uuid(), data)); + string const uri = String::compose("font_%1.ttf", _load_font_nodes.size()); + _load_font_nodes.push_back (shared_ptr(new InteropLoadFontNode(load_id, uri))); } bool diff --git a/src/interop_subtitle_asset.h b/src/interop_subtitle_asset.h index 4b96c795..b34a2a28 100644 --- a/src/interop_subtitle_asset.h +++ b/src/interop_subtitle_asset.h @@ -64,7 +64,7 @@ public: std::list > load_font_nodes () const; - void add_font (std::string load_id, boost::filesystem::path file); + void add_font (std::string load_id, dcp::ArrayData data); std::string xml_as_string () const; void write (boost::filesystem::path path) const; diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 0ebfcc61..606ef84c 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -527,10 +527,10 @@ SMPTESubtitleAsset::equals (shared_ptr other_asset, EqualityOptions } void -SMPTESubtitleAsset::add_font (string load_id, boost::filesystem::path file) +SMPTESubtitleAsset::add_font (string load_id, dcp::ArrayData data) { string const uuid = make_uuid (); - _fonts.push_back (Font (load_id, uuid, file)); + _fonts.push_back (Font(load_id, uuid, data)); _load_font_nodes.push_back (shared_ptr (new SMPTELoadFontNode (load_id, uuid))); } diff --git a/src/smpte_subtitle_asset.h b/src/smpte_subtitle_asset.h index 09cd4634..1f2215a8 100644 --- a/src/smpte_subtitle_asset.h +++ b/src/smpte_subtitle_asset.h @@ -75,7 +75,7 @@ public: std::string xml_as_string () const; void write (boost::filesystem::path path) const; void add (boost::shared_ptr); - void add_font (std::string id, boost::filesystem::path file); + void add_font (std::string id, dcp::ArrayData data); void set_key (Key key); void set_content_title_text (std::string t) { diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 063a2dfd..ab909a26 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -94,7 +94,7 @@ public: } virtual void add (boost::shared_ptr); - virtual void add_font (std::string id, boost::filesystem::path file) = 0; + virtual void add_font (std::string id, dcp::ArrayData data) = 0; std::map font_data () const; std::map font_filenames () const; diff --git a/test/dcp_font_test.cc b/test/dcp_font_test.cc index 6a3941f9..5884cbc0 100644 --- a/test/dcp_font_test.cc +++ b/test/dcp_font_test.cc @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE (interop_dcp_font_test) dcp::DCP dcp (directory); shared_ptr subs (new dcp::InteropSubtitleAsset ()); - subs->add_font ("theFontId", "test/data/dummy.ttf"); + subs->add_font ("theFontId", dcp::ArrayData("test/data/dummy.ttf")); subs->write (directory / "frobozz.xml"); check_file ("test/data/dummy.ttf", "build/test/interop_dcp_font_test/dummy.ttf"); @@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE (smpte_dcp_font_test) dcp::DCP dcp (directory); shared_ptr subs (new dcp::SMPTESubtitleAsset ()); - subs->add_font ("theFontId", "test/data/dummy.ttf"); + subs->add_font ("theFontId", dcp::ArrayData("test/data/dummy.ttf")); subs->write (directory / "frobozz.mxf"); shared_ptr reel (new dcp::Reel ()); diff --git a/test/test.cc b/test/test.cc index bace2326..69772e98 100644 --- a/test/test.cc +++ b/test/test.cc @@ -345,8 +345,7 @@ make_simple_with_interop_subs (boost::filesystem::path path) boost::filesystem::create_directory (path / "subs"); dcp::ArrayData data(4096); - data.write (path / "subs" / "font.ttf"); - subs->add_font ("afont", path / "subs" / "font.ttf"); + subs->add_font ("afont", data); subs->write (path / "subs" / "subs.xml"); shared_ptr reel_subs(new dcp::ReelSubtitleAsset(subs, dcp::Fraction(24, 1), 240, 0)); -- cgit v1.2.3