summaryrefslogtreecommitdiff
path: root/src/subtitle.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-29 11:57:08 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-29 11:57:08 +0100
commitaebf2cb7812c8f593b85182611b587e6014aefc6 (patch)
treec954ebc0cf39263b6c051e159f48e177cafae310 /src/subtitle.h
parent8b1958988ca234f51ec99385d81b95c1f0f092af (diff)
Re-work Subtitle class; remove STL text writer.
Diffstat (limited to 'src/subtitle.h')
-rw-r--r--src/subtitle.h90
1 files changed, 57 insertions, 33 deletions
diff --git a/src/subtitle.h b/src/subtitle.h
index fc08ac7..ca73b4b 100644
--- a/src/subtitle.h
+++ b/src/subtitle.h
@@ -25,46 +25,58 @@
#include "colour.h"
#include "vertical_reference.h"
#include "effect.h"
+#include "time_pair.h"
#include <boost/optional.hpp>
#include <string>
#include <list>
namespace sub {
-class Subtitle
+/** A piece of text with a single font, style, size etc. */
+class Block
{
public:
- Subtitle ()
+ Block ()
: colour (1, 1, 1)
, bold (false)
, italic (false)
, underline (false)
- , line (0)
{}
-
+
/** Subtitle text in UTF-8 */
std::string text;
std::string font;
/** font size */
- struct {
+ class FontSize {
+ public:
+ void set_proportional (float p) {
+ _proportional = p;
+ }
+
+ void set_points (int p) {
+ _points = p;
+ }
+
+ boost::optional<float> proportional () const {
+ return _proportional;
+ }
+
+ boost::optional<int> points () const {
+ return _points;
+ }
+
+ float proportional (int screen_height_in_points) const;
+ int points (int screen_height_in_points) const;
+
+ private:
/** as a proportion of screen height */
- boost::optional<float> proportional;
+ boost::optional<float> _proportional;
/** in points */
- boost::optional<int> points;
+ boost::optional<int> _points;
+
} font_size;
- float font_size_proportional (int screen_height_in_points) const;
- int font_size_points (int screen_height_in_points) const;
-
- /** vertical position of the baseline of the text */
- struct {
- /** as a proportion of screen height offset from some reference point */
- boost::optional<float> proportional;
- /** reference position for proportional */
- boost::optional<VerticalReference> reference;
- } vertical_position;
-
boost::optional<Effect> effect;
boost::optional<Colour> effect_colour;
@@ -72,28 +84,40 @@ public:
bool bold; ///< true to use a bold version of font
bool italic; ///< true to use an italic version of font
bool underline; ///< true to underline
- int line; ///< line number, starting from 0
+};
- /** from time */
- struct {
- boost::optional<FrameTime> frame;
- boost::optional<MetricTime> metric;
- } from;
+/** A line of text which starts and stops at specific times */
+class Subtitle
+{
+public:
+ Subtitle ()
+ {}
- FrameTime from_frame (float frames_per_second) const;
- MetricTime from_metric (float frames_per_second) const;
+ /** vertical position of the baseline of the text */
+ struct VerticalPosition {
- /** to time */
- struct {
- boost::optional<FrameTime> frame;
- boost::optional<MetricTime> metric;
- } to;
+ /** as a proportion of screen height offset from some reference point */
+ boost::optional<float> proportional;
+ /** reference position for proportional */
+ boost::optional<VerticalReference> reference;
+ /** line number from the top of the screen */
+ boost::optional<int> line;
+
+ bool operator== (VerticalPosition const & other) const;
+
+ } vertical_position;
- FrameTime to_frame (float frames_per_second) const;
- MetricTime to_metric (float frames_per_second) const;
+ /** from time */
+ TimePair from;
+ /** to time */
+ TimePair to;
boost::optional<MetricTime> fade_up;
boost::optional<MetricTime> fade_down;
+
+ std::list<Block> blocks;
+
+ bool same_metadata (Subtitle const &) const;
};
bool operator< (Subtitle const & a, Subtitle const & b);