From 0ceff613524f6c91227b823995745382fdf25a05 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 18 Jun 2007 06:56:10 +0000 Subject: [PATCH] Fixed support for TTXT version 1.1 Originally committed to SVN as r1247. --- aegisub/subtitle_format_ttxt.cpp | 54 ++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/aegisub/subtitle_format_ttxt.cpp b/aegisub/subtitle_format_ttxt.cpp index 0d3533e83..59391a0a1 100644 --- a/aegisub/subtitle_format_ttxt.cpp +++ b/aegisub/subtitle_format_ttxt.cpp @@ -94,6 +94,13 @@ void TTXTSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) { // Check root node name 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 AssDialogue *diag = NULL; wxXmlNode *child = doc.GetRoot()->GetChildren(); @@ -103,7 +110,9 @@ void TTXTSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) { if (child->GetName() == _T("TextSample")) { // Get properties 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 AssTime time; @@ -115,30 +124,41 @@ void TTXTSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) { // Create line if (!text.IsEmpty()) { - // Process text - wxString finalText; - finalText.Alloc(text.Length()); - bool in = false; - bool first = true; - for (size_t i=0;iStart = time; diag->End.SetMS(time.GetMS()+5000); - diag->Text = finalText; diag->group = _T("[Events]"); diag->Style = _T("Default"); diag->Comment = false; - diag->UpdateData(); diag->StartMS = diag->Start.GetMS(); + + // Process text for 1.0 + if (version == 0) { + wxString finalText; + finalText.Alloc(text.Length()); + bool in = false; + bool first = true; + for (size_t i=0;iText = finalText; + } + + // Process text for 1.1 + else { + text.Replace(_T("\r"),_T("")); + text.Replace(_T("\n"),_T("\\N")); + diag->Text = text; + } + + // Insert dialogue + diag->UpdateData(); Line->push_back(diag); lines++; }