Fixed support for TTXT version 1.1

Originally committed to SVN as r1247.
This commit is contained in:
Rodrigo Braz Monteiro 2007-06-18 06:56:10 +00:00
parent ee5aea601c
commit 0ceff61352
1 changed files with 37 additions and 17 deletions

View File

@ -94,6 +94,13 @@ void TTXTSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) {
// Check root node name // Check root node name
if (doc.GetRoot()->GetName() != _T("TextStream")) throw _T("Invalid TTXT file."); if (doc.GetRoot()->GetName() != _T("TextStream")) throw _T("Invalid TTXT file.");
// Check version
wxString verStr = doc.GetRoot()->GetPropVal(_T("version"),_T(""));
int version = -1;
if (verStr == _T("1.0")) version = 0;
else if (verStr == _T("1.1")) version = 1;
else throw wxString(_T("Unknown TTXT version: ") + verStr);
// Get children // Get children
AssDialogue *diag = NULL; AssDialogue *diag = NULL;
wxXmlNode *child = doc.GetRoot()->GetChildren(); wxXmlNode *child = doc.GetRoot()->GetChildren();
@ -103,7 +110,9 @@ void TTXTSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) {
if (child->GetName() == _T("TextSample")) { if (child->GetName() == _T("TextSample")) {
// Get properties // Get properties
wxString sampleTime = child->GetPropVal(_T("sampleTime"),_T("00:00:00.000")); wxString sampleTime = child->GetPropVal(_T("sampleTime"),_T("00:00:00.000"));
wxString text = child->GetPropVal(_T("text"),_T("")); wxString text;
if (version == 0) text = child->GetPropVal(_T("text"),_T(""));
else text = child->GetNodeContent();
// Parse time // Parse time
AssTime time; AssTime time;
@ -115,7 +124,17 @@ void TTXTSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) {
// Create line // Create line
if (!text.IsEmpty()) { if (!text.IsEmpty()) {
// Process text // Create dialogue
diag = new AssDialogue();
diag->Start = time;
diag->End.SetMS(time.GetMS()+5000);
diag->group = _T("[Events]");
diag->Style = _T("Default");
diag->Comment = false;
diag->StartMS = diag->Start.GetMS();
// Process text for 1.0
if (version == 0) {
wxString finalText; wxString finalText;
finalText.Alloc(text.Length()); finalText.Alloc(text.Length());
bool in = false; bool in = false;
@ -128,17 +147,18 @@ void TTXTSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) {
} }
else if (in) finalText += text[i]; else if (in) finalText += text[i];
} }
// Create dialogue
diag = new AssDialogue();
diag->Start = time;
diag->End.SetMS(time.GetMS()+5000);
diag->Text = finalText; diag->Text = finalText;
diag->group = _T("[Events]"); }
diag->Style = _T("Default");
diag->Comment = false; // Process text for 1.1
else {
text.Replace(_T("\r"),_T(""));
text.Replace(_T("\n"),_T("\\N"));
diag->Text = text;
}
// Insert dialogue
diag->UpdateData(); diag->UpdateData();
diag->StartMS = diag->Start.GetMS();
Line->push_back(diag); Line->push_back(diag);
lines++; lines++;
} }