Rationalise #undef-ing of ERROR.
[libdcp.git] / src / subtitle_asset_internal.cc
index 80e861f117a9b55cae26299138197a8276bf038e..bb67b45a83f333de0d2a9715c760535570631be8 100644 (file)
@@ -49,13 +49,6 @@ 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()) {
@@ -82,11 +75,11 @@ order::Font::Font (shared_ptr<SubtitleString> s, Standard standard)
 
 
 xmlpp::Element*
-order::Font::as_xml (xmlpp::Element* parent, Context& context) const
+order::Font::as_xml (xmlpp::Element* parent, Context&) const
 {
-       xmlpp::Element* e = parent->add_child ("Font", context.xmlns());
-       for (map<string, string>::const_iterator i = _values.begin(); i != _values.end(); ++i) {
-               e->set_attribute (i->first, i->second);
+       auto e = parent->add_child("Font");
+       for (const auto& i: _values) {
+               e->set_attribute (i.first, i.second);
        }
        return e;
 }
@@ -141,9 +134,17 @@ order::Part::as_xml (xmlpp::Element* parent, Context &) const
 
 
 xmlpp::Element*
-order::String::as_xml (xmlpp::Element* parent, Context &) const
+order::String::as_xml (xmlpp::Element* parent, Context& context) const
 {
-       parent->add_child_text (text);
+       if (fabs(_space_before) > SPACE_BEFORE_EPSILON) {
+               auto space = parent->add_child("Space");
+               auto size = raw_convert<string>(_space_before, 2);
+               if (context.standard == Standard::INTEROP) {
+                       size += "em";
+               }
+               space->set_attribute("Size", size);
+       }
+       parent->add_child_text (_text);
        return 0;
 }
 
@@ -164,7 +165,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)
+position_align (xmlpp::Element* e, order::Context& context, HAlign h_align, float h_position, VAlign v_align, float v_position, float z_position)
 {
        if (h_align != HAlign::CENTER) {
                if (context.standard == Standard::SMPTE) {
@@ -201,15 +202,19 @@ position_align (xmlpp::Element* e, order::Context& context, HAlign h_align, floa
                        e->set_attribute ("VPosition", "0");
                }
        }
+
+       if (fabs(z_position) > ALIGN_EPSILON && context.standard == Standard::SMPTE) {
+               e->set_attribute("Zposition", raw_convert<string>(z_position * 100, 6));
+       }
 }
 
 
 xmlpp::Element*
 order::Text::as_xml (xmlpp::Element* parent, Context& context) const
 {
-       auto e = parent->add_child ("Text", context.xmlns());
+       auto e = parent->add_child ("Text");
 
-       position_align (e, context, _h_align, _h_position, _v_align, _v_position);
+       position_align(e, context, _h_align, _h_position, _v_align, _v_position, _z_position);
 
        /* Interop only supports "horizontal" or "vertical" for direction, so only write this
           for SMPTE.
@@ -225,7 +230,7 @@ order::Text::as_xml (xmlpp::Element* parent, Context& context) const
 xmlpp::Element*
 order::Subtitle::as_xml (xmlpp::Element* parent, Context& context) const
 {
-       auto e = parent->add_child ("Subtitle", context.xmlns());
+       auto e = parent->add_child ("Subtitle");
        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));
@@ -257,11 +262,11 @@ order::Font::clear ()
 xmlpp::Element *
 order::Image::as_xml (xmlpp::Element* parent, Context& context) const
 {
-       auto e = parent->add_child ("Image", context.xmlns());
+       auto e = parent->add_child ("Image");
 
-       position_align (e, context, _h_align, _h_position, _v_align, _v_position);
+       position_align(e, context, _h_align, _h_position, _v_align, _v_position, _z_position);
        if (context.standard == Standard::SMPTE) {
-               e->add_child_text (_id);
+               e->add_child_text ("urn:uuid:" + _id);
        } else {
                e->add_child_text (_id + ".png");
        }