From 2ae92dcc97765deb2845dd07a338858aeb375cb3 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 24 Jun 2015 14:13:37 +0100 Subject: No-op: whitespace. --- test/certificates_test.cc | 8 ++++---- test/colour_test.cc | 2 +- test/cpl_sar_test.cc | 4 ++-- test/dcp_test.cc | 16 ++++++++-------- test/decryption_test.cc | 4 ++-- test/encryption_test.cc | 28 ++++++++++++++-------------- test/kdm_test.cc | 8 ++++---- test/local_time_test.cc | 2 +- test/read_interop_subtitle_test.cc | 2 +- test/recovery_test.cc | 10 +++++----- test/rewrite_subs.cc | 10 +++++----- test/rgb_xyz_test.cc | 6 +++--- test/round_trip_test.cc | 2 +- test/test.cc | 6 +++--- test/util_test.cc | 14 +++++++------- test/write_subtitle_test.cc | 2 +- 16 files changed, 62 insertions(+), 62 deletions(-) (limited to 'test') diff --git a/test/certificates_test.cc b/test/certificates_test.cc index 374dbc13..d355ad55 100644 --- a/test/certificates_test.cc +++ b/test/certificates_test.cc @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE (certificates) /* Leaf */ BOOST_CHECK_EQUAL (*i, c.leaf ()); - + BOOST_CHECK_EQUAL ( c.leaf().issuer(), "dnQualifier=6eat8r33US71avuQEojmH\\+bjk84=,CN=.smpte-430-2.INTERMEDIATE.NOT_FOR_PRODUCTION,OU=example.org,O=example.org" @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE (certificates) c.leaf().subject(), "dnQualifier=QFVlym7fuql6bPOnY38aaO1ZPW4=,CN=CS.smpte-430-2.LEAF.NOT_FOR_PRODUCTION,OU=example.org,O=example.org" ); - + ++i; /* Intermediate */ @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (certificates) i->subject(), "dnQualifier=6eat8r33US71avuQEojmH\\+bjk84=,CN=.smpte-430-2.INTERMEDIATE.NOT_FOR_PRODUCTION,OU=example.org,O=example.org" ); - + ++i; /* Root */ @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE (certificates_validation) dcp::CertificateChain good2; good2.add (dcp::Certificate (dcp::file_to_string ("test/ref/crypt/ca.self-signed.pem"))); BOOST_CHECK (good2.valid ()); - + dcp::CertificateChain bad1; bad1.add (dcp::Certificate (dcp::file_to_string ("test/ref/crypt/intermediate.signed.pem"))); bad1.add (dcp::Certificate (dcp::file_to_string ("test/ref/crypt/leaf.signed.pem"))); diff --git a/test/colour_test.cc b/test/colour_test.cc index cebe95ab..7169c177 100644 --- a/test/colour_test.cc +++ b/test/colour_test.cc @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE (colour) BOOST_CHECK_EQUAL (z.g, 0); BOOST_CHECK_EQUAL (z.b, 0); BOOST_CHECK_EQUAL (z.to_argb_string(), "FF000000"); - + dcp::Colour c ("FFFF0000"); BOOST_CHECK_EQUAL (c.r, 255); diff --git a/test/cpl_sar_test.cc b/test/cpl_sar_test.cc index cafa589f..92e38a00 100644 --- a/test/cpl_sar_test.cc +++ b/test/cpl_sar_test.cc @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE (cpl_sar) xmlpp::Document doc; xmlpp::Element* el = doc.create_root_node ("Test"); pa->write_to_cpl (el, dcp::INTEROP); - + cxml::Node node (el); BOOST_CHECK_EQUAL (node.node_child("MainPicture")->string_child ("ScreenAspectRatio"), "1.85"); } @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE (cpl_sar) xmlpp::Document doc; xmlpp::Element* el = doc.create_root_node ("Test"); pa->write_to_cpl (el, dcp::INTEROP); - + cxml::Node node (el); BOOST_CHECK_EQUAL (node.node_child("MainPicture")->string_child ("ScreenAspectRatio"), "2.39"); } diff --git a/test/dcp_test.cc b/test/dcp_test.cc index 0338e1f8..4a6cb429 100644 --- a/test/dcp_test.cc +++ b/test/dcp_test.cc @@ -89,9 +89,9 @@ BOOST_AUTO_TEST_CASE (dcp_test1) break; } } - + sound_writer->finalize (); - + cpl->add (shared_ptr ( new dcp::Reel ( shared_ptr (new dcp::ReelMonoPictureAsset (mp, 0)), @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE (dcp_test1) shared_ptr () ) )); - + d.add (cpl); d.write_xml (dcp::SMPTE, xml_meta); @@ -161,9 +161,9 @@ BOOST_AUTO_TEST_CASE (dcp_test2) break; } } - + sound_writer->finalize (); - + cpl->add (shared_ptr ( new dcp::Reel ( shared_ptr (new dcp::ReelStereoPictureAsset (mp, 0)), @@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE (dcp_test2) shared_ptr () ) )); - + d.add (cpl); d.write_xml (dcp::SMPTE, xml_meta); @@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE (dcp_test3) A.read (); dcp::DCP B ("test/ref/DCP/dcp_test1"); B.read (); - + BOOST_CHECK (A.equals (B, dcp::EqualityOptions(), boost::bind (¬e, _1, _2))); } @@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE (dcp_test4) A.read (); dcp::DCP B ("test/ref/DCP/dcp_test2"); B.read (); - + BOOST_CHECK (!A.equals (B, dcp::EqualityOptions(), boost::bind (¬e, _1, _2))); } diff --git a/test/decryption_test.cc b/test/decryption_test.cc index 16b2c469..2f0bb420 100644 --- a/test/decryption_test.cc +++ b/test/decryption_test.cc @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE (decryption_test) ), dcp::file_to_string ("test/data/private.key") ); - + encrypted.add (kdm); pair plaintext_frame = get_frame (plaintext); @@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE (decryption_test) /* Check that plaintext and encrypted are the same */ BOOST_CHECK_EQUAL (plaintext_frame.second, encrypted_frame.second); - + BOOST_CHECK_EQUAL ( memcmp ( plaintext_frame.first, diff --git a/test/encryption_test.cc b/test/encryption_test.cc index 10ba13a9..c176f208 100644 --- a/test/encryption_test.cc +++ b/test/encryption_test.cc @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE (encryption_test) { boost::filesystem::remove_all ("build/test/signer"); boost::filesystem::create_directory ("build/test/signer"); - + Kumu::libdcp_test = true; dcp::MXFMetadata mxf_metadata; @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE (encryption_test) xml_metadata.issuer = "OpenDCP 0.0.25"; xml_metadata.creator = "OpenDCP 0.0.25"; xml_metadata.issue_date = "2012-07-17T04:45:18+00:00"; - + boost::filesystem::remove_all ("build/test/DCP/encryption_test"); boost::filesystem::create_directories ("build/test/DCP/encryption_test"); dcp::DCP d ("build/test/DCP/encryption_test"); @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE (encryption_test) shared_ptr cpl (new dcp::CPL ("A Test DCP", dcp::FEATURE)); dcp::Key key; - + shared_ptr mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1))); mp->set_metadata (mxf_metadata); mp->set_key (key); @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE (encryption_test) ms->set_metadata (mxf_metadata); ms->set_key (key); shared_ptr sound_writer = ms->start_write ("build/test/DCP/encryption_test/audio.mxf", dcp::SMPTE); - + SF_INFO info; info.format = 0; SNDFILE* sndfile = sf_open ("test/data/1s_24-bit_48k_silence.wav", SFM_READ, &info); @@ -112,8 +112,8 @@ BOOST_AUTO_TEST_CASE (encryption_test) break; } } - - sound_writer->finalize (); + + sound_writer->finalize (); cpl->add (shared_ptr (new dcp::Reel ( shared_ptr (new dcp::ReelMonoPictureAsset (mp, 0)), @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE (encryption_test) cpl->set_content_version_id ("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00"); cpl->set_content_version_label_text ("81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00"); cpl->set_metadata (xml_metadata); - + d.add (cpl); d.write_xml (dcp::SMPTE, xml_metadata, signer); @@ -139,18 +139,18 @@ BOOST_AUTO_TEST_CASE (encryption_test) ); kdm.encrypt (signer, signer->certificates().leaf(), dcp::MODIFIED_TRANSITIONAL_1).as_xml ("build/test/encryption_test.kdm.xml"); - + int r = system ( "xmllint --path schema --nonet --noout --schema schema/SMPTE-430-1-2006-Amd-1-2009-KDM.xsd build/test/encryption_test.kdm.xml " "> build/test/xmllint.log 2>&1 < /dev/null" ); -#ifdef LIBDCP_POSIX +#ifdef LIBDCP_POSIX BOOST_CHECK_EQUAL (WEXITSTATUS (r), 0); #else BOOST_CHECK_EQUAL (r, 0); -#endif - +#endif + r = system ("xmlsec1 verify " "--pubkey-cert-pem test/ref/crypt/leaf.signed.pem " "--trusted-pem test/ref/crypt/intermediate.signed.pem " @@ -158,10 +158,10 @@ BOOST_AUTO_TEST_CASE (encryption_test) "--id-attr:Id http://www.smpte-ra.org/schemas/430-3/2006/ETM:AuthenticatedPublic " "--id-attr:Id http://www.smpte-ra.org/schemas/430-3/2006/ETM:AuthenticatedPrivate " "build/test/encryption_test.kdm.xml > build/test/xmlsec1.log 2>&1 < /dev/null"); - -#ifdef LIBDCP_POSIX + +#ifdef LIBDCP_POSIX BOOST_CHECK_EQUAL (WEXITSTATUS (r), 0); #else BOOST_CHECK_EQUAL (r, 0); -#endif +#endif } diff --git a/test/kdm_test.cc b/test/kdm_test.cc index 4051a44a..d6d4a2b6 100644 --- a/test/kdm_test.cc +++ b/test/kdm_test.cc @@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE (kdm_test) ); list keys = kdm.keys (); - + BOOST_CHECK_EQUAL (keys.size(), 2); BOOST_CHECK_EQUAL (keys.front().cpl_id(), "eece17de-77e8-4a55-9347-b6bab5724b9f"); @@ -66,9 +66,9 @@ BOOST_AUTO_TEST_CASE (kdm_passthrough_test) "xmldiff -c test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml build/kdm.xml" ); -#ifdef LIBDCP_WINDOWS +#ifdef LIBDCP_WINDOWS BOOST_CHECK_EQUAL (r, 0); -#else +#else BOOST_CHECK_EQUAL (WEXITSTATUS (r), 0); -#endif +#endif } diff --git a/test/local_time_test.cc b/test/local_time_test.cc index 9c682a74..4cd79158 100644 --- a/test/local_time_test.cc +++ b/test/local_time_test.cc @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE (local_time_test) BOOST_CHECK_THROW (dcp::LocalTime ("2013!01-05T18:06:59+04:00"), dcp::TimeFormatError); /* Correctly-formatted */ - + { dcp::LocalTime t ("2013-01-05T18:06:59+04:00"); BOOST_CHECK_EQUAL (t._year, 2013); diff --git a/test/read_interop_subtitle_test.cc b/test/read_interop_subtitle_test.cc index b268d629..aa1baeee 100644 --- a/test/read_interop_subtitle_test.cc +++ b/test/read_interop_subtitle_test.cc @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test1) dcp::Time (0, 0, 0, 1, 250), dcp::Time (0, 0, 0, 1, 250) )); - + s = subs.subtitles_during (dcp::Time (0, 0, 7, 190, 250), dcp::Time (0, 0, 7, 191, 250)); BOOST_REQUIRE_EQUAL (s.size(), 2); BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString ( diff --git a/test/recovery_test.cc b/test/recovery_test.cc index 566bbf21..cd7d3d92 100644 --- a/test/recovery_test.cc +++ b/test/recovery_test.cc @@ -44,8 +44,8 @@ BOOST_AUTO_TEST_CASE (recovery) #ifdef LIBDCP_POSIX /* XXX: fix this posix-only stuff */ Kumu::ResetTestRNG (); -#endif - +#endif + boost::filesystem::remove_all ("build/test/baz"); boost::filesystem::create_directories ("build/test/baz"); shared_ptr mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1))); @@ -72,9 +72,9 @@ BOOST_AUTO_TEST_CASE (recovery) fclose (f); } -#ifdef LIBDCP_POSIX +#ifdef LIBDCP_POSIX Kumu::ResetTestRNG (); -#endif +#endif mp.reset (new dcp::MonoPictureAsset (dcp::Fraction (24, 1))); writer = mp->start_write ("build/test/baz/video2.mxf", dcp::SMPTE, true); @@ -88,6 +88,6 @@ BOOST_AUTO_TEST_CASE (recovery) for (int i = 4; i < 24; ++i) { writer->write (data, size); } - + writer->finalize (); } diff --git a/test/rewrite_subs.cc b/test/rewrite_subs.cc index 6aa259a9..4cfc0c62 100644 --- a/test/rewrite_subs.cc +++ b/test/rewrite_subs.cc @@ -41,16 +41,16 @@ main (int argc, char* argv[]) cerr << "Syntax: " << argv[0] << " \n"; exit (EXIT_FAILURE); } - + DCP* dcp = new DCP (argv[1]); dcp->read (true); - + list > cpls = dcp->cpls (); for (list >::iterator i = cpls.begin(); i != cpls.end(); ++i) { - + list > reels = (*i)->reels (); for (list >::iterator j = reels.begin(); j != reels.end(); ++j) { - + if ((*j)->main_subtitle()) { (*j)->main_subtitle()->subtitle_asset()->write ((*j)->main_subtitle()->subtitle_asset()->file ()); } @@ -68,6 +68,6 @@ main (int argc, char* argv[]) cerr << e.what() << " when reading " << argv[1] << "\n"; exit (EXIT_FAILURE); } - + return 0; } diff --git a/test/rgb_xyz_test.cc b/test/rgb_xyz_test.cc index ca1378c8..c08d4979 100644 --- a/test/rgb_xyz_test.cc +++ b/test/rgb_xyz_test.cc @@ -118,7 +118,7 @@ note_handler (dcp::NoteType n, string s) BOOST_AUTO_TEST_CASE (xyz_rgb_range_test) { shared_ptr xyz (new dcp::OpenJPEGImage (dcp::Size (2, 2))); - + xyz->data(0)[0] = -4; xyz->data(0)[1] = 6901; xyz->data(0)[2] = 0; @@ -185,12 +185,12 @@ BOOST_AUTO_TEST_CASE (rgb_xyz_round_trip_test) scoped_array back (new uint8_t[size.width * size.height * 6]); dcp::xyz_to_rgb (xyz, dcp::ColourConversion::srgb_to_xyz (), back.get(), size.width * 6); -#if 0 +#if 0 uint16_t* p = reinterpret_cast (rgb.get ()); uint16_t* q = reinterpret_cast (back.get ()); for (int i = 0; i < (size.width * size.height); ++i) { /* XXX: doesn't quite work */ // BOOST_REQUIRE_EQUAL (*p++, *q++); } -#endif +#endif } diff --git a/test/round_trip_test.cc b/test/round_trip_test.cc index 2d10764a..90671d79 100644 --- a/test/round_trip_test.cc +++ b/test/round_trip_test.cc @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE (round_trip_test) scoped_array frame_A (new uint8_t[xyz_A->size().width * xyz_A->size().height * 4]); dcp::xyz_to_rgba (xyz_A, dcp::ColourConversion::srgb_to_xyz(), frame_A.get()); - + scoped_array frame_B (new uint8_t[xyz_B->size().width * xyz_B->size().height * 4]); dcp::xyz_to_rgba (xyz_B, dcp::ColourConversion::srgb_to_xyz(), frame_B.get()); diff --git a/test/test.cc b/test/test.cc index c83c1048..38e9c00e 100644 --- a/test/test.cc +++ b/test/test.cc @@ -118,14 +118,14 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check) BOOST_CHECK (ref_file); FILE* check_file = dcp::fopen_boost (check, "rb"); BOOST_CHECK (check_file); - + int const buffer_size = 65536; uint8_t* ref_buffer = new uint8_t[buffer_size]; uint8_t* check_buffer = new uint8_t[buffer_size]; stringstream error; error << "File " << check.string() << " differs from reference " << ref.string(); - + while (N) { uintmax_t this_time = min (uintmax_t (buffer_size), N); size_t r = fread (ref_buffer, 1, this_time, ref_file); @@ -137,7 +137,7 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check) if (memcmp (ref_buffer, check_buffer, this_time)) { break; } - + N -= this_time; } diff --git a/test/util_test.cc b/test/util_test.cc index d7c41a6a..eea1c799 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -28,7 +28,7 @@ using std::string; BOOST_AUTO_TEST_CASE (base64_decode_test) { int const N = 256; - + ifstream f ("test/data/base64_test"); BOOST_CHECK (f.good ()); string s; @@ -79,11 +79,11 @@ BOOST_AUTO_TEST_CASE (relative_to_root_test) { boost::filesystem::path root = "a"; root /= "b"; - + boost::filesystem::path file = "a"; file /= "b"; file /= "c"; - + boost::optional rel = dcp::relative_to_root (root, file); BOOST_CHECK (rel); BOOST_CHECK_EQUAL (rel.get(), boost::filesystem::path ("c")); @@ -93,21 +93,21 @@ BOOST_AUTO_TEST_CASE (relative_to_root_test) boost::filesystem::path root = "a"; root /= "b"; root /= "c"; - + boost::filesystem::path file = "a"; file /= "b"; - + boost::optional rel = dcp::relative_to_root (root, file); BOOST_CHECK (!rel); } { boost::filesystem::path root = "a"; - + boost::filesystem::path file = "a"; file /= "b"; file /= "c"; - + boost::optional rel = dcp::relative_to_root (root, file); BOOST_CHECK (rel); diff --git a/test/write_subtitle_test.cc b/test/write_subtitle_test.cc index 577eadec..d2402262 100644 --- a/test/write_subtitle_test.cc +++ b/test/write_subtitle_test.cc @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE (write_subtitle_test) dcp::Time (5, 6, 7, 8, 24) ) ); - + c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6"; check_xml ( -- cgit v1.2.3 From 81312913ad26aaee12eeabd3f27a537806c97049 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 24 Jun 2015 15:05:19 +0100 Subject: Fix various SNAFUs with Font ID handling. --- src/asset.cc | 7 +++++++ src/asset.h | 1 + src/dcp.cc | 2 +- src/font_asset.cc | 4 ++-- src/font_asset.h | 2 +- src/interop_subtitle_asset.cc | 23 +++++++++++++---------- src/interop_subtitle_asset.h | 2 +- src/smpte_subtitle_asset.cc | 23 +++++++++++++++-------- src/subtitle_asset.cc | 13 ++++--------- src/subtitle_asset.h | 34 ++++++++++++++++++---------------- test/dcp_font_test.cc | 6 +++--- tools/dcpdumpsub.cc | 2 +- 12 files changed, 67 insertions(+), 52 deletions(-) (limited to 'test') diff --git a/src/asset.cc b/src/asset.cc index 3d397831..6a15f216 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -49,6 +49,13 @@ Asset::Asset (boost::filesystem::path file) } +Asset::Asset (string id, boost::filesystem::path file) + : Object (id) + , _file (file) +{ + +} + void Asset::write_to_pkl (xmlpp::Node* node, Standard standard) const { diff --git a/src/asset.h b/src/asset.h index 12fe2657..f5b60bf7 100644 --- a/src/asset.h +++ b/src/asset.h @@ -47,6 +47,7 @@ class Asset : public Object public: Asset (); Asset (boost::filesystem::path file); + Asset (std::string id, boost::filesystem::path file); virtual bool equals ( boost::shared_ptr other, diff --git a/src/dcp.cc b/src/dcp.cc index c1675401..b710d61b 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -176,7 +176,7 @@ DCP::read (bool keep_going, ReadErrors* errors) throw DCPReadError ("Unknown MXF essence type"); } } else if (boost::filesystem::extension (path) == ".ttf") { - other_assets.push_back (shared_ptr (new FontAsset (path))); + other_assets.push_back (shared_ptr (new FontAsset (i->first, path))); } } diff --git a/src/font_asset.cc b/src/font_asset.cc index 8f8e4ff3..2cd03f27 100644 --- a/src/font_asset.cc +++ b/src/font_asset.cc @@ -27,8 +27,8 @@ using std::string; using namespace dcp; -FontAsset::FontAsset (boost::filesystem::path file) - : Asset (file) +FontAsset::FontAsset (string id, boost::filesystem::path file) + : Asset (id, file) { } diff --git a/src/font_asset.h b/src/font_asset.h index d0999322..8abd6047 100644 --- a/src/font_asset.h +++ b/src/font_asset.h @@ -31,7 +31,7 @@ namespace dcp { class FontAsset : public Asset { public: - FontAsset (boost::filesystem::path file); + FontAsset (std::string id, boost::filesystem::path file); private: std::string pkl_type (Standard standard) const; diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index ffa7d50b..a3850f04 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -90,10 +90,10 @@ InteropSubtitleAsset::xml_as_string () const } void -InteropSubtitleAsset::add_font (string id, boost::filesystem::path file) +InteropSubtitleAsset::add_font (string load_id, boost::filesystem::path file) { - add_font_data (id, file); - _load_font_nodes.push_back (shared_ptr (new InteropLoadFontNode (id, file.leaf().string ()))); + _fonts.push_back (Font (load_id, make_uuid(), file)); + _load_font_nodes.push_back (shared_ptr (new InteropLoadFontNode (load_id, file.leaf().string ()))); } bool @@ -163,10 +163,13 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const if (!f) { throw FileError ("could not open font file for writing", file, errno); } - map::const_iterator j = _fonts.find (i->id); + list::const_iterator j = _fonts.begin (); + while (j->load_id != i->id) { + ++j; + } if (j != _fonts.end ()) { - fwrite (j->second.data.get(), 1, j->second.size, f); - j->second.file = file; + fwrite (j->data.data.get(), 1, j->data.size, f); + j->file = file; } fclose (f); } @@ -183,7 +186,7 @@ InteropSubtitleAsset::resolve_fonts (list > objects) BOOST_FOREACH (shared_ptr j, _load_font_nodes) { if (j->uri == font->file().leaf().string ()) { - add_font_data (j->id, font->file ()); + _fonts.push_back (Font (j->id, i->id(), font->file ())); } } } @@ -192,8 +195,8 @@ InteropSubtitleAsset::resolve_fonts (list > objects) void InteropSubtitleAsset::add_font_assets (list >& assets) { - for (map::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { - DCP_ASSERT (i->second.file); - assets.push_back (shared_ptr (new FontAsset (i->second.file.get ()))); + BOOST_FOREACH (Font const & i, _fonts) { + DCP_ASSERT (i.file); + assets.push_back (shared_ptr (new FontAsset (i.uuid, i.file.get ()))); } } diff --git a/src/interop_subtitle_asset.h b/src/interop_subtitle_asset.h index 41ed83b3..8690d11c 100644 --- a/src/interop_subtitle_asset.h +++ b/src/interop_subtitle_asset.h @@ -47,7 +47,7 @@ public: std::list > load_font_nodes () const; - void add_font (std::string id, boost::filesystem::path file); + void add_font (std::string load_id, boost::filesystem::path file); Glib::ustring 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 8ea68362..8c0ce111 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -144,7 +144,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file) } if (j != _load_font_nodes.end ()) { - _fonts[(*j)->id] = FileData (data, buffer.Size ()); + _fonts.push_back (Font ((*j)->id, (*j)->urn, Data (data, buffer.Size ()))); } } } @@ -217,7 +217,10 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const descriptor.EncodingName = "UTF-8"; BOOST_FOREACH (shared_ptr i, _load_font_nodes) { - map::const_iterator j = _fonts.find (i->id); + list::const_iterator j = _fonts.begin (); + while (j != _fonts.end() && j->load_id != i->id) { + ++j; + } if (j != _fonts.end ()) { ASDCP::TimedText::TimedTextResourceDescriptor res; unsigned int c; @@ -245,11 +248,14 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const } BOOST_FOREACH (shared_ptr i, _load_font_nodes) { - map::const_iterator j = _fonts.find (i->id); + list::const_iterator j = _fonts.begin (); + while (j != _fonts.end() && j->load_id != i->id) { + ++j; + } if (j != _fonts.end ()) { ASDCP::TimedText::FrameBuffer buffer; - buffer.SetData (j->second.data.get(), j->second.size); - buffer.Size (j->second.size); + buffer.SetData (j->data.data.get(), j->data.size); + buffer.Size (j->data.size); r = writer.WriteAncillaryResource (buffer); if (ASDCP_FAILURE (r)) { boost::throw_exception (MXFFileError ("could not write font to timed text resource", p.string(), r)); @@ -341,8 +347,9 @@ SMPTESubtitleAsset::equals (shared_ptr other_asset, EqualityOptions } void -SMPTESubtitleAsset::add_font (string id, boost::filesystem::path file) +SMPTESubtitleAsset::add_font (string load_id, boost::filesystem::path file) { - add_font_data (id, file); - _load_font_nodes.push_back (shared_ptr (new SMPTELoadFontNode (id, make_uuid ()))); + string const uuid = make_uuid (); + _fonts.push_back (Font (load_id, uuid, file)); + _load_font_nodes.push_back (shared_ptr (new SMPTELoadFontNode (load_id, uuid))); } diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 367c3455..c0ffb75a 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include using std::string; @@ -308,18 +309,12 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, strin } } -void -SubtitleAsset::add_font_data (string id, boost::filesystem::path file) -{ - _fonts[id] = FileData (file); -} - map -SubtitleAsset::fonts () const +SubtitleAsset::fonts_with_load_ids () const { map out; - for (map::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { - out[i->first] = i->second; + BOOST_FOREACH (Font const & i, _fonts) { + out[i.load_id] = i.data; } return out; } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 31afecb3..51385b22 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -70,7 +70,7 @@ public: void add (SubtitleString); virtual void add_font (std::string id, boost::filesystem::path file) = 0; - std::map fonts () const; + std::map fonts_with_load_ids () const; virtual void write (boost::filesystem::path) const = 0; virtual Glib::ustring xml_as_string () const = 0; @@ -85,32 +85,34 @@ protected: void parse_subtitles (boost::shared_ptr xml, std::list > font_nodes); void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, std::string xmlns) const; - void add_font_data (std::string id, boost::filesystem::path file); /** All our subtitles, in no particular order */ std::list _subtitles; - class FileData : public Data { + class Font + { public: - FileData () {} - - FileData (boost::shared_array data_, boost::uintmax_t size_) - : Data (data_, size_) + Font (std::string load_id_, std::string uuid_, boost::filesystem::path file_) + : load_id (load_id_) + , uuid (uuid_) + , data (file_) + , file (file_) {} - FileData (boost::filesystem::path file_) - : Data (file_) + Font (std::string load_id_, std::string uuid_, Data data_) + : load_id (load_id_) + , uuid (uuid_) + , data (data_) {} - - /** .ttf file that this data was last written to */ + + std::string load_id; + std::string uuid; + Data data; + /** .ttf file that this data was last written to, if applicable */ mutable boost::optional file; }; - /** Font data, keyed by a subclass-dependent identifier. - * For Interop, the string is the font ID from the subtitle file. - * For SMPTE, the string is the font's URN from the subtitle file. - */ - std::map _fonts; + std::list _fonts; private: /** @struct ParseState diff --git a/test/dcp_font_test.cc b/test/dcp_font_test.cc index 5be8845d..daa16940 100644 --- a/test/dcp_font_test.cc +++ b/test/dcp_font_test.cc @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE (interop_dcp_font_test) fread (ref.get(), 1, size, f); fclose (f); - BOOST_CHECK_EQUAL (memcmp (subs2->_fonts["theFontId"].data.get(), ref.get(), size), 0); + BOOST_CHECK_EQUAL (memcmp (subs2->_fonts.front().data.data.get(), ref.get(), size), 0); } /** Create a DCP with SMPTE subtitles and check that the font is written and read back correctly */ @@ -106,6 +106,6 @@ BOOST_AUTO_TEST_CASE (smpte_dcp_font_test) fread (ref.get(), 1, size, f); fclose (f); - BOOST_REQUIRE (subs2->_fonts["theFontId"].data); - BOOST_CHECK_EQUAL (memcmp (subs2->_fonts["theFontId"].data.get(), ref.get(), size), 0); + BOOST_REQUIRE (subs2->_fonts.front().data.data); + BOOST_CHECK_EQUAL (memcmp (subs2->_fonts.front().data.data.get(), ref.get(), size), 0); } diff --git a/tools/dcpdumpsub.cc b/tools/dcpdumpsub.cc index 8cc9c90e..ac9c2522 100644 --- a/tools/dcpdumpsub.cc +++ b/tools/dcpdumpsub.cc @@ -76,7 +76,7 @@ main (int argc, char* argv[]) cout << sub.xml_as_string() << "\n"; if (extract_fonts) { - map fonts = sub.fonts (); + map fonts = sub.fonts_with_load_ids (); for (map::const_iterator i = fonts.begin(); i != fonts.end(); ++i) { FILE* f = dcp::fopen_boost (i->first + ".ttf", "wb"); if (!f) { -- cgit v1.2.3