X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fsubtitle.cc;h=2b98cb252eb30a51bc029d74a797b42ac023519b;hb=487f62d9e7e2b73cd44fdefe4a03735c7ed00fec;hp=105bf31a4cc8ac1d1219035e7f51a3a2463957d3;hpb=b5dc08b66bc7e2340dd5a8a0156036a65a49f269;p=libsub.git diff --git a/src/subtitle.cc b/src/subtitle.cc index 105bf31..2b98cb2 100644 --- a/src/subtitle.cc +++ b/src/subtitle.cc @@ -18,56 +18,66 @@ */ #include "subtitle.h" -#include "convert_time.h" -using std::list; using namespace sub; +Subtitle::Subtitle (RawSubtitle s) + : from (s.from) + , to (s.to) + , fade_up (s.fade_up) + , fade_down (s.fade_down) +{ + lines.push_back (Line (s)); +} + bool -sub::operator< (Subtitle const & a, Subtitle const & b) +Subtitle::same_metadata (RawSubtitle s) const { - if (a.from.frame && b.from.frame) { - return a.from.frame.get() < b.from.frame.get(); - } + return from == s.from && to == s.to && fade_up == s.fade_up && fade_down == s.fade_down; +} - if (a.from.metric && b.from.metric) { - return a.from.metric.get() < b.from.metric.get(); - } +Line::Line (RawSubtitle s) + : horizontal_position (s.horizontal_position) + , vertical_position (s.vertical_position) +{ + blocks.push_back (Block (s)); +} - assert (false); +bool +Line::same_metadata (RawSubtitle s) const +{ + return vertical_position == s.vertical_position; } -void -sub::convert_font_sizes (list& subs, int screen_height_in_points) +Block::Block (RawSubtitle s) + : text (s.text) + , font (s.font) + , font_size (s.font_size) + , effect (s.effect) + , effect_colour (s.effect_colour) + , colour (s.colour) + , bold (s.bold) + , italic (s.italic) + , underline (s.underline) { - for (list::iterator i = subs.begin(); i != subs.end(); ++i) { - if (i->font_size.proportional) { - i->font_size.points = i->font_size.proportional.get() * screen_height_in_points; - } else { - i->font_size.proportional = float (i->font_size.points.get()) / screen_height_in_points; - } - } + } -/** Take a list of Subtitles and convert their times either from metric to frame, or vice-versa, - * depending on what the Subtitles currently have. - * @param sub Subtitles. - * @param frames_per_second Video frames-per-second value to use in the conversion. - */ -void -sub::convert_times (list& subs, float frames_per_second) +bool +sub::operator== (Subtitle const & a, Subtitle const & b) +{ + return a.from == b.from && a.to == b.to && a.fade_up == b.fade_up && a.fade_down == b.fade_down && a.lines == b.lines; +} + +bool +sub::operator== (Line const & a, Line const & b) { - for (list::iterator i = subs.begin(); i != subs.end(); ++i) { - if (i->from.frame) { - i->from.metric = frame_to_metric (i->from.frame.get(), frames_per_second); - } else { - i->from.frame = metric_to_frame (i->from.metric.get(), frames_per_second); - } + return a.horizontal_position == b.horizontal_position && a.vertical_position == b.vertical_position && a.blocks == b.blocks; +} - if (i->to.frame) { - i->to.metric = frame_to_metric (i->to.frame.get(), frames_per_second); - } else { - i->to.frame = metric_to_frame (i->to.metric.get(), frames_per_second); - } - } +bool +sub::operator== (Block const & a, Block const & b) +{ + return a.text == b.text && a.font == b.font && a.font_size == b.font_size && a.effect == b.effect && a.effect_colour == b.effect_colour + && a.colour == b.colour && a.bold == b.bold && a.italic == b.italic && a.underline == b.underline; }