summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-06-24 15:05:19 +0100
committerCarl Hetherington <cth@carlh.net>2015-06-24 15:05:19 +0100
commit81312913ad26aaee12eeabd3f27a537806c97049 (patch)
tree8a58899a4df44bc88f85d52707152934cc0ccb51 /src
parent094117316524f12fc82adbdf721778eed04e66f6 (diff)
Fix various SNAFUs with Font ID handling.
Diffstat (limited to 'src')
-rw-r--r--src/asset.cc7
-rw-r--r--src/asset.h1
-rw-r--r--src/dcp.cc2
-rw-r--r--src/font_asset.cc4
-rw-r--r--src/font_asset.h2
-rw-r--r--src/interop_subtitle_asset.cc23
-rw-r--r--src/interop_subtitle_asset.h2
-rw-r--r--src/smpte_subtitle_asset.cc23
-rw-r--r--src/subtitle_asset.cc13
-rw-r--r--src/subtitle_asset.h34
10 files changed, 63 insertions, 48 deletions
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<const Asset> 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<FontAsset> (new FontAsset (path)));
+ other_assets.push_back (shared_ptr<FontAsset> (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<InteropLoadFontNode> (new InteropLoadFontNode (id, file.leaf().string ())));
+ _fonts.push_back (Font (load_id, make_uuid(), file));
+ _load_font_nodes.push_back (shared_ptr<InteropLoadFontNode> (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<string, FileData>::const_iterator j = _fonts.find (i->id);
+ list<Font>::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<shared_ptr<Object> > objects)
BOOST_FOREACH (shared_ptr<InteropLoadFontNode> 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<shared_ptr<Object> > objects)
void
InteropSubtitleAsset::add_font_assets (list<shared_ptr<Asset> >& assets)
{
- for (map<string, FileData>::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) {
- DCP_ASSERT (i->second.file);
- assets.push_back (shared_ptr<FontAsset> (new FontAsset (i->second.file.get ())));
+ BOOST_FOREACH (Font const & i, _fonts) {
+ DCP_ASSERT (i.file);
+ assets.push_back (shared_ptr<FontAsset> (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<boost::shared_ptr<LoadFontNode> > 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<dcp::SMPTELoadFontNode> i, _load_font_nodes) {
- map<string, FileData>::const_iterator j = _fonts.find (i->id);
+ list<Font>::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<dcp::SMPTELoadFontNode> i, _load_font_nodes) {
- map<string, FileData>::const_iterator j = _fonts.find (i->id);
+ list<Font>::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<const Asset> 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<SMPTELoadFontNode> (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<SMPTELoadFontNode> (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 <libxml++/nodes/element.h>
#include <boost/algorithm/string.hpp>
#include <boost/shared_array.hpp>
+#include <boost/foreach.hpp>
#include <fstream>
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<string, Data>
-SubtitleAsset::fonts () const
+SubtitleAsset::fonts_with_load_ids () const
{
map<string, Data> out;
- for (map<string, FileData>::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<std::string, Data> fonts () const;
+ std::map<std::string, Data> 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<cxml::Document> xml, std::list<boost::shared_ptr<FontNode> > 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<SubtitleString> _subtitles;
- class FileData : public Data {
+ class Font
+ {
public:
- FileData () {}
-
- FileData (boost::shared_array<uint8_t> 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<boost::filesystem::path> 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<std::string, FileData> _fonts;
+ std::list<Font> _fonts;
private:
/** @struct ParseState