+ bool const font_changed =
+ font != i.font() ||
+ italic != i.italic() ||
+ bold != i.bold() ||
+ underline != i.underline() ||
+ colour != i.colour() ||
+ size != i.size() ||
+ fabs (aspect_adjust - i.aspect_adjust()) > ASPECT_ADJUST_EPSILON ||
+ effect != i.effect() ||
+ effect_colour != i.effect_colour();
+
+ if (font_changed) {
+ font = i.font ();
+ italic = i.italic ();
+ bold = i.bold ();
+ underline = i.underline ();
+ colour = i.colour ();
+ size = i.size ();
+ aspect_adjust = i.aspect_adjust ();
+ effect = i.effect ();
+ effect_colour = i.effect_colour ();
+ }
+
+ if (!font_element || font_changed) {
+ font_element = root->add_child ("Font", xmlns);
+ if (font) {
+ 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());
+ font_element->set_attribute ("Size", raw_convert<string> (size));
+ if (fabs (aspect_adjust - 1.0) > ASPECT_ADJUST_EPSILON) {
+ font_element->set_attribute ("AspectAdjust", raw_convert<string> (aspect_adjust));
+ }
+ 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");
+ if (standard == SMPTE) {
+ font_element->set_attribute ("Underline", underline ? "yes" : "no");
+ } else {
+ font_element->set_attribute ("Underlined", underline ? "yes" : "no");
+ }
+ font_element->set_attribute ("Weight", bold ? "bold" : "normal");
+ }
+
+ if (!subtitle_element || font_changed ||
+ (last_in != i.in() ||
+ last_out != i.out() ||
+ last_fade_up_time != i.fade_up_time() ||
+ last_fade_down_time != i.fade_down_time()
+ )) {
+
+ 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(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 ();
+ last_fade_up_time = i.fade_up_time ();
+ last_fade_down_time = i.fade_down_time ();
+ }
+
+ xmlpp::Element* text = subtitle_element->add_child ("Text", xmlns);
+
+ if (i.h_align() != HALIGN_CENTER) {
+ 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) {
+ 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()));
+ }
+
+ if (i.v_position() > ALIGN_EPSILON) {
+ 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 {
+ if (standard == SMPTE) {
+ text->set_attribute ("Vposition", "0");
+ } else {
+ text->set_attribute ("VPosition", "0");
+ }
+ }
+
+ /* Interop only supports "horizontal" or "vertical" for direction, so only write this
+ for SMPTE.
+ */
+ if (i.direction() != DIRECTION_LTR && standard == SMPTE) {
+ text->set_attribute ("Direction", direction_to_string (i.direction ()));
+ }
+
+ text->add_child_text (i.text());
+ }
+}
+
+map<string, Data>
+SubtitleAsset::fonts_with_load_ids () const
+{
+ map<string, Data> out;
+ BOOST_FOREACH (Font const & i, _fonts) {
+ out[i.load_id] = i.data;
+ }
+ return out;