diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-07-19 01:04:04 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-07-19 23:36:56 +0100 |
| commit | a8cd625da7064816fc890d458c0d4e2dc04ba796 (patch) | |
| tree | 81cccce7f72b700917a7d3b3fe610ac6b4dd0faa /src | |
| parent | 13e3c3ed491f09f5079b3e3f759011fd2494b297 (diff) | |
More old stuff.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/text_file.cc | 96 | ||||
| -rw-r--r-- | src/lib/text_file.h | 46 |
2 files changed, 0 insertions, 142 deletions
diff --git a/src/lib/text_file.cc b/src/lib/text_file.cc deleted file mode 100644 index b6a07574b..000000000 --- a/src/lib/text_file.cc +++ /dev/null @@ -1,96 +0,0 @@ -/* - Copyright (C) 2014-2016 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 "text_file.h" -#include "cross.h" -#include "exceptions.h" -#include "text_file_content.h" -#include <sub/subrip_reader.h> -#include <sub/ssa_reader.h> -#include <sub/collect.h> -#include <unicode/ucsdet.h> -#include <unicode/ucnv.h> -#include <iostream> - -#include "i18n.h" - -using std::vector; -using std::cout; -using std::string; -using boost::shared_ptr; -using boost::scoped_array; -using dcp::Data; - -TextFile::TextFile (shared_ptr<const TextFileContent> content) -{ - Data in (content->path (0)); - - UErrorCode status = U_ZERO_ERROR; - UCharsetDetector* detector = ucsdet_open (&status); - ucsdet_setText (detector, reinterpret_cast<const char *> (in.data().get()), in.size(), &status); - - UCharsetMatch const * match = ucsdet_detect (detector, &status); - char const * in_charset = ucsdet_getName (match, &status); - - UConverter* to_utf16 = ucnv_open (in_charset, &status); - /* This is a guess; I think we should be able to encode any input in 4 times its input size */ - scoped_array<uint16_t> utf16 (new uint16_t[in.size() * 2]); - int const utf16_len = ucnv_toUChars ( - to_utf16, reinterpret_cast<UChar*>(utf16.get()), in.size() * 2, - reinterpret_cast<const char *> (in.data().get()), in.size(), - &status - ); - - UConverter* to_utf8 = ucnv_open ("UTF-8", &status); - /* Another guess */ - scoped_array<char> utf8 (new char[utf16_len * 2]); - ucnv_fromUChars (to_utf8, utf8.get(), utf16_len * 2, reinterpret_cast<UChar*>(utf16.get()), utf16_len, &status); - - ucsdet_close (detector); - ucnv_close (to_utf16); - ucnv_close (to_utf8); - - sub::Reader* reader = 0; - - string ext = content->path(0).extension().string(); - transform (ext.begin(), ext.end(), ext.begin(), ::tolower); - - if (ext == ".srt") { - reader = new sub::SubripReader (utf8.get()); - } else if (ext == ".ssa" || ext == ".ass") { - reader = new sub::SSAReader (utf8.get()); - } - - if (reader) { - _subtitles = sub::collect<vector<sub::Subtitle> > (reader->subtitles ()); - } - - delete reader; -} - -ContentTime -TextFile::length () const -{ - if (_subtitles.empty ()) { - return ContentTime (); - } - - return ContentTime::from_seconds (_subtitles.back().to.all_as_seconds ()); -} diff --git a/src/lib/text_file.h b/src/lib/text_file.h deleted file mode 100644 index 8cf0d3eae..000000000 --- a/src/lib/text_file.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (C) 2014-2016 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/>. - -*/ - -#ifndef DCPOMATIC_TEXT_SUBTITLE_H -#define DCPOMATIC_TEXT_SUBTITLE_H - -#include "dcpomatic_time.h" -#include <sub/subtitle.h> -#include <boost/shared_ptr.hpp> -#include <vector> - -class TextFileContent; -class text_file_time_test; -class text_file_coordinate_test; -class plain_text_content_test; -class text_file_parse_test; - -class TextFile -{ -public: - explicit TextFile (boost::shared_ptr<const TextFileContent>); - - ContentTime length () const; - -protected: - std::vector<sub::Subtitle> _subtitles; -}; - -#endif |
