summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-01-22 19:59:07 +0000
committerCarl Hetherington <cth@carlh.net>2015-01-22 19:59:07 +0000
commit305c00f13c929478de39123008d93b52ed2ec7ca (patch)
tree782fce23c14185378ede55d0f5393f2024fddaff /src
parent14e4eac6689b5ffe3542d45ad62708507efcd791 (diff)
parent6986647a7ec79fe1a83da96c50bbf414dda859c5 (diff)
Merge branch 'master' of ssh://main.carlh.net/home/carl/git/libdcp
Diffstat (limited to 'src')
-rw-r--r--src/parse/subtitle.cc12
-rw-r--r--src/parse/subtitle.h3
-rw-r--r--src/subtitle_asset.cc15
-rw-r--r--src/subtitle_asset.h6
-rw-r--r--src/types.cc41
-rw-r--r--src/types.h16
6 files changed, 75 insertions, 18 deletions
diff --git a/src/parse/subtitle.cc b/src/parse/subtitle.cc
index 56222c97..8c53bd68 100644
--- a/src/parse/subtitle.cc
+++ b/src/parse/subtitle.cc
@@ -147,7 +147,8 @@ Subtitle::fade_time (shared_ptr<const cxml::Node> node, string name, optional<in
}
Text::Text (shared_ptr<const cxml::Node> node, optional<int> tcr)
- : v_align (CENTER)
+ : v_align (VERTICAL_CENTER)
+ , h_align (HORIZONTAL_CENTER)
{
/* Vertical position */
text = node->content ();
@@ -166,6 +167,15 @@ Text::Text (shared_ptr<const cxml::Node> node, optional<int> tcr)
v_align = string_to_valign (v.get ());
}
+ /* Horizontal alignment */
+ optional<string> h = node->optional_string_attribute ("HAlign");
+ if (!h) {
+ h = node->optional_string_attribute ("Halign");
+ }
+ if (h) {
+ h_align = string_to_halign (h.get ());
+ }
+
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<Font> (new Font (*i, tcr)));
diff --git a/src/parse/subtitle.h b/src/parse/subtitle.h
index 867b3f0e..3993a6be 100644
--- a/src/parse/subtitle.h
+++ b/src/parse/subtitle.h
@@ -34,13 +34,14 @@ class Text
public:
Text ()
: v_position (0)
- , v_align (TOP)
+ , v_align (VERTICAL_TOP)
{}
Text (boost::shared_ptr<const cxml::Node> node, boost::optional<int> tcr);
float v_position;
VAlign v_align;
+ HAlign h_align;
std::string text;
std::list<boost::shared_ptr<Font> > font_nodes;
};
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc
index e5ef9cd2..0e76a62d 100644
--- a/src/subtitle_asset.cc
+++ b/src/subtitle_asset.cc
@@ -187,16 +187,13 @@ SubtitleAsset::maybe_add_subtitle (string text, ParseState& parse_state)
libdcp::parse::Text effective_text (*parse_state.text_nodes.back ());
libdcp::parse::Subtitle effective_subtitle (*parse_state.subtitle_nodes.back ());
- cout << "Maybe add " << text << "\n";
-
shared_ptr<Subtitle> c = parse_state.current;
if (!c ||
effective_subtitle.in != c->in() ||
effective_subtitle.out != c->out() ||
effective_text.v_position != c->v_position() ||
- effective_text.v_align != c->v_align()) {
-
- cout << "(reset)\n";
+ effective_text.v_align != c->v_align() ||
+ effective_text.h_align != c->h_align()) {
parse_state.current.reset (
new Subtitle (
@@ -208,6 +205,7 @@ SubtitleAsset::maybe_add_subtitle (string text, ParseState& parse_state)
effective_subtitle.out,
effective_text.v_position,
effective_text.v_align,
+ effective_text.h_align,
"",
effective_font.effect ? effective_font.effect.get() : NONE,
effective_font.effect_color.get(),
@@ -267,6 +265,7 @@ Subtitle::Subtitle (
Time out,
float v_position,
VAlign v_align,
+ HAlign h_align,
string text,
Effect effect,
Color effect_color,
@@ -281,6 +280,7 @@ Subtitle::Subtitle (
, _out (out)
, _v_position (v_position)
, _v_align (v_align)
+ , _h_align (h_align)
, _text (text)
, _effect (effect)
, _effect_color (effect_color)
@@ -313,6 +313,7 @@ libdcp::operator== (Subtitle const & a, Subtitle const & b)
a.out() == b.out() &&
a.v_position() == b.v_position() &&
a.v_align() == b.v_align() &&
+ a.h_align() == b.h_align() &&
a.text() == b.text() &&
a.effect() == b.effect() &&
a.effect_color() == b.effect_color() &&
@@ -334,7 +335,8 @@ libdcp::operator<< (ostream& s, Subtitle const & sub)
s << "non-italic";
}
- s << ", size " << sub.size() << ", color " << sub.color() << ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align()) << ";\n"
+ s << ", size " << sub.size() << ", color " << sub.color()
+ << ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align()) << ", halign " << ((int) sub.h_align()) << "; "
<< "effect " << ((int) sub.effect()) << ", effect color " << sub.effect_color();
return s;
@@ -486,6 +488,7 @@ SubtitleAsset::xml_as_string () const
xmlpp::Element* text = subtitle->add_child ("Text");
text->set_attribute ("VAlign", valign_to_string ((*i)->v_align()));
+ text->set_attribute ("HAlign", halign_to_string ((*i)->h_align()));
text->set_attribute ("VPosition", raw_convert<string> ((*i)->v_position()));
text->add_child_text ((*i)->text());
}
diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h
index a5014307..335b9f37 100644
--- a/src/subtitle_asset.h
+++ b/src/subtitle_asset.h
@@ -47,6 +47,7 @@ public:
Time out,
float v_position,
VAlign v_align,
+ HAlign h_align,
std::string text,
Effect effect,
Color effect_color,
@@ -90,6 +91,10 @@ public:
return _v_align;
}
+ HAlign h_align () const {
+ return _h_align;
+ }
+
Effect effect () const {
return _effect;
}
@@ -127,6 +132,7 @@ private:
*/
float _v_position;
VAlign _v_align;
+ HAlign _h_align;
std::string _text;
Effect _effect;
Color _effect_color;
diff --git a/src/types.cc b/src/types.cc
index f45e3345..920cc5e9 100644
--- a/src/types.cc
+++ b/src/types.cc
@@ -159,11 +159,11 @@ string
libdcp::valign_to_string (VAlign v)
{
switch (v) {
- case TOP:
+ case VERTICAL_TOP:
return "top";
- case CENTER:
+ case VERTICAL_CENTER:
return "center";
- case BOTTOM:
+ case VERTICAL_BOTTOM:
return "bottom";
}
@@ -174,14 +174,41 @@ VAlign
libdcp::string_to_valign (string s)
{
if (s == "top") {
- return TOP;
+ return VERTICAL_TOP;
} else if (s == "center") {
- return CENTER;
+ return VERTICAL_CENTER;
} else if (s == "bottom") {
- return BOTTOM;
+ return VERTICAL_BOTTOM;
}
boost::throw_exception (DCPReadError ("unknown subtitle valign type"));
}
-
+string
+libdcp::halign_to_string (HAlign h)
+{
+ switch (h) {
+ case HORIZONTAL_LEFT:
+ return "left";
+ case HORIZONTAL_CENTER:
+ return "center";
+ case HORIZONTAL_RIGHT:
+ return "right";
+ }
+
+ boost::throw_exception (MiscError ("unknown halign type"));
+}
+
+HAlign
+libdcp::string_to_halign (string s)
+{
+ if (s == "left") {
+ return HORIZONTAL_LEFT;
+ } else if (s == "center") {
+ return HORIZONTAL_CENTER;
+ } else if (s == "right") {
+ return HORIZONTAL_RIGHT;
+ }
+
+ boost::throw_exception (DCPReadError ("unknown subtitle halign type"));
+}
diff --git a/src/types.h b/src/types.h
index 013c1863..e02c36eb 100644
--- a/src/types.h
+++ b/src/types.h
@@ -72,14 +72,24 @@ extern Effect string_to_effect (std::string s);
enum VAlign
{
- TOP,
- CENTER,
- BOTTOM
+ VERTICAL_TOP,
+ VERTICAL_CENTER,
+ VERTICAL_BOTTOM
};
extern std::string valign_to_string (VAlign a);
extern VAlign string_to_valign (std::string s);
+enum HAlign
+{
+ HORIZONTAL_LEFT,
+ HORIZONTAL_CENTER,
+ HORIZONTAL_RIGHT
+};
+
+extern std::string halign_to_string (HAlign a);
+extern HAlign string_to_halign (std::string s);
+
enum Eye
{
EYE_LEFT,