diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-12-19 16:31:42 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-01-12 22:47:45 +0100 |
| commit | d9b0b7a6319b9faecfb58df7c3c772f440f09db0 (patch) | |
| tree | 58097575a0773b2cdf4feac0ccec6c50a2b8e795 /src | |
| parent | 83f28a7c67794c0a9e48c8016db11585939e4d5d (diff) | |
Make PlayerText comparable.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/bitmap_text.cc | 40 | ||||
| -rw-r--r-- | src/lib/bitmap_text.h | 3 | ||||
| -rw-r--r-- | src/lib/player_text.cc | 9 | ||||
| -rw-r--r-- | src/lib/rect.h | 8 | ||||
| -rw-r--r-- | src/lib/string_text.cc | 28 | ||||
| -rw-r--r-- | src/lib/string_text.h | 2 | ||||
| -rw-r--r-- | src/lib/util.h | 45 | ||||
| -rw-r--r-- | src/lib/wscript | 2 |
8 files changed, 136 insertions, 1 deletions
diff --git a/src/lib/bitmap_text.cc b/src/lib/bitmap_text.cc new file mode 100644 index 000000000..6e690b313 --- /dev/null +++ b/src/lib/bitmap_text.cc @@ -0,0 +1,40 @@ +/* + Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic 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. + + DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "bitmap_text.h" +#include "image.h" + +bool +operator== (BitmapText const & a, BitmapText const & b) +{ + if (!a.rectangle.equal(b.rectangle, 0.000001)) { + return false; + } + + return *a.image == *b.image; +} + +bool +operator!= (BitmapText const & a, BitmapText const & b) +{ + return !(a == b); +} + + diff --git a/src/lib/bitmap_text.h b/src/lib/bitmap_text.h index 2314c2db0..e9d7c3b79 100644 --- a/src/lib/bitmap_text.h +++ b/src/lib/bitmap_text.h @@ -45,4 +45,7 @@ public: dcpomatic::Rect<double> rectangle; }; +extern bool operator== (BitmapText const & a, BitmapText const & b); +extern bool operator!= (BitmapText const & a, BitmapText const & b); + #endif diff --git a/src/lib/player_text.cc b/src/lib/player_text.cc index d31c7d024..429f85ddf 100644 --- a/src/lib/player_text.cc +++ b/src/lib/player_text.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -20,6 +20,7 @@ #include "player_text.h" #include "font.h" +#include "util.h" #include <boost/foreach.hpp> using std::list; @@ -41,3 +42,9 @@ PlayerText::add_fonts (list<shared_ptr<Font> > fonts_) } } } + +bool +operator== (PlayerText const & a, PlayerText const & b) +{ + return deep_equals(a.fonts, b.fonts) && deep_equals(a.bitmap, b.bitmap) && deep_equals(a.string, b.string); +} diff --git a/src/lib/rect.h b/src/lib/rect.h index 4851ad007..4e4020073 100644 --- a/src/lib/rect.h +++ b/src/lib/rect.h @@ -112,6 +112,14 @@ public: { return (p.x >= x && p.x <= (x + width) && p.y >= y && p.y <= (y + height)); } + + bool equal (Rect<T> const & other, T threshold) const + { + return std::abs(x - other.x) < threshold && + std::abs(y - other.y) < threshold && + std::abs(width - other.width) < threshold && + std::abs(height - other.height) < threshold; + } }; } diff --git a/src/lib/string_text.cc b/src/lib/string_text.cc new file mode 100644 index 000000000..54ff32578 --- /dev/null +++ b/src/lib/string_text.cc @@ -0,0 +1,28 @@ +/* + Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic 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. + + DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "string_text.h" + +bool +operator== (StringText const & a, StringText const & b) +{ + return static_cast<dcp::SubtitleString const &>(a) == static_cast<dcp::SubtitleString const &>(b) && a.outline_width == b.outline_width; +} + diff --git a/src/lib/string_text.h b/src/lib/string_text.h index 4f4958163..4063a688d 100644 --- a/src/lib/string_text.h +++ b/src/lib/string_text.h @@ -38,4 +38,6 @@ public: int outline_width; }; +extern bool operator== (StringText const & a, StringText const & b); + #endif diff --git a/src/lib/util.h b/src/lib/util.h index c8dcb29d6..36f8cec9e 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -128,4 +128,49 @@ vector_to_list (std::vector<T> v) return l; } +template <class T> +bool +deep_equals (std::list<boost::shared_ptr<T> > a, std::list<boost::shared_ptr<T> > b) +{ + if (a.size() != b.size()) { + return false; + } + + typename std::list<boost::shared_ptr<T> >::const_iterator i = a.begin(); + typename std::list<boost::shared_ptr<T> >::const_iterator j = b.begin(); + + while (i != a.end()) { + if (**i != **j) { + return false; + } + ++i; + ++j; + } + + return true; +} + +template <class T> +bool +deep_equals (std::list<T> a, std::list<T> b) +{ + if (a.size() != b.size()) { + return false; + } + + typename std::list<T>::const_iterator i = a.begin(); + typename std::list<T>::const_iterator j = b.begin(); + + while (i != a.end()) { + if (*i != *j) { + return false; + } + ++i; + ++j; + } + + return true; +} + #endif + diff --git a/src/lib/wscript b/src/lib/wscript index b78586843..94102430e 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -39,6 +39,7 @@ sources = """ audio_processor.cc audio_ring_buffers.cc audio_stream.cc + bitmap_text.cc butler.cc text_content.cc text_decoder.cc @@ -149,6 +150,7 @@ sources = """ server.cc shuffler.cc state.cc + string_text.cc spl.cc spl_entry.cc string_log_entry.cc |
