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; Movement = 0;
#endif #endif
// Set group
group = _T("[Events]"); 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) { if (!Valid) {
throw _T("Failed parsing line."); throw _T("Failed parsing line.");
} }
// update
UpdateData(); UpdateData();
} }
@ -145,9 +159,13 @@ bool AssDialogue::Parse(wxString rawData, int version) {
else return false; else return false;
wxStringTokenizer tkn(rawData.Mid(pos),_T(","),wxTOKEN_RET_EMPTY_ALL); 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; if (!tkn.HasMoreTokens()) return false;
temp = tkn.GetNextToken().Trim(false).Trim(true); 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; if (version == 0) Layer = 0;
else { else {
long templ; long templ;
@ -184,15 +202,30 @@ bool AssDialogue::Parse(wxString rawData, int version) {
if (!tkn.HasMoreTokens()) return false; if (!tkn.HasMoreTokens()) return false;
SetMarginString(tkn.GetNextToken().Trim(false).Trim(true),1); SetMarginString(tkn.GetNextToken().Trim(false).Trim(true),1);
// Get vertical margin // Get top margin
if (!tkn.HasMoreTokens()) return false; if (!tkn.HasMoreTokens()) return false;
temp = tkn.GetNextToken().Trim(false).Trim(true); temp = tkn.GetNextToken().Trim(false).Trim(true);
SetMarginString(temp,2); 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 // Get effect
if (!tkn.HasMoreTokens()) return false; if (!rollBack) {
Effect = tkn.GetNextToken(); if (!tkn.HasMoreTokens()) return false;
temp = tkn.GetNextToken();
}
Effect = temp;
Effect.Trim(true); Effect.Trim(true);
Effect.Trim(false); 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 if (versionString == _T("v4.00++")) trueVersion = 2;
else throw _T("Unknown file version"); else throw _T("Unknown file version");
if (trueVersion != 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; version = trueVersion;
} }
} }

View file

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

View file

@ -91,6 +91,7 @@ public:
int alignment; int alignment;
int Margin[4]; int Margin[4];
int encoding; int encoding;
int relativeTo;
ASS_EntryType GetType() { return ENTRY_STYLE; } 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) - 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) - 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) - 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 =========================== = 1.10 beta - 2006.08.07 ===========================

View file

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