From aebf2cb7812c8f593b85182611b587e6014aefc6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 29 May 2014 11:57:08 +0100 Subject: Re-work Subtitle class; remove STL text writer. --- src/subtitle.h | 90 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 33 deletions(-) (limited to 'src/subtitle.h') 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 #include #include 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 proportional () const { + return _proportional; + } + + boost::optional 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 proportional; + boost::optional _proportional; /** in points */ - boost::optional points; + boost::optional _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 proportional; - /** reference position for proportional */ - boost::optional reference; - } vertical_position; - boost::optional effect; boost::optional 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 frame; - boost::optional 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 frame; - boost::optional metric; - } to; + /** as a proportion of screen height offset from some reference point */ + boost::optional proportional; + /** reference position for proportional */ + boost::optional reference; + /** line number from the top of the screen */ + boost::optional 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 fade_up; boost::optional fade_down; + + std::list blocks; + + bool same_metadata (Subtitle const &) const; }; bool operator< (Subtitle const & a, Subtitle const & b); -- cgit v1.2.3