Basic untested support for bold in subtitles.
authorCarl Hetherington <cth@carlh.net>
Mon, 4 Apr 2016 23:22:32 +0000 (00:22 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 4 Apr 2016 23:22:32 +0000 (00:22 +0100)
src/font_node.cc
src/font_node.h
src/subtitle_asset.cc
src/subtitle_string.cc
src/subtitle_string.h
test/asset_test.cc
test/read_interop_subtitle_test.cc
test/write_subtitle_test.cc

index 5d857bc10e17468faa814c8664051ee69e5b06fb..a5047211caefa6f876d1fbea96982085ec253265 100644 (file)
@@ -39,6 +39,7 @@ FontNode::FontNode (cxml::ConstNodePtr node, int tcr, string 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");
+       bold = node->optional_string_attribute("Weight").get_value_or("normal") == "bold";
        optional<string> c = node->optional_string_attribute ("Color");
        if (c) {
                colour = Colour (c.get ());
@@ -71,6 +72,7 @@ FontNode::FontNode (cxml::ConstNodePtr node, int tcr, string font_id_attribute)
 FontNode::FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes)
        : size (0)
        , italic (false)
+       , bold (false)
        , colour ("FFFFFFFF")
        , effect_colour ("FFFFFFFF")
 {
@@ -87,6 +89,9 @@ FontNode::FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes)
                if ((*i)->italic) {
                        italic = (*i)->italic.get ();
                }
+               if ((*i)->bold) {
+                       bold = (*i)->bold.get ();
+               }
                if ((*i)->colour) {
                        colour = (*i)->colour.get ();
                }
index 508156364f80466b6a495ef3d9e3c610065de406..b82308fb8ba5aad69a779e968a2b149cf352ce31 100644 (file)
@@ -48,6 +48,7 @@ public:
        int size;
        boost::optional<float> aspect_adjust;
        boost::optional<bool> italic;
+       boost::optional<bool> bold;
        boost::optional<Colour> colour;
        boost::optional<Effect> effect;
        boost::optional<Colour> effect_colour;
index 5074c35b9c4d08c3eec5ebf6391adc940ebc4918..352aff9a2efc8bed31d7403f22298eb96234b8a3 100644 (file)
@@ -143,6 +143,7 @@ SubtitleAsset::maybe_add_subtitle (string text, ParseState const & parse_state)
                SubtitleString (
                        effective_font.id,
                        effective_font.italic.get_value_or (false),
+                       effective_font.bold.get_value_or (false),
                        effective_font.colour.get_value_or (dcp::Colour (255, 255, 255)),
                        effective_font.size,
                        effective_font.aspect_adjust.get_value_or (1.0),
@@ -233,10 +234,11 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Stand
 
        string const xmlns = standard == SMPTE ? "dcst" : "";
 
-       /* XXX: script, underlined, weight not supported */
+       /* XXX: script, underlined not supported */
 
        optional<string> font;
        bool italic = false;
+       bool bold = false;
        Colour colour;
        int size = 0;
        float aspect_adjust = 1.0;
@@ -261,6 +263,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Stand
                bool const font_changed =
                        font          != i.font()          ||
                        italic        != i.italic()        ||
+                       bold          != i.bold()          ||
                        colour        != i.colour()        ||
                        size          != i.size()          ||
                        fabs (aspect_adjust - i.aspect_adjust()) > ASPECT_ADJUST_EPSILON ||
@@ -270,6 +273,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Stand
                if (font_changed) {
                        font = i.font ();
                        italic = i.italic ();
+                       bold = i.bold ();
                        colour = i.colour ();
                        size = i.size ();
                        aspect_adjust = i.aspect_adjust ();
@@ -300,7 +304,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Stand
                        } else {
                                font_element->set_attribute ("Underlined", "no");
                        }
-                       font_element->set_attribute ("Weight", "normal");
+                       font_element->set_attribute ("Weight", bold ? "bold" : "normal");
                }
 
                if (!subtitle_element || font_changed ||
index d565d453ae2eb91f4d3ffbe90aa50898e2b29b16..ea24e37f122aa1ad91f070d1877912c4600a213b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -30,6 +30,7 @@ using namespace dcp;
 SubtitleString::SubtitleString (
        optional<string> font,
        bool italic,
+       bool bold,
        Colour colour,
        int size,
        float aspect_adjust,
@@ -47,6 +48,7 @@ SubtitleString::SubtitleString (
        )
        : _font (font)
        , _italic (italic)
+       , _bold (bold)
        , _colour (colour)
        , _size (size)
        , _aspect_adjust (aspect_adjust)
@@ -82,6 +84,7 @@ dcp::operator== (SubtitleString const & a, SubtitleString const & b)
        return (
                a.font() == b.font() &&
                a.italic() == b.italic() &&
+               a.bold() == b.bold() &&
                a.colour() == b.colour() &&
                a.size() == b.size() &&
                fabs (a.aspect_adjust() - b.aspect_adjust()) < ASPECT_ADJUST_EPSILON &&
@@ -107,12 +110,18 @@ dcp::operator<< (ostream& s, SubtitleString const & sub)
          << "font " << sub.font().get_value_or ("[default]") << ", ";
 
        if (sub.italic()) {
-               s << "italic";
+               s << "italic";
        } else {
-               s << "non-italic";
+               s << "non-italic";
        }
 
-       s << ", size " << sub.size() << ", aspect " << sub.aspect_adjust() << ", colour " << sub.colour()
+       if (sub.bold()) {
+               s << "bold, ";
+       } else {
+               s << "normal, ";
+       }
+
+       s << "size " << sub.size() << ", aspect " << sub.aspect_adjust() << ", colour " << sub.colour()
          << ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align())
          << ", hpos " << sub.h_position() << ", halign " << ((int) sub.h_align())
          << ", effect " << ((int) sub.effect()) << ", effect colour " << sub.effect_colour();
index eaea94c0690a3e387c66913a813c5fb16d79130d..bd71b8da6b93e09c96f16651e31e714ddeb54abe 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -40,6 +40,7 @@ public:
        SubtitleString (
                boost::optional<std::string> font,
                bool italic,
+               bool bold,
                Colour colour,
                int size,
                float aspect_adjust,
@@ -65,6 +66,10 @@ public:
                return _italic;
        }
 
+       bool bold () const {
+               return _bold;
+       }
+
        Colour colour () const {
                return _colour;
        }
@@ -163,6 +168,8 @@ private:
        boost::optional<std::string> _font;
        /** true if the text is italic */
        bool _italic;
+       /** true if the weight is bold, false for normal */
+       bool _bold;
        /** text colour */
        Colour _colour;
        /** Size in points as if the screen height is 11 inches, so a 72pt font
index c53aca68a18346a0173bb1f9ea956d82219cff30..caf5e76c48e8428f4d2c94ba36ba33c1a8bcec48 100644 (file)
@@ -26,7 +26,7 @@ using boost::shared_ptr;
 class DummyAsset : public dcp::Asset
 {
 protected:
-       std::string pkl_type (dcp::Standard standard) const {
+       std::string pkl_type (dcp::Standard) const {
                return "none";
        }
 };
index a66327f1c59e73e629888c0f13028eef7a53b147..7cbb5803c904a59fff390b927c5fcb45e8435e14 100644 (file)
@@ -49,6 +49,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test1)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFontId"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   39,
                                   1.0,
@@ -70,6 +71,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test1)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFontId"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   39,
                                   1.0,
@@ -88,6 +90,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test1)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFontId"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   39,
                                   1.0,
@@ -109,6 +112,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test1)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFontId"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   39,
                                   1.0,
@@ -130,6 +134,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test1)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFontId"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   39,
                                   1.0,
@@ -157,6 +162,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -175,6 +181,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -196,6 +203,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -214,6 +222,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -235,6 +244,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -253,6 +263,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -274,6 +285,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -292,6 +304,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -313,6 +326,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -331,6 +345,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -352,6 +367,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFont"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -370,6 +386,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFont"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -391,6 +408,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFont"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -409,6 +427,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFont"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -430,6 +449,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFont"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -448,6 +468,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFont"),
                                   false,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -469,6 +490,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.front(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
@@ -487,6 +509,7 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
        BOOST_CHECK_EQUAL (s.back(), dcp::SubtitleString (
                                   string ("theFont"),
                                   true,
+                                  false,
                                   dcp::Colour (255, 255, 255),
                                   42,
                                   1.0,
index 8b50b0e3f0660fa7494ce8625956043a53aaf709..e407b81fa64e9ccfef11985a8ce57882c8af678e 100644 (file)
@@ -38,6 +38,7 @@ BOOST_AUTO_TEST_CASE (write_subtitle_test)
                dcp::SubtitleString (
                        string ("Frutiger"),
                        false,
+                       false,
                        dcp::Colour (255, 255, 255),
                        48,
                        1.0,
@@ -59,6 +60,7 @@ BOOST_AUTO_TEST_CASE (write_subtitle_test)
                dcp::SubtitleString (
                        boost::optional<string> (),
                        true,
+                       false,
                        dcp::Colour (128, 0, 64),
                        91,
                        1.0,