diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dcp_time.cc | 14 | ||||
| -rw-r--r-- | src/dcp_time.h | 3 | ||||
| -rw-r--r-- | src/interop_subtitle_asset.cc | 2 | ||||
| -rw-r--r-- | src/smpte_subtitle_asset.cc | 4 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 62 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 2 |
6 files changed, 66 insertions, 21 deletions
diff --git a/src/dcp_time.cc b/src/dcp_time.cc index 5e2e3121..19ab2de1 100644 --- a/src/dcp_time.cc +++ b/src/dcp_time.cc @@ -250,15 +250,21 @@ dcp::operator/ (Time a, Time const & b) return float (at) / bt; } -/** @return A string of the form h:m:s:e padded as in 00:00:00:000 */ +/** @return A string of the form h:m:s:e padded as in 00:00:00:000 (for Interop) or 00:00:00:00 (for SMPTE) */ string -Time::as_string () const +Time::as_string (Standard standard) const { stringstream str; str << setw(2) << setfill('0') << h << ":" << setw(2) << setfill('0') << m << ":" - << setw(2) << setfill('0') << s << ":" - << setw(3) << setfill('0') << e; + << setw(2) << setfill('0') << s << ":"; + + if (standard == SMPTE) { + str << setw(2) << setfill('0') << e; + } else { + str << setw(3) << setfill('0') << e; + } + return str.str (); } diff --git a/src/dcp_time.h b/src/dcp_time.h index 1221fb32..270177dd 100644 --- a/src/dcp_time.h +++ b/src/dcp_time.h @@ -24,6 +24,7 @@ #ifndef LIBDCP_TIME_H #define LIBDCP_TIME_H +#include "types.h" #include <stdint.h> #include <string> #include <iostream> @@ -71,7 +72,7 @@ public: int e; ///< editable units (where 1 editable unit is 1 / tcr_ seconds) int tcr; ///< timecode rate: the number of editable units per second. - std::string as_string () const; + std::string as_string (Standard standard) const; double as_seconds () const; int64_t as_editable_units (int tcr_) const; Time rebase (int tcr_) const; diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index fbdd839b..c6479612 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -84,7 +84,7 @@ InteropSubtitleAsset::xml_as_string () const load_font->set_attribute ("URI", (*i)->uri); } - subtitles_as_xml (root, 250, ""); + subtitles_as_xml (root, 250, INTEROP); return doc.write_to_string_formatted ("UTF-8"); } diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index c792506a..57caf927 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -202,7 +202,7 @@ SMPTESubtitleAsset::xml_as_string () const root->add_child("EditRate", "dcst")->add_child_text (_edit_rate.as_string ()); root->add_child("TimeCodeRate", "dcst")->add_child_text (raw_convert<string> (_time_code_rate)); if (_start_time) { - root->add_child("StartTime", "dcst")->add_child_text (_start_time.get().as_string ()); + root->add_child("StartTime", "dcst")->add_child_text (_start_time.get().as_string (SMPTE)); } BOOST_FOREACH (shared_ptr<SMPTELoadFontNode> i, _load_font_nodes) { @@ -211,7 +211,7 @@ SMPTESubtitleAsset::xml_as_string () const load_font->set_attribute ("ID", i->id); } - subtitles_as_xml (root->add_child ("SubtitleList", "dcst"), _time_code_rate, "dcst"); + subtitles_as_xml (root->add_child ("SubtitleList", "dcst"), _time_code_rate, SMPTE); return doc.write_to_string_formatted ("UTF-8"); } diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 077b5288..6a57f455 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -208,12 +208,17 @@ struct SubtitleSorter { } }; +/** @param standard Standard (INTEROP or SMPTE); this is used rather than putting things in the child + * class because the differences between the two are fairly subtle. + */ void -SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, string xmlns) const +SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Standard standard) const { list<SubtitleString> sorted = _subtitles; sorted.sort (SubtitleSorter ()); + string const xmlns = standard == SMPTE ? "dcst" : ""; + /* XXX: script, underlined, weight not supported */ optional<string> font; @@ -261,7 +266,11 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, strin if (!font_element || font_changed) { font_element = root->add_child ("Font", xmlns); if (font) { - font_element->set_attribute ("Id", font.get ()); + if (standard == SMPTE) { + font_element->set_attribute ("ID", font.get ()); + } else { + font_element->set_attribute ("Id", font.get ()); + } } font_element->set_attribute ("Italic", italic ? "yes" : "no"); font_element->set_attribute ("Color", colour.to_argb_string()); @@ -272,7 +281,11 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, strin font_element->set_attribute ("Effect", effect_to_string (effect)); font_element->set_attribute ("EffectColor", effect_colour.to_argb_string()); font_element->set_attribute ("Script", "normal"); - font_element->set_attribute ("Underlined", "no"); + if (standard == SMPTE) { + font_element->set_attribute ("Underline", "no"); + } else { + font_element->set_attribute ("Underlined", "no"); + } font_element->set_attribute ("Weight", "normal"); } @@ -285,10 +298,15 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, strin subtitle_element = font_element->add_child ("Subtitle", xmlns); subtitle_element->set_attribute ("SpotNumber", raw_convert<string> (spot_number++)); - subtitle_element->set_attribute ("TimeIn", i->in().rebase(time_code_rate).as_string()); - subtitle_element->set_attribute ("TimeOut", i->out().rebase(time_code_rate).as_string()); - subtitle_element->set_attribute ("FadeUpTime", raw_convert<string> (i->fade_up_time().as_editable_units(time_code_rate))); - subtitle_element->set_attribute ("FadeDownTime", raw_convert<string> (i->fade_down_time().as_editable_units(time_code_rate))); + subtitle_element->set_attribute ("TimeIn", i->in().rebase(time_code_rate).as_string(standard)); + subtitle_element->set_attribute ("TimeOut", i->out().rebase(time_code_rate).as_string(standard)); + if (standard == SMPTE) { + subtitle_element->set_attribute ("FadeUpTime", i->fade_up_time().rebase(time_code_rate).as_string(standard)); + subtitle_element->set_attribute ("FadeDownTime", i->fade_down_time().rebase(time_code_rate).as_string(standard)); + } else { + subtitle_element->set_attribute ("FadeUpTime", raw_convert<string> (i->fade_up_time().as_editable_units(time_code_rate))); + subtitle_element->set_attribute ("FadeDownTime", raw_convert<string> (i->fade_down_time().as_editable_units(time_code_rate))); + } last_in = i->in (); last_out = i->out (); @@ -298,16 +316,36 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, strin xmlpp::Element* text = subtitle_element->add_child ("Text", xmlns); if (i->h_align() != HALIGN_CENTER) { - text->set_attribute ("HAlign", halign_to_string (i->h_align ())); + if (standard == SMPTE) { + text->set_attribute ("Halign", halign_to_string (i->h_align ())); + } else { + text->set_attribute ("HAlign", halign_to_string (i->h_align ())); + } } if (i->h_position() > ALIGN_EPSILON) { - text->set_attribute ("HPosition", raw_convert<string> (i->h_position() * 100, 6)); + if (standard == SMPTE) { + text->set_attribute ("Hposition", raw_convert<string> (i->h_position() * 100, 6)); + } else { + text->set_attribute ("HPosition", raw_convert<string> (i->h_position() * 100, 6)); + } + } + if (standard == SMPTE) { + text->set_attribute ("Valign", valign_to_string (i->v_align())); + } else { + text->set_attribute ("VAlign", valign_to_string (i->v_align())); } - text->set_attribute ("VAlign", valign_to_string (i->v_align())); if (i->v_position() > ALIGN_EPSILON) { - text->set_attribute ("VPosition", raw_convert<string> (i->v_position() * 100, 6)); + if (standard == SMPTE) { + text->set_attribute ("Vposition", raw_convert<string> (i->v_position() * 100, 6)); + } else { + text->set_attribute ("VPosition", raw_convert<string> (i->v_position() * 100, 6)); + } } else { - text->set_attribute ("VPosition", "0"); + if (standard == SMPTE) { + text->set_attribute ("Vposition", "0"); + } else { + text->set_attribute ("VPosition", "0"); + } } text->add_child_text (i->text()); } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 69bf40f8..88dc427b 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -84,7 +84,7 @@ protected: friend struct ::smpte_dcp_font_test; 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 subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Standard standard) const; /** All our subtitles, in no particular order */ std::list<SubtitleString> _subtitles; |
