#ifndef LIBSUB_SUBTITLE_H
#define LIBSUB_SUBTITLE_H
-#include "frame_time.h"
-#include "metric_time.h"
#include "colour.h"
#include "vertical_reference.h"
#include "effect.h"
-#include "time_pair.h"
+#include "font_size.h"
+#include "vertical_position.h"
+#include "horizontal_position.h"
+#include "raw_subtitle.h"
#include <boost/optional.hpp>
#include <string>
-#include <list>
+#include <vector>
namespace sub {
-/** A piece of text with a single font, style, size etc. */
+/** @class Block
+ * @brief A block of text within a subtitle's line
+ *
+ * This represents a block of text which has a particular style (font, size, effect, colour etc.)
+ */
class Block
{
public:
, italic (false)
, underline (false)
{}
-
+
+ /** Construct a Block taking any relevant information from a RawSubtitle */
+ Block (RawSubtitle s);
+
/** Subtitle text in UTF-8 */
std::string text;
- std::string font;
+ boost::optional<std::string> font;
/** font size */
- 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;
- /** in points */
- boost::optional<int> _points;
-
- } font_size;
+ FontSize font_size;
boost::optional<Effect> effect;
boost::optional<Colour> effect_colour;
-
+
Colour colour;
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
};
-/** A line of text which starts and stops at specific times */
-class Subtitle
+extern bool operator== (Block const & a, Block const & b);
+
+/** @class Line
+ * @brief A line of text within a subtitle.
+ *
+ * This represents a line of text which has a particular vertical position.
+ */
+class Line
{
public:
- Subtitle ()
- {}
+ Line ()
+ {
+ horizontal_position.reference = HORIZONTAL_CENTRE_OF_SCREEN;
+ }
+
+ /** Construct a Line taking any relevant information from a RawSubtitle */
+ Line (RawSubtitle s);
+
+ HorizontalPosition horizontal_position;
/** vertical position of the baseline of the text */
- struct VerticalPosition {
+ VerticalPosition vertical_position;
- /** 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;
+ std::vector<Block> blocks;
- bool operator== (VerticalPosition const & other) const;
-
- } vertical_position;
+ bool same_metadata (RawSubtitle) const;
+};
+
+extern bool operator== (Line const & a, Line const & b);
+
+/** @class Subtitle
+ * @brief A subtitle which has been collected into lines and blocks.
+ *
+ * This represents a chunk of text which appears and disappears at some particular
+ * times.
+ */
+class Subtitle
+{
+public:
+ Subtitle ()
+ {}
+
+ /** Construct a Line taking any relevant information from a RawSubtitle */
+ Subtitle (RawSubtitle s);
/** from time */
- TimePair from;
+ Time from;
/** to time */
- TimePair to;
-
- boost::optional<MetricTime> fade_up;
- boost::optional<MetricTime> fade_down;
+ Time to;
+
+ boost::optional<Time> fade_up;
+ boost::optional<Time> fade_down;
- std::list<Block> blocks;
+ std::vector<Line> lines;
- bool same_metadata (Subtitle const &) const;
+ bool same_metadata (RawSubtitle) const;
};
-bool operator< (Subtitle const & a, Subtitle const & b);
+extern bool operator== (Subtitle const & a, Subtitle const & b);
}