- for (list<shared_ptr<dcp::SubtitleNode> >::iterator j = (*i)->subtitle_nodes.begin(); j != (*i)->subtitle_nodes.end(); ++j) {
- parse_state.subtitle_nodes.push_back (*j);
- examine_text_nodes (xml, (*j)->text_nodes, parse_state);
- examine_font_nodes (xml, (*j)->font_nodes, parse_state);
- parse_state.subtitle_nodes.pop_back ();
- }
-
- examine_font_nodes (xml, (*i)->font_nodes, parse_state);
- examine_text_nodes (xml, (*i)->text_nodes, parse_state);
-
- parse_state.font_nodes.pop_back ();
+template <class T>
+optional<T>
+optional_number_attribute (xmlpp::Element const * node, string name)
+{
+ boost::optional<std::string> s = optional_string_attribute (node, name);
+ if (!s) {
+ return boost::optional<T> ();
+ }
+
+ std::string t = s.get ();
+ boost::erase_all (t, " ");
+ return raw_convert<T> (t);
+}
+
+SubtitleAsset::ParseState
+SubtitleAsset::font_node_state (xmlpp::Element const * node, Standard standard) const
+{
+ ParseState ps;
+
+ if (standard == INTEROP) {
+ ps.font_id = optional_string_attribute (node, "Id");
+ } else {
+ ps.font_id = optional_string_attribute (node, "ID");
+ }
+ ps.size = optional_number_attribute<int64_t> (node, "Size");
+ ps.aspect_adjust = optional_number_attribute<float> (node, "AspectAdjust");
+ ps.italic = optional_bool_attribute (node, "Italic");
+ ps.bold = optional_string_attribute(node, "Weight").get_value_or("normal") == "bold";
+ if (standard == INTEROP) {
+ ps.underline = optional_bool_attribute (node, "Underlined");
+ } else {
+ ps.underline = optional_bool_attribute (node, "Underline");
+ }
+ optional<string> c = optional_string_attribute (node, "Color");
+ if (c) {
+ ps.colour = Colour (c.get ());
+ }
+ optional<string> const e = optional_string_attribute (node, "Effect");
+ if (e) {
+ ps.effect = string_to_effect (e.get ());
+ }
+ c = optional_string_attribute (node, "EffectColor");
+ if (c) {
+ ps.effect_colour = Colour (c.get ());
+ }
+
+ return ps;
+}
+
+SubtitleAsset::ParseState
+SubtitleAsset::text_node_state (xmlpp::Element const * node) const
+{
+ ParseState ps;
+
+ optional<float> hp = optional_number_attribute<float> (node, "HPosition");
+ if (!hp) {
+ hp = optional_number_attribute<float> (node, "Hposition");
+ }
+ if (hp) {
+ ps.h_position = hp.get () / 100;
+ }
+
+ optional<string> ha = optional_string_attribute (node, "HAlign");
+ if (!ha) {
+ ha = optional_string_attribute (node, "Halign");
+ }
+ if (ha) {
+ ps.h_align = string_to_halign (ha.get ());
+ }
+
+ optional<float> vp = optional_number_attribute<float> (node, "VPosition");
+ if (!vp) {
+ vp = optional_number_attribute<float> (node, "Vposition");
+ }
+ if (vp) {
+ ps.v_position = vp.get () / 100;
+ }
+
+ optional<string> va = optional_string_attribute (node, "VAlign");
+ if (!va) {
+ va = optional_string_attribute (node, "Valign");
+ }
+ if (va) {
+ ps.v_align = string_to_valign (va.get ());