Re-work Subtitle class; remove STL text writer.
[libsub.git] / src / subtitle.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "subtitle.h"
21
22 using namespace sub;
23
24 bool
25 sub::operator< (Subtitle const & a, Subtitle const & b)
26 {
27         if (a.from.frame() && b.from.frame()) {
28                 return a.from.frame().get() < b.from.frame().get();
29         }
30
31         if (a.from.metric() && b.from.metric()) {
32                 return a.from.metric().get() < b.from.metric().get();
33         }
34
35         assert (false);
36 }
37
38
39 float
40 Block::FontSize::proportional (int screen_height_in_points) const
41 {
42         if (_proportional) {
43                 return _proportional.get ();
44         }
45
46         return float (_points.get ()) / screen_height_in_points;
47 }
48
49 int
50 Block::FontSize::points (int screen_height_in_points) const
51 {
52         if (_points) {
53                 return _points.get ();
54         }
55
56         return _proportional.get() * screen_height_in_points;
57 }
58
59 bool
60 Subtitle::same_metadata (Subtitle const & other) const
61 {
62         return (
63                 vertical_position == other.vertical_position &&
64                 from == other.from &&
65                 to == other.to &&
66                 fade_up == other.fade_up &&
67                 fade_down == other.fade_down
68                 );
69 }
70
71 bool
72 Subtitle::VerticalPosition::operator== (Subtitle::VerticalPosition const & other) const
73 {
74         if (proportional && reference && other.proportional && other.reference) {
75                 return proportional.get() == other.proportional.get() && reference.get() == other.reference.get();
76         } else if (line && other.line) {
77                 return line.get() == other.line.get();
78         }
79
80         return false;
81 }
82