4 #include <boost/lexical_cast.hpp>
5 #include <boost/algorithm/string.hpp>
7 #include "exceptions.h"
11 using namespace boost;
13 Fraction::Fraction (string s)
16 split (b, s, is_any_of (" "));
18 boost::throw_exception (XMLError ("malformed fraction " + s + " in XML node"));
20 numerator = lexical_cast<int> (b[0]);
21 denominator = lexical_cast<int> (b[1]);
25 dcp::operator== (Fraction const & a, Fraction const & b)
27 return (a.numerator == b.numerator && a.denominator == b.denominator);
31 dcp::operator!= (Fraction const & a, Fraction const & b)
33 return (a.numerator != b.numerator || a.denominator != b.denominator);
44 Color::Color (int r_, int g_, int b_)
52 /** Construct a Color from an ARGB hex string; the alpha value is ignored.
53 * @param argb_hex A string of the form AARRGGBB, where e.g. RR is a two-character
56 Color::Color (string argb_hex)
59 if (sscanf (argb_hex.c_str(), "%2x%2x%2x%2x", &alpha, &r, &g, &b) < 4) {
60 boost::throw_exception (XMLError ("could not parse colour string"));
64 /** @return An ARGB string of the form AARRGGBB, where e.g. RR is a two-character
65 * hex value. The alpha value will always be FF (ie 255; maximum alpha).
68 Color::to_argb_string () const
73 << setw(2) << setfill('0') << r
74 << setw(2) << setfill('0') << g
75 << setw(2) << setfill('0') << b;
82 /** operator== for Colors.
83 * @param a First color to compare.
84 * @param b Second color to compare.
87 dcp::operator== (Color const & a, Color const & b)
89 return (a.r == b.r && a.g == b.g && a.b == b.b);
92 /** operator!= for Colors.
93 * @param a First color to compare.
94 * @param b Second color to compare.
97 dcp::operator!= (Color const & a, Color const & b)
103 dcp::operator<< (ostream& s, Color const & c)
105 s << "(" << c.r << ", " << c.g << ", " << c.b << ")";
110 dcp::effect_to_string (Effect e)
121 boost::throw_exception (MiscError ("unknown effect type"));
125 dcp::string_to_effect (string s)
129 } else if (s == "border") {
131 } else if (s == "shadow") {
135 boost::throw_exception (DCPReadError ("unknown subtitle effect type"));
139 dcp::valign_to_string (VAlign v)
150 boost::throw_exception (MiscError ("unknown valign type"));
154 dcp::string_to_valign (string s)
158 } else if (s == "center") {
160 } else if (s == "bottom") {
164 boost::throw_exception (DCPReadError ("unknown subtitle valign type"));