From aebf2cb7812c8f593b85182611b587e6014aefc6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 29 May 2014 11:57:08 +0100 Subject: [PATCH] Re-work Subtitle class; remove STL text writer. --- src/dcp_reader.cc | 55 +- src/dcp_reader.h | 10 +- src/stl_binary_reader.cc | 47 +- src/stl_binary_writer.cc | 134 +++++ src/{convert_time.h => stl_binary_writer.h} | 27 +- src/stl_text_reader.cc | 54 +- src/stl_text_reader.h | 6 +- src/stl_text_writer.cc | 84 --- src/stl_text_writer.h | 26 - src/subtitle.cc | 76 ++- src/subtitle.h | 90 ++-- src/{convert_time.cc => time_pair.cc} | 35 +- src/wscript | 6 +- test/dcp_reader_test.cc | 540 +++++++++++--------- test/dcp_to_stl_text_test.cc | 47 -- test/stl_text_reader_test.cc | 189 ++++--- test/stl_text_writer_test.cc | 68 --- test/time_test.cc | 17 +- test/wscript | 2 - tools/dumpsubs.cc | 4 +- 20 files changed, 783 insertions(+), 734 deletions(-) create mode 100644 src/stl_binary_writer.cc rename src/{convert_time.h => stl_binary_writer.h} (55%) delete mode 100644 src/stl_text_writer.cc delete mode 100644 src/stl_text_writer.h rename src/{convert_time.cc => time_pair.cc} (57%) delete mode 100644 test/dcp_to_stl_text_test.cc delete mode 100644 test/stl_text_writer_test.cc diff --git a/src/dcp_reader.cc b/src/dcp_reader.cc index 4c3384e..bd5c183 100644 --- a/src/dcp_reader.cc +++ b/src/dcp_reader.cc @@ -207,6 +207,13 @@ public: string uri; }; +struct DCPReader::ParseState { + list > font_nodes; + list > text_nodes; + list > subtitle_nodes; + boost::optional subtitle; +}; + } /** @param s A string. @@ -263,6 +270,10 @@ DCPReader::DCPReader (istream& in) ParseState parse_state; examine_font_nodes (xml, font_nodes, parse_state); + if (parse_state.subtitle && !parse_state.subtitle.get().blocks.empty ()) { + _subs.push_back (parse_state.subtitle.get ()); + } + _subs.sort (); } @@ -308,7 +319,7 @@ DCPReader::examine_text_nodes ( } void -DCPReader::maybe_add_subtitle (string text, ParseState const & parse_state) +DCPReader::maybe_add_subtitle (string text, ParseState& parse_state) { if (empty_or_white_space (text)) { return; @@ -325,19 +336,31 @@ DCPReader::maybe_add_subtitle (string text, ParseState const & parse_state) DCPText effective_text (*parse_state.text_nodes.back ()); DCPSubtitle effective_subtitle (*parse_state.subtitle_nodes.back ()); - Subtitle s; - s.text = text; - s.font = font_id_to_name (effective_font.id); - s.font_size.proportional = float (effective_font.size) / (72 * 11); - s.vertical_position.proportional = float (effective_text.v_position) / 100; - s.vertical_position.reference = effective_text.v_align; - s.effect = effective_font.effect; - s.effect_colour = effective_font.effect_colour; - s.colour = effective_font.colour.get (); - s.italic = effective_font.italic.get (); - s.from.metric = effective_subtitle.in; - s.to.metric = effective_subtitle.out; - s.fade_up = effective_subtitle.fade_up_time; - s.fade_down = effective_subtitle.fade_down_time; - _subs.push_back (s); + Subtitle proposed_subtitle; + proposed_subtitle.vertical_position.proportional = float (effective_text.v_position) / 100; + proposed_subtitle.vertical_position.reference = effective_text.v_align; + proposed_subtitle.from.set_metric (effective_subtitle.in); + proposed_subtitle.to.set_metric (effective_subtitle.out); + proposed_subtitle.fade_up = effective_subtitle.fade_up_time; + proposed_subtitle.fade_down = effective_subtitle.fade_down_time; + + if (!parse_state.subtitle || !parse_state.subtitle.get().same_metadata (proposed_subtitle)) { + /* We need a new Subtitle */ + if (parse_state.subtitle && !parse_state.subtitle.get().blocks.empty ()) { + /* Push the old one */ + _subs.push_back (parse_state.subtitle.get ()); + } + parse_state.subtitle = proposed_subtitle; + } + + Block block; + block.text = text; + block.font = font_id_to_name (effective_font.id); + block.font_size.set_proportional (float (effective_font.size) / (72 * 11)); + block.effect = effective_font.effect; + block.effect_colour = effective_font.effect_colour; + block.colour = effective_font.colour.get (); + block.italic = effective_font.italic.get (); + + parse_state.subtitle.get().blocks.push_back (block); } diff --git a/src/dcp_reader.h b/src/dcp_reader.h index 51ada1a..aa8df7f 100644 --- a/src/dcp_reader.h +++ b/src/dcp_reader.h @@ -37,14 +37,10 @@ public: DCPReader (std::istream &); private: - - struct ParseState { - std::list > font_nodes; - std::list > text_nodes; - std::list > subtitle_nodes; - }; - void maybe_add_subtitle (std::string text, ParseState const & parse_state); + struct ParseState; + + void maybe_add_subtitle (std::string text, ParseState& parse_state); void examine_font_nodes ( boost::shared_ptr xml, diff --git a/src/stl_binary_reader.cc b/src/stl_binary_reader.cc index 0d97e2e..ebcee1b 100644 --- a/src/stl_binary_reader.cc +++ b/src/stl_binary_reader.cc @@ -26,11 +26,13 @@ #include "compose.hpp" using std::map; +using std::vector; using std::cout; using std::string; using std::istream; using boost::lexical_cast; using boost::algorithm::replace_all; +using boost::is_any_of; using boost::locale::conv::utf_to_utf; using namespace sub; @@ -120,7 +122,6 @@ STLBinaryReader::STLBinaryReader (istream& in) editor_contact_details = get_string (341, 32); for (int i = 0; i < tti_blocks; ++i) { - Subtitle sub; in.read ((char *) _buffer, 128); if (in.gcount() != 128) { @@ -131,26 +132,32 @@ STLBinaryReader::STLBinaryReader (istream& in) continue; } - sub.from.frame = get_timecode (5); - sub.to.frame = get_timecode (9); - sub.line = get_int (13, 1); - - /* XXX: justification, effects */ - - string s = get_string (16, 112); - - /* 8Ah is a new line */ - replace_all (s, "\x8a", "\n"); - - /* 8Fh is unused space, so trim the string to the first instance of that */ - size_t unused = s.find_first_of ('\x8f'); - if (unused != string::npos) { - s = s.substr (0, unused); + string const whole = get_string (16, 112); + + /* Split the text up into lines (8Ah is a new line) */ + vector lines; + split (lines, whole, is_any_of ("\x8a")); + + for (size_t i = 0; i < lines.size(); ++i) { + Subtitle sub; + sub.from.set_frame (get_timecode (5)); + sub.to.set_frame (get_timecode (9)); + sub.vertical_position.line = get_int (13, 1) + i; + + /* XXX: justification, effects */ + + /* 8Fh is unused space, so trim the string to the first instance of that */ + size_t unused = lines[i].find_first_of ('\x8f'); + if (unused != string::npos) { + lines[i] = lines[i].substr (0, unused); + } + + Block block; + block.text = utf_to_utf (iso6937_to_utf16 (lines[i].c_str())); + sub.blocks.push_back (block); + + _subs.push_back (sub); } - - sub.text = utf_to_utf (iso6937_to_utf16 (s.c_str())); - - _subs.push_back (sub); } } diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc new file mode 100644 index 0000000..34e4d73 --- /dev/null +++ b/src/stl_binary_writer.cc @@ -0,0 +1,134 @@ +/* + Copyright (C) 2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include +#include "stl_binary_writer.h" +#include "compose.hpp" + +using std::list; +using std::ofstream; +using std::string; +using namespace sub; + +static void +put_string (char* p, string s) +{ + memcpy (p, s.c_str (), s.length ()); +} + +static void +put_string (char* p, int n, string s) +{ + memcpy (p, s.c_str (), s.length ()); + memset (p + s.length(), ' ', s.length () - n); +} + +/** @param language ISO 3-character country code for the language of the subtitles */ +void +sub::write_stl_binary ( + list subtitles, + float frames_per_second, + string language, + string original_programme_title, + string original_episode_title, + string translated_programme_title, + string translated_episode_title, + string translator_name, + string translator_contact_details, + string creation_date, + string revision_date, + int revision_number, + string country_of_origin, + string publisher, + string editor_name, + string editor_contact_details, + boost::filesystem::path file_name + ) +{ + assert (language.size() == 3); + assert (original_programme_title.size() <= 32); + assert (original_episode_title.size() <= 32); + assert (translated_programme_title.size() <= 32); + assert (translated_episode_title.size() <= 32); + assert (translator_name.size() <= 32); + assert (translator_contact_details.size() <= 32); + assert (creation_date.size() == 6); + assert (revision_date.size() == 6); + assert (revision_number <= 99); + assert (country_of_origin.size() == 3); + assert (publisher.size() <= 32); + assert (editor_name.size() <= 32); + assert (editor_contact_details.size() <= 32); + + char* buffer = new char[1024]; + ofstream output (file_name.string().c_str ()); + + /* Code page: 850 */ + put_string (buffer + 0, "850"); + /* Disk format code */ + put_string (buffer + 3, String::compose ("STL%1.01", rint (frames_per_second))); + /* Display standard code: open subtitling */ + put_string (buffer + 11, "0"); + /* Character code table: Latin (ISO 6937) */ + put_string (buffer + 12, "00"); + put_string (buffer + 14, language); + put_string (buffer + 16, 32, original_programme_title); + put_string (buffer + 48, 32, original_episode_title); + put_string (buffer + 80, 32, translated_programme_title); + put_string (buffer + 112, 32, translated_episode_title); + put_string (buffer + 144, 32, translator_name); + put_string (buffer + 176, 32, translator_contact_details); + /* Subtitle list reference code */ + put_string (buffer + 208, "0000000000000000"); + put_string (buffer + 224, creation_date); + put_string (buffer + 230, revision_date); + put_string (buffer + 236, String::compose ("%02d", revision_number)); + /* TTI blocks */ + put_string (buffer + 238, String::compose ("%05d", subtitles.size ())); + /* Total number of subtitles */ + put_string (buffer + 243, String::compose ("%05d", subtitles.size ())); + /* Total number of subtitle groups */ + put_string (buffer + 248, "000"); + /* Maximum number of displayable characters in any text row */ + /* XXX */ + put_string (buffer + 251, "99"); + /* Maximum number of displayable rows */ + /* XXX */ + put_string (buffer + 253, "99"); + /* Time code status */ + put_string (buffer + 255, "1"); + /* Start-of-programme time code */ + put_string (buffer + 256, "00000000"); + /* First-in-cue time code */ + put_string (buffer + 264, "00000000"); + /* Total number of disks */ + put_string (buffer + 272, "1"); + /* Disk sequence number */ + put_string (buffer + 273, "1"); + put_string (buffer + 274, country_of_origin); + put_string (buffer + 277, publisher); + put_string (buffer + 309, editor_name); + put_string (buffer + 341, editor_contact_details); + + output.write (buffer, 1024); + + delete[] buffer; +} diff --git a/src/convert_time.h b/src/stl_binary_writer.h similarity index 55% rename from src/convert_time.h rename to src/stl_binary_writer.h index 92ec737..7dbf5a5 100644 --- a/src/convert_time.h +++ b/src/stl_binary_writer.h @@ -17,12 +17,31 @@ */ -#include "metric_time.h" -#include "frame_time.h" +#include +#include namespace sub { -FrameTime metric_to_frame (MetricTime, float frames_per_second); -MetricTime frame_to_metric (FrameTime, float frames_per_second); +class Subtitle; + +extern void write_stl_binary ( + std::list subtitles, + float frames_per_second, + std::string language, + std::string original_programme_title, + std::string original_episode_title, + std::string translated_programme_title, + std::string translated_episode_title, + std::string translator_name, + std::string translator_contact_details, + std::string creation_date, + std::string revision_date, + int revision_number, + std::string country_of_origin, + std::string publisher, + std::string editor_name, + std::string editor_contact_details, + boost::filesystem::path file_name + ); } diff --git a/src/stl_text_reader.cc b/src/stl_text_reader.cc index f9e9b65..0b4141c 100644 --- a/src/stl_text_reader.cc +++ b/src/stl_text_reader.cc @@ -38,6 +38,8 @@ using namespace sub; STLTextReader::STLTextReader (istream& in) { + _subtitle.vertical_position.line = 0; + while (in.good ()) { string line; getline (in, line); @@ -91,38 +93,37 @@ STLTextReader::STLTextReader (istream& in) continue; } - _current.from.frame = from.get (); - _current.to.frame = to.get (); + _subtitle.from.set_frame (from.get ()); + _subtitle.to.set_frame (to.get ()); /* Parse ^B/^I/^U */ string text = line.substr (divider[1] + 1); for (size_t i = 0; i < text.length(); ++i) { if (text[i] == '|') { - maybe_push (); - _current.line++; + maybe_push_subtitle (); + _subtitle.vertical_position.line = _subtitle.vertical_position.line.get() + 1; } else if (text[i] == '^') { - maybe_push (); + maybe_push_block (); if ((i + 1) < text.length()) { switch (text[i + 1]) { case 'B': - _current.bold = !_current.bold; + _block.bold = !_block.bold; break; case 'I': - _current.italic = !_current.italic; + _block.italic = !_block.italic; break; case 'U': - _current.underline = !_current.underline; + _block.underline = !_block.underline; break; } } ++i; } else { - _current.text += text[i]; + _block.text += text[i]; } } - maybe_push (); - _current.line = 0; + maybe_push_subtitle (); } } } @@ -144,24 +145,37 @@ void STLTextReader::set (string name, string value) { if (name == "$FontName") { - _current.font = value; + _block.font = value; } else if (name == "$Bold") { - _current.bold = value == "True"; + _block.bold = value == "True"; } else if (name == "$Italic") { - _current.italic = value == "True"; + _block.italic = value == "True"; } else if (name == "$Underlined") { - _current.underline = value == "True"; + _block.underline = value == "True"; } else if (name == "$FontSize") { - _current.font_size.points = lexical_cast (value); + _block.font_size.set_points (lexical_cast (value)); + } +} + +void +STLTextReader::maybe_push_subtitle () +{ + maybe_push_block (); + + if (!_subtitle.blocks.empty ()) { + _subs.push_back (_subtitle); + _subtitle.blocks.clear (); + _subtitle.vertical_position.line = 0; } } void -STLTextReader::maybe_push () +STLTextReader::maybe_push_block () { - if (!_current.text.empty ()) { - _subs.push_back (_current); - _current.text.clear (); + if (!_block.text.empty ()) { + _subtitle.blocks.push_back (_block); + _block.text.clear (); } } + diff --git a/src/stl_text_reader.h b/src/stl_text_reader.h index c48a8e5..e6a550a 100644 --- a/src/stl_text_reader.h +++ b/src/stl_text_reader.h @@ -29,10 +29,12 @@ public: private: void set (std::string name, std::string value); - void maybe_push (); + void maybe_push_subtitle (); + void maybe_push_block (); boost::optional time (std::string t) const; - Subtitle _current; + Subtitle _subtitle; + Block _block; }; } diff --git a/src/stl_text_writer.cc b/src/stl_text_writer.cc deleted file mode 100644 index 6a8601d..0000000 --- a/src/stl_text_writer.cc +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright (C) 2014 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "stl_text_writer.h" -#include - -using std::list; -using std::ostream; -using std::string; -using boost::optional; -using namespace sub; - -void -sub::write_stl_text (list subtitles, int screen_height_in_points, float frames_per_second, ostream& out) -{ - optional font; - optional font_size; - bool bold = false; - bool italic = false; - bool underline = false; - int line = 0; - optional from; - optional to; - - for (list::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) { - bool started_new = false; - if (!font || font.get() != i->font) { - out << "\n$FontName = " << i->font; - font = i->font; - started_new = true; - } - if (!font_size || font_size.get() != i->font_size_points (screen_height_in_points)) { - out << "\n$FontSize = " << i->font_size_points (screen_height_in_points); - font_size = i->font_size_points (screen_height_in_points); - started_new = true; - } - string text; - if (bold != i->bold) { - text += "^B"; - bold = i->bold; - } - if (italic != i->italic) { - text += "^I"; - italic = i->italic; - } - if (underline != i->underline) { - text += "^U"; - underline = i->underline; - } - - text += i->text; - - if (from && from.get() == i->from_frame(frames_per_second) && to && to.get() == i->to_frame(frames_per_second) && !started_new) { - for (int j = line; j < i->line; ++j) { - out << "|"; - } - out << text; - line = i->line; - } else { - out << "\n" << i->from_frame(frames_per_second).timecode() << "," << i->to_frame(frames_per_second).timecode() << "," << text; - from = i->from_frame (frames_per_second); - to = i->to_frame (frames_per_second); - line = 0; - } - } - - out << "\n"; -} diff --git a/src/stl_text_writer.h b/src/stl_text_writer.h deleted file mode 100644 index d44696f..0000000 --- a/src/stl_text_writer.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright (C) 2014 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "subtitle.h" - -namespace sub { - -extern void write_stl_text (std::list subtitles, int screen_height_in_points, float frames_per_second, std::ostream &); - -} diff --git a/src/subtitle.cc b/src/subtitle.cc index 6d3360f..5eb5784 100644 --- a/src/subtitle.cc +++ b/src/subtitle.cc @@ -18,81 +18,65 @@ */ #include "subtitle.h" -#include "convert_time.h" -using std::list; using namespace sub; bool sub::operator< (Subtitle const & a, Subtitle const & b) { - if (a.from.frame && b.from.frame) { - return a.from.frame.get() < b.from.frame.get(); + if (a.from.frame() && b.from.frame()) { + return a.from.frame().get() < b.from.frame().get(); } - if (a.from.metric && b.from.metric) { - return a.from.metric.get() < b.from.metric.get(); + if (a.from.metric() && b.from.metric()) { + return a.from.metric().get() < b.from.metric().get(); } assert (false); } -FrameTime -Subtitle::from_frame (float frames_per_second) const -{ - if (from.frame) { - return from.frame.get (); - } - - return metric_to_frame (from.metric.get(), frames_per_second); -} -FrameTime -Subtitle::to_frame (float frames_per_second) const +float +Block::FontSize::proportional (int screen_height_in_points) const { - if (to.frame) { - return to.frame.get (); + if (_proportional) { + return _proportional.get (); } - return metric_to_frame (to.metric.get(), frames_per_second); + return float (_points.get ()) / screen_height_in_points; } -MetricTime -Subtitle::from_metric (float frames_per_second) const +int +Block::FontSize::points (int screen_height_in_points) const { - if (from.metric) { - return from.metric.get (); + if (_points) { + return _points.get (); } - return frame_to_metric (from.frame.get(), frames_per_second); + return _proportional.get() * screen_height_in_points; } -MetricTime -Subtitle::to_metric (float frames_per_second) const +bool +Subtitle::same_metadata (Subtitle const & other) const { - if (to.metric) { - return to.metric.get (); - } - - return frame_to_metric (to.frame.get(), frames_per_second); + return ( + vertical_position == other.vertical_position && + from == other.from && + to == other.to && + fade_up == other.fade_up && + fade_down == other.fade_down + ); } -float -Subtitle::font_size_proportional (int screen_height_in_points) const +bool +Subtitle::VerticalPosition::operator== (Subtitle::VerticalPosition const & other) const { - if (font_size.proportional) { - return font_size.proportional.get (); + if (proportional && reference && other.proportional && other.reference) { + return proportional.get() == other.proportional.get() && reference.get() == other.reference.get(); + } else if (line && other.line) { + return line.get() == other.line.get(); } - return float (font_size.points.get ()) / screen_height_in_points; + return false; } -int -Subtitle::font_size_points (int screen_height_in_points) const -{ - if (font_size.points) { - return font_size.points.get (); - } - - return font_size.proportional.get() * screen_height_in_points; -} 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); diff --git a/src/convert_time.cc b/src/time_pair.cc similarity index 57% rename from src/convert_time.cc rename to src/time_pair.cc index 3ae165b..186d54c 100644 --- a/src/convert_time.cc +++ b/src/time_pair.cc @@ -17,21 +17,40 @@ */ -#include "metric_time.h" -#include "frame_time.h" -#include "convert_time.h" +#include "time_pair.h" -using std::cout; using namespace sub; FrameTime -sub::metric_to_frame (MetricTime t, float frames_per_second) +TimePair::frame (float frames_per_second) const { - return FrameTime (t.hours(), t.minutes(), t.seconds(), t.milliseconds() * frames_per_second / 1000); + if (_frame) { + return _frame.get (); + } + + MetricTime const m = _metric.get (); + return FrameTime (m.hours(), m.minutes(), m.seconds(), m.milliseconds() * frames_per_second / 1000); } MetricTime -sub::frame_to_metric (FrameTime t, float frames_per_second) +TimePair::metric (float frames_per_second) const +{ + if (_metric) { + return _metric.get (); + } + + FrameTime const f = _frame.get (); + return MetricTime (f.hours(), f.minutes(), f.seconds(), f.frames() * 1000 / frames_per_second); +} + +bool +TimePair::operator== (TimePair const & other) const { - return MetricTime (t.hours(), t.minutes(), t.seconds(), t.frames() * 1000 / frames_per_second); + if (_metric && other._metric) { + return _metric.get() == other._metric.get(); + } else if (_frame && other._frame) { + return _frame.get() == other._frame.get(); + } + + return false; } diff --git a/src/wscript b/src/wscript index c2bdd64..dd04aa9 100644 --- a/src/wscript +++ b/src/wscript @@ -12,7 +12,6 @@ def build(bld): obj.export_includes = ['.'] obj.source = """ colour.cc - convert_time.cc dcp_reader.cc effect.cc frame_time.cc @@ -23,22 +22,21 @@ def build(bld): reader_factory.cc stl_binary_reader.cc stl_text_reader.cc - stl_text_writer.cc + time_pair.cc subtitle.cc vertical_reference.cc """ headers = """ colour.h - convert_time.h dcp_reader.h effect.h frame_time.h metric_time.h reader.h stl_text_reader.h - stl_text_writer.h subtitle.h + time_pair.h vertical_reference.h """ diff --git a/test/dcp_reader_test.cc b/test/dcp_reader_test.cc index 0029d16..0163108 100644 --- a/test/dcp_reader_test.cc +++ b/test/dcp_reader_test.cc @@ -36,81 +36,91 @@ BOOST_AUTO_TEST_CASE (dcp_reader_test1) list::iterator i = subs.begin (); BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (39) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric, sub::MetricTime (0, 0, 5, 198 * 4)); - BOOST_CHECK_EQUAL (i->to.metric, sub::MetricTime (0, 0, 7, 115 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + sub::Block b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (39) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 0, 5, 198 * 4)); + BOOST_CHECK_EQUAL (i->to.metric(), sub::MetricTime (0, 0, 7, 115 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.15, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::BOTTOM); - BOOST_CHECK_EQUAL (i->text, "My jacket was Idi Amin's"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "My jacket was Idi Amin's"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 4)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 4)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (39) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric, sub::MetricTime (0, 0, 7, 177 * 4)); - BOOST_CHECK_EQUAL (i->to.metric, sub::MetricTime (0, 0, 11, 31 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (39) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 0, 7, 177 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 0, 11, 31 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.21, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::BOTTOM); - BOOST_CHECK_EQUAL (i->text, "My corset was H.M. The Queen's"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "My corset was H.M. The Queen's"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 4)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 4)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (39) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric, sub::MetricTime (0, 0, 7, 177 * 4)); - BOOST_CHECK_EQUAL (i->to.metric, sub::MetricTime (0, 0, 11, 31 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (39) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 0, 7, 177 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 0, 11, 31 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.15, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::BOTTOM); - BOOST_CHECK_EQUAL (i->text, "My large wonderbra"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "My large wonderbra"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 4)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 4)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (39) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric, sub::MetricTime (0, 0, 11, 94 * 4)); - BOOST_CHECK_EQUAL (i->to.metric, sub::MetricTime (0, 0, 13, 63 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (39) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 0, 11, 94 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 0, 13, 63 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.15, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::BOTTOM); - BOOST_CHECK_EQUAL (i->text, "Once belonged to the Shah"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "Once belonged to the Shah"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 4)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 4)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (39) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric, sub::MetricTime (0, 0, 13, 104 * 4)); - BOOST_CHECK_EQUAL (i->to.metric, sub::MetricTime (0, 0, 15, 177 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (39) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric(), sub::MetricTime (0, 0, 13, 104 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 0, 15, 177 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.15, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::BOTTOM); - BOOST_CHECK_EQUAL (i->text, "And these are Roy Hattersley's jeans"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "And these are Roy Hattersley's jeans"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 4)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 4)); } @@ -125,353 +135,397 @@ BOOST_AUTO_TEST_CASE (dcp_reader_test2) list::iterator i = subs.begin (); BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric, sub::MetricTime (0, 0, 41, 62 * 4)); - BOOST_CHECK_EQUAL (i->to.metric, sub::MetricTime (0, 0, 43, 52 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + sub::Block b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric(), sub::MetricTime (0, 0, 41, 62 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 0, 43, 52 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "At afternoon tea with John Peel"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "At afternoon tea with John Peel"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric, sub::MetricTime (0, 0, 41, 62 * 4)); - BOOST_CHECK_EQUAL (i->to.metric, sub::MetricTime (0, 0, 43, 52 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric(), sub::MetricTime (0, 0, 41, 62 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 0, 43, 52 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "I enquired if his accent was real"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "I enquired if his accent was real"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric, sub::MetricTime (0, 0, 50, 42 * 4)); - BOOST_CHECK_EQUAL (i->to.metric, sub::MetricTime (0, 0, 52, 21 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric(), sub::MetricTime (0, 0, 50, 42 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 0, 52, 21 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "He said \"out of the house"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "He said \"out of the house"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric, sub::MetricTime (0, 0, 50, 42 * 4)); - BOOST_CHECK_EQUAL (i->to.metric, sub::MetricTime (0, 0, 52, 21 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric(), sub::MetricTime (0, 0, 50, 42 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 0, 52, 21 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "I'm incredibly scouse"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "I'm incredibly scouse"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 2, 208 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 04, 10 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 2, 208 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 04, 10 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "At home it depends how I feel.\""); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "At home it depends how I feel.\""); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 2, 208 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 4, 10 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 2, 208 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 4, 10 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "I spent a long weekend in Brighton"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "I spent a long weekend in Brighton"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 15, 42 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 16, 42 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 15, 42 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 16, 42 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "With the legendary Miss Enid Blyton"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "With the legendary Miss Enid Blyton"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 15, 42 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 16, 42 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 15, 42 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 16, 42 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "She said \"you be Noddy"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "She said \"you be Noddy"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 20, 219 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 22, 73 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 20, 219 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 22, 73 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "and I'll show you my body\""); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "and I'll show you my body\""); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 20, 219 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 22, 73 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 20, 219 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 22, 73 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "But Big Ears kept turning the light on."); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "But Big Ears kept turning the light on."); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 27, 115 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 28, 208 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 27, 115 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 28, 208 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "That curious creature the Sphinx"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "That curious creature the Sphinx"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 27, 115 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 28, 208 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 27, 115 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 28, 208 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "Is smarter than anyone thinks"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "Is smarter than anyone thinks"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 42, 229 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 45, 62 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 42, 229 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 45, 62 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "It sits there and smirks"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "It sits there and smirks"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 42, 229 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 45, 62 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 42, 229 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 45, 62 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "And you don't think it works"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "And you don't think it works"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 45, 146 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 47, 94 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 45, 146 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 47, 94 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "Then when you're not looking, it winks."); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "Then when you're not looking, it winks."); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 45, 146 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 47, 94 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 45, 146 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 47, 94 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "When it snows you will find Sister Sledge"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "When it snows you will find Sister Sledge"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 47, 146 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 48, 167 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 47, 146 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 48, 167 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "Out mooning, at night, on the ledge"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "Out mooning, at night, on the ledge"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 47, 146 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 48, 167 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 47, 146 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 48, 167 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "One storey down"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "One storey down"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 53, 21 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 56, 10 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 53, 21 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 56, 10 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "Is the maestro, James Brown"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "Is the maestro, James Brown"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 1, 53, 21 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 1, 56, 10 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 1, 53, 21 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 1, 56, 10 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "Displaying his meat and two veg."); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "Displaying his meat and two veg."); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 2, 5, 208 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 2, 7, 31 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 2, 5, 208 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 2, 7, 31 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.89, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "HELLO"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "HELLO"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK (i->colour == sub::Colour (1, 1, 1)); - BOOST_CHECK_EQUAL (i->font_size.proportional.get(), float (42) / (72 * 11)); - BOOST_CHECK_EQUAL (i->from.metric.get(), sub::MetricTime (0, 2, 5, 208 * 4)); - BOOST_CHECK_EQUAL (i->to.metric.get(), sub::MetricTime (0, 2, 7, 31 * 4)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.italic, true); + BOOST_CHECK (b.colour == sub::Colour (1, 1, 1)); + BOOST_CHECK_EQUAL (b.font_size.proportional().get(), float (42) / (72 * 11)); + BOOST_CHECK_EQUAL (i->from.metric().get(), sub::MetricTime (0, 2, 5, 208 * 4)); + BOOST_CHECK_EQUAL (i->to.metric().get(), sub::MetricTime (0, 2, 7, 31 * 4)); BOOST_CHECK_CLOSE (i->vertical_position.proportional.get(), 0.95, 1); BOOST_CHECK_EQUAL (i->vertical_position.reference.get(), sub::TOP); - BOOST_CHECK_EQUAL (i->text, "WORLD"); - BOOST_CHECK_EQUAL (i->effect, sub::BORDER); - BOOST_CHECK (i->effect_colour.get() == sub::Colour (0, 0, 0)); + BOOST_CHECK_EQUAL (b.text, "WORLD"); + BOOST_CHECK_EQUAL (b.effect, sub::BORDER); + BOOST_CHECK (b.effect_colour.get() == sub::Colour (0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_up.get(), sub::MetricTime (0, 0, 0, 0)); BOOST_CHECK_EQUAL (i->fade_down.get(), sub::MetricTime (0, 0, 0, 0)); } diff --git a/test/dcp_to_stl_text_test.cc b/test/dcp_to_stl_text_test.cc deleted file mode 100644 index 4f553bc..0000000 --- a/test/dcp_to_stl_text_test.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (C) 2014 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include "test.h" -#include "dcp_reader.h" -#include "stl_text_writer.h" - -using std::string; -using std::ifstream; -using std::ofstream; - -BOOST_AUTO_TEST_CASE (dcp_to_stl_text_test) -{ - using boost::filesystem::path; - - if (private_test.empty ()) { - return; - } - - path p = private_test / "fd586c30-6d38-48f2-8241-27359acf184c_sub.xml"; - ifstream f (p.c_str ()); - sub::DCPReader r (f); - path const q = path ("build") / path ("test") / path ("fd586c30-6d38-48f2-8241-27359acf184c_sub.stl"); - ofstream g (q.c_str ()); - sub::write_stl_text (r.subtitles (), 72 * 11, 24, g); - path const c = private_test / "fd586c30-6d38-48f2-8241-27359acf184c_sub.stl"; - g.close (); - check_text (q, c); -} diff --git a/test/stl_text_reader_test.cc b/test/stl_text_reader_test.cc index fa9d448..ddf754e 100644 --- a/test/stl_text_reader_test.cc +++ b/test/stl_text_reader_test.cc @@ -24,6 +24,7 @@ using std::list; using std::ifstream; +using std::vector; /* Test reading of a textual STL file */ BOOST_AUTO_TEST_CASE (stl_text_reader_test) @@ -35,111 +36,105 @@ BOOST_AUTO_TEST_CASE (stl_text_reader_test) list::iterator i = subs.begin (); BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->text, " This is a subtitle "); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->font_size.points.get(), 42); - BOOST_CHECK_EQUAL (i->bold, false); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK_EQUAL (i->underline, false); - BOOST_CHECK_EQUAL (i->line, 0); - BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 0, 41, 9)); - BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 0, 42, 21)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + sub::Block b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.text, " This is a subtitle "); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.font_size.points().get(), 42); + BOOST_CHECK_EQUAL (b.bold, false); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK_EQUAL (b.underline, false); + BOOST_CHECK_EQUAL (i->vertical_position.line.get(), 0); + BOOST_CHECK_EQUAL (i->from.frame().get(), sub::FrameTime (0, 0, 41, 9)); + BOOST_CHECK_EQUAL (i->to.frame().get(), sub::FrameTime (0, 0, 42, 21)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->text, " and that's a line break"); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->font_size.points.get(), 42); - BOOST_CHECK_EQUAL (i->bold, false); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK_EQUAL (i->underline, false); - BOOST_CHECK_EQUAL (i->line, 1); - BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 0, 41, 9)); - BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 0, 42, 21)); + BOOST_CHECK_EQUAL (i->blocks.size(), 1); + b = i->blocks.front (); + BOOST_CHECK_EQUAL (b.text, " and that's a line break"); + BOOST_CHECK_EQUAL (b.font, "Arial"); + BOOST_CHECK_EQUAL (b.font_size.points().get(), 42); + BOOST_CHECK_EQUAL (b.bold, false); + BOOST_CHECK_EQUAL (b.italic, false); + BOOST_CHECK_EQUAL (b.underline, false); + BOOST_CHECK_EQUAL (i->vertical_position.line.get(), 1); + BOOST_CHECK_EQUAL (i->from.frame().get(), sub::FrameTime (0, 0, 41, 9)); + BOOST_CHECK_EQUAL (i->to.frame().get(), sub::FrameTime (0, 0, 42, 21)); ++i; BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->text, " This is some "); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->font_size.points.get(), 42); - BOOST_CHECK_EQUAL (i->bold, false); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK_EQUAL (i->underline, false); - BOOST_CHECK_EQUAL (i->line, 0); - BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1)); - BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10)); - ++i; - - BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->text, "bold"); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->font_size.points.get(), 42); - BOOST_CHECK_EQUAL (i->bold, true); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK_EQUAL (i->underline, false); - BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1)); - BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10)); - ++i; - - BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->text, " and some "); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->font_size.points.get(), 42); - BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1)); - BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10)); - BOOST_CHECK_EQUAL (i->bold, false); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK_EQUAL (i->underline, false); - BOOST_CHECK_EQUAL (i->line, 0); - ++i; - - BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->text, "bold italic"); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->font_size.points.get(), 42); - BOOST_CHECK_EQUAL (i->bold, true); - BOOST_CHECK_EQUAL (i->italic, true); - BOOST_CHECK_EQUAL (i->underline, false); - BOOST_CHECK_EQUAL (i->line, 0); - BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1)); - BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10)); - ++i; + BOOST_CHECK_EQUAL (i->blocks.size(), 7); + BOOST_CHECK_EQUAL (i->vertical_position.line.get(), 0); + BOOST_CHECK_EQUAL (i->from.frame().get(), sub::FrameTime (0, 1, 1, 1)); + BOOST_CHECK_EQUAL (i->to.frame().get(), sub::FrameTime (0, 1, 2, 10)); - BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->text, " and some "); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->font_size.points.get(), 42); - BOOST_CHECK_EQUAL (i->bold, false); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK_EQUAL (i->underline, false); - BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1)); - BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10)); - ++i; - - BOOST_CHECK (i != subs.end ()); - BOOST_CHECK_EQUAL (i->text, "underlined"); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->font_size.points.get(), 42); - BOOST_CHECK_EQUAL (i->bold, false); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK_EQUAL (i->underline, true); - BOOST_CHECK_EQUAL (i->line, 0); - BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1)); - BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10)); - ++i; - - BOOST_CHECK_EQUAL (i->text, "."); - BOOST_CHECK_EQUAL (i->font, "Arial"); - BOOST_CHECK_EQUAL (i->font_size.points.get(), 42); - BOOST_CHECK_EQUAL (i->bold, false); - BOOST_CHECK_EQUAL (i->italic, false); - BOOST_CHECK_EQUAL (i->underline, false); - BOOST_CHECK_EQUAL (i->line, 0); - BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1)); - BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10)); - ++i; + list::iterator j = i->blocks.begin (); + + BOOST_CHECK (j != i->blocks.end ()); + BOOST_CHECK_EQUAL (j->text, " This is some "); + BOOST_CHECK_EQUAL (j->font, "Arial"); + BOOST_CHECK_EQUAL (j->font_size.points().get(), 42); + BOOST_CHECK_EQUAL (j->bold, false); + BOOST_CHECK_EQUAL (j->italic, false); + BOOST_CHECK_EQUAL (j->underline, false); + ++j; + + BOOST_CHECK (j != i->blocks.end ()); + BOOST_CHECK_EQUAL (j->text, "bold"); + BOOST_CHECK_EQUAL (j->font, "Arial"); + BOOST_CHECK_EQUAL (j->font_size.points().get(), 42); + BOOST_CHECK_EQUAL (j->bold, true); + BOOST_CHECK_EQUAL (j->italic, false); + BOOST_CHECK_EQUAL (j->underline, false); + ++j; + + BOOST_CHECK (j != i->blocks.end ()); + BOOST_CHECK_EQUAL (j->text, " and some "); + BOOST_CHECK_EQUAL (j->font, "Arial"); + BOOST_CHECK_EQUAL (j->font_size.points().get(), 42); + BOOST_CHECK_EQUAL (j->bold, false); + BOOST_CHECK_EQUAL (j->italic, false); + BOOST_CHECK_EQUAL (j->underline, false); + ++j; + + BOOST_CHECK (j != i->blocks.end ()); + BOOST_CHECK_EQUAL (j->text, "bold italic"); + BOOST_CHECK_EQUAL (j->font, "Arial"); + BOOST_CHECK_EQUAL (j->font_size.points().get(), 42); + BOOST_CHECK_EQUAL (j->bold, true); + BOOST_CHECK_EQUAL (j->italic, true); + BOOST_CHECK_EQUAL (j->underline, false); + ++j; + + BOOST_CHECK (j != i->blocks.end ()); + BOOST_CHECK_EQUAL (j->text, " and some "); + BOOST_CHECK_EQUAL (j->font, "Arial"); + BOOST_CHECK_EQUAL (j->font_size.points().get(), 42); + BOOST_CHECK_EQUAL (j->bold, false); + BOOST_CHECK_EQUAL (j->italic, false); + BOOST_CHECK_EQUAL (j->underline, false); + ++j; + + BOOST_CHECK (j != i->blocks.end ()); + BOOST_CHECK_EQUAL (j->text, "underlined"); + BOOST_CHECK_EQUAL (j->font, "Arial"); + BOOST_CHECK_EQUAL (j->font_size.points().get(), 42); + BOOST_CHECK_EQUAL (j->bold, false); + BOOST_CHECK_EQUAL (j->italic, false); + BOOST_CHECK_EQUAL (j->underline, true); + ++j; + + BOOST_CHECK (j != i->blocks.end ()); + BOOST_CHECK_EQUAL (j->text, "."); + BOOST_CHECK_EQUAL (j->font, "Arial"); + BOOST_CHECK_EQUAL (j->font_size.points().get(), 42); + BOOST_CHECK_EQUAL (j->bold, false); + BOOST_CHECK_EQUAL (j->italic, false); + BOOST_CHECK_EQUAL (j->underline, false); + ++j; - BOOST_CHECK (i == subs.end ()); + BOOST_CHECK (j == i->blocks.end ()); } diff --git a/test/stl_text_writer_test.cc b/test/stl_text_writer_test.cc deleted file mode 100644 index 8706bf3..0000000 --- a/test/stl_text_writer_test.cc +++ /dev/null @@ -1,68 +0,0 @@ -/* - Copyright (C) 2014 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include "stl_text_writer.h" -#include "subtitle.h" -#include "test.h" - -using std::list; -using std::string; -using std::ifstream; -using std::ofstream; - -static sub::Subtitle -make (string text, bool bold, bool italic, bool underline, int line, sub::FrameTime from, sub::FrameTime to) -{ - sub::Subtitle s; - s.text = text; - s.font = "Arial"; - s.font_size.points = 42; - s.bold = bold; - s.italic = italic; - s.underline = underline; - s.line = line; - s.from.frame = from; - s.to.frame = to; - return s; -} - -/* Test writing of an textual STL file */ -BOOST_AUTO_TEST_CASE (stl_text_writer_test) -{ - list subs; - subs.push_back (make (" This is a subtitle ", false, false, false, 0, sub::FrameTime (0, 0, 41, 9), sub::FrameTime (0, 0, 42, 21))); - subs.push_back (make (" and that's a line break", false, false, false, 1, sub::FrameTime (0, 0, 41, 9), sub::FrameTime (0, 0, 42, 21))); - subs.push_back (make (" This is some ", false, false, false, 0, sub::FrameTime (0, 1, 1, 1), sub::FrameTime (0, 1, 2, 10))); - subs.push_back (make ("bold", true, false, false, 0, sub::FrameTime (0, 1, 1, 1), sub::FrameTime (0, 1, 2, 10))); - subs.push_back (make (" and some ", false, false, false, 0, sub::FrameTime (0, 1, 1, 1), sub::FrameTime (0, 1, 2, 10))); - subs.push_back (make ("bold italic", true, true, false, 0, sub::FrameTime (0, 1, 1, 1), sub::FrameTime (0, 1, 2, 10))); - subs.push_back (make (" and some ", false, false, false, 0, sub::FrameTime (0, 1, 1, 1), sub::FrameTime (0, 1, 2, 10))); - subs.push_back (make ("underlined", false, false, true, 0, sub::FrameTime (0, 1, 1, 1), sub::FrameTime (0, 1, 2, 10))); - subs.push_back (make (".", false, false, false, 0, sub::FrameTime (0, 1, 1, 1), sub::FrameTime (0, 1, 2, 10))); - - ofstream f ("build/test/test.stl"); - write_stl_text (subs, 24, 72 * 11, f); - f.close (); - - check_text ("test/ref/test.stl", "build/test/test.stl"); -} - - diff --git a/test/time_test.cc b/test/time_test.cc index a244377..977ebd2 100644 --- a/test/time_test.cc +++ b/test/time_test.cc @@ -20,7 +20,7 @@ #include #include "metric_time.h" #include "frame_time.h" -#include "convert_time.h" +#include "time_pair.h" /* Check time construction */ BOOST_AUTO_TEST_CASE (time_construction_test) @@ -45,12 +45,17 @@ BOOST_AUTO_TEST_CASE (time_construction_test) /* Check time conversions */ BOOST_AUTO_TEST_CASE (time_conversion_test) { + sub::TimePair p; + /* 40ms = 1 frame at 25fps */ - BOOST_CHECK_EQUAL (metric_to_frame (sub::MetricTime (3, 5, 7, 40), 25), sub::FrameTime (3, 5, 7, 1)); - BOOST_CHECK_EQUAL (frame_to_metric (sub::FrameTime (3, 5, 7, 1), 25), sub::MetricTime (3, 5, 7, 40)); + p.set_metric (sub::MetricTime (3, 5, 7, 40)); + BOOST_CHECK_EQUAL (p.frame (25), sub::FrameTime (3, 5, 7, 1)); + p.set_frame (sub::FrameTime (3, 5, 7, 1)); + BOOST_CHECK_EQUAL (p.metric (25), sub::MetricTime (3, 5, 7, 40)); /* 120ms = 3 frames at 25fps */ - BOOST_CHECK_EQUAL (metric_to_frame (sub::MetricTime (3, 5, 7, 120), 25), sub::FrameTime (3, 5, 7, 3)); - BOOST_CHECK_EQUAL (frame_to_metric (sub::FrameTime (3, 5, 7, 3), 25), sub::MetricTime (3, 5, 7, 120)); + p.set_metric (sub::MetricTime (3, 5, 7, 120)); + BOOST_CHECK_EQUAL (p.frame (25), sub::FrameTime (3, 5, 7, 3)); + p.set_frame (sub::FrameTime (3, 5, 7, 3)); + BOOST_CHECK_EQUAL (p.metric (25), sub::MetricTime (3, 5, 7, 120)); } - diff --git a/test/wscript b/test/wscript index c3ee7f4..d9ea727 100644 --- a/test/wscript +++ b/test/wscript @@ -17,11 +17,9 @@ def build(bld): obj.use = 'libsub' obj.source = """ dcp_reader_test.cc - dcp_to_stl_text_test.cc iso6937_test.cc stl_binary_reader_test.cc stl_text_reader_test.cc - stl_text_writer_test.cc time_test.cc test.cc """ diff --git a/tools/dumpsubs.cc b/tools/dumpsubs.cc index b37203d..9ee890d 100644 --- a/tools/dumpsubs.cc +++ b/tools/dumpsubs.cc @@ -83,7 +83,9 @@ main (int argc, char* argv[]) list subs = reader->subtitles (); for (list::const_iterator i = subs.begin(); i != subs.end(); ++i) { - cout << i->text << "\n"; + for (list::const_iterator j = i->blocks.begin(); j != i->blocks.end(); ++j) { + cout << j->text << "\n"; + } } return 0; -- 2.30.2