Added support for reading v4.00++ (ASS2) files.

Originally committed to SVN as r741.
This commit is contained in:
Rodrigo Braz Monteiro 2007-01-08 01:54:02 +00:00
parent a477f58582
commit 0fbfd67864
6 changed files with 73 additions and 13 deletions

View File

@ -81,11 +81,25 @@ AssDialogue::AssDialogue(wxString _data,int version) {
Movement = 0;
#endif
// Set group
group = _T("[Events]");
Valid = Parse(_data,version);
// Try parsing in different ways
int count = 0;
Valid = false;
while (!Valid && count < 3) {
Valid = Parse(_data,version);
count++;
version++;
if (version > 2) version = 0;
}
// Not valid
if (!Valid) {
throw _T("Failed parsing line.");
}
// update
UpdateData();
}
@ -145,9 +159,13 @@ bool AssDialogue::Parse(wxString rawData, int version) {
else return false;
wxStringTokenizer tkn(rawData.Mid(pos),_T(","),wxTOKEN_RET_EMPTY_ALL);
// Get layer number
// Get first token and see if it has "Marked=" in it
if (!tkn.HasMoreTokens()) return false;
temp = tkn.GetNextToken().Trim(false).Trim(true);
if (temp.Lower().Left(7) == _T("marked=")) version = 0;
else if (version == 0) version = 1;
// Get layer number
if (version == 0) Layer = 0;
else {
long templ;
@ -184,15 +202,30 @@ bool AssDialogue::Parse(wxString rawData, int version) {
if (!tkn.HasMoreTokens()) return false;
SetMarginString(tkn.GetNextToken().Trim(false).Trim(true),1);
// Get vertical margin
// Get top margin
if (!tkn.HasMoreTokens()) return false;
temp = tkn.GetNextToken().Trim(false).Trim(true);
SetMarginString(temp,2);
SetMarginString(temp,3);
if (version == 1) SetMarginString(temp,3);
// Get bottom margin
bool rollBack = false;
if (version == 2) {
if (!tkn.HasMoreTokens()) return false;
wxString oldTemp = temp;
temp = tkn.GetNextToken().Trim(false).Trim(true);
if (!temp.IsNumber()) {
version = 1;
rollBack = true;
}
}
// Get effect
if (!tkn.HasMoreTokens()) return false;
Effect = tkn.GetNextToken();
if (!rollBack) {
if (!tkn.HasMoreTokens()) return false;
temp = tkn.GetNextToken();
}
Effect = temp;
Effect.Trim(true);
Effect.Trim(false);

View File

@ -368,7 +368,7 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS
else if (versionString == _T("v4.00++")) trueVersion = 2;
else throw _T("Unknown file version");
if (trueVersion != version) {
wxLogMessage(_T("Warning: File has the wrong extension."));
if (!(trueVersion == 2 && version == 1)) wxLogMessage(_T("Warning: File has the wrong extension."));
version = trueVersion;
}
}

View File

@ -189,6 +189,7 @@ AssStyle::AssStyle() {
Margin[2] = 10;
Margin[3] = 10;
encoding = 0;
relativeTo = 1;
UpdateData();
}
@ -214,6 +215,7 @@ AssStyle::~AssStyle() {
//////////////////////////////
// Parses value from ASS data
bool AssStyle::Parse(wxString rawData,int version) {
// Tokenize
wxString temp;
long templ;
wxStringTokenizer tkn(rawData.Mid(6),_T(","),wxTOKEN_RET_EMPTY_ALL);
@ -381,12 +383,20 @@ bool AssStyle::Parse(wxString rawData,int version) {
if (!tkn.HasMoreTokens()) return false;
SetMarginString(tkn.GetNextToken(),1);
// Read vertical margin
// Read top margin
if (!tkn.HasMoreTokens()) return false;
SetMarginString(tkn.GetNextToken(),2);
temp = tkn.GetNextToken();
SetMarginString(temp,2);
// Read bottom margin
if (version == 2) {
if (!tkn.HasMoreTokens()) return false;
SetMarginString(tkn.GetNextToken(),3);
}
else SetMarginString(temp,3);
// Read alpha level
if (version == 0) {
// Read alpha level
if (!tkn.HasMoreTokens()) return false;
temp = tkn.GetNextToken();
}
@ -397,6 +407,14 @@ bool AssStyle::Parse(wxString rawData,int version) {
temp.ToLong(&templ);
encoding = templ;
// Read relative to
if (version == 2) {
if (!tkn.HasMoreTokens()) return false;
temp = tkn.GetNextToken();
temp.ToLong(&templ);
relativeTo = templ;
}
// End
if (tkn.HasMoreTokens()) return false;
return true;
@ -551,6 +569,7 @@ AssEntry *AssStyle::Clone() {
final->spacing = spacing;
final->strikeout = strikeout;
final->underline = underline;
final->relativeTo = relativeTo;
final->SetEntryData(GetEntryData());
// Return

View File

@ -91,6 +91,7 @@ public:
int alignment;
int Margin[4];
int encoding;
int relativeTo;
ASS_EntryType GetType() { return ENTRY_STYLE; }

View File

@ -80,6 +80,7 @@ Please visit http://aegisub.net to download latest version
- Destination of screenshots can now be set in the options dialog. (AMZ)
- Moved karaoke syllable text in audio display to the top instead of bottom, since it often covers important information in spectrum mode (jfs)
- Implemented a version checker that can automatically or manually check if there are any updates to Aegisub. (AMZ)
- Added support for reading v4.00++ (ASS2) files. (AMZ)
= 1.10 beta - 2006.08.07 ===========================

View File

@ -83,7 +83,8 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
// Reader
TextFileReader file(filename,encoding);
int version = filename.Right(4).Lower() == _T(".ssa");
int version = 1;
if (filename.Right(4).Lower() == _T(".ssa")) version = 0;
// Parse file
wxString curgroup;
@ -104,12 +105,17 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
curgroup = wxbuffer;
version = 1;
}
else if (wxbuffer.Lower() == _T("[v4++ styles]")) {
wxbuffer = _T("[V4+ Styles]");
curgroup = wxbuffer;
version = 2;
}
// Not-so-special case for other groups, just set it
else if (wxbuffer[0] == _T('[')) {
curgroup = wxbuffer;
// default from extension in all other sections
version = 1;
if (filename.Right(4).Lower() == _T(".ssa")) version = 0;
//version = 1;
//if (filename.Right(4).Lower() == _T(".ssa")) version = 0;
}
// Add line