2006-02-26 23:45:34 +01:00
|
|
|
// Copyright (c) 2006, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// AEGISUB
|
|
|
|
//
|
|
|
|
// Website: http://aegisub.cellosoft.com
|
|
|
|
// Contact: mailto:zeratul@cellosoft.com
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2006-12-23 04:55:00 +01:00
|
|
|
#include "setup.h"
|
2006-02-27 22:57:10 +01:00
|
|
|
#include "subtitle_format.h"
|
2006-02-27 01:06:46 +01:00
|
|
|
#include "subtitle_format_ass.h"
|
|
|
|
#include "subtitle_format_srt.h"
|
|
|
|
#include "subtitle_format_txt.h"
|
2006-12-23 04:55:00 +01:00
|
|
|
#if USE_PRS == 1
|
2006-03-30 00:39:41 +02:00
|
|
|
#include "subtitle_format_prs.h"
|
2006-12-23 04:55:00 +01:00
|
|
|
#endif
|
2006-12-17 06:32:18 +01:00
|
|
|
#include "subtitle_format_mkv.h"
|
2006-02-26 23:45:34 +01:00
|
|
|
#include "ass_file.h"
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Constructor
|
2006-02-27 22:57:10 +01:00
|
|
|
SubtitleFormat::SubtitleFormat() {
|
2006-02-26 23:45:34 +01:00
|
|
|
Line = NULL;
|
|
|
|
Register();
|
2006-02-27 22:57:10 +01:00
|
|
|
isCopy = false;
|
2006-02-26 23:45:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
// Destructor
|
2006-02-27 22:57:10 +01:00
|
|
|
SubtitleFormat::~SubtitleFormat () {
|
2006-02-26 23:45:34 +01:00
|
|
|
Remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-27 22:57:10 +01:00
|
|
|
////////
|
|
|
|
// List
|
|
|
|
std::list<SubtitleFormat*> SubtitleFormat::formats;
|
|
|
|
bool SubtitleFormat::loaded = false;
|
|
|
|
|
|
|
|
|
2006-02-26 23:45:34 +01:00
|
|
|
//////////////
|
|
|
|
// Set target
|
2006-02-27 22:57:10 +01:00
|
|
|
void SubtitleFormat::SetTarget(AssFile *file) {
|
|
|
|
ClearCopy();
|
2006-02-26 23:45:34 +01:00
|
|
|
if (!file) Line = NULL;
|
|
|
|
else Line = &file->Line;
|
|
|
|
assFile = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-27 22:57:10 +01:00
|
|
|
///////////////
|
|
|
|
// Create copy
|
|
|
|
void SubtitleFormat::CreateCopy() {
|
|
|
|
SetTarget(new AssFile(*assFile));
|
|
|
|
isCopy = true;
|
2006-02-26 23:45:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-27 22:57:10 +01:00
|
|
|
//////////////
|
|
|
|
// Clear copy
|
|
|
|
void SubtitleFormat::ClearCopy() {
|
|
|
|
if (isCopy) {
|
|
|
|
delete assFile;
|
|
|
|
assFile = NULL;
|
|
|
|
isCopy = false;
|
2006-02-26 23:45:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////
|
|
|
|
// Clear subtitles
|
2006-02-27 22:57:10 +01:00
|
|
|
void SubtitleFormat::Clear() {
|
2006-02-26 23:45:34 +01:00
|
|
|
assFile->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Load default
|
2006-02-27 22:57:10 +01:00
|
|
|
void SubtitleFormat::LoadDefault() {
|
2006-02-26 23:45:34 +01:00
|
|
|
assFile->LoadDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-27 01:06:46 +01:00
|
|
|
////////////
|
|
|
|
// Add line
|
2006-07-01 04:27:37 +02:00
|
|
|
int SubtitleFormat::AddLine(wxString data,wxString group,int lasttime,bool &IsSSA,wxString *outgroup) {
|
|
|
|
return assFile->AddLine(data,group,lasttime,IsSSA,outgroup);
|
2006-02-27 01:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
2006-02-27 22:57:10 +01:00
|
|
|
// Add formats
|
|
|
|
void SubtitleFormat::LoadFormats () {
|
2006-02-27 01:06:46 +01:00
|
|
|
if (!loaded) {
|
2006-02-27 22:57:10 +01:00
|
|
|
new ASSSubtitleFormat();
|
|
|
|
new SRTSubtitleFormat();
|
|
|
|
new TXTSubtitleFormat();
|
2006-12-17 06:32:18 +01:00
|
|
|
new MKVSubtitleFormat();
|
2006-12-23 04:55:00 +01:00
|
|
|
#if USE_PRS == 1
|
2006-03-30 00:39:41 +02:00
|
|
|
new PRSSubtitleFormat();
|
2006-04-08 21:34:57 +02:00
|
|
|
#endif
|
2006-02-27 01:06:46 +01:00
|
|
|
}
|
|
|
|
loaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////
|
2006-02-27 22:57:10 +01:00
|
|
|
// Destroy formats
|
|
|
|
void SubtitleFormat::DestroyFormats () {
|
|
|
|
std::list<SubtitleFormat*>::iterator cur;
|
|
|
|
for (cur=formats.begin();cur!=formats.end();cur = formats.begin()) {
|
|
|
|
delete *cur;
|
|
|
|
}
|
|
|
|
formats.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////
|
|
|
|
// Get an appropriate reader
|
|
|
|
SubtitleFormat *SubtitleFormat::GetReader(wxString filename) {
|
|
|
|
LoadFormats();
|
|
|
|
std::list<SubtitleFormat*>::iterator cur;
|
|
|
|
SubtitleFormat *reader;
|
|
|
|
for (cur=formats.begin();cur!=formats.end();cur++) {
|
2006-02-27 01:06:46 +01:00
|
|
|
reader = *cur;
|
2006-02-27 22:57:10 +01:00
|
|
|
if (reader->CanReadFile(filename)) return reader;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////
|
|
|
|
// Get an appropriate writer
|
|
|
|
SubtitleFormat *SubtitleFormat::GetWriter(wxString filename) {
|
|
|
|
LoadFormats();
|
|
|
|
std::list<SubtitleFormat*>::iterator cur;
|
|
|
|
SubtitleFormat *writer;
|
|
|
|
for (cur=formats.begin();cur!=formats.end();cur++) {
|
|
|
|
writer = *cur;
|
|
|
|
if (writer->CanWriteFile(filename)) return writer;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////
|
|
|
|
// Register
|
|
|
|
void SubtitleFormat::Register() {
|
|
|
|
std::list<SubtitleFormat*>::iterator cur;
|
|
|
|
for (cur=formats.begin();cur!=formats.end();cur++) {
|
|
|
|
if (*cur == this) return;
|
|
|
|
}
|
|
|
|
formats.push_back(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////
|
|
|
|
// Remove
|
|
|
|
void SubtitleFormat::Remove() {
|
|
|
|
std::list<SubtitleFormat*>::iterator cur;
|
|
|
|
for (cur=formats.begin();cur!=formats.end();cur++) {
|
|
|
|
if (*cur == this) {
|
|
|
|
formats.erase(cur);
|
|
|
|
return;
|
|
|
|
}
|
2006-02-27 01:06:46 +01:00
|
|
|
}
|
|
|
|
}
|