Pick up SMPTE subtitle font IDs correctly.
authorCarl Hetherington <cth@carlh.net>
Thu, 29 Oct 2015 19:33:09 +0000 (19:33 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 29 Oct 2015 19:33:09 +0000 (19:33 +0000)
src/font_node.cc
src/font_node.h
src/interop_subtitle_asset.cc
src/smpte_subtitle_asset.cc
src/subtitle_node.cc
src/subtitle_node.h
src/text_node.cc
src/text_node.h
test/text_test.cc

index 5461d6aeacb3921559cf3f532baa176f68cb469f..5d857bc10e17468faa814c8664051ee69e5b06fb 100644 (file)
@@ -31,11 +31,11 @@ using boost::shared_ptr;
 using boost::optional;
 using namespace dcp;
 
-FontNode::FontNode (cxml::ConstNodePtr node, int tcr)
+FontNode::FontNode (cxml::ConstNodePtr node, int tcr, string font_id_attribute)
 {
        text = node->content ();
 
-       id = node->optional_string_attribute ("Id");
+       id = node->optional_string_attribute (font_id_attribute);
        size = node->optional_number_attribute<int64_t> ("Size").get_value_or (0);
        aspect_adjust = node->optional_number_attribute<float> ("AspectAdjust");
        italic = node->optional_bool_attribute ("Italic");
@@ -54,17 +54,17 @@ FontNode::FontNode (cxml::ConstNodePtr node, int tcr)
 
        list<cxml::NodePtr> s = node->node_children ("Subtitle");
        BOOST_FOREACH (cxml::NodePtr& i, s) {
-               subtitle_nodes.push_back (shared_ptr<SubtitleNode> (new SubtitleNode (i, tcr)));
+               subtitle_nodes.push_back (shared_ptr<SubtitleNode> (new SubtitleNode (i, tcr, font_id_attribute)));
        }
 
        list<cxml::NodePtr> f = node->node_children ("Font");
        BOOST_FOREACH (cxml::NodePtr& i, f) {
-               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, tcr)));
+               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, tcr, font_id_attribute)));
        }
 
        list<cxml::NodePtr> t = node->node_children ("Text");
        BOOST_FOREACH (cxml::NodePtr& i, t) {
-               text_nodes.push_back (shared_ptr<TextNode> (new TextNode (i, tcr)));
+               text_nodes.push_back (shared_ptr<TextNode> (new TextNode (i, tcr, font_id_attribute)));
        }
 }
 
index 92dd6b218367d936f8502c9013d2d0711bfad7fa..508156364f80466b6a495ef3d9e3c610065de406 100644 (file)
@@ -40,7 +40,7 @@ public:
                : size (0)
        {}
 
-       FontNode (cxml::ConstNodePtr node, int tcr);
+       FontNode (cxml::ConstNodePtr node, int tcr, std::string font_id_attribute);
        FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes);
 
        std::string text;
index bf493fdaeb7b1b3d4e25f5b119a32e00efad1f7b..5777c31ab4bc00acdd0d95795d1914437d7c3533 100644 (file)
@@ -55,7 +55,7 @@ InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file)
        list<cxml::NodePtr> f = xml->node_children ("Font");
        list<shared_ptr<dcp::FontNode> > font_nodes;
        BOOST_FOREACH (cxml::NodePtr& i, f) {
-               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, 250)));
+               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, 250, "Id")));
        }
 
        parse_subtitles (xml, font_nodes);
index 130b344fb37c6aa7833c1c1909bcff9996623e4c..070ade734f7d0153e51373d38ae0b58c2307f28c 100644 (file)
@@ -121,7 +121,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file)
        list<cxml::NodePtr> f = subtitle_list->node_children ("Font");
        list<shared_ptr<dcp::FontNode> > font_nodes;
        BOOST_FOREACH (cxml::NodePtr& i, f) {
-               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, _time_code_rate)));
+               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, _time_code_rate, "ID")));
        }
 
        parse_subtitles (xml, font_nodes);
index f53878b6453e565fe04d3de21b454317dbdcff80..e221b43b1c3a875db4d9163181c2b66d7b234797 100644 (file)
@@ -31,19 +31,19 @@ using boost::shared_ptr;
 using boost::lexical_cast;
 using namespace dcp;
 
-SubtitleNode::SubtitleNode (boost::shared_ptr<const cxml::Node> node, int tcr)
+SubtitleNode::SubtitleNode (boost::shared_ptr<const cxml::Node> node, int tcr, string font_id_attribute)
 {
        in = Time (node->string_attribute ("TimeIn"), tcr);
        out = Time (node->string_attribute ("TimeOut"), tcr);
 
        list<cxml::NodePtr> f = node->node_children ("Font");
        for (list<cxml::NodePtr>::iterator i = f.begin(); i != f.end(); ++i) {
-               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (*i, tcr)));
+               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (*i, tcr, font_id_attribute)));
        }
 
        list<cxml::NodePtr> t = node->node_children ("Text");
        for (list<cxml::NodePtr>::iterator i = t.begin(); i != t.end(); ++i) {
-               text_nodes.push_back (shared_ptr<TextNode> (new TextNode (*i, tcr)));
+               text_nodes.push_back (shared_ptr<TextNode> (new TextNode (*i, tcr, font_id_attribute)));
        }
 
        fade_up_time = fade_time (node, "FadeUpTime", tcr);
index 401897042508ad59dedf6fd6859131389a936590..7886105032609aa06b4969eee3d03eabf1a2dd80 100644 (file)
@@ -38,7 +38,7 @@ class SubtitleNode
 {
 public:
        SubtitleNode () {}
-       SubtitleNode (boost::shared_ptr<const cxml::Node> node, int tcr);
+       SubtitleNode (boost::shared_ptr<const cxml::Node> node, int tcr, std::string font_id_attribute);
 
        Time in;
        Time out;
index 666e58460c52970e4576efcafd2054305686792e..aa318ce75b4e4b6c6c425b45148258baa8b1ab0b 100644 (file)
@@ -37,7 +37,7 @@ using namespace dcp;
  *  in this object's member variables.
  *  @param node Node to read.
  */
-TextNode::TextNode (boost::shared_ptr<const cxml::Node> node, int tcr)
+TextNode::TextNode (boost::shared_ptr<const cxml::Node> node, int tcr, string font_id_attribute)
        : h_position (0)
        , h_align (HALIGN_CENTER)
        , v_position (0)
@@ -79,6 +79,6 @@ TextNode::TextNode (boost::shared_ptr<const cxml::Node> node, int tcr)
 
        list<cxml::NodePtr> f = node->node_children ("Font");
        BOOST_FOREACH (cxml::NodePtr& i, f) {
-               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, tcr)));
+               font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, tcr, font_id_attribute)));
        }
 }
index 1affd83f22e2ff94a4e6bbd6cdf86ff898147803..f10d7c4b73b33db4854f7729a777adcf1c211d8a 100644 (file)
@@ -48,7 +48,7 @@ public:
                , v_align (VALIGN_TOP)
        {}
 
-       TextNode (boost::shared_ptr<const cxml::Node> node, int tcr);
+       TextNode (boost::shared_ptr<const cxml::Node> node, int tcr, std::string font_id_attribute);
 
        float h_position;
        HAlign h_align;
index a9723bb156930cc12e697268fd3369eb003777c8..9fff25d6a9101eff13de31290c34bc58f50b1ae4 100644 (file)
@@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE (text_test1)
        text->set_attribute("VAlign", "top");
        text->add_child_text("Hello world");
 
-       dcp::TextNode t (cxml::NodePtr (new cxml::Node (text)), 250);
+       dcp::TextNode t (cxml::NodePtr (new cxml::Node (text)), 250, "Id");
        BOOST_CHECK_CLOSE (t.v_position, 0.042, 0.001);
        BOOST_CHECK_EQUAL (t.v_align, dcp::VALIGN_TOP);
        BOOST_CHECK_EQUAL (t.text, "Hello world");
@@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE (text_test2)
        text->set_attribute("Valign", "top");
        text->add_child_text("Hello world");
 
-       dcp::TextNode t (cxml::NodePtr (new cxml::Node (text)), 250);
+       dcp::TextNode t (cxml::NodePtr (new cxml::Node (text)), 250, "Id");
        BOOST_CHECK_CLOSE (t.v_position, 0.042, 0.001);
        BOOST_CHECK_EQUAL (t.v_align, dcp::VALIGN_TOP);
        BOOST_CHECK_EQUAL (t.text, "Hello world");