diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-01-24 04:15:26 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-01-24 04:15:26 +0100 |
| commit | ceaf7bc52712cb60708ed5eb5c62c5e463dd8e89 (patch) | |
| tree | c55e4b85ee30138ce83263045d77d01631378b2e /src/subtitle_asset_internal.cc | |
| parent | 6c37cc1979b2a01205a888c4c98f3334685ee8dd (diff) | |
Tidying.
Diffstat (limited to 'src/subtitle_asset_internal.cc')
| -rw-r--r-- | src/subtitle_asset_internal.cc | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/subtitle_asset_internal.cc b/src/subtitle_asset_internal.cc index d7b16cbd..f1674789 100644 --- a/src/subtitle_asset_internal.cc +++ b/src/subtitle_asset_internal.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of libdcp. @@ -31,22 +31,31 @@ files in the program, then also delete it here. */ + +/** @file src/subtitle_asset_internal.cc + * @brief Internal SubtitleAsset helpers + */ + + #include "subtitle_asset_internal.h" #include "subtitle_string.h" #include "compose.hpp" #include <cmath> + using std::string; using std::map; using std::shared_ptr; using namespace dcp; + string order::Context::xmlns () const { return standard == Standard::SMPTE ? "dcst" : ""; } + order::Font::Font (shared_ptr<SubtitleString> s, Standard standard) { if (s->font()) { @@ -71,6 +80,7 @@ order::Font::Font (shared_ptr<SubtitleString> s, Standard standard) _values["Weight"] = s->bold() ? "bold" : "normal"; } + xmlpp::Element* order::Font::as_xml (xmlpp::Element* parent, Context& context) const { @@ -81,6 +91,7 @@ order::Font::as_xml (xmlpp::Element* parent, Context& context) const return e; } + /** Modify our values so that they contain only those that are common to us and * other. */ @@ -89,42 +100,46 @@ order::Font::take_intersection (Font other) { map<string, string> inter; - for (map<string, string>::const_iterator i = other._values.begin(); i != other._values.end(); ++i) { - map<string, string>::iterator t = _values.find (i->first); - if (t != _values.end() && t->second == i->second) { - inter.insert (*i); + for (auto const& i: other._values) { + auto t = _values.find (i.first); + if (t != _values.end() && t->second == i.second) { + inter.insert (i); } } _values = inter; } + /** Modify our values so that it contains only those keys that are not in other */ void order::Font::take_difference (Font other) { map<string, string> diff; - for (map<string, string>::const_iterator i = _values.begin(); i != _values.end(); ++i) { - if (other._values.find (i->first) == other._values.end ()) { - diff.insert (*i); + for (auto const& i: _values) { + if (other._values.find (i.first) == other._values.end()) { + diff.insert (i); } } _values = diff; } + bool order::Font::empty () const { return _values.empty (); } + xmlpp::Element* order::Part::as_xml (xmlpp::Element* parent, Context &) const { return parent; } + xmlpp::Element* order::String::as_xml (xmlpp::Element* parent, Context &) const { @@ -132,6 +147,7 @@ order::String::as_xml (xmlpp::Element* parent, Context &) const return 0; } + void order::Part::write_xml (xmlpp::Element* parent, order::Context& context) const { @@ -146,6 +162,7 @@ order::Part::write_xml (xmlpp::Element* parent, order::Context& context) const } } + static void position_align (xmlpp::Element* e, order::Context& context, HAlign h_align, float h_position, VAlign v_align, float v_position) { @@ -186,10 +203,11 @@ position_align (xmlpp::Element* e, order::Context& context, HAlign h_align, floa } } + xmlpp::Element* order::Text::as_xml (xmlpp::Element* parent, Context& context) const { - xmlpp::Element* e = parent->add_child ("Text", context.xmlns()); + auto e = parent->add_child ("Text", context.xmlns()); position_align (e, context, _h_align, _h_position, _v_align, _v_position); @@ -203,10 +221,11 @@ order::Text::as_xml (xmlpp::Element* parent, Context& context) const return e; } + xmlpp::Element* order::Subtitle::as_xml (xmlpp::Element* parent, Context& context) const { - xmlpp::Element* e = parent->add_child ("Subtitle", context.xmlns()); + auto e = parent->add_child ("Subtitle", context.xmlns()); e->set_attribute ("SpotNumber", raw_convert<string> (context.spot_number++)); e->set_attribute ("TimeIn", _in.rebase(context.time_code_rate).as_string(context.standard)); e->set_attribute ("TimeOut", _out.rebase(context.time_code_rate).as_string(context.standard)); @@ -220,22 +239,25 @@ order::Subtitle::as_xml (xmlpp::Element* parent, Context& context) const return e; } + bool order::Font::operator== (Font const & other) const { return _values == other._values; } + void order::Font::clear () { _values.clear (); } + xmlpp::Element * order::Image::as_xml (xmlpp::Element* parent, Context& context) const { - xmlpp::Element* e = parent->add_child ("Image", context.xmlns()); + auto e = parent->add_child ("Image", context.xmlns()); position_align (e, context, _h_align, _h_position, _v_align, _v_position); if (context.standard == Standard::SMPTE) { |
