From 8526058d24faec5f83ffd66758fef8d8c8159f73 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 13 May 2013 15:57:00 +0100 Subject: Use libxml++ for writing XML. --- src/asset.cc | 37 +++++++-------- src/asset.h | 7 +-- src/cpl.cc | 75 +++++++++++++++---------------- src/cpl.h | 5 ++- src/dcp.cc | 92 ++++++++++++++++++-------------------- src/picture_asset.cc | 21 +++++---- src/picture_asset.h | 6 +-- src/reel.cc | 17 +++---- src/reel.h | 3 +- src/sound_asset.cc | 17 ++++--- src/sound_asset.h | 6 +-- src/subtitle_asset.cc | 121 ++++++++++++++++++++++---------------------------- src/subtitle_asset.h | 5 +-- 13 files changed, 192 insertions(+), 220 deletions(-) (limited to 'src') diff --git a/src/asset.cc b/src/asset.cc index 58c821a7..84bdd2bd 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include "AS_DCP.h" #include "KM_util.h" #include "asset.h" @@ -50,31 +51,27 @@ Asset::Asset (string directory, string file_name, int edit_rate, int intrinsic_d } void -Asset::write_to_pkl (ostream& s) const +Asset::write_to_pkl (xmlpp::Node* node) const { - s << " \n" - << " urn:uuid:" << _uuid << "\n" - << " " << _file_name << "\n" - << " " << digest() << "\n" - << " " << filesystem::file_size(path()) << "\n" - << " application/mxf\n" - << " \n"; + xmlpp::Node* asset = node->add_child ("Asset"); + asset->add_child("Id")->add_child_text ("urn:uuid:" + _uuid); + asset->add_child("AnnotationText")->add_child_text (_file_name); + asset->add_child("Hash")->add_child_text (digest ()); + asset->add_child("Size")->add_child_text (lexical_cast (filesystem::file_size(path()))); + asset->add_child("Type")->add_child_text ("application/mxf"); } void -Asset::write_to_assetmap (ostream& s) const +Asset::write_to_assetmap (xmlpp::Node* node) const { - s << " \n" - << " urn:uuid:" << _uuid << "\n" - << " \n" - << " \n" - << " " << _file_name << "\n" - << " 1\n" - << " 0\n" - << " " << filesystem::file_size(path()) << "\n" - << " \n" - << " \n" - << " \n"; + xmlpp::Node* asset = node->add_child ("Asset"); + asset->add_child("Id")->add_child_text ("urn:uuid:" + _uuid); + xmlpp::Node* chunk_list = asset->add_child ("ChunkList"); + xmlpp::Node* chunk = chunk_list->add_child ("Chunk"); + chunk->add_child("Path")->add_child_text (_file_name); + chunk->add_child("VolumeIndex")->add_child_text ("1"); + chunk->add_child("Offset")->add_child_text ("0"); + chunk->add_child("Length")->add_child_text (lexical_cast (filesystem::file_size(path()))); } filesystem::path diff --git a/src/asset.h b/src/asset.h index 06c66356..3bc713a3 100644 --- a/src/asset.h +++ b/src/asset.h @@ -28,6 +28,7 @@ #include #include #include +#include #include "types.h" namespace ASDCP { @@ -55,17 +56,17 @@ public: /** Write details of the asset to a CPL stream. * @param s Stream. */ - virtual void write_to_cpl (std::ostream& s) const = 0; + virtual void write_to_cpl (xmlpp::Node *) const = 0; /** Write details of the asset to a PKL stream. * @param s Stream. */ - void write_to_pkl (std::ostream& s) const; + void write_to_pkl (xmlpp::Node *) const; /** Write details of the asset to a ASSETMAP stream. * @param s Stream. */ - void write_to_assetmap (std::ostream& s) const; + void write_to_assetmap (xmlpp::Node *) const; std::string uuid () const { return _uuid; diff --git a/src/cpl.cc b/src/cpl.cc index 3a2ad0b3..e7eb1ced 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -34,6 +34,7 @@ using std::ofstream; using std::ostream; using std::list; using boost::shared_ptr; +using boost::lexical_cast; using namespace libdcp; CPL::CPL (string directory, string name, ContentKind content_kind, int length, int frames_per_second) @@ -180,45 +181,42 @@ CPL::write_xml (XMLMetadata const & metadata) const stringstream s; s << _uuid << "_cpl.xml"; p /= s.str(); - ofstream os (p.string().c_str()); - - os << "\n" - << "\n" - << " urn:uuid:" << _uuid << "\n" - << " " << _name << "\n" - << " " << metadata.issue_date << "\n" - << " " << metadata.creator << "\n" - << " " << _name << "\n" - << " " << content_kind_to_string (_content_kind) << "\n" - << " \n" - << " urn:uri:" << _uuid << "_" << metadata.issue_date << "\n" - << " " << _uuid << "_" << metadata.issue_date << "\n" - << " \n" - << " \n" - << " \n"; + + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("CompositionPlaylist", "http://www.smpte-ra.org/schemas/429-7/2006/CPL"); + root->add_child("Id")->add_child_text ("urn:uuid:" + _uuid); + root->add_child("AnnotationText")->add_child_text (_name); + root->add_child("IssueDate")->add_child_text (metadata.issue_date); + root->add_child("Creator")->add_child_text (metadata.creator); + root->add_child("ContentTitleText")->add_child_text (_name); + root->add_child("ContentKind")->add_child_text (content_kind_to_string (_content_kind)); + { + xmlpp::Node* cv = root->add_child ("ContentVersion"); + cv->add_child ("Id")->add_child_text ("urn:uri:" + _uuid + "_" + metadata.issue_date); + cv->add_child ("LabelText")->add_child_text (_uuid + "_" + metadata.issue_date); + } + root->add_child("RatingList"); + + xmlpp::Node* reel_list = root->add_child ("ReelList"); for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { - (*i)->write_to_cpl (os); + (*i)->write_to_cpl (reel_list); } - os << " \n" - << "\n"; - - os.close (); + doc.write_to_file_formatted (p.string (), "UTF-8"); _digest = make_digest (p.string ()); _length = boost::filesystem::file_size (p.string ()); } void -CPL::write_to_pkl (ostream& s) const +CPL::write_to_pkl (xmlpp::Node* node) const { - s << " \n" - << " urn:uuid:" << _uuid << "\n" - << " " << _digest << "\n" - << " " << _length << "\n" - << " text/xml\n" - << " \n"; + xmlpp::Node* asset = node->add_child ("Asset"); + asset->add_child("Id")->add_child_text ("urn:uuid:" + _uuid); + asset->add_child("Hash")->add_child_text (_digest); + asset->add_child("Size")->add_child_text (lexical_cast (_length)); + asset->add_child("Type")->add_child_text ("text/xml"); } list > @@ -241,19 +239,16 @@ CPL::assets () const } void -CPL::write_to_assetmap (ostream& s) const +CPL::write_to_assetmap (xmlpp::Node* node) const { - s << " \n" - << " urn:uuid:" << _uuid << "\n" - << " \n" - << " \n" - << " " << _uuid << "_cpl.xml\n" - << " 1\n" - << " 0\n" - << " " << _length << "\n" - << " \n" - << " \n" - << " \n"; + xmlpp::Node* asset = node->add_child ("Asset"); + asset->add_child("Id")->add_child_text ("urn:uuid:" + _uuid); + xmlpp::Node* chunk_list = asset->add_child ("ChunkList"); + xmlpp::Node* chunk = chunk_list->add_child ("Chunk"); + chunk->add_child("Path")->add_child_text (_uuid + "_cpl.xml"); + chunk->add_child("VolumeIndex")->add_child_text ("1"); + chunk->add_child("Offset")->add_child_text("0"); + chunk->add_child("Length")->add_child_text(lexical_cast (_length)); } diff --git a/src/cpl.h b/src/cpl.h index c04fd6ad..0c86b91e 100644 --- a/src/cpl.h +++ b/src/cpl.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "types.h" namespace libdcp { @@ -74,8 +75,8 @@ public: bool equals (CPL const & other, EqualityOptions options, boost::function note) const; void write_xml (XMLMetadata const &) const; - void write_to_assetmap (std::ostream& s) const; - void write_to_pkl (std::ostream& s) const; + void write_to_assetmap (xmlpp::Node *) const; + void write_to_pkl (xmlpp::Node *) const; private: std::string _directory; diff --git a/src/dcp.cc b/src/dcp.cc index 7a43e9b2..c7634b5d 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "dcp.h" #include "asset.h" @@ -48,6 +49,7 @@ using std::stringstream; using std::ofstream; using std::ostream; using boost::shared_ptr; +using boost::lexical_cast; using namespace libdcp; DCP::DCP (string directory) @@ -80,30 +82,29 @@ DCP::write_pkl (string pkl_uuid, XMLMetadata const & metadata) const stringstream s; s << pkl_uuid << "_pkl.xml"; p /= s.str(); - ofstream pkl (p.string().c_str()); - - pkl << "\n" - << "\n" - << " urn:uuid:" << pkl_uuid << "\n" - /* XXX: this is a bit of a hack */ - << " " << _cpls.front()->name() << "\n" - << " " << metadata.issue_date << "\n" - << " " << metadata.issuer << "\n" - << " " << metadata.creator << "\n" - << " \n"; + + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("PackingList", "http://www.smpte-ra.org/schemas/429-8/2007/PKL"); + + root->add_child("Id")->add_child_text ("urn:uuid:" + pkl_uuid); + /* XXX: this is a bit of a hack */ + root->add_child("AnnotationText")->add_child_text (_cpls.front()->name()); + root->add_child("IssueDate")->add_child_text (metadata.issue_date); + root->add_child("Issuer")->add_child_text (metadata.issuer); + root->add_child("Creator")->add_child_text (metadata.creator); + + xmlpp::Node* asset_list = root->add_child ("AssetList"); list > a = assets (); for (list >::const_iterator i = a.begin(); i != a.end(); ++i) { - (*i)->write_to_pkl (pkl); + (*i)->write_to_pkl (asset_list); } for (list >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { - (*i)->write_to_pkl (pkl); + (*i)->write_to_pkl (asset_list); } - pkl << " \n" - << "\n"; - + doc.write_to_file_formatted (p.string (), "UTF-8"); return p.string (); } @@ -113,12 +114,11 @@ DCP::write_volindex () const boost::filesystem::path p; p /= _directory; p /= "VOLINDEX.xml"; - ofstream vi (p.string().c_str()); - vi << "\n" - << "\n" - << " 1\n" - << "\n"; + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("VolumeIndex", "http://www.smpte-ra.org/schemas/429-9/2007/AM"); + root->add_child("Index")->add_child_text ("1"); + doc.write_to_file_formatted (p.string (), "UTF-8"); } void @@ -127,41 +127,37 @@ DCP::write_assetmap (string pkl_uuid, int pkl_length, XMLMetadata const & metada boost::filesystem::path p; p /= _directory; p /= "ASSETMAP.xml"; - ofstream am (p.string().c_str()); - - am << "\n" - << "\n" - << " urn:uuid:" << make_uuid() << "\n" - << " " << metadata.creator << "\n" - << " 1\n" - << " " << metadata.issue_date << "\n" - << " " << metadata.issuer << "\n" - << " \n"; - - am << " \n" - << " urn:uuid:" << pkl_uuid << "\n" - << " true\n" - << " \n" - << " \n" - << " " << pkl_uuid << "_pkl.xml\n" - << " 1\n" - << " 0\n" - << " " << pkl_length << "\n" - << " \n" - << " \n" - << " \n"; + + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("AssetMap", "http://www.smpte-ra.org/schemas/429-9/2007/AM"); + + root->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid()); + root->add_child("Creator")->add_child_text (metadata.creator); + root->add_child("VolumeCount")->add_child_text ("1"); + root->add_child("IssueDate")->add_child_text (metadata.issue_date); + root->add_child("Issuer")->add_child_text (metadata.issuer); + xmlpp::Node* asset_list = root->add_child ("AssetList"); + + xmlpp::Node* asset = asset_list->add_child ("Asset"); + asset->add_child("Id")->add_child_text ("urn:uuid:" + pkl_uuid); + asset->add_child("PackingList")->add_child_text ("true"); + xmlpp::Node* chunk_list = asset->add_child ("ChunkList"); + xmlpp::Node* chunk = chunk_list->add_child ("Chunk"); + chunk->add_child("Path")->add_child_text (pkl_uuid + "_pkl.xml"); + chunk->add_child("VolumeIndex")->add_child_text ("1"); + chunk->add_child("Offset")->add_child_text ("0"); + chunk->add_child("Length")->add_child_text (lexical_cast (pkl_length)); for (list >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { - (*i)->write_to_assetmap (am); + (*i)->write_to_assetmap (asset_list); } list > a = assets (); for (list >::const_iterator i = a.begin(); i != a.end(); ++i) { - (*i)->write_to_assetmap (am); + (*i)->write_to_assetmap (asset_list); } - am << " \n" - << "\n"; + doc.write_to_file_formatted (p.string (), "UTF-8"); } diff --git a/src/picture_asset.cc b/src/picture_asset.cc index 788e3dc4..72a63173 100644 --- a/src/picture_asset.cc +++ b/src/picture_asset.cc @@ -64,18 +64,17 @@ PictureAsset::PictureAsset (string directory, string mxf_name) } void -PictureAsset::write_to_cpl (ostream& s) const +PictureAsset::write_to_cpl (xmlpp::Node* node) const { - s << " \n" - << " urn:uuid:" << _uuid << "\n" - << " " << _file_name << "\n" - << " " << _edit_rate << " 1\n" - << " " << _intrinsic_duration << "\n" - << " " << _entry_point << "\n" - << " " << _duration << "\n" - << " " << _edit_rate << " 1\n" - << " " << _size.width << " " << _size.height << "\n" - << " \n"; + xmlpp::Node* mp = node->add_child ("MainPicture"); + mp->add_child ("Id")->add_child_text ("urn:uuid:" + _uuid); + mp->add_child ("AnnotationText")->add_child_text (_file_name); + mp->add_child ("EditRate")->add_child_text (lexical_cast (_edit_rate) + " 1"); + mp->add_child ("IntrinsicDuration")->add_child_text (lexical_cast (_intrinsic_duration)); + mp->add_child ("EntryPoint")->add_child_text (lexical_cast (_entry_point)); + mp->add_child ("Duration")->add_child_text (lexical_cast (_duration)); + mp->add_child ("FrameRate")->add_child_text (lexical_cast (_edit_rate) + " 1"); + mp->add_child ("ScreenAspectRatio")->add_child_text (lexical_cast (_size.width) + " " + lexical_cast (_size.height)); } bool diff --git a/src/picture_asset.h b/src/picture_asset.h index 59c4dc00..3edf3a1c 100644 --- a/src/picture_asset.h +++ b/src/picture_asset.h @@ -59,10 +59,10 @@ public: */ PictureAsset (std::string directory, std::string mxf_name, boost::signals2::signal* progress, int fps, int intrinsic_duration, Size size); - /** Write details of this asset to a CPL stream. - * @param s Stream. + /** Write details of this asset to a CPL XML node. + * @param node Node. */ - void write_to_cpl (std::ostream& s) const; + void write_to_cpl (xmlpp::Node* node) const; bool equals (boost::shared_ptr other, EqualityOptions opt, boost::function note) const; diff --git a/src/reel.cc b/src/reel.cc index 86533ea2..481b153b 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -27,26 +27,23 @@ using namespace std; using namespace libdcp; void -Reel::write_to_cpl (ostream& s) const +Reel::write_to_cpl (xmlpp::Node* node) const { - s << " \n" - << " urn:uuid:" << make_uuid() << "\n" - << " \n"; + xmlpp::Node* reel = node->add_child ("Reel"); + reel->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid()); + xmlpp::Node* asset_list = reel->add_child ("AssetList"); if (_main_picture) { - _main_picture->write_to_cpl (s); + _main_picture->write_to_cpl (asset_list); } if (_main_sound) { - _main_sound->write_to_cpl (s); + _main_sound->write_to_cpl (asset_list); } if (_main_subtitle) { - _main_subtitle->write_to_cpl (s); + _main_subtitle->write_to_cpl (asset_list); } - - s << " \n" - << " \n"; } bool diff --git a/src/reel.h b/src/reel.h index 93dc0920..49a756ad 100644 --- a/src/reel.h +++ b/src/reel.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "types.h" namespace libdcp { @@ -54,7 +55,7 @@ public: return _main_subtitle; } - void write_to_cpl (std::ostream & s) const; + void write_to_cpl (xmlpp::Node *) const; bool equals (boost::shared_ptr other, EqualityOptions opt, boost::function notes) const; diff --git a/src/sound_asset.cc b/src/sound_asset.cc index 9b6b48aa..4a7abd4d 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -211,16 +211,15 @@ SoundAsset::construct (boost::function get_path, MXFMetadata c } void -SoundAsset::write_to_cpl (ostream& s) const +SoundAsset::write_to_cpl (xmlpp::Node* node) const { - s << " \n" - << " urn:uuid:" << _uuid << "\n" - << " " << _file_name << "\n" - << " " << _edit_rate << " 1\n" - << " " << _intrinsic_duration << "\n" - << " " << _entry_point << "\n" - << " " << _duration << "\n" - << " \n"; + xmlpp::Node* ms = node->add_child ("MainSound"); + ms->add_child ("Id")->add_child_text ("urn:uuid:" + _uuid); + ms->add_child ("AnnotationText")->add_child_text (_file_name); + ms->add_child ("EditRate")->add_child_text (lexical_cast (_edit_rate) + " 1"); + ms->add_child ("IntrinsicDuration")->add_child_text (lexical_cast (_intrinsic_duration)); + ms->add_child ("EntryPoint")->add_child_text (lexical_cast (_entry_point)); + ms->add_child ("Duration")->add_child_text (lexical_cast (_duration)); } bool diff --git a/src/sound_asset.h b/src/sound_asset.h index 5c230e06..1e3553a0 100644 --- a/src/sound_asset.h +++ b/src/sound_asset.h @@ -127,10 +127,10 @@ public: boost::shared_ptr start_write (MXFMetadata const & metadata = MXFMetadata ()); - /** Write details of this asset to a CPL stream. - * @param s Stream. + /** Write details of this asset to a CPL XML node. + * @param node Node. */ - void write_to_cpl (std::ostream& s) const; + void write_to_cpl (xmlpp::Node* node) const; bool equals (boost::shared_ptr other, EqualityOptions opt, boost::function note) const; diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index d89d52de..5decc1e3 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -276,15 +276,15 @@ SubtitleAsset::add (shared_ptr s) } void -SubtitleAsset::write_to_cpl (ostream& s) const +SubtitleAsset::write_to_cpl (xmlpp::Node* node) const { /* XXX: should EditRate, Duration and IntrinsicDuration be in here? */ - - s << " \n" - << " urn:uuid:" << _uuid << "\n" - << " " << _file_name << "\n" - << " 0\n" - << " \n"; + + xmlpp::Node* ms = node->add_child ("MainSubtitle"); + ms->add_child("Id")->add_child_text("urn:uuid:" + _uuid); + ms->add_child("AnnotationText")->add_child_text (_file_name); + /* XXX */ + ms->add_child("EntryPoint")->add_child_text ("0"); } struct SubtitleSorter { @@ -299,26 +299,30 @@ struct SubtitleSorter { void SubtitleAsset::write_xml () const { - ofstream f (path().string().c_str()); - write_xml (f); + ofstream s (path().string().c_str()); + write_xml (s); } void SubtitleAsset::write_xml (ostream& s) const { - s << "\n" - << "\n" - << " " << _uuid << "\n" - << " " << _movie_title << "\n" - << " " << _reel_number << "\n" - << " " << _language << "\n"; + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("DCSubtitle"); + root->set_attribute ("Version", "1.0"); + + root->add_child("SubtitleID")->add_child_text (_uuid); + root->add_child("MovieTitle")->add_child_text (_movie_title); + root->add_child("ReelNumber")->add_child_text (lexical_cast (_reel_number)); + root->add_child("Language")->add_child_text (_language); if (_load_font_nodes.size() > 1) { boost::throw_exception (MiscError ("multiple LoadFont nodes not supported")); } if (!_load_font_nodes.empty ()) { - s << " id << "\" URI=\"" << _load_font_nodes.front()->uri << "\"/>\n"; + xmlpp::Element* load_font = root->add_child("LoadFont"); + load_font->set_attribute("Id", _load_font_nodes.front()->id); + load_font->set_attribute("URI", _load_font_nodes.front()->uri); } list > sorted = _subtitles; @@ -329,7 +333,6 @@ SubtitleAsset::write_xml (ostream& s) const /* XXX: multiple fonts not supported */ /* XXX: script, underlined, weight not supported */ - bool first = true; bool italic = false; Color color; int size = 0; @@ -341,66 +344,61 @@ SubtitleAsset::write_xml (ostream& s) const Time last_fade_up_time; Time last_fade_down_time; + xmlpp::Element* font = 0; + xmlpp::Element* subtitle = 0; + for (list >::iterator i = sorted.begin(); i != sorted.end(); ++i) { /* We will start a new ... whenever some font property changes. - I suppose should really make an optimal hierarchy of tags, but + I suppose we should really make an optimal hierarchy of tags, but that seems hard. */ - bool const font_changed = first || + bool const font_changed = italic != (*i)->italic() || color != (*i)->color() || size != (*i)->size() || effect != (*i)->effect() || effect_color != (*i)->effect_color(); - stringstream a; if (font_changed) { italic = (*i)->italic (); - a << "Italic=\"" << (italic ? "yes" : "no") << "\" "; color = (*i)->color (); - a << "Color=\"" << color.to_argb_string() << "\" "; size = (*i)->size (); - a << "Size=\"" << size << "\" "; effect = (*i)->effect (); - a << "Effect=\"" << effect_to_string(effect) << "\" "; effect_color = (*i)->effect_color (); - a << "EffectColor=\"" << effect_color.to_argb_string() << "\" "; - a << "Script=\"normal\" Underlined=\"no\" Weight=\"normal\""; } - if (first || font_changed || + if (!font || font_changed) { + font = root->add_child ("Font"); + string id = "theFontId"; + if (!_load_font_nodes.empty()) { + id = _load_font_nodes.front()->id; + } + font->set_attribute ("Id", id); + font->set_attribute ("Italic", italic ? "yes" : "no"); + font->set_attribute ("Color", color.to_argb_string()); + font->set_attribute ("Size", lexical_cast (size)); + font->set_attribute ("Effect", effect_to_string (effect)); + font->set_attribute ("EffectColor", effect_color.to_argb_string()); + font->set_attribute ("Script", "normal"); + font->set_attribute ("Underlined", "no"); + font->set_attribute ("Weight", "normal"); + } + + if (!subtitle || (last_in != (*i)->in() || last_out != (*i)->out() || last_fade_up_time != (*i)->fade_up_time() || last_fade_down_time != (*i)->fade_down_time() )) { - if (!first) { - s << " \n"; - } - - if (font_changed) { - if (!first) { - s << " \n"; - } - - string id = "theFontId"; - if (!_load_font_nodes.empty()) { - id = _load_font_nodes.front()->id; - } - - s << " \n"; - } - - s << " in().to_string() << "\" " - << "TimeOut=\"" << (*i)->out().to_string() << "\" " - << "FadeUpTime=\"" << (*i)->fade_up_time().to_ticks() << "\" " - << "FadeDownTime=\"" << (*i)->fade_down_time().to_ticks() << "\"" - << ">\n"; + subtitle = font->add_child ("Subtitle"); + subtitle->set_attribute ("SpotNumber", lexical_cast (spot_number++)); + subtitle->set_attribute ("TimeIn", (*i)->in().to_string()); + subtitle->set_attribute ("TimeOut", (*i)->out().to_string()); + subtitle->set_attribute ("FadeUpTime", lexical_cast ((*i)->fade_up_time().to_ticks())); + subtitle->set_attribute ("FadeDownTime", lexical_cast ((*i)->fade_down_time().to_ticks())); last_in = (*i)->in (); last_out = (*i)->out (); @@ -408,23 +406,12 @@ SubtitleAsset::write_xml (ostream& s) const last_fade_down_time = (*i)->fade_down_time (); } - s << " v_align()) << "\" " - << "VPosition=\"" << (*i)->v_position() << "\"" - << ">" << escape ((*i)->text()) << "\n"; - - first = false; + xmlpp::Element* text = subtitle->add_child ("Text"); + text->set_attribute ("VAlign", valign_to_string ((*i)->v_align())); + text->set_attribute ("VPosition", lexical_cast ((*i)->v_position())); + text->add_child_text ((*i)->text()); } - s << " \n"; - s << " \n"; - s << "\n"; + doc.write_to_stream_formatted (s); } -/** XXX: Another reason why we should be writing with libxml++ */ -string -SubtitleAsset::escape (string s) const -{ - boost::replace_all (s, "&", "&"); - return s; -} diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 0d662d6c..2da1ce7b 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -123,7 +123,7 @@ public: SubtitleAsset (std::string directory, std::string xml_file); SubtitleAsset (std::string directory, std::string movie_title, std::string language); - void write_to_cpl (std::ostream&) const; + void write_to_cpl (xmlpp::Node *) const; virtual bool equals (boost::shared_ptr, EqualityOptions, boost::function note) const { /* XXX */ note (ERROR, "subtitle assets not compared yet"); @@ -143,11 +143,10 @@ public: void read_xml (std::string); void write_xml () const; - void write_xml (std::ostream& s) const; + void write_xml (std::ostream &) const; private: std::string font_id_to_name (std::string id) const; - std::string escape (std::string) const; struct ParseState { std::list > font_nodes; -- cgit v1.2.3