}
+Asset::Asset (string id, boost::filesystem::path file)
+ : Object (id)
+ , _file (file)
+{
+
+}
+
void
Asset::write_to_pkl (xmlpp::Node* node, Standard standard) const
{
public:
Asset ();
Asset (boost::filesystem::path file);
+ Asset (std::string id, boost::filesystem::path file);
virtual bool equals (
boost::shared_ptr<const Asset> other,
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)));
}
}
using namespace dcp;
-FontAsset::FontAsset (boost::filesystem::path file)
- : Asset (file)
+FontAsset::FontAsset (string id, boost::filesystem::path file)
+ : Asset (id, file)
{
}
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;
}
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
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);
}
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 ()));
}
}
}
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 ())));
}
}
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;
}
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 ())));
}
}
}
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;
}
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));
}
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)));
}
#include <libxml++/nodes/element.h>
#include <boost/algorithm/string.hpp>
#include <boost/shared_array.hpp>
+#include <boost/foreach.hpp>
#include <fstream>
using std::string;
}
}
-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;
}
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;
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
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 */
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);
}
cout << sub.xml_as_string() << "\n";
if (extract_fonts) {
- map<string, dcp::Data> fonts = sub.fonts ();
+ map<string, dcp::Data> fonts = sub.fonts_with_load_ids ();
for (map<string, dcp::Data>::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
FILE* f = dcp::fopen_boost (i->first + ".ttf", "wb");
if (!f) {